<?php
require "config.php";

header('Content-Type: application/json');

$total = $conn->query("
SELECT COUNT(*) j FROM pengajuan
")->fetch_assoc()['j'];

$proses = $conn->query("
SELECT COUNT(*) j FROM pengajuan
WHERE LOWER(TRIM(status_surat))='menunggu'
OR status_surat IS NULL
OR status_surat=''
")->fetch_assoc()['j'];

$selesai = $conn->query("
SELECT COUNT(*) j FROM pengajuan
WHERE LOWER(TRIM(status_surat))='diterima'
")->fetch_assoc()['j'];

$ditolak = $conn->query("
SELECT COUNT(*) j FROM pengajuan
WHERE LOWER(TRIM(status_surat))='ditolak'
")->fetch_assoc()['j'];

echo json_encode([
"total"=>(int)$total,
"proses"=>(int)$proses,
"selesai"=>(int)$selesai,
"ditolak"=>(int)$ditolak
]);
