0
votes

Have the need to override the Calculate Overdue Charges (AR507000) Calculate action. Was going to try to override the entire CalculateFinancialCharges but that seemed to daunting (not even sure if possible). In my extension class I just want to do some post processing: If rows found on ARFinChargeRecords after running base Calculate logic then prompt user. If they answer yes, iterate through ARFinChargeRecords and update FinChargeAmt with: current invoice balance * .02

I'm very new to Acumatica development and have been through all T courses. This my first real-world problem to solve and I'm not having much luck. It appears Base.calculate calls itself? I tried using the example of the invoice release action override, but this seems different somehow.

Here is what I have so far in my extension class but nothing really working so far. var row1 = row is just there for breakpoint/debugging purposes:

    public PXAction<ARFinChargesApplyMaint.ARFinChargesApplyParameters> Calculate;
    [PXButton]
    [PXUIField(DisplayName = "Calculate")]
    protected void calculate()
    {
        Base.calculate.Press();

        //int iCachedData = 0;
        //foreach (var row in Base.ARFinChargeRecords.Cache.Cached)
        //{
        //    iCachedData++;
        //    yield return row;
        //}

        //if (iCachedData > 0)
        //{
            if (Base.ARSetup.Ask("Apply Special Calculation (Percent Of Open Balance)", MessageButtons.YesNo) == WebDialogResult.Yes)
            {
                foreach (var row in Base.ARFinChargeRecords.Cache.Cached) {

                  var row1 = row;

                }

                // update FinChargeAmount with Balance * .02
                // Base.ARFinChargeRecords
                // Base.ARInvoices.
            }
        // }
    }
1
Scope of 'what is not working' is too broad. Try to narrow down the issue to one actionable item that is not working and describe the problem fully, ex: method override is not called. - Hugues Beauséjour
If I run the calculate I get 2 rows showing overdue charges using the built-in logic. I get prompted twice with the Ask (so almost like Base.calculate is recursive) but I never see any rows when I step into this. row1 = row never gets hit. But again, I'm not even sure if A) the calculate action can be overridden and B) if it can, I don't understand how to do it, apparently. I'm trying to reference the labs from T300, but can't find any example that looks close to what I need to do. (run logic AFTER the base action) - rjean99

1 Answers

0
votes

Calculate action can be overridden. Below is out-of-box Calculate action

out-of-box Calculate action

It should be overridden as below (without any of your custom logic):

public class ARFinChargesApplyMaintPXExt : PXGraphExtension<ARFinChargesApplyMaint>
{
    [PXOverride]
    public virtual IEnumerable Calculate(PXAdapter adapter)
    {
        Base.calculate.Press(adapter);

        return adapter.Get();
    }
} 

Out-of-box Calculate action starts Asynchronous operation (via PXLongOperation.StartOperation), creates new Graph instance for ARFinChargesApplyMaint and invokes CalculateFinancialCharges method (which generates rows displayed in grid)

With above observations, possible approach to address your requirement would be:

  1. Add confirmation and store confirmation value (Yes/No) in hidden custom field of DAC working with Filter view (ARFinChargesApplyMaint.ARFinChargesApplyParameters) before invoking Base.calculate.Press(adapter).
  2. Override virtual method CalculateFinancialCharges, and add RowInserted event-handler for ARFinChargesApplyMaint.ARFinChargesDetails DAC to alter logic for FinChargeAmt field.

Below code is for your reference

using System;
using PX.Data;
using System.Collections;
using PX.Objects.AR;

namespace DemoPkg
{
    public class ARFinChargesApplyMaintPXExt : PXGraphExtension<ARFinChargesApplyMaint>
    {
        [PXOverride]
        public virtual IEnumerable Calculate(PXAdapter adapter)
        {
            WebDialogResult result = adapter.View.Ask(Base.Filter.Current, "Confirmation",
                                                      "Apply Special Calculation (Percent Of Open Balance)?",
                                                      MessageButtons.YesNo, MessageIcon.Question);
            ARFinChargesApplyMaint.ARFinChargesApplyParameters filterData = Base.Filter.Current;
            ARFinChargesApplyParametersPXExt filterDataExt = PXCache<ARFinChargesApplyMaint.ARFinChargesApplyParameters>.GetExtension<ARFinChargesApplyParametersPXExt>(filterData);
            filterDataExt.UsrReCalcFinChargeAmt = (result == WebDialogResult.Yes);
            Base.Filter.Update(filterData);

            Base.calculate.Press(adapter);

            return adapter.Get();
        }

        [PXOverride]
        public virtual void CalculateFinancialCharges(ARFinChargesApplyMaint.ARFinChargesApplyParameters filter, Action<ARFinChargesApplyMaint.ARFinChargesApplyParameters> BaseInvoke)
        {
            ARFinChargesApplyParametersPXExt filterDataExt = PXCache<ARFinChargesApplyMaint.ARFinChargesApplyParameters>.GetExtension<ARFinChargesApplyParametersPXExt>(filter);
            if (filterDataExt.UsrReCalcFinChargeAmt.GetValueOrDefault(false))
            {
                Base.RowInserted.AddHandler<ARFinChargesApplyMaint.ARFinChargesDetails>((sender, e) =>
                {
                    ARFinChargesApplyMaint.ARFinChargesDetails data = (ARFinChargesApplyMaint.ARFinChargesDetails)e.Row;
                    data.FinChargeAmt = 600.00m; // your custom calculated value
                });
            }
            BaseInvoke(filter);
        }
    }

    public sealed class ARFinChargesApplyParametersPXExt : PXCacheExtension<ARFinChargesApplyMaint.ARFinChargesApplyParameters>
    {
        #region UsrReCalcFinChargeAmt
        public abstract class usrReCalcFinChargeAmt : PX.Data.BQL.BqlBool.Field<usrReCalcFinChargeAmt> { }

        [PXDBBool]
        [PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "Recalc Amount", Visibility = PXUIVisibility.Invisible)]
        public bool? UsrReCalcFinChargeAmt { get; set; }
        #endregion
    }
}

Below help articles can be referred in Acumatica Customization Guide

To Override an Action Delegate Method

Altering BLC Virtual Methods