Auto Double-Calculate

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
naturick
Veteran Member
Posts: 39
Joined: 2014-07-07 18:47
Location: Cluj-Napoca
Contact:

Auto Double-Calculate

Post by naturick » 2014-07-15 15:02

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.

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Auto Double-Calculate

Post by a.gneady » 2014-07-25 22:50

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.
:idea: AppGini plugins to add more power to your apps:

Post Reply