@php $bulanId = ['','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember']; $fmtTgl = fn($d) => $d ? $d->format('d') . ' ' . $bulanId[(int)$d->format('n')] . ' ' . $d->format('Y') : '—'; $fmtTglJam = fn($d) => $d ? $d->format('d') . ' ' . $bulanId[(int)$d->format('n')] . ' ' . $d->format('Y, H:i') : '—'; $fmtEd = fn($tgl) => $tgl ? $tgl->format('d-m-Y') : '—'; $nomor = $ppb->nomor; $tanggal = $fmtTgl($ppb->tanggal); $cetakPada = $fmtTglJam(now()); $colSpan = $tampilHarga ? 6 : 4; $logoUrl = $company->logoUrl('logo_desktop', 'build/assets/img/logo.png'); $telp = $company->no_telp_1 ? 'Telp: ' . $company->no_telp_1 . ($company->no_telp_2 ? ' / ' . $company->no_telp_2 : '') : null; // Bangun flat rows (item × lot) lalu chunk 13 per halaman $allRows = []; $grandTotal = 0; foreach ($ppb->items->filter(fn($i) => ($i->qty_dipenuhi ?? 0) > 0)->values() as $item) { foreach ($item->lots->filter(fn($l) => $l->qty > 0) as $lot) { $jenisNie = $item->barang?->jenis_nie ?? $item->barang?->merekBarang?->jenis_nie ?? null; $noNie = $item->barang?->no_nie ?? $item->barang?->merekBarang?->no_nie ?? null; $noLot = $lot->stok->no_lot ?? null; $noSerial = $lot->stok->no_serial ?? null; $subtotal = ($item->harga_jual ?? 0) * $lot->qty; $grandTotal += $subtotal; $allRows[] = compact('item','lot','jenisNie','noNie','noLot','noSerial','subtotal'); } } $pages = array_chunk($allRows, 13) ?: [[]]; $totalPages = count($pages); $rowStart = 1; @endphp
@foreach($pages as $pgIdx => $pageRows) @php $isLast = ($pgIdx === $totalPages - 1); @endphp
{{-- ══ HEADER ══════════════════════════════════════════ --}}
{{ $company->nama_perusahaan }}
{{ $company->alamat }} @if($telp)
{{ $telp }}@endif @if($company->email)  |  {{ $company->email }}@endif
Surat Jalan
No: {{ $nomor }}
Tgl: {{ $tanggal }}
{{-- ══ INFO PENERIMA ══════════════════════════════════════ --}}
Kepada Yth.
{{ $ppb->nama_faskes ?? '—' }}
@if($ppb->faskes?->alamat_pengiriman)
{{ $ppb->faskes->alamat_pengiriman }}
@elseif($ppb->faskes?->alamat)
{{ $ppb->faskes->alamat }}
@endif @if($ppb->faskes?->telp_pengiriman)
Telp: {{ $ppb->faskes->telp_pengiriman }}
@endif
{{-- ══ TABEL BARANG ══════════════════════════════════════ --}}
@if($tampilHarga) @endif @forelse($pageRows as $row) @php extract($row); $nieStr = ($jenisNie || $noNie) ? trim(($jenisNie ?? '') . ($jenisNie && $noNie ? ' — ' : '') . ($noNie ?? '')) : null; $lotSnParts = collect(); if ($noSerial) $lotSnParts->push('SN: ' . $noSerial); if ($noLot) $lotSnParts->push('LOT: ' . $noLot); @endphp @if($tampilHarga) @endif @empty @endforelse @if($isLast) @if($tampilHarga) @else @endif @endif
No Nama Barang Qty (pcs) Expired DateHarga Satuan Subtotal
{{ $rowStart++ }}
{{ $item->nama_barang }}
@if($lotSnParts->isNotEmpty())
{{ $lotSnParts->implode(' | ') }}@if($nieStr) ({{ $nieStr }})@endif
@elseif($nieStr)
{{ $nieStr }}
@endif
{{ number_format($lot->qty) }} {{ $fmtEd($lot->stok->tanggal_kedaluwarsa) }}{{ number_format($item->harga_jual ?? 0, 0, ',', '.') }} {{ number_format($subtotal, 0, ',', '.') }}
Tidak ada barang.
Total: {{ number_format($ppb->items->sum('qty_dipenuhi')) }} Rp {{ number_format($grandTotal, 0, ',', '.') }}
{{-- .page-body --}} {{-- TTD hanya di halaman terakhir, footer di semua halaman --}}
{{-- .page --}} @endforeach
{{-- #pages-wrapper --}}