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

            #region Get Shipment Positions

            P_L2SH_GSPfToSH_1334 positionsGetParam = new P_L2SH_GSPfToSH_1334();
            positionsGetParam.ShipmentHeaderID = Parameter.ShippmentHeaderID;
            var shipmentPositions = cls_Get_ShipmentPositions_for_Tenant_or_ShipmentHeaderID.Invoke(Connection, Transaction, positionsGetParam, securityTicket).Result.ToList();

            #endregion

            if (shipmentPositions.Count() == 0)
            {
                returnValue.Result = new L5SO_GSPwPaSfSH_1141[0];
                return(returnValue);
            }

            #region Get Articles For ShipmentPositions

            P_L3AR_GAfAL_0942 articlesGetParam = new P_L3AR_GAfAL_0942();
            articlesGetParam.ProductID_List = shipmentPositions.Select(i => i.CMN_PRO_Product_RefID).Distinct().ToArray();

            var articles = cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction, articlesGetParam, securityTicket).Result;

            #endregion

            #region Get Quantities on Shelf contents per product

            var articleIDs     = shipmentPositions.Select(x => x.CMN_PRO_Product_RefID).Distinct();
            var qntsPerProduct = new L3WH_GASCQfPL_1239[] { };
            if (articleIDs.Count() > 0)
            {
                var qntParam = new P_L3WH_GASCQfPL_1239 {
                    ProductIDList = articleIDs.ToArray()
                };
                qntsPerProduct = cls_Get_All_ShelfContent_Quantities_for_ProductListID.Invoke(Connection, Transaction, qntParam, securityTicket).Result;
            }

            #endregion

            #region Get ABDAPrices

            var abdaPricesParam = new P_L2PR_GPVfSC_1424()
            {
                SubscribedCatalogITL = EnumUtils.GetEnumDescription(EPublicCatalogs.ABDA)
            };

            var abdaPrices = cls_Get_PriceValues_for_SubscribedCatalogITL.Invoke(Connection, Transaction, abdaPricesParam, securityTicket).Result;

            #endregion

            #region cls_Get_AllGeneralAverageProcurementPrices_for_TenantID

            var avgProcPrice = cls_Get_AllGeneralAverageProcurementPrices_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;

            #endregion

            List <L5SO_GSPwPaSfSH_1141> listOfPositionsWithPrices = new List <L5SO_GSPwPaSfSH_1141>();

            foreach (var position in shipmentPositions)
            {
                var quantity = qntsPerProduct.Where(i => i.Product_RefID == position.CMN_PRO_Product_RefID).SingleOrDefault();
                if (quantity == null)
                {
                    quantity = new L3WH_GASCQfPL_1239()
                    {
                        Product_RefID          = position.CMN_PRO_Product_RefID,
                        Sum_Quantity_Current   = 0,
                        Sum_R_ReservedQuantity = 0,
                        Sum_R_FreeQuantity     = 0
                    };
                }

                var tempPositionWithPrice = new L5SO_GSPwPaSfSH_1141();
                tempPositionWithPrice.ShipmentPositionID = position.LOG_SHP_Shipment_PositionID;

                var reservationSum = ORM_LOG_RSV_Reservation.Query.Search(Connection, Transaction, new ORM_LOG_RSV_Reservation.Query()
                {
                    LOG_SHP_Shipment_Position_RefID = position.LOG_SHP_Shipment_PositionID,
                    IsDeleted             = false,
                    IsReservationExecuted = false
                }).Sum(x => x.ReservedQuantity);

                var correspodingCustomerOrderPosition = new ORM_ORD_CUO_CustomerOrder_Position();

                var positionArticle = articles.Where(ar => ar.CMN_PRO_ProductID == position.CMN_PRO_Product_RefID).Single();
                tempPositionWithPrice.Product_Number    = positionArticle.Product_Number;
                tempPositionWithPrice.Product_Name      = positionArticle.Product_Name;
                tempPositionWithPrice.UnitAmount        = positionArticle.UnitAmount;
                tempPositionWithPrice.UnitIsoCode       = positionArticle.UnitIsoCode;
                tempPositionWithPrice.DossageFormName   = positionArticle.DossageFormName;
                tempPositionWithPrice.Producer          = positionArticle.ProducerName;
                tempPositionWithPrice.CMN_PRO_ProductID = positionArticle.CMN_PRO_ProductID;

                tempPositionWithPrice.ReservedQuantity  = reservationSum;
                tempPositionWithPrice.QuantityToShip    = position.QuantityToShip;
                tempPositionWithPrice.QuantityInStock   = quantity.Sum_Quantity_Current;
                tempPositionWithPrice.QuantityAvailable = quantity.Sum_R_FreeQuantity;

                tempPositionWithPrice.ABDAPrice  = abdaPrices.Where(i => i.CMN_PRO_Product_RefID == position.CMN_PRO_Product_RefID).Select(j => j.PriceAmount).SingleOrDefault();
                tempPositionWithPrice.SalesPrice = position.ShipmentPosition_ValueWithoutTax;
                tempPositionWithPrice.AverageProcurementPrice = avgProcPrice.Where(i => i.Product_RefID == position.CMN_PRO_Product_RefID).Select(j => j.PriceValue_Amount).SingleOrDefault();
                tempPositionWithPrice.ShipmentPosition_PricePerUnitValueWithoutTax = position.ShipmentPosition_PricePerUnitValueWithoutTax;

                #region Product Replacement Allowed

                var assignmentToCustomerOrderPositionQuery = new ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition.Query();
                assignmentToCustomerOrderPositionQuery.LOG_SHP_Shipment_Position_RefID = position.LOG_SHP_Shipment_PositionID;
                assignmentToCustomerOrderPositionQuery.Tenant_RefID = securityTicket.TenantID;
                assignmentToCustomerOrderPositionQuery.IsDeleted    = false;
                var foundAssignment = ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition.Query.
                                      Search(Connection, Transaction, assignmentToCustomerOrderPositionQuery).SingleOrDefault();

                if (foundAssignment != null)
                {
                    correspodingCustomerOrderPosition.Load(Connection, Transaction, foundAssignment.ORD_CUO_CustomerOrder_Position_RefID);
                    tempPositionWithPrice.IsProductReplacementAllowed = correspodingCustomerOrderPosition.IsProductReplacementAllowed;
                }
                else
                {
                    tempPositionWithPrice.IsProductReplacementAllowed = true;
                }

                #endregion

                listOfPositionsWithPrices.Add(tempPositionWithPrice);
            }

            returnValue.Result = listOfPositionsWithPrices.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 2
