@extends('layouts.finance')
@section('title', 'Inventory')
@section('subtitle', 'Voucher stock, costs and margins')
@section('content')
@php
$dateFilter = $dateFilter ?? ['active' => false, 'from' => null, 'to' => null, 'label' => null];
$activeTab = $activeTab ?? request('tab', 'available');
$rangeParams = ($dateFilter['active'] ?? false) ? ['from' => $dateFilter['from'], 'to' => $dateFilter['to']] : [];
$soldVouchers = $soldVouchers ?? collect();
$soldVoucherError = $soldVoucherError ?? null;
$soldVoucherRange = $soldVoucherRange ?? ['label' => now()->startOfMonth()->format('d M Y').' to '.now()->endOfMonth()->format('d M Y')];
$totalUnits = $products->sum(fn($p) => $p->stock);
$totalValuePkr = $products->sum(fn($p) => (float) ($p->total_cost ?? ($p->stock * (float) $p->cost_price)));
$soldQty = $soldVouchers->sum(fn($row) => (int) ($row['sold_qty'] ?? 0));
$soldRevenue = $soldVouchers->sum(fn($row) => (float) ($row['revenue'] ?? 0));
$soldProfit = $soldVouchers->sum(fn($row) => (float) ($row['profit'] ?? 0));
@endphp
@include('dashboard.cards._date-filter', [
'dateFilter' => $dateFilter,
'filterRoute' => 'finance.inventory',
'filterHidden' => ['tab' => $activeTab],
])
@if($activeTab === 'available')
@include('partials.kpi', ['label' => 'SKUs', 'value' => $products->count()])
@include('partials.kpi', ['label' => 'Total Units', 'value' => number_format($totalUnits)])
@include('partials.kpi', ['label' => 'Total Value', 'value' => 'PKR '.number_format($totalValuePkr, 2)])
Available Voucher Inventory
@if($inventoryError)
@endif
| SKU | Name | Source | Available Qty | Avg Cost | Total Cost | Sell | Cur. |
@forelse($products as $product)
| {{ $product->sku }} |
{{ $product->name }} |
{{ $product->category }} |
{{ number_format($product->stock) }} |
{{ $metrics->money($product->cost_price, $product->currency) }} |
{{ $metrics->money($product->total_cost ?? ($product->stock * (float) $product->cost_price), $product->currency) }} |
{{ $metrics->money($product->selling_price, $product->currency) }} |
{{ $product->currency }} |
@empty
| No available inventory found in examism_v3. |
@endforelse
@else
Sold Vouchers
Sale price and profit for {{ $soldVoucherRange['label'] }}
{{ number_format($soldQty) }} sold
@if($soldVoucherError)
@endif
@include('partials.kpi', ['label' => 'Sold Qty', 'value' => number_format($soldQty)])
@include('partials.kpi', ['label' => 'Sale Amount', 'value' => $metrics->money($soldRevenue, 'PKR'), 'color' => '#10b981'])
@include('partials.kpi', ['label' => 'Profit', 'value' => $metrics->money($soldProfit, 'PKR'), 'color' => $soldProfit >= 0 ? '#10b981' : '#ef4444'])
| Voucher |
Sold Qty |
Avg Sale Price |
Total Sale |
Avg Buying |
Total Cost |
Profit |
Margin |
@forelse($soldVouchers as $row)
| {{ $row['title'] ?? '-' }} |
{{ number_format((int) ($row['sold_qty'] ?? 0)) }} |
{{ $metrics->money((float) ($row['sale_price_per_voucher'] ?? 0), 'PKR') }} |
{{ $metrics->money((float) ($row['revenue'] ?? 0), 'PKR') }} |
{{ $metrics->money((float) ($row['buying_price_per_voucher'] ?? 0), 'PKR') }} |
{{ $metrics->money((float) ($row['cogs'] ?? 0), 'PKR') }} |
{{ $metrics->money((float) ($row['profit'] ?? 0), 'PKR') }}
|
{{ number_format((float) ($row['margin'] ?? 0), 1) }}% |
@empty
| No sold vouchers found for this date range. |
@endforelse
@endif
@endsection