With some help and a lot of trial and error I was able to create a customization that allowed for the following:
- "Total Profit" field on the Sales Order summary area
- "GP %" field on the Sales Order summary area
- "Total Profit" field on the Sales Order details area (by line)
- "GP %" field on the Sales Order details area (by line)
Total Profit = Ext. Price - Ext. Cost GP % = (Total Profit / Ext. Price) * 100
The calculation for these four fields works some of the time, but I have noticed when I commit the line either by entering a new line or with Control + Enter, and then go back and change the Ext. Cost, the Total Profit and GP% don't update. Even when I save and refresh it does this. The only time it seems to work 100% is when I enter it in very methodically going one step at a time. But this is not how the out of the box totals are calculated. It doesn't matter which order you enter in your quantity, price, etc. - the out of the box totals always update. How do I make my four custom fields like this in Acumatica?
SOLine Custom fields (each field separated by a blank line):
[PXDBCurrency(typeof(SOLine.curyInfoID), typeof(SOLineExt.usrTotalProfit))]
[PXUIField(DisplayName = "Total Profit", Enabled = false)]
[PXFormula(typeof(Sub<SOLine.curyLineAmt, SOLine.curyExtCost>))]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXFormula(null, typeof(SumCalc<SOOrderExt.usrCuryOrderTotalProfit>))]
[PXDBDecimal(4)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXFormula(typeof(Switch<Case<Where<SOLine.curyLineAmt, Equal<decimal0>>, decimal0>, Div<SOLineExt.usrTotalProfit, SOLine.curyLineAmt>>))]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "GP %", Enabled = false)]
[PXFormula(typeof(Mult<SOLineExt.usrGPPercent, decimal100>))]
[PXDefault(TypeCode.Decimal, "0.0")]
SOOrder Custom fields (each field separated by a blank line):
[PXDBCurrency(typeof(SOOrder.curyInfoID), typeof(SOOrderExt.usrOrderTotalProfit))]
[PXUIField(DisplayName = "Total Profit", Enabled = false)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXDBDecimal(4)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXFormula(typeof(Switch<Case<Where<SOOrder.curyOrderTotal, Equal<decimal0>>, decimal0>, Div<SOOrderExt.usrOrderTotalProfit, SOOrder.curyOrderTotal>>))]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "GP %", Enabled = false)]
[PXFormula(typeof(Mult<SOOrderExt.usrOrderGPPercent, decimal100>))]