<?php
include("../db.php");
$requestData= $_REQUEST;
$s = $_POST['s'];
$e = $_POST['e'];
$columns = array( 
	0 =>  'name_inp',
	1 =>  'value_inp',
	2 =>  'comment_inp',
	3 =>  'date_inp',
    4 =>  'time',
	5 => 'name_emp',
	6 => 'name_cata'
);

$sql = "
SELECT * FROM `inp_mony` left join `inp` on `inp`.`id_inp` = `inp_mony`.`id_inp`  left join `emp` on `emp`.`id_emp` = `inp_mony`.`id_user` 
left join `cata` on `cata`.`id_cata` = `inp_mony`.`id_member`
where `inp_mony`.`date_inp` between '$s' and '$e'
";
$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "
SELECT * FROM `inp_mony` left join `inp` on `inp`.`id_inp` = `inp_mony`.`id_inp`  left join `emp` on `emp`.`id_emp` = `inp_mony`.`id_user`
 left join `cata` on `cata`.`id_cata` = `inp_mony`.`id_member`

where `inp_mony`.`date_inp` between '$s' and '$e'
";
if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( name_inp LIKE '".$requestData['search']['value']."%'  ";
	$sql.=" OR value_inp LIKE '".$requestData['search']['value']."%' ";       
	$sql.=" OR comment_inp LIKE '".$requestData['search']['value']."%' ";       
	$sql.=" OR date_inp LIKE '".$requestData['search']['value']."%' ";       
	$sql.=" OR time LIKE '".$requestData['search']['value']."%' ";       
	$sql.=" OR name_cata LIKE '".$requestData['search']['value']."%' ";       
	$sql.=" OR name_emp 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_inp"];
	$nestedData[] = $row["value_inp"];
	$nestedData[] = $row["name_emp"];
	$nestedData[] = $row["name_cata"];
	$nestedData[] = $row["comment_inp"];
	$nestedData[] = $row["date_inp"];
	$nestedData[] = $row["time"];
	$data[] = $nestedData;
}



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

echo json_encode($json_data);

?>



