@jinin Yes it is in release status
Hi @FarhanaM60 I have verified this and I can able to create the Checks and Payments document successfully . Please find the code and screenshots for your reference.
public class APInvoiceEntryExt : PXGraphExtension<APInvoiceEntry> { public PXAction<APInvoice> CheckPay; PXUIField(DisplayName = "Check Pay Test", MapEnableRights = PXCacheRights.Select)] protected virtual IEnumerable checkPay(PXAdapter adapter, ,PXString()] string ActionName) { if (Base.Document.Current != null) { APPaymentEntry grp = PXGraph.CreateInstance<APPaymentEntry>(); APPayment payment = new APPayment(); payment.DocType = APDocType.Check; payment = PXCache<APPayment>.CreateCopy(grp.Document.Insert(payment)); payment.VendorID = Base.Document.Current.VendorID; payment.VendorLocationID = Base.Document.Current.PayLocationID; // payment.AdjDate = row.PmtDate; payment.CuryID = Base.Document.Current.CuryID; payment.PaymentMethodID = Base.Document.Current.PayTypeID; payment.DocDesc = Base.Document.Current.DocDesc; grp.FieldDefaulting.AddHandler<APPayment.cashAccountID>((sender, e) => { if (Base.Document.Current.DocType == APDocType.Prepayment) { e.NewValue = null; e.Cancel = true; } }); grp.FieldDefaulting.AddHandler<CurrencyInfo.curyID>((sender, e) => { if (e.Row != null) { e.NewValue = ((CurrencyInfo)e.Row).CuryID; e.Cancel = true; } }); payment = grp.Document.Update(payment); decimal? controlamt = 0; grp.Document.Current = payment; APAdjust adj = new APAdjust(); adj.AdjdDocType = APDocType.Invoice; adj.AdjdRefNbr = Base.Document.Current.RefNbr; adj.CuryAdjgAmt = Base.Document.Current.CuryLineTotal; adj = grp.Adjustments.Insert(adj); if (grp.Adjustments.Select().Count > 0) { payment.CuryOrigDocAmt = controlamt; //payment.CuryApplAmt = row.TotAmt; payment = grp.Document.Update(payment); APPayment copy = grp.Document.Cache.CreateCopy(payment) as APPayment; grp.Document.Cache.RaiseRowUpdated(payment, copy); payment = grp.Document.Update(payment); grp.Actions.PressSave(); } } return adapter.Get(); } }
Hi @jinin . Thank You for your reply .. I will try now and let you know
ok @FarhanaM60 . Will check and update you.
@FarhanaM60 Can you make sure the document is already released? If the document is not released also we will get this error.
@FarhanaM60 Are you able to apply manually with this reference number?
@Naveen B Manually i can apply
@FarhanaM60 Can you please try with below code. Hope this helps!
APPaymentEntry docgraph = PXGraph.CreateInstance<APPaymentEntry>(); docgraph.Clear(); APPayment newPayment = new APPayment(); newPayment.DocType = APDocType.Check; newPayment.PaymentMethodID = paymentmethodid; // Ordergraph.Document.Current.PaymentMethodID; newPayment.CuryOrigDocAmt = amount; docgraph.Document.Cache.Insert(newPayment); docgraph.Document.Current.PMInstanceID = Ordergraph.Document.Current.PMInstanceID; docgraph.Document.Current.CashAccountID = Ordergraph.Document.Current.CashAccountID; docgraph.Document.Current.ExtRefNbr = Ordergraph.Document.Current.GetExtension<SOOrderAMIExt>().UsrKNPaymentRefNbr; docgraph.Document.Cache.Update(docgraph.Document.Current); docgraph.Save.Press(); APAdjust adjnew = new APAdjust(); adjnew.AdjdRefNbr = Ordergraph.Document.Current.OrderNbr; adjnew.AdjdDocType = Ordergraph.Document.Current.OrderType; adjnew.CuryAdjgAmt = amount; docgraph.Adjustments.Cache.Insert(adjnew); docgraph.Save.Press();
@Naveen B -Thank You I will try and let you know
@FarhanaM60 Sure. If this is not working, can you please share your graph code.
@Naveen B -the given code is against to the bill for Sales Order I think
am pasting my graph code please check and let me know
grp.Clear(); APPayment payment = new APPayment(); payment.DocType = APDocType.Check; payment = PXCache<APPayment>.CreateCopy(grp.Document.Insert(payment)); payment.VendorID = inv.VendorID; payment.VendorLocationID = inv.PayLocationID; payment.AdjDate = row.PmtDate; payment.CuryID = inv.CuryID; payment.PaymentMethodID = inv.PayTypeID; payment.DocDesc = inv.DocDesc; this.FieldDefaulting.AddHandler<APPayment.cashAccountID>((sender, e) => { if (inv.DocType == APDocType.Prepayment) { e.NewValue = null; e.Cancel = true; } }); this.FieldDefaulting.AddHandler<CurrencyInfo.curyID>((sender, e) => { if (e.Row != null) { e.NewValue = ((CurrencyInfo)e.Row).CuryID; e.Cancel = true; } });
payment = grp.Document.Update(payment); decimal? controlamt = 0; grp.Document.Current = payment;
APAdjust adj = new APAdjust(); //adj = PXCache<APAdjust>.CreateCopy(grp.Adjustments.Insert(adj)); adj.AdjdDocType = APDocType.Invoice; adj.AdjdRefNbr = inv.RefNbr; adj.CuryAdjgAmt = inv.CuryLineTotal;
//grp.Adjustments.Cache.RaiseFieldUpdated<APAdjust.adjdRefNbr>(adj, null); adj = grp.Adjustments.Insert(adj);
foreach (TSAWSPayment lin in PXSelect<TSAWSPayment, Where<TSAWSPayment.printNbr, Equal<Required<TSAWSPayment.printNbr>>, And<TSAWSPayment.vendorID, Equal<Required<TSAWSPayment.vendorID>>>>>.Select(this, row.PrintNbr, row.VendorID))
{ TSAWSPayment payrow = lin; //InsertAPAdjustments(payrow, grp, payment,inv); //grp.Adjustments.Current = grp.Adjustments.Search<APAdjust.adjdDocType, APAdjust.adjdRefNbr>(inv.DocType, inv.RefNbr); APAdjust adj1 = new APAdjust(); //adj = PXCache<APAdjust>.CreateCopy(grp.Adjustments.Insert(adj)); adj.AdjdDocType = APDocType.Invoice; adj.AdjdRefNbr = inv.RefNbr; adj.CuryAdjgAmt = inv.CuryLineTotal;
//grp.Adjustments.Cache.RaiseFieldUpdated<APAdjust.adjdRefNbr>(adj, null); adj=grp.Adjustments.Insert(adj); controlamt = controlamt + payrow.ApplytoAmt; } if (grp.Adjustments.Select().Count > 0) { payment.CuryOrigDocAmt = controlamt; payment.CuryApplAmt = row.TotAmt; payment = grp.Document.Update(payment); APPayment copy = grp.Document.Cache.CreateCopy(payment) as APPayment; grp.Document.Cache.RaiseRowUpdated(payment, copy); payment = grp.Document.Update(payment); grp.Actions.PressSave();
Ok @FarhanaM60 Thanks for sharing the code, will take a look and let you know.
Hi @FarhanaM60 Can you please confirm on this?
I do not see any INVOICE type here
@Naveen B -APDoctype.invoice means bill.. its saving in backend as inv
@FarhanaM60 Gotcha! Thanks for clarifying!
@Naveen B -Thank you for your effort .. I think you have added Button in Bills From there you have tried Right?? But i have done From processing Screen.. Yes from where we are doing is not the issue but when it is working it will be good .. But unfortunately its not working for me
Hi @FarhanaM60 Yes, that is correct.
In your processing screen, you are only doing creation Checks and Payments document OR also creating the Bills and Adjustments document before this creation Checks and Payments ?
Hi @Naveen Boga ,
I’m also trying the same concept from Processing screen, for the insertion of “Debit Adjustment” in Check and payment screen. Actually it is creating the header record, but the Adjustment entries are not getting created without any error. Below is my sample code, could you please help me to check.
APPaymentEntry grp = PXGraph.CreateInstance<APPaymentEntry>(); APInvoice aPayInvoice = PXSelect<APInvoice, Where<APInvoice.refNbr, Equal<Required<APInvoice.refNbr>>, And<APInvoice.docType, Equal<Required<APInvoice.docType>>>>>.Select(this, header.RefNbr, "INV"); APRegister apRegister = PXSelect<APRegister, Where<APRegister.origRefNbr, Equal<Required<APRegister.origRefNbr>>, And<APRegister.origDocType, Equal<Required<APRegister.origDocType>>, And<APRegister.origModule, Equal<Required<APRegister.origModule>>>>>>.Select(this, header.RefNbr, "INV", "AP"); APPayment payment = new APPayment(); payment.DocType = APDocType.DebitAdj; // payment = PXCache<APPayment>.CreateCopy(grp.Document.Insert(payment)); payment.Hold = true; payment.Status = "H"; payment.VendorID = aPayInvoice.VendorID; payment.VendorLocationID = aPayInvoice.PayLocationID; payment.CuryID = aPayInvoice.CuryID; payment.PaymentMethodID = aPayInvoice.PayTypeID; payment.DocDesc = aPayInvoice.DocDesc; grp.FieldDefaulting.AddHandler<APPayment.cashAccountID>((sender, e) => { if (aPayInvoice.DocType == APDocType.DebitAdj) { e.NewValue = null; e.Cancel = true; } }); grp.FieldDefaulting.AddHandler<CurrencyInfo.curyID>((sender, e) => { if (e.Row != null) { e.NewValue = ((CurrencyInfo)e.Row).CuryID; e.Cancel = true; } });
payment = grp.Document.Insert(payment); decimal? controlamt = 0; grp.Document.Current = payment; APAdjust adj = grp.Adjustments.Insert(new APAdjust { AdjdBranchID = this.Accessinfo.BranchID, AdjdDocType = APDocType.Invoice, AdjdRefNbr = aPayInvoice.RefNbr, CuryAdjgAmt = aPayInvoice.CuryLineTotal }); grp.Actions.PressSave();
Regards,
Ramya Krishna
@Naveen B -Only Checks and Payments Record
@FarhanaM60 Then definitely I don’t see any issue with the code, but also not sure why it is not working in your instance.
Hi @FarhanaM60
Can you assign the value for below fields and check once ? We did this for one of our project and works fine for us.
APAdjust adjnew = new APAdjust(); adjnew.AdjdDocType = ARDocType.Payment; adjnew.AdjdRefNbr = objlist.RefNbr; adjnew.CuryAdjgAmt = objlist.OpenOrderTotal; docgraph.Adjustments.Insert(adjnew);
docgraph.Actions.PressSave();
Same issue @jinin an error occurred ref nbr cannot be found