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

	
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	
	$user_id = $_SESSION['username'];
	date_default_timezone_set('Africa/Gaborone');
    $entryDate = date("Y-m-d H:i:s",time()-3600); 
	
	$table_name = $_SESSION['db_prefix']."_loans";
   	$loans_query = "INSERT INTO $table_name (emp_id, issue_date, issued_by, authorised_by, reason, notes, amount) VALUES ('".$_SESSION['emp_id'] ."' , '".$_SESSION['issue_date']."', '".$_SESSION['issued_by']."', '".$_SESSION['authorised_by']."', '".$_SESSION['use']."', '".$_SESSION['notes']."', '".$_SESSION['amount']."') ";
    execsql($loans_query);
	
	$table_name = $_SESSION['db_prefix']."_loans";
	$number_query = "SELECT loans_id FROM $table_name ORDER BY loans_id DESC LIMIT 1 ";
	$number_result = mySQL_query($number_query);
	$loans_id = mysql_result($number_result, 0, "loans_id");
	
	$table_name = $_SESSION['db_prefix']."_loans_lines";
	$line_query = "INSERT INTO $table_name (loans_id, reference_date, reference, amount_credit ) VALUES ('".$loans_id."', '".$_SESSION['issue_date']."', '".$_SESSION['use']."', '".$_SESSION['amount']."'  ) ";
	execsql($line_query);
	
		
	$table_name = $_SESSION['db_prefix']."_tracking_hr";
   $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '27', '".$_SESSION['emp_id'] ."' ,'".$_SESSION['amount']."','".$_SESSION['issued_by']."','".$loans_id."' )";
   $trackingResult = mySQL_query($trackingQuery);
	
	
	
	if (isset($_GET['new_button']) )
	   {
		 $action='loanWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='loans_list.php?date=0&emp_id=';
	  }
	
	 $_SESSION['emp_id']="";
     $_SESSION['amount'] = "";
	 $_SESSION['issued_by'] = "";
	 $_SESSION['issue_date'] = date('Y-m-d');
     $_SESSION['employee_name'] = "";
	 $_SESSION['use'] = "";
	 $_SESSION['notes'] = "";

	 
?>

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



