Question

Checks and Payments-Error: An error occurred during processing of the field Reference Nbr. value 032616 Error: Reference Nbr. '032616' cannot be found in the system.

  • 8 December 2021
  • 24 replies
  • 651 views

Userlevel 1
Badge

Checks and payments entry record creating Programmatically using .csv File

Payment Type    Pmt Number    CashAcct    Pmt Date    VendID    ApplyToVendorRef    ApplyToAmt    TotalAmt
CHECK    10184000001    ORE-OP    11/16/2021    PIOT    INV2809    2185.02    2185.02

 

the above fields i have in csv file.. using Vendor reference number am fetching data from Bills Screen and then am trying to create checks and payments record against to that bill- am able to create header part when coming to insert in APAdjust table am facing an issue above error throwing

Error: An error occurred during processing of the field Reference Nbr. value 032616          Error: Reference Nbr. '032616' cannot be found in the system.

am also sending the code which i have written for APAdjust .. Please suggest me with the Solution

 

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;
                        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 adj = new APAdjust();
                            adj = PXCache<APAdjust>.CreateCopy(grp.Adjustments.Insert(adj));
                            adj.AdjdDocType = inv.DocType;
                            adj.AdjdRefNbr = inv.RefNbr;
                            
                            grp.Adjustments.Cache.RaiseFieldUpdated<APAdjust.adjdRefNbr>(adj, null);
                            adj=grp.Adjustments.Insert(adj);
                            
                            controlamt = controlamt + payrow.ApplytoAmt;
                            
                        }

Version-21.106.0024


24 replies

Userlevel 7
Badge +11

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();

Userlevel 1
Badge

Hi @jinin . Thank You for your reply .. I will try now and let you know

 

Userlevel 1
Badge

Same issue @jinin an error occurred ref nbr cannot be found

 

Userlevel 7
Badge +11

ok @FarhanaM60 . Will check and update you.

Userlevel 1
Badge

Okay Sure

Userlevel 7
Badge +11

@FarhanaM60 

Can you make sure the document is already released? If the document is not released also we will get this error.

Userlevel 7
Badge +17

@FarhanaM60  Are you able to apply manually with this reference number?

Userlevel 1
Badge

@Naveen B  Manually i can apply

 

Userlevel 1
Badge

@jinin Yes it is in release status

Userlevel 7
Badge +17

@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();

 

 

Userlevel 1
Badge

@Naveen B -Thank You I will try and let you know

 

Userlevel 7
Badge +17

@FarhanaM60  Sure.  If this is not working, can you please share your graph code.

Userlevel 1
Badge

Yeah Sure @Naveen B 

Userlevel 1
Badge

@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();

Userlevel 7
Badge +17

Ok @FarhanaM60  Thanks for sharing the code, will take a look and let you know.

Userlevel 7
Badge +17

Hi @FarhanaM60  Can you please confirm on this?

 

 

I do not see any INVOICE type here

 

 

Userlevel 1
Badge

@Naveen B -APDoctype.invoice means bill.. its saving in backend as inv

 

Userlevel 7
Badge +17

@FarhanaM60  Gotcha!  Thanks for clarifying!

Userlevel 7
Badge +17

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();
}
}

 

 

Userlevel 1
Badge

@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

Userlevel 7
Badge +17

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 ?

Userlevel 1
Badge

@Naveen B -Only Checks and Payments Record

Userlevel 7
Badge +17

@FarhanaM60  Then definitely I don’t see any issue with the code, but also not sure why it is not working in your instance.

 

Userlevel 4
Badge

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

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved