CalcBuilder Forum

2 Calculators one set of code

User phil_adler 2016-02-05 21:17:52

I have 2 calculators within one set of code. Both use date pickers

here is the code:

/* Start Jail Calculator */
$date1 = new DateTime($sdate);
$date2 = new DateTime($edate);
$count = date_diff($date1,$date2);
$total = $count->days;
$inlinedate1 = $total;
$date1 = new DateTime($sdate2);
$date2 = new DateTime($edate2);
$count2 = date_diff($date1,$date2);
$total = $count2->days;
$inlinedate2 = $total;
$date1 = new DateTime($sdate3);
$date2 = new DateTime($edate3);
$count3 = date_diff($date1,$date2);
$total = $count3->days;
$inlinedate3 = $total;
$date1 = new DateTime($sdate4);
$date2 = new DateTime($edate4);
$count4 = date_diff($date1,$date2);
$total = $count4->days;
$inlinedate4 = $total;
$date1 = new DateTime($sdate5);
$date2 = new DateTime($edate5);
$count5 = date_diff($date1,$date2);
$total = $count5->days;
$inlinedate5 = $total;
$grandtotalinline = $inlinedate1 + $inlinedate2 + $inlinedate3 + $inlinedate4 + $inlinedate5;
/* End Jail Calculator */

/* Start Speedy Calculator */
$ctype = "$caseType";
switch ($ctype) {
case "Misdemeanor":
$mdate = New DateTime($arrestDate);
$mdate->add(new DateInterval('P90D'));
$speedyDate= $mdate->format('m-d-Y');
break;
case "Felony":
$fdate = New DateTime($arrestDate);
$fdate->add(new DateInterval('P175D'));
$speedyDate= $fdate->format('m-d-Y');
break;
}
/* End Speedy Calculator */



Now when I choose a date in one calculator the formulas work on both either giving me zeros or just a certain # of days. How can i stop this behavior. for an example please see http://www.philadler.com/newylo/jail-credit-calculator.

Edited by phil_adler - 05.02.2016 21:18

Moonsoft support 2016-02-08 09:51:19

Hi,
yes, inside one calculator, all code is executed from top to bottom when you launch the calculation (either with the calculate button, or because of the inline fields). If you want to separate the two calculators, you should create another calculator, so each one will have its fields and code, and then create a new module typed 'Calcbuilder', select the second calculator and publish at the same position than the original.

Hope this helps, regards

...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!
...
List Manager

Build different lists for your site

Buy now!