@extends('layouts.app') @section('content')
{{-- ╔════════════ HEADER ════════════╗ --}}
← Back to matrix

{{ trim($drug->name . ' ' . ($drug->strength ?? '') . ' ' . ($drug->form ?? '')) }}

{{ $drug->code }} · Category: {{ $drug->category }} · Reorder level: {{ number_format($drug->reorder_level) }}
Opening
{{ number_format($opening) }}
Closing
{{ number_format($closing) }}
Net
{{ ($closing - $opening) > 0 ? '+' : '' }}{{ number_format($closing - $opening) }}
{{-- Window picker --}}
{{ $timeline->count() }} movement{{ $timeline->count() === 1 ? '' : 's' }} in window
{{-- ╔════════════ TIMELINE TABLE ════════════╗ --}}
@if($timeline->isEmpty())
No movement in this window.
@else
{{-- Opening balance row --}} @foreach($timeline as $m) @endforeach {{-- Closing balance row --}}
Date Type Reference / Notes Batch By In Out Running
Opening balance ({{ $start->format('d M Y') }}) {{ number_format($opening) }}
{{ $m['created_at']->format('d M Y') }}
{{ $m['created_at']->format('H:i') }}
{{ ucfirst($m['type']) }}{{ $m['is_adjustment'] ? ' ⚠' : '' }} @if($m['department'])
{{ $m['department'] }}
@endif
{{ $m['reference'] ?? '—' }} @if($m['notes'])
{{ $m['notes'] }}
@endif
{{ $m['batch'] ?? '—' }} {{ $m['by'] }} {{ $m['quantity'] > 0 ? '+' . number_format($m['quantity']) : '·' }} {{ $m['quantity'] < 0 ? number_format($m['quantity']) : '·' }} {{ number_format($m['running']) }}
Closing balance ({{ $end->format('d M Y') }}) {{ number_format($closing) }}
@endif
{{-- ─── Quick stats footer ─── --}} @if($timeline->isNotEmpty()) @php $totalIn = $timeline->where('quantity', '>', 0)->sum('quantity'); $totalOut = abs($timeline->where('quantity', '<', 0)->where('is_adjustment', false)->sum('quantity')); $totalAdj = abs($timeline->where('is_adjustment', true)->sum('quantity')); $adjCount = $timeline->where('is_adjustment', true)->count(); @endphp
Total received
+{{ number_format($totalIn) }}
Total dispensed
-{{ number_format($totalOut) }}
Adjustments (loss)
{{ $totalAdj > 0 ? '-' . number_format($totalAdj) : '0' }}
{{ $adjCount }} event{{ $adjCount === 1 ? '' : 's' }}
Loss rate
@if($totalIn > 0) {{ number_format(($totalAdj / $totalIn) * 100, 1) }}% @else — @endif
of received
@endif
@endsection