@extends('layouts.app')
@section('title','Current Stock')
@section('content')
<div class="page-head"><div><h1>Current stock</h1><p>Calculated from immutable stock movements; never edited directly.</p></div><div class="text-end"><small class="text-muted d-block">Total inventory value</small><strong class="fs-4 text-accent">SAR {{ number_format((float)$totalValue,2) }}</strong></div></div><div class="card-erp"><div class="card-erp-body"><form class="row g-2 align-items-end"><div class="col-md-4"><label class="form-label">Warehouse</label><select name="warehouse_id" class="form-select"><option value="">All warehouses</option>@foreach($warehouses as $w)<option value="{{ $w->id }}" @selected(request('warehouse_id')==$w->id)>{{ $w->code }} · {{ $w->name_en }}</option>@endforeach</select></div><div class="col-md-3"><label class="form-label">Category</label><select name="category_id" class="form-select"><option value="">All categories</option>@foreach($categories as $c)<option value="{{ $c->id }}" @selected(request('category_id')==$c->id)>{{ $c->name_en }}</option>@endforeach</select></div><div class="col-md-3"><label class="form-label">Stock status</label><select name="stock_status" class="form-select"><option value="">All stock</option><option value="low" @selected(request('stock_status')==='low')>Low stock</option><option value="negative" @selected(request('stock_status')==='negative')>Negative</option></select></div><div class="col-md-2"><button class="btn btn-dark w-100">Filter</button></div></form></div><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Code</th><th>Product</th><th>Arabic</th><th>Warehouse</th><th>Base unit</th><th class="text-end">Quantity</th><th class="text-end">Average cost</th><th class="text-end">Stock value</th><th></th></tr></thead><tbody>@forelse($stocks as $s)<tr><td>{{ $s->product?->product_code }}</td><td><b>{{ $s->product?->name_en }}</b></td><td dir="rtl">{{ $s->product?->name_ar }}</td><td>{{ $s->warehouse?->code }}</td><td>{{ $s->product?->baseUnit?->code }}</td><td class="text-end fw-bold {{ $s->qty<0?'text-danger':'' }}">{{ number_format((float)$s->qty,4) }}</td><td class="text-end">{{ number_format((float)$s->avg_cost,4) }}</td><td class="text-end">{{ number_format((float)$s->qty*(float)$s->avg_cost,2) }}</td><td><a class="btn btn-light border btn-dense" href="{{ route('stock-ledger.by-warehouse',$s->product_id) }}">Detail</a></td></tr>@empty<tr><td colspan="9" class="text-center text-muted py-5">No stock records.</td></tr>@endforelse</tbody></table></div>@if($stocks->hasPages())<div class="card-erp-body border-top">{{ $stocks->links() }}</div>@endif</div>
@endsection
