Skip to main content
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
  • 324 views

Forum|alt.badge.img

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

Best answer by Naveen Boga

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

 

View original

Naveen Boga
Captain II
Forum|alt.badge.img+19

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

 


Forum|alt.badge.img+9
  • Semi-Pro I
  • December 1, 2021

Hi @Naveen B Nice sample. 

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


Forum|alt.badge.img
  • Jr Varsity III
  • December 1, 2021

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


Naveen Boga
Captain II
Forum|alt.badge.img+19

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

 


Forum|alt.badge.img
  • Jr Varsity III
  • December 1, 2021

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


Forum|alt.badge.img
  • Jr Varsity III
  • December 4, 2021

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings