From 837112d41efc9b22e2a4e7fd5e1af5760a78f6a2 Mon Sep 17 00:00:00 2001 From: Vckynando12 Date: Tue, 25 Mar 2025 11:40:40 +0700 Subject: [PATCH] update report pdf view a part of perubahan --- resources/views/export/reports-pdf.blade.php | 230 +++++++++++++++++-- 1 file changed, 208 insertions(+), 22 deletions(-) diff --git a/resources/views/export/reports-pdf.blade.php b/resources/views/export/reports-pdf.blade.php index c00f175..b33be0d 100644 --- a/resources/views/export/reports-pdf.blade.php +++ b/resources/views/export/reports-pdf.blade.php @@ -66,6 +66,8 @@ .badge-last-access { background-color: #ede9fe; } .badge-restart-esp { background-color: #ffedd5; } .badge-restart-wemos { background-color: #fef3c7; } + .badge-sensor { background-color: #dbeafe; } + .badge-info { background-color: #e0e7ff; } @@ -94,44 +96,228 @@ @php $changes = []; - // Detect changes based on your logic - // This is a simplified example - if(isset($report['security']['motion'])) { - $changes[] = ['type' => 'Motion', 'badge' => 'badge-motion']; + $prevReport = isset($reports[$index+1]) ? $reports[$index+1] : null; + + // Security changes - only show if there's an actual change from previous value + if(isset($report['security'])) { + // Motion detection + if(isset($report['security']['motion'])) { + $currentMotion = $report['security']['motion']; + $prevMotion = ($prevReport && isset($prevReport['security']['motion'])) + ? $prevReport['security']['motion'] + : null; + + if($prevMotion !== $currentMotion && $currentMotion != 'none') { + $changes[] = [ + 'type' => 'Motion: ' . ucfirst($currentMotion), + 'badge' => 'badge-motion' + ]; + } + } + + // Security status + if(isset($report['security']['status'])) { + $currentStatus = $report['security']['status']; + $prevStatus = ($prevReport && isset($prevReport['security']['status'])) + ? $prevReport['security']['status'] + : null; + + if($prevStatus !== $currentStatus && !empty($currentStatus)) { + $changes[] = [ + 'type' => 'Status: ' . ucfirst($currentStatus), + 'badge' => 'badge-status' + ]; + } + } + + // Fan status + if(isset($report['security']['fan'])) { + $currentFan = $report['security']['fan']; + $prevFan = ($prevReport && isset($prevReport['security']['fan'])) + ? $prevReport['security']['fan'] + : null; + + if($prevFan !== $currentFan) { + $changes[] = [ + 'type' => 'Fan: ' . ucfirst($currentFan), + 'badge' => 'badge-fan' + ]; + } + } } - if(isset($report['security']['status'])) { - $changes[] = ['type' => 'Status', 'badge' => 'badge-status']; + + // SmartCab changes + if(isset($report['smartcab'])) { + // Servo status + if(isset($report['smartcab']['servo_status'])) { + $currentServo = $report['smartcab']['servo_status']; + $prevServo = ($prevReport && isset($prevReport['smartcab']['servo_status'])) + ? $prevReport['smartcab']['servo_status'] + : null; + + if($prevServo !== $currentServo && !empty($currentServo)) { + $changes[] = [ + 'type' => 'Servo: ' . $currentServo, + 'badge' => 'badge-servo-status' + ]; + } + } + + // Last access + if(isset($report['smartcab']['last_access'])) { + $currentAccess = $report['smartcab']['last_access']; + $prevAccess = ($prevReport && isset($prevReport['smartcab']['last_access'])) + ? $prevReport['smartcab']['last_access'] + : null; + + if($prevAccess !== $currentAccess && !empty($currentAccess)) { + $changes[] = [ + 'type' => 'Access: ' . $currentAccess, + 'badge' => 'badge-last-access' + ]; + } + } } - if(isset($report['security']['fan'])) { - $changes[] = ['type' => 'Fan', 'badge' => 'badge-fan']; + + // Control changes - these are boolean events, so just show them when true + if(isset($report['control'])) { + if(isset($report['control']['restartESP']) && $report['control']['restartESP'] === true) { + $changes[] = ['type' => 'ESP Restart', 'badge' => 'badge-restart-esp']; + } + + if(isset($report['control']['restartWemos']) && $report['control']['restartWemos'] === true) { + $changes[] = ['type' => 'Wemos Restart', 'badge' => 'badge-restart-wemos']; + } } - if(isset($report['smartcab']['servo_status'])) { - $changes[] = ['type' => 'Servo', 'badge' => 'badge-servo-status']; + + // Sensor changes - for the first report, show initial values + if($index === 0 || !$prevReport) { + if(isset($report['dht11'])) { + if(isset($report['dht11']['temperature'])) { + $changes[] = [ + 'type' => 'Suhu: ' . $report['dht11']['temperature'] . '°C', + 'badge' => 'badge-sensor' + ]; + } + + if(isset($report['dht11']['humidity'])) { + $changes[] = [ + 'type' => 'Kelembaban: ' . $report['dht11']['humidity'] . '%', + 'badge' => 'badge-sensor' + ]; + } + } + } else { + // For subsequent reports, only show changes in sensor values + if(isset($report['dht11']) && isset($prevReport['dht11'])) { + if(isset($report['dht11']['temperature']) && isset($prevReport['dht11']['temperature'])) { + $diff = abs($report['dht11']['temperature'] - $prevReport['dht11']['temperature']); + if($diff >= 1) { // Only show if temperature changed by at least 1 degree + $changes[] = [ + 'type' => 'Suhu: ' . $report['dht11']['temperature'] . '°C', + 'badge' => 'badge-sensor' + ]; + } + } + + if(isset($report['dht11']['humidity']) && isset($prevReport['dht11']['humidity'])) { + $diff = abs($report['dht11']['humidity'] - $prevReport['dht11']['humidity']); + if($diff >= 5) { // Only show if humidity changed by at least 5% + $changes[] = [ + 'type' => 'Kelembaban: ' . $report['dht11']['humidity'] . '%', + 'badge' => 'badge-sensor' + ]; + } + } + } + } + + // For first report (most recent), always show current state + if($index === 0) { + if(empty($changes)) { + $changes[] = ['type' => 'Status saat ini', 'badge' => 'badge-info']; + } } - // Add more change types as needed @endphp - @foreach($changes as $change) - {{ $change['type'] }} - @endforeach + @if(count($changes) > 0) + @foreach($changes as $change) + {{ $change['type'] }} + @endforeach + @else + Tidak ada perubahan + @endif @if(isset($report['security'])) -
Gerakan: {{ ucfirst($report['security']['motion'] ?? 'N/A') }}
-
Status: {{ ucfirst($report['security']['status'] ?? 'N/A') }}
-
Fan: {{ $report['security']['fan'] ?? 'N/A' }}
+
+ Gerakan: + @if(isset($report['security']['motion'])) + + {{ ucfirst($report['security']['motion'] ?? 'Tidak ada') }} + + @else + Tidak ada data + @endif +
+
+ Status: + @if(isset($report['security']['status'])) + + {{ ucfirst($report['security']['status'] ?? 'Normal') }} + + @else + Normal + @endif +
+
+ Fan: + + {{ ucfirst($report['security']['fan'] ?? 'Off') }} + +
@else - N/A +
Tidak ada data keamanan
@endif @if(isset($report['smartcab'])) -
Servo: {{ $report['smartcab']['servo_status'] ?? 'N/A' }}
-
Last Access: {{ $report['smartcab']['last_access'] ?? 'N/A' }}
+
+ Servo: + + {{ $report['smartcab']['servo_status'] ?? 'N/A' }} + +
+ @if(isset($report['smartcab']['last_access']) && !empty($report['smartcab']['last_access'])) +
Akses Terakhir: {{ $report['smartcab']['last_access'] }}
+ @endif @endif + @if(isset($report['dht11'])) -
Suhu: {{ $report['dht11']['temperature'] ?? 'N/A' }}°C
-
Kelembaban: {{ $report['dht11']['humidity'] ?? 'N/A' }}%
+
+ Sensor DHT11: +
+
+ Suhu: + + {{ $report['dht11']['temperature'] ?? 'N/A' }}°C + +
+
+ Kelembaban: {{ $report['dht11']['humidity'] ?? 'N/A' }}% +
+ @endif + + @if(isset($report['control']) && ($report['control']['restartESP'] || $report['control']['restartWemos'])) +
+ Restart Status: + @if($report['control']['restartESP']) + ESP restarted + @endif + @if($report['control']['restartWemos']) + Wemos restarted + @endif +
@endif