扩展术语计算

时间:2018-05-24 14:42:40

标签: acumatica

我试图延长发票条款的计算(字段条款ID,在票据和审核屏幕上(AP301000)

Acumatica的标准行为是:当您更新termsID字段时,它会自动更新dueDate字段和discountDate字段

所以我的想法是查看APInvoiceEntry中的代码并查找TermsID_FieldUpdated

protected virtual void APInvoice_TermsID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
    Terms terms = (Terms)PXSelectorAttribute.Select<APInvoice.termsID>(sender, e.Row);

    if (terms != null && terms.InstallmentType != TermsInstallmentType.Single)
    {
        foreach (APAdjust adj in Adjustments.Select())
        {
            Adjustments.Cache.Delete(adj);
        }
    }
}

但除了删除调整的缓存之外,它似乎什么都不做。而且我不知道要扩展什么以增加另一种计算术语日期的方法。

(目标是允许以下计算: - 我拿发票日期,加30天,如果我在下个月的第10天以下,我将截止日期设定为下个月的第10天,否则我将截止日期设定为第10天下个月的下一个月。)

谢谢,

2 个答案:

答案 0 :(得分:1)

我在DueDate上添加了一个FieldUpdated事件处理程序,并检查了调用堆栈以找到修改DueDate的方法: enter image description here

包含逻辑的[Terms(...)]属性:

#region TermsID
public abstract class termsID : IBqlField
{
}

