예제 #1
0
        public static void AssignNumbersWithNoAdditionalProcessing(APPaymentEntry pe, APPayment doc)
        {
            PaymentMethod method = pe.paymenttype.Select(doc.PaymentMethodID);

            if (method == null || method.PrintOrExport == true)
            {
                // To persist the manual changes from "Release Checks" screen (AC-94830)
                pe.Document.Cache.MarkUpdated(doc);
                return;
            }

            pe.RowPersisting.RemoveHandler <APAdjust>(pe.APAdjust_RowPersisting);
            pe.Clear();
            pe.Document.Current = pe.Document.Search <APPayment.refNbr>(doc.RefNbr, doc.DocType);
            PaymentMethodAccount det = pe.cashaccountdetail.Select();

            pe.Document.Current.StubCntr  = 1;
            pe.Document.Current.BillCntr  = 0;
            pe.Document.Current.ExtRefNbr = doc.ExtRefNbr;

            foreach (APAdjust adj in pe.Adjustments_print.Select())
            {
                pe.Document.Current.BillCntr++;
                SetAdjustmentStubNumber(pe, doc, adj, doc.ExtRefNbr);
            }

            det.APLastRefNbr = doc.ExtRefNbr;
            pe.cashaccountdetail.Update(det);

            pe.Document.Current.Printed = true;
            pe.Document.Current.Hold    = false;
            pe.Document.Update(pe.Document.Current);
        }
예제 #2
0
        private void GeneratePayment(APInvoice invoice)
        {
            PaymentEntry.Clear();
            var location    = TryGetInvoiceLocation(invoice);
            var payAccount  = invoice.PayAccountID ?? location.CashAccountID;
            var cashAccount = TryGetVendorCashAccount(payAccount);
            var payment     = CreateApPayment(invoice);

            UpdatePayment(invoice, payment, cashAccount, payAccount, location);
            SuppressDefaultEvents(invoice);
            PaymentEntry.Document.Current = PaymentEntry.Document.Update(payment);
        }
예제 #3
0
        private bool ProcessJointPayment(APInvoiceEntry invoiceEntry, APPaymentEntry paymentEntry,
                                         IReadOnlyCollection <APAdjust> adjustments, PayBillsFilter filter)
        {
            var invoice = InvoiceDataProvider.GetInvoice(
                Base, adjustments.First().AdjdDocType, adjustments.First().AdjdRefNbr);

            if (IsPaymentCycleWorkflow(invoice))
            {
                PXProcessing <APAdjust> .SetError(JointCheckMessages.PaymentCycleWorkflowIsStarted);

                return(false);
            }
            paymentEntry.Clear();
            var jointCheckPreparePaymentCreator = new JointCheckPreparePaymentCreator(invoiceEntry, paymentEntry, Base1);

            jointCheckPreparePaymentCreator.GenerateChecks(invoice, adjustments, filter);
            if (Base.APSetup.Current.HoldEntry == false)
            {
                lienWaiverHoldPaymentService.HoldPaymentsIfNeeded(invoice.RefNbr,
                                                                  LienWaiverSetup.Current.ShouldStopPayments);
                Base.Caches <APPayment>().Persist(PXDBOperation.Update);
            }
            return(true);
        }
