@extends('layouts.app')
@section('center')
@if(empty($data))
Device not found.
@else
@php
$dailyNcValue = 0;
$monthlyNcValue = 0;
$dailyConsumptionValue = 0;
$monthlyConsumptionValue = 0;
if (!empty($daily_nc_loss) && count($daily_nc_loss) > 0) {
$lastDailyNc = collect($daily_nc_loss)->last();
$dailyNcValue = (float) (is_array($lastDailyNc) ? ($lastDailyNc['total'] ?? 0) : ($lastDailyNc->total ?? 0));
}
if (!empty($monthly_nc_loss) && count($monthly_nc_loss) > 0) {
$lastMonthlyNc = collect($monthly_nc_loss)->last();
$monthlyNcValue = (float) (is_array($lastMonthlyNc) ? ($lastMonthlyNc['total'] ?? 0) : ($lastMonthlyNc->total ?? 0));
}
if (!empty($daily_kwh) && count($daily_kwh) > 0) {
$lastDailyConsumption = collect($daily_kwh)->last();
$dailyConsumptionValue = (float) (is_array($lastDailyConsumption) ? ($lastDailyConsumption['total'] ?? 0) : ($lastDailyConsumption->total ?? 0));
}
if (!empty($monthly_kwh) && count($monthly_kwh) > 0) {
$lastMonthlyConsumption = collect($monthly_kwh)->last();
$monthlyConsumptionValue = (float) (is_array($lastMonthlyConsumption) ? ($lastMonthlyConsumption['total'] ?? 0) : ($lastMonthlyConsumption->total ?? 0));
}
$dailyRatio = $dailyConsumptionValue > 0 ? ($dailyNcValue / $dailyConsumptionValue) * 100 : 0;
$monthlyRatio = $monthlyConsumptionValue > 0 ? ($monthlyNcValue / $monthlyConsumptionValue) * 100 : 0;
$hasNoData =
$latest_graph_data->isEmpty() &&
$daily_kwh->isEmpty() &&
$monthly_kwh->isEmpty() &&
(empty($daily_nc_loss) || $daily_nc_loss->isEmpty()) &&
(empty($monthly_nc_loss) || $monthly_nc_loss->isEmpty());
@endphp
@if($hasNoData)
No recent data available for this device.
@else
{{ number_format($dailyNcValue, 4) }}
kWh
{{ number_format($monthlyNcValue, 4) }}
kWh
{{ number_format($dailyConsumptionValue, 2) }}
kWh
{{ number_format($monthlyConsumptionValue, 2) }}
kWh
{{ number_format($dailyRatio, 2) }}
%
{{ number_format($monthlyRatio, 2) }}
%
@endif
@endif
@push('scripts')
@endpush
@endsection