Placing the calculation logic in the lines table causes the value to change dynamically as you navigate through lines. It in the header table seems to provide a static value, but it's unclear why.
Public real getTotalConsumptionCost(ProdId _prodId)
{
ProdJournalBOM prodJournlBOM;
real totalCost = 0;
select sum(ConsCost) from prodJournlBOM
where prodJournlBOM.ProdId == _prodId;
totalCost = prodJournlBOM.ConsCost;
return totalCost;
}
Select data from the header table to update and insert new records in the lines table. So where to write a method in a table of headers or lines.
By placing the calculation logic in the ProdTable
, I ensure that the total consumption cost is calculated consistently for any given product.
The getCalculatedTotalCost
method in the ProdJournalBOM
table provides a convenient way to access the calculated value for each line.
How about
public display real getTotalConsumptionCost()
{
ProdId _prodId = this.ProdId;
...