예제 #4
0
        protected virtual void PrintPayments(List <APPayment> list, PrintChecksFilter filter, PaymentMethod paymentMethod)
        {
            if (list.Count == 0)
            {
                return;
            }

            if (paymentMethod.UseForAP == true)
            {
                if (paymentMethod.APPrintChecks == true && string.IsNullOrEmpty(paymentMethod.APCheckReportID))
                {
                    throw new PXException(Messages.FieldNotSetInPaymentMethod, PXUIFieldAttribute.GetDisplayName <PaymentMethod.aPCheckReportID>(paymenttype.Cache), paymentMethod.PaymentMethodID);
                }

                if (paymentMethod.APPrintChecks == true && paymentMethod.APPrintRemittance == true && string.IsNullOrEmpty(paymentMethod.APRemittanceReportID))
                {
                    throw new PXException(Messages.FieldNotSetInPaymentMethod, PXUIFieldAttribute.GetDisplayName <PaymentMethod.aPRemittanceReportID>(paymenttype.Cache), paymentMethod.PaymentMethodID);
                }
            }

            bool printAdditionRemit = false;

            if (paymentMethod.APCreateBatchPayment == true)
            {
                CABatch batch = CreateBatchPayment(list, filter);
                if (batch != null)
                {
                    bool           failed = false;
                    APPaymentEntry pe     = CreateInstance <APPaymentEntry>();

                    string NextCheckNbr = filter.NextCheckNbr;
                    foreach (APPayment pmt in list)
                    {
                        APPayment payment = pmt;
                        PXProcessing <APPayment> .SetCurrentItem(payment);

                        try
                        {
                            payment = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                            if (payment.PrintCheck != true)
                            {
                                throw new PXException(Messages.CantPrintNonprintableCheck);
                            }
                            if ((payment.DocType == APDocType.Check || payment.DocType == APDocType.QuickCheck) &&
                                payment.Status != APDocStatus.PendingPrint)
                            {
                                throw new PXException(Messages.ChecksMayBePrintedInPendingPrintStatus);
                            }

                            AssignNumbers(pe, payment, ref NextCheckNbr, true);

                            if (payment.Passed == true)
                            {
                                pe.TimeStamp = payment.tstamp;
                            }
                            pe.Save.Press();
                            payment.tstamp = pe.TimeStamp;
                            pe.Clear();
                        }
                        catch (PXException e)
                        {
                            PXProcessing <APPayment> .SetError(e);

                            failed = true;
                        }
                    }
                    if (failed)
                    {
                        throw new PXOperationCompletedWithErrorException(Messages.APPaymentsAreAddedToTheBatchButWasNotUpdatedCorrectly, batch.BatchNbr);
                    }
                    RedirectToResultWithCreateBatch(batch);
                }
            }
            else
            {
                APReleaseChecks     pp          = CreateInstance <APReleaseChecks>();
                ReleaseChecksFilter filter_copy = PXCache <ReleaseChecksFilter> .CreateCopy(pp.Filter.Current);

                filter_copy.PayAccountID = filter.PayAccountID;
                filter_copy.PayTypeID    = filter.PayTypeID;
                filter_copy.CuryID       = filter.CuryID;
                pp.Filter.Cache.Update(filter_copy);

                APPaymentEntry pe             = CreateInstance <APPaymentEntry>();
                bool           failed         = false;
                Dictionary <string, string> d = new Dictionary <string, string>();

                string nextCheckNbr = filter.NextCheckNbr;
                string prevCheckNbr = nextCheckNbr;

                int idxReportFilter = 0;
                foreach (APPayment pmt in list)
                {
                    APPayment payment = pmt;
                    PXProcessing <APPayment> .SetCurrentItem(payment);

                    try
                    {
                        prevCheckNbr = nextCheckNbr;
                        if (filter.IsNextNumberDuplicated(this, nextCheckNbr))
                        {
                            string duplicate = nextCheckNbr;
                            nextCheckNbr = AutoNumberAttribute.NextNumber(nextCheckNbr);
                            throw new PXException(Messages.ConflictWithExistingCheckNumber, duplicate);
                        }

                        payment = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        if (payment.PrintCheck != true)
                        {
                            throw new PXException(Messages.CantPrintNonprintableCheck);
                        }
                        if ((payment.DocType == APDocType.Check || payment.DocType == APDocType.QuickCheck) &&
                            payment.Status != APDocStatus.PendingPrint)
                        {
                            throw new PXException(Messages.ChecksMayBePrintedInPendingPrintStatus);
                        }
                        AssignNumbers(pe, payment, ref nextCheckNbr);

                        if (payment.Passed == true)
                        {
                            pe.TimeStamp = payment.tstamp;
                        }
                        pe.Save.Press();
                        payment.tstamp = pe.TimeStamp;
                        pe.Clear();

                        APPayment seldoc = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        seldoc.Selected = true;
                        seldoc.Passed   = true;
                        seldoc.tstamp   = payment.tstamp;
                        pp.APPaymentList.Cache.Update(seldoc);
                        pp.APPaymentList.Cache.SetStatus(seldoc, PXEntryStatus.Updated);

                        printAdditionRemit |= seldoc.BillCntr > paymentMethod.APStubLines;

                        StringBuilder sbDocType = new StringBuilder("APPayment.DocType");
                        sbDocType.Append(Convert.ToString(idxReportFilter));
                        StringBuilder sbRefNbr = new StringBuilder("APPayment.RefNbr");
                        sbRefNbr.Append(Convert.ToString(idxReportFilter));

                        idxReportFilter++;

                        d[sbDocType.ToString()] = payment.DocType == APDocType.QuickCheck ? APDocType.QuickCheck : APDocType.Check;
                        d[sbRefNbr.ToString()]  = payment.RefNbr;
                        PXProcessing <APPayment> .SetProcessed();
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);

                        failed       = true;
                        nextCheckNbr = prevCheckNbr;
                    }
                }

                if (failed)
                {
                    PXReportRequiredException report = null;
                    if (d.Count > 0)
                    {
                        d[ReportMessages.CheckReportFlag] = ReportMessages.CheckReportFlagValue;
                        report = new PXReportRequiredException(d, paymentMethod.APCheckReportID, PXBaseRedirectException.WindowMode.New, "Check");
                    }
                    throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased, report);
                }
                else
                {
                    if (d.Count > 0)
                    {
                        RedirectToResultNoBatch(pp, d, paymentMethod, printAdditionRemit, nextCheckNbr);
                    }
                }
            }
        }
