update report pdf view a part of perubahan

This commit is contained in:
Vckynando12 2025-03-25 11:40:40 +07:00
parent bcfecf4b79
commit 837112d41e
1 changed files with 208 additions and 22 deletions

View File

@ -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; }
</style>
</head>
<body>
@ -94,44 +96,228 @@
<td>
@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)
<span class="badge {{ $change['badge'] }}">{{ $change['type'] }}</span>
@endforeach
@if(count($changes) > 0)
@foreach($changes as $change)
<span class="badge {{ $change['badge'] }}">{{ $change['type'] }}</span>
@endforeach
@else
<span class="text-gray-400">Tidak ada perubahan</span>
@endif
</td>
<td>
@if(isset($report['security']))
<div>Gerakan: {{ ucfirst($report['security']['motion'] ?? 'N/A') }}</div>
<div>Status: {{ ucfirst($report['security']['status'] ?? 'N/A') }}</div>
<div>Fan: {{ $report['security']['fan'] ?? 'N/A' }}</div>
<div>
<strong>Gerakan:</strong>
@if(isset($report['security']['motion']))
<span style="{{ $report['security']['motion'] == 'detected' ? 'color: #e11d48; font-weight: bold;' : 'color: #22c55e;' }}">
{{ ucfirst($report['security']['motion'] ?? 'Tidak ada') }}
</span>
@else
<span>Tidak ada data</span>
@endif
</div>
<div>
<strong>Status:</strong>
@if(isset($report['security']['status']))
<span style="{{ $report['security']['status'] == 'danger' ? 'color: #e11d48; font-weight: bold;' : 'color: #22c55e;' }}">
{{ ucfirst($report['security']['status'] ?? 'Normal') }}
</span>
@else
<span>Normal</span>
@endif
</div>
<div>
<strong>Fan:</strong>
<span style="{{ isset($report['security']['fan']) && $report['security']['fan'] == 'on' ? 'color: #22c55e;' : 'color: #6b7280;' }}">
{{ ucfirst($report['security']['fan'] ?? 'Off') }}
</span>
</div>
@else
N/A
<div class="text-center">Tidak ada data keamanan</div>
@endif
</td>
<td>
@if(isset($report['smartcab']))
<div>Servo: {{ $report['smartcab']['servo_status'] ?? 'N/A' }}</div>
<div>Last Access: {{ $report['smartcab']['last_access'] ?? 'N/A' }}</div>
<div>
<strong>Servo:</strong>
<span style="{{ isset($report['smartcab']['servo_status']) && $report['smartcab']['servo_status'] == 'Terbuka' ? 'color: #0ea5e9;' : 'color: #6b7280;' }}">
{{ $report['smartcab']['servo_status'] ?? 'N/A' }}
</span>
</div>
@if(isset($report['smartcab']['last_access']) && !empty($report['smartcab']['last_access']))
<div><strong>Akses Terakhir:</strong> {{ $report['smartcab']['last_access'] }}</div>
@endif
@endif
@if(isset($report['dht11']))
<div>Suhu: {{ $report['dht11']['temperature'] ?? 'N/A' }}°C</div>
<div>Kelembaban: {{ $report['dht11']['humidity'] ?? 'N/A' }}%</div>
<div style="margin-top: 4px; padding-top: 4px; border-top: 1px dotted #e5e7eb;">
<strong>Sensor DHT11:</strong>
</div>
<div>
<strong>Suhu:</strong>
<span style="{{ isset($report['dht11']['temperature']) && $report['dht11']['temperature'] > 30 ? 'color: #e11d48;' : 'color: #0ea5e9;' }}">
{{ $report['dht11']['temperature'] ?? 'N/A' }}°C
</span>
</div>
<div>
<strong>Kelembaban:</strong> {{ $report['dht11']['humidity'] ?? 'N/A' }}%
</div>
@endif
@if(isset($report['control']) && ($report['control']['restartESP'] || $report['control']['restartWemos']))
<div style="margin-top: 4px; padding-top: 4px; border-top: 1px dotted #e5e7eb;">
<strong>Restart Status:</strong>
@if($report['control']['restartESP'])
<span style="color: #f97316;">ESP restarted</span>
@endif
@if($report['control']['restartWemos'])
<span style="color: #f59e0b;">Wemos restarted</span>
@endif
</div>
@endif
</td>
</tr>