Ejemplo n.º 1
0
        public virtual List <PXResult <SOOrderShipment, SOOrder> > UpdateOrderShipments(ARRegister arDoc, HashSet <object> processed)
        {
            bool isCancellationInvoice = (arDoc.IsCancellation == true);
            bool isCorrectionInvoice   = (arDoc.IsCorrection == true);
            var  boundInvoice          = isCancellationInvoice
                                ? ARInvoice.PK.Find(this, arDoc.OrigDocType, arDoc.OrigRefNbr)
                                : arDoc;

            var orderShipments = this.Items.View.SelectMultiBound(new object[] { boundInvoice })
                                 .Cast <PXResult <SOOrderShipment, SOOrder> >()
                                 .ToList();

            foreach (var ordershipment in orderShipments)
            {
                SOOrderShipment copy = PXCache <SOOrderShipment> .CreateCopy(ordershipment);

                if (isCancellationInvoice)
                {
                    ARInvoice existingCorrectionInvoice = PXSelect <ARInvoice,
                                                                    Where <ARInvoice.origDocType, Equal <Current <ARInvoice.origDocType> >,
                                                                           And <ARInvoice.origRefNbr, Equal <Current <ARInvoice.origRefNbr> >,
                                                                                And <ARInvoice.isCorrection, Equal <True> > > > >
                                                          .SelectSingleBound(this, new[] { arDoc });

                    copy.InvoiceType = existingCorrectionInvoice?.DocType;
                    copy.InvoiceNbr  = existingCorrectionInvoice?.RefNbr;
                }
                copy.InvoiceReleased = !isCancellationInvoice;

                this.Items.Update(copy);

                if (!isCancellationInvoice && !isCorrectionInvoice)
                {
                    SOOrder     order = ordershipment;
                    SOOrderType otype = SOOrderType.PK.Find(this, order.OrderType);
                    if ((order.Completed == true || otype.RequireShipping == false) && order.BilledCntr <= 1 && order.ShipmentCntr <= order.BilledCntr + order.ReleasedCntr)
                    {
                        foreach (SOAdjust adj in this.Adjustments.Select(order.OrderType, order.OrderNbr))
                        {
                            SOAdjust adjcopy = PXCache <SOAdjust> .CreateCopy(adj);

                            adjcopy.CuryAdjdAmt = 0m;
                            adjcopy.CuryAdjgAmt = 0m;
                            adjcopy.AdjAmt      = 0m;
                            this.Adjustments.Update(adjcopy);
                        }
                    }
                }
                processed.Add(arDoc);
            }
            return(orderShipments);
        }
Ejemplo n.º 2
0
        public static void SetSupportsApproval(PXGraph sender, SOOrderType row)
        {
            if (row == null)
            {
                return;
            }

            using (new PXConnectionScope())
            {
                PXView view = new PXView(sender, true, SupportsApprovalSelect);
                var    r    = view.SelectSingle(row.Behavior);
                row.SupportsApproval = r != null;
            }
        }
Ejemplo n.º 3
0
        public virtual void CompleteSOLinesAndSplits(ARRegister ardoc, List <PXResult <SOOrderShipment, SOOrder> > orderShipments)
        {
            if (ardoc.IsCancellation == true || ardoc.IsCorrection == true)
            {
                return;
            }

            foreach (PXResult <SOOrderShipment, SOOrder> orderShipment in orderShipments)
            {
                SOOrder     order     = orderShipment;
                SOOrderType orderType = SOOrderType.PK.Find(this, order.OrderType);
                if (orderType.RequireShipping == false)
                {
                    PXDatabase.Update <SOLine>(
                        new PXDataFieldAssign <SOLine.completed>(true),
                        new PXDataFieldRestrict <SOLine.completed>(false),
                        new PXDataFieldRestrict <SOLine.orderType>(PXDbType.VarChar, 2, order.OrderType, PXComp.EQ),
                        new PXDataFieldRestrict <SOLine.orderNbr>(PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ));
                    PXDatabase.Update <SOLineSplit>(
                        new PXDataFieldAssign <SOLineSplit.completed>(true),
                        new PXDataFieldRestrict <SOLineSplit.completed>(false),
                        new PXDataFieldRestrict <SOLineSplit.orderType>(PXDbType.VarChar, 2, order.OrderType, PXComp.EQ),
                        new PXDataFieldRestrict <SOLineSplit.orderNbr>(PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ));
                }
            }
            PXUpdateJoin <
                Set <SOLine.completed, True>,
                SOLine,
                InnerJoin <ARTran, On <ARTran.sOOrderType, Equal <SOLine.orderType>,
                                       And <ARTran.sOOrderNbr, Equal <SOLine.orderNbr>,
                                            And <ARTran.sOOrderLineNbr, Equal <SOLine.lineNbr> > > > >,
                Where <SOLine.lineType, Equal <SOLineType.miscCharge>,
                       And <SOLine.completed, Equal <False>,
                            And <ARTran.tranType, Equal <Required <ARTran.tranType> >,
                                 And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > > >
            .Update(this,
                    ardoc.DocType,
                    ardoc.RefNbr);
        }