예제 #5
0
        public virtual void AssignNumbers(APPaymentEntry pe, APPayment doc, ref string NextCheckNbr, bool skipStubs = false)
        {
            pe.RowPersisting.RemoveHandler <APAdjust>(pe.APAdjust_RowPersisting);
            pe.Clear();
            doc = pe.Document.Current = pe.Document.Search <APPayment.refNbr>(doc.RefNbr, doc.DocType);
            PaymentMethodAccount det = pe.cashaccountdetail.Select();

            doc.IsPrintingProcess = true;             // indicates that the payment under printing process (to prevent update by PaymentRefAttribute)

            if (string.IsNullOrEmpty(NextCheckNbr))
            {
                throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing);
            }

            if (string.IsNullOrEmpty(pe.Document.Current.ExtRefNbr))
            {
                pe.Document.Current.StubCntr  = 1;
                pe.Document.Current.BillCntr  = 0;
                pe.Document.Current.ExtRefNbr = NextCheckNbr;

                if (pe.Document.Current.DocType == APDocType.QuickCheck && pe.Document.Current.CuryOrigDocAmt <= 0m)
                {
                    throw new PXException(Messages.ZeroCheck_CannotPrint);
                }

                if (!skipStubs)                         // print check
                {
                    APAdjust[]    adjustments = pe.Adjustments_print.Select().RowCast <APAdjust>().ToArray();
                    PaymentMethod pt          = pe.paymenttype.Select();
                    int           stubCount   = (int)Math.Ceiling(adjustments.Length / (decimal)(pt.APStubLines ?? 1));
                    if (stubCount > 1 && pt.APPrintRemittance != true)
                    {
                        string   endNumber  = AutoNumberAttribute.NextNumber(NextCheckNbr, stubCount - 1);
                        string[] duplicates = PXSelect <CashAccountCheck,
                                                        Where <CashAccountCheck.accountID, Equal <Required <PrintChecksFilter.payAccountID> >,
                                                               And <CashAccountCheck.paymentMethodID, Equal <Required <PrintChecksFilter.payTypeID> >,
                                                                    And <CashAccountCheck.checkNbr, GreaterEqual <Required <PrintChecksFilter.nextCheckNbr> >,
                                                                         And <CashAccountCheck.checkNbr, LessEqual <Required <PrintChecksFilter.nextCheckNbr> > > > > > >
                                              .Select(this, det.CashAccountID, det.PaymentMethodID, NextCheckNbr, endNumber)
                                              .RowCast <CashAccountCheck>()
                                              .Select(check => check.CheckNbr)
                                              .ToArray();

                        if (duplicates.Any())
                        {
                            throw new PXException(
                                      Messages.TooSmallCheckNumbersGap,
                                      stubCount,
                                      NextCheckNbr,
                                      endNumber,
                                      string.Join(",", duplicates));
                        }
                    }

                    short ordinalInStub = 0;
                    int   stubOrdinal   = 0;
                    foreach (APAdjust adj in adjustments)
                    {
                        pe.Document.Current.BillCntr++;

                        if (ordinalInStub > pt.APStubLines - 1)
                        {
                            //AssignCheckNumber only for first StubLines in check, other/all lines will be printed on remittance report
                            if (pt.APPrintRemittance == true)
                            {
                                adj.StubNbr = null;
                                pe.Adjustments.Cache.Update(adj);
                                continue;
                            }
                            NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);

                            pe.Document.Current.StubCntr++;
                            ordinalInStub = 0;
                            stubOrdinal++;
                        }

                        SetAdjustmentStubNumber(pe, doc, adj, NextCheckNbr);
                        StoreStubNumber(pe, doc, det, NextCheckNbr, stubOrdinal);

                        ordinalInStub++;
                    }
                }
                else                         // create batch payment
                {
                    //Update last number
                    det.APLastRefNbr = NextCheckNbr;
                }

                pe.cashaccountdetail.Update(det);                         // det.APLastRefNumber was modified in StoreStubNumber method

                NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);
                pe.Document.Current.Printed = true;
                pe.Document.Current.Hold    = false;
                pe.Document.Update(pe.Document.Current);
            }
            else
            {
                if (pe.Document.Current.Printed != true || pe.Document.Current.Hold == true)
                {
                    pe.Document.Current.Printed = true;
                    pe.Document.Current.Hold    = false;
                    pe.Document.Update(pe.Document.Current);
                }
            }
        }
