Jump to content


Photo

Need Advice *SOLVED*


  • Please log in to reply
12 replies to this topic

#1 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 18 September 2006 - 01:24 AM

I am making a small script the totals hours using military based time. It is to total hours taken off between each driver's shift (work period). The driver's must take 10 hours off between each shift. So there are 14 input fields total. 7 inputs for their "in time" and 7 for their "out time". In time is the time the punch in and out time is the time the clock out. I am not sure how to work with the military time server wise though? Like getting the server to understand 17:00 is 5pm and 04:00 is 4am. Then to have it find the hours between 5pm and 4am. Here is my attempt at the basics of it:

<?php

if (isset($_POST['submit'])) {

function total_time($out, $in) {
	$good = $out + 10;
	$total = $out + $in;
	if ($total > $good) {
	$over = $total - $good;
	echo "The driver only took off: $over hours<br />";
	} 
	else {
	$within = $good - $total;
	echo "The driver is good, getting $within hours<br />";
	}
}

$combined_one = total_time($_POST['out_one'],$_POST['in_one']);
$combined_two = total_time($_POST['out_two'],$_POST['in_two']);
$combined_three = total_time($_POST['out_three'],$_POST['in_three']);
$combined_four = total_time($_POST['out_four'],$_POST['in_four']);
$combined_five = total_time($_POST['out_five'],$_POST['in_five']);
$combined_six = total_time($_POST['out_six'],$_POST['in_six']);
$combined_seven = total_time($_POST['out_seven'],$_POST['in_seven']);

}

?>

<form name="time" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?view=dot&page=employees/dot/forms/time">
<table>

   <tr>
      <td></td>
      <td align="right">Out One:</td>
      <td>&nbsp;<input type="text" name="out_one" id="addbasicinput"></td>
   </tr>

   <tr>
      <td align="right">In One:</td>
      <td>&nbsp;<input type="text" name="in_one" id="addbasicinput"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Out Two:</td>
      <td>&nbsp;<input type="text" name="out_two" id="addbasicinput"></td>
   </tr>

   <tr>
      <td align="right">In Two:</td>
      <td>&nbsp;<input type="text" name="in_two" id="addbasicinput"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Out Three:</td>
      <td>&nbsp;<input type="text" name="out_three" id="addbasicinput"></td>
   </tr>

   <tr>
      <td align="right">In Three:</td>
      <td>&nbsp;<input type="text" name="in_three" id="addbasicinput"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Out Four:</td>
      <td>&nbsp;<input type="text" name="out_four" id="addbasicinput"></td>
   </tr>

   <tr>
      <td align="right">In Four:</td>
      <td>&nbsp;<input type="text" name="in_four" id="addbasicinput"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Out Five:</td>
      <td>&nbsp;<input type="text" name="out_five" id="addbasicinput"></td>
   </tr>

   <tr>
      <td align="right">In Five:</td>
      <td>&nbsp;<input type="text" name="in_five" id="addbasicinput"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Out Six:</td>
      <td>&nbsp;<input type="text" name="out_six" id="addbasicinput"></td>
   </tr>

   <tr>
      <td align="right">In Six:</td>
      <td>&nbsp;<input type="text" name="in_six" id="addbasicinput"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Out Seven:</td>
      <td>&nbsp;<input type="text" name="out_seven" id="addbasicinput"></td>
   </tr>

   <tr>
      <td align="right">In Seven:</td>
      <td>&nbsp;<input type="text" name="in_seven" id="addbasicinput"></td>
      <td></td>
   </tr>

</table>

		<br><input name='submit' type='submit' value='Total Hours' id="addbasicselect">
</form>

Any suggestions/guidance/advice/help is greatly appreciated. Thanks.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 September 2006 - 01:38 AM

A few observations.

Server time is not necessarily your local time. You may need to adjust any php calculated/derived dates and times based on that difference.

The 24-hour format is much better to work with for anything like this.

Allowing your users to enter time is what they think of as time is going to lead to problems, e.g. Time in - 7, 7am, just before seven, are all understandable human times and incomprehensible to your script.  Choose a javascript date/time picker that lets them choose the times that are entered - that way YOU control the format of data entry.

No matter what instructions you provide for filling in the form, users will find a way to mess up.  Your design task/scripting task is to make it as easy as possible for them to avoid making what you or I might think of as dumb mistakes, and to catch those before they add 'bad' data to your database.
Legend has it that reading the manual never killed anyone.
My site

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 18 September 2006 - 01:43 AM

We have software that give us a print off of there time sheet, but does not total the time off inbetween shifts. There will only be one person ever using this script to total the times. Would it be possible to assign the military times to variables? I mean I know that would be possible, but I am not sure how I would get the server to be able to tell between am/pm etc. This script is just to make it easier for that one person to total the times, note them on paper.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 September 2006 - 01:51 AM

With only one user, many of your data entry problems will loom less large.

