New Calc value based on previous Calc Value

ontarget

Active Member
I have a calc element that is working out the value of catering based on numbers served. The catering options are checkbox as they require multi selection. The 'other' option is a field which can take any numerical value.

PHP:
$catering = array_sum($data['aaa_maindatabase___main_catering_detail_raw']) + '{aaa_maindatabase___main_other_catering}';
$totalcatering = $catering * (int)'{aaa_maindatabase___main_served}';
return $totalcatering;

So typically they could choose
scones = ?3
lunch = ?14.00
= ?17.00 * 10 persons served = ?170

I then need to calculate what they are paying the catering firm e.g
scones = ?2
lunch = ?10
= ?12 * 10 = ?120
How can i run a second calc which changes the values of the same checkboxes to the catering firms values?
I think I need to do an array to get the checkbox values then reencode the array with the new values then do the calc on those - am I correct? How do i get checkbox values into an array in fabrik?
 
Ok I got the output of the checkbox array

PHP:
$options = FabrikWorker::JSONtoData($data['aaa_maindatabase___main_catering_detail'], true);
$pieces = implode(',', $options);
return $pieces;
This shows a csv of all checkboxes that have been checked.
How can I grab an individual item from that array and do a calc on it?

[aaa_maindatabase___main_catering_detail_raw] => ["3.00","14.00"]
 
You can't calc on calcs because it's not determined which is running first.
You have to (re)do the complete calculation.
 
Ok thanks for the reply, if i did another set of identical checkboxes but containing the other values this would achieve what i need but it means the user has to fill 2 sets of identical checkboxes! Is there any way i can fill out one set of checkboxes and the other set are replicated / filled automatically?
 
Hi Troester - I've been thinking about it and its not actually a calc on a calc its 2 different calcs performed on the same checkbox element

Calc 1 grabs the values of the checkboxes sums them and does a multiplication

Calc 2 grabs the values of the same checkboxes and returns them as a different (lesser number) then sum them and perform a multiplication

I was thinking a switch statement would do the trick but I'm not getting any value showing - is this correct? I can then use the array_sum value to match any combination of checkboxes and change their value to the 2nd value

Here's my code - ive kept it simple with no maths yet just to see if i can output the new values.
PHP:
$prestige = array_sum($data['aaa_maindatabase___main_catering_detail_raw']);

switch ($prestige)
{
case '2.86' :return '2'; break;
case '3.81' :return '3'; break;
case '5.24' :return '5';
}
 
Looks like you are very close. Would this do it for calc1:
PHP:
$options= FabrikWorker::JSONtoData($data['aaa_maindatabase___main_catering_detail'],true);
$catering=array_sum($options) + (int) '{aaa_maindatabase___main_other_catering}';
$totalCatering=$catering * (int) '{aaa_maindatabase___main_served}';
return $totalCatering;
 
Looks like you are very close. Would this do it for calc1:
PHP:
$options= FabrikWorker::JSONtoData($data['aaa_maindatabase___main_catering_detail'],true);
$catering=array_sum($options) + (int) '{aaa_maindatabase___main_other_catering}';
$totalCatering=$catering * (int) '{aaa_maindatabase___main_served}';
return $totalCatering;
Hi sophist thanks I have calc1 working already it was calc2 that is waking me up at night . I read that switch statements are more efficient than if else when there are lots of iterations but I don?t have much experience of using them.


Sent from my iPhone using Tapatalk
 
Perhaps you want:
PHP:
$prestige=array_sum($data['aaa_maindatabase___main_catering_detail_raw']);
return int($prestige);
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top