-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_document_status.php
More file actions
61 lines (49 loc) · 2.04 KB
/
check_document_status.php
File metadata and controls
61 lines (49 loc) · 2.04 KB
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
53
54
55
56
57
58
59
60
61
<?php
// Database connection
require_once 'db.php';
// Set timezone to Philippines
date_default_timezone_set('Asia/Manila');
try {
// Get all approved documents that haven't been picked up
$query = "SELECT Id, DateRequested, Status
FROM document_requests
WHERE Status = 'approved'
AND (pickup_status IS NULL OR pickup_status = 'pending')";
$stmt = $conn->prepare($query);
$stmt->execute();
$documents = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Get current time in Philippines
$currentTime = new DateTime();
foreach ($documents as $document) {
// Convert request date to DateTime
$requestDate = new DateTime($document['DateRequested']);
// Calculate the difference
$interval = $currentTime->diff($requestDate);
$daysDifference = $interval->days;
// If more than 3 days have passed
if ($daysDifference > 3) {
// Update status to OVERDUE
$updateQuery = "UPDATE document_requests
SET Status = 'OVERDUE'
WHERE Id = :documentId";
$updateStmt = $conn->prepare($updateQuery);
$updateStmt->bindParam(':documentId', $document['Id']);
$updateStmt->execute();
// Log the status change
$logQuery = "INSERT INTO status_change_logs
(document_id, old_status, new_status, change_date)
VALUES (:documentId, :oldStatus, 'OVERDUE', NOW())";
$logStmt = $conn->prepare($logQuery);
$logStmt->bindParam(':documentId', $document['Id']);
$logStmt->bindParam(':oldStatus', $document['Status']);
$logStmt->execute();
}
}
echo "Document status check completed successfully.";
} catch (PDOException $e) {
error_log("Error checking document status: " . $e->getMessage());
echo "Error checking document status. Please check error logs.";
}
// Close the connection
$conn = null;
?>