@extends('layouts.app') @section('title', 'Batch Report') @section('content') @php $statusBadges = [ 'expired' => ['danger', 'Expired'], 'expiring' => ['warning', 'Expiring soon'], 'valid' => ['success', 'Good'], 'none' => ['secondary', 'No expiry'], ]; @endphp

Batch Report

Search a batch number to see every item received under it
@include('partials.pdf-button')
Batches
{{ number_format($totals['batches']) }}
Units in stock
{{ number_format($totals['in_stock']) }}
@if($search !== '' || $status !== 'all') Clear @endif
@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 * (float) ($b->unit_cost ?? $b->product?->purchase_price ?? 0)); @endphp
Batch {{ $group->batch_no }}
{{ $items->count() }} {{ Str::plural('item', $items->count()) }} · {{ number_format($units) }} in stock · {{ formatCurrency($value) }}
@foreach($items as $batch) @php $remaining = (float) $batch->quantity_remaining; [$badge, $label] = $remaining > 0 ? $statusBadges[$batch->expiryStatus()] : ['secondary', 'Used up']; $days = $batch->expiry_date ? (int) \Carbon\Carbon::today()->diffInDays($batch->expiry_date, false) : null; @endphp @endforeach
Product Expiry Received Received qty Sold In stock Value Status
@if($batch->product) {{ $batch->product->name }}
{{ $batch->product->sku }}
@else Deleted product @endif
{{ $batch->expiry_date ? $batch->expiry_date->format('d M Y') : '—' }} @if($days !== null && $remaining > 0)
{{ $days < 0 ? abs($days) . ' days ago' : ($days === 0 ? 'today' : 'in ' . $days . ' days') }}
@endif
{{ ($batch->received_at ?? $batch->created_at)->format('d M Y') }} {{ (float) $batch->quantity_received }} {{ (float) ($sold[$batch->id] ?? 0) }} {{ $remaining }} {{ formatCurrency($remaining * (float) ($batch->unit_cost ?? $batch->product?->purchase_price ?? 0)) }} {{ $label }}
@empty
{{ $search !== '' ? 'No batch matches "' . $search . '".' : 'No batches yet.' }}
@endforelse
{{ $groups->links() }}
@endsection