public void Persist(PersistDelegate baseMethod)
 {
     Base.Document.Current.CuryOrderTotal = GetOrderTotals(Base.Document.Current);
     UpdateOrderTotals(Base.Document.Current);
     UpdateARBalances(Base, Base.Document.Current);
     baseMethod();
 }
        public void Persist(PersistDelegate baseMethod)
        {
            if (SharedFunctions.isFSSetupSet(Base) == false ||
                PXAccess.FeatureInstalled <FeaturesSet.equipmentManagementModule>() == false)
            {
                baseMethod();
                return;
            }

            //// Invoice
            ARRegister arRegisterRow                      = (ARRegister)Base.Caches[typeof(ARRegister)].Current;
            Dictionary <int?, int?> newEquiments          = new Dictionary <int?, int?>();
            SMEquipmentMaint        graphSMEquipmentMaint = PXGraph.CreateInstance <SMEquipmentMaint>();

            if (processEquipmentAndComponents)
            {
                CreateEquipments(graphSMEquipmentMaint, arRegisterRow, newEquiments);
                ReplaceEquipments(graphSMEquipmentMaint, arRegisterRow);
                UpgradeEquipmentComponents(graphSMEquipmentMaint, arRegisterRow, newEquiments);
                CreateEquipmentComponents(graphSMEquipmentMaint, arRegisterRow, newEquiments);
                ReplaceComponents(graphSMEquipmentMaint, arRegisterRow);
            }

            baseMethod();
        }
Exemple #3
0
 public void Persist(PersistDelegate baseMethod)
 {
     baseMethod();
     // We need to reset Slots and Cache after the values may change.
     PXDatabase.ResetSlots();
     PXPageCacheUtils.InvalidateCachedPages();
 }
Exemple #4
0
        public void Persist(PersistDelegate baseMethod)
        {
            if (SharedFunctions.isFSSetupSet(Base) == false)
            {
                baseMethod();
                return;
            }

            baseMethod();
            UpdateCosts();
        }
Exemple #5
0
        public void Persist(PersistDelegate baseMethod)
        {
            ARRegister      invoice        = Base.ARDocument.Current;
            List <Contract> setupContracts = new List <Contract>();

            if (SetupContract)
            {
                // Create, set up, and activate contracts
                ContractMaint contractMaint = PXGraph.CreateInstance <ContractMaint>();
                CTBillEngine  engine        = PXGraph.CreateInstance <CTBillEngine>();
                int           seq           = 1;
                // Reuse ARTran_TranType_RefNbr from ARReleaseProcess
                foreach (ARTran tran in

                         PXSelect <ARTran,
                                   Where <ARTran.tranType, Equal <Required <ARInvoice.docType> >,
                                          And <ARTran.refNbr, Equal <Required <ARInvoice.refNbr> >,
                                               And <ARTranExt.usrSIMCardID, IsNotNull,
                                                    And <ARTranExt.usrContractID, IsNull> > > >,
                                   OrderBy <Asc <ARTran.tranType, Asc <ARTran.refNbr,
                                                                       Asc <ARTran.lineNbr> > > > >
                         .Select(Base, invoice.DocType, invoice.RefNbr))
                {
                    // Create, set up, and activate contract for a particular SOInvoice line
                    ARTranExt tranExt = PXCache <ARTran> .GetExtension <ARTranExt>(tran);

                    Contract contract = CreateActivateContract(contractMaint,
                                                               invoice.DocDate, invoice.CustomerID, invoice.CustomerLocationID,
                                                               tranExt.UsrSIMCardID, tranExt.UsrPhoneNumber, engine);
                    setupContracts.Add(contract);
                    // Associate the generated contract with the SOInvoice line
                    tranExt.UsrContractID = contract.ContractID;

                    Base.ARTran_TranType_RefNbr.Cache.SetValueExt(tran, "UsrContractID", contract.ContractID);
                    Base.ARTran_TranType_RefNbr.Cache.SetStatus(tran, PXEntryStatus.Modified);
                    Base.ARTran_TranType_RefNbr.Cache.Update(tran);
                    Base.ARTran_TranType_RefNbr.Cache.IsDirty = true;
                    seq++;
                }
            }
            baseMethod();
        }