/// <summary>
/// The <see cref="PX.Objects.CS.Terms">credit terms</see> associated with the document (unavailable for prepayments and debit adjustments).\
/// Defaults to the <see cref="Vendor.TermsID">credit terms of the vendor</see>.
/// </summary>
[PXDBString(10, IsUnicode = true)]
[PXDefault(typeof(Search<Vendor.termsID,
    Where<Vendor.bAccountID, Equal<Current<APInvoice.vendorID>>,
        And<Current<APInvoice.docType>, NotEqual<APDocType.debitAdj>>>>),
    PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Terms", Visibility = PXUIVisibility.Visible)]
[APTermsSelector]
[Terms(typeof(APInvoice.docDate), typeof(APInvoice.dueDate), typeof(APInvoice.discDate), typeof(APInvoice.curyOrigDocAmt), typeof(APInvoice.curyOrigDiscAmt))]
public virtual string TermsID
{
    get;
    set;
}
#endregion

在条款属性中,您将找到修改截止日期的代码。 您可以考虑提供自定义属性或绕过该逻辑。

public static void CalcTermsDates(Terms terms, DateTime? docDate, out DateTime? dueDate, out DateTime? discDate)
{
    dueDate = null;
    discDate = null;
    if (docDate != null && terms != null)
    {
        DateTime DocDate = docDate.Value;
        switch (terms.DueType)
        {
            case TermsDueType.FixedNumberOfDays:
                dueDate = DocDate.AddDays((double)terms.DayDue00);
                break;
            case TermsDueType.Prox:
                DateTime sameDayOfNextMonth = DocDate.AddMonths(1);
                DateTime firstDayOfNextMonth = new DateTime(sameDayOfNextMonth.Year, sameDayOfNextMonth.Month, 1);
                dueDate = firstDayOfNextMonth.AddDays((double)terms.DayDue00);
                break;
            case TermsDueType.DayOfNextMonth:
                dueDate = new PXDateTime(DocDate.Year, DocDate.Month, (int)terms.DayDue00).AddMonths(1);
                break;
            case TermsDueType.DayOfTheMonth:
                int monthShift = DocDate.Day > (int)terms.DayDue00 ? 1 : 0;
                dueDate = new PXDateTime(DocDate.Year, DocDate.Month, (int)terms.DayDue00).AddMonths(monthShift);
                break;
            case TermsDueType.Custom:
                int nextmonth = 0;
                if (DocDate.Day >= terms.DayFrom00 && DocDate.Day <= terms.DayTo00)
                {
                    if (terms.DayDue00 <= terms.DayTo00)
                    {
                        nextmonth = 1;
                    }
                    dueDate = new PXDateTime(DocDate.Year, DocDate.Month, (int)terms.DayDue00).AddMonths(nextmonth);
                }
                if (DocDate.Day >= terms.DayFrom01 && DocDate.Day <= terms.DayTo01)
                {
                    if (terms.DayDue01 <= terms.DayTo01)
                    {
                        nextmonth = 1;
                    }
                    dueDate = new PXDateTime(DocDate.Year, DocDate.Month, (int)terms.DayDue01).AddMonths(nextmonth);
                }
                break;
            case TermsDueType.EndOfMonth:
                dueDate = new DateTime(DocDate.Year, DocDate.Month, 1).AddMonths(1).AddDays(-1);
                break;
            case TermsDueType.EndOfNextMonth:
                dueDate = new DateTime(DocDate.Year, DocDate.Month, 1).AddMonths(2).AddDays(-1);
                break;
            default:
                break;
        }

        if (terms.InstallmentType == TermsInstallmentType.Multiple)
        {
            discDate = dueDate;
        }
        else
        {
        switch (terms.DiscType)
        {
            case TermsDueType.FixedNumberOfDays:
                discDate = DocDate.AddDays((double)terms.DayDisc);
                break;
            case TermsDueType.Prox:
                DateTime sameDayOfNextMonth = DocDate.AddMonths(1);
                DateTime firstDayOfNextMonth = new DateTime(sameDayOfNextMonth.Year, sameDayOfNextMonth.Month, 1);
                discDate = firstDayOfNextMonth.AddDays((double)terms.DayDisc);
                break;
            case TermsDueType.DayOfNextMonth:
                discDate = new PXDateTime(DocDate.Year, DocDate.Month, (int)terms.DayDisc).AddMonths(1);
                break;
            case TermsDueType.DayOfTheMonth:
                int monthShift;

                    if (terms.DueType == TermsDueType.DayOfNextMonth && DocDate.Day <= (int)terms.DayDue00)
                        monthShift = DocDate.Day >= (int)terms.DayDisc ? 1 : 0;
                else if (terms.DueType == TermsDueType.EndOfNextMonth)
                    monthShift = DocDate.Day >= (int)terms.DayDisc ? 1 : 0;
                else
                    monthShift = DocDate.Day > (int)terms.DayDue00 ? 1 : 0;
                discDate = new PXDateTime(DocDate.Year, DocDate.Month, (int)terms.DayDisc).AddMonths(monthShift);
                break;
            case TermsDueType.EndOfMonth:
                discDate = new DateTime(DocDate.Year, DocDate.Month, 1).AddMonths(1).AddDays(-1);
                break;
            case TermsDueType.EndOfNextMonth:
                discDate = new DateTime(DocDate.Year, DocDate.Month, 1).AddMonths(2).AddDays(-1);
                break;
            default:
                break;
        }
        }

        if (discDate > dueDate)
        {
            discDate = dueDate;
        }
    }           
}

您可以创建从现有属性(例如:条款)派生的新属性(例如:MyTerms)和覆盖方法(例如:CalcTerms)。然后,您重新定义/扩展使用该属性(TermsID)的字段,以便它使用您的属性(MyTerms)而不是(Terms)。

主要问题是指您要更改的代码所在的方法无法覆盖,在这种情况下,您需要复制粘贴代码批量在自定义属性中并放弃遗产。

起点是属性代码。要获得它,请在自定义项目编辑器中使用VIEW SOURCE功能: enter image description here

然后使用&#39;在文件中查找&#39;获取属性代码: enter image description here

答案 1 :(得分:0)

实现一个APInvoice_DueDate_FieldUpdated事件处理程序,当术语发生变化时,它将被引发。