SUM - Repeteable group + condicional

javier94

Member
i'm usign jomla 3.8.3 and fabrik 3.8

i have a form named CAT-curriculum-administracio

and 3 repeteable groups in this form.. named

cat-curriculum-administracio-annex-1-dades
cat-curriculum-administracio-annex-2-dades
cat-curriculum-administracio-annex-3 dades

in each group there is one element named " percentage prova % " is a dropdown with values from 0-95

i would like to sum this 3 elements if are not repeteable or "X" if are repeteable and the result show in the element "% confirmacio percentage (1)"

show in group

cat-curriculum-administracio-valoracio-proves


and in the total SUM element should be a conditional like this :

if "yes" the sum of all the non possible repeteable groups the number is = 100 .. show

"100 % is correct "

If "not" the sum of all the non possible repeteable groups the number is <100 or >100.. show

" 95% or 105% is not correct. check again"

for the sum of all repeteable groups i have use..

i have seen in other post.. this code.. and i used.. but doesn?t work .. the sum is not correct.

in the calcul box

return array_sum($data['cat_curriculum_administraci_135_repeat___percentatge_prova_Annex_1_raw'])
+ array_sum($data['cat_curriculum_administraci_138_repeat___percentatge_prova_Annex_2_raw'])
+ array_sum($data['cat_curriculum_administraci_140_repeat___percentatge_prova_Annex_3_raw']);



in the ajax revision

{cat_curriculum_administraci_135_repeat___percentatge_prova_Annex_1},
{cat_curriculum_administraci_138_repeat___percentatge_prova_Annex_2},
{cat_curriculum_administraci_140_repeat___percentatge_prova_Annex_3}


and i have found other conditional code like this..

calcul box

if {(cat_curriculum_administraci_135_repeat___percentatge_prova_Annex_1_raw) +
(cat_curriculum_administraci_138_repeat___percentatge_prova_Annex_2_raw) +
(cat_curriculum_administraci_140_repeat___percentatge_prova_Annex_3_raw)=100}{return 'Perfecte 100% percentatge';
}
else{
return'Percentatge NO es correcte'
}

in the ajax box

{cat_curriculum_administraci_135_repeat___percentatge_prova_Annex_1},
{cat_curriculum_administraci_138_repeat___percentatge_prova_Annex_2},
{cat_curriculum_administraci_140_repeat___percentatge_prova_Annex_3}

i think is a mix between both codes.. because i think the second code doesn?t work because for SUM
non repeteable groups.. you must use in fabrik 3 array function..

i would like see the calculation when you change any value before to save if is posible.

if you can tell me which code will works.. will be perfect

thanks

javier...
 
Last edited:
Now i found some code and is working..

in calcul element / more

calcul box

$sum = array_sum($data['cat_curriculum_administraci_135_repeat___percentatge_prova_Annex_1'])
+ array_sum($data['cat_curriculum_administraci_138_repeat___percentatge_prova_Annex_2'])
+ array_sum($data['cat_curriculum_administraci_140_repeat___percentatge_prova_Annex_3']);

if($sum==100){
$text = " <STRONG><FONT COLOR=\"#46a546\">" . $sum . "% CORRECTE </FONT></STRONG>";
} else {
$text = " <STRONG><FONT COLOR=\"#FF0000\">" . $sum . "% INCORRECTE </FONT></STRONG>";
}

return $text;

button -- > only calcul to save --> green
button--> Ajax calcul --> green


in Fields Ajax to revise


{cat_curriculum_administraci_135_repeat___percentatge_prova_Annex_1_0},
{cat_curriculum_administraci_138_repeat___percentatge_prova_Annex_2_0},
{cat_curriculum_administraci_140_repeat___percentatge_prova_Annex_3_0}


you can close this item!

Thanks!
Javier
 
Couple of things ...

I check that calc element, and you were starting it with a +=, like ...

Code:
$sum += array_sum($data['cat_curriculum_administraci_116_repeat___merits_experiencia_profesional']);

That will actually throw a PHP warning, as $sum doesn't exist at that point. Using += is shorthand for "$foo = $foo + $something", so $foo has to exist. So you need to do ...

Code:
$sum = 0;
$sum += array_sum($data['cat_curriculum_administraci_116_repeat___merits_experiencia_profesional']);

Also, for elements in repeat groups, don't add the _X to it, either when referncing it in $data['whatever'] or with a {whatever} placeholder. Fabrik will automagically know about the repeat suffix.

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

Thank you.

Members online

Back
Top