<?php
include("../db.php");
$requestData= $_REQUEST;
$s = $_POST['s'];
$e = $_POST['e'];
$columns = array( 
	0 =>  'name_emp',
	1 =>  'start',
    2 =>  'end',
    3 =>  'code_emp',
    4 =>  'date'
);

$sql = "
SELECT * FROM `rev_emp` left join `emp` on `emp`.`id_emp` = `rev_emp`.`id_emp`  where `rev_emp`.`date` BETWEEN '$s' and '$e'
";
$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "
SELECT * FROM `rev_emp` left join `emp` on `emp`.`id_emp` = `rev_emp`.`id_emp`  where `rev_emp`.`date` BETWEEN '$s' and '$e'";
if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( name_emp LIKE '".$requestData['search']['value']."%'  ";
	$sql.=" OR start LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR end LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR code_emp LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR date LIKE '".$requestData['search']['value']."%' )";    
}
$query=mysqli_query($db, $sql);
$totalFiltered = mysqli_num_rows($query); 
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
$query=mysqli_query($db, $sql);
$data = array();
while( $row=mysqli_fetch_array($query)) {
	$nestedData=array(); 
	$nestedData[] = $row["name_emp"];
	$nestedData[] = $row["code_emp"];
	$nestedData[] = $row["start"];
	$nestedData[] = $row["end"];
	$nestedData[] = $row["date"];
	
	$data[] = $nestedData;
}



$json_data = array(
			"draw"            => intval( $requestData['draw']),   
			"recordsTotal"    => intval( $totalData ),  
			"recordsFiltered" => intval( $totalFiltered ),
			"data"            => $data
			);

echo json_encode($json_data);

?>



