<!--Notice: (c)2013 This page is part of the management program for Tlhomeso Timbers, Gaborone, 
and developed by Customized Software (Pty) Ltd, Gaborone, Botswana. 
Customized Software holds the copyright on the source code on this and all other pages in the 
management program. For more info contact Customized Software on email: info@bwcustomized.com-->

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

	
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	
	$user_id = $_SESSION['username'];
	date_default_timezone_set('Africa/Khartoum');
    $entry_time = date("Y-m-d H:i:s",time()-3600); 
	
	
	
	$table_name2 = $_SESSION['db_prefix']."_leave_records";
	

    $balance_query = "SELECT balance FROM $table_name2 WHERE  emp_id = '".$_SESSION['emp_id']."' ORDER BY leave_id DESC LIMIT 1";
	//echo $balance_query."<br>";
    $balance_result = mySQL_query($balance_query);
    $balance_num = mysql_num_rows($balance_result);
	if ($balance_num==0) {
		$balance=0; 
	}
	else {
        $balance = mysql_result($balance_result, 0, "balance");
	}
	
	$new_balance = $balance + $_SESSION['day_no'];
	
	
   	$leave_query = "INSERT INTO $table_name2 (`emp_id`, `rec_date`, `given`, `balance`,  `reason`, `notes`) VALUES ('".$_SESSION['emp_id'] ."', '".$_SESSION['rec_date']."', '".$_SESSION['day_no']."', '".$new_balance."', '".$_SESSION['give_take']."', '".$_SESSION['notes']."') ";
   // echo $leave_query;
	execsql($leave_query);
	
		
	$table_name = $_SESSION['db_prefix']."_tracking_hr";
	$action_query = "INSERT INTO $table_name (entry_date, user, action, details) VALUES ('".$entry_time."' ,'".$user_id."','Leave days to' ,'".$_SESSION['emp_id']."' )";
	execsql($action_query);
	
	
	
	if (isset($_GET['new_button']) )
	   {
		 $action='leaveToWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='leave_employee.php?emp_id='.$_SESSION['emp_id'].'&date=0';
	  }
	
	 
     $_SESSION['emp_id']="";
     $_SESSION['day_no'] = "";
	 $_SESSION['rec_date'] = date('Y-m-d');
     $_SESSION['employee_name'] = "";
	 $_SESSION['give_take'] = "";
	 $_SESSION['notes'] = "";

	 
?>

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



