@php $tonePill = [ 'up' => 'bg-emerald-50 text-emerald-700', 'down' => 'bg-rose-50 text-rose-700', 'muted' => 'bg-slate-100 text-slate-500', ]; // Movement-type presentation (badge colour + label). $typeMeta = [ 'opening' => ['label' => __('Opening'), 'color' => 'slate'], 'receipt' => ['label' => __('Receipt'), 'color' => 'emerald'], 'consumption' => ['label' => __('Consumption'), 'color' => 'indigo'], // Not a type of its own: a consumption whose reason is the shop's own // use (a customer's invoice printed at the counter). Shown and filtered // apart so it is never read as a sale or as spoilage. 'internal_use' => ['label' => __('Internal use'), 'color' => 'amber'], 'wastage' => ['label' => __('Wastage'), 'color' => 'rose'], 'adjustment' => ['label' => __('Adjustment'), 'color' => 'amber'], 'stocktake' => ['label' => __('Stocktake'), 'color' => 'sky'], 'return' => ['label' => __('Return'), 'color' => 'violet'], ]; $stockActionMeta = [ 'receive' => ['title' => __('Receive Stock'), 'verb' => __('Receive')], 'adjust' => ['title' => __('Adjust Stock'), 'verb' => __('Adjust')], 'writeoff' => ['title' => __('Write Off Stock'), 'verb' => __('Write off')], 'stocktake' => ['title' => __('Stocktake'), 'verb' => __('Stocktake')], ]; // Status badge for a material/variant given its on-hand vs reorder level. $statusFor = function (float $onHand, $level) { if ($onHand <= 0) { return ['label' => __('Out'), 'color' => 'rose']; } if ($level !== null && $onHand <= (float) $level) { return ['label' => __('Low'), 'color' => 'amber']; } return ['label' => __('In Stock'), 'color' => 'emerald']; }; @endphp
{{-- Header --}} @if ($canManage) {{ __('New Material') }} @endif {{-- KPI cards: compact so all five stay on a single row on desktop. --}}
@foreach ($kpis as $kpi)

{{ $kpi['label'] }}

{{ $kpi['value'] }}

{{ $kpi['sub']['text'] }}
@endforeach
{{-- Main panel --}} {{-- Toolbar --}}
@if ($tab === 'movements') @elseif ($tab !== 'suppliers') @endif
{{-- ============================== MATERIALS ============================== --}} @if ($tab === 'materials') @if (! $committedAvailable)
{{ __('No active-job demand to commit, Available equals On Hand.') }}
@endif
@forelse ($materials as $material) @php $isOpen = $expandedMaterial === $material->id; $onHand = (float) $material->variants->sum(fn ($v) => (float) $v->on_hand); $stockValue = (float) $material->variants->sum(fn ($v) => (float) $v->on_hand * (float) $v->avg_cost); $committedQty = (float) $material->variants->sum(fn ($v) => (float) ($committed[$v->id] ?? 0)); $available = $onHand - $committedQty; $avgCost = $onHand > 0 ? $stockValue / $onHand : (float) ($material->default_cost ?? 0); $status = $statusFor($onHand, $material->reorder_level); @endphp $drawerMaterialId === $material->id, ])> {{-- Variants: revealed only when the material row is expanded --}} @if ($isOpen) @endif @empty @endforelse
{{ __('Material') }} {{ __('Category') }} {{ __('On Hand') }} {{ __('Available') }} {{ __('Unit Cost') }} {{ __('Value') }} {{ __('Status') }} {{ __('Actions') }}
@if ($material->category) {{ $material->category->name }} @else — @endif @qty($onHand) @qty($available) {{ $baseCode }} {{ number_format($avgCost, 2) }} {{ $baseCode }} {{ number_format($stockValue, 2) }} {{ $status['label'] }}
@if ($canManage) @endif
@if ($canManage) @endif @foreach ($material->variants as $variant) @php $vCommitted = (float) ($committed[$variant->id] ?? 0); $vAvailable = (float) $variant->on_hand - $vCommitted; $vLevel = $variant->reorder_level ?? $material->reorder_level; $vStatus = $statusFor((float) $variant->on_hand, $vLevel); @endphp @if ($canManage) @endif @endforeach
{{ __('Variant') }} {{ __('On Hand') }} {{ __('Available') }} {{ __('Avg Cost') }} {{ __('Value') }} {{ __('Status') }}{{ __('Stock Actions') }}

{{ $variant->label }}

@if ($variant->size || $variant->color)

{{ collect([$variant->size, $variant->color])->filter()->implode(' · ') }}

@endif
@qty($variant->on_hand) {{ $material->base_unit }} @qty($vAvailable) {{ $baseCode }} {{ number_format((float) $variant->avg_cost, 2) }} {{ $baseCode }} {{ number_format((float) $variant->on_hand * (float) $variant->avg_cost, 2) }} @if (! $variant->is_active) {{ __('Inactive') }} @else {{ $vStatus['label'] }} @endif
@if ($canManage && $search === '' && $categoryFilter === '') {{ __('New Material') }} @endif
{{ $materials->links() }}
{{-- ============================== MOVEMENTS ============================== --}} @elseif ($tab === 'movements')
@forelse ($movements as $mv) @php $meta = $mv->reason === \App\Models\StockMovement::REASON_INTERNAL_USE ? $typeMeta['internal_use'] : ($typeMeta[$mv->type] ?? ['label' => ucfirst($mv->type), 'color' => 'slate']); @endphp @empty @endforelse
{{ __('Date') }} {{ __('Material / Variant') }} {{ __('Location') }} {{ __('Type') }} {{ __('Quantity') }} {{ __('Unit Cost') }} {{ __('Value') }} {{ __('By') }} {{ __('Notes') }}
{{ optional($mv->moved_on)->format('d M Y') }}

