<?php 
	include("../config.php");
	include("../Datatable.php");

	$obj = new Datatable($conn);
    $obj->aColumns 		= array('lhc_balance_history.id', 'lhc_balance_history.lhc_no', 'lhc_balance_history.p_date','lhc_balance_history.payment_to', 'lhc_balance_history.created_id','lhc.agent','truck_mst.o_name','lhc_balance_history.adj_amnt');
    $obj->eColumns 		= array('lhc_balance_history.id');
    $obj->sIndexColumn 	= "lhc_balance_history.id";
    $obj->sTable 		= "lhc_balance_history";
    $obj->myWhere 		= " JOIN lhc on lhc.lhc_no = lhc_balance_history.lhc_no 
    JOIN truck_mst on truck_mst.truck_no = lhc.truck_no
    WHERE lhc_balance_history.company_id = '".$_SESSION['company_id']."' AND lhc_balance_history.branch_id = '".$_SESSION['branch_id']."' AND DATE(lhc_balance_history.p_date)>='".$_SESSION['from_year']."' AND DATE(lhc_balance_history.p_date)<='".$_SESSION['to_year']."'";
    $obj->datatable_process();

    $cou = 0;
    if(isset($_GET['iDisplayStart'])) {
    	$cou = $_GET['iDisplayStart'];
    }
    $master_user  = combine(getAllRecords('users'), 'id', 'name');
    $master_truck = combine(getAllRecords('truck_mst'), 'id', 'o_name');
    while ($aRow = mysqli_fetch_array($obj->rResult)) {
    	$lhc = mysqli_query($conn, "SELECT * FROM `lhc` WHERE `lhc_no` = '".$aRow['lhc_no']."'");
    	$lhc_row = mysqli_fetch_assoc($lhc);

		$temp_arr   = array();
		$temp_arr[] = ++$cou;
		$temp_arr[] = $aRow['lhc_no'];
		$temp_arr[] = risFormatDate($aRow['p_date'], 'd-m-Y');
		$temp_arr[] = @$master_truck[$lhc_row['owner_name']];
		$temp_arr[] = $lhc_row['agent'];
		$temp_arr[] = $aRow['payment_to'];
		$temp_arr[] = $aRow['adj_amnt'];
		$temp_arr[] = @$master_user[$aRow['created_id']];
		
		$str = '';
		
		if( hasPermission($_SESSION['user_detail']['role_id'], 'lhc_balance_payment_delete') ) {
		$str .= '<button type="button" class="btn btn-danger delete_data" id="'.$aRow["id"].'" data-toggle="tooltip" data-placement="top" title="DELETE LHC..!!" onclick="confirmDelete(this);"><em class="fa fa-trash"></em></button>&nbsp;';
		}
		$str .= '<a href="lhc/itc_new_lhc.php?eid='.$aRow['lhc_no'].'" name="edit" class="btn btn-info" data-toggle="tooltip" data-placement="top" title="ADVANCE PAYMENT PRINT..!!" target="_blank"><em class="fa fa-print"></em></a>&nbsp;';		

		$temp_arr[] = $str;
		$obj->output['aaData'][] = $temp_arr;
    }

    echo json_encode($obj->output);
    exit();
?>