@extends('layouts.finance') @section('title', 'Revenue Detail') @section('subtitle', 'Paid Examism voucher order revenue for the current month') @section('content') @php $displayCurrency = 'PKR'; $fmt = fn($usd) => $metrics->moneyIn($usd, 'USD', $displayCurrency); $profitDetails = $profitDetails ?? ['summary' => [], 'products' => collect(), 'recent_orders' => collect()]; $profitSummary = $profitDetails['summary'] ?? []; $productRows = collect($profitDetails['products'] ?? []); $recentOrders = collect($profitDetails['recent_orders'] ?? []); $productOptions = collect($productOptions ?? $productRows); $pointCards = $pointCards ?? []; $filters = $filters ?? ['mode' => 'month', 'month' => now()->format('Y-m'), 'from' => now()->startOfMonth()->toDateString(), 'to' => now()->endOfMonth()->toDateString(), 'product_id' => null]; $dashboardRevenueUsd = (float) $kpis['revenue']; $sourceCurrency = $profitSummary['currency'] ?? 'PKR'; $summaryRevenueUsd = $metrics->usd((float) ($profitSummary['revenue'] ?? 0), $sourceCurrency); $revenueUsd = $summaryRevenueUsd; $detailRevenueUsd = $metrics->usd($productRows->sum('revenue'), $sourceCurrency); $recentRevenueUsd = $metrics->usd($recentOrders->sum('revenue'), $sourceCurrency); $isDashboardScope = $filters['mode'] === 'month' && $filters['month'] === now()->format('Y-m') && empty($filters['product_id']); $reconciliationDelta = $dashboardRevenueUsd - $summaryRevenueUsd; $isExact = $isDashboardScope && $reconciliationDelta == 0.0; @endphp
Back to Dashboard

Filters

{{ $filters['mode'] === 'date' ? 'Date wise' : 'Monthly' }}
Reset
Filtered Revenue
{{ $fmt($revenueUsd) }}
{{ \Illuminate\Support\Carbon::parse($filters['from'])->format('M d, Y') }} - {{ \Illuminate\Support\Carbon::parse($filters['to'])->format('M d, Y') }}
Products Sold
{{ number_format($productRows->sum('sold_qty')) }}
Voucher keys delivered
Paid Orders
{{ number_format($productRows->sum('orders_count')) }}
payment_status = paid
{{ $isDashboardScope ? 'Dashboard Check' : 'Dashboard (Mo.)' }}
{{ $isDashboardScope ? ($isExact ? 'Exact' : $metrics->money($reconciliationDelta)) : $fmt($dashboardRevenueUsd) }}
{{ $isDashboardScope ? 'No rounded tolerance used' : 'Current month total' }}
@foreach(['quarterly_awarded' => 'ico-bg-indigo', 'yearly_awarded' => 'ico-bg-purple', 'redeemed' => 'ico-bg-amber'] as $type => $iconClass) @php $card = $pointCards[$type] ?? null; @endphp
{{ $card['label'] ?? ucfirst(str_replace('_', ' ', $type)) }}
{{ number_format((float) ($card['value'] ?? 0), 2) }}
{{ $filters['from'] }} to {{ $filters['to'] }}
@endforeach

Revenue Source

{{ $profitSummary['source'] ?? 'examism_v3' }}
Paid order revenue{{ $fmt($summaryRevenueUsd) }}
Product detail total{{ $fmt($detailRevenueUsd) }}
Dashboard KPI total{{ $fmt($dashboardRevenueUsd) }}
Selected range{{ $filters['from'] }} to {{ $filters['to'] }}

Recent Orders

Latest rows shown{{ number_format($recentOrders->count()) }}
Latest 20 revenue{{ $fmt($recentRevenueUsd) }}
Revenue currency{{ $sourceCurrency }}
USD to PKR{{ number_format((float) $settings['usd_to_pkr'], 4) }}

Revenue by Product

Current month
{{-- No separate Revenue column: sale_price_per_voucher is revenue/qty, so a "sale amount" column and a "revenue" column are the same number. --}} @forelse($productRows as $row) @php $rowQty = (int) ($row['sold_qty'] ?? 0); $rowRevenueUsd = $metrics->usd($row['revenue'], 'PKR'); // Totals for the period, not unit prices: sale amount is the // period revenue, buying amount is the recorded cost of the // vouchers actually sold. Unit price shown beneath each. $rowSaleTotalUsd = $metrics->usd((float) ($row['revenue'] ?? 0), 'PKR'); $rowBuyingTotalUsd = $metrics->usd((float) ($row['cogs'] ?? 0), 'PKR'); $rowSaleUnitUsd = $metrics->usd((float) ($row['sale_price_per_voucher'] ?? 0), 'PKR'); $rowBuyingUnitUsd = $metrics->usd((float) ($row['buying_price_per_voucher'] ?? 0), 'PKR'); // The service's own definition: revenue - cogs - redeemed points. // Subtracting cost alone would overstate profit on orders that // were part-paid with points. $rowPointsUsd = $metrics->usd((float) ($row['points'] ?? 0), 'PKR'); $rowProfitUsd = $metrics->usd((float) ($row['profit'] ?? 0), 'PKR'); $rowMargin = (float) ($row['margin'] ?? 0); @endphp @empty @endforelse @if($productRows->sum('sold_qty') > 0) @php $totalSaleUsd = $metrics->usd((float) $productRows->sum('revenue'), 'PKR'); $totalBuyingUsd = $metrics->usd((float) $productRows->sum('cogs'), 'PKR'); $totalPointsUsd = $metrics->usd((float) $productRows->sum('points'), 'PKR'); $totalProfitUsd = $metrics->usd((float) $productRows->sum('profit'), 'PKR'); $totalMargin = $totalSaleUsd > 0 ? ($totalProfitUsd / $totalSaleUsd) * 100 : 0.0; @endphp @endif
ProductQtyOrdersSale AmountBuying AmountPoints UsedProfitShare
{{ $row['title'] }} {{ number_format($row['sold_qty']) }} {{ number_format($row['orders_count']) }} @if($rowQty > 0) {{ $fmt($rowSaleTotalUsd) }}
{{ $fmt($rowSaleUnitUsd) }} each
@else - @endif
@if($rowQty > 0) {{ $fmt($rowBuyingTotalUsd) }}
{{ $fmt($rowBuyingUnitUsd) }} each
@else - @endif
{{ $rowPointsUsd > 0 ? $fmt($rowPointsUsd) : '-' }} @if($rowQty > 0) {{ $fmt($rowProfitUsd) }}
{{ number_format($rowMargin, 2) }}% margin
@else - @endif
{{ $revenueUsd > 0 ? number_format(($rowRevenueUsd / $revenueUsd) * 100, 2) : '0.00' }}%
No paid voucher revenue found for this month.
Total {{ number_format($productRows->sum('sold_qty')) }} {{ number_format($productRows->sum('orders_count')) }} {{ $fmt($totalSaleUsd) }} {{ $fmt($totalBuyingUsd) }} {{ $totalPointsUsd > 0 ? $fmt($totalPointsUsd) : '-' }} {{ $fmt($totalProfitUsd) }}
{{ number_format($totalMargin, 2) }}% margin
100.00%

Recent Paid Orders

Latest 20
@forelse($recentOrders as $order) @empty @endforelse
OrderDateQtyRevenue
#{{ $order['id'] }} {{ $order['date'] ?: '-' }} {{ number_format($order['qty']) }} {{ $fmt($metrics->usd($order['revenue'], 'PKR')) }}
No recent paid orders found for this month.

Revenue Trend - 6 Months

USD
@push('scripts') @endpush @endsection