<?php 
    include("../config.php");
    include("../Datatable.php");
    $where = '';
    $type  = $_GET['lr_no'];
    

    $obj = new Datatable($conn);

    $obj->aColumns      = array('id','ref_no', 'image','remark','created_id');
    $obj->eColumns      = array('id');
    $obj->sIndexColumn  = "id";
    $obj->sTable        = "image_master";
    $obj->myWhere       = " WHERE company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND DATE(created_datetime)>='".$_SESSION['from_year']."' AND DATE(created_datetime)<='".$_SESSION['to_year']."' AND ref_no = '".$type."'";
    $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)) {
        
        if($aRow['image'] != ''){
            $style = 'display:block';            
        }else{
            $style = 'display:none';
        }
        if($aRow['status'] == '0'){
            $status = 'PENDING';
        }else{
            $status = 'RECEIVED';
        }
        $temp_arr = array();
        $temp_arr[] = ++$cou;
        $temp_arr[] = $aRow['remark'];
        
            $str = '';
            $str .= '<a href="assets/upload/truck_document/'.$aRow['image'].'" class="btn btn-primary" data-toggle="tooltip" data-placement="top" style="width:30%;" title="VIEW DOCUMENTS...!!" target="_blank" style="'.$style.'"><em class="fa fa-file-image-o"></em></a>&nbsp;';

            $str .= '<a href="assets/upload/truck_document/'.$aRow['image'].'" class="btn btn-primary" data-toggle="tooltip" data-placement="top" style="width:30%;" title="DOWNLOAD DOCUMENTS...!!" download="" style="'.$style.'"><em class="fa fa-cloud-download"></em></a>&nbsp;';

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

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