This topic is locked

Master-Detail Calculation

4/2/2019 12:13:35 AM
PHPRunner General questions
E
ehwagner author

I am new to phprunner and need some help. I have a master-detail edit page and I need to do a calculation involving master fields and a sum total of a column in the detail section. The picture below depicts what I am trying to do. I have read javascript examples for calculations on the fly which is fine for the master fields, but I don't know how to retrieve the sum total of the detail. The calculation does not need to performed upon showing the page, but if master money or factor change or if the sum total of the detail section is changed (add,edit,delete detail rows) then the calculation should be performed and displayed. Any help would greatly be appreciated. This is pretty important to me. Thank you in advance.


admin 4/3/2019

This is possible but not straightforward and a fair amount of coding will be required. The main issue is that we do not have an API to access details table info on the master Add page. Also re-calculation should happen when details records are deleted, added or edited.
The closest we have is an Invoice template where similar calculation is implemented:

https://xlinesoft.com/invoice

A
ayctech 4/4/2019

I did it with jQuery
in your case it would be input[name^=value_precio_total_detalle], the calculations I put in javascript onload of the detail so that it calculates in the cabezera
go through all the selections

$('select[name^=value_precio_total_detalle] option:selected').each(function() {

if ($(this).val().length > 0) {

add += Number($(this).val());

}

})
if (add>0){

$("input[id^=value_precio_total_cobros]").val(add);

}

E
ehwagner author 4/9/2019



I did it with jQuery
in your case it would be input[name^=value_precio_total_detalle], the calculations I put in javascript onload of the detail so that it calculates in the cabezera
go through all the selections

$('select[name^=value_precio_total_detalle] option:selected').each(function() {

if ($(this).val().length > 0) {

add += Number($(this).val());

}

})
if (add>0){

$("input[id^=value_precio_total_cobros]").val(add);

}



Ronald,

Thank you for your assistance. I could not get this to work in my project. I think partly because you are doing it in the javascript onload of the detail plus you have inline edit of the detail, where I'm trying to do it at the Master level and I'm not doing an inline edit. Is there a way to do it as depicted in my picture from the Master level?

E
ehwagner author 4/9/2019



This is possible but not straightforward and a fair amount of coding will be required. The main issue is that we do not have an API to access details table info on the master Add page. Also re-calculation should happen when details records are deleted, added or edited.
The closest we have is an Invoice template where similar calculation is implemented:

https://xlinesoft.com/invoice


So if I purchase the invoice template, which I will never use, will it show how the calculation can be done?

A
ayctech 4/9/2019

I already understood what you want to do, is the sum of the details you are doing with the total function type = total?
alert($('span[id^=total1_precio_total_compras]').text());
$('span[id^=!!see what the field is called!!').text()

E
ehwagner author 4/10/2019



I already understood what you want to do, is the sum of the details you are doing with the total function type = total?
alert($('span[id^=total1_precio_total_compras]').text());
$('span[id^=!!see what the field is called!!').text()


Ronald,

The answer is "YES" on the Total question. Here is the Designer image:



A
ayctech 4/11/2019

is a bit complicated as you want to do, you have to extract the number with jquery (the code below), turn it into an integer and remove the point with a function so you can add with the input of the header
alert ($ ('span [id ^ = total1_precio_total_compras]'). text ());