Example #1
0
 private static void SetAdjustmentStubNumber(APPaymentEntry pe, APPayment doc, APAdjust adj, string StubNbr)
 {
     adj.StubNbr         = StubNbr;
     adj.CashAccountID   = doc.CashAccountID;
     adj.PaymentMethodID = doc.PaymentMethodID;
     pe.Adjustments.Cache.Update(adj);
 }
Example #2
0
        private const bool AutoReleaseDebitAdjustments = true;         //TODO: now (26.10.2017) we can't apply nonreleased debit adjustment

        public static APInvoice CreateAndReleasePPDDebitAdj(APInvoiceEntry ie, APPPDDebitAdjParameters filter, List <PendingPPDDebitAdjApp> list, bool autoReleaseDebitAdjustments)
        {
            APInvoice invDebitAdj;

            try
            {
                ie.Clear(PXClearOption.ClearAll);
                PXUIFieldAttribute.SetError(ie.Document.Cache, null, null, null);

                using (var ts = new PXTransactionScope())
                {
                    invDebitAdj = ie.CreatePPDDebitAdj(filter, list);
                    if (invDebitAdj != null)
                    {
                        if (autoReleaseDebitAdjustments == true)
                        {
                            using (new PXTimeStampScope(null))
                            {
                                APDocumentRelease.ReleaseDoc(new List <APRegister> {
                                    invDebitAdj
                                }, false);
                                APPaymentEntry paymentEntry = PXGraph.CreateInstance <APPaymentEntry>();
                                APPayment      debitAdj     = PXSelect <APPayment,
                                                                        Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                                               And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > >
                                                              .Select(paymentEntry, invDebitAdj.DocType, invDebitAdj.RefNbr)
                                                              .First();

                                paymentEntry.Document.Current = debitAdj;
                                paymentEntry.SelectTimeStamp();
                                CreatePPDApplications(paymentEntry, list, debitAdj);
                                paymentEntry.Persist();
                                APDocumentRelease.ReleaseDoc(new List <APRegister> {
                                    invDebitAdj
                                }, false);                                                                                               // It needs to release applications
                            }
                        }

                        foreach (PendingPPDDebitAdjApp adj in list)
                        {
                            PXProcessing <PendingPPDDebitAdjApp> .SetInfo(adj.Index, ActionsMessages.RecordProcessed);
                        }
                    }
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                foreach (PendingPPDDebitAdjApp adj in list)
                {
                    PXProcessing <PendingPPDDebitAdjApp> .SetError(adj.Index, e);
                }

                invDebitAdj = null;
            }

            return(invDebitAdj);
        }
Example #3
0
        private static void SetAdjustmentStubNumber(APPaymentEntry pe, APPayment doc, IAdjustmentStub adj, string StubNbr)
        {
            adj.StubNbr         = StubNbr;
            adj.CashAccountID   = doc.CashAccountID;
            adj.PaymentMethodID = doc.PaymentMethodID;

            if (adj.Persistent)
            {
                pe.Caches[adj.GetType()].Update(adj);
            }
        }
        protected virtual void APPayment_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e)
        {
            APPayment row = e.NewRow as APPayment;

            if (row != null && row.Selected == true)
            {
                PXFieldState state = (PXFieldState)sender.GetStateExt <APPayment.extRefNbr>(row);
                if (state != null && !string.IsNullOrEmpty(state.Error))
                {
                    row.Selected = false;
                }
            }
        }
        public virtual IEnumerable ViewPayment(PXAdapter adapter)
        {
            PendingPPDDebitAdjApp adj = Applications.Current;

            if (adj != null)
            {
                APPayment payment = PXSelect <APPayment, Where <APPayment.refNbr, Equal <Current <PendingPPDDebitAdjApp.payRefNbr> >,
                                                                And <APPayment.docType, Equal <Current <PendingPPDDebitAdjApp.payDocType> > > > >
                                    .Select(this).First();

                if (payment != null)
                {
                    PXGraph graph = PXGraph.CreateInstance <APPaymentEntry>();
                    PXRedirectHelper.TryRedirect(graph, payment, PXRedirectHelper.WindowMode.NewWindow);
                }
            }
            return(adapter.Get());
        }
        private void SetNumbering(PXCache sender, APPayment row)
        {
            if (row == null)
            {
                return;
            }
            if (Base.IsWithinContext)
            {
                Numbering numbering = PXSelectJoin <Numbering,
                                                    InnerJoin <GLWorkBook, On <GLWorkBook.voucherNumberingID, Equal <Numbering.numberingID> > >,
                                                    Where <GLWorkBook.workBookID, Equal <Required <GLWorkBook.workBookID> > > > .Select(this.Base, Base.GetContextValue <GLVoucherBatch.workBookID>());

                AutoNumberAttribute.SetNumberingId <APPayment.refNbr>(sender, row.DocType, numbering.NumberingID);
                if (numbering.UserNumbering == true)
                {
                    sender.RaiseExceptionHandling <APPayment.refNbr>(row, row.RefNbr, new PXException(GL.Messages.ManualNumberingDisabled));
                }
            }
        }
