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


	$obj = new Datatable($conn);

	$obj->aColumns 		= array('id','commission_date', 'vendor_id', 'bill_no', 'bill_date', 'bill_amount', 'commission_per','commission_amt', 'created_id');
    $obj->eColumns 		= array('id');
    $obj->sIndexColumn 	= "id";
    $obj->sTable 		= "mst_commission";
    $obj->myWhere 		= "WHERE company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."'";
    $obj->groupBy       = 'GROUP BY bill_no';
    $obj->datatable_process();

    $cou = 0;
    if(isset($_GET['iDisplayStart'])) {
    	$cou = $_GET['iDisplayStart'];
    }
    $master_user = combine(getAllRecords('users'), 'id', 'name');
    while ($aRow = mysqli_fetch_array($obj->rResult)) {
        $temp_arr = array();
        
        $party      = "SELECT * FROM `vendor_master` WHERE `id` = '".$aRow['vendor_id']."'";
        $party_res  = mysqli_query($conn,$party);
        $party_row  = mysqli_fetch_array($party_res);
        
		$temp_arr[] = ++$cou;
		$temp_arr[] = $party_row['name'];
		$temp_arr[] = substr($aRow['bill_no'], 9);
        $temp_arr[] = date("d-m-Y", strtotime($aRow['commission_date']));
		$temp_arr[] = date("d-m-Y", strtotime($aRow['bill_date']));
		$temp_arr[] = $aRow['bill_amount'];
        $temp_arr[] = $aRow['commission_per'];
		$temp_arr[] = $aRow['commission_amt'];
        $temp_arr[] = @$master_user[$aRow['created_id']];
		
		$str = '';        
		if( hasPermission($_SESSION['user_detail']['role_id'], 'bill_delete') ) {
		$str .= '<button type="button" class="btn btn-danger delete_data" id="'.$aRow["bill_no"].'" data-toggle="tooltip" data-placement="top" title="DELETE BILL..!!" onclick="confirmDelete(this);"><em class="fa fa-trash"></em></button>&nbsp;';
		}

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

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