Monday, 17 February 2014

The Job Suspend issue Resolved

Today I wanted to work on how to get around if a job was suspended multiple times by a technician. I had a few idea's how to do this:
a) Take the start and finish time of when the job was suspended and then take this time away from the grand total time taken (Job start and Job Finish).
b)Take the start time of the job but when suspended take the job Start time away from the time it was suspended and add this to a TotalTimeTaken field in the database. Then once the the job was unsuspended it would be given the current time of when it was unsuspended. Once the job was finish you would then add up the Start time(updated start time when unsuspended) to the finish time then add that to the TotalTimeTaken time to give a grand total of the time taken.

Even though option B sounded alot more sophisticated it was the easier of the 2 to code. As Option A would have needed another table in the database and the problem of when a when the job was suspended would become an issue. As when a job has been suspended multiple times you would have multiple times in the table for that specific job causing more confusion of working out the total of all suspended times.

With using option B this was already worked out at each stage of when the suspension took place then it would only need to add up 2 times at the end which would be the TotalTimeTaken and the start and finish time given the grand total.

I did have a few issues with coding this as subtracted to times in php wasn't as easy as I first thought. As I firstly just put the times into 2 variables an and tried to subtract it gave me the difference between them in seconds which wasnt what I wanted.
After doing some research on forums about this issue i came around the function strtotime(), this would convert the time into a string format making it into a whole number. This would then make it easier to subtract the 2 values away from one another.
After subtracting the 2 values I then was given a total, but this was still in a string format so this would need to be converted back into Time. This was done but using the Time Format built into php example code below:
gmdate("H:i:s", $total);

H = putting the time back into 24 hour format
i = Minutes with leading zeroes so from 00 to 59
s = adding the second back so from 00 to 59

This is how i got around the problem of allowing technicians to be able to suspend a job multiple times

No comments:

Post a Comment