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

$officer = $_GET['o'];
/*
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 
            SUM(CASE WHEN status = '0' THEN 1 ELSE 0 END) AS 'notify',
            SUM(CASE WHEN status = 'C' THEN 1 ELSE 0 END) AS 'selesai',
            SUM(CASE WHEN (status <> '0' AND status <> 'C') THEN 1 ELSE 0 END) AS 'semasa'
        FROM reports WHERE officer = '" .$officer. "' ";
$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(
        'officer' => $officer,
        'notify' => $row['notify'],
        'selesai' => $row['selesai'],
        'semasa' => $row['semasa']
    );
}

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

echo $result;

?>