protected static FR_L5CO_ACOaCS_2108_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_ACOaCS_2108[] Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CO_ACOaCS_2108_Array();
            List <L5CO_ACOaCS_2108> confirmedProcurementOrders = new List <L5CO_ACOaCS_2108>();
            foreach (var param in Parameter)
            {
                L5CO_ACOaCS_2108 procurementOrderITL = new L5CO_ACOaCS_2108();
                var confirmedStatus = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
                                                                                    new ORM_ORD_CUO_CustomerOrder_Status.Query
                {
                    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Confirmed),
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted = false
                }).Single().ORD_CUO_CustomerOrder_StatusID;

                var customerOrder = new ORM_ORD_CUO_CustomerOrder_Header();
                customerOrder.Load(Connection, Transaction, param.CustomerOrderHeaderID);
                customerOrder.Current_CustomerOrderStatus_RefID = confirmedStatus;
                customerOrder.IsCustomerOrderFinalized          = true;
                customerOrder.Save(Connection, Transaction);

                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, securityTicket.AccountID);

                ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
                newStatusInHistory.CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID;
                newStatusInHistory.StatusHistoryComment       = param.Message;
                newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
                newStatusInHistory.CustomerOrder_Status_RefID            = confirmedStatus;
                newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
                newStatusInHistory.Save(Connection, Transaction);


                procurementOrderITL.ProcurementOrderITL = customerOrder.ProcurementOrderITL;
                procurementOrderITL.ProcuringTenatID    = customerOrder.OrderingCustomer_BusinessParticipant_RefID.ToString();



                ORM_CMN_NumberRange_UsageArea numberRangeUsageArea = ORM_CMN_NumberRange_UsageArea.Query.Search(Connection, Transaction, new ORM_CMN_NumberRange_UsageArea.Query()
                {
                    IsDeleted              = false,
                    Tenant_RefID           = securityTicket.TenantID,
                    GlobalStaticMatchingID = NumberRangeGlobalPropertyMatchingID
                }).FirstOrDefault();


                if (numberRangeUsageArea == null)
                {
                    throw new Exception(String.Format("Number range usage area with GPMID = {0} was not found.", NumberRangeGlobalPropertyMatchingID));
                }

                ORM_CMN_NumberRange numberRange = ORM_CMN_NumberRange.Query.Search(Connection, Transaction, new ORM_CMN_NumberRange.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    NumberRange_UsageArea_RefID = numberRangeUsageArea.CMN_NumberRange_UsageAreaID
                }).FirstOrDefault();

                if (numberRange == null)
                {
                    throw new Exception(String.Format("Number range for area with GPMID = {0} was not found.", NumberRangeGlobalPropertyMatchingID));
                }

                numberRange.Value_Current++;
                numberRange.Save(Connection, Transaction);
                string shipmentNumber = numberRange.FixedPrefix + numberRange.Value_Current.ToString().PadLeft(numberRange.Formatting_NumberLength, numberRange.Formatting_LeadingFillCharacter[0]);

                ORM_LOG_SHP_Shipment_Header shipmentHeader = new ORM_LOG_SHP_Shipment_Header();
                shipmentHeader.LOG_SHP_Shipment_HeaderID          = Guid.NewGuid();
                shipmentHeader.RecipientBusinessParticipant_RefID = customerOrder.OrderingCustomer_BusinessParticipant_RefID;
                shipmentHeader.ShipmentHeaderITL              = shipmentHeader.LOG_SHP_Shipment_HeaderID.ToString();
                shipmentHeader.ShipmentHeader_Number          = shipmentNumber;
                shipmentHeader.Shippipng_AddressUCD_RefID     = customerOrder.ShippingAddressUCD_RefID;
                shipmentHeader.ShipmentPriority               = 0;
                shipmentHeader.ShipmentHeader_ValueWithoutTax = customerOrder.TotalValue_BeforeTax;
                shipmentHeader.ShipmentHeader_Currency_RefID  = customerOrder.CustomerOrder_Currency_RefID;
                shipmentHeader.Tenant_RefID = securityTicket.TenantID;
                shipmentHeader.IsDeleted    = false;
                shipmentHeader.Save(Connection, Transaction);

                var customerOrderPositions = ORM_ORD_CUO_CustomerOrder_Position.Query.Search(Connection, Transaction, new ORM_ORD_CUO_CustomerOrder_Position.Query()
                {
                    CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });

                if (customerOrderPositions != null)
                {
                    foreach (var customerOrderPosition in customerOrderPositions)
                    {
                        ORM_LOG_SHP_Shipment_Position shipmentPosition = new ORM_LOG_SHP_Shipment_Position();
                        shipmentPosition.LOG_SHP_Shipment_PositionID   = Guid.NewGuid();
                        shipmentPosition.ShipmentPositionITL           = shipmentPosition.LOG_SHP_Shipment_PositionID.ToString();
                        shipmentPosition.LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                        shipmentPosition.CMN_PRO_Product_RefID         = customerOrderPosition.CMN_PRO_Product_RefID;
                        shipmentPosition.CMN_PRO_ProductVariant_RefID  = customerOrderPosition.CMN_PRO_Product_Variant_RefID;
                        shipmentPosition.CMN_PRO_ProductRelease_RefID  = customerOrderPosition.CMN_PRO_Product_Release_RefID;
                        shipmentPosition.QuantityToShip = customerOrderPosition.Position_Quantity;
                        shipmentPosition.ShipmentPosition_PricePerUnitValueWithoutTax = customerOrderPosition.Position_ValuePerUnit;
                        shipmentPosition.ShipmentPosition_ValueWithoutTax             = customerOrderPosition.Position_ValueTotal;
                        shipmentPosition.IsCancelled  = false;
                        shipmentPosition.Tenant_RefID = securityTicket.TenantID;
                        shipmentPosition.IsDeleted    = false;
                        shipmentPosition.Save(Connection, Transaction);
                        ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition customerOrderPositionToShipmentPosition = new ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition();
                        customerOrderPositionToShipmentPosition.AssignmentID = Guid.NewGuid();
                        customerOrderPositionToShipmentPosition.LOG_SHP_Shipment_Position_RefID      = shipmentPosition.LOG_SHP_Shipment_PositionID;
                        customerOrderPositionToShipmentPosition.ORD_CUO_CustomerOrder_Position_RefID = customerOrderPosition.ORD_CUO_CustomerOrder_PositionID;
                        customerOrderPositionToShipmentPosition.Tenant_RefID = securityTicket.TenantID;
                        customerOrderPositionToShipmentPosition.IsDeleted    = false;
                        customerOrderPositionToShipmentPosition.Save(Connection, Transaction);
                    }
                }


                //TO DO: UNCOMMENT AFTER JANKO ADD STATUSES
                //var shipmentStatusHistoryStatusID = ORM_LOG_SHP_Shipment_Status.Query.Search(Connection, Transaction, new ORM_LOG_SHP_Shipment_Status.Query()
                //{
                //    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EShipmentStatus.Created),
                //    Tenant_RefID = securityTicket.TenantID,
                //    IsDeleted = false
                //}).Single().LOG_SHP_Shipment_StatusID;

                //ORM_LOG_SHP_Shipment_StatusHistory shipmentStatusHistory = new ORM_LOG_SHP_Shipment_StatusHistory();
                //shipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID = Guid.NewGuid();
                //shipmentStatusHistory.LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                //shipmentStatusHistory.LOG_SHP_Shipment_Status_RefID = shipmentStatusHistoryStatusID;
                //shipmentStatusHistory.PerformedBy_BusinessParticipant_RefID = securityTicket.TenantID;
                //shipmentStatusHistory.Tenant_RefID = securityTicket.TenantID;
                //shipmentStatusHistory.IsDeleted = false;
                //shipmentStatusHistory.Save(Connection, Transaction);

                ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader shipmentToCustomerOrderHeader = new ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader();
                shipmentToCustomerOrderHeader.AssignmentID = Guid.NewGuid();
                shipmentToCustomerOrderHeader.LOG_SHP_Shipment_Header_RefID      = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                shipmentToCustomerOrderHeader.ORD_CUO_CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID;
                shipmentToCustomerOrderHeader.Tenant_RefID = securityTicket.TenantID;
                shipmentToCustomerOrderHeader.IsDeleted    = false;
                shipmentToCustomerOrderHeader.Save(Connection, Transaction);


                confirmedProcurementOrders.Add(procurementOrderITL);
            }
            returnValue.Result = confirmedProcurementOrders.ToArray();
            return(returnValue);

            #endregion UserCode
        }
