@extends('layouts.app')
@section('title','Stock Ledger')
@section('content')
<div class="page-head"><div><h1>Stock ledger</h1><p>Immutable transaction trail for every inventory movement.</p></div><a class="btn btn-light border" href="{{ route('stock-ledger.export',request()->query()) }}">Export CSV</a></div><div class="card-erp"><div class="card-erp-body"><form class="row g-2 align-items-end"><div class="col-md-3"><label class="form-label">Warehouse</label><select name="warehouse_id" class="form-select"><option value="">All</option>@foreach($warehouses as $w)<option value="{{ $w->id }}" @selected(request('warehouse_id')==$w->id)>{{ $w->code }}</option>@endforeach</select></div><div class="col-md-3"><label class="form-label">Transaction type</label><select name="transaction_type" class="form-select"><option value="">All types</option>@foreach($txTypes as $t)<option @selected(request('transaction_type')===$t)>{{ $t }}</option>@endforeach</select></div><div class="col-md-2"><label class="form-label">From</label><input type="date" name="date_from" class="form-control" value="{{ request('date_from') }}"></div><div class="col-md-2"><label class="form-label">To</label><input type="date" name="date_to" class="form-control" value="{{ request('date_to') }}"></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>Date</th><th>Type</th><th>Reference</th><th>Product</th><th>Warehouse</th><th class="text-end">Qty in</th><th class="text-end">Qty out</th><th class="text-end">Base in</th><th class="text-end">Base out</th><th class="text-end">Cost</th><th class="text-end">Running</th></tr></thead><tbody>@forelse($ledgers as $l)<tr><td>{{ $l->transaction_date->format('d M Y') }}</td><td><span class="badge bg-light text-dark">{{ $l->transaction_type }}</span></td><td>{{ $l->reference_number }}</td><td><b>{{ $l->product?->product_code }}</b> · {{ $l->product?->name_en }}</td><td>{{ $l->warehouse?->code }}</td><td class="text-end text-success">{{ number_format((float)$l->qty_in,4) }}</td><td class="text-end text-danger">{{ number_format((float)$l->qty_out,4) }}</td><td class="text-end">{{ number_format((float)$l->base_qty_in,4) }}</td><td class="text-end">{{ number_format((float)$l->base_qty_out,4) }}</td><td class="text-end">{{ number_format((float)$l->unit_cost,4) }}</td><td class="text-end fw-bold">{{ number_format((float)$l->running_quantity,4) }}</td></tr>@empty<tr><td colspan="11" class="text-center text-muted py-5">No stock movements.</td></tr>@endforelse</tbody></table></div>@if($ledgers->hasPages())<div class="card-erp-body border-top">{{ $ledgers->links() }}</div>@endif</div>
@endsection
