You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何扩展Acumatica AP301000界面TermsID字段的账期日期计算

自定义Acumatica AP账单账期日期计算逻辑

要实现你需要的自定义到期日规则,你需要扩展APInvoiceEntry图中的TermsID字段更新事件,覆盖或补充标准的日期计算逻辑。以下是具体步骤和代码示例:

理解标准流程

Acumatica中默认的账期日期(到期日、折扣日)计算是由TermsHelper类的CalculateDueDates方法处理的,但你看到的APInvoice_TermsID_FieldUpdated方法仅处理了分期账期的调整项清理,并未直接负责日期计算。我们需要在这个事件中添加自定义逻辑来覆盖默认的日期结果。

实现自定义逻辑

创建一个APInvoiceEntry的图形扩展类,通过PXOverride重写TermsID_FieldUpdated方法,先执行标准逻辑,再应用你的自定义日期规则:

using System;
using PX.Data;
using PX.Objects.AP;

public class APInvoiceEntry_CustomTermsExtension : PXGraphExtension<APInvoiceEntry>
{
    [PXOverride]
    public void APInvoice_TermsID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e, PXInvokeBaseHandler baseHandler)
    {
        // 先执行标准的账期变更处理(清理分期调整项)
        baseHandler(sender, e);

        APInvoice invoice = e.Row as APInvoice;
        // 跳过发票日期为空的情况
        if (invoice == null || invoice.InvoiceDate == null) return;

        // 执行自定义到期日计算
        DateTime invoiceDate = invoice.InvoiceDate.Value;
        DateTime thirtyDaysLater = invoiceDate.AddDays(30);

        // 计算下月10日:先取当月第一天,加1个月,再加9天(因为1号+9天是10号)
        DateTime nextMonth10th = new DateTime(invoiceDate.Year, invoiceDate.Month, 1)
                                    .AddMonths(1)
                                    .AddDays(9);
        // 计算下下月10日
        DateTime nextNextMonth10th = nextMonth10th.AddMonths(1);

        // 根据规则确定到期日
        DateTime customDueDate = thirtyDaysLater < nextMonth10th 
                                    ? nextMonth10th 
                                    : nextNextMonth10th;

        // 更新到期日和折扣日(如果折扣日需要和到期日一致,可按需调整)
        invoice.DueDate = customDueDate;
        invoice.DiscountDate = customDueDate;

        // 通知缓存更新数据
        sender.Update(invoice);
    }
}

可选:仅对特定账期应用自定义规则

如果你只想让特定的账期ID使用这个自定义逻辑,而非所有账期,可以添加条件判断:

// 在计算日期前添加判断
if (invoice.TermsID == "NET30_CUSTOM") // 替换为你的目标账期ID
{
    // 执行上述自定义计算逻辑
}
else
{
    // 对其他账期保留标准计算逻辑
    Terms terms = PXSelectorAttribute.Select<APInvoice.termsID>(sender, invoice) as Terms;
    if (terms != null)
    {
        TermsHelper.CalculateDueDates(sender, invoice, terms);
    }
}

测试场景验证

确保测试以下边界场景:

  • 发票日期为1月5日:30天后是2月4日,早于2月10日 → 到期日设为2月10日
  • 发票日期为1月15日:30天后是2月14日,晚于2月10日 → 到期日设为3月10日
  • 发票日期为1月31日:30天后是3月2日,晚于2月10日 → 到期日设为3月10日

内容的提问来源于stack exchange,提问作者Maxime

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:11:47