<?php
include("../db.php");
$requestData= $_REQUEST;
$columns = array( 
	0 =>  'id_inv',
	1 => 'name_cus',
	2 => 'phone_cus',
	3 => 'name_inv',
	4 => 'date_inv',
	5 => 'comment_inv'
);


	$sql = "SELECT * ";
	$sql.="  from `inv` where `active_inv` = '0'";


$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;

$sql = "SELECT * ";
$sql.="  from `inv` where `active_inv` = '0'";

if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( id_inv LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR name_cus LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR phone_cus LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR name_inv 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();
$i = 0;
while( $row=mysqli_fetch_array($query)) {
	$nestedData=array(); 
	$i = $i  +1;
	
	$nestedData[] = $i;
	$nestedData[] = $row["name_cus"];
	$nestedData[] = $row["phone_cus"];
	$nestedData[] = $row['name_inv'];
	$nestedData[] = $row['date_inv'];
	$nestedData[] = $row['comment_inv'];
	$nestedData[] = 
	"
	                   <button  style='' onclick='del_cus_inv(".$row['id_inv'].")'  href='javascript:void(0)' data-role='del' data-id='".$row['id_inv']."' rel='tooltip'  data-placement='auto' data-original-title='حذف العميل' class='btn btn-danger'>حذف</button>

   ";	
	$data[] = $nestedData;
}



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

echo json_encode($json_data);

?>



