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 ProcessPaymentFilter_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { //refresh last number when saved values are populated in filter ProcessPaymentFilter oldRow = (ProcessPaymentFilter)e.OldRow; ProcessPaymentFilter row = (ProcessPaymentFilter)e.Row; if ((oldRow.PayAccountID == null && oldRow.PayTypeID == null) || (oldRow.PayAccountID != row.PayAccountID || oldRow.PayTypeID != row.PayTypeID)) { ((ProcessPaymentFilter)e.Row).CurySelTotal = 0m; ((ProcessPaymentFilter)e.Row).SelTotal = 0m; ((ProcessPaymentFilter)e.Row).SelCount = 0; ((ProcessPaymentFilter)e.Row).NextCheckNbr = null; ARPaymentList.Cache.Clear(); } }
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); } }
protected virtual void ARPayment_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { ProcessPaymentFilter filter = Filter.Current; if (filter != null) { object OldRow = e.OldRow; if (object.ReferenceEquals(e.Row, e.OldRow) && !_copies.TryGetValue(e.Row, out OldRow)) { decimal?curyval = 0m; decimal?val = 0m; int? count = 0; foreach (ARPayment res in ARPaymentList.Select()) { if (res.Selected == true) { curyval += res.CuryOrigDocAmt ?? 0m; val += res.OrigDocAmt ?? 0m; count++; } } filter.CurySelTotal = curyval; filter.SelTotal = val; filter.SelCount = count; } else { ARPayment old_row = OldRow as ARPayment; ARPayment new_row = e.Row as ARPayment; 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; } } }
protected virtual void ProcessPaymentFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { bool SuggestNextNumber = false; ProcessPaymentFilter row = (ProcessPaymentFilter)e.Row; PXUIFieldAttribute.SetVisible <ProcessPaymentFilter.curyID>(sender, null, PXAccess.FeatureInstalled <FeaturesSet.multicurrency>()); if (e.Row != null && cashaccountdetail.Current != null && (!Equals(cashaccountdetail.Current.CashAccountID, row.PayAccountID) || !Equals(cashaccountdetail.Current.PaymentMethodID, row.PayTypeID))) { cashaccountdetail.Current = null; SuggestNextNumber = true; } if (e.Row != null && paymenttype.Current != null && (!Equals(paymenttype.Current.PaymentMethodID, row.PayTypeID))) { paymenttype.Current = null; } if (e.Row != null && string.IsNullOrEmpty(row.NextCheckNbr)) { SuggestNextNumber = true; } PXUIFieldAttribute.SetVisible <ProcessPaymentFilter.nextCheckNbr>(sender, null, true); if (e.Row == null) { return; } if (cashaccountdetail.Current != null && true == cashaccountdetail.Current.ARAutoNextNbr && SuggestNextNumber) { row.NextCheckNbr = string.IsNullOrEmpty(cashaccountdetail.Current.ARLastRefNbr) == false?AutoNumberAttribute.NextNumber(cashaccountdetail.Current.ARLastRefNbr) : string.Empty; } sender.RaiseExceptionHandling <ProcessPaymentFilter.payTypeID>(e.Row, row.PayTypeID, paymenttype.Current != null && true != PXCache <PaymentMethod> .GetExtension <PaymentMethodExt>(paymenttype.Current).ARCreateBatchPayment ? new PXSetPropertyException(AP.Messages.PaymentTypeNoPrintCheck, PXErrorLevel.Warning) : null); sender.RaiseExceptionHandling <ProcessPaymentFilter.nextCheckNbr>(e.Row, row.NextCheckNbr, paymenttype.Current != null && paymenttype.Current.PrintOrExport == true && String.IsNullOrEmpty(row.NextCheckNbr) ? new PXSetPropertyException(AP.Messages.NextCheckNumberIsRequiredForProcessing, PXErrorLevel.Warning) : !string.IsNullOrEmpty(row.NextCheckNbr) && !AutoNumberAttribute.CanNextNumber(row.NextCheckNbr) ? new PXSetPropertyException(AP.Messages.NextCheckNumberCanNotBeInc, PXErrorLevel.Warning) : null); if (/*HttpContext.Current != null && */ Filter.Current.BranchID != PXAccess.GetBranchID()) { Filter.Current.BranchID = PXAccess.GetBranchID(); } ProcessPaymentFilter filter = Filter.Current; PaymentMethod pt = paymenttype.Current; ARPaymentList.SetProcessTooltip(Messages.Process); ARPaymentList.SetProcessAllTooltip(Messages.ProcessAll); ARPaymentList.SetProcessDelegate( delegate(List <ARPayment> list) { var graph = CreateInstance <ARProcessPayment>(); graph.ProcessPayments(list, filter, pt); } ); }