<?
header('Access-Control-Allow-Origin: *');
//header('Content-Type: application/json');

//$id = $_GET['id'];
/*
if ($id){
    echo $id;
}
else {
    echo 'All Items';
}
*/


//$mysqli = new mysqli("localhost", "afxtech1_myori", "myori2017", "afxtech1_myori");
include_once("db_connect.php");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 


//$id = '003';
//$query = "SELECT * FROM reports WHERE status = '0' ORDER BY rpt_txn ";
//$query = "SELECT id, rpt_txn, status, DATE(rpt_txn) as 'rpt_date', area, remark1, remark2 FROM reports WHERE officer is NULL or officer = '' ORDER BY rpt_txn ";

//fuad:20211107 
$query = "SELECT id, rpt_txn, status, DATE(rpt_txn) as 'rpt_date', area, remark1, remark2, product_category FROM reports WHERE officer is NULL or officer = '' ORDER BY rpt_txn ";
$dbresult = $mysqli->query($query);

//echo 'Hello...here1';
//die();

$mysqli->close();

$data = [];

while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){
    $dt = date_create($row['rpt_date']);
    $data[] = array(
        'id' => $row['id'],
        'rpt_txn' => $row['rpt_txn'],
        'status' => $row['status'],
        'rpt_date' => $row['rpt_date'],
        'dt' => date_format($dt,"M d"),
        'loc' => $row['area'],
        'remark1' => $row['remark1'],
        'remark2' => $row['remark2'],   
        
        'pcategory' => $row['product_category'],   
    );
}

if($dbresult){
    $result = json_encode($data);              
}
else {
    $result = "{success:false}";
}

echo $result;

?>