@extends('layouts.app', ['class' => 'g-sidenav-show bg-gray-100'])
@push('styles')
@endpush
@section('content')
@include('layouts.navbars.auth.topnav', ['title' => 'Report Stok per Layout'])
@php
$rows = collect($table_result ?? []);
$totalTransactions = $rows->count();
$totalBags = $rows->sum(function ($row) {
$value = $row->{'TOTAL BAG'} ?? ($row->total_bag ?? ($row->total_bags ?? 0));
$numeric = preg_replace('/[^0-9.\-]/', '', (string) $value);
return (float) ($numeric !== '' ? $numeric : 0);
});
$totalWeight = $rows->sum(function ($row) {
$value = $row->{'TOTAL BERAT'} ?? ($row->total_berat ?? 0);
$numeric = preg_replace('/[^0-9.\-]/', '', (string) $value);
return (float) ($numeric !== '' ? $numeric : 0);
});
$headers = $rows->isNotEmpty() ? array_keys((array) $rows->first()) : [];
$bagKey = in_array('BAG ID', $headers, true)
? 'BAG ID'
: (in_array('LAYOUT ID', $headers, true)
? 'LAYOUT ID'
: $headers[0] ?? null);
$dynamicHeaders = array_values(array_filter($headers, fn($h) => $bagKey === null ? true : $h !== $bagKey));
@endphp
| NO |
BAG ID |
@foreach ($dynamicHeaders as $header)
{{ $header }} |
@endforeach
@foreach ($rows as $index => $item)
| {{ $index + 1 }} |
{{ $bagKey !== null ? $item->{$bagKey} ?? '-' : '-' }} |
@foreach ($dynamicHeaders as $header)
@php
$cellValue = $item->{$header} ?? '';
$alignClass = '';
if (
stripos((string) $header, 'TOTAL') !== false ||
stripos((string) $header, 'BERAT') !== false ||
stripos((string) $header, 'QTY') !== false
) {
$alignClass = 'text-end';
}
@endphp
{{ $cellValue }} |
@endforeach
@endforeach
@if ($rows->isEmpty())
Tidak ada data
@endif
@if ($rows->isNotEmpty())
Total Transaksi
{{ number_format($totalTransactions) }}
Total Bag Unik
{{ number_format($totalBags) }}
Total Berat (Per Bag ID)
{{ number_format((float) $totalWeight, 2) }} kg
@endif
@endsection
@push('js')
@endpush