<?php 
session_start();
include('../includes/dbcon.php');

$str=" ";

$error=0;

$edate=date("Y-m-d");
$userid=$_SESSION['hrm_id'];

$tdate= trim($_POST['tdate']);
$r_id= trim($_POST['r_id']);
$emp_id=$_SESSION['hrm_emp_id'];
//$emp_id= trim($_POST['emp_id']);


///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     Validation    !!!!!!!!!!
if (empty($emp_id)){ $emp_id=0; }
if (empty($r_id)){
	$r_id=0;
}
else {
		

$ll="select * from tran_master where t_date='$tdate' and  userid=$userid and emp_id=$emp_id ";


$querydoc=mysqli_query($con,"select * from tran_master where t_date='$tdate' and  userid=$userid and emp_id=$emp_id  ")or die(mysqli_error());
	 $count=mysqli_num_rows($querydoc);

	 echo $count;
	 if ($count>0){ 

echo "<script type='text/javascript'>alert('Already entered!');</script>";
				echo "<script>document.location='day_start.php'</script>";

	 } 

	 	else {



mysqli_begin_transaction($con);

//$ss="INSERT INTO tran_master(t_date,r_id,t_end,userid,edate) 
			// VALUES($tdate,$r_id,$userid,'$edate'";

//echo $ss;			 	
if ($emp_id>0)
{
if ( mysqli_query($con,"INSERT INTO tran_master(t_date,r_id,emp_id,userid,edate) 
			 VALUES('$tdate',$r_id,$emp_id,$userid,'$edate' )  ")or die(mysqli_error($con)))
	        {

	         

							mysqli_commit($con);
							echo "<script>document.location='day_start.php'</script>"; 

			}  
	        
}

}  /// else
}