예제 #6
0
        public static void Redirect(PXCache sender, CATran catran)
        {
            if (catran == null)
            {
                return;
            }
            if (catran.OrigTranType == CAAPARTranType.GLEntry)
            {
                JournalEntry graph = PXGraph.CreateInstance <JournalEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.BatchModule.Current = PXSelect <Batch, Where <Batch.module, Equal <Required <Batch.module> >, And <Batch.batchNbr, Equal <Required <Batch.batchNbr> > > > > .Select(graph, catran.OrigModule, catran.OrigRefNbr);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.AP && (catran.OrigTranType == AP.APDocType.QuickCheck || catran.OrigTranType == AP.APDocType.VoidQuickCheck))
            {
                APQuickCheckEntry graph = PXGraph.CreateInstance <APQuickCheckEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.Document.Current = PXSelect <APQuickCheck, Where <APQuickCheck.refNbr, Equal <Required <APQuickCheck.refNbr> >,
                                                                        And <APQuickCheck.docType, Equal <Required <APQuickCheck.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.AP && catran.OrigTranType == CATranType.CABatch)
            {
                CABatchEntry graph = PXGraph.CreateInstance <CABatchEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.Document.Current = PXSelect <CABatch, Where <CABatch.batchNbr, Equal <Required <CATran.origRefNbr> > > > .Select(graph, catran.OrigRefNbr);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.AP)
            {
                APPaymentEntry graph = PXGraph.CreateInstance <APPaymentEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.Document.Current = (APPayment)PXSelect <APPayment, Where <APPayment.refNbr, Equal <Required <APPayment.refNbr> >,
                                                                                And <APPayment.docType, Equal <Required <APPayment.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.AR && (catran.OrigTranType == ARDocType.CashSale || catran.OrigTranType == ARDocType.CashReturn))
            {
                ARCashSale document = (ARCashSale)PXSelect <ARCashSale, Where <ARCashSale.refNbr, Equal <Required <ARCashSale.refNbr> >,
                                                                               And <ARCashSale.docType, Equal <Required <ARCashSale.docType> > > > > .Select(sender.Graph, catran.OrigRefNbr, catran.OrigTranType);

                if (document.OrigModule == BatchModule.SO && document.Released == false)
                {
                    SO.SOInvoiceEntry graph = PXGraph.CreateInstance <SO.SOInvoiceEntry>();
                    graph.Clear();
                    sender.IsDirty = false;

                    graph.Document.Current = (ARInvoice)PXSelect <ARInvoice, Where <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> >,
                                                                                    And <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > .Select(sender.Graph, catran.OrigRefNbr, catran.OrigTranType);

                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
                else
                {
                    ARCashSaleEntry graph = PXGraph.CreateInstance <ARCashSaleEntry>();
                    graph.Clear();
                    if (sender != null)
                    {
                        sender.IsDirty = false;
                    }

                    graph.Document.Current = document;
                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }
            else if (catran.OrigModule == GL.BatchModule.AR)
            {
                ARPaymentEntry graph = PXGraph.CreateInstance <ARPaymentEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.Document.Current = (ARPayment)PXSelect <ARPayment, Where <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> >,
                                                                                And <ARPayment.docType, Equal <Required <ARPayment.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.CA && catran.OrigTranType == CATranType.CAAdjustment)
            {
                CATranEntry graph = PXGraph.CreateInstance <CATranEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.CAAdjRecords.Current = PXSelect <CAAdj, Where <CAAdj.tranID, Equal <Required <CAAdj.tranID> > > > .Select(graph, catran.TranID);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.CA && catran.OrigTranType == CATranType.CATransferExp)
            {
                CATranEntry graph = PXGraph.CreateInstance <CATranEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.CAAdjRecords.Current = PXSelect <CAAdj, Where <CAAdj.adjTranType, Equal <CAAPARTranType.cATransferExp>, And <CAAdj.transferNbr, Equal <Required <CATran.origRefNbr> > > > > .Select(graph, catran.OrigRefNbr);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.CA)
            {
                if (catran.OrigTranType == CATranType.CADeposit || catran.OrigTranType == CATranType.CAVoidDeposit)
                {
                    CADepositEntry graph = PXGraph.CreateInstance <CADepositEntry>();
                    graph.Clear();
                    if (sender != null)
                    {
                        sender.IsDirty = false;
                    }
                    graph.Document.Current = PXSelect <CADeposit, Where <CADeposit.tranType, Equal <Required <CADeposit.tranType> >,
                                                                         And <CADeposit.refNbr, Equal <Required <CADeposit.refNbr> > > > >
                                             .Select(graph, catran.OrigTranType, catran.OrigRefNbr);

                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
                else
                {
                    CashTransferEntry graph = PXGraph.CreateInstance <CashTransferEntry>();
                    graph.Clear();
                    if (sender != null)
                    {
                        sender.IsDirty = false;
                    }
                    graph.Transfer.Current = PXSelect <CATransfer, Where <CATransfer.tranIDOut, Equal <Required <CATransfer.tranIDOut> >, Or <CATransfer.tranIDIn, Equal <Required <CATransfer.tranIDIn> > > > >
                                             .Select(graph, catran.TranID, catran.TranID);

                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }
        }
예제 #7
0
        protected virtual void PrintPayments(List <APPayment> list, PrintChecksFilter filter, PaymentMethod paymenttype)
        {
            if (list.Count == 0)
            {
                return;
            }

            bool printAdditionRemit = false;

            if (paymenttype.APCreateBatchPayment == true)
            {
                CABatch batch = CreateBatchPayment(list, filter);
                if (batch != null)
                {
                    bool           failed = false;
                    APPaymentEntry pe     = PXGraph.CreateInstance <APPaymentEntry>();

                    string NextCheckNbr = filter.NextCheckNbr;
                    for (int i = 0; i < list.Count; i++)
                    {
                        try
                        {
                            AssignNumbers(pe, list[i], ref NextCheckNbr, true);

                            if (list[i].Passed == true)
                            {
                                pe.TimeStamp = list[i].tstamp;
                            }
                            pe.Save.Press();
                            list[i].tstamp = pe.TimeStamp;
                            pe.Clear();
                            APPayment seldoc = (APPayment)pe.Document.Search <APPayment.refNbr>(list[i].RefNbr, list[i].DocType);
                            printAdditionRemit = seldoc.BillCntr > paymenttype.APStubLines;
                        }
                        catch (Exception e)
                        {
                            PXProcessing <APPayment> .SetError(i, e);

                            failed = true;
                        }
                    }
                    if (failed)
                    {
                        throw new PXOperationCompletedException(Messages.APPaymentsAreAddedToTheBatchButWasNotUpdatedCorrectly, batch.BatchNbr);
                    }
                    else
                    {
                        RedirectToResultWithCreateBatch(batch);
                    }
                }
            }
            else
            {
                APReleaseChecks     pp          = PXGraph.CreateInstance <APReleaseChecks>();
                ReleaseChecksFilter filter_copy = PXCache <ReleaseChecksFilter> .CreateCopy(pp.Filter.Current);

                filter_copy.PayAccountID = filter.PayAccountID;
                filter_copy.PayTypeID    = filter.PayTypeID;
                filter_copy.CuryID       = filter.CuryID;
                pp.Filter.Cache.Update(filter_copy);

                APPaymentEntry              pe      = PXGraph.CreateInstance <APPaymentEntry>();
                bool                        failed  = false;
                List <APPayment>            paylist = new List <APPayment>(list.Count);
                Dictionary <string, string> d       = new Dictionary <string, string>();

                string NextCheckNbr = null;

                if (filter != null)
                {
                    NextCheckNbr = filter.NextCheckNbr;
                }

                int idxReportFilter = 0;

                for (int i = 0; i < list.Count; i++)
                {
                    try
                    {
                        AssignNumbers(pe, list[i], ref NextCheckNbr);

                        if (list[i].Passed == true)
                        {
                            pe.TimeStamp = list[i].tstamp;
                        }
                        pe.Save.Press();
                        list[i].tstamp = pe.TimeStamp;
                        pe.Clear();

                        APPayment seldoc = (APPayment)pe.Document.Search <APPayment.refNbr>(list[i].RefNbr, list[i].DocType);
                        seldoc.Selected = true;
                        seldoc.Passed   = true;
                        seldoc.tstamp   = list[i].tstamp;
                        pp.APPaymentList.Cache.Update(seldoc);
                        pp.APPaymentList.Cache.SetStatus(seldoc, PXEntryStatus.Updated);

                        printAdditionRemit = seldoc.BillCntr > paymenttype.APStubLines;

                        StringBuilder sbDocType = new StringBuilder("APPayment.DocType");
                        sbDocType.Append(Convert.ToString(idxReportFilter));
                        StringBuilder sbRefNbr = new StringBuilder("APPayment.RefNbr");
                        sbRefNbr.Append(Convert.ToString(idxReportFilter));

                        idxReportFilter++;

                        d[sbDocType.ToString()] = list[i].DocType == APDocType.QuickCheck ? APDocType.QuickCheck : APDocType.Check;
                        d[sbRefNbr.ToString()]  = list[i].RefNbr;
                    }
                    catch (Exception e)
                    {
                        PXProcessing <APPayment> .SetError(i, e);

                        failed = true;
                    }
                }

                if (failed)
                {
                    if (d.Count > 0)
                    {
                        d[ReportMessages.CheckReportFlag] = ReportMessages.CheckReportFlagValue;
                        var requiredException = new PXReportRequiredException(d, paymenttype.APCheckReportID,
                                                                              PXBaseRedirectException.WindowMode.New, "Check");
                        throw new PXException(GL.Messages.DocumentsNotReleased, requiredException);
                    }
                    throw new PXOperationCompletedException(GL.Messages.DocumentsNotReleased);
                }
                else
                {
                    if (d.Count > 0)
                    {
                        RedirectToResultNoBatch(pp, d, paymenttype, printAdditionRemit, NextCheckNbr);
                    }
                }
            }
        }
예제 #8
0
        public static void AssignNumbers(APPaymentEntry pe, APPayment doc, ref string NextCheckNbr, bool skipStubs)
        {
            pe.RowPersisting.RemoveHandler <APAdjust>(pe.APAdjust_RowPersisting);
            pe.Clear(PXClearOption.PreserveTimeStamp);
            pe.Document.Current = (APPayment)pe.Document.Search <APPayment.refNbr>(doc.RefNbr, doc.DocType);
            if (String.IsNullOrEmpty(NextCheckNbr) == false)
            {
                if (String.IsNullOrEmpty(pe.Document.Current.ExtRefNbr))
                {
                    pe.Document.Current.StubCntr  = 1;
                    pe.Document.Current.BillCntr  = 0;
                    pe.Document.Current.ExtRefNbr = NextCheckNbr;
                    if (String.IsNullOrEmpty(NextCheckNbr))
                    {
                        throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing);
                    }

                    if (pe.Document.Current.DocType == APDocType.QuickCheck && pe.Document.Current.CuryOrigDocAmt <= 0m)
                    {
                        throw new PXException(Messages.ZeroCheck_CannotPrint);
                    }

                    if (!skipStubs)
                    {
                        short j = 0;
                        foreach (PXResult <APAdjust> res in pe.Adjustments_print.Select())
                        {
                            pe.Document.Current.BillCntr++;

                            APAdjust             adj = (APAdjust)res;
                            PaymentMethod        pt  = pe.paymenttype.Select();
                            PaymentMethodAccount det = pe.cashaccountdetail.Select();
                            if (j > pt.APStubLines - 1)
                            {
                                //AssignCheckNumber only for first StubLines in check, other/all lines will be printed on remittance report
                                if (pt.APPrintRemittance == true)
                                {
                                    adj.StubNbr = null;
                                    pe.Adjustments.Cache.Update(adj);
                                    continue;
                                }
                                NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);
                                pe.Document.Current.StubCntr++;
                                j = 0;
                            }
                            adj.StubNbr = NextCheckNbr;
                            pe.Adjustments.Cache.Update(adj);
                            det.APLastRefNbr = NextCheckNbr;
                            pe.cashaccountdetail.Update(det);
                            j++;
                        }
                    }
                    NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);
                    pe.Document.Current.Printed          = true;
                    pe.Document.Current.Hold             = false;
                    pe.Document.Current.UpdateNextNumber = true;
                    pe.Document.Update(pe.Document.Current);
                }
                else
                {
                    if (pe.Document.Current.Printed != true || pe.Document.Current.Hold != false)
                    {
                        pe.Document.Current.Printed = true;
                        pe.Document.Current.Hold    = false;
                        pe.Document.Update(pe.Document.Current);
                    }
                }
            }
            else
            {
                PaymentMethod        method = pe.paymenttype.Select();
                PaymentMethodAccount det    = pe.cashaccountdetail.Select();
                //if (method != null && (method.PrintOrExport == false || det.APAutoNextNbr == true))
                {
                    if (pe.Document.Current.DocType == APDocType.QuickCheck && pe.Document.Current.CuryOrigDocAmt <= 0m)
                    {
                        throw new PXException(Messages.ZeroCheck_CannotPrint);
                    }

                    pe.Document.Current.StubCntr  = 1;
                    pe.Document.Current.BillCntr  = 0;
                    pe.Document.Current.ExtRefNbr = doc.ExtRefNbr;
                    if (!skipStubs)
                    {
                        foreach (PXResult <APAdjust> res in pe.Adjustments_print.Select())
                        {
                            pe.Document.Current.BillCntr++;

                            APAdjust adj = (APAdjust)res;
                            adj.StubNbr = doc.ExtRefNbr;
                            pe.Adjustments.Cache.Update(adj);
                        }
                    }
                    pe.Document.Current.Printed = true;
                    pe.Document.Current.Hold    = false;
                    pe.Document.Update(pe.Document.Current);
                }
            }
        }