@extends('layouts.finance') @section('title', ($selectedProduct['title'] ?? 'Item').' Profit') @section('subtitle', 'Filtered sold voucher profit after redeemed quarterly and yearly points') @section('content') @php $displayCurrency = 'PKR'; $fmt = fn($usd) => $metrics->moneyIn($usd, 'USD', $displayCurrency); $profitDetails = $profitDetails ?? ['summary' => [], 'products' => collect(), 'recent_orders' => collect(), 'point_details' => []]; $summary = $profitDetails['summary'] ?? []; $productRows = collect($profitDetails['products'] ?? []); $row = $productRows->first() ?? [ 'item_id' => $selectedProduct['item_id'] ?? $filters['product_id'], 'title' => $selectedProduct['title'] ?? 'Item #'.$filters['product_id'], 'sold_qty' => 0, 'orders_count' => 0, 'revenue' => 0, 'cogs' => 0, 'issued_points' => 0, 'issued_points_breakdown' => ['quarterly' => 0, 'yearly' => 0], 'points' => 0, 'points_breakdown' => ['quarterly' => 0, 'yearly' => 0], 'profit' => 0, 'margin' => 0, ]; $recentOrders = collect($profitDetails['recent_orders'] ?? []); $pointDetails = $profitDetails['point_details'] ?? ['summary' => [], 'by_item_user' => collect(), 'recent' => collect(), 'source' => null]; $pointRows = collect($pointDetails['by_item_user'] ?? []); $sourceCurrency = $summary['currency'] ?? 'PKR'; $revenueUsd = $metrics->usd((float) ($row['revenue'] ?? 0), 'PKR'); $cogsUsd = $metrics->usd((float) ($row['cogs'] ?? 0), 'PKR'); $issuedUsd = $metrics->usd((float) ($row['issued_points'] ?? 0), 'PKR'); $usedUsd = $metrics->usd((float) ($row['points'] ?? 0), 'PKR'); $profitUsd = $metrics->usd((float) ($row['profit'] ?? 0), 'PKR'); $grossUsd = $revenueUsd - $cogsUsd; $soldQty = (float) ($row['sold_qty'] ?? 0); $avgBuying = (float) ($row['buying_price_per_voucher'] ?? ($soldQty > 0 ? ((float) ($row['cogs'] ?? 0) / $soldQty) : 0)); $saleAfterPoints = (float) ($row['sale_after_points_per_voucher'] ?? ($soldQty > 0 ? (((float) ($row['revenue'] ?? 0) - (float) ($row['points'] ?? 0)) / $soldQty) : 0)); $avgBuyingUsd = $metrics->usd($avgBuying, 'PKR'); $saleAfterPointsUsd = $metrics->usd($saleAfterPoints, 'PKR'); $issuedBreakdown = collect($row['issued_points_breakdown'] ?? []); $usedBreakdown = collect($row['points_breakdown'] ?? []); $isPositive = ((float) ($row['profit'] ?? 0)) >= 0; @endphp
Back to Profit Dashboard

Filters

{{ $filters['mode'] === 'date' ? 'Date wise' : 'Monthly' }}
Reset
Sold Voucher
{{ number_format((float) ($row['sold_qty'] ?? 0)) }}
{{ number_format((float) ($row['orders_count'] ?? 0)) }} paid orders
Sale Price
{{ $fmt($revenueUsd) }}
Filtered revenue
Buying Price
{{ $fmt($cogsUsd) }}
Sold voucher cost
Buying / Voucher
{{ $fmt($avgBuyingUsd) }}
Average cost
Sale After Points / Voucher
{{ $fmt($saleAfterPointsUsd) }}
After redeemed points
Redeemed Points
{{ $fmt($usedUsd) }}
Quarterly/yearly only
Profit
{{ $fmt($profitUsd) }}
After redeemed points

{{ $row['title'] ?? $selectedProduct['title'] }} Profit Detail

