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

            //Put your code here
            List <L5PP_GSHwDOfPfT_1013> retVal = new List <L5PP_GSHwDOfPfT_1013>();
            returnValue.Result = retVal.ToArray();

            #region Retrieve Headers

            // get all headers
            P_L2SH_GSHfT_1527 shipmentHeadersParam = new P_L2SH_GSHfT_1527();
            shipmentHeadersParam.IsShipped                = false;
            shipmentHeadersParam.ShipmentNumber           = Parameter.ShipmentNumber;
            shipmentHeadersParam.ShipmentCreationDateFrom = Parameter.ShipmentCreationDateFrom;
            shipmentHeadersParam.ShipmentCreationDateTo   = Parameter.ShipmentCreationDateTo;
            var headersResult = cls_Get_ShippmentHeaders_for_TenantID.Invoke(Connection, Transaction, shipmentHeadersParam, securityTicket).Result;

            if (headersResult == null)
            {
                return(returnValue);
            }

            // filter headers
            List <L2SH_GSHfT_1527> headers     = new List <L2SH_GSHfT_1527>();
            List <L2SH_GSHfT_1527> tempHeaders = new List <L2SH_GSHfT_1527>();
            if (Parameter.HasPositionsPartiallyToPick)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.IsPartiallyReadyForPicking && !i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.IsReadyForPicking)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.IsReadyForPicking && !i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.IsInPickingProcess)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.HasPickingStarted || i.HasPickingFinished || i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.NoPositionsFullyToPick)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i =>
                                                  !(i.IsPartiallyReadyForPicking && !i.IsManuallyCleared_ForPicking) &&
                                                  !(i.IsReadyForPicking && !i.IsManuallyCleared_ForPicking) &&
                                                  !(i.HasPickingStarted || i.HasPickingFinished || i.IsManuallyCleared_ForPicking)
                                                  ).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            #endregion

            L5PP_GSHwDOfPfT_1013 retValItem;
            foreach (var header in headers)
            {
                #region Getting data

                #region Shipment positions
                // get one shipment position for shipment header
                ORM_LOG_SHP_Shipment_Position.Query shipmentPositionsQuery = new ORM_LOG_SHP_Shipment_Position.Query();
                shipmentPositionsQuery.LOG_SHP_Shipment_Header_RefID = header.LOG_SHP_Shipment_HeaderID;
                shipmentPositionsQuery.Tenant_RefID = securityTicket.TenantID;
                shipmentPositionsQuery.IsDeleted    = false;
                List <ORM_LOG_SHP_Shipment_Position> shipmentPositions = ORM_LOG_SHP_Shipment_Position.Query.Search(Connection, Transaction, shipmentPositionsQuery);

                if (shipmentPositions == null || shipmentPositions.Count == 0)
                {
                    continue;
                }
                #endregion

                #region Distribution order position for shipment position
                // get one distribution order position for shipment position
                ORM_ORD_DIS_DistributionOrderPosition_2_ShipmentOrderPosition distributionOrder2ShipmentPosition = null;
                foreach (var shipmentPosition in shipmentPositions)
                {
                    ORM_ORD_DIS_DistributionOrderPosition_2_ShipmentOrderPosition.Query distributionOrder2ShipmentPositionQuery = new ORM_ORD_DIS_DistributionOrderPosition_2_ShipmentOrderPosition.Query();
                    distributionOrder2ShipmentPositionQuery.LOG_SHP_Shipment_Position_RefID = shipmentPosition.LOG_SHP_Shipment_PositionID;
                    distributionOrder2ShipmentPositionQuery.Tenant_RefID = securityTicket.TenantID;
                    distributionOrder2ShipmentPositionQuery.IsDeleted    = false;
                    distributionOrder2ShipmentPosition =
                        ORM_ORD_DIS_DistributionOrderPosition_2_ShipmentOrderPosition.Query
                        .Search(Connection, Transaction, distributionOrder2ShipmentPositionQuery).FirstOrDefault();

                    if (distributionOrder2ShipmentPosition != null)
                    {
                        break;
                    }
                }

                if (distributionOrder2ShipmentPosition == null)
                {
                    continue;
                }
                #endregion

                #region Disrtibution order position
                ORM_ORD_DIS_DistributionOrder_Position orm_DistributionOrderPosition = new ORM_ORD_DIS_DistributionOrder_Position();
                var distributionOrderPosition = orm_DistributionOrderPosition.Load(Connection, Transaction, distributionOrder2ShipmentPosition.ORD_DIS_DistributionOrder_Position_RefID);
                if (distributionOrderPosition.Status != FR_Status.Success || orm_DistributionOrderPosition.ORD_DIS_DistributionOrder_PositionID == Guid.Empty)
                {
                    continue;
                }
                #endregion

                #region Distribution order header
                // get sitribution order header for distribution order position
                ORM_ORD_DIS_DistributionOrder_Header.Query distributionOrderHeaderQuery = new ORM_ORD_DIS_DistributionOrder_Header.Query();
                distributionOrderHeaderQuery.ORD_DIS_DistributionOrder_HeaderID = orm_DistributionOrderPosition.DistributionOrder_Header_RefID;
                distributionOrderHeaderQuery.Tenant_RefID = securityTicket.TenantID;
                distributionOrderHeaderQuery.IsDeleted    = false;

                ORM_ORD_DIS_DistributionOrder_Header distributionOrderHeader = ORM_ORD_DIS_DistributionOrder_Header.Query.Search(Connection, Transaction, distributionOrderHeaderQuery).FirstOrDefault();
                if (distributionOrderHeader == null)
                {
                    continue;
                }

                // apply filter for distribution order header
                if (Parameter.OrderDateFrom != null)
                {
                    if (distributionOrderHeader.DistributionOrderDate < Parameter.OrderDateFrom)
                    {
                        continue;
                    }
                }

                if (Parameter.OrderDateTo != null)
                {
                    if (distributionOrderHeader.DistributionOrderDate > Parameter.OrderDateTo)
                    {
                        continue;
                    }
                }

                if (!String.IsNullOrEmpty(Parameter.DistributionOrderNumber))
                {
                    if (!distributionOrderHeader.DistributionOrderNumber.ToUpper().Contains(Parameter.DistributionOrderNumber.ToUpper()))
                    {
                        continue;
                    }
                }
                #endregion

                #region CostCenter
                // get cost center for distribution order header
                ORM_CMN_STR_CostCenter orm_CostCenter = new ORM_CMN_STR_CostCenter();
                var costCenter = orm_CostCenter.Load(Connection, Transaction, distributionOrderHeader.Charged_CostCenter_RefID);
                if (costCenter.Status != FR_Status.Success || orm_CostCenter.CMN_STR_CostCenterID == Guid.Empty)
                {
                    continue;
                }

                if (!String.IsNullOrEmpty(Parameter.CostCenter))
                {
                    // apply filter for cost center
                    if (!orm_CostCenter.Name.Contents.Any(i => i.Content.ToLower().Contains(Parameter.CostCenter)))
                    {
                        continue;
                    }
                }
                #endregion

                #region Office
                // get office for cost center
                ORM_CMN_STR_Office_2_CostCenter.Query office2CostCenterQuery = new ORM_CMN_STR_Office_2_CostCenter.Query();
                office2CostCenterQuery.CostCenter_RefID = orm_CostCenter.CMN_STR_CostCenterID;
                office2CostCenterQuery.Tenant_RefID     = securityTicket.TenantID;
                office2CostCenterQuery.IsDefault        = false;
                ORM_CMN_STR_Office_2_CostCenter office2CostCenter = ORM_CMN_STR_Office_2_CostCenter.Query.Search(Connection, Transaction, office2CostCenterQuery).FirstOrDefault();

                ORM_CMN_STR_Office orm_Office = null;
                if (office2CostCenter != null)
                {
                    orm_Office = new ORM_CMN_STR_Office();
                    var office = orm_Office.Load(Connection, Transaction, office2CostCenter.Office_RefID);
                    if (office.Status != FR_Status.Success || orm_Office.CMN_STR_OfficeID == Guid.Empty)
                    {
                        // there is no office with such ID
                        orm_Office = null;
                    }
                    else
                    {
                        // office loaded, apply filter
                        if (!String.IsNullOrEmpty(Parameter.OrganizationalUnit))
                        {
                            if (!(orm_Office.Office_InternalName.ToLower().Contains(Parameter.OrganizationalUnit) ||
                                  orm_Office.Office_Name.Contents.Any(i => i.Content.ToLower().Contains(Parameter.OrganizationalUnit))))
                            {
                                continue;
                            }
                        }
                    }
                }
                #endregion

                #endregion

                retValItem = new L5PP_GSHwDOfPfT_1013();
                retValItem.LOG_SHP_Shipment_HeaderID = header.LOG_SHP_Shipment_HeaderID;
                retValItem.ShipmentHeader_Number     = header.ShipmentHeader_Number;
                retValItem.IsShipped                    = header.IsShipped;
                retValItem.IsBilled                     = header.IsBilled;
                retValItem.IsReadyForPicking            = header.IsReadyForPicking;
                retValItem.IsPartiallyReadyForPicking   = header.IsPartiallyReadyForPicking;
                retValItem.HasPickingStarted            = header.HasPickingStarted;
                retValItem.HasPickingFinished           = header.HasPickingFinished;
                retValItem.IsManuallyCleared_ForPicking = header.IsManuallyCleared_ForPicking;
                retValItem.ShipmentCreationDate         = header.Creation_Timestamp;

                retValItem.ORD_DIS_DistributionOrder_HeaderID = distributionOrderHeader.ORD_DIS_DistributionOrder_HeaderID;
                retValItem.DistributionOrderNumber            = distributionOrderHeader.DistributionOrderNumber;
                retValItem.DistributionOrderDate = distributionOrderHeader.DistributionOrderDate;

                retValItem.CMN_STR_CostCenterID = orm_CostCenter.CMN_STR_CostCenterID;
                retValItem.CostCenterName       = orm_CostCenter.Name;

                retValItem.CMN_STR_OfficeID   = orm_Office != null ? orm_Office.CMN_STR_OfficeID : Guid.Empty;
                retValItem.OfficeInternalName = orm_Office != null ? orm_Office.Office_InternalName : String.Empty;

                retVal.Add(retValItem);
            }

            retVal = retVal.Skip(Parameter.From).Take(Parameter.Size).ToList();

            returnValue.Result = retVal.ToArray();

            return(returnValue);

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

            //Put your code here
            List <L5PP_GSHwCOfPfT_1348> retVal = new List <L5PP_GSHwCOfPfT_1348>();
            returnValue.Result = retVal.ToArray();

            #region Retrieve Headers

            // get all headers
            P_L2SH_GSHfT_1527 shipmentHeadersParam = new P_L2SH_GSHfT_1527();
            shipmentHeadersParam.IsShipped                = false;
            shipmentHeadersParam.ShipmentNumber           = Parameter.ShipmentNumber;
            shipmentHeadersParam.ShipmentCreationDateFrom = Parameter.ShipmentCreationDateFrom;
            shipmentHeadersParam.ShipmentCreationDateTo   = Parameter.ShipmentCreationDateTo;
            var headersResult = cls_Get_ShippmentHeaders_for_TenantID.Invoke(Connection, Transaction, shipmentHeadersParam, securityTicket).Result;

            if (headersResult == null)
            {
                return(returnValue);
            }

            // filter headers
            List <L2SH_GSHfT_1527> headers     = new List <L2SH_GSHfT_1527>();
            List <L2SH_GSHfT_1527> tempHeaders = new List <L2SH_GSHfT_1527>();
            if (Parameter.HasPositionsPartiallyToPick)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.IsPartiallyReadyForPicking && !i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.IsReadyForPicking)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.IsReadyForPicking && !i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.IsInPickingProcess)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.HasPickingStarted || i.HasPickingFinished || i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.NoPositionsFullyToPick)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i =>
                                                  !(i.IsPartiallyReadyForPicking && !i.IsManuallyCleared_ForPicking) &&
                                                  !(i.IsReadyForPicking && !i.IsManuallyCleared_ForPicking) &&
                                                  !(i.HasPickingStarted || i.HasPickingFinished || i.IsManuallyCleared_ForPicking)
                                                  ).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            #endregion

            L5PP_GSHwCOfPfT_1348 retValItem;
            foreach (var header in headers)
            {
                #region Getting data

                #region Shipment positions
                // get one shipment position for shipment header
                ORM_LOG_SHP_Shipment_Position.Query shipmentPositionsQuery = new ORM_LOG_SHP_Shipment_Position.Query();
                shipmentPositionsQuery.LOG_SHP_Shipment_Header_RefID = header.LOG_SHP_Shipment_HeaderID;
                shipmentPositionsQuery.Tenant_RefID = securityTicket.TenantID;
                shipmentPositionsQuery.IsDeleted    = false;
                List <ORM_LOG_SHP_Shipment_Position> shipmentPositions = ORM_LOG_SHP_Shipment_Position.Query.Search(Connection, Transaction, shipmentPositionsQuery);

                if (shipmentPositions == null || shipmentPositions.Count == 0)
                {
                    continue;
                }
                #endregion

                #region Customer order position for shipment position
                // get one customer order position for shipment position
                ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition customerOrder2ShipmentPosition = null;
                foreach (var shipmentPosition in shipmentPositions)
                {
                    ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition.Query customerOrder2ShipmentPositionQuery = new ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition.Query();
                    customerOrder2ShipmentPositionQuery.LOG_SHP_Shipment_Position_RefID = shipmentPosition.LOG_SHP_Shipment_PositionID;
                    customerOrder2ShipmentPositionQuery.Tenant_RefID = securityTicket.TenantID;
                    customerOrder2ShipmentPositionQuery.IsDeleted    = false;
                    customerOrder2ShipmentPosition =
                        ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition.Query
                        .Search(Connection, Transaction, customerOrder2ShipmentPositionQuery).FirstOrDefault();

                    if (customerOrder2ShipmentPosition != null)
                    {
                        break;
                    }
                }

                if (customerOrder2ShipmentPosition == null)
                {
                    continue;
                }
                #endregion

                #region Customer order position
                ORM_ORD_CUO_CustomerOrder_Position orm_CustomerOrderPosition = new ORM_ORD_CUO_CustomerOrder_Position();
                var distributionOrderPosition = orm_CustomerOrderPosition.Load(Connection, Transaction, customerOrder2ShipmentPosition.ORD_CUO_CustomerOrder_Position_RefID);
                if (distributionOrderPosition.Status != FR_Status.Success || orm_CustomerOrderPosition.ORD_CUO_CustomerOrder_PositionID == Guid.Empty)
                {
                    continue;
                }
                #endregion

                #region Customer order header
                // get customer order header for customer order position
                ORM_ORD_CUO_CustomerOrder_Header.Query customerOrderHeaderQuery = new ORM_ORD_CUO_CustomerOrder_Header.Query();
                customerOrderHeaderQuery.ORD_CUO_CustomerOrder_HeaderID = orm_CustomerOrderPosition.CustomerOrder_Header_RefID;
                customerOrderHeaderQuery.Tenant_RefID = securityTicket.TenantID;
                customerOrderHeaderQuery.IsDeleted    = false;
                if (!String.IsNullOrEmpty(Parameter.CustomerOrderNumber))
                {
                    customerOrderHeaderQuery.CustomerOrder_Number = Parameter.CustomerOrderNumber;
                }

                ORM_ORD_CUO_CustomerOrder_Header customerOrderHeader = ORM_ORD_CUO_CustomerOrder_Header.Query.Search(Connection, Transaction, customerOrderHeaderQuery).FirstOrDefault();
                if (customerOrderHeader == null)
                {
                    continue;
                }

                // apply filter for customer order header
                if (Parameter.OrderDateFrom != null)
                {
                    if (customerOrderHeader.CustomerOrder_Date < Parameter.OrderDateFrom)
                    {
                        continue;
                    }
                }

                if (Parameter.OrderDateTo != null)
                {
                    if (customerOrderHeader.CustomerOrder_Date > Parameter.OrderDateTo)
                    {
                        continue;
                    }
                }
                #endregion

                #region Customer
                ORM_CMN_BPT_BusinessParticipant.Query bussinerParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                bussinerParticipantQuery.CMN_BPT_BusinessParticipantID = customerOrderHeader.OrderingCustomer_BusinessParticipant_RefID;
                bussinerParticipantQuery.Tenant_RefID = securityTicket.TenantID;
                bussinerParticipantQuery.IsDeleted    = false;

                ORM_CMN_BPT_BusinessParticipant bussinerParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bussinerParticipantQuery).FirstOrDefault();

                if (bussinerParticipant == null)
                {
                    continue;
                }

                if (!String.IsNullOrEmpty(Parameter.Customer))
                {
                    if (!bussinerParticipant.DisplayName.ToUpper().Contains(Parameter.Customer.ToUpper()))
                    {
                        continue;
                    }
                }
                #endregion

                #endregion

                retValItem = new L5PP_GSHwCOfPfT_1348();
                retValItem.LOG_SHP_Shipment_HeaderID = header.LOG_SHP_Shipment_HeaderID;
                retValItem.ShipmentHeader_Number     = header.ShipmentHeader_Number;
                retValItem.IsShipped                    = header.IsShipped;
                retValItem.IsBilled                     = header.IsBilled;
                retValItem.IsReadyForPicking            = header.IsReadyForPicking;
                retValItem.IsPartiallyReadyForPicking   = header.IsPartiallyReadyForPicking;
                retValItem.HasPickingStarted            = header.HasPickingStarted;
                retValItem.HasPickingFinished           = header.HasPickingFinished;
                retValItem.IsManuallyCleared_ForPicking = header.IsManuallyCleared_ForPicking;
                retValItem.ShipmentCreationDate         = header.Creation_Timestamp;

                retValItem.ORD_CUO_CustomerOrder_HeaderID = customerOrderHeader.ORD_CUO_CustomerOrder_HeaderID;
                retValItem.CustomerOrderNumber            = customerOrderHeader.CustomerOrder_Number;
                retValItem.CustomerOrderDate = customerOrderHeader.CustomerOrder_Date;

                retValItem.Customer = bussinerParticipant.DisplayName;

                retVal.Add(retValItem);
            }

            retVal = retVal.Skip(Parameter.From).Take(Parameter.Size).ToList();

            returnValue.Result = retVal.ToArray();

            return(returnValue);

            #endregion UserCode
        }