Example #2
0
        protected static FR_L5RS_CSaRSH_0244 Execute(DbConnection Connection, DbTransaction Transaction, P_L5RS_CSaRSH_0244 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5RS_CSaRSH_0244();

            returnValue.Result = new L5RS_CSaRSH_0244();

            #region New ShipmentHeader
            var newShipmentHeaderId = Guid.NewGuid();

            #region Get Tenant Curency ID
            var defaultCurrency = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
            #endregion

            #region Create Shipment Status History
            #region Get 'Returned' Shipment status
            var returnedStatusId = ORM_LOG_SHP_Shipment_Status.Query.Search(
                Connection,
                Transaction,
                new ORM_LOG_SHP_Shipment_Status.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EShipmentStatus.Returned),
                Tenant_RefID             = securityTicket.TenantID
            }).FirstOrDefault().LOG_SHP_Shipment_StatusID;
            #endregion

            #region Fetch Status History 'performed by' User Account
            var performedByAccount = new ORM_USR_Account();
            performedByAccount.Load(Connection, Transaction, securityTicket.AccountID);
            #endregion

            #region Get ShipmentHeader Number
            var shipmentHeaderNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(
                Connection,
                Transaction,
                new P_L2NR_GaIINfUA_1454()
            {
                GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.SupplierReturnShipmentNumber)
            },
                securityTicket).Result.Current_IncreasingNumber;
            #endregion

            var newShipmentStatusHistory = new ORM_LOG_SHP_Shipment_StatusHistory();
            newShipmentStatusHistory.Creation_Timestamp                    = DateTime.Now;
            newShipmentStatusHistory.IsDeleted                             = false;
            newShipmentStatusHistory.LOG_SHP_Shipment_Header_RefID         = newShipmentHeaderId;
            newShipmentStatusHistory.LOG_SHP_Shipment_Status_RefID         = returnedStatusId;
            newShipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID      = Guid.NewGuid();
            newShipmentStatusHistory.PerformedBy_BusinessParticipant_RefID =
                performedByAccount == null
                ? Guid.Empty
                : performedByAccount.BusinessParticipant_RefID;
            newShipmentStatusHistory.Tenant_RefID = securityTicket.TenantID;
            #endregion

            #region Create Shipment Header Object
            var newShipmentHeader = new ORM_LOG_SHP_Shipment_Header();
            newShipmentHeader.Creation_Timestamp                 = DateTime.Now;
            newShipmentHeader.LOG_SHP_Shipment_HeaderID          = newShipmentHeaderId;
            newShipmentHeader.RecipientBusinessParticipant_RefID = Parameter.SupplierID;
            newShipmentHeader.ShipmentHeader_Currency_RefID      = defaultCurrency.CMN_CurrencyID;
            newShipmentHeader.ShipmentHeader_Number              = shipmentHeaderNumber;
            newShipmentHeader.ShipmentHeader_ValueWithoutTax     = 0;
            newShipmentHeader.ShipmentPriority   = 0;
            newShipmentHeader.ShipmentType_RefID = newShipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID;
            newShipmentHeader.Tenant_RefID       = securityTicket.TenantID;
            #endregion
            #endregion

            #region New ReturnShipment Header
            var newReturnShipmentHeaderId = Guid.NewGuid();
            var newReturnShipmentHeader   = new ORM_LOG_SHP_ReturnShipment_Header();
            newReturnShipmentHeader.Creation_Timestamp              = DateTime.Now;
            newReturnShipmentHeader.Ext_Shipment_Header_RefID       = newShipmentHeaderId;
            newReturnShipmentHeader.LOG_SHP_ReturnShipment_HeaderID = newReturnShipmentHeaderId;
            newReturnShipmentHeader.Tenant_RefID = securityTicket.TenantID;
            #endregion

            #region Save
            var resultHistory        = newShipmentStatusHistory.Save(Connection, Transaction);
            var resultHeader         = newShipmentHeader.Save(Connection, Transaction);
            var resultShipmentHeader = newReturnShipmentHeader.Save(Connection, Transaction);
            if (resultHistory.Status != FR_Status.Success || resultHeader.Status != FR_Status.Success || resultShipmentHeader.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = null;
            }
            else
            {
                returnValue.Status = FR_Status.Success;
                returnValue.Result.ShipmentHeaderID       = newShipmentHeaderId;
                returnValue.Result.ShipmentHeaderNumber   = newShipmentHeader.ShipmentHeader_Number;
                returnValue.Result.ReturnShipmentHeaderID = newReturnShipmentHeaderId;
            }
            #endregion

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5RS_CSaRSPfH_0449 Execute(DbConnection Connection, DbTransaction Transaction, P_L5RS_CSaRSPfH_0449 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5RS_CSaRSPfH_0449();

            returnValue.Result = new L5RS_CSaRSPfH_0449();
            FR_Base resultHeader, resultPosition, resultReturnPosition;

            if (Parameter.Positions.Count() <= 0)
            {
                returnValue.Status = FR_Status.Success;
                returnValue.Result = null;
                return(returnValue);
            }

            #region Load Shipment Header and calculate Total Price
            decimal totalValueWithoutTax = 0;

            #region Load Shipment Header
            var shipmentHeader = new ORM_LOG_SHP_Shipment_Header();
            var result         = shipmentHeader.Load(Connection, Transaction, Parameter.Positions[0].ShipmentHeaderID);
            if (result.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = null;
                return(returnValue);
            }
            #endregion

            #region Load Shipment Header Positions And Calculate Total Value
            var shipmentPositions = ORM_LOG_SHP_Shipment_Position.Query.Search(
                Connection,
                Transaction,
                new ORM_LOG_SHP_Shipment_Position.Query()
            {
                LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID,
                Tenant_RefID = securityTicket.TenantID
            }).ToList();
            foreach (var position in shipmentPositions)
            {
                totalValueWithoutTax += position.ShipmentPosition_ValueWithoutTax;
            }
            #endregion

            shipmentHeader.ShipmentHeader_ValueWithoutTax = totalValueWithoutTax;
            #endregion

            var resultShipmentPositionsIDs      = new List <Guid>();
            var resultReturnShipmentPositionIDs = new List <Guid>();
            foreach (P_L5RS_CSaRSPfH_0449a position in Parameter.Positions)
            {
                #region Create Shipment Position Object
                var newShipmentPositionObject = new ORM_LOG_SHP_Shipment_Position();
                newShipmentPositionObject.CMN_PRO_Product_RefID         = position.ProductId;
                newShipmentPositionObject.Creation_Timestamp            = DateTime.Now;
                newShipmentPositionObject.LOG_SHP_Shipment_Header_RefID = position.ShipmentHeaderID;
                newShipmentPositionObject.LOG_SHP_Shipment_PositionID   = Guid.NewGuid();
                newShipmentPositionObject.QuantityToShip = position.Quantity;
                newShipmentPositionObject.ShipmentPosition_ValueWithoutTax             = position.PricePerUnit * position.Quantity;
                newShipmentPositionObject.ShipmentPosition_PricePerUnitValueWithoutTax = position.PricePerUnit;
                newShipmentPositionObject.Tenant_RefID         = securityTicket.TenantID;
                shipmentHeader.ShipmentHeader_ValueWithoutTax += newShipmentPositionObject.ShipmentPosition_ValueWithoutTax;
                #endregion

                #region Create ReturnShipment Position Object
                var newReturnShipmentPositionObject = new ORM_LOG_SHP_ReturnShipment_Position();
                newReturnShipmentPositionObject.Creation_Timestamp                = DateTime.Now;
                newReturnShipmentPositionObject.Ext_Shipment_Position_RefID       = newShipmentPositionObject.LOG_SHP_Shipment_PositionID;
                newReturnShipmentPositionObject.LOG_SHP_ReturnShipment_PositionID = Guid.NewGuid();
                newReturnShipmentPositionObject.ReturnPolicy_RefID                = position.ReturnPolicyId;
                newReturnShipmentPositionObject.ReturnProductOriginatedFromReceiptPosition_RefID = position.ReceiptPositionId;
                newReturnShipmentPositionObject.ReturnShipment_Header_RefID = position.ReturnShipmentHeaderID;
                newReturnShipmentPositionObject.Tenant_RefID = securityTicket.TenantID;
                #endregion

                #region Save Position
                resultPosition       = newShipmentPositionObject.Save(Connection, Transaction);
                resultReturnPosition = newReturnShipmentPositionObject.Save(Connection, Transaction);
                if (resultPosition.Status != FR_Status.Success || resultReturnPosition.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = null;
                    return(returnValue);
                }
                resultShipmentPositionsIDs.Add(newShipmentPositionObject.LOG_SHP_Shipment_PositionID);
                resultReturnShipmentPositionIDs.Add(newReturnShipmentPositionObject.LOG_SHP_ReturnShipment_PositionID);
                #endregion
            }

            #region Update Shipment Header with Total Value
            resultHeader = shipmentHeader.Save(Connection, Transaction);
            if (resultHeader.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = null;
                return(returnValue);
            }
            #endregion

            #region Fetch ShipmentHeader SupplierName
            var supplierBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
            supplierBusinessParticipant.Load(Connection, Transaction, shipmentHeader.RecipientBusinessParticipant_RefID);
            #endregion

            returnValue.Status = FR_Status.Success;
            returnValue.Result.ShipmentPositionIDs        = resultShipmentPositionsIDs.ToArray();
            returnValue.Result.ReturnShipmentPositionIDs  = resultReturnShipmentPositionIDs.ToArray();
            returnValue.Result.ShipmentHeaderSupplierName = supplierBusinessParticipant == null
                    ? string.Empty : supplierBusinessParticipant.DisplayName;
            returnValue.Result.ShipmentHeaderNumber     = shipmentHeader.ShipmentHeader_Number;
            returnValue.Result.ShipmentHeaderTotalValue = shipmentHeader.ShipmentHeader_ValueWithoutTax;

            return(returnValue);

            #endregion UserCode
        }
Example #4
0
        protected static FR_L6CN_SCNaURS_0910 Execute(DbConnection Connection, DbTransaction Transaction, P_L6CN_SCNaURS_0910 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6CN_SCNaURS_0910();
            returnValue.Result = new L6CN_SCNaURS_0910();
            var newShipmentHeaderGuids        = new List <Guid>();
            var shipmentPositionsToBeCredited = new List <Guid>();
            var newShipmentPositions          = new List <P_L5RS_CSaRSPfH_0449a>();

            foreach (var header in Parameter.ShipmentHeaders)
            {
                var shipmentHeader          = new ORM_LOG_SHP_Shipment_Header();
                var shipmentHeaderPositions = new List <ORM_LOG_SHP_Shipment_Position>();

                #region Load Shipment Header and Positions
                var result = shipmentHeader.Load(Connection, Transaction, header.ShipmentHeaderID);
                if (result.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    return(returnValue);
                }

                shipmentHeaderPositions = ORM_LOG_SHP_Shipment_Position.Query.Search(
                    Connection,
                    Transaction,
                    new ORM_LOG_SHP_Shipment_Position.Query()
                {
                    LOG_SHP_Shipment_Header_RefID = header.ShipmentHeaderID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                });
                #endregion

                L5RS_CSaRSH_0244 newHeader = null;
                decimal          updatedHeaderTotalValue = 0;

                foreach (var position in shipmentHeaderPositions)
                {
                    var positionToBeCredited = header.ShipmentPositions.FirstOrDefault(hsp => hsp.ShipmentPositionID == position.LOG_SHP_Shipment_PositionID);

                    // Split Shipment in case that not all positions of one header are selected for crediting
                    // or in case that selected positions quantities are edited.
                    #region Create New Header and Position Object if position is not selected or dirty
                    if (positionToBeCredited == null || positionToBeCredited.Quantity != positionToBeCredited.OriginalQuantity)
                    {
                        if (Parameter.ReturnToStock == false)
                        {
                            #region Create New Header
                            if (newHeader == null)
                            {
                                var newHeaderParameter = new P_L5RS_CSaRSH_0244()
                                {
                                    SupplierID = Parameter.SupplierId
                                };
                                var createResult = cls_Create_Shipment_and_ReturnShipment_Header.Invoke(Connection, Transaction, newHeaderParameter, securityTicket);
                                if (createResult.Status != FR_Status.Success)
                                {
                                    returnValue.Status = FR_Status.Error_Internal;
                                    return(returnValue);
                                }
                                newHeader = createResult.Result;
                                newShipmentHeaderGuids.Add(newHeader.ShipmentHeaderID);
                            }
                            #endregion

                            #region Set New Position Object
                            P_L5RS_CSaRSPfH_0449a newPosition;
                            if (positionToBeCredited == null)
                            {
                                var productTrackingInstance = cls_Get_ProductTrackingInstance_for_StockReceiptPosition.Invoke(
                                    Connection,
                                    Transaction,
                                    new P_L5SR_GPTIfSRP_1322()
                                {
                                    ReceiptPositionsID = header.ShipmentPositions[0].ReceiptPositionID
                                },
                                    securityTicket).Result;
                                newPosition = new P_L5RS_CSaRSPfH_0449a()
                                {
                                    Quantity                = Convert.ToInt32(position.QuantityToShip),
                                    PricePerUnit            = position.ShipmentPosition_PricePerUnitValueWithoutTax,
                                    ProductId               = position.CMN_PRO_Product_RefID,
                                    ReceiptPositionId       = header.ShipmentPositions[0].ReceiptPositionID,
                                    ReturnPolicyId          = header.ShipmentPositions[0].ReturnPolicyID,
                                    ShipmentHeaderID        = newHeader.ShipmentHeaderID,
                                    ReturnShipmentHeaderID  = newHeader.ReturnShipmentHeaderID,
                                    ProductTrackingInstance = productTrackingInstance.LOG_ProductTrackingInstanceID,
                                    ShelfContentID          = productTrackingInstance.LOG_WRH_Shelf_ContentID
                                };
                            }
                            else
                            {
                                var productTrackingInstance = cls_Get_ProductTrackingInstance_for_StockReceiptPosition.Invoke(
                                    Connection,
                                    Transaction,
                                    new P_L5SR_GPTIfSRP_1322()
                                {
                                    ReceiptPositionsID = positionToBeCredited.ReceiptPositionID
                                },
                                    securityTicket).Result;
                                newPosition = new P_L5RS_CSaRSPfH_0449a()
                                {
                                    Quantity                = positionToBeCredited.OriginalQuantity - positionToBeCredited.Quantity,
                                    PricePerUnit            = positionToBeCredited.OriginalTotalValue / positionToBeCredited.OriginalQuantity,
                                    ProductId               = positionToBeCredited.ProductId,
                                    ReceiptPositionId       = positionToBeCredited.ReceiptPositionID,
                                    ReturnPolicyId          = positionToBeCredited.ReturnPolicyID,
                                    ShipmentHeaderID        = newHeader.ShipmentHeaderID,
                                    ReturnShipmentHeaderID  = newHeader.ReturnShipmentHeaderID,
                                    ProductTrackingInstance = productTrackingInstance.LOG_ProductTrackingInstanceID,
                                    ShelfContentID          = productTrackingInstance.LOG_WRH_Shelf_ContentID
                                };
                            }
                            newShipmentPositions.Add(newPosition);
                            #endregion
                        }
                        else
                        {
                            #region Return to Stock
                            //The difference in the credited quantity compared to the returned position is taken back to stock.

                            if (positionToBeCredited == null)
                            {
                                var productTrackingInstance = cls_Get_ProductTrackingInstance_for_StockReceiptPosition.Invoke(
                                    Connection,
                                    Transaction,
                                    new P_L5SR_GPTIfSRP_1322()
                                {
                                    ReceiptPositionsID = header.ShipmentPositions[0].ReceiptPositionID
                                },
                                    securityTicket).Result;

                                CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content shelfContent = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content();
                                shelfContent.Load(Connection, Transaction, productTrackingInstance.LOG_WRH_Shelf_ContentID);

                                shelfContent.Quantity_Current = Convert.ToInt32(position.QuantityToShip);
                                shelfContent.Save(Connection, Transaction);

                                CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment shelfContentAdjustment = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment();
                                shelfContentAdjustment.ShelfContent_RefID    = shelfContent.Shelf_RefID;
                                shelfContentAdjustment.QuantityChangedAmount = shelfContent.Quantity_Current;
                                shelfContentAdjustment.QuantityChangedDate   = DateTime.Now;
                                shelfContentAdjustment.Creation_Timestamp    = DateTime.Now;
                                shelfContentAdjustment.Tenant_RefID          = securityTicket.TenantID;
                                shelfContentAdjustment.Save(Connection, Transaction);
                            }
                            else
                            {
                                var productTrackingInstance = cls_Get_ProductTrackingInstance_for_StockReceiptPosition.Invoke(
                                    Connection,
                                    Transaction,
                                    new P_L5SR_GPTIfSRP_1322()
                                {
                                    ReceiptPositionsID = positionToBeCredited.ReceiptPositionID
                                },
                                    securityTicket).Result;

                                CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content shelfContent = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_Content();
                                shelfContent.Load(Connection, Transaction, productTrackingInstance.LOG_WRH_Shelf_ContentID);

                                shelfContent.Quantity_Current = positionToBeCredited.OriginalQuantity - positionToBeCredited.Quantity;
                                shelfContent.Save(Connection, Transaction);

                                CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment shelfContentAdjustment = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment();
                                shelfContentAdjustment.ShelfContent_RefID    = shelfContent.Shelf_RefID;
                                shelfContentAdjustment.QuantityChangedAmount = shelfContent.Quantity_Current;
                                shelfContentAdjustment.QuantityChangedDate   = DateTime.Now;
                                shelfContentAdjustment.Creation_Timestamp    = DateTime.Now;
                                shelfContentAdjustment.Tenant_RefID          = securityTicket.TenantID;
                                shelfContentAdjustment.Save(Connection, Transaction);
                            }

                            #endregion
                        }
                    }
                    #endregion

                    if (positionToBeCredited == null)
                    {
                        #region Cancel Position

                        #region Get Account
                        var account = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                        {
                            Tenant_RefID  = securityTicket.TenantID,
                            IsDeleted     = false,
                            USR_AccountID = securityTicket.AccountID
                        }).FirstOrDefault();
                        #endregion

                        position.IsCancelled     = true;
                        position.CancelledOnDate = DateTime.Now;
                        position.CancelledBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
                        var resultUpdate = position.Save(Connection, Transaction);
                        if (resultUpdate.Status != FR_Status.Success)
                        {
                            returnValue.Status = FR_Status.Error_Internal;
                            return(returnValue);
                        }
                        #endregion
                    }
                    else
                    {
                        shipmentPositionsToBeCredited.Add(positionToBeCredited.ReturnShipmentPositionID);
                        updatedHeaderTotalValue += positionToBeCredited.TotalValue;

                        #region Update Position if data is dirty
                        if (positionToBeCredited.Quantity != positionToBeCredited.OriginalQuantity ||
                            positionToBeCredited.TotalValue != positionToBeCredited.OriginalTotalValue)
                        {
                            position.QuantityToShip = positionToBeCredited.Quantity;
                            position.ShipmentPosition_ValueWithoutTax = positionToBeCredited.TotalValue;
                            var resultUpdate = position.Save(Connection, Transaction);
                            if (resultUpdate.Status != FR_Status.Success)
                            {
                                returnValue.Status = FR_Status.Error_Internal;
                                return(returnValue);
                            }
                        }
                        #endregion
                    }
                }

                #region Update shipmentHeader

                #region Create Credited Status History
                // fetch 'credited' status id
                var returnedStatusId = ORM_LOG_SHP_Shipment_Status.Query.Search(
                    Connection,
                    Transaction,
                    new ORM_LOG_SHP_Shipment_Status.Query()
                {
                    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EShipmentStatus.Credited),
                    Tenant_RefID             = securityTicket.TenantID
                }).FirstOrDefault().LOG_SHP_Shipment_StatusID;
                // fetch Status History 'credited by' User Account
                var performedByAccount = ORM_USR_Account.Query.Search(
                    Connection,
                    Transaction,
                    new ORM_USR_Account.Query()
                {
                    USR_AccountID = securityTicket.AccountID
                })
                                         .FirstOrDefault();
                // create status Shipment Status history entry
                var statusHistoryCredited = new ORM_LOG_SHP_Shipment_StatusHistory();
                statusHistoryCredited.Creation_Timestamp                    = DateTime.Now;
                statusHistoryCredited.IsDeleted                             = false;
                statusHistoryCredited.LOG_SHP_Shipment_Header_RefID         = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                statusHistoryCredited.LOG_SHP_Shipment_Status_RefID         = returnedStatusId;
                statusHistoryCredited.LOG_SHP_Shipment_StatusHistoryID      = Guid.NewGuid();
                statusHistoryCredited.PerformedBy_BusinessParticipant_RefID =
                    performedByAccount == null
                    ? Guid.Empty
                    : performedByAccount.BusinessParticipant_RefID;
                statusHistoryCredited.Tenant_RefID = securityTicket.TenantID;
                var resultSave = statusHistoryCredited.Save(Connection, Transaction);
                if (resultSave.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    return(returnValue);
                }
                #endregion

                shipmentHeader.ShipmentType_RefID             = statusHistoryCredited.LOG_SHP_Shipment_StatusHistoryID;
                shipmentHeader.ShipmentHeader_ValueWithoutTax = updatedHeaderTotalValue;
                resultSave = shipmentHeader.Save(Connection, Transaction);
                if (resultSave.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    return(returnValue);
                }
                #endregion
            }

            #region Create New Positions
            foreach (var shipmentHeaderId in newShipmentHeaderGuids)
            {
                var positions = new P_L5RS_CSaRSPfH_0449();
                positions.Positions = newShipmentPositions.FindAll(nsp => nsp.ShipmentHeaderID == shipmentHeaderId).ToArray();
                var returnShipment = new P_L5RS_SRSHaP_0807a()
                {
                    CreateNewHeader   = false,
                    ShipmentHeader    = null,
                    ShipmentPositions = positions
                };
                var savePositionsInputParameter = new P_L5RS_SRSHaP_0807()
                {
                    ReturnShipments = new P_L5RS_SRSHaP_0807a[] { returnShipment }
                };
                var resultCreate = cls_Save_ReturnShipment_Header_and_Position.Invoke(Connection, Transaction, savePositionsInputParameter, securityTicket);
                if (resultCreate.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    return(returnValue);
                }
            }
            #endregion

            #region Save CreditNote Header and Positions
            var inputParameter = new P_L5RS_CNfRS_1119()
            {
                headerId                = Guid.Empty,
                headerNumber            = Parameter.CreditNoteHeaderNumber,
                headerValue             = Parameter.CreditNoteHeaderValue,
                currencyRef             = Parameter.CreditNoteHeaderCurrencyId,
                creditNoteDate          = Parameter.CreditNoteHeaderDate,
                returnShipmentPositions = shipmentPositionsToBeCredited.ToArray(),
                receiptPositions        = null
            };
            var resultCreditNote = cls_Save_CreditNote_for_ReturnShipment.Invoke(Connection, Transaction, inputParameter, securityTicket);
            if (resultCreditNote.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                return(returnValue);
            }
            #endregion

            returnValue.Status = FR_Status.Success;
            returnValue.Result.CreditNoteHeaderId = resultCreditNote.Result;

            return(returnValue);

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

            var param = new P_L3SO_GSaUERfPTIL_1153()
            {
                ProductTrackingInstanceIDList = Parameter.TracknigInstances.Select(i => i.ProductTrackingInstanceID).ToArray()
            };
            var shippingsAndActiveReservations = cls_Get_Shippings_and_ActiveReservations_for_ProductTrackingInstanceIDList.Invoke(Connection, Transaction, param, securityTicket).Result;

            var param2 = new P_L3SO_GARQfMCFPSH_1450()
            {
                ProductTrackingInstanceList = Parameter.TracknigInstances.Select(i => i.ProductTrackingInstanceID).ToArray()
            };
            var activeAndStartedReservations = cls_Get_ActiveReservedQuantities_for_ManuallyClearedForPickingShippmentHeaders.Invoke(Connection, Transaction, param2, securityTicket).Result;


            foreach (var trackingInstance in shippingsAndActiveReservations)
            {
                var inParam = Parameter.TracknigInstances.SingleOrDefault(i => i.ProductTrackingInstanceID == trackingInstance.LOG_ProductTrackingInstance_RefID);

                var activeAndStartedReservation = activeAndStartedReservations.SingleOrDefault(i => i.LOG_ProductTrackingInstance_RefID == trackingInstance.LOG_ProductTrackingInstance_RefID);
                var activeAndStartedQuantities  = (activeAndStartedReservation == null) ? 0 : activeAndStartedReservation.ReservedQuantityFromTrackingInstance;

                if (inParam != null && (inParam.CurrentQuantityOnTrackingInstance - activeAndStartedQuantities) < inParam.RemovedQuantityFromTrackingInstance)
                {
                    throw new Exception("Reservation can't be deleted because picking has been started.");
                }

                foreach (var item in trackingInstance.Reservations)
                {
                    #region ShipmentHeaders

                    var shipmentHeader = new ORM_LOG_SHP_Shipment_Header();
                    shipmentHeader.Load(Connection, Transaction, item.LOG_SHP_Shipment_HeaderID);
                    shipmentHeader.IsPartiallyReadyForPicking   = false;
                    shipmentHeader.IsReadyForPicking            = false;
                    shipmentHeader.IsManuallyCleared_ForPicking = false;
                    shipmentHeader.HasPickingStarted            = false;
                    shipmentHeader.Save(Connection, Transaction);

                    #endregion

                    #region Reservation

                    var reservation = new ORM_LOG_RSV_Reservation();
                    reservation.Load(Connection, Transaction, item.LOG_RSV_ReservationID);
                    reservation.IsDeleted = true;
                    reservation.Save(Connection, Transaction);

                    #endregion

                    #region Reservation Tracking Instance

                    var reservationTrackingInstance = new ORM_LOG_RSV_Reservation_TrackingInstance();
                    reservationTrackingInstance.Load(Connection, Transaction, item.LOG_RSV_Reservation_TrackingInstanceID);
                    reservationTrackingInstance.IsDeleted = true;
                    reservationTrackingInstance.Save(Connection, Transaction);

                    #endregion
                }
            }

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guids Execute(DbConnection Connection, DbTransaction Transaction, P_L5OS_ABL_1157 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var         returnValue = new FR_Guids();
            List <Guid> retVal      = new List <Guid>();

            Guid shippmentHeaderID = Guid.Empty;

            P_L5OS_GASFD_1234 param = new P_L5OS_GASFD_1234();
            param.HEC_DoctorID = Parameter.HEC_Doctor_RefID;
            var dateNow = DateTime.Now;
            param.ToDate   = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 23, 59, 59, 999);
            param.FormDate = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 0, 0, 0, 0);

            var res = cls_Get_ActiveShippmentForDoctorID.Invoke(Connection, Transaction, param, securityTicket).Result;

            if (res != null && res.Length > 0)
            {
                shippmentHeaderID = res[0].LOG_SHP_Shipment_HeaderID;
            }

            if (shippmentHeaderID == Guid.Empty)
            {
                ORM_LOG_SHP_Shipment_Header header = new ORM_LOG_SHP_Shipment_Header();
                header.IsShipped    = false;
                header.Tenant_RefID = securityTicket.TenantID;
                header.Save(Connection, Transaction);

                shippmentHeaderID = header.LOG_SHP_Shipment_HeaderID;
            }

            for (int i = 0; i < Parameter.Count; i++)
            {
                ORM_LOG_SHP_Shipment_Position logShippmentPosition = new ORM_LOG_SHP_Shipment_Position();
                logShippmentPosition.CMN_PRO_Product_RefID         = Parameter.CMN_PRO_ProductID;
                logShippmentPosition.LOG_SHP_Shipment_Header_RefID = shippmentHeaderID;
                logShippmentPosition.Save(Connection, Transaction);

                ORM_HEC_ShippingPosition_BarcodeLabel shippmentLabel = new ORM_HEC_ShippingPosition_BarcodeLabel();
                shippmentLabel.Doctor_RefID = Parameter.HEC_Doctor_RefID;
                shippmentLabel.LOG_SHP_Shipment_Position_RefID = logShippmentPosition.LOG_SHP_Shipment_PositionID;
                shippmentLabel.R_IsSubmission_Complete         = false;
                shippmentLabel.Tenant_RefID = securityTicket.TenantID;
                List <ORM_HEC_ShippingPosition_BarcodeLabel> positionLabels;
                String barcodeLabel = "";
                do
                {
                    barcodeLabel = RandomString.Generate(9);

                    var positionLabelsQuery = new ORM_HEC_ShippingPosition_BarcodeLabel.Query();
                    positionLabelsQuery.ShippingPosition_BarcodeLabel = barcodeLabel;
                    positionLabelsQuery.Tenant_RefID = securityTicket.TenantID;
                    positionLabelsQuery.IsDeleted    = false;
                    positionLabels = ORM_HEC_ShippingPosition_BarcodeLabel.Query.Search(Connection, Transaction, positionLabelsQuery);
                } while (positionLabels != null && positionLabels.Count != 0);

                shippmentLabel.ShippingPosition_BarcodeLabel = barcodeLabel;
                shippmentLabel.Save(Connection, Transaction);

                retVal.Add(shippmentLabel.HEC_ShippingPosition_BarcodeLabelID);
            }
            returnValue.Result = retVal.ToArray();
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PP_CSHS_1305 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            //Put your code here
            if (Parameter.LOG_SHP_Shipment_HeaderID == null || Parameter.LOG_SHP_Shipment_HeaderID == Guid.Empty)
            {
                return(null);
            }

            ORM_LOG_SHP_Shipment_Header shipmentHeader = new ORM_LOG_SHP_Shipment_Header();
            var shipmentHeaderResult = shipmentHeader.Load(Connection, Transaction, Parameter.LOG_SHP_Shipment_HeaderID);

            if (shipmentHeaderResult.Status != FR_Status.Success || shipmentHeader.LOG_SHP_Shipment_HeaderID == Guid.Empty)
            {
                return(null);
            }

            if (Parameter.IsReadyForPicking != null)
            {
                shipmentHeader.IsReadyForPicking = (Boolean)Parameter.IsReadyForPicking;

                var param = new P_L2SH_SSSH_1313();
                param.ShipmentHeaderID     = Parameter.LOG_SHP_Shipment_HeaderID;
                param.ShipmentHeaderStatus = EShipmentStatus.ReadyForPicking;

                cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);
            }
            if (Parameter.IsPartiallyReadyForPicking != null)
            {
                shipmentHeader.IsPartiallyReadyForPicking = (Boolean)Parameter.IsPartiallyReadyForPicking;

                var param = new P_L2SH_SSSH_1313();
                param.ShipmentHeaderID     = Parameter.LOG_SHP_Shipment_HeaderID;
                param.ShipmentHeaderStatus = EShipmentStatus.PartiallyReadyForPicking;

                cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);
            }
            if (Parameter.IsManuallyCleared_ForPicking != null)
            {
                shipmentHeader.IsManuallyCleared_ForPicking = (Boolean)Parameter.IsManuallyCleared_ForPicking;

                var param = new P_L2SH_SSSH_1313();
                param.ShipmentHeaderID     = Parameter.LOG_SHP_Shipment_HeaderID;
                param.ShipmentHeaderStatus = EShipmentStatus.ManuallyClearedForPicking;

                cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);
            }
            if (Parameter.HasPickingStarted != null)
            {
                shipmentHeader.HasPickingStarted = (Boolean)Parameter.HasPickingStarted;

                var param = new P_L2SH_SSSH_1313();
                param.ShipmentHeaderID     = Parameter.LOG_SHP_Shipment_HeaderID;
                param.ShipmentHeaderStatus = EShipmentStatus.PickingStarted;

                cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);
            }
            if (Parameter.HasPickingFinished != null)
            {
                shipmentHeader.HasPickingFinished = (Boolean)Parameter.HasPickingFinished;

                var param = new P_L2SH_SSSH_1313();
                param.ShipmentHeaderID     = Parameter.LOG_SHP_Shipment_HeaderID;
                param.ShipmentHeaderStatus = EShipmentStatus.PickingFinished;

                cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);
            }
            if (Parameter.IsBilled != null)
            {
                shipmentHeader.IsBilled = (Boolean)Parameter.IsBilled;

                var param = new P_L2SH_SSSH_1313();
                param.ShipmentHeaderID     = Parameter.LOG_SHP_Shipment_HeaderID;
                param.ShipmentHeaderStatus = EShipmentStatus.Billed;

                cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);
            }

            if (Parameter.IsShipped != null)
            {
                shipmentHeader.IsShipped = (Boolean)Parameter.IsShipped;

                var param = new P_L2SH_SSSH_1313();
                param.ShipmentHeaderID     = Parameter.LOG_SHP_Shipment_HeaderID;
                param.ShipmentHeaderStatus = EShipmentStatus.Shipped;

                cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);
            }

            if (Parameter.IsDeleted != null)
            {
                var param = new P_L2SH_SSSH_1313();
                param.ShipmentHeaderID     = Parameter.LOG_SHP_Shipment_HeaderID;
                param.ShipmentHeaderStatus = EShipmentStatus.Deleted;

                cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);
            }

            shipmentHeader.Save(Connection, Transaction);

            return(returnValue);

            #endregion UserCode
        }