{{ $filters['from'] }} to {{ $filters['to'] }}
Item Sold Voucher Buying Price Sale Price Buying / Voucher Sale After Points / Voucher Q Issued Y Issued Issued Total Q Redeemed Y Redeemed Redeemed Total Profit
{{ $row['title'] ?? $selectedProduct['title'] }} {{ number_format((float) ($row['sold_qty'] ?? 0)) }} {{ $fmt($cogsUsd) }} {{ $fmt($revenueUsd) }} {{ $fmt($avgBuyingUsd) }} {{ $fmt($saleAfterPointsUsd) }} {{ $fmt($metrics->usd((float) ($issuedBreakdown['quarterly'] ?? 0), 'PKR')) }} {{ $fmt($metrics->usd((float) ($issuedBreakdown['yearly'] ?? 0), 'PKR')) }} {{ $fmt($issuedUsd) }} {{ $fmt($metrics->usd((float) ($usedBreakdown['quarterly'] ?? 0), 'PKR')) }} {{ $fmt($metrics->usd((float) ($usedBreakdown['yearly'] ?? 0), 'PKR')) }} {{ $fmt($usedUsd) }} {{ $fmt($profitUsd) }}

Formula

{{ $summary['source'] ?? 'examism_v3' }}
Sale price{{ $fmt($revenueUsd) }}
Buying price-{{ $fmt($cogsUsd) }}
Gross profit before points{{ $fmt($grossUsd) }}
Issued points shown only{{ $fmt($issuedUsd) }}
Redeemed points deducted-{{ $fmt($usedUsd) }}
Profit{{ $fmt($profitUsd) }}

Point Detail by User

{{ $pointDetails['source'] ?? 'No point ledger' }}
@forelse($pointRows as $pointRow) @php $points = $pointRow['points'] ?? []; $quarterly = $points['quarterly'] ?? []; $yearly = $points['yearly'] ?? []; $total = $points['total'] ?? []; @endphp @empty @endforelse
User Business Q Issued Q Redeemed Y Issued Y Redeemed Total Issued Total Used
{{ $pointRow['agent_name'] }}
{{ $pointRow['agent_email'] ?: 'No email' }}
{{ $pointRow['agent_business_name'] ?: '-' }} {{ number_format((float) ($quarterly['issued'] ?? 0), 2) }} {{ number_format((float) ($quarterly['used'] ?? 0), 2) }} {{ number_format((float) ($yearly['issued'] ?? 0), 2) }} {{ number_format((float) ($yearly['used'] ?? 0), 2) }} {{ number_format((float) ($total['issued'] ?? 0), 2) }} {{ number_format((float) ($total['used'] ?? 0), 2) }}
No quarterly or yearly redeemed point detail found for this item and date range.

Sold Voucher Orders

Latest {{ number_format($recentOrders->count()) }}
@forelse($recentOrders as $order) @php $orderProfit = $metrics->usd((float) ($order['profit'] ?? 0), 'PKR'); $orderQty = (float) ($order['qty'] ?? 0); $orderSaleAfterPoints = (float) ($order['sale_after_points_per_voucher'] ?? ($orderQty > 0 ? (((float) ($order['revenue'] ?? 0) - (float) ($order['points'] ?? 0)) / $orderQty) : 0)); $orderAvgBuying = (float) ($order['buying_price_per_voucher'] ?? ($orderQty > 0 ? ((float) ($order['cogs'] ?? 0) / $orderQty) : 0)); $orderPositive = ((float) ($order['profit'] ?? 0)) >= 0; @endphp @empty @endforelse
Order Date Sold Voucher Sale Price Buying Price Sale After Points / Voucher Buying / Voucher Redeemed Points Profit
#{{ $order['id'] }} {{ $order['date'] ?: '-' }} {{ number_format((float) ($order['qty'] ?? 0)) }} {{ $fmt($metrics->usd((float) ($order['revenue'] ?? 0), 'PKR')) }} {{ $fmt($metrics->usd((float) ($order['cogs'] ?? 0), 'PKR')) }} {{ $fmt($metrics->usd($orderSaleAfterPoints, 'PKR')) }} {{ $fmt($metrics->usd($orderAvgBuying, 'PKR')) }} {{ $fmt($metrics->usd((float) ($order['points'] ?? 0), 'PKR')) }} {{ $fmt($orderProfit) }}
No sold voucher orders found for this item and date range.
@endsection