<?php
include("../include/session.php");

	
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	
	if ($_SESSION['rate']=='150') {
	        $o1_min = ($_SESSION['hours']*60) + $_SESSION['min'];
			$o2_min = '0';
	}
	if ($_SESSION['rate']=='200') {
	        $o2_min = ($_SESSION['hours']*60) + $_SESSION['min'];
			$o1_min = '0';
	}
	
	$user_id = $_SESSION['username'];
	date_default_timezone_set('Africa/Khartoum');
    $entry_time = date("Y-m-d H:i:s",time()-3600);
	
	$table_name = $_SESSION['db_prefix']."_time_record";
	$overtime_query = "INSERT INTO $table_name (`date`, `emp_id`, `status`, `status_2`, `clock_in`, `clock_out`, `w_min`, `l_min`, `e_min`, `o1_min`, `o2_min`, `type`, `reason`, `checked`, `entry_by`, `entry_time`) VALUES (
			'".$_SESSION['overtime_date']."',
			'".$_SESSION['emp_id']."',
			'O',
			'O',
			'0',
			'0',
			'0',
			'0',
			'0',
			'".$o1_min."',
			'".$o2_min."',
			'O',
			'".$_SESSION['reason']."',
			'2',
			'".$user_id."',
			'".$entry_time."'
			)";
	execsql($overtime_query);
	
		
	$table_name = $_SESSION['db_prefix']."_tracking_hr";
   $trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_time."' ,'".$_SESSION['username']."', '22', '".$_SESSION['emp_id']."',  '".$_SESSION['rate']."' ,'".$_SESSION['hours']."','".$_SESSION['min']."')";
   $trackingResult = mySQL_query($trackingQuery);
	
	
	
	if (isset($_GET['new_button']) )
	   {
		 $action='overtimeWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='worked_hours_list.php?date=0';
	  }
	
	 
     $_SESSION['emp_id']="";
     $_SESSION['overtime_date'] = date('Y-m-d');
     $_SESSION['employee_name'] = "";
	 $_SESSION['rate'] = "";
	 $_SESSION['hours'] = "";
	 $_SESSION['min'] = "";
	 $_SESSION['reason'] = "";

	 
?>

<script language="javascript" type="text/javascript">
        <!--
		  window.location="<?php echo $action ?> ";
        -->
       </script>



