修改发布“帐单和调整”文档时生成的GL批次

时间:2018-03-09 16:59:32

标签: acumatica acumatica-kb

目标是从AP账单页面生成日记账交易,并在GLTran中添加2个额外的行。

第一次尝试

首先,我将“日记帐交易”图表中的“发布”操作扩展为包含2个新行:

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

结果:创建并发布批次,正确输入2个新行。

在此之后,我认为发布AP Bill还会触发GL Page的扩展逻辑。但是,这并没有发生 - 条例草案的发布似乎并没有重新使用GL页面中定义的 Release 逻辑。

第二次尝试

然后,我回到GL页面并将逻辑包含在RowPersisted事件中,以便在保存文档后立即创建2个新行:

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

        }
    }

结果:正确创建和保存批次,输入了2个新行。

在此之后,我认为发布AP账单将触发此扩展事件,因为应该从Bill页面创建和使用日记帐分录图,但在这种情况下,同时发布AP账单,没有添加生成的批次中有2个新行。

第三次尝试

然后我想我可以扩展比尔的发布行动,并通过搜索&lt;&gt;控制生成的日记帐分录。方法。但是,在这种情况下,扩展逻辑似乎在事务中执行,因为Document.Current.BatchNbr仍为NULL:

Current BatchNbr Null

第四次尝试

最后,我尝试扩展APReleaseProcess的Persist()方法,类似于指南T300中的方法,但是没有列出任何方法(版本17.207.0029):

enter image description here

关于如何进入这些GL线的任何其他想法?

谢谢!

1 个答案:

答案 0 :(得分:2)

希望这并不会让你永远经历这4次尝试......但我必须说,你问题中的努力和细节数量令人印象深刻,非常感谢!

在为AP账单生成的批次中插入2个额外的GL交易需要两步定制:

  1. 要插入其他总帐交易,您需要覆盖 JournalEntry BLC扩展程序中的持久方法,并调用逻辑以仅在自定义<时插入其他GLTrans strong> ModifyBatchFromAP 布尔标志值等于 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. 之后在 APInvoiceEntry_Extension 中的重写发布操作中,您将为订阅 InstanceCreated 事件JournalEntry BLC类型将 ModifyBatchFromAP 标记值设置为 True ,允许您从第1步开始执行的逻辑仅为AP文件:

    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);
            }
        }
    }
    
  3. P.S。由于应用了PXHiddenAttribute,目前无法使用 APReleaseProcess 类的“选择方法覆盖”对话框。让我把它转发给我们的工程团队,让他们关注这个问题。