Example #7
0
        protected virtual void APPayment_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            PrintChecksFilter filter = Filter.Current;

            if (filter != null)
            {
                object OldRow = e.OldRow;
                if (ReferenceEquals(e.Row, e.OldRow) && !_copies.TryGetValue(e.Row, out OldRow))
                {
                    decimal?curyval = 0m;
                    decimal?val     = 0m;
                    int?    count   = 0;
                    foreach (APPayment res in APPaymentList.Select())
                    {
                        if (res.Selected == true)
                        {
                            curyval += res.CuryOrigDocAmt ?? 0m;
                            val     += res.OrigDocAmt ?? 0m;
                            count++;
                        }
                    }

                    filter.CurySelTotal = curyval;
                    filter.SelTotal     = val;
                    filter.SelCount     = count;
                }
                else
                {
                    APPayment old_row = OldRow as APPayment;
                    APPayment new_row = e.Row as APPayment;

                    filter.CurySelTotal -= old_row.Selected == true ? old_row.CuryOrigDocAmt : 0m;
                    filter.CurySelTotal += new_row.Selected == true ? new_row.CuryOrigDocAmt : 0m;

                    filter.SelTotal -= old_row.Selected == true ? old_row.OrigDocAmt : 0m;
                    filter.SelTotal += new_row.Selected == true ? new_row.OrigDocAmt : 0m;

                    filter.SelCount -= old_row.Selected == true ? 1 : 0;
                    filter.SelCount += new_row.Selected == true ? 1 : 0;
                }
            }
        }
Example #8
0
        public virtual void StoreStubNumber(APPaymentEntry pe, APPayment doc, PaymentMethodAccount det, string StubNbr, int stubOrdinal)
        {
            if (doc.VoidAppl == true || StubNbr == null)
            {
                return;
            }

            pe.CACheck.Insert(new CashAccountCheck
            {
                AccountID       = doc.CashAccountID,
                PaymentMethodID = doc.PaymentMethodID,
                CheckNbr        = StubNbr,
                DocType         = doc.DocType,
                RefNbr          = doc.RefNbr,
                FinPeriodID     = doc.FinPeriodID,
                DocDate         = doc.DocDate,
                VendorID        = doc.VendorID
            });

            det.APLastRefNbr = StubNbr;
        }
        protected virtual void APPayment_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected bs)
        {
            if (bs != null)
            {
                bs(sender, e);
            }
            APPayment row = e.Row as APPayment;

            if (row == null)
            {
                return;
            }
            bool           isWithinContext = Base.IsWithinContext;
            GLVoucher      voucher         = this.Voucher.Select();
            GLVoucherBatch voucherBatch    = this.VoucherBatch.Select();
            PXCache        voucherCache    = this.Voucher.Cache;
            bool           isDetached      = (voucher == null);

            PXUIFieldAttribute.SetEnabled <GLVoucher.refNbr>(voucherCache, voucher, false);
            PXUIFieldAttribute.SetVisible <GLVoucher.refNbr>(voucherCache, voucher, !isDetached);
            PXUIFieldAttribute.SetEnabled <APPayment.refNbr>(sender, e.Row, !isWithinContext);
            this.SaveAndAdd.SetVisible(!isDetached && isWithinContext);
            this.SaveAndAdd.SetEnabled(!isDetached && isWithinContext);
            if (isWithinContext)
            {
                Base.release.SetVisible(false);
                Base.release.SetEnabled(false);
                Base.voidCheck.SetVisible(false);
                Base.voidCheck.SetEnabled(false);
            }
            PXUIFieldAttribute.SetVisible <GLVoucher.voucherBatchNbr>(Voucher.Cache, null, !isDetached && !isWithinContext);
            PXUIFieldAttribute.SetVisible <GLVoucher.workBookID>(Voucher.Cache, null, !isDetached && !isWithinContext);
            if (isWithinContext && !isDetached)
            {
                sender.AllowInsert = !(voucherBatch != null && voucherBatch.Released == true);
            }
        }
        public static void ReleasePayments(List <APPayment> list, string Action)
        {
            APReleaseChecks releaseChecksGraph = CreateInstance <APReleaseChecks>();
            APPaymentEntry  pe        = CreateInstance <APPaymentEntry>();
            CABatchEntry    be        = CreateInstance <CABatchEntry>();
            bool            failed    = false;
            bool            successed = false;

            List <APRegister> docs = new List <APRegister>(list.Count);

            foreach (APPayment payment in list)
            {
                if (payment.Passed == true)
                {
                    releaseChecksGraph.TimeStamp = pe.TimeStamp = payment.tstamp;
                }

                switch (Action)
                {
                case ReleaseChecksFilter.action.ReleaseChecks:
                    payment.Printed = true;
                    break;

                case ReleaseChecksFilter.action.ReprintChecks:
                case ReleaseChecksFilter.action.VoidAndReprintChecks:
                    payment.ExtRefNbr = null;
                    payment.Printed   = false;
                    break;

                default:
                    continue;
                }

                PXProcessing <APPayment> .SetCurrentItem(payment);

                if (Action == ReleaseChecksFilter.action.ReleaseChecks)
                {
                    try
                    {
                        pe.Document.Current = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        if (pe.Document.Current?.ExtRefNbr != payment.ExtRefNbr)
                        {
                            APPayment payment_copy = PXCache <APPayment> .CreateCopy(pe.Document.Current);

                            payment_copy.ExtRefNbr = payment.ExtRefNbr;
                            pe.Document.Update(payment_copy);
                        }

                        if (PaymentRefAttribute.PaymentRefMustBeUnique(pe.paymenttype.Current) && string.IsNullOrEmpty(payment.ExtRefNbr))
                        {
                            throw new PXException(ErrorMessages.FieldIsEmpty, typeof(APPayment.extRefNbr).Name);
                        }

                        payment.IsReleaseCheckProcess = true;

                        APPrintChecks.AssignNumbersWithNoAdditionalProcessing(pe, payment);
                        pe.Save.Press();

                        object[] persisted = PXTimeStampScope.GetPersisted(pe.Document.Cache, pe.Document.Current);
                        if (persisted == null || persisted.Length == 0)
                        {
                            //preserve timestamp which will be @@dbts after last record committed to db on previous Persist().
                            //otherwise another process updated APAdjust.
                            docs.Add(payment);
                        }
                        else
                        {
                            if (payment.Passed == true)
                            {
                                pe.Document.Current.Passed = true;
                            }
                            docs.Add(pe.Document.Current);
                        }
                        successed = true;
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);

                        docs.Add(null);
                        failed = true;
                    }
                }

                if (Action == ReleaseChecksFilter.action.ReprintChecks || Action == ReleaseChecksFilter.action.VoidAndReprintChecks)
                {
                    try
                    {
                        payment.IsPrintingProcess = true;
                        using (PXTransactionScope transactionScope = new PXTransactionScope())
                        {
                            #region Update CABatch if ReprintChecks
                            CABatch caBatch = PXSelectJoin <CABatch,
                                                            InnerJoin <CABatchDetail, On <CABatch.batchNbr, Equal <CABatchDetail.batchNbr> > >,
                                                            Where <CABatchDetail.origModule, Equal <Required <APPayment.origModule> >,
                                                                   And <CABatchDetail.origDocType, Equal <Required <APPayment.docType> >,
                                                                        And <CABatchDetail.origRefNbr, Equal <Required <APPayment.refNbr> > > > > > .
                                              Select(be, payment.OrigModule, payment.DocType, payment.RefNbr);

                            if (caBatch != null)
                            {
                                be.Document.Current = caBatch;
                                int           DetailCount = be.Details.Select().Count;                       // load
                                CABatchDetail detail      = be.Details.Locate(new CABatchDetail()
                                {
                                    BatchNbr    = be.Document.Current.BatchNbr,
                                    OrigModule  = payment.OrigModule,
                                    OrigDocType = payment.DocType,
                                    OrigRefNbr  = payment.RefNbr,
                                    OrigLineNbr = CABatchDetail.origLineNbr.DefaultValue,
                                });
                                if (detail != null)
                                {
                                    // payment.Status is recalculated in CABatchEntry.Delete
                                    if (DetailCount == 1)
                                    {
                                        be.Document.Delete(be.Document.Current);                                         // Details will delete by PXParent
                                    }
                                    else
                                    {
                                        be.Details.Delete(detail);                                          // recalculated batch totals
                                    }
                                }
                                be.Save.Press();
                            }
                            else
                            {
                                PXCache cacheAPPayment = releaseChecksGraph.APPaymentList.Cache;

                                cacheAPPayment.SetValueExt <APPayment.printed>(payment, false);
                                cacheAPPayment.SetValueExt <APPayment.hold>(payment, false);
                                cacheAPPayment.SetValueExt <APPayment.extRefNbr>(payment, null);
                                // APPayment.Status is recalculated by SetStatusCheckAttribute
                                cacheAPPayment.MarkUpdated(payment);

                                cacheAPPayment.PersistUpdated(payment);
                                cacheAPPayment.Persisted(false);
                            }
                            #endregion
                            // TODO: Need to rework. Use legal CRUD methods of caches!
                            releaseChecksGraph.TimeStamp = PXDatabase.SelectTimeStamp();

                            // delete check numbers only if Reprint (not Void and Reprint)
                            PaymentMethod pm = pe.paymenttype.Select(payment.PaymentMethodID);
                            if (pm.APPrintChecks == true && Action == ReleaseChecksFilter.action.ReprintChecks)
                            {
                                APPayment doc = payment;
                                new HashSet <string>(pe.Adjustments_Raw.Select(doc.DocType, doc.RefNbr)
                                                     .RowCast <APAdjust>()
                                                     .Select(adj => adj.StubNbr))
                                .ForEach(nbr => PaymentRefAttribute.DeleteCheck((int)doc.CashAccountID, doc.PaymentMethodID, nbr));

                                // sync PaymentMethodAccount.APLastRefNbr with actual last CashAccountCheck number
                                PaymentMethodAccount det = releaseChecksGraph.cashaccountdetail.SelectSingle(payment.CashAccountID, payment.PaymentMethodID);
                                PaymentRefAttribute.LastCashAccountCheckSelect.Clear(releaseChecksGraph);
                                CashAccountCheck cacheck = PaymentRefAttribute.LastCashAccountCheckSelect.SelectSingleBound(releaseChecksGraph, new object[] { det });
                                det.APLastRefNbr = cacheck?.CheckNbr;
                                releaseChecksGraph.cashaccountdetail.Cache.PersistUpdated(det);
                                releaseChecksGraph.cashaccountdetail.Cache.Persisted(false);
                            }
                            // END TODO
                            if (string.IsNullOrEmpty(payment.ExtRefNbr))
                            {
                                //try to get next number
                                releaseChecksGraph.APPaymentList.Cache.SetDefaultExt <APPayment.extRefNbr>(payment);
                            }
                            transactionScope.Complete();
                        }
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);
                    }
                    docs.Add(null);
                }
            }
            if (successed)
            {
                APDocumentRelease.ReleaseDoc(docs, true);
            }

            if (failed)
            {
                throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased);
            }
        }
