[SOLVED] Calc based on Time Elements not running on Save (does Ajax)

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
  • string.gif
    [string] raw = "02,00"
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
 
I think it may be related to either 3.6 or Joomla 3.7. I'm going to look in my database - I could have sworn these calc's were running before I upgraded and if they were I'll have some test records that show it. If I can demostrate that they were, I'll restore from a backup that is prior to update and carefully track the update through Joomla -> 3.7 and/or Fabrik 3.6.
That may give you a hint.

Unfortunately - while I backed up prior to the update, it all seemed to be working so I continued development work after the update. I didn't catch this failure until training yesterday.
If I have to go back and re-do all those changes, I'm probably looking at 10-12 hours. None of those changes had to do with this particular code - but with other things.

-I'll let you know
Bob
 
Okay- I rolled back to Joomla 3.6.5 (Stable) and Fabrik 3.5.2.
The calculations operate correctly in that version - both in the AJAX and storage in the table and in the attached email.

The code in the calculation is identical except for the second of the lines:
if ( empty($start_time[1])) {$start_time[1]="00";}
if ( empty($start_time[1])) {$start_time[1]="00";}
Which is wrong anyway. It should be
if ( empty($start_time[1])) {$start_time[0]="00";}

This sets the string to "00" instead of "hh" if somebody has not selected a time.

I updated the 3.6.5/3.5.2 version to have both the "empty" statements - and it runs fine.

Next - I'll update the site to J 3.7 I guess and see if that makes any difference.
 
What can I do to help. Should I update the 'working' site from 3.5.2 to 3.6 and see if it breaks?
I don't want you off on a wild goose chase.

I'm avaliable on Skype if you want - though I'm multi-tasking...
 
Okay - I A-B'd it (didn't ABA cause I didn't go back.

With Joomla 3.6.5 and Fabrik 3.5.2 - it works.
Notice this. Availability Start and Stop are time fields directly written.
Availability hours, days cost are calculated fields based on start and stop with the code above as an exemplar.

Joomla 3.6.5 and Fabrik 3.5.2
upload_2017-4-28_15-58-53.png
With Joomla 3.6.5 and Fabrik 3.6 - it does not work.
upload_2017-4-28_16-2-56.png

These are 2 records from the same system. I entered the same start and stop times. The only difference is the bottom one is post 3.5.2->3.6 update.

Please let me know if I can help.
I'll double check the sites information to make sure you have access. This site is develop.aviation-cdps.org (that is the 3.6.5/3.6 one.)

BTW - Jdump does not work as well on the latest Joomla and or Fabrik also. Not sure what is going on there. Did Joomla do something that broke us?

Bob
 

Attachments

  • upload_2017-4-28_16-1-33.png
    upload_2017-4-28_16-1-33.png
    7.6 KB · Views: 40
I'll try and get to this tomorrow (Sunday). I had a lot of real life stuff to do today. I don't usually have a life at weekends, but this weekend I do.

-- hugh
 
Okay. Life is important! My workaround plans on this are 3 fold, and I think I can manage.

1) As long as the actual 'times' are recorded in the database - I can always come back and re-run the calcs on the submitted forms when we get this fixed. But this is kind of my last resort cause I don't like releasing this with a key component not working.

2) I may yank the calc out of the fields and do it in the plugin and see if that works (again - temporarily - since it is important to display them if possible so people can verify the data they entered.

3) I may shift to a text field with a ##:## type mask to force compliance with time formats. In theory my calcuation should be very close to correct for that structure and I can just drop the replacement of , with :.

I'll takle these Monday morning - I'm on a damn satellite internet here at my house and I've hit my throttle for the month which means I've got terrible performance (Not that satellite interenet is every anything but terrible, but when you are throttled, it is even more terrible. HINT: when Hughs or DISH or any of those satellite services brag about what they provide, they are lying. It is overpriced and work terribily, and they make yo usign u)
I can't replicate this.

Which site is this on?

-- hugh
It's on both sites in my sites page. Aviation-dfcp.org and develop.aviation-dfpc.org. I created admin login for you on both, details in sites. I'll be online in Skype in about 30 min
 
Hugh - I left you a long message on Skype. I'll be working on the "aviation" site - I'd recommend you look at develop.aviation. See the sites or my Skype.

-Bob
 
Okay - I'll give it a try. Could I just patch this code in or do I need to pull a full git?
 
That got it -
I pulled just the code that changed (I know that is not the "proper" method, but I'm trying to be quick here.) That got it. Seems to be calculating correctly now.

I'm going to run a full suite of test on calcs, but hopefully this was the only problem and was causing all the other calc issues.
Note - I fixed this only on the main site, not the develop site since the main site is the one that is 'current'.

Thanks Again!

Bob
 
Okay - cool - I was able to verify that this code change resolved the issue. Calc's are now running based on Time Element in repeated groups on submit. (sorry - another corner case ....)

I did find another problem which I'll put in a different string - and that I have a work around for so it is something that should be addressed at some time but is not as critical.

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

Thank you.

Members online

Back
Top