Page 1 of 1

Auto Double-Calculate

Posted: 2014-07-15 15:02
by naturick
Situation:

I have a table LOTTI and a related table LOTTI_LINES

In LOTTI I have fields:
ID_LOTTO
INITIAL_QUANTITY (manual filled)
FINAL_QUANTITY (auto calculate)

In LOTTI_LINES I have fields:
ID_LOTTO
TRASH_QUANTITY (manual filled)

Now I would like to auto fill FINAL_QUANTITY like yhis:
INITIAL_QUANTITY - (SUM OF ALL RELATED TRASH_QUANTITY)...

Is it possible to do it?

I have already put some calculation on before_update and before_insert section of HOOK file to calculate some % between FIANL_QUANTITY and INITIAL_QUANTITY to know the final %...and works fine.

Thanks.

Re: Auto Double-Calculate

Posted: 2014-07-25 22:50
by a.gneady
You'd need to use the after_insert hook of the "hooks/LOTTI_LINES.php" file ... You should add code to execute an SQL statement for updating the FINAL_QUANTITY field of the LOTTI table ... something like this:

Code: Select all

sql("update LOTTI set FINAL_QUANTITY=$final_quantity where ID_LOTTI=$id_lotti", $eo);
You need of course to calculate the value of $final_quantity and specify the value of $id_lotti before the above code line.