Example #11
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);
                    }
                }
            }
        }
Example #12
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);
        }
Example #13
0
 public static void AssignNumbers(APPaymentEntry pe, APPayment doc, ref string NextCheckNbr)
 {
     AssignNumbers(pe, doc, ref NextCheckNbr, false);
 }
Example #14
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);
                }
            }
        }
        protected static void CreatePPDApplications(APPaymentEntry paymentEntry, List <PendingPPDDebitAdjApp> list, APPayment debitAdj)
        {
            foreach (PendingPPDDebitAdjApp doc in list)
            {
                var adj = new APAdjust();
                adj.AdjdDocType = doc.AdjdDocType;
                adj.AdjdRefNbr  = doc.AdjdRefNbr;
                adj             = paymentEntry.Adjustments_Raw.Insert(adj);

                adj.CuryAdjgAmt = doc.InvCuryDocBal;
                adj             = paymentEntry.Adjustments_Raw.Update(adj);

                string refNbr = debitAdj.RefNbr;
                PXUpdate <Set <APAdjust.pPDDebitAdjRefNbr, Required <APAdjust.pPDDebitAdjRefNbr> >, APAdjust,
                          Where <APAdjust.adjdDocType, Equal <Required <APAdjust.adjdDocType> >,
                                 And <APAdjust.adjdRefNbr, Equal <Required <APAdjust.adjdRefNbr> >,
                                      And <APAdjust.adjgDocType, Equal <Required <APAdjust.adjgDocType> >,
                                           And <APAdjust.adjgRefNbr, Equal <Required <APAdjust.adjgRefNbr> >,
                                                And <APAdjust.released, Equal <True>,
                                                     And <APAdjust.voided, NotEqual <True>,
                                                          And <APAdjust.pendingPPD, Equal <True> > > > > > > > >
                .Update(paymentEntry, refNbr, doc.AdjdDocType, doc.AdjdRefNbr, doc.AdjgDocType, doc.AdjgRefNbr);
            }
        }
