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


	$obj = new Datatable($conn);

	$obj->aColumns 		= array('branch', 'company_id', 'state', 'city', 'con_name', 'mobile', 'email', 'pancard', 'gst_in', 'address', 'status', 'created_id');
    $obj->eColumns 		= array('id');
    $obj->sIndexColumn 	= "id";
    $obj->sTable 		= "branch_mst";
    
    $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)) {

    	$com     = "select * from company_mst where id ='".$aRow['company_id']."'";
        $com_res = mysqli_query($conn,$com);
        $com_row = mysqli_fetch_array($com_res);

        $temp_arr = array();

		$temp_arr[] = ++$cou;
		$temp_arr[] = $aRow['branch'];
		$temp_arr[] = $com_row['name'];
		$temp_arr[] = $aRow['con_name'];
		$temp_arr[] = $aRow['mobile'];
		$temp_arr[] = $aRow['gst_in'];
		$label = '';
		if($aRow['status'] == '0'){ 
			$label .='<span class="label label-md label-warning">ACTIVE</span>';
		}else{
			$label .='<span class="label label-md label-danger">IN-ACTIVE</span>';
		}
		
		$temp_arr[] = $label;
		$temp_arr[] = @$master_user[$aRow['created_id']];

		$str = '';
		if( hasPermission($_SESSION['user_detail']['role_id'], 'branch_edit') ) {
		$str .= '<a href="index.php?page=branch_mst/add.php&eid='.$aRow['id'].'" name="edit" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="EDIT BRANCH...!!"><em class="fa fa-pencil"></em></a>&nbsp;';
		}

		if( hasPermission($_SESSION['user_detail']['role_id'], 'branch_delete') ) {
		$str .= '<button type="button" class="btn btn-danger delete_data" id="'.$aRow["id"].'" data-toggle="tooltip" data-placement="top" title="DELETE BRANCH..!!" onclick="confirmDelete(this);"><em class="fa fa-trash"></em></button>';
		}
		$temp_arr[] = $str;

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

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