@extends('layouts.app') @section('title', 'Pharmacy | Inventory') @section('styles') @endsection @section('content') @php $authUser = Auth::user(); $isFullAccess = $authUser->hasAnyRole('Super Admin','Hospital Admin','Pharmacy User'); $canEditDrugs = $authUser->hasAnyRole('Super Admin','Hospital Admin'); @endphp {{-- Page header removed per UI cleanup; sidebar already names the page. --}}
@if($isFullAccess) Stock Take @endif
{{-- Drug Inventory (unified: drug list + stock levels + expiries, with hidden batch drill-down) --}}
@if(request('search'))Clear@endif
| Filter:
@if($isFullAccess) @endif @if($canEditDrugs) Bulk Edit @endif
@if($isFullAccess)@endif @forelse($drugs ?? [] as $d) @php // Active batches = not yet expired, still has quantity $activeBatches = $d->batches->where('expiry_date', '>', now())->where('quantity_remaining', '>', 0)->sortBy('expiry_date'); $allBatches = $d->batches->sortBy('expiry_date'); $totalStock = $activeBatches->sum('quantity_remaining'); $earliest = $activeBatches->first()?->expiry_date; // Status tier (worst-first): out > expired-only > expiring-30 > low > expiring-90 > ok $isOut = $totalStock <= 0; $isLow = !$isOut && $totalStock <= $d->reorder_level; $isExp30 = $earliest && $earliest->diffInDays(now(), false) >= 0 && $earliest->lte(now()->addDays(30)); $isExp90 = $earliest && !$isExp30 && $earliest->lte(now()->addDays(90)); $stockRowClass = $isOut ? 'out' : ($isLow ? 'low' : 'ok'); $expiryRowClass = ($isExp30 || $isExp90) ? 'yes' : 'no'; @endphp @if($isFullAccess) @endif @if($allBatches->count() > 0) {{-- Hidden batch drill-down row --}} @endif @empty @endforelse
Drug Name Generic Stock Reorder Earliest Expiry Price (KES) Status
@if($allBatches->count() > 0) @endif {{ $d->name }} {{ $d->generic_name }} {{ $totalStock }} {{ $d->reorder_level }} {{ $earliest?->format('d M Y') ?? '—' }} @if($isExp30) Near Expiry @elseif($isExp90) Near Expiry @endif {{ number_format($d->selling_price) }} @if($isOut)Out of Stock @elseif($isExp30)Expiring <30d @elseif($isLow)Low Stock @elseif($isExp90)Expiring @elseif(!$d->is_active)Inactive @elseOK@endif @if($canEditDrugs)
@csrf @method('DELETE')
@else @endif
No drugs in catalog.
@if(isset($drugs) && $drugs->hasPages())
{{ $drugs->links() }}
@endif
{{-- Suppliers Panel --}}

{{ ($suppliers ?? collect())->count() }} supplier(s) registered

@forelse($suppliers ?? [] as $sup) @empty @endforelse
Name Contact Person Phone Email Address Drugs Status
{{ $sup->name }} {{ $sup->contact_person ?? '-' }} {{ $sup->phone ?? '-' }} {{ $sup->email ?? '-' }} {{ $sup->address ?? '-' }} {{ $sup->drug_items_count }} @if($sup->is_active)Active@elseInactive@endif
No suppliers registered. Click "Add Supplier" to create one.
{{-- Procurement Requests Panel ───────────────────────────────────── Was a separate sidebar entry; now lives here next to the inventory it operates on. Scope: Admin sees all requests, Pharmacy User sees their own. --}}
{{-- New Request button: Admins + Pharmacy User. Admins have full rights — they can create on behalf, approve, edit items, and delete requests entirely. --}} {{-- Suggested reorder alert --}} @if(isset($procSuggested) && $procSuggested->count() > 0)

{{ $procSuggested->count() }} drug(s) at or below reorder level

@foreach($procSuggested->take(5) as $d) {{ $d->name }} ({{ $d->current_stock }} left) @endforeach @if($procSuggested->count() > 5)+{{ $procSuggested->count()-5 }} more@endif

Create Request
@endif
@forelse($procRequests ?? [] as $pr) @empty @endforelse
Request # Submitted By Date Priority Items Status Reviewed By
{{ $pr->request_number }} {{ $pr->requester?->name ?? '—' }} {{ $pr->created_at->format('d M Y, H:i') }} @if($pr->urgency === 'urgent') Urgent @else Normal @endif {{ $pr->activeItems->count() }} {{ $pr->status_label }} {{ $pr->reviewer?->name ?? '—' }} View →
No procurement requests yet. Create your first one →
@if(isset($procRequests) && $procRequests->hasPages())
{{ $procRequests->links() }}
@endif
{{-- Add Drug Modal --}} {{-- Edit Drug Modal --}} @endsection @section('scripts') @include('partials._tab-state-helper', ['defaultTab' => 'drugs']) @endsection