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

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 


$emp_id = $_GET['emp_id_text'];


$table_name = $_SESSION['db_prefix']."_sick_records";
$balance_query = "SELECT balance FROM $table_name WHERE emp_id = '".$emp_id."' ORDER BY sick_id DESC LIMIT 1";
$balance_result = mySQL_query($balance_query);
$balance_num = mysql_num_rows($balance_result);
if ($balance_num!=0) {
$balance = mysql_result($balance_result, 0, "balance");
}
else{
	$balance=0;
}


$record_date = $_GET['record_date'];
$days1 = $_GET['sick_days1_select'];
$days2 = $_GET['sick_days2_select'];
$add_subtract = $_GET['add_subtract_radio'];
$reason = $_GET['sick_reason_select'];
$notes = $_GET['notes_text'];

if ($add_subtract=='+') {
	$days_plus = $days1.'.'.$days2;
	$balance=$balance+$days_plus;
	} 
	else { $days_plus = '';
	}
	
if ($add_subtract=='-') {
	$days_minus = $days1.'.'.$days2;
	$balance=$balance-$days_minus;
	} 
	else {
		 $days_minus = '';
		 }


$table_name = $_SESSION['db_prefix']."_sick_records";
$sick_query = "INSERT INTO $table_name (emp_id, rec_date, days_plus, days_minus, balance, reason, notes ) VALUES ('".$emp_id."', '".$record_date."', '".$days_plus."', '".$days_minus."', '".$balance."', '".$reason."', '".$notes."') ";
execsql($sick_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 ('".$entry_date."' ,'".$_SESSION['username']."', '32', '".$emp_id."' ,'".$days_plus."','".$days_minus."','".$balance."' )";
   $trackingResult = mySQL_query($trackingQuery);




if (isset($_GET['save_close_button']) )
	   { ?>
       <script>
	 		 window.location="../hr_module/hr_main.php?date=0";
		</script>
        <?php		 
	   }
	   
	if (isset($_GET['save_button']) )
	   {  ?>
       <script>
	         window.location="sick_adjust.php?emp_id="
	   </script>
        <?php		 
	   }
	   ?>

