Solved

How to insert a new line in GL transaction with newly created account ID for AP Bill(To Replicate Retainage Logic)

  • 30 November 2021
  • 6 replies
  • 294 views

Userlevel 4
Badge

Hi All,

I’m working on the below scenario, could anyone please help on this.

I have created a new GL account category in Vendor card. In AP bill header i have a Boolean field and in Transaction line i have a amount field. Like retainage logic, once i release the Bill, it should create a corresponding line in Journal transaction with the account  and sub account ID linked to the vendor card.

 
​​​​

​​​​​​

Regards,

Ramya

icon

Best answer by Naveen Boga 1 December 2021, 10:57

View original

6 replies

Userlevel 7
Badge +17

Hi @ramya15  I worked on the same kind of requirement from the Payments screen.

Here is sample code, I have attached and hope this helps you!

 

 public PXAction<ARPayment> release;
[PXUIField(DisplayName = "Release", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXButton()]
public IEnumerable Release(PXAdapter adapter)
{
PXGraph.InstanceCreated.AddHandler<JournalEntry>(graph =>
{
graph.RowInserted.AddHandler<Batch>((cache, e) =>
{
var row = (Batch)e.Row;
graph.BatchModule.Current = row;
GLTran crline = new GLTran();
crline.AccountID = Base.Document.Current.ARAccountID;
crline.SubID = Base.Document.Current.ARSubID;

crline.TranType = ARDocType.Payment;
crline.RefNbr = Base.Document.Current.RefNbr;
crline.CuryCreditAmt = 10;
crline.CuryDebitAmt = 0;
crline.Released = true;
graph.GLTranModuleBatNbr.Insert(crline);
});
});
return Base.release.Press(adapter);
}

 

Userlevel 7
Badge +9

Hi @Naveen B Nice sample. 

@ramya15 How are you managing the addition of amount to the “COGS-Subcontractors” shown in your screenshots?

Userlevel 4
Badge

Hi @Naveen B,

Thank you so much. Now i can post into the newly created account, but got a issues.

Actually it is creating a extra line with Rounding Difference , how to fix this issue. Please help me on this.

 

@ChandrasekharM 

I have enabled Subcontract module. Also I created the AP bill from subcontract and then posted into GL accounts.

 

Regards,

Ramya

Userlevel 7
Badge +17

Hi @ramya15  If you wanted to update the existing line, then you need to the conditions and update the line. Just like below.

Hope this helps!

 public PXAction<ARPayment> release;
[PXUIField(DisplayName = "Release", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXButton()]
public IEnumerable Release(PXAdapter adapter)
{
PXGraph.InstanceCreated.AddHandler<JournalEntry>(graph =>
{
graph.RowUpdated.AddHandler<GLTran>((cache, e) =>
{
var crline = (GLTran)e.Row;
graph.GLTranModuleBatNbr.Current = crline;
if (crline.AccountID == cond1 && row.SubID == Cond2)
{

// GLTran crline = new GLTran();
// crline.AccountID = Base.Document.Current.ARAccountID;
// crline.SubID = Base.Document.Current.ARSubID;

crline.TranType = ARDocType.Payment;
crline.RefNbr = Base.Document.Current.RefNbr;
crline.CuryCreditAmt = 10;
crline.CuryDebitAmt = 0;
crline.Released = true;
graph.GLTranModuleBatNbr.Cache.Update(crline);
}
});
});
return Base.release.Press(adapter);
}

 

Userlevel 4
Badge

Hi @Naveen B,

Thanks for your response. 

Using the initial code which was shared by you was working as expected. but only problem is it created a extra line for rounding differnce. Could you please help me to reticfy this. 

 

//Insert LAD amount in to GL Entries
            var invoice = Base.Document.Current;
            var invoiceExt = invoice.GetExtension<APRegisterExt>();
            if (invoiceExt.UsrApplyLAD == true)
            {
                PXGraph.InstanceCreated.AddHandler<JournalEntry>(graph =>
            {
                graph.RowInserted.AddHandler<Batch>((cache, e) =>
                {
                    var row = (Batch)e.Row;
                    graph.BatchModule.Current = row;
                    GLTran crline = new GLTran();

                    BAccount bAccount = PXSelect<BAccount,
                             Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>.Select(Base, invoice.VendorID);
                    var bAccountExt= bAccount.GetExtension<BAccountExt>();

                    crline.AccountID = bAccountExt.UsrVLADAccID;
                    crline.SubID = bAccountExt.UsrVLADSubAccID; 
                    crline.TranType = Base.Transactions.Current.TranType;
                    crline.RefNbr = Base.Document.Current.RefNbr;
                    crline.TranDesc = Base.Transactions.Current.TranDesc;
                    crline.CuryCreditAmt = invoiceExt.UsrLADAmountTotal;
                    crline.CuryDebitAmt = 0;
                    crline.Released = true;
                    graph.GLTranModuleBatNbr.Insert(crline);
                });
            });
            }

 

Thank you,

Ramya

Userlevel 4
Badge

Hi @Naveen B,

I updated the already existing record using the below. Thank you so much.

PXGraph.InstanceCreated.AddHandler<JournalEntry>((graph) =>
            {
                graph.RowInserted.AddHandler<Batch>((cache, args) =>
                {
                    var row = (Batch)args.Row;
                    graph.BatchModule.Current = row;
                    GLTran crline = new GLTran
                    {
                        AccountID = bAccountExt.UsrVLADAccID,
                        SubID = bAccountExt.UsrVLADSubAccID,
                        TranType = Base.Transactions.Current.TranType,
                        RefNbr = Base.Document.Current.RefNbr,
                        TranDesc = Base.Transactions.Current.TranDesc,
                        CuryCreditAmt = 0,
                        CuryDebitAmt = invoiceExt.UsrLADAmountTotal,
                        Released = false
                    };
                    graph.GLTranModuleBatNbr.Insert(crline);
                });

                graph.RowInserted.AddHandler<GLTran>((cache, args) =>
                {
                    var trans = (GLTran)args.Row;
                    if (trans != null && location != null)
                    {
                        if (trans.AccountID == location.VAPAccountID && trans.SubID == location.VAPSubID)
                        {
                            trans.CuryCreditAmt += invoiceExt.UsrLADAmountTotal.GetValueOrDefault(0);
                            graph.GLTranModuleBatNbr.Cache.Update(trans);
                        }
                        /* if (trans.AccountID == bAccountExt.UsrVLADAccID && trans.SubID == bAccountExt.UsrVLADSubAccID)
                         {
                             trans.CuryCreditAmt = 0;
                             graph.GLTranModuleBatNbr.Cache.Update(trans);
                         }*/
                    }
                });
            });

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