Example #8
0
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L3SO_USHSaDARfSH_1054 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Bool();

            #region Reset Shipment Header

            var shipmentHeader = new ORM_LOG_SHP_Shipment_Header();
            shipmentHeader.Load(Connection, Transaction, Parameter.ShipmentHeaderID);

            if (shipmentHeader.IsShipped)
            {
                returnValue.Result = false;
                return(returnValue);
            }

            shipmentHeader.IsPartiallyReadyForPicking   = false;
            shipmentHeader.IsManuallyCleared_ForPicking = false;
            shipmentHeader.IsReadyForPicking            = false;
            shipmentHeader.HasPickingStarted            = false;
            shipmentHeader.Save(Connection, Transaction);

            #endregion

            #region Save EShipmentStatus.FlagsCleared

            var param = new P_L2SH_SSSH_1210();
            param.ShipmentHeaderID     = Parameter.ShipmentHeaderID;
            param.ShipmentHeaderStatus = EShipmentStatus.FlagsCleared;

            cls_Save_ShipmentStatusHistory.Invoke(Connection, Transaction, param, securityTicket);

            #endregion

            var positions = ORM_LOG_SHP_Shipment_Position.Query.Search(Connection, Transaction, new ORM_LOG_SHP_Shipment_Position.Query()
            {
                LOG_SHP_Shipment_Header_RefID = Parameter.ShipmentHeaderID,
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            });

            foreach (var position in positions)
            {
                var reservations = ORM_LOG_RSV_Reservation.Query.Search(Connection, Transaction, new ORM_LOG_RSV_Reservation.Query()
                {
                    LOG_SHP_Shipment_Position_RefID = position.LOG_SHP_Shipment_PositionID,
                    IsReservationExecuted           = false, //this is impossible, but I still want to keep better trace if somehow happen  @Pedja
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });

                foreach (var reservation in reservations)
                {
                    #region Delete Reservation

                    reservation.IsDeleted = true;
                    reservation.Save(Connection, Transaction);

                    #endregion

                    #region Delete Reservation TrackingInstance

                    var reservationTrackingInstance = ORM_LOG_RSV_Reservation_TrackingInstance.Query.SoftDelete(Connection, Transaction, new ORM_LOG_RSV_Reservation_TrackingInstance.Query()
                    {
                        LOG_RSV_Reservation_RefID = reservation.LOG_RSV_ReservationID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    });

                    #endregion
                }
            }

            returnValue.Result = true;
            return(returnValue);

            #endregion UserCode
        }