Ejemplo n.º 4
0
        protected GetTaxRequest BuildGetTaxRequestWithFRTCate <TLineAmt, TLineQty, TDocDiscount>(SOOrder order, string docCode, string debugMethodName)
            where TLineAmt : IBqlField
            where TLineQty : IBqlField
            where TDocDiscount : IBqlField
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Debug.Indent();

            if (order == null)
            {
                throw new PXArgumentException(nameof(order));
            }

            Customer cust = (Customer)Base.customer.View.SelectSingleBound(new object[] { order });
            Location loc  = (Location)Base.location.View.SelectSingleBound(new object[] { order });

            IAddressBase fromAddress = GetFromAddress(order);
            IAddressBase toAddress   = GetToAddress(order);

            Debug.Print($"{DateTime.Now.TimeOfDay} Select Customer, Location, Addresses in {sw.ElapsedMilliseconds} millisec");

            if (fromAddress == null)
            {
                throw new PXException(Messages.FailedGetFromAddressSO);
            }

            if (toAddress == null)
            {
                throw new PXException(Messages.FailedGetToAddressSO);
            }

            GetTaxRequest request = new GetTaxRequest();

            request.CompanyCode        = Base1.CompanyCodeFromBranch(order.TaxZoneID, order.BranchID);
            request.CurrencyCode       = order.CuryID;
            request.CustomerCode       = cust.AcctCD;
            request.TaxRegistrationID  = loc?.TaxRegistrationID;
            request.OriginAddress      = AddressConverter.ConvertTaxAddress(fromAddress);
            request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress);
            request.DocCode            = docCode;
            request.DocDate            = order.OrderDate.GetValueOrDefault();
            request.LocationCode       = GetExternalTaxProviderLocationCode <SOLine, SOLine.FK.Order.SameAsCurrent, SOLine.siteID>(order);

            Sign docSign = Sign.Plus;

            request.CustomerUsageType = order.AvalaraCustomerUsageType;

            if (!string.IsNullOrEmpty(order.ExternalTaxExemptionNumber))
            {
                request.ExemptionNo = order.ExternalTaxExemptionNumber;
            }

            SOOrderType orderType = (SOOrderType)Base.soordertype.View.SelectSingleBound(new object[] { order });

            if (orderType.DefaultOperation == SOOperation.Receipt)
            {
                request.DocType = TaxDocumentType.ReturnOrder;
                docSign         = Sign.Minus;
            }
            else
            {
                request.DocType = TaxDocumentType.SalesOrder;
            }

            PXSelectBase <SOLine> select = new PXSelectJoin <SOLine, LeftJoin <InventoryItem, On <SOLine.FK.InventoryItem>,
                                                                               LeftJoin <Account, On <Account.accountID, Equal <SOLine.salesAcctID> > > >,
                                                             Where <SOLine.orderType, Equal <Current <SOOrder.orderType> >,
                                                                    And <SOLine.orderNbr, Equal <Current <SOOrder.orderNbr> > > >,
                                                             OrderBy <Asc <SOLine.orderType,
                                                                           Asc <SOLine.orderNbr,
                                                                                Asc <SOLine.lineNbr> > > > >(Base);

            PXCache documentCache = Base.Caches[typeof(SOOrder)];

            request.Discount = (documentCache.GetValue <TDocDiscount>(order) as decimal?) ?? 0m;

            Stopwatch sw2 = new Stopwatch();

            sw2.Start();

            // Add additional condition to skip the calculation including the freight amount. Per YJ's request.
            if (order.CuryFreightTot > 0 && !string.IsNullOrEmpty(order.FreightTaxCategoryID))
            {
                var line = new TaxCartItem();
                line.Index              = short.MinValue;
                line.Quantity           = 1;
                line.UOM                = "EA";
                line.Amount             = docSign * order.CuryFreightTot.GetValueOrDefault();
                line.Description        = PXMessages.LocalizeNoPrefix(Messages.FreightDesc);
                line.DestinationAddress = request.DestinationAddress;
                line.OriginAddress      = request.OriginAddress;
                line.ItemCode           = "N/A";
                line.Discounted         = false;
                line.TaxCode            = order.FreightTaxCategoryID;

                request.CartItems.Add(line);
            }

            PXCache lineCache = Base.Caches[typeof(SOLine)];

            foreach (PXResult <SOLine, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order }))
            {
                SOLine        tran             = (SOLine)res;
                InventoryItem item             = (InventoryItem)res;
                Account       salesAccount     = (Account)res;
                bool          lineIsDiscounted = request.Discount > 0m &&
                                                 ((tran.DocumentDiscountRate ?? 1m) != 1m || (tran.GroupDiscountRate ?? 1m) != 1m);

                var line = new TaxCartItem();
                line.Index = tran.LineNbr ?? 0;

                decimal lineAmount = (lineCache.GetValue <TLineAmt>(tran) as decimal?) ?? 0m;
                decimal lineQty    = (lineCache.GetValue <TLineQty>(tran) as decimal?) ?? 0m;

                line.Amount = orderType.DefaultOperation != tran.Operation
                                        ? Sign.Minus * docSign * lineAmount
                                        : docSign * lineAmount;

                line.Description        = tran.TranDesc;
                line.DestinationAddress = AddressConverter.ConvertTaxAddress(Base1.GetToAddress(order, tran));
                line.OriginAddress      = AddressConverter.ConvertTaxAddress(Base1.GetFromAddress(order, tran));
                line.ItemCode           = item.InventoryCD;
                line.Quantity           = Math.Abs(lineQty);
                line.UOM        = tran.UOM;
                line.Discounted = lineIsDiscounted;
                line.RevAcct    = salesAccount.AccountCD;

                line.TaxCode           = tran.TaxCategoryID;
                line.CustomerUsageType = tran.AvalaraCustomerUsageType;

                if (tran.Operation == SOOperation.Receipt && tran.InvoiceDate != null)
                {
                    line.TaxOverride.Reason          = Messages.ReturnReason;
                    line.TaxOverride.TaxDate         = tran.InvoiceDate.Value;
                    line.TaxOverride.TaxOverrideType = TaxOverrideType.TaxDate;
                }

                request.CartItems.Add(line);
            }

            sw2.Stop();
            Debug.Print($"{DateTime.Now.TimeOfDay} Select detail lines in {sw2.ElapsedMilliseconds} millisec.");

            Debug.Unindent();
            sw.Stop();
            Debug.Print($"{DateTime.Now.TimeOfDay} {debugMethodName}() in {sw.ElapsedMilliseconds} millisec.");

            return(request);
        }
Ejemplo n.º 5
0
        public virtual void IntegrityCheckProc(INItemSiteSummary itemsite, string minPeriod, bool replanBackorders)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (INItemPlan p in PXSelectReadonly2 <INItemPlan, LeftJoin <Note, On <Note.noteID, Equal <INItemPlan.refNoteID> > >, Where <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <Note.noteID, IsNull> > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, p.PlanID, PXComp.EQ));
                    }

                    foreach (INItemPlan p in PXSelectReadonly2 <INItemPlan,
                                                                InnerJoin <INRegister, On <INRegister.noteID, Equal <INItemPlan.refNoteID>, And <INRegister.siteID, Equal <INItemPlan.siteID> > > >,
                                                                Where <INRegister.docType, Equal <INDocType.transfer>,
                                                                       And <INRegister.released, Equal <boolTrue>,
                                                                            And <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >,
                                                                                 And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> > > > > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, p.PlanID, PXComp.EQ));
                    }

                    foreach (PXResult <INTranSplit, INRegister, INSite, INItemSite> res in PXSelectJoin <INTranSplit,
                                                                                                         InnerJoin <INRegister, On <INRegister.docType, Equal <INTranSplit.docType>, And <INRegister.refNbr, Equal <INTranSplit.refNbr> > >,
                                                                                                                    InnerJoin <INSite, On <INSite.siteID, Equal <INRegister.toSiteID> >,
                                                                                                                               LeftJoin <INItemSite, On <INItemSite.inventoryID, Equal <INTranSplit.inventoryID>, And <INItemSite.siteID, Equal <INRegister.toSiteID> > >,
                                                                                                                                         LeftJoin <INTran, On <INTran.origTranType, Equal <INTranSplit.tranType>, And <INTran.origRefNbr, Equal <INTranSplit.refNbr>, And <INTran.origLineNbr, Equal <INTranSplit.lineNbr> > > >,
                                                                                                                                                   LeftJoin <INItemPlan, On <INItemPlan.planID, Equal <INTranSplit.planID> > > > > > >,
                                                                                                         Where <INRegister.docType, Equal <INDocType.transfer>,
                                                                                                                And2 <Where <INRegister.released, Equal <boolTrue>, And <INTranSplit.released, Equal <boolTrue>,
                                                                                                                                                                         Or <INRegister.released, Equal <boolFalse> > > >,
                                                                                                                      And <INTranSplit.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >,
                                                                                                                           And <INTranSplit.siteID, Equal <Current <INItemSiteSummary.siteID> >,
                                                                                                                                And <INTranSplit.invtMult, Equal <shortMinus1>,
                                                                                                                                     And <INItemPlan.planID, IsNull,
                                                                                                                                          And <INTran.refNbr, IsNull> > > > > > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        INTranSplit split = res;
                        INRegister  doc   = res;

                        if (split.TransferType == INTransferType.OneStep && doc.Released == true)
                        {
                            if (doc.TransferType == INTransferType.OneStep)
                            {
                                doc.TransferType = INTransferType.TwoStep;
                                Caches[typeof(INRegister)].Update(doc);
                            }
                            split.TransferType = INTransferType.TwoStep;
                        }
                        INItemPlan plan = INItemPlanIDAttribute.DefaultValues(this.Caches[typeof(INTranSplit)], res);
                        if (plan.LocationID == null)
                        {
                            plan.LocationID = ((INItemSite)res).DfltReceiptLocationID ?? ((INSite)res).ReceiptLocationID;
                        }

                        plan = (INItemPlan)this.Caches[typeof(INItemPlan)].Insert(plan);

                        split.PlanID = plan.PlanID;
                        Caches[typeof(INTranSplit)].SetStatus(split, PXEntryStatus.Updated);
                    }


                    PXDatabase.Update <INSiteStatus>(
                        new PXDataFieldRestrict <INSiteStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldRestrict <INSiteStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                        new PXDataFieldAssign <INSiteStatus.qtyAvail>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyHardAvail>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyNotAvail>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINIssues>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyInTransit>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINReplaned>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOBooked>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOShipped>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOShipping>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOFixed>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySODropShip>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m)
                        );

                    PXDatabase.Update <INLocationStatus>(
                        new PXDataFieldRestrict <INLocationStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldRestrict <INLocationStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                        new PXDataFieldAssign <INLocationStatus.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INLocationStatus.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INLocationStatus.qtyINIssues>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyINReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyInTransit>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOBooked>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOShipped>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOShipping>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOFixed>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySODropShip>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m)
                        );

                    PXDatabase.Update <INLotSerialStatus>(
                        new PXDataFieldRestrict <INLotSerialStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldRestrict <INLotSerialStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                        new PXDataFieldAssign <INLotSerialStatus.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INLotSerialStatus.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INLotSerialStatus.qtyINIssues>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyINReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyInTransit>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOBooked>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOShipped>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOShipping>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOFixed>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySODropShip>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m)

                        );

                    PXDatabase.Update <INItemLotSerial>(
                        new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldAssign("QtyAvail", PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign("QtyHardAvail", PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign("QtyINTransit", PXDbType.Decimal, 0m)
                        );

                    PXDatabase.Update <INSiteLotSerial>(
                        new PXDataFieldRestrict <INSiteLotSerial.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldRestrict <INSiteLotSerial.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                        new PXDataFieldAssign <INSiteLotSerial.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INSiteLotSerial.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INSiteLotSerial.qtyInTransit>(PXDbType.Decimal, 0m)
                        );


                    foreach (PXResult <ReadOnlyLocationStatus, INLocation> res in PXSelectJoinGroupBy <ReadOnlyLocationStatus, InnerJoin <INLocation, On <INLocation.locationID, Equal <ReadOnlyLocationStatus.locationID> > >, Where <ReadOnlyLocationStatus.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <ReadOnlyLocationStatus.siteID, Equal <Current <INItemSiteSummary.siteID> > > >, Aggregate <GroupBy <ReadOnlyLocationStatus.inventoryID, GroupBy <ReadOnlyLocationStatus.siteID, GroupBy <ReadOnlyLocationStatus.subItemID, GroupBy <INLocation.inclQtyAvail, Sum <ReadOnlyLocationStatus.qtyOnHand> > > > > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        SiteStatus status = new SiteStatus();
                        status.InventoryID = ((ReadOnlyLocationStatus)res).InventoryID;
                        status.SubItemID   = ((ReadOnlyLocationStatus)res).SubItemID;
                        status.SiteID      = ((ReadOnlyLocationStatus)res).SiteID;
                        status             = (SiteStatus)sitestatus.Cache.Insert(status);

                        if (((INLocation)res).InclQtyAvail == true)
                        {
                            status.QtyAvail     += ((ReadOnlyLocationStatus)res).QtyOnHand;
                            status.QtyHardAvail += ((ReadOnlyLocationStatus)res).QtyOnHand;
                        }
                        else
                        {
                            status.QtyNotAvail += ((ReadOnlyLocationStatus)res).QtyOnHand;
                        }
                    }

                    INPlanType plan60 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan60> > > .Select(this);

                    INPlanType plan61 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan61> > > .Select(this);

                    INPlanType plan70 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan70> > > .Select(this);

                    INPlanType plan74 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan74> > > .Select(this);

                    INPlanType plan76 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan76> > > .Select(this);

                    INPlanType plan42 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan42> > > .Select(this);

                    INPlanType plan44 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan44> > > .Select(this);

                    foreach (PXResult <INItemPlan, INPlanType, SOShipLineSplit, POReceiptLineSplit> res in PXSelectJoin <INItemPlan,
                                                                                                                         InnerJoin <INPlanType, On <INPlanType.planType, Equal <INItemPlan.planType> >,
                                                                                                                                    LeftJoin <SOShipLineSplit, On <SOShipLineSplit.planID, Equal <INItemPlan.planID> >,
                                                                                                                                              LeftJoin <POReceiptLineSplit, On <POReceiptLineSplit.planID, Equal <INItemPlan.planID> > > > >,
                                                                                                                         Where <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> > > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        INItemPlan         plan     = (INItemPlan)res;
                        INPlanType         plantype = (INPlanType)res;
                        INPlanType         locplantype;
                        SOShipLineSplit    sosplit = (SOShipLineSplit)res;
                        POReceiptLineSplit posplit = (POReceiptLineSplit)res;

                        if (plan.InventoryID != null &&
                            plan.SubItemID != null &&
                            plan.SiteID != null)
                        {
                            switch (plan.PlanType)
                            {
                            case INPlanConstants.Plan61:
                            case INPlanConstants.Plan63:
                                locplantype = plantype;

                                if (sosplit.ShipmentNbr != null)
                                {
                                    SOOrderType ordetype = PXSelect <SOOrderType, Where <SOOrderType.orderType, Equal <Current <SOShipLineSplit.origOrderType> > > > .SelectSingleBound(this, new object[] { sosplit });

                                    if (plan.OrigPlanType == null)
                                    {
                                        plan.OrigPlanType = ordetype.OrderPlanType;
                                    }

                                    if (plan.OrigPlanType == INPlanConstants.Plan60 && sosplit.IsComponentItem != true)
                                    {
                                        plantype = plantype - plan60;
                                    }

                                    if ((plan.OrigPlanType == INPlanConstants.Plan61 || plan.OrigPlanType == INPlanConstants.Plan63) && sosplit.IsComponentItem != true)
                                    {
                                        plantype = plantype - plan61;
                                    }
                                }

                                break;

                            case INPlanConstants.Plan71:
                            case INPlanConstants.Plan72:
                                locplantype = plantype;
                                if (posplit.ReceiptNbr == null)
                                {
                                    PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, plan.PlanID, PXComp.EQ));
                                    continue;
                                }
                                if (posplit.PONbr != null)
                                {
                                    plantype = plantype - plan70;
                                }
                                break;

                            case INPlanConstants.Plan77:
                                locplantype = plantype;
                                if (posplit.ReceiptNbr != null && posplit.PONbr != null)
                                {
                                    plantype = plantype - plan76;
                                }

                                break;

                            case INPlanConstants.Plan75:
                                locplantype = plantype;
                                if (posplit.ReceiptNbr != null && posplit.PONbr != null)
                                {
                                    plantype = plantype - plan74;
                                }
                                break;

                            case INPlanConstants.Plan43:
                            case INPlanConstants.Plan45:
                                if (plan.OrigPlanType == INPlanConstants.Plan44)
                                {
                                    plantype = plantype - plan44;
                                }

                                if (plan.OrigPlanType == INPlanConstants.Plan42)
                                {
                                    plantype = plantype - plan42;
                                }
                                locplantype = plantype;
                                break;

                            default:
                                locplantype = plantype;
                                break;
                            }

                            if (plan.LocationID != null)
                            {
                                LocationStatus item = INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <LocationStatus>(this, plan, locplantype, true);
                                INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteStatus>(this, plan, plantype, (bool)item.InclQtyAvail);
                                if (!string.IsNullOrEmpty(plan.LotSerialNbr))
                                {
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <LotSerialStatus>(this, plan, locplantype, true);
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <ItemLotSerial>(this, plan, locplantype, true);
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteLotSerial>(this, plan, locplantype, true);
                                }
                            }
                            else
                            {
                                INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteStatus>(this, plan, plantype, true);
                                if (!string.IsNullOrEmpty(plan.LotSerialNbr))
                                {
                                    //TODO: check if LotSerialNbr was allocated on OrigPlanType
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <ItemLotSerial>(this, plan, plantype, true);
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteLotSerial>(this, plan, plantype, true);
                                }
                            }
                        }
                    }
                    if (replanBackorders)
                    {
                        INReleaseProcess.ReplanBackOrders(this);
                        initemplan.Cache.Persist(PXDBOperation.Insert);
                        initemplan.Cache.Persist(PXDBOperation.Update);
                    }

                    Caches[typeof(INTranSplit)].Persist(PXDBOperation.Update);

                    sitestatus.Cache.Persist(PXDBOperation.Insert);
                    sitestatus.Cache.Persist(PXDBOperation.Update);

                    locationstatus.Cache.Persist(PXDBOperation.Insert);
                    locationstatus.Cache.Persist(PXDBOperation.Update);

                    lotserialstatus.Cache.Persist(PXDBOperation.Insert);
                    lotserialstatus.Cache.Persist(PXDBOperation.Update);

                    itemlotserial.Cache.Persist(PXDBOperation.Insert);
                    itemlotserial.Cache.Persist(PXDBOperation.Update);

                    sitelotserial.Cache.Persist(PXDBOperation.Insert);
                    sitelotserial.Cache.Persist(PXDBOperation.Update);

                    if (minPeriod != null)
                    {
                        FinPeriod period =
                            PXSelect <FinPeriod,
                                      Where <FinPeriod.finPeriodID, Equal <Required <FinPeriod.finPeriodID> > > >
                            .SelectWindowed(this, 0, 1, minPeriod);

                        if (period == null)
                        {
                            return;
                        }
                        DateTime startDate = (DateTime)period.StartDate;

                        PXDatabase.Delete <INItemCostHist>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("CostSiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE)
                            );

                        PXDatabase.Delete <INItemSalesHistD>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("QtyPlanSales", PXDbType.Decimal, 0m),
                            new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE)

                            );
                        PXDatabase.Delete <INItemCustSalesStats>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("LastDate", PXDbType.DateTime, 8, startDate, PXComp.GE));

                        PXDatabase.Update <INItemSalesHistD>(
                            new PXDataFieldAssign("QtyIssues", PXDbType.Decimal, 0m),
                            new PXDataFieldAssign("QtyExcluded", PXDbType.Decimal, 0m),
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE)
                            );

                        foreach (INLocation loc in PXSelectReadonly2 <INLocation, InnerJoin <INItemCostHist, On <INItemCostHist.costSiteID, Equal <INLocation.locationID> > >, Where <INLocation.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INItemCostHist.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> > > > > .SelectMultiBound(this, new object[] { itemsite }))
                        {
                            PXDatabase.Delete <INItemCostHist>(
                                new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                                new PXDataFieldRestrict("CostSiteID", PXDbType.Int, 4, loc.LocationID, PXComp.EQ),
                                new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE)
                                );
                        }

                        PXDatabase.Delete <INItemSiteHist>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE)
                            );

                        PXDatabase.Delete <INItemSiteHistD>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE)
                            );

                        INTran prev_tran = null;
                        foreach (PXResult <INTran, INTranSplit> res in PXSelectReadonly2 <INTran, InnerJoin <INTranSplit, On <INTranSplit.tranType, Equal <INTran.tranType>, And <INTranSplit.refNbr, Equal <INTran.refNbr>, And <INTranSplit.lineNbr, Equal <INTran.lineNbr> > > > >, Where <INTran.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INTran.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INTran.finPeriodID, GreaterEqual <Required <INTran.finPeriodID> >, And <INTran.released, Equal <boolTrue> > > > >, OrderBy <Asc <INTran.tranType, Asc <INTran.refNbr, Asc <INTran.lineNbr> > > > > .SelectMultiBound(this, new object[] { itemsite }, minPeriod))
                        {
                            INTran      tran  = res;
                            INTranSplit split = res;

                            if (!Caches[typeof(INTran)].ObjectsEqual(prev_tran, tran))
                            {
                                INReleaseProcess.UpdateSalesHistD(this, tran);
                                INReleaseProcess.UpdateCustSalesStats(this, tran);

                                prev_tran = tran;
                            }

                            if (split.BaseQty != 0m)
                            {
                                INReleaseProcess.UpdateSiteHist(this, res, split);
                                INReleaseProcess.UpdateSiteHistD(this, split);
                            }
                        }

                        foreach (PXResult <INTran, INTranCost> res in PXSelectReadonly2 <INTran, InnerJoin <INTranCost, On <INTranCost.tranType, Equal <INTran.tranType>, And <INTranCost.refNbr, Equal <INTran.refNbr>, And <INTranCost.lineNbr, Equal <INTran.lineNbr> > > > >, Where <INTran.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INTran.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INTranCost.finPeriodID, GreaterEqual <Required <INTran.finPeriodID> >, And <INTran.released, Equal <boolTrue> > > > > > .SelectMultiBound(this, new object[] { itemsite }, minPeriod))
                        {
                            INReleaseProcess.UpdateCostHist(this, (INTranCost)res, (INTran)res);
                        }

                        itemcosthist.Cache.Persist(PXDBOperation.Insert);
                        itemcosthist.Cache.Persist(PXDBOperation.Update);

                        itemsitehist.Cache.Persist(PXDBOperation.Insert);
                        itemsitehist.Cache.Persist(PXDBOperation.Update);

                        itemsitehistd.Cache.Persist(PXDBOperation.Insert);
                        itemsitehistd.Cache.Persist(PXDBOperation.Update);

                        itemsalehistd.Cache.Persist(PXDBOperation.Insert);
                        itemsalehistd.Cache.Persist(PXDBOperation.Update);

                        itemcustsalesstats.Cache.Persist(PXDBOperation.Insert);
                        itemcustsalesstats.Cache.Persist(PXDBOperation.Update);
                    }

                    ts.Complete();
                }

                sitestatus.Cache.Persisted(false);
                locationstatus.Cache.Persisted(false);
                lotserialstatus.Cache.Persisted(false);

                itemcosthist.Cache.Persisted(false);
                itemsitehist.Cache.Persisted(false);
                itemsitehistd.Cache.Persisted(false);
            }
        }
