<?php

global $db;
ini_set("display_errors", "0");
error_reporting(E_ALL);
$requestData= $_REQUEST;
$columns = array( 
	0 => 'ref_no',
	1 => 'created_on',
	2 => 'so_id',
	4 => 'exporter_name',
	
);

$data = $db->query("SELECT COUNT(id) as jumlah FROM custom_declarations WHERE company_id = '" . $_SESSION['company_id'] . "'");

$count = $data[0]["jumlah"];
$totalData = $count;
$totalFiltered = $totalData;

$sql = "SELECT * FROM custom_declarations WHERE company_id = '".$_SESSION['company_id']."'";
$data = $db->query($sql);
$totalFiltered = count($data);
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
$data = $db->query($sql);

$qweqwe = array();

foreach ($data as $key => $value) {
	
    $nestedData = array();
	$nestedData[] = $value["ref_no"];
	$nestedData[] = date('d/m/Y', strtotime($value["created_on"]));
	$nestedData[] = getSOData($value["so_id"], "marking_no");
	$nestedData[] = getSOData($value["so_id"], "supplier_company_name");
	$nestedData[] = $value["exporter_name"];
	$nestedData[] = '<div class="btn-group">
						<button class="btn green btn-xs btn-circle btn-outline dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false"> Actions
							<i class="fa fa-angle-down"></i>
						</button>
						<ul class="dropdown-menu" role="menu">
							<li>
								<a href="/shipping-order/details/'.$value["so_id"].'">
									<i class="icon-docs"></i> Details </a>
							</li>                                                                
						</ul>
					</div>';
	
	$qweqwe[] = $nestedData;
	
	
}
$json_data = array(
			"draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. 
			"recordsTotal"    => intval( $totalData ),  // total number of records
			"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
			"data"            => $qweqwe   // total data array
			);
echo json_encode($json_data);
