【问题标题】:Modifying the GL Batch generated when a Bills and Adjustments document is released修改下达账单和调整单时生成的 GL 批次
【发布时间】:2018-03-13 05:13:32
【问题描述】:

目标是获取从 AP 账单页面生成的日记帐交易,并在 GLTran 中添加 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 账单会触发此扩展事件,因为应该从账单页面创建和使用日记帐分录图,但在这种情况下,同时发布 AP 账单,并没有添加生成的 Batch 中有 2 个新行。

第三次尝试

然后我想我可以扩展 Bill 的 Release 操作并使用 Search 方法控制生成的 Journal Entry。但是,在这种情况下,扩展逻辑似乎在事务中执行,因为 Document.Current.BatchNbr 仍然为 NULL:

第四次尝试

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

关于如何输入这些 GL 行还有其他想法吗?

谢谢!

【问题讨论】:

    标签: acumatica acumatica-kb


    【解决方案1】:

    希望,这 4 次尝试并没有让您花太多时间……但我不得不说,您问题中的努力和细节令人印象深刻,非常感谢!

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

    1. 要插入额外的 GL Transactions,您需要在 JournalEntry BLC 扩展中重写 Persist 方法,并仅在自定义 ModifyBatchFromAP 时调用插入额外 GLTrans 的逻辑 布尔标志值等于 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 中覆盖的 Release 操作中,您将为 JournalEntry 订阅 InstanceCreated 事件strong> 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);
              }
          }
      }
      

    附:由于应用了 PXHiddenAttribute 类,目前无法将 Select Method to Override 对话框与 APReleaseProcess 类一起使用。让我将此转发给我们的工程团队,以引起他们对此事的关注。

    【讨论】:

    • 感谢鲁斯兰的详细回复!我会试一试,然后告诉你结果。
    • 做到了。谢谢鲁斯兰!
    • 不客气,@BillBlake!很高兴这得到了解决。我可以请你接受我的回答吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    相关资源
    最近更新 更多