Ejemplo n.º 6
0
        public virtual void OrderAvailabilityCheck(PXCache sender, ARTran row, bool onPersist = false)
        {
            if (row.InvtMult == 0 || row.SOOrderType == null && row.SOOrderNbr == null && row.SOOrderLineNbr == null || row.Released == true)
            {
                return;
            }

            if (row.LineType == SOLineType.MiscCharge)
            {
                RaiseAvailabilityException(sender, row, typeof(ARTran.inventoryID), Messages.NonStockNoShipCantBeInvoicedDirectly, onPersist,
                                           sender.GetValueExt <ARTran.inventoryID>(row));
            }

            var res = GetLinkedSOLine(row);

            if (res == null)
            {
                RaiseAvailabilityException(sender, row, typeof(ARTran.sOOrderNbr), Messages.SOLineNotFound, onPersist);
            }

            SOLine      line      = res;
            SOOrderType orderType = res;

            if (orderType.OrderType == null || orderType.RequireShipping == false || orderType.ARDocType == ARDocType.NoUpdate)
            {
                RaiseAvailabilityException(sender, row, typeof(ARTran.sOOrderType), Messages.SOTypeCantBeInvoicedDirectly, onPersist,
                                           sender.GetValueExt <ARTran.sOOrderType>(row));
            }

            if (line.Completed == true)
            {
                RaiseAvailabilityException(sender, row, typeof(ARTran.sOOrderNbr), Messages.CompletedSOLineCantBeInvoicedDirectly, onPersist);
            }

            if (line.CustomerID != row.CustomerID)
            {
                RaiseAvailabilityException(sender, row, typeof(ARTran.sOOrderNbr), Messages.CustomerDiffersInvoiceAndSO, onPersist);
            }

            if (line.POCreate == true)
            {
                RaiseAvailabilityException(sender, row, typeof(ARTran.sOOrderNbr), Messages.SOLineMarkedForPOCantBeInvoicedDirectly, onPersist);
            }

            if (line.InventoryID != row.InventoryID)
            {
                RaiseAvailabilityException(sender, row, typeof(ARTran.inventoryID), Messages.InventoryItemDiffersInvoiceAndSO, onPersist);
            }

            int arTranInvtMult = Math.Sign((row.InvtMult * row.Qty) ?? 0m);

            if (arTranInvtMult != 0)
            {
                int soLineInvtMult = (line.Operation == SOOperation.Receipt) ? 1 : -1;
                if (soLineInvtMult != arTranInvtMult)
                {
                    RaiseAvailabilityException(sender, row, typeof(ARTran.qty), Messages.OperationDiffersInvoiceAndSO, onPersist);
                }
            }

            decimal absQty = Math.Abs(row.BaseQty ?? 0m);

            if (PXDBQuantityAttribute.Round((decimal)(line.BaseOrderQty * line.CompleteQtyMax / 100m - line.BaseShippedQty - absQty)) < 0m)
            {
                RaiseAvailabilityException(sender, row, typeof(ARTran.qty), Messages.OrderCheck_QtyNegative, onPersist,
                                           sender.GetValueExt <ARTran.inventoryID>(row), sender.GetValueExt <ARTran.subItemID>(row),
                                           sender.GetValueExt <ARTran.sOOrderType>(row), sender.GetValueExt <ARTran.sOOrderNbr>(row));
            }
        }