public static CABatch CreateBatchPayment(List <APPayment> list, PrintChecksFilter filter) { CABatchEntry be = CreateInstance <CABatchEntry>(); CABatch result = be.Document.Insert(new CABatch()); be.Document.Current = result; CABatch copy = (CABatch)be.Document.Cache.CreateCopy(result); copy.CashAccountID = filter.PayAccountID; copy.PaymentMethodID = filter.PayTypeID; result = be.Document.Update(copy); foreach (APPayment iPmt in list) { if (iPmt.CashAccountID != result.CashAccountID || iPmt.PaymentMethodID != result.PaymentMethodID) { throw new PXException(Messages.APPaymentDoesNotMatchCABatchByAccountOrPaymentType); } if (string.IsNullOrEmpty(iPmt.ExtRefNbr) && string.IsNullOrEmpty(filter.NextCheckNbr)) { throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing); } be.AddPayment(iPmt, true); } be.Save.Press(); result = be.Document.Current; return(result); }
public static CABatch CreateBatchPayment(List <ARPayment> list, ProcessPaymentFilter filter) { CABatch result = new CABatch(); //var resultExt = PXCache<CABatch>.GetExtension<CABatchExt>(result); //resultExt.BatchModule = GL.BatchModule.AR; ARBatchEntry be = PXGraph.CreateInstance <ARBatchEntry>(); result = be.Document.Insert(result); be.Document.Current = result; CABatch copy = (CABatch)be.Document.Cache.CreateCopy(result); copy.CashAccountID = filter.PayAccountID; copy.PaymentMethodID = filter.PayTypeID; be.Document.SetValueExt <CABatchExt.batchModule>(copy, GL.BatchModule.AR); result = be.Document.Update(copy); foreach (ARPayment iPmt in list) { if (iPmt.CashAccountID != result.CashAccountID || iPmt.PaymentMethodID != iPmt.PaymentMethodID) { throw new PXException(AP.Messages.APPaymentDoesNotMatchCABatchByAccountOrPaymentType); } if (String.IsNullOrEmpty(iPmt.ExtRefNbr) && string.IsNullOrEmpty(filter.NextCheckNbr)) { throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing); } CABatchDetail detail = be.AddPayment(iPmt); } be.Save.Press(); result = be.Document.Current; return(result); }
protected virtual void RedirectToResultWithCreateBatch(CABatch batch) { CABatchEntry be = CreateInstance <CABatchEntry>(); be.Document.Current = be.Document.Search <CABatch.batchNbr>(batch.BatchNbr); be.SelectTimeStamp(); throw new PXRedirectRequiredException(be, "Redirect"); }
public virtual void RecalcTotals() { CABatch row = this.Document.Current; if (row != null) { row.DetailTotal = row.CuryDetailTotal = row.CuryTotal = row.Total = decimal.Zero; foreach (PXResult <ARPayment, CABatchDetail> it in this.ARPaymentList.Select()) { ARPayment pmt = it; if (!String.IsNullOrEmpty(pmt.RefNbr)) { row.CuryDetailTotal += pmt.CuryOrigDocAmt; row.DetailTotal += pmt.OrigDocAmt; } } } }
protected virtual void ProcessPayments(List <ARPayment> list, ProcessPaymentFilter filter, PaymentMethod paymenttype) { if (list.Count == 0) { return; } CABatch batch = CreateBatchPayment(list, filter); if (batch != null) { bool failed = false; ARPaymentEntryExt pe = PXGraph.CreateInstance <ARPaymentEntryExt>(); string NextCheckNbr = filter.NextCheckNbr; for (int i = 0; i < list.Count; i++) { try { AssignNumbers(pe, list[i], ref NextCheckNbr); var docExt = PXCache <ARPayment> .GetExtension <ARPaymentExt>(list[i]); if (docExt.Passed == true) { pe.TimeStamp = list[i].tstamp; } pe.Save.Press(); list[i].tstamp = pe.TimeStamp; pe.Clear(); } catch (Exception e) { PXProcessing <ARPayment> .SetError(i, e); failed = true; } } if (failed) { throw new PXOperationCompletedWithErrorException(Messages.ARPaymentsAreAddedToTheBatchButWasNotUpdatedCorrectly, batch.BatchNbr); } RedirectToResultWithCreateBatch(batch); } }
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); } }
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); } } } }
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); } } } }