@php $org = auth()->user()->organization ?? \App\Models\System\Organization::find(auth()->user()->organization_id); $documentTitle = 'Stock Valuation Report'; @endphp @extends('documents.inventory._layout', [ 'documentTitle' => 'Stock Valuation Report', 'reference' => null, 'documentDate' => $reportDate, ]) @section('header-meta')
Currency: {{ $currency }}
Generated: {{ $reportDate }}
@endsection @section('content') @php $totalCost = $levels->sum(fn($l) => ($l->quantity_on_hand ?? 0) * (float)($l->lot?->landed_cost_per_unit ?? $l->average_cost ?? 0)); $totalSell = $levels->sum(fn($l) => ($l->quantity_on_hand ?? 0) * (float)($l->lot?->selling_price ?? 0)); $totalOutlet = $levels->sum(fn($l) => ($l->quantity_on_hand ?? 0) * (float)($l->lot?->outlet_price ?? 0)); $totalFloor = $levels->sum(fn($l) => ($l->quantity_on_hand ?? 0) * (float)($l->lot?->discount_cap ?? 0)); @endphp {{-- Summary cards --}}
Total at Cost
{{ $currency }} {{ number_format($totalCost, 0) }}
Total at Selling
{{ $currency }} {{ number_format($totalSell, 0) }}
Total at Outlet
{{ $currency }} {{ number_format($totalOutlet, 0) }}
Discount Floor
{{ $currency }} {{ number_format($totalFloor, 0) }}
{{-- Detail table grouped by location --}} @php $byLocation = $levels->groupBy(fn($l) => $l->location?->name ?? 'Unknown'); @endphp @foreach($byLocation as $locationName => $locationLevels)

{{ $locationName }}

@foreach($locationLevels as $i => $level) @php $qty = $level->quantity_on_hand ?? 0; $cost = (float)($level->lot?->landed_cost_per_unit ?? $level->average_cost ?? 0); $sell = (float)($level->lot?->selling_price ?? 0); $margin = $sell > 0 && $cost > 0 ? round((($sell - $cost) / $sell) * 100, 1) : null; $lowMargin = $margin !== null && $margin < 0; $highMargin = $margin !== null && $margin > 30; $rowClass = $lowMargin ? 'bg-red' : ($highMargin ? 'bg-green' : ''); @endphp @endforeach @php $locCost = $locationLevels->sum(fn($l) => ($l->quantity_on_hand ?? 0) * (float)($l->lot?->landed_cost_per_unit ?? $l->average_cost ?? 0)); $locSell = $locationLevels->sum(fn($l) => ($l->quantity_on_hand ?? 0) * (float)($l->lot?->selling_price ?? 0)); @endphp
# Product Lot Qty Cost/Unit Total at Cost Selling Price Total at Selling Margin %
{{ $i + 1 }} {{ $level->product?->name ?? '—' }} @if($level->product?->sku)
{{ $level->product->sku }}@endif
{{ $level->lot?->lot_number ?? '—' }} {{ number_format($qty) }} {{ $cost > 0 ? number_format($cost, 4) : '—' }} {{ number_format($qty * $cost, 0) }} {{ $sell > 0 ? number_format($sell, 2) : '—' }} {{ $sell > 0 ? number_format($qty * $sell, 0) : '—' }} {{ $margin !== null ? $margin.'%' : '—' }}
{{ $locationName }} Subtotal {{ number_format($locCost, 0) }} {{ $locSell > 0 ? number_format($locSell, 0) : '—' }}
@endforeach {{-- Grand totals --}}
Grand Total — At Cost {{ $currency }} {{ number_format($totalCost, 0) }}
Grand Total — At Selling {{ $currency }} {{ number_format($totalSell, 0) }}
{{-- Legend --}}
Legend: Red = Margin < 0% (selling below cost) Green = Margin > 30%
@endsection