Beispiel #1
0
        public virtual IEnumerable orders()
        {
            PXUIFieldAttribute.SetDisplayName <SOShipment.customerID>(Caches[typeof(SOShipment)], Messages.CustomerID);

            SOShipmentFilter filter = Filter.Current;
            int?action = GetActionIDByName(filter.Action);

            if (action == null)
            {
                yield break;
            }

            if (_ActionChanged)
            {
                Orders.Cache.Clear();
            }

            PXSelectBase cmd;

            switch (action)
            {
            case SOShipmentEntryActionsAttribute.CreateInvoice:
                cmd = new
                      PXSelectJoin <SOShipment,
                                    InnerJoin <INSite, On <SOShipment.FK.Site>,
                                               InnerJoinSingleTable <Customer, On <SOShipment.customerID, Equal <Customer.bAccountID> >,
                                                                     LeftJoin <Carrier, On <SOShipment.FK.Carrier> > > >,
                                    Where <SOShipment.confirmed, Equal <boolTrue>,
                                           And2 <Match <Customer, Current <AccessInfo.userName> >,
                                                 And2 <Match <INSite, Current <AccessInfo.userName> >,
                                                       And <Exists <
                                                                Select <SOOrderShipment,
                                                                        Where <SOOrderShipment.shipmentNbr, Equal <SOShipment.shipmentNbr>,
                                                                               And <SOOrderShipment.shipmentType, Equal <SOShipment.shipmentType>,
                                                                                    And <SOOrderShipment.invoiceNbr, IsNull,
                                                                                         And <SOOrderShipment.createARDoc, Equal <True> > > > > > > > > > > >(this);
                break;

            case SOShipmentEntryActionsAttribute.PostInvoiceToIN:
                cmd = new
                      PXSelectJoin <SOShipment,
                                    InnerJoin <INSite, On <SOShipment.FK.Site>,
                                               LeftJoinSingleTable <Customer, On <SOShipment.customerID, Equal <Customer.bAccountID> >,
                                                                    LeftJoin <Carrier, On <SOShipment.FK.Carrier> > > >,
                                    Where <SOShipment.confirmed, Equal <boolTrue>,
                                           And2 <Where <Customer.bAccountID, IsNull, Or <Match <Customer, Current <AccessInfo.userName> > > >,
                                                 And2 <Match <INSite, Current <AccessInfo.userName> >,
                                                       And <Exists <
                                                                Select <SOOrderShipment,
                                                                        Where <SOOrderShipment.shipmentNbr, Equal <SOShipment.shipmentNbr>,
                                                                               And <SOOrderShipment.shipmentType, Equal <SOShipment.shipmentType>,
                                                                                    And <SOOrderShipment.invtRefNbr, IsNull,
                                                                                         And <SOOrderShipment.createINDoc, Equal <True> > > > > > > > > > > >(this);
                break;

            case SOShipmentEntryActionsAttribute.CreateDropshipInvoice:
                cmd = new PXSelectJoinGroupBy <POReceipt,
                                               InnerJoin <SOOrderShipment, On <SOOrderShipment.shipmentNbr, Equal <POReceipt.receiptNbr>, And <SOOrderShipment.shipmentType, Equal <SOShipmentType.dropShip> > >,
                                                          InnerJoin <SOOrder, On <SOOrder.orderType, Equal <SOOrderShipment.orderType>, And <SOOrder.orderNbr, Equal <SOOrderShipment.orderNbr> > >,
                                                                     InnerJoin <SOOrderType, On <SOOrderType.orderType, Equal <SOOrderShipment.orderType> >,
                                                                                InnerJoinSingleTable <Customer, On <SOOrder.customerID, Equal <Customer.bAccountID> > > > > >,
                                               Where <POReceipt.released, Equal <True>,
                                                      //And2<Where<POReceiptLine.lineType, Equal<POLineType.goodsForDropShip>, Or<POReceiptLine.lineType, Equal<POLineType.nonStockForDropShip>>>,
                                                      And <SOOrderType.aRDocType, NotEqual <ARDocType.noUpdate>,
                                                           And <SOOrderShipment.invoiceNbr, IsNull,
                                                                And <Match <Customer, Current <AccessInfo.userName> > > > > >,
                                               Aggregate <GroupBy <POReceipt.receiptNbr,
                                                                   GroupBy <POReceipt.createdByID,
                                                                            GroupBy <POReceipt.lastModifiedByID,
                                                                                     GroupBy <POReceipt.released,
                                                                                              GroupBy <POReceipt.ownerID,
                                                                                                       GroupBy <POReceipt.hold> > > > > > > >(this);
                break;

            case SOShipmentEntryActionsAttribute.CancelReturn:
                cmd = new PXSelectJoinGroupBy <SOShipment,
                                               InnerJoin <INSite, On <SOShipment.FK.Site>,
                                                          LeftJoin <Carrier, On <SOShipment.FK.Carrier>,
                                                                    InnerJoin <SOOrderShipment, On <SOOrderShipment.shipmentType, Equal <SOShipment.shipmentType>, And <SOOrderShipment.shipmentNbr, Equal <SOShipment.shipmentNbr> > >,
                                                                               InnerJoin <SOOrder, On <SOOrder.orderType, Equal <SOOrderShipment.orderType>, And <SOOrder.orderNbr, Equal <SOOrderShipment.orderNbr> > >,
                                                                                          InnerJoinSingleTable <Customer, On <SOOrder.customerID, Equal <Customer.bAccountID> > > > > > >,
                                               Where <SOShipment.labelsPrinted, Equal <False>,
                                                      And2 <Match <Customer, Current <AccessInfo.userName> >,
                                                            And <Match <INSite, Current <AccessInfo.userName> > > > >,
                                               Aggregate <GroupBy <SOShipment.shipmentNbr,
                                                                   GroupBy <SOShipment.createdByID,
                                                                            GroupBy <SOShipment.lastModifiedByID,
                                                                                     GroupBy <SOShipment.confirmed,
                                                                                              GroupBy <SOShipment.ownerID,
                                                                                                       GroupBy <SOShipment.released,
                                                                                                                GroupBy <SOShipment.hold,
                                                                                                                         GroupBy <SOShipment.resedential,
                                                                                                                                  GroupBy <SOShipment.saturdayDelivery,
                                                                                                                                           GroupBy <SOShipment.groundCollect,
                                                                                                                                                    GroupBy <SOShipment.saturdayDelivery,
                                                                                                                                                             GroupBy <SOShipment.shippedViaCarrier,
                                                                                                                                                                      GroupBy <SOShipment.labelsPrinted> > > > > > > > > > > > > > >(this);
                break;

            default:
                cmd = new
                      PXSelectJoin <SOShipment,
                                    InnerJoin <INSite, On <SOShipment.FK.Site>,
                                               LeftJoinSingleTable <Customer, On <SOShipment.customerID, Equal <Customer.bAccountID> >,
                                                                    LeftJoin <Carrier, On <SOShipment.FK.Carrier> > > >,
                                    Where2 <Match <INSite, Current <AccessInfo.userName> >,
                                            And2 <Where <Customer.bAccountID, IsNull, Or <Match <Customer, Current <AccessInfo.userName> > > >,
                                                  And <Exists <
                                                           Select <SOOrderShipment,
                                                                   Where <SOOrderShipment.shipmentNbr, Equal <SOShipment.shipmentNbr>,
                                                                          And <SOOrderShipment.shipmentType, Equal <SOShipment.shipmentType> > > > > > > > >(this);
                break;
            }

            if (typeof(PXSelectBase <SOShipment>).IsAssignableFrom(cmd.GetType()))
            {
                ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.shipDate, LessEqual <Current <SOShipmentFilter.endDate> > > >();

                if (filter.SiteID != null)
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.siteID, Equal <Current <SOShipmentFilter.siteID> > > >();
                }

                if (!string.IsNullOrEmpty(filter.CarrierPluginID))
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <Carrier.carrierPluginID, Equal <Current <SOShipmentFilter.carrierPluginID> > > >();
                }

                if (!string.IsNullOrEmpty(filter.ShipVia))
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.shipVia, Equal <Current <SOShipmentFilter.shipVia> > > >();
                }

                if (filter.StartDate != null)
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.shipDate, GreaterEqual <Current <SOShipmentFilter.startDate> > > >();
                }

                if (filter.CustomerID != null)
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.customerID, Equal <Current <SOShipmentFilter.customerID> > > >();
                }

                if (action == SOShipmentEntryActionsAttribute.PrintLabels && filter.ShowPrinted == false)
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.labelsPrinted, Equal <False> > >();
                }

                if (action == SOShipmentEntryActionsAttribute.PrintPickList && filter.ShowPrinted == false)
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.pickListPrinted, Equal <False> > >();
                }

                if (filter.PackagingType == SOPackageType.ForFiltering.Manual)
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.isManualPackage, Equal <True> > >();
                }
                else if (filter.PackagingType == SOPackageType.ForFiltering.Auto)
                {
                    ((PXSelectBase <SOShipment>)cmd).WhereAnd <Where <SOShipment.isManualPackage, Equal <False> > >();
                }

                int startRow  = PXView.StartRow;
                int totalRows = 0;

                foreach (object res in ((PXSelectBase <SOShipment>)cmd).View.Select(null, null, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows))
                {
                    SOShipment shipment = PXResult.Unwrap <SOShipment>(res);
                    SOShipment cached   = (SOShipment)Orders.Cache.Locate(shipment);
                    if (cached != null)
                    {
                        shipment.Selected       = cached.Selected;
                        shipment.BillSeparately = cached.BillSeparately;
                    }
                    yield return(shipment);
                }
                PXView.StartRow = 0;
            }

            if (typeof(PXSelectBase <POReceipt>).IsAssignableFrom(cmd.GetType()))
            {
                ((PXSelectBase <POReceipt>)cmd).WhereAnd <Where <POReceipt.receiptDate, LessEqual <Current <SOShipmentFilter.endDate> > > >();

                if (filter.CustomerID != null)
                {
                    ((PXSelectBase <POReceipt>)cmd).WhereAnd <Where <SOOrderShipment.customerID, Equal <Current <SOShipmentFilter.customerID> > > >();
                }

                if (filter.ShipVia != null)
                {
                    ((PXSelectBase <POReceipt>)cmd).WhereAnd <Where <SOOrder.shipVia, Equal <Current <SOShipmentFilter.shipVia> > > >();
                }

                if (filter.CarrierPluginID != null)
                {
                    ((PXSelectBase <POReceipt>)cmd).Join <InnerJoin <Carrier, On <Carrier.carrierID, Equal <SOOrder.shipVia> > > >();
                    ((PXSelectBase <POReceipt>)cmd).WhereAnd <Where <Carrier.carrierPluginID, Equal <Current <SOShipmentFilter.carrierPluginID> > > >();
                }

                if (filter.StartDate != null)
                {
                    ((PXSelectBase <POReceipt>)cmd).WhereAnd <Where <POReceipt.receiptDate, GreaterEqual <Current <SOShipmentFilter.startDate> > > >();
                }

                foreach (PXResult <POReceipt, SOOrderShipment, SOOrder> res in ((PXSelectBase <POReceipt>)cmd).Select())
                {
                    SOShipment order  = res;
                    SOShipment cached = (SOShipment)Orders.Cache.Locate(order);

                    if (cached == null)
                    {
                        Orders.Cache.SetStatus(order, PXEntryStatus.Held);
                    }
                    else
                    {
                        order.Selected       = cached.Selected;
                        order.BillSeparately = cached.BillSeparately;
                    }
                    yield return(order);
                }
            }
            Orders.Cache.IsDirty = false;
        }