Calculate between 2 Tables

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Calculate between 2 Tables

Post by dharbitindy » 2019-06-17 15:00

Hello,
I have 2 tables and I'm trying to do a simple calculation from one to the other. The results table will hold the calculation of lbs_per_m, or Pounds per 1,000. The part_weight field is from the quoting table and the math is; part_weight * 1000 / 16. This (I thought worked just fine earlier) but now, I cannot get this calculation to work between the 2 tables, or any of the other Parent Child tables for that matter...

In this case, the Parent Table is quoting, and the Child Table is results.

Attached are screen shots of my code. Please help!

Much appreciated,
David
Attachments
ajax-quoting-part_weight.PNG
Trying to streamline update
ajax-quoting-part_weight.PNG (23.62 KiB) Viewed 1777 times
quoting_table.PNG
Parent Table
quoting_table.PNG (241.18 KiB) Viewed 1777 times
results_table.PNG
Child Table
results_table.PNG (178.92 KiB) Viewed 1777 times
results-dv-js.PNG
Trying to streamline update
results-dv-js.PNG (38.97 KiB) Viewed 1777 times
ResultsPHP.PNG
Calculation File
ResultsPHP.PNG (27.62 KiB) Viewed 1777 times

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Calculate between 2 Tables

Post by pbottcher » 2019-06-17 15:13

Hi,

can you replace in your results.php file the $data['part_weight'] with $data['quoting_ID']

Also I do not understand what you try to do in the results-dv-js. To me there seems to be no part_weight in that table.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Calculate between 2 Tables

Post by dharbitindy » 2019-06-17 15:33

Wow, you are quick and good! That fixed the calculation in the results.php, and yes you are right (Sorry, I'm a newbie at this) about the results-dv.js. I think that I need to replace the part_weight with the lbs_per_m in the results table, correct?

Thanks so much for the quick reply and solution!

David

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Calculate between 2 Tables

Post by pbottcher » 2019-06-17 16:02

Hi,

well it depends what you try to acheive :-). I guess you wan to display the calculated lbs_per_m when the user changes the quoting_ID.
In that case you need to adjust you sql statement in the ajax-quoting-part_weight.php to give you the calculated value. Now you just retrieve the value.

Also you might review your setting. You set the lbs_per_m value via the javascript. In the before_insert / before_update you recalculate the same value and overwrite the value that should be already there. So the second part would not be needed to my opinion.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Calculate between 2 Tables

Post by dharbitindy » 2019-06-17 16:17

pböttcher wrote:
2019-06-17 16:02
Hi,

well it depends what you try to acheive :-). I guess you wan to display the calculated lbs_per_m when the user changes the quoting_ID.
In that case you need to adjust you sql statement in the ajax-quoting-part_weight.php to give you the calculated value. Now you just retrieve the value.

Also you might review your setting. You set the lbs_per_m value via the javascript. In the before_insert / before_update you recalculate the same value and overwrite the value that should be already there. So the second part would not be needed to my opinion.
Apologies, in the above reply I meant to say replace the part_weight with lbs_per_m in the results-dv.js file, not results table.

Thanks again,
David

Awesome, I'll take a look at what you are saying. I'm sure that you are correct, and again, much appreciated!
David

Post Reply