Column Subtotal goes wrong

shaq

New Member
Hi,

I have 3 elements calc :
- first element named cotisation_retraite which is calc element (result of a field element * 0.08)
- second element named autres_cotisations which is also a calc element (result of another calc element *drop down element)
- Third element named total_cotisation which is the sum of cotisation_retraite + autres_cotisations

Also the calculation are correct for each calc element except when I want to do the subtotal in column of total_cotisation. I checked Yes in List view settings/calculations/Sum.

I also re-edited the form and changed some numbers and saved it so I can retrigger the calculation.

Nothing happen the same wrong sum in subtotal still displayed.

Little help please.

Thanks
 
It sounds like the second and third elements are using the results of another calc element.
That is unreliable. There is no guarantee of the order of calculations - so, for instance, "autres_cotisations" may not be calculated before "total_cotisation"

You will need to repeat the calculation independently. Basically repeat the autres_cotisations calculation in total_cotisation.

The easiest way to do that would be to put each calculation in a function (file) that you call from the calc fields. That way you can easily call "autres_cotisations" from 2 calc fields.

-bob
 
Bob is correct. You can't use calc values in other calcs, as the order of calculation is not defined (an may be different during form submission vs list display, etc). So if calc 1 relies on the result of calc 2, but calc 1 runs before calc 2 ... :(

So as Bob says, you have to redo the code in each calc, so each calc is independent.

-- hugh
 
Thanks for your time but I tried to do each calc alone, it still the same result.

the calc for the {fab_salaries___cotisation_retraite} is correct and formula is :
$myCalc1 = (int)'{fab_salaries___salaire_brut_mensuel_deplaf}' * 0.08;
return $myCalc1;

the calc for the {fab_salaries___autres_cotisations} is also correct and formula is :
$MyCalc2= $data['fab_employeurs___regime'] * $data['fab_salaries___salaire_brut_mensuel_plaf'] ;

the calc for the {fab_salaries___total_cotisation} was previously like this :
return (int)'{fab_salaries___cotisation_retraite}' + (int)'{fab_salaries___autres_cotisations}';

And also returned good result.

Now I changed {fab_salaries___total_cotisation} formula like this :
$MyCalc2 = $data['fab_employeurs___regime'] * $data['fab_salaries___salaire_brut_mensuel_plaf'];
return $MyCalc2 + (int)'{fab_salaries___salaire_brut_mensuel_deplaf}' * 0.08;

And it returned correct result too.

The probleme I have its that when I set to YES the Sum the column total in List view settings/Calculations for the three elements.
I have correct result for cotisation_retraite but SUM = 0 for autres_cotisations.

And As the column total sum of total_cotisation should be : the column total sum of cotisation_retraite + the column total sum of autres_cotisations,

It only show the SUM in column total of cotisation_retraite in total_cotisation SUM total column

Here is a print screen.

Regards
 

Attachments

  • sum column total goes wrong.jpg
    sum column total goes wrong.jpg
    128.4 KB · Views: 48
Oh before I forgot.

{fab_salaries___salaire_brut_mensuel_plaf} is a calc element and use a this script :

if ({fab_salaries___salaire_brut_mensuel_deplaf_raw}>400000){

return '400000';
}
else{

return {fab_salaries___salaire_brut_mensuel_deplaf};
}

This calc element is included in autres_cotisations.
 
Can you look in something like phpMyAdmin and make sure the fields for those calcs actually have values in the table(s).

It's possible for calc's to be showing values in the list, but not actually have values in the table itself (depending on the "Calc on save" setting, and whether rows existed before the calc was added).

-- hugh
 
You right.
I checked in the table itself in PhpMyAdmin and autres_cotisations has 0 as value. May be because it himself based on another calc element (salaire_brut_mensuel_plaf)
I dont understand what's going on here.
Little help please
Regards
 
Can you check please if this code for the calc element (salaire_brut_mensuel_plaf) is correct.


if ({fab_salaries___salaire_brut_mensuel_deplaf_raw}>400000){

return '400000';
}
else{

return {fab_salaries___salaire_brut_mensuel_deplaf};
}
 
First thing, always use quotes around placeholders, and if doing math on them, cast them to the type you want, to avoid errors if they are blank:

Code:
if ((int)'{fab_salaries___salaire_brut_mensuel_deplaf_raw}' >400000) {
   return '400000';
}
else {
    return '{fab_salaries___salaire_brut_mensuel_deplaf_raw}';
}

And second issue ... the calc that uses that value needs to redo that calc.

In a previous post you said:

the calc for the {fab_salaries___autres_cotisations} is also correct and formula is :
$MyCalc2= $data['fab_employeurs___regime'] * $data['fab_salaries___salaire_brut_mensuel_plaf'] ;

But a) that's not returning anything, and b) if 'fab_salaries___salaire_brut_mensuel_plaf' is a calc, this one needs to redo it. So something like ...

Code:
$myCalc1 = (int)'{fab_salaries___salaire_brut_mensuel_deplaf_raw}' >400000) ? 400000 : '{fab_salaries___salaire_brut_mensuel_deplaf_raw}';
return $data['fab_employeurs___regime'] * $myCalc1;

-- hugh
 
Nope....
nothing happen.... only blank on autres_cotisations..... I even lose the calc I had before with this element....

Sorry !
 
I know. I installed some security updates on the main server who didnt respond after a reboot command. Am waiting root password from my IAAS's to restore services from cpanel or SSH mode. I will let you know as soon as its okay.

Sorry... Errors occured on server less than 1hour after my last post here. My bad !!!
 
OK, which list/form do I need to look at and test these on? You have 17 copies of each.

Is this live data? If so, is there a specific record I should test on?

-- hugh
 
Okay, I disabled unecessary list. You should focus on below list :

List and form : Employeurs and SALARIES
group : Employeurs, SALARIES and Employeurs-[fab_salaries]

Elements : fab_salaries___salaire_brut_mensuel_deplaf (id 344) (field)
fab_salaries___salaire_brut_mensuel_plaf (id 351) (calc)
fab_salaries___cotisation_retraite (id 365) (calc)
fab_salaries___autres_cotisations (id 379) (calc)
fab_salaries___total_cotisation (id 372) (calc)

All those elements from Employeurs-[fab_salaries] group.

If you log in frontend with login sent by skype you will see that autres_cotisations calc are empty. Cotisation_retraite and total_cotisation have correct results.

There is a last drop down element [regime] from Employeurs list who is included in calculation in autres_cotisations.

autres_cotisations = [regime] x [salaire_brut_mensuel_plaf].

Hope I was clear.

Regards
 
You hadn't used the code from my post #9, you still had the old code that tried to re-use a calc, and didn't return anything.

I've replace it with:

Code:
return '{fab_employeurs___regime_raw}' * min('{fab_salaries___salaire_brut_mensuel_deplaf}', '400000');

And I've replaced the code in salaire_brut_mensuel_plaf with ...

Code:
return min('{fab_salaries___salaire_brut_mensuel_deplaf}', '400000');

... which is a quicker way of doing what you were doing.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top