0

The goal is taking the Journal Transaction generated from the AP Bill page and adding 2 additional rows in GLTran.

1st Attempt

First, I extended the Release action from the Journal Transactions graph to include the 2 new lines:

        public class JournalEntryExt : PXGraphExtension<JournalEntry>
{
    public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
    [PXOverride]
    public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
    {
        baseMethod(adapter);

        //new code
        GLTran tranRow = new GLTran();
        tranRow = this.Base.GLTranModuleBatNbr.Insert(tranRow);

        tranRow.AccountID = 2713;
        tranRow.SubID = 467;
        tranRow.CuryDebitAmt = 100;
        this.Base.GLTranModuleBatNbr.Update(tranRow);


        tranRow = new GLTran();
        tranRow = this.Base.GLTranModuleBatNbr.Insert(tranRow);

        tranRow.AccountID = 1514;
        tranRow.SubID = 467;
        tranRow.CuryCreditAmt = 100;
        this.Base.GLTranModuleBatNbr.Update(tranRow);

        this.Base.Actions.PressSave();


        return adapter.Get();
    }

Result: Creating and releasing the batch, entered the 2 new lines correctly.

After this, I thought that releasing the AP Bill would also trigger this extended logic from the GL Page. However, that didn't occur - The release of the Bill doesn't seem to re-use the Release logic defined in the GL page.

2nd Attempt

Then, I went back to the GL page and included the logic in the RowPersisted event, so that the 2 new lines would get created right after saving the document:

    public class JournalEntryExt : PXGraphExtension<JournalEntry>
    {
        protected virtual void Batch_RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
    {
        if (e.Row == null)
        {
            return;
        }

        Batch batchRow = (Batch)e.Row;

        if (batchRow != null
                && e.Operation == PXDBOperation.Insert
                && e.TranStatus == PXTranStatus.Completed)
        {
            ////new code
            GLTran tranRow = new GLTran();
            tranRow = this.Base.GLTranModuleBatNbr.Insert(tranRow);

            tranRow.AccountID = 2713;
            tranRow.SubID = 467;
            tranRow.CuryDebitAmt = 102;
            this.Base.GLTranModuleBatNbr.Update(tranRow);


            tranRow = new GLTran();
            tranRow = this.Base.GLTranModuleBatNbr.Insert(tranRow);

            tranRow.AccountID = 1514;
            tranRow.SubID = 467;
            tranRow.CuryCreditAmt = 102;
            this.Base.GLTranModuleBatNbr.Update(tranRow);

        }
    }

Result: Creating and saving the Batch correctly entered the 2 new lines.

After this, I thought that releasing the AP Bill would trigger this extended event, given that a Journal Entry graph should get created and used from the Bill page, but in this case, also releasing the AP Bill, did not add the 2 new lines in the generated Batch.

3rd Attempt

Then I thought I could extend the Bill's Release action and take control of the generated Journal Entry with the Search<> method. However, in this case, the extended logic seems to be executed within a transaction as the Document.Current.BatchNbr was still NULL:

Current BatchNbr Null

4th Attempt

Finally, I tried to extend the Persist() method of APReleaseProcess similarly to how it's done in the guide T300, however none of the methods are listed (version 17.207.0029):

enter image description here

Any other ideas as to how to enter these GL Lines?

Thanks!

RuslanDev
  • 6,718
  • 1
  • 14
  • 27
Bill Blake
  • 104
  • 7

1 Answers1

4

Hopefully, it didn't take you forever to go through these 4 attempts... I've got to say though, the number of efforts and details in your question is quite impressive and definitely very appreciated!

A 2-step customization will be required to insert 2 additional GL Transactions in the Batch generated for an AP Bill:

  1. to insert additional GL Transactions, you need to override Persist method within the JournalEntry BLC extension and invoke the logic to insert additional GLTrans only if the custom ModifyBatchFromAP boolean flag value equals True:

    using PX.Data;
    using System;
    
    namespace PX.Objects.GL
    {
        public class JournalEntry_Extension : PXGraphExtension<JournalEntry>
        {
            private bool modifyBatchFromAP = false;
    
            public bool ModifyBatchFromAP
            {
                get
                {
                    return modifyBatchFromAP;
                }
                set
                {
                    modifyBatchFromAP = value;
                }
            }
    
            [PXOverride]
            public void Persist(Action del)
            {
                if (ModifyBatchFromAP)
                {
                    var glTran = Base.GLTranModuleBatNbr.Insert();
                    Base.GLTranModuleBatNbr.SetValueExt<GLTran.accountID>(glTran, "20000");
                    glTran = Base.GLTranModuleBatNbr.Update(glTran);
                    Base.GLTranModuleBatNbr.SetValueExt<GLTran.subID>(glTran, "000000");
                    glTran.CuryDebitAmt = 100;
                    glTran.TranDesc = "Additional Debit Transaction for AP Doc";
                    Base.GLTranModuleBatNbr.Update(glTran);
    
                    glTran = Base.GLTranModuleBatNbr.Insert();
                    Base.GLTranModuleBatNbr.SetValueExt<GLTran.accountID>(glTran, "20200");
                    glTran = Base.GLTranModuleBatNbr.Update(glTran);
                    Base.GLTranModuleBatNbr.SetValueExt<GLTran.subID>(glTran, "000000");
                    glTran.CuryCreditAmt = 100;
                    glTran.TranDesc = "Additional Credit Transaction for AP Doc";
                    Base.GLTranModuleBatNbr.Update(glTran);
                }
    
                del();
            }
        }
    }
    
  2. after that in the overridden Release action within the APInvoiceEntry_Extension, you will subscribe to the InstanceCreated event for the JournalEntry BLC type to set ModifyBatchFromAP flag value to True allowing your logic from step 1 to execute for the Batch generated only for an AP document:

    using PX.Data;
    using PX.Objects.GL;
    using System.Collections;
    
    namespace PX.Objects.AP
    {
        public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
        {
            public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
    
            [PXOverride]
            public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
            {
                PXGraph.InstanceCreated.AddHandler<JournalEntry>((JournalEntry graph) =>
                {
                    graph.GetExtension<JournalEntry_Extension>().ModifyBatchFromAP = true;
                });
    
                return baseMethod(adapter);
            }
        }
    }
    

P.S. it is not currently possible to use the Select Method to Override dialog with the APReleaseProcess class due to PXHiddenAttribute applied to it. Let me forward this to our Engineering Team to bring their attention on that matter.

RuslanDev
  • 6,718
  • 1
  • 14
  • 27