-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMonthIndicators.php
37 lines (30 loc) · 996 Bytes
/
getMonthIndicators.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
session_start();
require('koneksi.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$sql = "SELECT DISTINCT DATE_FORMAT(waktu, '%Y-%m') as month,
DATE_FORMAT(waktu, '%M %Y') as monthName,
SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) as unacceptedTasks
FROM laporan
WHERE nama = ?
GROUP BY DATE_FORMAT(waktu, '%Y-%m')
ORDER BY month DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $name);
$stmt->execute();
$result = $stmt->get_result();
$months = array();
while ($row = $result->fetch_assoc()) {
$months[] = array(
'month' => $row['month'],
'monthName' => $row['monthName'],
'hasUnacceptedTasks' => $row['unacceptedTasks'] > 0
);
}
echo json_encode($months);
$stmt->close();
} else {
echo json_encode(['error' => 'Invalid request method']);
}
$conn->close();