Exemple #6
0
        public void Persist(PersistDelegate baseMethod)
        {
            var needUpdatePackedQty = Base.Packages.Cache.Dirty.RowCast <SOPackageDetailEx>().Count() > 0;


            if (needUpdatePackedQty)
            {
                // Except Delete row
                IEnumerable <SOPackageDetailEx> _packages = Base.Packages.Cache.Cached.RowCast <SOPackageDetailEx>();
                _packages = _packages.Except((IEnumerable <SOPackageDetailEx>)Base.Packages.Cache.Deleted);
                var _shipLines = Base.Transactions.Cache.Cached.RowCast <SOShipLine>();
                _shipLines = _shipLines.Except((IEnumerable <SOShipLine>)Base.Transactions.Cache.Deleted);
                // Recalculate PackedQty
                foreach (var item in _shipLines)
                {
                    item.PackedQty = _packages.Where(x => x.GetExtension <SOPackageDetailExt>().UsrShipmentSplitLineNbr == item.LineNbr).Sum(x => x.Qty);
                    Base.Caches[typeof(SOShipLine)].Update(item);
                }
            }

            baseMethod();
        }
Exemple #7
0
        public void Persist(PersistDelegate baseMethod)
        {
            baseMethod();

            APRegister    doc    = Base.APDocument.Current;
            APRegisterExt docExt = PXCache <APRegister> .GetExtension <APRegisterExt>(doc);

            // Check for document and released flag
            if (TWNGUIValidation.ActivateTWGUI(Base) == true &&
                doc != null &&
                doc.Released == true &&
                doc.DocType.IsIn(APDocType.Invoice, APDocType.DebitAdj))
            {
                //if (Base.APTaxTran_TranType_RefNbr.Current == null)
                //{
                //    throw new PXException(TWMessages.NoInvTaxDtls);
                //}

                foreach (TWNManualGUIAPBill row in SelectFrom <TWNManualGUIAPBill> .Where <TWNManualGUIAPBill.docType.IsEqual <@P.AsString>
                                                                                           .And <TWNManualGUIAPBill.refNbr.IsEqual <@P.AsString> > > .View.Select(Base, doc.DocType, doc.RefNbr))
                {
                    // Avoid standard logic calling this method twice and inserting duplicate records into TWNGUITrans.
                    if (CountExistedRec(Base, row.GUINbr, row.VATInCode, doc.RefNbr) >= 1)
                    {
                        return;
                    }

                    if (Tax.PK.Find(Base, row.TaxID).GetExtension <TaxExt>().UsrTWNGUI != true)
                    {
                        continue;
                    }

                    Vendor vendor = Vendor.PK.Find(Base, row.VendorID);

                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        TWNReleaseProcess rp = PXGraph.CreateInstance <TWNReleaseProcess>();

                        TWNGUITrans tWNGUITrans = rp.InitAndCheckOnAP(row.GUINbr, row.VATInCode);

                        rp.CreateGUITrans(new STWNGUITran()
                        {
                            VATCode       = row.VATInCode,
                            GUINbr        = row.GUINbr,
                            GUIStatus     = TWNGUIStatus.Used,
                            BranchID      = Base.APTran_TranType_RefNbr.Current.BranchID,
                            GUIDirection  = TWNGUIDirection.Receipt,
                            GUIDate       = row.GUIDate,
                            GUITitle      = vendor?.AcctName,
                            TaxZoneID     = row.TaxZoneID,
                            TaxCategoryID = row.TaxCategoryID,
                            TaxID         = row.TaxID,
                            TaxNbr        = row.TaxNbr,
                            OurTaxNbr     = row.OurTaxNbr,
                            NetAmount     = row.NetAmt,
                            TaxAmount     = row.TaxAmt,
                            AcctCD        = vendor?.AcctCD,
                            AcctName      = vendor?.AcctName,
                            DeductionCode = row.Deduction,
                            Remark        = row.Remark,
                            BatchNbr      = doc.BatchNbr,
                            OrderNbr      = doc.RefNbr
                        });

                        if (tWNGUITrans != null)
                        {
                            if (tWNGUITrans.NetAmtRemain < row.NetAmt)
                            {
                                throw new PXException(TWMessages.RemainAmt);
                            }

                            ViewGUITrans.SetValueExt <TWNGUITrans.netAmtRemain>(tWNGUITrans, (tWNGUITrans.NetAmtRemain -= row.NetAmt));
                            ViewGUITrans.SetValueExt <TWNGUITrans.taxAmtRemain>(tWNGUITrans, (tWNGUITrans.TaxAmtRemain -= row.TaxAmt));

                            tWNGUITrans = ViewGUITrans.Update(tWNGUITrans);
                        }

                        // Manually Saving as base code will not call base graph persis.
                        ViewGUITrans.Cache.Persist(PXDBOperation.Insert);
                        ViewGUITrans.Cache.Persist(PXDBOperation.Update);

                        ts.Complete(Base);
                    }
                }
            }

            // Triggering after save events.
            ViewGUITrans.Cache.Persisted(false);
        }
