@extends('layouts.app') @section('title', 'Purchases Report') @section('content') @php $qty = fn ($value) => rtrim(rtrim(number_format((float) $value, 2), '0'), '.'); $periods = ['' => 'This month', 'today' => 'Today', 'yesterday' => 'Yesterday', 'this_week' => 'This week', 'last_month' => 'Last month', 'this_year' => 'This year', 'all' => 'All time']; $customDates = request()->hasAny(['from', 'to']) && !request()->filled('period'); $activePeriod = $customDates ? null : request('period', ''); $periodText = $activePeriod === 'all' ? 'all time' : ($from->isSameDay($to) ? 'on ' . $from->format('l, d M Y') : 'from ' . $from->format('d M Y') . ' to ' . $to->format('d M Y')); $filtered = request()->hasAny(['supplier_id', 'product', 'batch_no', 'reference', 'payment_status', 'source']) && collect(request()->only(['supplier_id', 'product', 'batch_no', 'reference', 'payment_status', 'source']))->filter()->isNotEmpty(); $sourceTone = ['purchase' => 'primary', 'opening_stock' => 'info', 'bulk_products' => 'info', 'stock_adjustment' => 'success', 'bulk_stock' => 'success']; @endphp

Purchases

All stock received {{ $periodText }}: purchases, opening stock of new products and stock adjustments.

@foreach($periods as $key => $label) {{ $label }} @endforeach
@foreach([ ['Money spent', formatCurrency($totals->cost), number_format($totals->purchases) . ' ' . ($totals->purchases == 1 ? 'entry' : 'entries'), 'bi-wallet2', 'danger'], ['Value at selling price', formatCurrency($totals->sales_value), 'if all of it is sold', 'bi-cash-coin', 'primary'], ['Expected profit', formatCurrency($totals->profit), $totals->margin !== null ? $totals->margin . '% of the selling value' : 'nothing received', 'bi-graph-up-arrow', $totals->profit >= 0 ? 'success' : 'danger'], ['Units received', $qty($totals->quantity), number_format($totals->products) . ' ' . ($totals->products == 1 ? 'product' : 'products'), 'bi-box-seam', 'secondary'], ] as [$label, $value, $hint, $icon, $tone])
{{ $label }}
{{ $value }}
{{ $hint }}
@endforeach
@if($bySource->count() > 1 || $bySupplier->count() > 1)
@if($bySource->count() > 1)
Where the stock came from
@foreach($bySource as $row) @php $share = $totals->cost > 0 ? $row->cost / $totals->cost * 100 : 0; @endphp
{{ $sources[$row->source] ?? 'Purchase' }} {{ formatCurrency($row->cost) }} · sells for {{ formatCurrency($row->sales_value) }}
@endforeach
@endif @if($bySupplier->count() > 1)
By supplier
@foreach($bySupplier as $row) @endforeach
{{ $row->supplier ?? 'No supplier' }} {{ $qty($row->quantity) }} units {{ formatCurrency($row->cost) }}
@endif
@endif
@if($items->isEmpty())
Nothing received {{ $periodText }}{{ $filtered ? ' matching the filters' : '' }}. @if($activePeriod !== 'all') @endif
@else
@foreach($items as $item) @php $expiry = $item->expiry_date ?? $item->exp_date; $source = $item->purchase?->source ?? 'purchase'; @endphp @endforeach
DateProductSourceBatch QtyUnit costCostSells forBy
{{ $item->purchase?->purchase_date?->format('d M Y') }} @if($item->product) {{ $item->product->name }} @else Deleted product @endif
{{ $item->purchase?->reference_no }}{{ $item->purchase?->supplier ? ' · ' . $item->purchase->supplier->name : '' }}
{{ $sources[$source] ?? 'Purchase' }} {{ $item->batch_no ?? '-' }}@if($expiry)
exp {{ \Carbon\Carbon::parse($expiry)->format('d M Y') }}
@endif
{{ $qty($item->quantity) }} {{ formatCurrency($item->unit_cost) }} {{ formatCurrency($item->line_total) }} {{ formatCurrency((float) $item->quantity * (float) $item->selling_price) }} {{ $item->purchase?->user?->name ?? '-' }}
Total {{ $items->total() > $items->count() ? '(all pages)' : '' }} {{ $qty($totals->quantity) }} {{ formatCurrency($totals->cost) }} {{ formatCurrency($totals->sales_value) }}
@if($items->hasPages())
{{ $items->links() }}
@endif @endif
@endsection