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

include_once("db_connect.php");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 

$query = "SELECT sum(case when status = '0' then 1 else 0 end) baru, 
            sum(case when status = '1' then 1 else 0 end) aktif,
            sum(case when status = 'C' then 1 else 0 end) selesai,
            sum(case when status = '9' then 1 else 0 end) nfa,
            count(*) total  
            from reports ";
$dbresult = $mysqli->query($query);

$mysqli->close();


$data = [];
while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){

    $data[] = array(
        'baru' => $row['baru'],
        'aktif' => $row['aktif'],
        'selesai' => $row['selesai'],
        'nfa' => $row['nfa'],
        'total' => $row['total']
    );

}


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

echo $result;

?>