{{ $mv->variant?->material?->name ?? '—' }}

{{ $mv->variant?->label }} @if ($mv->supplier) · {{ $mv->supplier->name }} @endif

{{ $mv->location?->name ?? '—' }} {{ $meta['label'] }} {{ (float) $mv->quantity > 0 ? '+' : '' }}@qty((float) $mv->quantity) {{ $baseCode }} {{ number_format((float) $mv->unit_cost, 2) }} {{ $baseCode }} {{ number_format((float) $mv->value, 2) }} {{ $mv->recorder?->name ?? __('System') }} {{ $mv->notes ?: '—' }}
{{ $movements->links() }}
{{-- ============================== LOW STOCK ============================== --}} @elseif ($tab === 'low_stock')
@if ($canManage) @endif @forelse ($lowStock as $variant) @php $level = $variant->reorder_level ?? $variant->material?->reorder_level; $reorderQty = $variant->material?->reorder_qty; @endphp @if ($canManage) @endif @empty @endforelse
{{ __('Material / Variant') }} {{ __('Category') }} {{ __('On Hand') }} {{ __('Reorder Level') }} {{ __('Reorder Qty') }}{{ __('Actions') }}

{{ $variant->material?->name ?? '—' }}

{{ $variant->label }}

@if ($variant->material?->category) {{ $variant->material->category->name }} @else — @endif @qty($variant->on_hand) {{ $variant->material?->base_unit }} {{ $level !== null ? \App\Support\Number::qty($level) : '—' }} {{ $reorderQty !== null ? \App\Support\Number::qty($reorderQty) : '—' }}
{{ $lowStock->links() }}
{{-- ========================= REORDER SUGGESTIONS ========================= --}} @elseif ($tab === 'reorder')
@if ($canManage) @endif @forelse ($reorder as $variant) @php $level = $variant->reorder_level ?? $variant->material?->reorder_level; @endphp @if ($canManage) @endif @empty @endforelse
{{ __('Material / Variant') }} {{ __('On Hand') }} {{ __('Reorder Level') }} {{ __('Suggested Qty') }} {{ __('Preferred Supplier') }}{{ __('Action') }}

{{ $variant->material?->name ?? '—' }}

{{ $variant->label }}

@qty($variant->on_hand) {{ $variant->material?->base_unit }} {{ $level !== null ? \App\Support\Number::qty($level) : '—' }} @qty($variant->suggested_qty) {{ $variant->material?->base_unit }} @if ($variant->suggested_supplier_name)

{{ $variant->suggested_supplier_name }}

@if ($variant->suggested_lead_time !== null)

{{ trans_choice('{1} :count day lead|[2,*] :count days lead', (int) $variant->suggested_lead_time, ['count' => (int) $variant->suggested_lead_time]) }}

@endif @else {{ __('No supplier set') }} @endif
{{ $reorder->links() }}
{{-- ============================== SUPPLIERS ============================== --}} @else
@forelse ($suppliers as $supplier) @empty @endforelse
{{ __('Supplier') }} {{ __('Category') }} {{ __('Materials') }} {{ __('Lead Time') }} {{ __('Payable Balance') }} {{ __('Last Purchase') }}

{{ $supplier->name }}

@if ($supplier->is_preferred) {{ __('Preferred') }} @endif @unless ($supplier->is_active) {{ __('Inactive') }} @endunless
@if ($supplier->contact_person)

{{ $supplier->contact_person }}

@endif
{{ $supplier->category ?: '—' }} @php $supplies = (int) ($supplyCounts[$supplier->id] ?? 0); @endphp {{ $supplies > 0 ? number_format($supplies) : __('none') }} {{ $supplier->lead_time_days !== null ? trans_choice('{1} :count day|[2,*] :count days', (int) $supplier->lead_time_days, ['count' => (int) $supplier->lead_time_days]) : '—' }} {{ $baseCode }} {{ number_format($supplier->payable_balance, 2) }} {{ $supplier->last_purchase_at ? \Illuminate\Support\Carbon::parse($supplier->last_purchase_at)->format('d M Y') : '—' }}
{{ $suppliers->links() }}
@endif
{{-- ============================ DETAIL DRAWER ============================ --}} @if ($drawer) @endif {{-- ============================ STOCK ACTION MODAL ============================ --}} {{ $stockActionMeta[$stockAction]['title'] ?? __('Stock') }}

{{ $stockVariantLabel }}

@if ($stockAction === 'writeoff')

{{ __('Quantity to remove. Valued at the running weighted-average cost.') }}

@elseif ($stockAction === 'stocktake')

{{ __('The physical count. The difference vs on-hand is posted as a stocktake movement.') }}

@endif
@if (in_array($stockAction, ['receive', 'adjust'], true))
@if ($stockAction === 'receive')

{{ __('Cost per base unit. Blends into the weighted-average cost.') }}

@endif
@endif @if ($stockAction === 'receive')

{{ __('Links this supplier to the material and remembers what they charged.') }}

@endif
{{ __('Cancel') }} {{ $stockActionMeta[$stockAction]['verb'] ?? __('Save') }}