@extends('pdf.layout') @section('content') @php $today = \Carbon\Carbon::today(); $cost = fn ($b) => (float) ($b->unit_cost ?? $b->product?->purchase_price ?? 0); @endphp
Batches
{{ number_format($totals['batches']) }}
Units in stock
{{ number_format($totals['in_stock']) }}
Expiring in 30 days
{{ number_format($totals['expiring']) }}
Expired, still in stock
{{ number_format($totals['expired']) }}
@forelse($groups as $group) @php $items = $batches[$group->batch_no] ?? collect(); $units = $items->sum(fn ($b) => (float) $b->quantity_remaining); $value = $items->sum(fn ($b) => (float) $b->quantity_remaining * $cost($b)); @endphp

Batch {{ $group->batch_no }} - {{ $items->count() }} item(s), {{ number_format($units) }} in stock, MWK {{ number_format($value, 2) }}

@foreach($items as $b) @php $left = (float) $b->quantity_remaining; $days = $b->expiry_date ? (int) $today->diffInDays($b->expiry_date, false) : null; [$class, $text] = $left <= 0 ? ['badge-grey', 'Used up'] : ($days === null ? ['badge-grey', 'No expiry'] : ($days < 0 ? ['badge-red', 'Expired'] : ($days <= 30 ? ['badge-amber', 'Expiring'] : ['badge-green', 'Good']))); @endphp @endforeach
ProductExpiryReceivedReceived qtySoldIn stockValue (MWK)Status
{{ $b->product->name ?? 'Deleted product' }}
{{ $b->product->sku ?? '' }}
{{ $b->expiry_date?->format('d M Y') ?? '-' }}@if($days !== null && $left > 0)
{{ $days < 0 ? abs($days) . ' days ago' : ($days === 0 ? 'today' : 'in ' . $days . ' days') }}
@endif
{{ ($b->received_at ?? $b->created_at)->format('d M Y') }} {{ (float) $b->quantity_received }} {{ (float) ($sold[$b->id] ?? 0) }} {{ $left }} {{ number_format($left * $cost($b), 2) }} {{ $text }}
@empty
No batches match these filters.
@endforelse @endsection