예제 #1
0
        protected static FR_L5AR_GPDfASP_1604 Execute(DbConnection Connection, DbTransaction Transaction, P_L5AR_GPDfASP_1604 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5AR_GPDfASP_1604();
            returnValue.Result = new L5AR_GPDfASP_1604();

            #region DefaultCurrency

            var dafaultCurrency = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result;

            #endregion

            #region Prices

            P_L5AR_GPaPfAaCID_1020 pricesParam = new P_L5AR_GPaPfAaCID_1020();
            pricesParam.ArticleID  = Parameter.ArticleID;
            pricesParam.CurrencyID = dafaultCurrency.CMN_CurrencyID;
            var pricesAndPricelists = cls_Get_Pricelists_and_Prices_for_Article_and_Currency_ID.Invoke(Connection, Transaction, pricesParam, securityTicket).Result;

            returnValue.Result.PricesAndPricelists = pricesAndPricelists;
            #endregion

            #region Articles

            var article = cls_Get_Product_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result.Where(a => a.CMN_PRO_ProductID == Parameter.ArticleID).Single();
            returnValue.Result.Product = article;

            #endregion

            #region Formulas

            var formulas = cls_Get_AllDynamicPricingFormulas_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;
            returnValue.Result.Formulas = formulas;

            #endregion

            #region Standard Prices

            var standardPricesParam = new P_L3PR_GSPfPIL_1645()
            {
                ProductIDList = new Guid[1] {
                    Parameter.ArticleID
                }
            };
            var standardprice = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, standardPricesParam, securityTicket).Result.SingleOrDefault();
            returnValue.Result.StandardPrices = standardprice;
            #endregion

            return(returnValue);

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

            #region Get Return Shipment Positions
            var returnShipmentPositions = cls_Get_ReturnShipmentPositions_for_PositionIDs.Invoke(Connection, Transaction, Parameter.SearchCriteria, securityTicket).Result;
            #endregion

            #region Get Articles
            var articleIDs = returnShipmentPositions.Select(rsp => rsp.CMN_PRO_Product_RefID).Distinct().ToArray <Guid>();

            var articles = new L3AR_GAfAL_0942[0];
            var prices   = new L3PR_GSPfPIL_1645[0];

            if (articleIDs.Length != 0)
            {
                var parameterArticles = new P_L3AR_GAfAL_0942
                {
                    ProductID_List = articleIDs
                };
                articles = cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction, parameterArticles, securityTicket).Result;

                var parameterPrices = new P_L3PR_GSPfPIL_1645
                {
                    ProductIDList = articleIDs
                };
                prices = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, parameterPrices, securityTicket).Result;
            }
            #endregion

            #region Set Return Value
            var returnElements = new List <L5RS_GRSPwAfP_1526>();
            foreach (var position in returnShipmentPositions)
            {
                var returnElement = new L5RS_GRSPwAfP_1526
                {
                    Article  = articles.FirstOrDefault(a => a.CMN_PRO_ProductID == position.CMN_PRO_Product_RefID),
                    Price    = prices.FirstOrDefault(a => a.ProductID == position.CMN_PRO_Product_RefID),
                    Position = position
                };
                returnElements.Add(returnElement);
            }
            returnValue.Result = returnElements.ToArray();
            #endregion

            return(returnValue);

            #endregion UserCode
        }
