@extends('layouts.app') @section('title', 'Sales by Product') @include('inventory.accounting.partials.styles') @section('content')

Sales by Product

{{ \Carbon\Carbon::parse($from)->format('M j') }} – {{ \Carbon\Carbon::parse($to)->format('M j, Y') }}

@include('inventory.accounting.partials.sub-nav') @php $totalRev = array_sum(array_column($sales, 'revenue')); $totalCogs = array_sum(array_column($sales, 'cogs')); $totalProfit = $totalRev - $totalCogs; $totalMargin = $totalRev > 0 ? round(($totalProfit / $totalRev) * 100, 2) : 0; @endphp {{-- Top-of-page KPI strip so the merchant sees the bottom line first --}}
Revenue
₦{{ number_format($totalRev, 2) }}
COGS
₦{{ number_format($totalCogs, 2) }}
Gross Profit
₦{{ number_format($totalProfit, 2) }}
Margin
{{ $totalMargin }}%
@forelse($sales as $i => $row) @empty @endforelse @if(! empty($sales)) @endif
# Product Qty Sold Revenue COGS Profit Margin Share
{{ $i + 1 }} {{ $row['product_name'] }} {{ number_format($row['qty']) }} {{ number_format($row['revenue'], 2) }} {{ number_format($row['cogs'], 2) }} {{ number_format($row['profit'], 2) }} {{ $row['margin_pct'] }}% {{ $totalRev > 0 ? round(($row['revenue'] / $totalRev) * 100, 1) : 0 }}%
No sales in this period.
Total {{ number_format($totalRev, 2) }} {{ number_format($totalCogs, 2) }} {{ number_format($totalProfit, 2) }} {{ $totalMargin }}%
@if(empty($sales) || array_sum(array_column($sales, 'cogs')) === 0)

Profit columns only populate for products that have a Cost Price set. Add cost prices on your products to unlock per-product profitability tracking.

@endif
@endsection