Example #16
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);
                }
            }
        }
        public static void ReleasePayments(List <APPayment> list, string Action)
        {
            APReleaseChecks releaseChecksGraph = CreateInstance <APReleaseChecks>();
            APPaymentEntry  pe        = CreateInstance <APPaymentEntry>();
            bool            failed    = false;
            bool            successed = false;

            List <APRegister> docs = new List <APRegister>(list.Count);

            foreach (APPayment payment in list)
            {
                if (payment.Passed == true)
                {
                    releaseChecksGraph.TimeStamp = pe.TimeStamp = payment.tstamp;
                }

                switch (Action)
                {
                case ReleaseChecksFilter.action.ReleaseChecks:
                    payment.Printed = true;
                    break;

                case ReleaseChecksFilter.action.ReprintChecks:
                case ReleaseChecksFilter.action.VoidAndReprintChecks:
                    payment.ExtRefNbr = null;
                    payment.Printed   = false;
                    break;

                default:
                    continue;
                }

                PXProcessing <APPayment> .SetCurrentItem(payment);

                if (Action == ReleaseChecksFilter.action.ReleaseChecks)
                {
                    try
                    {
                        pe.Document.Current = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        if (PaymentRefAttribute.PaymentRefMustBeUnique(pe.paymenttype.Current) && string.IsNullOrEmpty(payment.ExtRefNbr))
                        {
                            throw new PXException(ErrorMessages.FieldIsEmpty, typeof(APPayment.extRefNbr).Name);
                        }

                        payment.IsReleaseCheckProcess = true;

                        APPrintChecks.AssignNumbersWithNoAdditionalProcessing(pe, payment);
                        pe.Save.Press();

                        object[] persisted = PXTimeStampScope.GetPersisted(pe.Document.Cache, pe.Document.Current);
                        if (persisted == null || persisted.Length == 0)
                        {
                            //preserve timestamp which will be @@dbts after last record committed to db on previous Persist().
                            //otherwise another process updated APAdjust.
                            docs.Add(payment);
                        }
                        else
                        {
                            if (payment.Passed == true)
                            {
                                pe.Document.Current.Passed = true;
                            }
                            docs.Add(pe.Document.Current);
                        }
                        successed = true;
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);

                        docs.Add(null);
                        failed = true;
                    }
                }

                if (Action == ReleaseChecksFilter.action.ReprintChecks || Action == ReleaseChecksFilter.action.VoidAndReprintChecks)
                {
                    try
                    {
                        payment.IsPrintingProcess = true;

                        releaseChecksGraph.APPaymentList.Cache.SetValueExt <APPayment.printed>(payment, false);
                        releaseChecksGraph.APPaymentList.Cache.SetValueExt <APPayment.hold>(payment, false);
                        releaseChecksGraph.APPaymentList.Cache.SetValueExt <APPayment.extRefNbr>(payment, null);

                        releaseChecksGraph.APPaymentList.Cache.RaiseRowSelected(payment);                         //We need payment's status to be set correctly before persisting
                        // TODO: Need to rework. Use legal CRUD methods of caches!
                        releaseChecksGraph.APPaymentList.Cache.PersistUpdated(payment);
                        releaseChecksGraph.APPaymentList.Cache.Persisted(false);

                        releaseChecksGraph.TimeStamp = PXDatabase.SelectTimeStamp();

                        // delete check numbers only if Reprint (not Void and Reprint)
                        PaymentMethod pm = pe.paymenttype.Select(payment.PaymentMethodID);
                        if (pm.APPrintChecks == true && Action == ReleaseChecksFilter.action.ReprintChecks)
                        {
                            APPayment doc = payment;
                            new HashSet <string>(pe.Adjustments_Raw.Select(doc.DocType, doc.RefNbr)
                                                 .RowCast <APAdjust>()
                                                 .Select(adj => adj.StubNbr))
                            .ForEach(nbr => PaymentRefAttribute.DeleteCheck((int)doc.CashAccountID, doc.PaymentMethodID, nbr));

                            // sync PaymentMethodAccount.APLastRefNbr with actual last CashAccountCheck number
                            PaymentMethodAccount det = releaseChecksGraph.cashaccountdetail.SelectSingle(payment.CashAccountID, payment.PaymentMethodID);
                            PaymentRefAttribute.LastCashAccountCheckSelect.Clear(releaseChecksGraph);
                            CashAccountCheck cacheck = PaymentRefAttribute.LastCashAccountCheckSelect.SelectSingleBound(releaseChecksGraph, new object[] { det });
                            det.APLastRefNbr = cacheck?.CheckNbr;
                            releaseChecksGraph.cashaccountdetail.Cache.PersistUpdated(det);
                            releaseChecksGraph.cashaccountdetail.Cache.Persisted(false);
                        }
                        // END TODO
                        if (string.IsNullOrEmpty(payment.ExtRefNbr))
                        {
                            //try to get next number
                            releaseChecksGraph.APPaymentList.Cache.SetDefaultExt <APPayment.extRefNbr>(payment);
                        }
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);
                    }
                    docs.Add(null);
                }
            }
            if (successed)
            {
                APDocumentRelease.ReleaseDoc(docs, true);
            }

            if (failed)
            {
                throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased);
            }
        }
Example #18
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);
                    }
                }
            }
        }
        public static void ReleasePayments(List <APPayment> list, string Action)
        {
            APReleaseChecks graph     = CreateInstance <APReleaseChecks>();
            APPaymentEntry  pe        = CreateInstance <APPaymentEntry>();
            bool            failed    = false;
            bool            successed = false;

            List <APRegister> docs = new List <APRegister>(list.Count);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Passed == true)
                {
                    graph.TimeStamp = pe.TimeStamp = list[i].tstamp;
                }

                switch (Action)
                {
                case "R":
                    list[i].Printed = true;
                    break;

                case "D":
                case "V":
                    list[i].ExtRefNbr = null;
                    list[i].Printed   = false;
                    break;

                default:
                    continue;
                }

                if ((bool)list[i].Printed)
                {
                    try
                    {
                        APPrintChecks.AssignNumbersWithNoAdditionalProcessing(pe, list[i]);
                        pe.Save.Press();

                        object[] persisted = PXTimeStampScope.GetPersisted(pe.Document.Cache, pe.Document.Current);
                        if (persisted == null || persisted.Length == 0)
                        {
                            //preserve timestamp which will be @@dbts after last record committed to db on previous Persist().
                            //otherwise another process updated APAdjust.
                            docs.Add(list[i]);
                        }
                        else
                        {
                            if (list[i].Passed == true)
                            {
                                pe.Document.Current.Passed = true;
                            }
                            docs.Add(pe.Document.Current);
                        }
                        successed = true;
                    }
                    catch (Exception e)
                    {
                        PXProcessing <APPayment> .SetError(i, e);

                        docs.Add(null);
                        failed = true;
                    }
                }
                else
                {
                    try
                    {
                        list[i].Hold = true;
                        // TODO: Need to rework. Use legal CRUD methods of caches!
                        graph.APPaymentList.Cache.PersistUpdated(list[i]);
                        graph.APPaymentList.Cache.Persisted(false);

                        graph.TimeStamp = PXDatabase.SelectTimeStamp();

                        // delete check numbers only if Reprint (not Void and Reprint)
                        PaymentMethod pm = pe.paymenttype.Select(list[i].PaymentMethodID);
                        if (pm.APPrintChecks == true && Action == "D")
                        {
                            APPayment doc = list[i];
                            new HashSet <string>(pe.Adjustments_Raw.Select(doc.DocType, doc.RefNbr, doc.LineCntr)
                                                 .RowCast <APAdjust>()
                                                 .Select(adj => adj.StubNbr))
                            .ForEach(nbr => PaymentRefAttribute.DeleteCheck((int)doc.CashAccountID, doc.PaymentMethodID, nbr));

                            // sync PaymentMethodAccount.APLastRefNbr with actual last CashAccountCheck number
                            PaymentMethodAccount det = graph.cashaccountdetail.SelectSingle(list[i].CashAccountID, list[i].PaymentMethodID);
                            PaymentRefAttribute.LastCashAccountCheckSelect.Clear(graph);
                            CashAccountCheck cacheck = PaymentRefAttribute.LastCashAccountCheckSelect.SelectSingleBound(graph, new object[] { det });
                            det.APLastRefNbr = cacheck == null ? null : cacheck.CheckNbr;
                            graph.cashaccountdetail.Cache.PersistUpdated(det);
                            graph.cashaccountdetail.Cache.Persisted(false);
                        }
                        // END TODO
                        if (string.IsNullOrEmpty(list[i].ExtRefNbr))
                        {
                            //try to get next number
                            graph.APPaymentList.Cache.SetDefaultExt <APPayment.extRefNbr>(list[i]);
                        }
                    }
                    catch (Exception e)
                    {
                        PXProcessing <APPayment> .SetError(i, e);
                    }
                    docs.Add(null);
                }
            }
            if (successed)
            {
                APDocumentRelease.ReleaseDoc(docs, true);
            }

            if (failed)
            {
                throw new PXException(GL.Messages.DocumentsNotReleased);
            }
        }