Sales Order CostValue, Margin computation

Hi Guys,

I’m working on a customization right now in form Sales Order. please see details below:

I purchased Same Item=“4800000013” with different Unit Price.

now, as part of this customization, in Sales Order > Totals,standard of AX 2012 R2 compute the weighted average. Aside from WA, I want to compute also the "Cost Value, Margin and Ratio" based on my last purchase price…

can anyone help me on this matter. please

Thanks and Regards,

Paul