首页 > 解决方案 > 在发布后的发票和备忘录上,我们启用了页眉和页脚的自定义字段,但在修改余额时更新错误值

问题描述

如果状态已关闭且余额 = 0,我需要启用一些自定义字段,包括页眉和页脚,然后如果我们修改持久委托上的任何页脚字段值,设置修改后字段的值并更新事务缓存(下面的示例代码)然后余额 0 正在更新发票总计字段的值。

public class KWARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
    {
[PXOverride]
        public void Persist(Action del)
        {            
            if ((Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.Inserted || Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.Updated))
            {
                foreach (ARTran items in Base.Transactions.Select())
                {

                    if (Base.Document.Current.DocType == ARDocType.Invoice)
                    {
                        if (Base.Document.Current.Released == true)
                        {
                             Base.Transactions.Cache.SetValue<ARTran.curyTranAmt>(items, items.CuryTranAmt);
                        }
                    }
                        Base.Transactions.Update(items);
                }
            }
            del();
        }
   }

在修改网格中的任何字段之前,请查看余额值

修改网格字段后,查看余额值

标签: acumatica

解决方案


这发生在 ARInvoiceEntry.ARTran_RowUpdated 事件中。通常在 Acumatica 中,您无法更新已发布的交易,因此那里没有其他条件,并且一旦您尝试更新任何值并保存交易 - 余额的计算方式与平衡文档的计算方式相同。

protected virtual void ARTran_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
    ARTran row = (ARTran)e.Row;
    ARTran oldRow = (ARTran)e.OldRow;
    if (row != null)
    {
        if ((!sender.ObjectsEqual<ARTran.branchID>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.inventoryID>(e.Row, e.OldRow) ||
            !sender.ObjectsEqual<ARTran.baseQty>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.curyUnitPrice>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.curyTranAmt>(e.Row, e.OldRow) ||
            !sender.ObjectsEqual<ARTran.curyExtPrice>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.curyDiscAmt>(e.Row, e.OldRow) ||
            !sender.ObjectsEqual<ARTran.discPct>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.manualDisc>(e.Row, e.OldRow) ||
            !sender.ObjectsEqual<ARTran.discountID>(e.Row, e.OldRow)) && row.LineType != SOLineType.Discount)
            RecalculateDiscounts(sender, row);

        if (row.ManualDisc != true)
        {
            var discountCode = (ARDiscount)PXSelectorAttribute.Select<SOLine.discountID>(sender, row);
            row.DiscPctDR = (discountCode != null && discountCode.IsAppliedToDR == true) ? row.DiscPct : 0.0m;
        }

        if ((e.ExternalCall || sender.Graph.IsImport)
            && sender.ObjectsEqual<ARTran.inventoryID>(e.Row, e.OldRow) && sender.ObjectsEqual<ARTran.uOM>(e.Row, e.OldRow)
            && sender.ObjectsEqual<ARTran.qty>(e.Row, e.OldRow) && sender.ObjectsEqual<ARTran.branchID>(e.Row, e.OldRow)
            && sender.ObjectsEqual<ARTran.siteID>(e.Row, e.OldRow) && sender.ObjectsEqual<ARTran.manualPrice>(e.Row, e.OldRow)
            && (!sender.ObjectsEqual<ARTran.curyUnitPrice>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.curyExtPrice>(e.Row, e.OldRow))
            && row.ManualPrice == oldRow.ManualPrice)
            row.ManualPrice = true;

        if (row.ManualPrice != true)
        {
            row.CuryUnitPriceDR = row.CuryUnitPrice;
        }

        // BALANCE WILL BE CALCULATED HERE!!!
        //
        TaxAttribute.Calculate<ARTran.taxCategoryID>(sender, e); 

        //Validate that Sales Account <> Deferral Account:
        if (!sender.ObjectsEqual<ARTran.accountID, ARTran.deferredCode>(e.Row, e.OldRow))
        {
            if (!string.IsNullOrEmpty(row.DeferredCode))
            {
                DRDeferredCode defCode = PXSelect<DRDeferredCode, Where<DRDeferredCode.deferredCodeID, Equal<Required<DRDeferredCode.deferredCodeID>>>>.Select(this, row.DeferredCode);
                if (defCode != null)
                {
                    if (defCode.AccountID == row.AccountID)
                    {
                        sender.RaiseExceptionHandling<ARTran.accountID>(e.Row, row.AccountID,
                            new PXSetPropertyException(Messages.AccountIsSameAsDeferred, PXErrorLevel.Warning));
                    }
                }
            }
        }
    }
}

因此,您只需覆盖 ARInvoiceEntry.ARTran_RowUpdated 事件并禁用已发布文档的计算。像这样的东西:

[Serializable]
public class ARInvoiceEntry_Extension : PXGraphExtension<ARInvoiceEntry>
{
    public delegate void EventDelegate(PXCache sender, PXRowUpdatedEventArgs e);

    [PXOverride]
    public void ARTran_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e, EventDelegate baseMethod)
    {
        if (Base.Document.Current.Released != true)
        {
            baseMethod.Invoke(sender, e);
        }
    }
}

推荐阅读