how to calculate the sum of all volumes and display the total in the Total volume field as shown below.
First we will create on INRegister DAC a Usr decimal field that will hold the value of "Total Volume".
Please note that any DAC extension fields that utilize [PXDefault]
attribute should have the Persisting check set to PXPersistingCheck.Nothing
this will prevent errors occuring when trying to save legacy documents within the system.
public class INRegisterExtension : PXCacheExtension<INRegister>
{
#region UsrTotalVolume
public abstract class usrTotalVolume : BqlDecimal.Field<usrTotalVolume>
{
}
[PXDBDecimal]
[PXDefault(TypeCode.Decimal, "0.00", PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Total Volume")]
public virtual decimal? UsrTotalVolume { get;set;}
#endregion
}
Next we will create our detail level Usr field which will hold the value of "Volume" within the grid.
public class INTranExtension : PXCacheExtension<INTran>
{
#region UsrVolume
public abstract class usrVolume : BqlDecimal.Field<usrVolume>
{
}
[PXDBDecimal]
[PXDefault(TypeCode.Decimal, "0.00", PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Volume")]
public virtual decimal? UsrVolume { get; set; }
#endregion
}
Finally we will create a PXGraphExtension
which will append the [PXFormula]
attribute to our child Usr field allowing the calculations you desire specifically in the context of this data entry screen.
If a formula is included on a DAC it's logic is called whenever the DAC is utilized ( GI, Reports, Ect ) thus we add it on a Graph Extension so we are only utilizing logic when needed, i.e. on the data entry page.
public class INTransferEntryExtension : PXGraphExtension<INTransferEntry>
{
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXFormula(null, typeof(SumCalc<INRegisterExtension.usrTotalVolume>))]
protected virtual void __(Events.CacheAttached<INTranExtension.usrVolume> e)
{
}
}
Results seen below :