@extends('layouts.admin') @section('title', 'Cost & Profit — ' . $sale->invoice_no) @section('content') @php $rows = $sale->items->map(function ($i) use ($alloc) { $parts = $alloc[$i->id] ?? collect(); $cost = $parts->isEmpty() ? round((float) $i->quantity * (float) $i->unit_cost, 2) : round($parts->sum(fn ($a) => (float) $a->quantity * (float) $a->unit_cost), 2); $rev = round((float) $i->line_total, 2); // before VAT return ['item' => $i, 'parts' => $parts, 'rev' => $rev, 'cost' => $cost, 'profit' => round($rev - $cost, 2)]; }); $totRev = $rows->sum('rev'); $totCost = $rows->sum('cost'); $totProfit = round($totRev - $totCost, 2); $margin = $totRev > 0 ? round($totProfit / $totRev * 100, 1) : 0; @endphp
| Taken from stock lot | Lot date | Supplier | Qty taken | Cost / unit | Cost |
|---|---|---|---|---|---|
| @if ($b) {{ $b->purchase?->reference ?? 'Opening stock' }} @else No lot (product cost used) @endif | {{ $b?->received_date?->format('d M Y') ?? '—' }} | {{ $b?->purchase?->supplier?->name ?? '—' }} | {{ (float) $a->quantity }} | {{ number_format($a->unit_cost, 2) }} | {{ number_format($a->quantity * $a->unit_cost, 2) }} |
| Sold before FIFO tracking — single cost recorded | {{ (float) $i->quantity }} | {{ number_format($i->unit_cost, 2) }} | {{ number_format($r['cost'], 2) }} | ||