0
        protected static FR_L5SO_GSHwBIfT_1533_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5SO_GSHwBIfT_1533 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5SO_GSHwBIfT_1533_Array();


            #region Retrieve Headers

            var param = new P_L5SO_GSOHfTID_1650()
            {
                IsPartiallyReadyForPicking   = Parameter.IsPartiallyReadyForPicking,
                IsReadyForPicking            = Parameter.IsReadyForPicking,
                HasPickingStarted            = Parameter.HasPickingStarted,
                HasPickingFinished           = Parameter.HasPickingFinished,
                IsManuallyCleared_ForPicking = Parameter.IsManuallyCleared_ForPicking,
                IsBilled  = Parameter.IsBilled,
                IsShipped = Parameter.IsShipped
            };

            var headers = cls_Get_ShippingOrderHeaders_for_TenantID.Invoke(Connection, Transaction, param, securityTicket).Result;

            var orgUnits = cls_Get_Shipment_OrganizationalUnits_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;

            #endregion

            var result = new List <L5SO_GSHwBIfT_1533>();

            foreach (var header in headers)
            {
                var notesCount = ORM_LOG_SHP_Shipment_Note.Query.Search(Connection, Transaction,
                                                                        new ORM_LOG_SHP_Shipment_Note.Query()
                {
                    Shipment_Header_RefID = header.LOG_SHP_Shipment_HeaderID,
                    IsDeleted             = false
                }).Count();

                var orgUnit = orgUnits.Where(i => i.LOG_SHP_Shipment_Header_RefID == header.LOG_SHP_Shipment_HeaderID).SingleOrDefault();

                if (orgUnit == null)
                {
                    orgUnit = new L5SO_GSOUfT_1607();
                }

                #region Get Shipment Positions

                List <Guid> ProductsInHeader = new List <Guid>();

                P_L2SH_GSPfToSH_1334 positionsGetParam = new P_L2SH_GSPfToSH_1334();
                positionsGetParam.ShipmentHeaderID = header.LOG_SHP_Shipment_HeaderID;
                var shipmentPositions = cls_Get_ShipmentPositions_for_Tenant_or_ShipmentHeaderID.Invoke(Connection, Transaction, positionsGetParam, securityTicket).Result.ToList();

                ProductsInHeader = shipmentPositions.Select(x => x.CMN_PRO_Product_RefID).Distinct().ToList();

                #endregion


                var item = new L5SO_GSHwBIfT_1533()
                {
                    LOG_SHP_Shipment_HeaderID      = header.LOG_SHP_Shipment_HeaderID,
                    ORD_CUO_CustomerOrder_HeaderID = header.ORD_CUO_CustomerOrder_HeaderID,
                    ShipmentHeader_Number          = header.ShipmentHeader_Number,
                    CustomerOrder_Number           = header.CustomerOrder_Number,
                    CustomerOrderCreationDate      = header.CustomerOrderCreationDate,
                    ShippingCreationDate           = header.ShippingCreationDate,
                    IsPartiallyReadyForPicking     = header.IsPartiallyReadyForPicking,
                    IsReadyForPicking            = header.IsReadyForPicking,
                    HasPickingStarted            = header.HasPickingStarted,
                    HasPickingFinished           = header.HasPickingFinished,
                    IsManuallyCleared_ForPicking = header.IsManuallyCleared_ForPicking,
                    IsBilled          = header.IsBilled,
                    IsShipped         = header.IsShipped,
                    CompanyName_Line1 = header.CompanyName_Line1,
                    NotesCount        = notesCount,
                    CMN_BPT_CTM_OrganizationalUnitID     = orgUnit.CMN_BPT_CTM_OrganizationalUnitID,
                    InternalOrganizationalUnitNumber     = orgUnit.InternalOrganizationalUnitNumber,
                    InternalOrganizationalUnitSimpleName = orgUnit.InternalOrganizationalUnitSimpleName,
                    ShipmentHeaderAddress = header.Shippipng_AddressUCD_RefID,
                    AllProductIDsInHeader = ProductsInHeader.ToArray()
                };

                result.Add(item);
            }

            returnValue.Result = result.ToArray();

            return(returnValue);

            #endregion UserCode
        }