<?php
include("../db.php");
$requestData= $_REQUEST;
$columns = array( 
	0 =>  'id_expense',
	1 => 'name_expense'
);

$sql = "SELECT * ";
$sql.=" FROM expen where `active_expense` = '0'";
$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "SELECT * ";
$sql.=" FROM expen where `active_expense` = '0'";
if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( id_expense LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR name_expense 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["id_expense"];
	$nestedData[] = $row["name_expense"];
	$nestedData[] = "<button type='button' class='btn btn-danger' onclick=del_table_1('".$row['id_expense']."',6)>حذف</button>
	<button type='button' class='btn btn-success' onclick='get_exp(".$row['id_expense'].")'>تعديل</button>
	<button type='button' class='btn btn-warning' onclick='insert_mony(".$row['id_expense'].",0)'>صرف</button>";
	
	$data[] = $nestedData;
}



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

echo json_encode($json_data);

?>