Is the user trainable to enter times in 24-hour format (let's hope so) as that would solve that problem.  The alternative really is a date-picker because any decent one lets the user pick 'human' times/dates but can put a date/time result into the form field in any format you want.

http://www.rainfores...etimepicker.htm - example 6 looks like what'll work for you.
Legend has it that reading the manual never killed anyone.
My site

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 18 September 2006 - 01:59 AM

Yes, the person is trainable to enter the time in 24-hour format.  I would probably need to find a reference sheet for them though.

#6 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 18 September 2006 - 02:00 AM

Oh, and the only problem I see with the picker is that it does date and time. Whereas we only need the time.

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 September 2006 - 02:04 AM

I'm sure a little googling will find a free time-picker for you :)

And why don't you need date?  If my start time is 10pm on Monday and my end time is 8am on Tuesday, the script (and the poor soul entering the data) will need to know that's a 10-hour shift, not a minus 14-hour shift ...
Legend has it that reading the manual never killed anyone.
My site

#8 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 18 September 2006 - 02:24 AM

This script is just for the sake of totaling hours taken off between shifts. It won't store anything to a db etc, just output the results each time. All I need it to output is the amount of hours/minutes between the off time and start time the next morning. If the driver has taken off 10 hours it will output good, along with the total time he took off. If he took off less than 10 hours, it will output bad, along with the time he took off. I guess in order to do that I need to track the date as well?

#9 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 18 September 2006 - 05:00 PM

I think I see what your saying, my only problem is getting the server to recognize it through my coding. This is beginning to become more complicated that what I originally planned.

#10 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 20 September 2006 - 10:47 PM

Sorry to bump this guys, but I am still trying to get it straight. No luck yet.

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 September 2006 - 02:57 AM

Can't help right now, but I thought at least I'd post to let you know I'll be back tomorrow if you're still stuck.  Meantime, if you post some code anyone might be able to help you over the next hurdle.  If you have a live demonstration - working or not - that might help us visualize what's happening or not happening.  Don't forget to be as explicit as possible in describing what's not working properly.
Legend has it that reading the manual never killed anyone.
My site

#12 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 21 September 2006 - 07:27 AM

Thanks Andy, I really appreciate you taking the time to help. Let me be more specific about what I am trying to do:

We have drivers that work x amount of hours a day (Monday through Friday, possibly through Saturday and Sunday). They punch in every day and punch out (meaning they have a time card they they fill in when they start work and when they finish work). Our drivers are required to take off 10 hours after each shift before they can start the next shift. So what I am trying to do is make an input system that goes off of their hours (start time and finish time), to make sure they have taken off the 10 hours before starting the next shift.

We have print offs that give us that information based in military time. We could manually total each drivers time between shifts etc, but with 250 something drivers it gets to be a pain for the guy doing it. So what I am aiming to do is make a simple calculator to figure it out. I figure I need 7 input fields as shown in the live example located at:

http://www.mach5software.com/demo.php

My problem is that I am not sure how to really work with the time (24-hour format) and getting the server to distinguish between the days etc. Here is what I got for the code:

<?php

if (isset($_POST['submit'])) {

   //Check hours between their out time and in time to make sure they take 10 hours off
   function total_time($out, $in) {
	//A good time would be their out time plus 10 hours... not sure if I am doing that right at all.
	$good = $out + 10;
	//The total time would be the time between their out time and in time the next day. I am sure im doing this part wrong.
	$total = $out - $in;
	//If the total time ($total) is less-than or equal to the good time ($good) then that means the driver didn't take 10 hours off.
	if ($total < $good) {
	$over = $good - $total;
	echo "The driver only took off: $over hours<br />";
	} 
	else {
	//The driver IS taking atleast 10 hours off. Find the exact hours over the 10 hours he took off. Probably going about this wrong as well.
	$within = $total - $good;
	echo "The driver is good, getting $within hours<br />";
	}
   }


   $total_one = total_time($_POST['monday_out'],$_POST['tuesday_in']);
   $total_two = total_time($_POST['tuesday_out'],$_POST['wednesday_in']);
   $total_three = total_time($_POST['wednesday_out'],$_POST['thursday_in']);
   $total_four = total_time($_POST['thursday_out'],$_POST['friday_in']);
   $total_five = total_time($_POST['friday_out'],$_POST['saturday_in']);
   $total_six = total_time($_POST['saturday_out'],$_POST['sunday_in']);
   $total_seven = total_time($_POST['sunday_out'],$_POST['monday_in']);

}

?>

<form name="time" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>

   <tr>
      <td></td>
      <td align="right">Monday Out:</td>
      <td>&nbsp;<input type="text" name="monday_out"></td>
   </tr>

   <tr>
      <td align="right">Tuesday In:</td>
      <td>&nbsp;<input type="text" name="tuesday_in"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Tuesday Out:</td>
      <td>&nbsp;<input type="text" name="tuesday_out"></td>
   </tr>

   <tr>
      <td align="right">Wednesday In:</td>
      <td>&nbsp;<input type="text" name="wednesday_in"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Wednesday Out:</td>
      <td>&nbsp;<input type="text" name="wednesday_out"></td>
   </tr>

   <tr>
      <td align="right">Thursday In:</td>
      <td>&nbsp;<input type="text" name="thursday_in"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Thursday Out:</td>
      <td>&nbsp;<input type="text" name="thursday_out"></td>
   </tr>

   <tr>
      <td align="right">Friday In:</td>
      <td>&nbsp;<input type="text" name="friday_in"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Friday Out:</td>
      <td>&nbsp;<input type="text" name="friday_out"></td>
   </tr>

   <tr>
      <td align="right">Satuday In:</td>
      <td>&nbsp;<input type="text" name="saturday_in"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Saturday Out:</td>
      <td>&nbsp;<input type="text" name="saturday_out"></td>
   </tr>

   <tr>
      <td align="right">Sunday In:</td>
      <td>&nbsp;<input type="text" name="sunday_in"></td>
      <td></td>
   </tr>

   <tr>
      <td></td>
      <td align="right">Sunday Out:</td>
      <td>&nbsp;<input type="text" name="out_seven"></td>
   </tr>

   <tr>
      <td align="right">Moday In:</td>
      <td>&nbsp;<input type="text" name="monday_in"></td>
      <td></td>
   </tr>

</table>

		<br><input name='submit' type='submit' value='Total Hours'>
</form>

Once again, any help/comments/suggestions are appreciated. Thanks.

#13 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 22 September 2006 - 02:52 PM

*bumps* in hopes that Andy or someone helps. Sorry guys, I am just totally lost. Any direction would be greatly appreciated.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users