예제 #3
0
        protected static FR_L5CA_GPLfCD_1328 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_GPLfCD_1328 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            //Put your code here

            var returnValue = new FR_L5CA_GPLfCD_1328();
            returnValue.Result = new L5CA_GPLfCD_1328();

            #region DefaultCurrency

            var defaultCurrency = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result;

            #endregion

            #region Prices

            P_L3PR_GPaPfALaCID_1409 pricesParam = new P_L3PR_GPaPfALaCID_1409();
            pricesParam.ArticleID  = Parameter.ProductID;
            pricesParam.CurrencyID = defaultCurrency.CMN_CurrencyID;
            var pricesAndPricelists = cls_Get_Pricelists_and_Prices_for_ArticleList_and_Currency_ID.Invoke(Connection, Transaction, pricesParam, securityTicket).Result;

            returnValue.Result.PricesAndPricelists = pricesAndPricelists;
            #endregion

            #region Formulas

            var formulas = cls_Get_AllDynamicPricingFormulas_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;
            returnValue.Result.Formulas = formulas;

            #endregion

            #region Standard Prices

            var standardPricesParam = new P_L3PR_GSPfPIL_1645()
            {
                ProductIDList = Parameter.ProductID
            };
            var standardprice = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, standardPricesParam, securityTicket).Result;
            returnValue.Result.StandardPrices = standardprice;
            #endregion

            return(returnValue);

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

            List <L5PO_GOEDPwAD_1719> list = new List <L5PO_GOEDPwAD_1719>();

            var extraDemandProducts = cls_Get_Open_ExtraDemandProducts.Invoke(Connection, Transaction, securityTicket).Result;

            L3AR_GAfAL_0942[]   articles = new L3AR_GAfAL_0942[0];
            L3PR_GSPfPIL_1645[] prices   = new L3PR_GSPfPIL_1645[0];
            if (extraDemandProducts.Count() != 0)
            {
                var articleIds = extraDemandProducts.Select(x => x.Product_RefID).Distinct().ToArray();

                var articleParam = new P_L3AR_GAfAL_0942 {
                    ProductID_List = articleIds
                };
                articles = CL3_Articles.Atomic.Retrieval.cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction, articleParam, securityTicket).Result;

                var priceParam = new P_L3PR_GSPfPIL_1645 {
                    ProductIDList = articleIds
                };
                prices = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, priceParam, securityTicket).Result;
            }

            L5PO_GOEDPwAD_1719 listItem = null;
            foreach (var item in extraDemandProducts)
            {
                listItem = new L5PO_GOEDPwAD_1719();

                listItem.ExtraDemandProduct = item;
                listItem.Article            = articles.Single(x => x.CMN_PRO_ProductID == item.Product_RefID);
                listItem.Price = prices.Single(x => x.ProductID == item.Product_RefID);

                list.Add(listItem);
            }

            returnValue.Result = list.ToArray();

            return(returnValue);

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

            #region Get StockReceiptPositions Position

            var parameterPositions = new CL5_APOLogistic_StockReceipt.Atomic.Retrieval.P_L5SR_GSROfHA_1408();
            parameterPositions.ReceiptHeaderID = Parameter.ReceiptHeaderID;

            var positions = CL5_APOLogistic_StockReceipt.Atomic.Retrieval.cls_Get_StockReceiptsPositions_for_ReceiptHeaderID_Atomic
                            .Invoke(Connection, Transaction, parameterPositions, securityTicket).Result;

            #endregion

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

            #region Get Articles

            var paramArticles = new CL3_Articles.Atomic.Retrieval.P_L3AR_GAfAL_0942();
            paramArticles.ProductID_List = positions.Select(x => x.ReceiptPosition_Product_RefID).Distinct().ToArray();

            var articles = CL3_Articles.Atomic.Retrieval.cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction, paramArticles, securityTicket).Result;

            #endregion

            #region Get All StoragePlaces for TenantID
            var filterCriteria = new P_L3WH_GSPfFC_1504()
            {
                WarehouseGroupID    = null,
                WarehouseID         = null,
                AreaID              = null,
                RackID              = null,
                UseShelfIDList      = true,
                ShelfIDs            = positions.Select(i => i.Target_WRH_Shelf_RefID).Distinct().ToArray(),
                UseProductIDList    = false,
                ProductIDs          = new Guid[] { Guid.Empty },
                BottomShelfQuantity = null,
                TopShelfQuantity    = null,
                UseProductTrackingInstanceIDList = false,
                ProductTrackingInstanceIDs       = new Guid[] { Guid.Empty },
                StartExpirationDate = null,
                EndExpirationDate   = null
            };
            var allStoragePlacesForTenant = cls_Get_StoragePlaces_for_FilterCriteria.Invoke(
                Connection,
                Transaction,
                filterCriteria,
                securityTicket).Result;

            #endregion

            #region Get_StandardPrices_for_ProductIDList

            var priceParam = new P_L3PR_GSPfPIL_1645
            {
                ProductIDList = positions.Select(x => x.ReceiptPosition_Product_RefID).Distinct().ToArray()
            };

            var prices = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, priceParam, securityTicket).Result;

            #endregion

            var result = new List <L5SR_GSRPfH_1544>();

            foreach (var position in positions)
            {
                var retObj = new L5SR_GSRPfH_1544();
                retObj.OrderPosition  = position;
                retObj.Article        = articles.SingleOrDefault(x => x.CMN_PRO_ProductID == position.ReceiptPosition_Product_RefID);
                retObj.StandardPrices = prices.SingleOrDefault(x => x.ProductID == position.ReceiptPosition_Product_RefID);

                if (position.Target_WRH_Shelf_RefID != Guid.Empty)
                {
                    var storagePlace = allStoragePlacesForTenant.Where(i => i.LOG_WRH_ShelfID == position.Target_WRH_Shelf_RefID).FirstOrDefault();

                    if (storagePlace != null)
                    {
                        retObj.StoragePlace = String.Format("{0}-{1}-{2}-{3}",
                                                            storagePlace.WarehouseCoordinateCode,
                                                            storagePlace.AreaCoordinateCode,
                                                            storagePlace.RackCoordinateCode,
                                                            storagePlace.ShelfCoordinateCode);
                    }
                }
                result.Add(retObj);
            }

            returnValue.Result = result.ToArray();
            return(returnValue);

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

            #region Get_StandardPrices_for_ProductIDList

            var priceParam = new P_L3PR_GSPfPIL_1645
            {
                ProductIDList = Parameter.StockPositions.Select(x => x.ProductID).ToArray()
            };

            var prices = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, priceParam, securityTicket).Result;

            #endregion

            #region ProcurementHeader

            var procurementHeader = ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query.Search(Connection, Transaction,
                                                                                                    new ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query()
            {
                LOG_RCP_Receipt_Header_RefID = Parameter.ReceiptHeaderID,
                IsDeleted = false
            }).Single();

            #endregion

            foreach (var item in Parameter.StockPositions)
            {
                var pricePerUnit = prices.Where(i => i.ProductID == item.ProductID).Select(j => j.AbdaPrice).SingleOrDefault();

                #region Receipt Header and Positions

                // create new position
                var receiptPosition = new ORM_LOG_RCP_Receipt_Position();
                receiptPosition.LOG_RCP_Receipt_PositionID = Guid.NewGuid();
                receiptPosition.Creation_Timestamp         = DateTime.Now;
                receiptPosition.Tenant_RefID                  = securityTicket.TenantID;
                receiptPosition.ReceiptPositionITL            = receiptPosition.LOG_RCP_Receipt_PositionID.ToString();
                receiptPosition.Receipt_Header_RefID          = Parameter.ReceiptHeaderID;
                receiptPosition.ReceiptPosition_Product_RefID = item.ProductID;
                receiptPosition.TotalQuantityFreeOfCharge     = 0.0;
                receiptPosition.TotalQuantityTakenIntoStock   = 0.0;
                receiptPosition.ExpectedPositionPrice         = pricePerUnit;
                receiptPosition.Save(Connection, Transaction);

                #endregion

                #region Procurement Order Positions

                var product = CL1_CMN_PRO.ORM_CMN_PRO_Product.Query.Search(Connection, Transaction,
                                                                           new CL1_CMN_PRO.ORM_CMN_PRO_Product.Query()
                {
                    CMN_PRO_ProductID = item.ProductID,
                    IsDeleted         = false,
                    Tenant_RefID      = securityTicket.TenantID
                }).Single();

                var packageInfo = CL1_CMN_PRO_PAC.ORM_CMN_PRO_PAC_PackageInfo.Query.Search(Connection, Transaction,
                                                                                           new CL1_CMN_PRO_PAC.ORM_CMN_PRO_PAC_PackageInfo.Query()
                {
                    CMN_PRO_PAC_PackageInfoID = product.PackageInfo_RefID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).Single();

                var procurementPosition = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position()
                {
                    ORD_PRC_ProcurementOrder_PositionID = Guid.NewGuid(),
                    ProcurementOrder_Header_RefID       = procurementHeader.ORD_PRO_ProcurementOrder_Header_RefID,
                    CMN_PRO_Product_RefID         = item.ProductID,
                    Position_Unit_RefID           = packageInfo.PackageContent_MeasuredInUnit_RefID,
                    Position_Quantity             = item.OrderQuantity,
                    Position_ValuePerUnit         = pricePerUnit,
                    Position_ValueTotal           = pricePerUnit * (decimal)item.OrderQuantity,
                    IsBonusDelivery_WasNotOrdered = true,
                    Creation_Timestamp            = DateTime.Now,
                    Tenant_RefID = securityTicket.TenantID,
                };

                procurementPosition.Save(Connection, Transaction);

                var receiptToProcurementPosition = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptPosition_2_ProcurementOrderPosition()
                {
                    AssignmentID       = Guid.NewGuid(),
                    Creation_Timestamp = DateTime.Now,
                    Tenant_RefID       = securityTicket.TenantID,
                    ORD_PRO_ProcurementOrder_Position_RefID      = procurementPosition.ORD_PRC_ProcurementOrder_PositionID,
                    LOG_RCP_Receipt_Position_RefID               = receiptPosition.LOG_RCP_Receipt_PositionID,
                    ReceivedQuantityFromProcurementOrderPosition = item.OrderQuantity
                };
                receiptToProcurementPosition.Save(Connection, Transaction);

                #endregion

                #region Forwarding Instruction

                var forwardingInstruction = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position_ForwardingInstruction();
                var businessParticipant   = CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction,
                                                                                                     new CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query()
                {
                    IfTenant_Tenant_RefID = securityTicket.TenantID,
                    IsDeleted             = false
                }).Single();

                forwardingInstruction.ORD_PRC_ProcurementOrder_Position_ForwardingInstructionID = Guid.NewGuid();
                forwardingInstruction.Creation_Timestamp = DateTime.Now;
                forwardingInstruction.Tenant_RefID       = securityTicket.TenantID;
                forwardingInstruction.ProcurementOrder_Position_RefID     = procurementPosition.ORD_PRC_ProcurementOrder_PositionID;
                forwardingInstruction.ForwardTo_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                forwardingInstruction.QuantityToForward = 0;
                forwardingInstruction.Save(Connection, Transaction);

                #endregion
            }

            return(returnValue);

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

            var priceForAllProducts = new List <L3PR_GSPfPIL_1645>();
            var articles            = new List <L3AR_GAfAL_0942>();
            var productsBySupplier  = new List <L3SP_GPfSvSR_1524>();
            var productListId       = new List <Guid>();

            #region Filter by storage and quantity
            var filterCriteria = new P_L3WH_GSPfFC_1504()
            {
                WarehouseGroupID = Parameter.WarehouseStructure.Warehouse_GroupID,
                WarehouseID      = Parameter.WarehouseStructure.WarehouseID,
                AreaID           = Parameter.WarehouseStructure.AreaID,
                RackID           = Parameter.WarehouseStructure.RackID,
                UseShelfIDList   = Parameter.WarehouseStructure.ShelfID != null,
                ShelfIDs         = new Guid[] { Parameter.WarehouseStructure.ShelfID == null
                    ? Guid.Empty : new Guid(Parameter.WarehouseStructure.ShelfID.ToString()) },
                UseProductIDList    = false,
                ProductIDs          = new Guid[] { Guid.Empty },
                BottomShelfQuantity = (int?)Parameter.QuantityBottom,
                TopShelfQuantity    = (int?)Parameter.QuantityTop,
                UseProductTrackingInstanceIDList = false,
                ProductTrackingInstanceIDs       = new Guid[] { Guid.Empty },
                StartExpirationDate = null,
                EndExpirationDate   = null
            };
            var resultStoragePlaces = cls_Get_StoragePlaces_for_FilterCriteria.Invoke(
                Connection,
                Transaction,
                filterCriteria,
                securityTicket);
            if (resultStoragePlaces.Status != FR_Status.Success || resultStoragePlaces.Result == null || resultStoragePlaces.Result.Count() <= 0)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = new L6SC_GFDfSC_1424()
                {
                };
                return(returnValue);
            }
            var productsByStorage = resultStoragePlaces.Result.ToList();
            var productIDsByStorageAndQuantity = productsByStorage.Select(x => x.Product_RefID).Distinct().ToList();
            #endregion

            #region Filter by Supplier
            if (productIDsByStorageAndQuantity.Count != 0)
            {
                productsBySupplier = cls_Get_ProductIDs_for_SupplierID_via_StockReceipts.Invoke(Connection, Transaction,
                                                                                                new P_L3SP_GPfSvSR_1524
                {
                    ProvidingSupplier = Parameter.ProvidingSupplier
                },
                                                                                                securityTicket).Result.ToList();

                if (Parameter.ProvidingSupplier != null)
                {
                    var productIDsBySupplier = productsBySupplier.Select(x => x.ReceiptPosition_Product_RefID).ToList();
                    productListId = productIDsBySupplier.Intersect(productIDsByStorageAndQuantity).ToList();
                }
                else
                {
                    productListId = productIDsByStorageAndQuantity;
                }
            }
            #endregion

            #region Filter by date of shipment
            if (Parameter.DateOfShipmentFrom != null || Parameter.DateOfShipmentTo != null)
            {
                var dateOfShipmentParam = new P_L6SC_GDSfAL_1418();
                dateOfShipmentParam.ProductID_List = productListId.ToArray();
                dateOfShipmentParam.shipmentStatus = null;
                dateOfShipmentParam.DateFrom       = Parameter.DateOfShipmentFrom;
                var filterByDate = Get_DateOfShipment_for_ArticleList.Invoke(Connection, Transaction, dateOfShipmentParam, securityTicket).Result;
                productListId = filterByDate
                                .Where(x => x.GlobalPropertyMatchingID != EnumUtils.GetEnumDescription(EShipmentStatus.Shipped))
                                .Select(x => x.CMN_PRO_Product_RefID).Distinct().ToList();
            }
            #endregion

            #region Filter by Price
            if (productListId.Count != 0)
            {
                var  filteredPrice     = new List <L3PR_GSPfPIL_1645>();
                var  priceParams       = new P_L3PR_GSPfPIL_1645();
                bool isFilteredByPrice = false;
                priceParams.ProductIDList = productListId.ToArray();
                priceForAllProducts       = cls_Get_StandardPrices_for_ProductIDList.Invoke(
                    Connection,
                    Transaction,
                    priceParams,
                    securityTicket).Result.ToList();

                if (Parameter.Price.DefaultSalesPriceFrom != null || Parameter.Price.DefaultSalesPriceTo != null)
                {
                    filteredPrice = priceForAllProducts.Where(x =>
                                                              (Parameter.Price.DefaultSalesPriceFrom == null || x.SalesPrice >= Parameter.Price.DefaultSalesPriceFrom) &&
                                                              (Parameter.Price.DefaultSalesPriceTo == null || x.SalesPrice <= Parameter.Price.DefaultSalesPriceTo)).ToList();
                    isFilteredByPrice = true;
                }

                if (Parameter.Price.AverageProcurementPriceFrom != null || Parameter.Price.AverageProcurementPriceTo != null)
                {
                    if (isFilteredByPrice)
                    {
                        filteredPrice = filteredPrice.Where(x =>
                                                            (Parameter.Price.AverageProcurementPriceFrom == null || x.AverageProcurementPrice >= Parameter.Price.AverageProcurementPriceFrom) &&
                                                            (Parameter.Price.AverageProcurementPriceTo == null || x.AverageProcurementPrice <= Parameter.Price.AverageProcurementPriceTo)).ToList();
                    }
                    else
                    {
                        filteredPrice = priceForAllProducts.Where(x =>
                                                                  (Parameter.Price.AverageProcurementPriceFrom == null || x.AverageProcurementPrice >= Parameter.Price.AverageProcurementPriceFrom) &&
                                                                  (Parameter.Price.AverageProcurementPriceTo == null || x.AverageProcurementPrice <= Parameter.Price.AverageProcurementPriceTo)).ToList();
                        isFilteredByPrice = true;
                    }
                }

                if (isFilteredByPrice)
                {
                    var productListByPrice = filteredPrice.Select(x => x.ProductID).ToList();
                    productListId = productListId.Intersect(productListByPrice).ToList();
                }
            }
            #endregion

            #region Get_Articles_for_ArticleList add producerID
            if (productListId.Count != 0)
            {
                var getArticlesParams = new P_L3AR_GAfAL_0942();
                getArticlesParams.ProducingBusinessParticipant = Parameter.ProducingBusinessParticipant;
                getArticlesParams.ProductID_List = productListId.ToArray();
                getArticlesParams.ProductGroupID = Parameter.ProductGroupID;

                articles = cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction, getArticlesParams, securityTicket).Result.ToList();
            }
            #endregion

            #region filter by producer
            if ((articles.Count != 0) && (String.IsNullOrEmpty(Parameter.Producer) == false))
            {
                articles = articles.Where(x => x.ProducerName.Contains(Parameter.Producer)).ToList();
            }
            #endregion

            #region Get Msr for products

            var productIDs     = articles.Select(x => x.CMN_PRO_ProductID).ToArray();
            var msrForProducts = cls_Get_MSR_for_ProductIDList.Invoke(
                Connection,
                Transaction,
                new P_L3AS_GSMRfPL_1508 {
                ProductIDList = productIDs
            },
                securityTicket
                ).Result;

            #endregion

            if (productListId.Count != 0)
            {
                var returnItemList = new List <L6SC_GFDfSC_1424a>();
                foreach (var item in productsByStorage)
                {
                    var article           = articles.SingleOrDefault(x => x.CMN_PRO_ProductID == item.Product_RefID);
                    var productMst        = msrForProducts.SingleOrDefault(x => x.ProductID == item.Product_RefID);
                    var trackingInstances = cls_GetTrackingInstances_for_ShelfContent.Invoke(
                        Connection,
                        Transaction,
                        new P_L3TI_GTIfSC_1455()
                    {
                        ShelfContentID = item.LOG_WRH_Shelf_ContentID
                    },
                        securityTicket).Result;
                    if (article != null && trackingInstances != null && trackingInstances.Count() > 0)
                    {
                        var returnItem = new L6SC_GFDfSC_1424a();
                        returnItem.Storage          = productsByStorage.Single(x => x.LOG_WRH_Shelf_ContentID == item.LOG_WRH_Shelf_ContentID);
                        returnItem.Price            = priceForAllProducts.SingleOrDefault(x => x.ProductID == item.Product_RefID);
                        returnItem.Article          = article;
                        returnItem.Supplier         = productsBySupplier.Where(x => x.ReceiptPosition_Product_RefID == item.Product_RefID).ToArray();
                        returnItem.TrackingInstance = trackingInstances[0];
                        returnItem.MSR = (productMst != null) ? productMst.MSR : 0.0;
                        returnItemList.Add(returnItem);
                    }
                }
                returnValue.Result.FullGridData = returnItemList.ToArray();
            }

            return(returnValue);

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

            #region ArticleInfo

            var articleQuery = new ORM_CMN_PRO_Product.Query();
            articleQuery.CMN_PRO_ProductID = Parameter.ArticleID;
            articleQuery.Tenant_RefID      = securityTicket.TenantID;
            var articleFound = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, articleQuery).SingleOrDefault();

            returnValue.Result.PZN         = articleFound.Product_Number;
            returnValue.Result.ArticleName = articleFound.Product_Name;

            #endregion

            #region Standard Prices

            var standardPriceParam = new P_L3PR_GSPfPIL_1645()
            {
                ProductIDList = new Guid[1] {
                    Parameter.ArticleID
                }
            };

            var standardPrice = cls_Get_StandardPrices_for_ProductIDList.Invoke(
                Connection, Transaction, standardPriceParam, securityTicket).Result.SingleOrDefault();

            returnValue.Result.StandardPrices = standardPrice;

            #endregion

            #region Suppliers for Product

            var suppliersParam = new P_L5AA_GPSfPI_1248()
            {
                ProductID = Parameter.ArticleID
            };

            var SupplierProducts = cls_Get_ProductSuppliers_for_ProductID.Invoke(
                Connection, Transaction, suppliersParam, securityTicket).Result;

            returnValue.Result.ProductSuppliers = SupplierProducts;

            #endregion

            #region Predefined DiscountTypes

            var discountTypesParam = new P_L2DT_GDTfGPMIL_1546
            {
                GlobalPropertyMatchingID_List = EnumUtils.GetAllEnumDescriptions <EDiscountType>().ToArray()
            };
            returnValue.Result.DiscountTypes = cls_Get_DiscountTypes_for_GlobalPropertyMatchingID_List.Invoke(
                Connection, Transaction, discountTypesParam, securityTicket).Result;

            #endregion

            return(returnValue);

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

            #region Get Preloading Data

            #region Get StandardPrices for Products
            var priceParam = new P_L3PR_GSPfPIL_1645
            {
                ProductIDList = Parameter.Positions.Select(p => p.ProductId).ToArray()
            };
            var prices = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, priceParam, securityTicket).Result;
            #endregion
            #endregion

            #region Create Receipt Header
            var resultReceiptHeader = cls_Save_StockReceiptHeader.Invoke(
                Connection,
                Transaction,
                new P_L5SR_SRH_1545()
            {
                ReceiptHeaderID = Guid.Empty,
                SupplierID      = Parameter.SupplierID
            },
                securityTicket);
            if (resultReceiptHeader.Result == Guid.Empty)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = false;
                return(returnValue);
            }
            #endregion

            #region Create Receipt positions for Receipt header
            var receiptPositions = new List <P_L5RS_CNfRS_1119a>();
            foreach (var position in Parameter.Positions)
            {
                #region Get Preloading Data
                #region Get Performed By Account
                var performedByBusinessParticipant = new ORM_USR_Account();
                performedByBusinessParticipant.Load(Connection, Transaction, securityTicket.AccountID);
                if (performedByBusinessParticipant.BusinessParticipant_RefID == Guid.Empty)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = false;
                    return(returnValue);
                }
                #endregion
                #endregion

                #region Create new Receipt Position object
                var receiptPosition = new ORM_LOG_RCP_Receipt_Position();
                receiptPosition.LOG_RCP_Receipt_PositionID = Guid.NewGuid();
                receiptPosition.Creation_Timestamp         = DateTime.Now;
                receiptPosition.Tenant_RefID                  = securityTicket.TenantID;
                receiptPosition.ReceiptPositionITL            = receiptPosition.LOG_RCP_Receipt_PositionID.ToString();
                receiptPosition.Receipt_Header_RefID          = resultReceiptHeader.Result;
                receiptPosition.ReceiptPosition_Product_RefID = position.ProductId;
                receiptPosition.TotalQuantityFreeOfCharge     = 0.0;
                receiptPosition.TotalQuantityTakenIntoStock   = position.Quantity;
                receiptPosition.ExpectedPositionPrice         = Convert.ToDecimal(position.Quantity) * position.ValuePerUnit;
                receiptPosition.ExpectedPositionPrice         = prices.Where(i => i.ProductID == position.ProductId).Select(j => j.AbdaPrice).SingleOrDefault();
                #endregion

                #region Create new QualityControlItem object
                var qualityControlItem = new ORM_LOG_RCP_Receipt_Position_QualityControlItem();
                qualityControlItem.LOG_RCP_Receipt_Position_QualityControlItem = Guid.NewGuid();
                qualityControlItem.Tenant_RefID           = securityTicket.TenantID;
                qualityControlItem.Creation_Timestamp     = DateTime.Now;
                qualityControlItem.Receipt_Position_RefID = receiptPosition.LOG_RCP_Receipt_PositionID;
                qualityControlItem.Quantity               = position.Quantity;
                qualityControlItem.BatchNumber            = position.BatchNumber;
                qualityControlItem.ExpiryDate             = position.ExpiryDate;
                qualityControlItem.Target_WRH_Shelf_RefID = position.ShelfId;
                qualityControlItem.QualityControl_PerformedByBusinessParticipant_RefID = performedByBusinessParticipant.BusinessParticipant_RefID;
                qualityControlItem.ReceiptPositionCountedItemITL  = string.Empty;
                qualityControlItem.QualityControl_PerformedAtDate = DateTime.Now;
                #endregion

                #region Save objects
                var resultReceiptPosition = receiptPosition.Save(Connection, Transaction);
                if (resultReceiptPosition.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = false;
                    return(returnValue);
                }
                var resultQualityControlItem = qualityControlItem.Save(Connection, Transaction);
                if (resultQualityControlItem.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = false;
                    return(returnValue);
                }
                #endregion

                receiptPositions.Add(new P_L5RS_CNfRS_1119a()
                {
                    receiptPositionId = receiptPosition.LOG_RCP_Receipt_PositionID,
                    compesationValue  = qualityControlItem.Quantity * Convert.ToDouble(position.ValuePerUnit)
                });
            }
            #endregion

            #region Place articles on stock
            CL3_Warehouse.Complex.Manipulation.cls_StockReceipt_IntakeConfirmation.Invoke(
                Connection,
                Transaction,
                new P_L3WH_SRIC_1421()
            {
                ReceiptHeaderID    = resultReceiptHeader.Result,
                WithoutProcurement = true
            },
                securityTicket);
            #endregion

            #region Create CreditNote
            var resultCreditNote = cls_Save_CreditNote_for_ReturnShipment.Invoke(
                Connection,
                Transaction,
                new P_L5RS_CNfRS_1119()
            {
                headerId                = Parameter.CreditNoteHeaderID,
                headerValue             = Convert.ToDecimal(receiptPositions.Sum(rp => rp.compesationValue)),
                receiptPositions        = receiptPositions.ToArray(),
                returnShipmentPositions = null
            },
                securityTicket);
            if (resultCreditNote.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = false;
                return(returnValue);
            }
            #endregion

            returnValue.Result = true;
            returnValue.Status = FR_Status.Success;

            return(returnValue);

            #endregion UserCode
        }