using System; using System.Reflection; using System.Transactions; using Produmex.Foundation.Data.Sbo; using Produmex.Foundation.Data.Sbo.Attributes; using Produmex.Foundation.Data.Sbo.BusinessObjects; using Produmex.Foundation.Data.Sbo.BusinessObjects.Convertors; using Produmex.Foundation.Data.Sbo.BusinessObjects.Definitions.Tables; using Produmex.Foundation.Data.Sbo.Providers; using Produmex.Foundation.Data.Sbo.Utilities; using Produmex.Foundation.Diagnostics; using Produmex.Foundation.Reflection; using Produmex.Foundation.Resources; using Produmex.Foundation.SboGui; using Produmex.Sbo.Logex.Data.BusinessObjects; using Produmex.Sbo.Logex.Data.BusinessObjects.Definitions; using Produmex.Sbo.Logex.Data.Providers; using System.Diagnostics; using Produmex.Sbo.Logex.Data.BusinessObjects.Definitions.Tables; using System.Text; using Produmex.Foundation.Data.SqlClient; using System.Globalization; // css_ref System.Data; // css_ref System.Xml; // css_ref Interop.SAPbobsCOM.dll; // css_ref log4net.dll; // css_ref Produmex.Foundation.Data.dll; // css_ref Produmex.Foundation.Data.Sbo.dll; // css_ref Produmex.Foundation.dll; // css_ref Produmex.Foundation.Sbo.dll; // css_ref Produmex.Sbo.Logex.Data.dll; namespace AddUpdateData { class Program { // DOES NOT NEED TO BE UPDATED - is taken over from /cs parameter in BAT file private static string CONNECTION_STRING = "";// private static readonly ILog s_log = LogProvider.GetLogger(MethodInfo.GetCurrentMethod().DeclaringType); private static string pmxWarehouseCode = ""; private static string destinationBin = ""; static void Main(string[] args) { try { CloseOldMoveOrders(); CreateMoveOrders(); } catch (Exception ex) { s_log.Error("", ex); Console.WriteLine(ex); Console.ReadLine(); } } private static void CloseOldMoveOrders() { using (TransactionScope scope = PmxDbConnection.GetNewTransactionScope()) { using (PmxDbConnectionDirect conn = PmxDbConnectionMgr.GetDirectConnection(SboConnectionString.ParseStringToObject(CONNECTION_STRING))) //using (PmxDbConnectionHana conn = new PmxDbConnectionHana(CONNECTION_STRING)) { conn.Open(); Console.Write("Connection is open"); //conn.EnlistTransaction(Transaction.Current); PmxMoveOrderProvider moveOrderProv = new PmxMoveOrderProvider(conn); // STEP 1 : GET OPENED MOVES AND CLOSE THEM : OPTIONAL string queryOldMO = @"SELECT ""DocEntry"" FROM PMX_MOHE WHERE ""DocStatus"" = 'O' AND ""MoveOrderType"" = 'R'"; using (ISboRecordset rsOldMO = SboRecordsetHelper.RunQuery(s_log, queryOldMO, conn)) { if (!rsOldMO.EoF)//Check if you get result from the query while (!rsOldMO.EoF) { //moveOrderProv.CloseMoveOrderIfPossible(rsOldMO.GetTypedValue("DocEntry")); PmxMoveOrder mo = moveOrderProv.GetBO(rsOldMO.GetTypedValue("DocEntry")); moveOrderProv.CloseDocument(mo); rsOldMO.MoveNext(); } } } scope.Complete(); } } private static void CreateMoveOrders() { using (TransactionScope scope = PmxDbConnection.GetNewTransactionScope()) { using (PmxDbConnectionDirect conn = PmxDbConnectionMgr.GetDirectConnection(SboConnectionString.ParseStringToObject(CONNECTION_STRING))) //using (PmxDbConnectionHana conn = new PmxDbConnectionHana(CONNECTION_STRING)) { conn.Open(); Console.Write("Connection is open"); //conn.EnlistTransaction(Transaction.Current); PmxMoveOrderProvider moveOrderProv = new PmxMoveOrderProvider(conn); // STEP 2 : IDENTIFY THE BINS THAT NEED TO BE REPLENISHED string queryDemandByItem = @"SELECT DISTINCT T0.""ItemCode"", T0.""QtyToMove"", T0.""StorLocCode"", T0.""PmxWhsCode"" FROM PMX_REPLENISH_PICKLOC_DEMAND_BASED_DEFAULT_LOCATION T0 WITH(NOLOCK) INNER JOIN PMX_REPLENISH_AVAILABLE_BULK_STOCK_CHECK T1 WITH(NOLOCK) ON T0.""ItemCode"" = T1.""ItemCode"" AND T0.""PmxWhsCode"" = T1.""PmxWhsCode"""; using (ISboRecordset rsDemandByItem = SboRecordsetHelper.RunQuery(s_log, queryDemandByItem, conn)) { if (!rsDemandByItem.EoF)//Check if you get result from the query { Console.Write("Create Move Order"); PmxMoveOrder moveOrder = moveOrderProv.GetNewBO(); while (!rsDemandByItem.EoF) { string itemCode = rsDemandByItem.GetTypedValue("ItemCode"); string PmxWhsCode = rsDemandByItem.GetTypedValue("PmxWhsCode"); double quantityToMove = rsDemandByItem.GetTypedValue("QtyToMove"); //double quantityInMoveDoc = 0; //int numberOfSSCCtoMove = rsDemandByItem.GetTypedValue("SsccToMove"); destinationBin = rsDemandByItem.GetTypedValue("StorLocCode"); pmxWarehouseCode = rsDemandByItem.GetTypedValue("PmxWhsCode"); s_log.Info("Picking replenishement : ItemCode " + itemCode + " to BinLocation " + destinationBin ); // STEP 3: GET BULK STOCK OVERVIEW PER EACH ITEM string bulkStockQuery = @"SELECT * FROM PMX_REPLENISH_BULK_STOCK WHERE ""ItemCode"" = '"+ itemCode + @"' AND ""PmxWhsCode"" = '"+ PmxWhsCode + @"' ORDER BY ""BestBeforeDate"" "; using (ISboRecordset rsBulk = SboRecordsetHelper.RunQuery(s_log, bulkStockQuery, conn)) { if (!rsBulk.EoF)//Check if you get result from the query { while (!rsBulk.EoF) { if (quantityToMove > 0) { Console.Write("Create Line "); PmxMoveOrderLine moveOrderLine = moveOrderProv.GetNewAddedLine(moveOrder); moveOrderLine.ItemCode = rsBulk.GetTypedValue("ItemCode"); moveOrderLine.SourceStorageLocationCode = rsBulk.GetTypedValue("StorLocCode"); moveOrderLine.DestinationStorageLocationCode = destinationBin; double quantityForLine = rsBulk.GetTypedValue("Quantity"); moveOrderLine.OpenQuantity = quantityForLine; moveOrderLine.Quantity = quantityForLine; //keep track of current quantities //quantityInMoveDoc = quantityInMoveDoc + quantityForLine; quantityToMove = quantityToMove - quantityForLine; //set batch if needed if (rsBulk.GetTypedValue("ItemTransactionalInfoKey") != 0) { moveOrderLine.ItemTransactionalInfoKey = rsBulk.GetTypedValue("ItemTransactionalInfoKey");} //set LUID if needed - forces scan of SSCC during Replenish if (rsBulk.GetTypedValue("LogunitIdentkey") != 0) { moveOrderLine.SourceLogisticUnitIdentKey = rsBulk.GetTypedValue("LogunitIdentkey");} //setting of destination LUID only used in Put-away //moveOrderLine.DestinationLogisticUnitIdentKey = rsBulk.GetTypedValue("LogunitIdentkey"); moveOrderLine.QualityStatusCode = rsBulk.GetTypedValue("QualityStatusCode"); //1 SSCC added to MOVE so substract it from total number to move //numberOfSSCCtoMove--; } rsBulk.MoveNext(); } } } rsDemandByItem.MoveNext(); } if ( moveOrder.DocLines.Count > 0) { moveOrder.FromPmxWhsCode = pmxWarehouseCode; moveOrder.ToPmxWhsCode = pmxWarehouseCode; moveOrder.MoveOrderType = PmxMoveOrderType.Replenish; // - default value //MoveOrderTypes: //Move //PutAway //Replenish //WarehouseTransfer //PutAwayProduction //moveOrder.MoveLogUnitIn1Time = PmxMoveInOneTime.MustBeMovedInOneTime; // used if must move in 1 time (only put-away) //moveOrder.DueDate = DateTime.Now; - default value moveOrder.Priority = 100; moveOrderProv.AddBO(moveOrder); } } } //Complete transaction scope.Complete(); } } } } }