Column Subtotal goes wrong

Yeah ! Calculation is back in autres_cotisations element. Thanks...

Just one last thing, how to get subtotal in column for total_cotisation correct.
I mean subtotal in column for total_cotisation = subtotal in column cotisation_retraite + subtotal in column autres_cotisations.
Now only subtotal in column cotisation_retraite is considered.

Regards
 
I've fixed the code you had in that one. Don't know if it's correct, specifically what operator precedence you intend ...

Code:
$MyCalc2 = '{fab_employeurs___regime_raw}' * min('{fab_salaries___salaire_brut_mensuel_deplaf}', '400000');
return $MyCalc2 + (int)'{fab_salaries___salaire_brut_mensuel_deplaf}' * 0.08;

So that second line is going to do the multiplication by .08 first, then the addition. If you need to do the multiplication after the addition, use parens to group the addition operation.

-- hugh
 
Operator precedence in PHP follows the standard PEMDAS mnemonic (Parentheses, Exponents, Multiplication, Division, Addition, Subtraction).

So ...

2 + 2 * 4 = 10
(2 + 2) * 4 = 16

-- hugh
 
Understood. Calculation for cotisation_retraite, autres_cotisations and total_cotisation are correct. Just little problem with sum in column for autres_cotisations and total_cotisation. Its that something we can fix or not. Just sayin'.

Regards
 
Are you talking about the "list calculations"?

If so, I kinda tried to explain that earlier in the thread. Calc element values are only saved to the database when you save a form. So, say you change the calculations (like we did), such that every row now has different values for the calcs, you may see the new values in the list's individual rows, but that's because the values are being calc'ed on the fly as the element is being rendered (your calc is re-run during list display). But the column totals are built from the data actually in the database, using database queries (like SUM() or AVG(), etc). And because those calc values haven't yet been saved to the database, the calculations don't see them.

So, yes ... you can "fix" it (in quotes, because it's not really "broken", you just haven't saved those values yet) by editing and saving all your forms, to force the calc values to be saved to the database. Which is why it pays to get all your calcs right before you have a lot of data.

I just did that for the first record in the list, and the totals now look OK for that one.

BTW, I notice that some of those forms are HUGE. You may well run into issues with PHP's settings, which by default restricts the number of form inputs to 1000, and also restricts the total size of form inputs. You'll notice you have that problem if you start to lose repeats after saving. At which point you need to edit your php.ini, and increase max_input_vars, and possibly max_post_size (or some such).

-- hugh
 
Thanks for your help guys. That work well. All calculation tested and rendered correct. I dont know what I would do without your help.

I didnt use a code you sent me earlier because I got server interruption while I was doing it. After I restored former backup and didnt remember or get time to reedit this code for calc use.

Thanks again and great job. Thread closed.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top