Exemple #8
0
 public void Persist(PersistDelegate baseMethod)
 {
     UpdateOrderBalances((SOOrder)Base.Caches["SOOrder"].Current);
     UpdateInvoiceTotal(Base.Document.Current);
     baseMethod();
 }
Exemple #9
0
        public void Persist(PersistDelegate baseMethod)
        {
            baseMethod();

            if (skipPersist == false)
            {
                ARRegister    doc    = Base.ARDocument.Current;
                ARRegisterExt docExt = PXCache <ARRegister> .GetExtension <ARRegisterExt>(doc);

                // Check for document and released flag
                if (doc != null &&
                    doc.Released == true &&
                    doc.DocType.IsIn(ARDocType.Invoice, ARDocType.CreditMemo, ARDocType.CashSale) &&
                    ((string.IsNullOrEmpty(docExt.UsrGUINbr) && docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode36) || !string.IsNullOrEmpty(docExt.UsrVATOutCode))
                    )
                {
                    if (docExt.UsrVATOutCode.IsIn(TWGUIFormatCode.vATOutCode33, TWGUIFormatCode.vATOutCode34) &&
                        docExt.UsrCreditAction == TWNCreditAction.NO)
                    {
                        throw new PXException(TWMessages.CRACIsNone);
                    }
                    else if (docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode37)
                    {
                        throw new PXException(TWMessages.VATOutCodeIs37);
                    }

                    TaxTran xTran = APReleaseProcess_Extension.SelectTaxTran(Base, doc.DocType, doc.RefNbr, BatchModule.AR);

                    if (xTran == null)
                    {
                        throw new PXException(TWMessages.NoInvTaxDtls);
                    }

                    if (PXCache <Tax> .GetExtension <TaxExt>(Tax.PK.Find(Base, xTran.TaxID)).UsrTWNGUI != true)
                    {
                        return;
                    }

                    decimal?netAmt     = xTran.TaxableAmt + xTran.RetainedTaxableAmt;
                    decimal?taxAmt     = xTran.TaxAmt + xTran.RetainedTaxAmt;
                    decimal?remainNet  = netAmt;
                    decimal?remainTax  = taxAmt;
                    decimal?settledNet = 0;
                    decimal?settledTax = 0;

                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        TWNReleaseProcess rp = PXGraph.CreateInstance <TWNReleaseProcess>();

                        Customer customer = SelectFrom <Customer> .Where <Customer.bAccountID.IsEqual <@P.AsInt> > .View.ReadOnly.Select(Base, doc.CustomerID);

                        string[] gUINbrs = !string.IsNullOrEmpty(docExt.UsrGUINbr) ? docExt.UsrGUINbr.Split(';') : new string[1] {
                            string.Empty
                        };

                        for (int i = 0; i < gUINbrs.Length; i++)
                        {
                            string gUINbr = gUINbrs[i].TrimStart();

                            // Avoid standard logic calling this method twice and inserting duplicate records into TWNGUITrans.
                            if (APReleaseProcess_Extension.CountExistedRec(Base, gUINbr, docExt.UsrVATOutCode, doc.RefNbr) > 0)
                            {
                                return;
                            }

                            TWNGUITrans tWNGUITrans = rp.InitAndCheckOnAR(gUINbr, docExt.UsrVATOutCode);

                            string taxCateID = string.Empty;

                            foreach (ARTran row in Base.ARTran_TranType_RefNbr.Cache.Cached)
                            {
                                taxCateID = row.TaxCategoryID;

                                goto CreatGUI;
                            }

CreatGUI:
                            if (docExt.UsrCreditAction.IsIn(TWNCreditAction.CN, TWNCreditAction.NO))
                            {
                                //TWNGUIPreferences gUIPreferences = SelectFrom<TWNGUIPreferences>.View.Select(Base);

                                //string numberingSeq = (docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode32) ? gUIPreferences.GUI2CopiesNumbering : gUIPreferences.GUI3CopiesNumbering;

                                //docExt.UsrGUINbr = ARGUINbrAutoNumAttribute.GetNextNumber(Base.ARDocument.Cache, doc, numberingSeq, doc.DocDate);

                                FSAppointment appointment = SelectFrom <FSAppointment> .LeftJoin <FSPostDoc> .On <FSPostDoc.appointmentID.IsEqual <FSAppointment.appointmentID> >
                                                            .Where <FSPostDoc.postDocType.IsEqual <@P.AsString>
                                                                    .And <FSPostDoc.postRefNbr.IsEqual <@P.AsString> > >
                                                            .View.ReadOnly.Select(Base, doc.DocType, doc.RefNbr);

                                if (tWNGUITrans != null)
                                {
                                    settledNet = (tWNGUITrans.NetAmtRemain < remainNet) ? tWNGUITrans.NetAmtRemain : remainNet;
                                    settledTax = (tWNGUITrans.TaxAmtRemain < remainTax) ? tWNGUITrans.TaxAmtRemain : remainTax;

                                    remainNet -= settledNet;
                                    remainTax -= settledTax;
                                }
                                else
                                {
                                    settledNet = remainNet;
                                    settledTax = remainTax;
                                }

                                rp.CreateGUITrans(new STWNGUITran()
                                {
                                    VATCode       = docExt.UsrVATOutCode,
                                    GUINbr        = gUINbr ?? string.Empty,
                                    GUIStatus     = doc.CuryOrigDocAmt == 0m ? TWNGUIStatus.Voided : TWNGUIStatus.Used,
                                    BranchID      = doc.BranchID,
                                    GUIDirection  = TWNGUIDirection.Issue,
                                    GUIDate       = docExt.UsrGUIDate.Value.Date.Add(doc.CreatedDateTime.Value.TimeOfDay),
                                    GUITitle      = customer.AcctName,
                                    TaxZoneID     = Base.ARInvoice_DocType_RefNbr.Current.TaxZoneID,
                                    TaxCategoryID = taxCateID,
                                    TaxID         = xTran.TaxID,
                                    TaxNbr        = docExt.UsrTaxNbr,
                                    OurTaxNbr     = docExt.UsrOurTaxNbr,
                                    NetAmount     = settledNet < 0 ? 0 : settledNet,
                                    TaxAmount     = settledTax < 0 ? 0 : settledTax,
                                    AcctCD        = customer.AcctCD,
                                    AcctName      = customer.AcctName,
                                    Remark        = (appointment is null) ? string.Empty : appointment.RefNbr,
                                    BatchNbr      = doc.BatchNbr,
                                    OrderNbr      = doc.RefNbr,
                                    CarrierType   = GetCarrierType(docExt.UsrCarrierID),
                                    CarrierID     = docExt.UsrB2CType == TWNB2CType.MC ? GetCarrierID(docExt.UsrTaxNbr, docExt.UsrCarrierID) : null,
                                    NPONbr        = docExt.UsrB2CType == TWNB2CType.NPO ? GetNPOBAN(docExt.UsrTaxNbr, docExt.UsrNPONbr) : null,
                                    B2CPrinted    = (docExt.UsrB2CType == TWNB2CType.DEF && string.IsNullOrEmpty(docExt.UsrTaxNbr)) ? true : false,
                                });
        public void Persist(PersistDelegate baseMethod)
        {
            if (Base.Document.Current != null && Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.Inserted && Base.Document.Current.OrderType == POOrderType.DropShip)
            {
                var row = Base.Document.Current;

                //Copy ship via from SO
                SOOrder salesOrder = SelectFrom <SOOrder>
                                     .Where <SOOrder.orderType.IsEqual <@P.AsString>
                                             .And <SOOrder.orderNbr.IsEqual <@P.AsString> > >
                                     .View
                                     .ReadOnly
                                     .Select(Base, row.SOOrderType, row.SOOrderNbr);

                if (salesOrder != null)
                {
                    row.ShipVia = salesOrder.ShipVia;
                }

                //Get the Inventory Item for dropship fees to use for defaulting values
                InventoryItem dropshipFeeItem = SelectFrom <InventoryItem>
                                                .Where <InventoryItem.inventoryCD.IsEqual <@P.AsString> >
                                                .View
                                                .ReadOnly
                                                .Select(Base, "DROPSHIP FEE");

                //If item is null, just bail because you can't ad items anyway
                if (dropshipFeeItem == null)
                {
                    throw new PXException(ShoebaccaProj.Messages.MissingDropshipFeeItem);
                }

                var fees = GetVendorDropshipFees(row.VendorID.Value);
                if (fees.DiscountPercentage != 0 && !DropshipFeesItemExistOnInvoice(dropshipFeeItem.InventoryID.Value, Messages.DropShipDiscountPercentage))
                {
                    decimal totalCost = 0;
                    foreach (POLine line in Base.Transactions.Select())
                    {
                        if (line.InventoryID != dropshipFeeItem.InventoryID)
                        {
                            totalCost += line.ExtCost.Value;
                        }
                    }

                    decimal discount = Decimal.Round((fees.DiscountPercentage / 100) * totalCost, 2);
                    AddDropshipFees(dropshipFeeItem.InventoryID.Value, Messages.DropShipDiscountPercentage, 1, -discount);
                }

                if (fees.ItemHandlingFee != 0 && !DropshipFeesItemExistOnInvoice(dropshipFeeItem.InventoryID.Value, Messages.DropShipItemHandlingFee))
                {
                    int lineCount = 0;
                    foreach (POLine line in Base.Transactions.Select())
                    {
                        if (line.InventoryID != dropshipFeeItem.InventoryID)
                        {
                            lineCount++;
                        }
                    }

                    AddDropshipFees(dropshipFeeItem.InventoryID.Value, Messages.DropShipItemHandlingFee, lineCount, fees.ItemHandlingFee);
                }

                if (fees.OrderHandlingFee != 0 && !DropshipFeesItemExistOnInvoice(dropshipFeeItem.InventoryID.Value, Messages.DropShipOrderHandlingFee))
                {
                    AddDropshipFees(dropshipFeeItem.InventoryID.Value, Messages.DropShipOrderHandlingFee, 1, fees.OrderHandlingFee);
                }
            }

            baseMethod();
        }