@extends('layouts.app') @section('content') @php // ─── window navigation helpers ───────────────────────────────────── $endStr = $window_end->toDateString(); $prevEnd = $window_end->copy()->subDays($window_days)->toDateString(); $nextEnd = $window_end->copy()->addDays($window_days); // Don't allow paging into the future if ($nextEnd->gt(now())) { $nextEnd = now(); } $nextEndStr = $nextEnd->toDateString(); $isFuture = $window_end->copy()->addDays($window_days)->gt(now()); // Build a route helper for the current view that lets us swap one query param $base = ['end' => $endStr, 'days' => $window_days, 'search' => $search, 'adjustments_only' => $adjustments_only ? 1 : 0]; @endphp
{{-- ╔════════════ TOP BAR ════════════╗ --}}

Pharmacy Stock Movement Log

Day-by-drug movement matrix · negative = stock out · red = adjustment

{{-- ─── Window navigation row ─── --}}
{{ $days[0]->format('d M') }} → {{ end($days)->format('d M Y') }} @if(! $isFuture) @else @endif Today
{{-- ─── Filters --- --}}
{{-- ╔════════════ MATRIX ════════════╗ --}}
@if(count($rows) === 0)
No stock movement in this window. @if($adjustments_only)
("Adjustments only" is on — try turning it off.)
@endif
@else
@foreach($days as $day) @php $isWeekend = $day->isWeekend(); $isToday = $day->isToday(); @endphp @endforeach @foreach($rows as $row) {{-- Drug name (sticky left, click to drill into timeline) --}} {{-- Cells: one per day --}} @foreach($days as $day) @php $key = $day->toDateString(); $cell = $row['cells'][$key] ?? null; @endphp @if($cell === null) @else @php $isAdj = $cell['kind'] === 'adjustment'; $isPositive = !$isAdj && $cell['net'] > 0; $cellBg = $isAdj ? 'bg-red-50' : ($isPositive ? 'bg-green-50' : ''); $textColor = $isAdj ? 'text-red-700 font-semibold' : ($cell['net'] > 0 ? 'text-green-700 font-semibold' : ($cell['net'] < 0 ? 'text-gray-800' : 'text-gray-400')); @endphp @endif @endforeach {{-- Balance --}} @endforeach {{-- Footer with column totals --}} @foreach($days as $day) @php $t = $totals[$day->toDateString()] ?? ['net'=>0,'in'=>0,'out'=>0]; @endphp @endforeach
Drug
{{ $day->format('D') }}
{{ $day->format('d M') }}
Balance today
{{ $row['drug_name'] }}
{{ $row['drug_code'] }}
· {{ $cell['net'] > 0 ? '+' : '' }}{{ number_format($cell['net']) }} @if($isAdj) @endif {{ number_format($row['balance_today']) }}
Daily net
{{ $t['net'] > 0 ? '+' : '' }}{{ number_format($t['net']) }}
@if($t['in'] > 0) +{{ number_format($t['in']) }} @endif @if($t['out'] < 0) {{ number_format($t['out']) }} @endif
@endif {{-- ─── Pagination ─── --}} @if($last_page > 1)
Showing {{ ($page - 1) * $per_page + 1 }}–{{ min($page * $per_page, $total_rows) }} of {{ number_format($total_rows) }} drugs
@if($page > 1) Previous @endif @if($page < $last_page) Next @endif
@endif
{{-- ─── Legend ─── --}}
= cell with adjustment (loss signal) = stock in (positive movement) +30 = stock in -5 = stock out (dispense) -20 ⚠ = adjustment · = no movement Click a drug name → full timeline Click a cell → day breakdown
{{-- ╔════════════ DAY DETAIL MODAL ════════════╗ --}} @endsection