protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L3WH_SSCA_1732 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Bool();
            returnValue.Result = false;

            double adjustedQuantity = 0.0;

            CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment adjustment = null;
            CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance contentAdjustmentTrackingInstance = null;
            CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content shelfContent = null;

            if (Parameter.Adjustments == null)
            {
                return(returnValue);
            }

            var adjustmentsShelfContent = new Dictionary <Guid, Double>();

            #region Adjustments without TrackingInstances

            foreach (var item in Parameter.Adjustments.Where(x => x.TrackingInstanceID == Guid.Empty))
            {
                var productTrackingInstaces = CL1_LOG_WRH.ORM_LOG_WRH_ShelfContent_2_TrackingInstance.Query.Search(Connection, Transaction,
                                                                                                                   new CL1_LOG_WRH.ORM_LOG_WRH_ShelfContent_2_TrackingInstance.Query
                {
                    LOG_WRH_Shelf_Content_RefID = item.ShelfContentID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).ToArray();

                shelfContent = CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content.Query.Search(Connection, Transaction,
                                                                                  new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content.Query()
                {
                    LOG_WRH_Shelf_ContentID = item.ShelfContentID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).Single();

                double shelfContent_CurrentQuantity_Minus_TrackingInstances_CurrentQuantity = shelfContent.Quantity_Current;
                if (productTrackingInstaces != null)
                {
                    foreach (var assignment in productTrackingInstaces)
                    {
                        var productTrackingInstancesByShelfContent = CL1_LOG.ORM_LOG_ProductTrackingInstance.Query.Search(Connection, Transaction,
                                                                                                                          new CL1_LOG.ORM_LOG_ProductTrackingInstance.Query
                        {
                            LOG_ProductTrackingInstanceID = assignment.LOG_ProductTrackingInstance_RefID,
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID
                        }).Single();
                        shelfContent_CurrentQuantity_Minus_TrackingInstances_CurrentQuantity -= productTrackingInstancesByShelfContent.CurrentQuantityOnTrackingInstance;
                    }
                }

                adjustedQuantity = item.AdjustedQuantity - shelfContent_CurrentQuantity_Minus_TrackingInstances_CurrentQuantity;

                adjustment = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment
                {
                    LOG_WRH_Shelf_ContentAdjustmentID = item.IsRelocation ? item.RelocationAdjustmentID : Guid.NewGuid(),
                    ShelfContent_RefID    = item.ShelfContentID,
                    QuantityChangedAmount = adjustedQuantity,
                    QuantityChangedDate   = DateTime.Now,
                    IsManualCorrection    = item.IsManualCorrection,
                    IfManualCorrection_InventoryChangeReason_RefID = item.IfManualCorrection_InventoryChangeReason_RefID,
                    IsRelocation = item.IsRelocation,
                    IfRelocation_CorrespondingAdjustment_RefID = item.IfRelocation_CorrespondingAdjustment_RefID,
                    IsShipmentWithdrawal = item.IsShipmentWithdrawal,
                    IfShipmentWithdrawal_ShipmentPosition_RefID = item.IfShipmentWithdrawal_ShipmentPosition_RefID,
                    PerformedAt_Date          = DateTime.Now,
                    PerformedBy_Account_RefID = securityTicket.AccountID,
                    Creation_Timestamp        = DateTime.Now,
                    Tenant_RefID = securityTicket.TenantID
                };
                adjustment.Save(Connection, Transaction);

                if (adjustmentsShelfContent.ContainsKey(item.ShelfContentID))
                {
                    adjustmentsShelfContent[item.ShelfContentID] += adjustedQuantity;
                }
                else
                {
                    adjustmentsShelfContent[item.ShelfContentID] = adjustedQuantity;
                }
            }

            #endregion

            #region Adjustments with TrackingInstances

            // Adjustements that have tracking instances and memorize relative adjustement values by ShelfID
            foreach (var item in Parameter.Adjustments.Where(x => x.TrackingInstanceID != Guid.Empty))
            {
                var productTrackingInstance = new CL1_LOG.ORM_LOG_ProductTrackingInstance();
                productTrackingInstance.Load(Connection, Transaction, item.TrackingInstanceID);

                if (productTrackingInstance.LOG_ProductTrackingInstanceID == Guid.Empty || productTrackingInstance.IsDeleted == true)
                {
                    throw new Exception("Wrong Product tracking instance");
                }

                adjustedQuantity = item.AdjustedQuantity - productTrackingInstance.CurrentQuantityOnTrackingInstance;

                adjustment = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment
                {
                    LOG_WRH_Shelf_ContentAdjustmentID = item.IsRelocation ? item.RelocationAdjustmentID : Guid.NewGuid(),
                    ShelfContent_RefID    = item.ShelfContentID,
                    QuantityChangedAmount = adjustedQuantity,
                    QuantityChangedDate   = DateTime.Now,
                    IsManualCorrection    = item.IsManualCorrection,
                    IfManualCorrection_InventoryChangeReason_RefID = item.IfManualCorrection_InventoryChangeReason_RefID,
                    IsRelocation = item.IsRelocation,
                    IfRelocation_CorrespondingAdjustment_RefID = item.IfRelocation_CorrespondingAdjustment_RefID,
                    IsShipmentWithdrawal = item.IsShipmentWithdrawal,
                    IfShipmentWithdrawal_ShipmentPosition_RefID = item.IfShipmentWithdrawal_ShipmentPosition_RefID,
                    PerformedAt_Date          = DateTime.Now,
                    PerformedBy_Account_RefID = securityTicket.AccountID,
                    Creation_Timestamp        = DateTime.Now,
                    Tenant_RefID = securityTicket.TenantID,
                };
                adjustment.Save(Connection, Transaction);

                contentAdjustmentTrackingInstance = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance
                {
                    LOG_WRH_Shelf_ContentAdjustment_TrackingInstanceID = Guid.NewGuid(),
                    Creation_Timestamp = DateTime.Now,
                    Tenant_RefID       = securityTicket.TenantID,
                    LOG_ProductTrackingInstance_RefID     = item.TrackingInstanceID,
                    LOG_WRH_Shelf_ContentAdjustment_RefID = adjustment.LOG_WRH_Shelf_ContentAdjustmentID,
                    QuantityChangedAmount = item.AdjustedQuantity
                };
                contentAdjustmentTrackingInstance.Save(Connection, Transaction);

                productTrackingInstance.CurrentQuantityOnTrackingInstance = item.AdjustedQuantity;
                productTrackingInstance.Save(Connection, Transaction);

                if (adjustmentsShelfContent.ContainsKey(item.ShelfContentID))
                {
                    adjustmentsShelfContent[item.ShelfContentID] += adjustedQuantity;
                }
                else
                {
                    adjustmentsShelfContent[item.ShelfContentID] = adjustedQuantity;
                }
            }

            #endregion

            // update shelf content for all adjustments
            foreach (var item in adjustmentsShelfContent.Keys)
            {
                shelfContent = CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content.Query.Search(Connection, Transaction,
                                                                                  new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content.Query()
                {
                    LOG_WRH_Shelf_ContentID = item,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).Single();

                shelfContent.Quantity_Current += adjustmentsShelfContent[item];
                shelfContent.Save(Connection, Transaction);
            }

            returnValue.Result = true;
            return(returnValue);

            #endregion UserCode
        }
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_Bool Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L3WH_SSCA_1732 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_Bool functionReturn = new FR_Bool();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw new Exception("Exception occured in method cls_Save_Shelf_ContentAdjustments", ex);
            }
            return(functionReturn);
        }
 ///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_Bool Invoke(string ConnectionString, P_L3WH_SSCA_1732 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }
 ///<summary>
 /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured
 ///<summary>
 public static FR_Bool Invoke(DbConnection Connection, DbTransaction Transaction, P_L3WH_SSCA_1732 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }
Пример #5
0
        protected static FR_L3WH_UPTI_1439 Execute(DbConnection Connection, DbTransaction Transaction, P_L3WH_UPTI_1439 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3WH_UPTI_1439();
            returnValue.Result = new L3WH_UPTI_1439();

            //Put your code here

            List <P_L3WH_SSCA_1732a> contentAdjustments = new List <P_L3WH_SSCA_1732a>();
            List <L3WH_UPTI_1439a>   returnVal          = new List <L3WH_UPTI_1439a>();

            foreach (var trackingInstance in Parameter.ProductTrackingInstance)
            {
                P_L3WH_SSCA_1732a ca      = new P_L3WH_SSCA_1732a();
                L3WH_UPTI_1439a   retItem = new L3WH_UPTI_1439a();

                #region TrackingInstance
                var newTrackingInstance = new CL1_LOG.ORM_LOG_ProductTrackingInstance();
                var oldTrackingInstance = new CL1_LOG.ORM_LOG_ProductTrackingInstance();
                oldTrackingInstance.Load(Connection, Transaction, trackingInstance.ProductTrackingInstanceID);

                newTrackingInstance.BatchNumber        = trackingInstance.BatchNumber;
                newTrackingInstance.ExpirationDate     = trackingInstance.ExpirationDate;
                newTrackingInstance.Creation_Timestamp = DateTime.Now;

                newTrackingInstance.OwnedBy_BusinessParticipant_RefID = oldTrackingInstance.OwnedBy_BusinessParticipant_RefID;
                newTrackingInstance.R_FreeQuantity     = oldTrackingInstance.R_FreeQuantity;
                newTrackingInstance.R_ReservedQuantity = oldTrackingInstance.R_ReservedQuantity;
                newTrackingInstance.SerialNumber       = oldTrackingInstance.SerialNumber;
                newTrackingInstance.Tenant_RefID       = securityTicket.TenantID;
                newTrackingInstance.TrackingCode       = (oldTrackingInstance.TrackingCode == null) ? String.Empty : oldTrackingInstance.TrackingCode;
                newTrackingInstance.TrackingInstanceTakenFromSourceTrackingInstance_RefID = oldTrackingInstance.TrackingInstanceTakenFromSourceTrackingInstance_RefID;
                newTrackingInstance.CMN_PRO_Product_RefID             = oldTrackingInstance.CMN_PRO_Product_RefID;
                newTrackingInstance.CMN_PRO_Product_Release_RefID     = oldTrackingInstance.CMN_PRO_Product_Release_RefID;
                newTrackingInstance.CMN_PRO_Product_Variant_RefID     = oldTrackingInstance.CMN_PRO_Product_Variant_RefID;
                newTrackingInstance.CurrentQuantityOnTrackingInstance = oldTrackingInstance.CurrentQuantityOnTrackingInstance;
                newTrackingInstance.InitialQuantityOnTrackingInstance = oldTrackingInstance.InitialQuantityOnTrackingInstance;
                newTrackingInstance.IsDeleted = false;

                newTrackingInstance.Save(Connection, Transaction);

                oldTrackingInstance.TrackingCode = (oldTrackingInstance.TrackingCode == null) ? String.Empty : oldTrackingInstance.TrackingCode;
                oldTrackingInstance.IsDeleted    = true;
                oldTrackingInstance.Save(Connection, Transaction);
                #endregion

                #region ShelfContent

                CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content newShelfContent = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content();
                CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content oldShelfContent = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content();
                oldShelfContent.Load(Connection, Transaction, trackingInstance.ShelfContentID);

                newShelfContent.GlobalPropertyMatchingID = oldShelfContent.GlobalPropertyMatchingID;
                newShelfContent.IntakeIntoInventoryDate  = oldShelfContent.IntakeIntoInventoryDate;
                newShelfContent.IsLocked                          = oldShelfContent.IsLocked;
                newShelfContent.PlacedIntoStock_Date              = oldShelfContent.PlacedIntoStock_Date;
                newShelfContent.Product_RefID                     = oldShelfContent.Product_RefID;
                newShelfContent.Product_Release_RefID             = oldShelfContent.Product_Release_RefID;
                newShelfContent.Product_Variant_RefID             = oldShelfContent.Product_Variant_RefID;
                newShelfContent.Quantity_Current                  = oldShelfContent.Quantity_Current;
                newShelfContent.Quantity_Initial                  = oldShelfContent.Quantity_Initial;
                newShelfContent.R_FreeQuantity                    = oldShelfContent.R_FreeQuantity;
                newShelfContent.R_ProcurementValue                = oldShelfContent.R_ProcurementValue;
                newShelfContent.R_ProcurementValue_Currency_RefID = oldShelfContent.R_ProcurementValue_Currency_RefID;
                newShelfContent.R_ReservedQuantity                = oldShelfContent.R_ReservedQuantity;
                newShelfContent.ReceivedAsFulfillmentOf_ProcurementOrderHeader_RefID   = oldShelfContent.ReceivedAsFulfillmentOf_ProcurementOrderHeader_RefID;
                newShelfContent.ReceivedAsFulfillmentOf_ProcurementOrderPosition_RefID = oldShelfContent.ReceivedAsFulfillmentOf_ProcurementOrderPosition_RefID;
                newShelfContent.ReceptionDate           = oldShelfContent.ReceptionDate;
                newShelfContent.Shelf_RefID             = oldShelfContent.Shelf_RefID;
                newShelfContent.Tenant_RefID            = securityTicket.TenantID;
                newShelfContent.UsedShelfCapacityAmount = oldShelfContent.UsedShelfCapacityAmount;

                newShelfContent.LOG_WRH_Shelf_ContentID = Guid.NewGuid();
                newShelfContent.Creation_Timestamp      = DateTime.Now;
                newShelfContent.Save(Connection, Transaction);

                CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content.Query.SoftDelete(Connection, Transaction, new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content.Query()
                {
                    LOG_WRH_Shelf_ContentID = trackingInstance.ShelfContentID,
                    Tenant_RefID            = securityTicket.TenantID,
                    IsDeleted = false
                });

                CL1_LOG_WRH.ORM_LOG_WRH_ShelfContent_2_TrackingInstance shelfContent2TrackingInstance = new CL1_LOG_WRH.ORM_LOG_WRH_ShelfContent_2_TrackingInstance();
                shelfContent2TrackingInstance.LOG_ProductTrackingInstance_RefID = newTrackingInstance.LOG_ProductTrackingInstanceID;
                shelfContent2TrackingInstance.LOG_WRH_Shelf_Content_RefID       = newShelfContent.LOG_WRH_Shelf_ContentID;
                shelfContent2TrackingInstance.Tenant_RefID = securityTicket.TenantID;
                shelfContent2TrackingInstance.Save(Connection, Transaction);

                var oldsc2ti = CL1_LOG_WRH.ORM_LOG_WRH_ShelfContent_2_TrackingInstance.Query.SoftDelete(Connection, Transaction, new CL1_LOG_WRH.ORM_LOG_WRH_ShelfContent_2_TrackingInstance.Query()
                {
                    LOG_WRH_Shelf_Content_RefID = oldShelfContent.LOG_WRH_Shelf_ContentID,
                    Tenant_RefID = securityTicket.TenantID
                });

                #endregion

                ca.ProductID          = newTrackingInstance.CMN_PRO_Product_RefID;
                ca.ShelfContentID     = newShelfContent.LOG_WRH_Shelf_ContentID;
                ca.TrackingInstanceID = newTrackingInstance.LOG_ProductTrackingInstanceID;
                ca.AdjustedQuantity   = trackingInstance.Quantity;
                contentAdjustments.Add(ca);

                retItem.ProductID               = trackingInstance.ProductID;
                retItem.TrackingInstanceID      = newTrackingInstance.LOG_ProductTrackingInstanceID;
                retItem.LOG_WRH_Shelf_ContentID = newShelfContent.LOG_WRH_Shelf_ContentID;
                returnVal.Add(retItem);
            }

            P_L3WH_SSCA_1732 param = new P_L3WH_SSCA_1732();
            param.Adjustments = contentAdjustments.ToArray();
            cls_Save_Shelf_ContentAdjustments.Invoke(Connection, Transaction, param, securityTicket);

            returnValue.Result.newTrackingInstance = returnVal.ToArray();

            return(returnValue);

            #endregion UserCode
        }