<?php
require_once("config/configDB.php"); 

// storing  request (ie, get/post) global array to a variable  
$requestData= $_REQUEST;


$userpermissionEdit 	= $_POST['userpermissionEdit'];
$userpermissionDelete 	= $_POST['userpermissionDelete'];
//cname, city, pincode, mobile, gst_type, ccode, open_balance
$columns = array( 
// datatable column index  => database column name
	0 => 'id', 
	1 => 'utilize_code',
	2 => 'utilizedate',
	3 => 'hole',
	4 => 'totalfeet',
	5 => 'labour',
    6 => 'thotta90',
    7 => 'ed'
);

$sql = "SELECT id FROM explosive_utiliz_hdr where isdelete=1 and status=''";
$query=mysqli_query($conn, $sql) or die("customergriddata.php: get customer Data step 1");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  

$sql = "SELECT utilize_code,process_type, utilizedate,hole,contractor,total_cost, totalfeet, labour ,id  FROM explosive_utiliz_hdr WHERE 1=1 and isdelete=1 and status=''";
if( !empty($requestData['search']['value']) ) {   

	$sql.=" AND ( utilize_code LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR utilizedate LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR process_type LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR hole LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR totalfeet  LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR labour LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR total_cost LIKE '".$requestData['search']['value']."%' ";
	
    $sql.=" OR id LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("customergriddata.php: get customer Data step 2");
$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($conn, $sql) or die("customergriddata.php: get customer Data step 3");
	
//cname, city, pincode, mobile, gst_type, ccode, open_balance
$data = array();
while( $row=mysqli_fetch_array($query) ) { 
	$nestedData=array(); 

	$nestedData[] = $row["id"];
	//$nestedData[] = $row["utilize_code"];
	$nestedData[] = $row["utilizedate"];
	$nestedData[] = $row["process_type"];
	$nestedData[] = $row["hole"];
	$nestedData[] = $row["totalfeet"];
	$nestedData[] = number_format($row["total_cost"],2,'.','');
	
    
	
	//$date = new DateTime($row["employee_joining_date"]); 
	//$nestedData[] = $date->format('d-m-Y'); //only fetching date
	//$nestedData[] = $row["open_balance"];
	
	$edit  = "";
	if($userpermissionEdit==1) {
		$edit .="<a href='explosive_utilizeEdit.php?id=".$row['id']."' id='customerMaster_".$row['id']."' class='btn btn-primary'>Edit</a>&nbsp";
	}

	$Delete  = "";
	if($userpermissionDelete==1) {
		$Delete .="<a id='customerMasterDelete_".$row['id']."' class='btn btn-primary' onclick='ConfirmcustomerMasterDelete(".$row['id'].")' >Delete</a>";
	}
	$nestedData[] = $edit."&nbsp".$Delete;
	
	$data[] = $nestedData;
}

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

echo json_encode($json_data);  

?>
