コード例 #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;

            var adjustments = pe.GetAdjustmentsPrintList();

            foreach (var group in adjustments)
            {
                pe.Document.Current.BillCntr++;

                foreach (IAdjustmentStub adj in group.GroupedStubs)
                {
                    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
        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;
                pe.Document.Update(pe.Document.Current);

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

                if (!skipStubs)                 // print check
                {
                    pe.DeletePrintList();
                    var adjustments = pe.GetAdjustmentsPrintList();

                    PaymentMethod pt        = pe.paymenttype.Select();
                    int           stubCount = (int)Math.Ceiling(adjustments.Count() / (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 (var group 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)
                            {
                                foreach (IAdjustmentStub adj in group.GroupedStubs)
                                {
                                    adj.StubNbr = null;

                                    if (adj.Persistent)
                                    {
                                        pe.Caches[adj.GetType()].Update(adj);
                                    }
                                }

                                pe.AddCheckDetail(group, null);

                                continue;
                            }
                            NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);

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

                        foreach (IAdjustmentStub adj in group.GroupedStubs)
                        {
                            SetAdjustmentStubNumber(pe, doc, adj, NextCheckNbr);
                        }
                        pe.AddCheckDetail(group, 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);
                }
            }
        }