Exemplo n.º 1
0
        protected void _(Events.RowPersisting <ARInvoice> e, PXRowPersisting InvokeBaseHandler)
        {
            InvokeBaseHandler?.Invoke(e.Cache, e.Args);

            if (e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update)
            {
                ARRegisterExt regisExt = PXCache <ARRegister> .GetExtension <ARRegisterExt>(e.Row);

                //if (e.Row.CuryDocBal == decimal.Zero && string.IsNullOrEmpty(regisExt.UsrGUINbr))
                //{
                //    regisExt.UsrVATOutCode = string.Empty;
                //}
                //else
                if (string.IsNullOrEmpty(regisExt.UsrGUINbr) && (regisExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode31 ||
                                                                 regisExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode32 ||
                                                                 regisExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode35))
                {
                    TWNGUIPreferences gUIPreferences = SelectFrom <TWNGUIPreferences> .View.Select(Base);

                    regisExt.UsrGUINbr = ARGUINbrAutoNumAttribute.GetNextNumber(e.Cache, e.Row, regisExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode32 ? gUIPreferences.GUI2CopiesNumbering : gUIPreferences.GUI3CopiesNumbering,
                                                                                regisExt.UsrGUIDate);

                    tWNGUIValidation.CheckGUINbrExisted(Base, regisExt.UsrGUINbr, regisExt.UsrVATOutCode);
                }
            }
        }
Exemplo n.º 2
0
        protected void _(Events.RowSelected <ARInvoice> e, PXRowSelected baseHandler)
        {
            baseHandler?.Invoke(e.Cache, e.Args);

            ARInvoiceState state = Base.GetDocumentState(e.Cache, e.Row);

            ARRegisterExt registerExt = PXCache <ARRegister> .GetExtension <ARRegisterExt>(e.Row);

            bool taxNbrBlank  = string.IsNullOrEmpty(registerExt.UsrTaxNbr);
            bool statusClosed = e.Row.Status.Equals(ARDocStatus.Open) || e.Row.Status.Equals(ARDocStatus.Closed);

            //BuyPlasticBag.SetVisible(activateGUI);

            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrGUIDate>     (e.Cache, null, activateGUI);
            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrGUINbr>      (e.Cache, null, activateGUI);
            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrOurTaxNbr>   (e.Cache, null, activateGUI);
            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrTaxNbr>      (e.Cache, null, activateGUI);
            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrVATOutCode>  (e.Cache, null, activateGUI);
            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrB2CType>     (e.Cache, null, activateGUI);
            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrCarrierID>   (e.Cache, null, activateGUI);
            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrNPONbr>      (e.Cache, null, activateGUI);
            PXUIFieldAttribute.SetVisible <ARRegisterExt.usrCreditAction>(e.Cache, null, activateGUI &&
                                                                          !string.IsNullOrEmpty(registerExt.UsrVATOutCode) &&
                                                                          registerExt.UsrVATOutCode.IsIn(TWGUIFormatCode.vATOutCode33, TWGUIFormatCode.vATOutCode34));

            PXUIFieldAttribute.SetEnabled <ARRegisterExt.usrB2CType>     (e.Cache, e.Row, !statusClosed && taxNbrBlank);
            PXUIFieldAttribute.SetEnabled <ARRegisterExt.usrCarrierID>   (e.Cache, e.Row, !statusClosed && taxNbrBlank && registerExt.UsrB2CType == TWNB2CType.MC);
            PXUIFieldAttribute.SetEnabled <ARRegisterExt.usrNPONbr>      (e.Cache, e.Row, !statusClosed && taxNbrBlank && registerExt.UsrB2CType == TWNB2CType.NPO);
            PXUIFieldAttribute.SetEnabled <ARRegisterExt.usrVATOutCode>  (e.Cache, e.Row, string.IsNullOrEmpty(registerExt.UsrGUINbr));

            PXUIFieldAttribute.SetEnabled <ARRegisterExt.usrCreditAction>(e.Cache, e.Row, state.DocumentDescrEnabled);
        }
Exemplo n.º 3
0
        protected void _(Events.RowDeleted <ARInvoice> e)
        {
            ARRegisterExt aRRegisterExt = PXCache <ARRegister> .GetExtension <ARRegisterExt>(e.Row);

            string taxID = string.Empty;

            /// When deleted, ARTax does not keep the current record, but can fetches the record from the cache.
            foreach (ARTax aRTax in Base.Tax_Rows.Cache.Deleted)
            {
                taxID = aRTax.TaxID;

                goto CreateGUI;
            }

CreateGUI:
            if (activateGUI && string.IsNullOrEmpty(taxID))
            {
                throw new PXException(TWMessages.NoInvTaxDtls);
            }

            if (string.IsNullOrEmpty(aRRegisterExt.UsrGUINbr) || !activateGUI || string.IsNullOrEmpty(TX.Tax.PK.Find(Base, taxID).GetExtension <TX.TaxExt>().UsrGUIType))
            {
                return;
            }

            // Acuminator disable once PX1043 SavingChangesInEventHandlers [Justification]
            rp.CreateGUITrans(new STWNGUITran()
            {
                VATCode       = aRRegisterExt.UsrVATOutCode,
                GUINbr        = aRRegisterExt.UsrGUINbr,
                GUIStatus     = TWNGUIStatus.Voided,
                GUIDirection  = TWNGUIDirection.Issue,
                GUIDate       = aRRegisterExt.UsrGUIDate,
                TaxZoneID     = e.Row.TaxZoneID,
                TaxCategoryID = Base.taxzone.Current.DfltTaxCategoryID,
                TaxID         = taxID,
                TaxNbr        = aRRegisterExt.UsrTaxNbr,
                OurTaxNbr     = aRRegisterExt.UsrOurTaxNbr,
                NetAmount     = 0,
                TaxAmount     = 0,
                AcctCD        = Base.customer.Current.AcctCD,
                AcctName      = Base.customer.Current.AcctName,
                DeductionCode = string.Empty,
                Remark        = string.Format(TWMessages.DeleteInfo, Base.Accessinfo.UserName),
                OrderNbr      = e.Row.RefNbr
            });
        }
Exemplo n.º 4
0
        protected void _(Events.RowInserting <ARInvoice> e)
        {
            if (activateGUI && e.Row.DocType.Equals(ARDocType.CreditMemo))
            {
                ARRegisterExt registerExt = PXCache <ARRegister> .GetExtension <ARRegisterExt>(e.Row);

                switch (registerExt.UsrVATOutCode)
                {
                case TWGUIFormatCode.vATOutCode31:
                case TWGUIFormatCode.vATOutCode35:
                    registerExt.UsrVATOutCode = TWGUIFormatCode.vATOutCode33;
                    break;

                case TWGUIFormatCode.vATOutCode32:
                    registerExt.UsrVATOutCode = TWGUIFormatCode.vATOutCode34;
                    break;
                }
            }
        }
Exemplo n.º 5
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,
                                });