bggann
Active Member
Okay - I have a pretty complex calculation based on "Time" element plugins that is not working on "save". It does work in Ajax.
Because the time element is a bit "funny" I'm having to parse it.
The essence of the calc is
(Stop Time (hh:mm) - Start Time (hh:mm)) * hourly rate = result.
There is some rounding in there too.
My time elements are formatted at "hh:mm" - so the placeholder value will look like a string "hh,mm"
02:00 will be shown in the placeholder as
I need to covert that to a serial time so I can do the math. I have a 'tricky' method I found.
-> I replace the "," with a ":" (I use explode/implode to do that. I used explode/implode to check for non-selected times (hh:mm). STR_Replace would have changed the , to a : but would not handle if somebody had not picked a time/minute.
-> I add on a date (1/1/1980)
-> I use strtotime function.
-> I do the math on that result.
On Ajax calculation - the Dumped values are as show below
These dumps are in the calculation so they are from the same code.
On AJAX calculation dump returns (jdump) (see code below)
On SAVE the dumped values are:
Here is the code
--------------------
$start_raw = '{daily_log_7_repeat___availability_start_time_raw}';
dump($start_raw,'raw');
$start_time = explode(",",'{daily_log_7_repeat___availability_start_time_raw}');
dump($start_time,'exploded');
if ( empty($start_time[1])) {$start_time[1]="00";}
if ( empty($start_time[1])) {$start_time[1]="00";}
$start_time_text = implode(':',$start_time);
dump($start_time_text,'imploded');
$start_time_sec = strtotime('01/01/1980 '.$start_time_text.':00');
//dump($start_time,'start time');
$stop_time = explode(",",'{daily_log_7_repeat___availability_stop_time_raw}');
if ( empty($stop_time[1])) {$stop_time[1]="00";}
if ( empty($stop_time[1])) {$stop_time[1]="00";}
$stop_time_text = implode(':',$stop_time);
$stop_time_sec = strtotime('01/01/1980 '.$stop_time_text.':00');
if ($stop_time_sec < $start_time_sec) {
$stop_time_sec += 86400;
}
$total_time = (float)($stop_time_sec - $start_time_sec)/3600;
$rounded_time = round( $total_time + .4999);// Round up to next hour
return $rounded_time;
I'm running Joomla 3.7 (brand new0
I'm running Fabrik 3.6 (except for the fabrik list link which will not update and is at 3.5.2)
The Calc is set with
AJAX yes
Calc on SAVE yes
Calc on LOAD no
No extra observe fields
Because the time element is a bit "funny" I'm having to parse it.
The essence of the calc is
(Stop Time (hh:mm) - Start Time (hh:mm)) * hourly rate = result.
There is some rounding in there too.
My time elements are formatted at "hh:mm" - so the placeholder value will look like a string "hh,mm"
02:00 will be shown in the placeholder as
I need to covert that to a serial time so I can do the math. I have a 'tricky' method I found.
-> I replace the "," with a ":" (I use explode/implode to do that. I used explode/implode to check for non-selected times (hh:mm). STR_Replace would have changed the , to a : but would not handle if somebody had not picked a time/minute.
-> I add on a date (1/1/1980)
-> I use strtotime function.
-> I do the math on that result.
On Ajax calculation - the Dumped values are as show below
These dumps are in the calculation so they are from the same code.
On AJAX calculation dump returns (jdump) (see code below)
On SAVE the dumped values are:
Here is the code
--------------------
$start_raw = '{daily_log_7_repeat___availability_start_time_raw}';
dump($start_raw,'raw');
$start_time = explode(",",'{daily_log_7_repeat___availability_start_time_raw}');
dump($start_time,'exploded');
if ( empty($start_time[1])) {$start_time[1]="00";}
if ( empty($start_time[1])) {$start_time[1]="00";}
$start_time_text = implode(':',$start_time);
dump($start_time_text,'imploded');
$start_time_sec = strtotime('01/01/1980 '.$start_time_text.':00');
//dump($start_time,'start time');
$stop_time = explode(",",'{daily_log_7_repeat___availability_stop_time_raw}');
if ( empty($stop_time[1])) {$stop_time[1]="00";}
if ( empty($stop_time[1])) {$stop_time[1]="00";}
$stop_time_text = implode(':',$stop_time);
$stop_time_sec = strtotime('01/01/1980 '.$stop_time_text.':00');
if ($stop_time_sec < $start_time_sec) {
$stop_time_sec += 86400;
}
$total_time = (float)($stop_time_sec - $start_time_sec)/3600;
$rounded_time = round( $total_time + .4999);// Round up to next hour
return $rounded_time;
I'm running Joomla 3.7 (brand new0
I'm running Fabrik 3.6 (except for the fabrik list link which will not update and is at 3.5.2)
The Calc is set with
AJAX yes
Calc on SAVE yes
Calc on LOAD no
No extra observe fields