@php $selectedKeys = array_filter(explode(',', request()->input('columns', ''))); $allColKeys = ['item_name','category_name','total_qty','unit_cost','unit_sell', 'total_cost_value','total_sell_value','profit','batch_count','earliest_expiry','status']; $cols = empty($selectedKeys) ? $allColKeys : array_values(array_intersect($allColKeys, $selectedKeys)); $showHeader = request()->boolean('show_header'); $showSummary = request()->boolean('show_summary'); $colDef = [ 'item_name' => ['label' => 'Item', 'align' => 'left' ], 'category_name' => ['label' => 'Category', 'align' => 'left' ], 'total_qty' => ['label' => 'Qty', 'align' => 'right' ], 'unit_cost' => ['label' => 'Unit Cost', 'align' => 'right' ], 'unit_sell' => ['label' => 'Unit Price', 'align' => 'right' ], 'total_cost_value' => ['label' => 'Cost Value', 'align' => 'right' ], 'total_sell_value' => ['label' => 'Sell Value', 'align' => 'right' ], 'profit' => ['label' => 'Profit', 'align' => 'right' ], 'batch_count' => ['label' => 'Batches', 'align' => 'center'], 'earliest_expiry' => ['label' => 'Expiry', 'align' => 'center'], 'status' => ['label' => 'Status', 'align' => 'center'], ]; $colCount = count($cols) + 1; // +1 for the # column @endphp Inventory Stock Report

📊 Inventory Stock Report — Print Preview

@if($showHeader)

Inventory & Stock Valuation Report

Generated: {{ now()->format('d M Y, h:i A') }} Status: {{ ucfirst($f['status'] ?: 'All') }} Category: {{ $categoryLabel }} Location: {{ $locationLabel }} @if($f['search'])Search: "{{ $f['search'] }}"@endif Stock: {{ match($f['stockFilter']) { 'in'=>'In Stock','low'=>'Low Stock','out'=>'Out of Stock',default=>'All' } }} Items: {{ $summary['total_items'] }}
@endif @if($showSummary)
Total Items
{{ number_format($summary['total_items']) }}
Total Qty
{{ number_format($summary['total_qty'], 0) }}
Cost Value
{{ $currency }} {{ number_format($summary['total_cost_value'], 2) }}
Sell Value
{{ $currency }} {{ number_format($summary['total_sell_value'], 2) }}
Potential Profit
{{ $currency }} {{ number_format($summary['potential_profit'], 2) }}
Out of Stock
{{ $summary['out_of_stock'] }}
Low Stock
{{ $summary['low_stock'] }}
@endif @foreach($cols as $key) @endforeach @forelse($items as $i => $item) @php $qty = (float) $item->total_qty; $alert = (int) $item->alert_quantity; $profit = (float) $item->total_sell_value - (float) $item->total_cost_value; $ss = $qty <= 0 ? 'out' : ($alert > 0 && $qty <= $alert ? 'low' : 'ok'); $expiryClass = ''; if ($item->earliest_expiry) { $diff = now()->diffInDays($item->earliest_expiry, false); $expiryClass = $diff < 0 ? 'expiry-expired' : ($diff <= 30 ? 'expiry-soon' : ''); } $expiryLabel = $item->earliest_expiry ? \Carbon\Carbon::parse($item->earliest_expiry)->format('d M Y') : '—'; @endphp @foreach($cols as $key) @if($key === 'item_name') @elseif($key === 'category_name') @elseif($key === 'total_qty') @elseif($key === 'unit_cost') @elseif($key === 'unit_sell') @elseif($key === 'total_cost_value') @elseif($key === 'total_sell_value') @elseif($key === 'profit') @elseif($key === 'batch_count') @elseif($key === 'earliest_expiry') @elseif($key === 'status') @endif @endforeach @empty @endforelse @if($items->count() > 0) @php // Build footer cells matching the selected columns $footerSpanStart = 1; // for # col $colsSet = array_flip($cols); @endphp {{-- # --}} @foreach($cols as $key) @if($key === 'item_name') @elseif($key === 'total_qty') @elseif($key === 'total_cost_value') @elseif($key === 'total_sell_value') @elseif($key === 'profit') @else @endif @endforeach @endif
#{{ $colDef[$key]['label'] }}
{{ $i + 1 }}
{{ $item->item_name }}
@if($item->sku)
{{ $item->sku }}
@endif
{{ $item->category_name ?? '—' }}{{ number_format($qty, 0) }}{{ $currency }} {{ number_format($item->unit_cost, 2) }}{{ $currency }} {{ number_format($item->unit_sell, 2) }}{{ $currency }} {{ number_format($item->total_cost_value, 2) }}{{ $currency }} {{ number_format($item->total_sell_value, 2) }}{{ $currency }} {{ number_format($profit, 2) }}{{ $item->batch_count }}{{ $expiryLabel }}{{ $ss === 'out' ? 'Out of Stock' : ($ss === 'low' ? 'Low Stock' : 'In Stock') }}
No items match the selected filters.
Total — {{ number_format($summary['total_items']) }} items{{ number_format($summary['total_qty'], 0) }}{{ $currency }} {{ number_format($summary['total_cost_value'], 2) }}{{ $currency }} {{ number_format($summary['total_sell_value'], 2) }}{{ $currency }} {{ number_format($summary['potential_profit'], 2) }}