Esempio n. 1
0
        private static void VoidProcess(ARDunningLetter doc)
        {
            ARDunningLetterMaint graph = PXGraph.CreateInstance <ARDunningLetterMaint>();

            graph.Document.Current    = doc;
            graph.Details.AllowUpdate = true;
            foreach (ARDunningLetterDetail detail in graph.Details.Select())
            {
                ARDunningLetterProcess.ARInvoiceWithDL invoice = PXSelect <ARDunningLetterProcess.ARInvoiceWithDL, Where <ARDunningLetterProcess.ARInvoiceWithDL.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARDunningLetterProcess.ARInvoiceWithDL.docType, Equal <Required <ARInvoice.docType> > > > > .Select(graph, detail.RefNbr, detail.DocType);

                if (invoice != null && invoice.DunningLetterLevel > detail.DunningLetterLevel)
                {
                    throw new PXException(Messages.DunningLetterHigherLevelExists);
                }
            }
            ARInvoice feeInvoice = PXSelect <ARInvoice, Where <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > .Select(graph, doc.FeeRefNbr, doc.FeeDocType);

            if (feeInvoice != null && feeInvoice.Voided == false)
            {
                ARInvoiceEntry invoiceGraph = PXGraph.CreateInstance <ARInvoiceEntry>();
                invoiceGraph.Document.Current = feeInvoice;
                if (feeInvoice.Released == false)
                {
                    invoiceGraph.Delete.Press();
                }
                else if (feeInvoice.Released == true && feeInvoice.OpenDoc == true)
                {
                    if (feeInvoice.CuryOrigDocAmt != feeInvoice.CuryDocBal)
                    {
                        throw new PXException(Messages.DunningLetterHavePaidFee);
                    }
                    invoiceGraph.reverseInvoice.Press();                     // replace by reverse & attach in 2017R2
                    invoiceGraph.Document.Current.Hold = false;
                    invoiceGraph.Document.Update(invoiceGraph.Document.Current);
                    invoiceGraph.release.Press();
                    ARPaymentEntry paymentGraph = PXGraph.CreateInstance <ARPaymentEntry>();
                    paymentGraph.Document.Current = PXSelect <ARPayment, Where <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> >, And <ARPayment.docType, Equal <Required <ARPayment.docType> > > > > .Select(paymentGraph, invoiceGraph.Document.Current.RefNbr, invoiceGraph.Document.Current.DocType);

                    ARAdjust adj = new ARAdjust();
                    paymentGraph.Adjustments.Insert(adj);
                    adj.AdjdRefNbr  = feeInvoice.RefNbr;
                    adj.AdjdDocType = feeInvoice.DocType;
                    paymentGraph.Adjustments.Update(adj);
                    paymentGraph.release.Press();
                }
                else
                {
                    throw new PXException(Messages.DunningLetterHavePaidFee);
                }
            }
            foreach (ARDunningLetterDetail detail in graph.Details.Select())
            {
                detail.Voided = true;
                graph.Details.Update(detail);
            }

            doc.Voided = true;
            graph.Document.Update(doc);
            graph.Save.Press();
        }
Esempio n. 2
0
        private static void VoidProcess(ARDunningLetter doc)
        {
            ARDunningLetterMaint graph = PXGraph.CreateInstance <ARDunningLetterMaint>();

            graph.Document.Current    = doc;
            graph.Details.AllowUpdate = true;
            foreach (ARDunningLetterDetail detail in graph.Details.Select())
            {
                ARDunningLetterProcess.ARInvoiceWithDL invoice = PXSelect <ARDunningLetterProcess.ARInvoiceWithDL, Where <ARDunningLetterProcess.ARInvoiceWithDL.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARDunningLetterProcess.ARInvoiceWithDL.docType, Equal <Required <ARInvoice.docType> > > > > .Select(graph, detail.RefNbr, detail.DocType);

                if (invoice != null && invoice.DunningLetterLevel > detail.DunningLetterLevel)
                {
                    throw new PXException(Messages.DunningLetterHigherLevelExists);
                }
            }
            ARInvoice feeInvoice = PXSelect <ARInvoice, Where <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > .Select(graph, doc.FeeRefNbr, doc.FeeDocType);

            if (feeInvoice != null && feeInvoice.Voided == false)
            {
                ARInvoiceEntry invoiceGraph = PXGraph.CreateInstance <ARInvoiceEntry>();
                invoiceGraph.Document.Current = feeInvoice;
                if (feeInvoice.Released == false)
                {
                    invoiceGraph.Delete.Press();
                    doc.FeeRefNbr  = null;
                    doc.FeeDocType = null;
                }
                else if (feeInvoice.Released == true && feeInvoice.OpenDoc == true)
                {
                    if (feeInvoice.CuryOrigDocAmt != feeInvoice.CuryDocBal)
                    {
                        throw new PXException(Messages.DunningLetterHavePaidFee);
                    }
                    invoiceGraph.reverseInvoiceAndApplyToMemo.Press();
                    invoiceGraph.Document.Current.Hold = false;
                    invoiceGraph.Document.Update(invoiceGraph.Document.Current);
                    invoiceGraph.release.Press();
                }
                else
                {
                    throw new PXException(Messages.DunningLetterHavePaidFee);
                }
            }
            foreach (ARDunningLetterDetail detail in graph.Details.Select())
            {
                detail.Voided = true;
                graph.Details.Update(detail);
            }

            doc.Voided = true;
            graph.Document.Update(doc);
            graph.Save.Press();
        }
        public ARDunningLetterMaint()
        {
            Details.AllowUpdate         = false;
            Details.AllowInsert         = false;
            CurrentCustomer.AllowUpdate = false;
            foreach (ARDunningLetterDetail detail in Details.Select())
            {
                ARDunningLetterProcess.ARInvoiceWithDL invoice = PXSelect <ARDunningLetterProcess.ARInvoiceWithDL, Where <ARDunningLetterProcess.ARInvoiceWithDL.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARDunningLetterProcess.ARInvoiceWithDL.docType, Equal <Required <ARInvoice.docType> > > > > .Select(this, detail.RefNbr, detail.DocType);

                if (invoice != null && invoice.DunningLetterLevel > detail.DunningLetterLevel)
                {
                    VoidLetter.SetEnabled(false);
                    break;
                }
            }
        }