-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchAttendanceData.php
52 lines (43 loc) · 1.54 KB
/
fetchAttendanceData.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
session_start();
require('koneksi.php');
require('auth.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$month = $_POST['month'];
// Ambil data absensi
$attendanceQuery = "SELECT DATE(waktu) as tanggal, COUNT(CASE WHEN waktu IS NOT NULL THEN 1 END) as status FROM images WHERE user = ? ";
$params = array($name);
if ($month) {
$attendanceQuery .= "AND DATE_FORMAT(waktu, '%Y-%m') = ? ";
$params[] = $month;
}
$attendanceQuery .= "GROUP BY DATE(waktu) HAVING COUNT(*) >= 2 ORDER BY tanggal";
$stmt = $conn->prepare($attendanceQuery);
$stmt->bind_param(str_repeat('s', count($params)), ...$params);
$stmt->execute();
$result = $stmt->get_result();
$attendanceData = "";
while ($row = $result->fetch_assoc()) {
// Tambahkan kode untuk menampilkan data absensi seperti sebelumnya
$attendanceData .= "<tr>......</tr>";
}
// Ambil komentar bulanan
$monthlyComment = getMonthlyComment($conn, $name, $month);
echo json_encode([
'attendanceData' => $attendanceData,
'monthlyComment' => $monthlyComment
]);
}
function getMonthlyComment($conn, $name, $month)
{
$sql = "SELECT DISTINCT comment FROM laporan WHERE nama = ? AND DATE_FORMAT(waktu, '%Y-%m') = ? AND comment IS NOT NULL LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $name, $month);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
return $row['comment'];
}
return null;
}