@extends('dashboard.layouts.app') @section('content') @include('components.alert') @php $totals = $statement['totals']; $comparisonTotals = $comparisonStatement['totals'] ?? []; $comparisonEnabled = (bool) ($showComparison ?? false); $selectedCostCenter = $costCenters->firstWhere('id', (int) ($filters['cost_center_id'] ?? 0)); $formatAmount = function ($value, bool $dashZero = false) { $value = round((float) $value, 2); if (abs($value) < 0.00001) { return $dashZero ? '-' : '0.00'; } if ($value < 0) { return '(' . number_format(abs($value), 2) . ')'; } return number_format($value, 2); }; $amountClass = function ($value) { $value = round((float) $value, 2); if ($value < -0.00001) { return 'is-loss'; } if ($value > 0.00001) { return 'is-profit'; } return 'is-muted'; }; $comparisonValue = fn(string $key, int $sign = 1) => ($comparisonTotals[$key] ?? 0) * $sign; $comparisonRowsByCode = function (string $key) use ($comparisonStatement) { return collect($comparisonStatement[$key] ?? [])->keyBy('account_code'); }; @endphp
@if(!empty($filters['search'])) @endif
@if($comparisonEnabled) @endif @php $groups = [ [ 'title' => 'Revenue', 'rowsKey' => 'revenueRows', 'totalKey' => 'revenue', 'sign' => 1, 'empty' => 'No revenue accounts', ], [ 'title' => 'Cost of Revenue', 'rowsKey' => 'costOfRevenueRows', 'totalKey' => 'cost_of_revenue', 'sign' => -1, 'empty' => 'No cost of revenue accounts', ], [ 'title' => 'Selling and Distribution Expenses', 'rowsKey' => 'sellingRows', 'totalKey' => 'selling_expenses', 'sign' => -1, 'empty' => 'No selling expenses', ], [ 'title' => 'General and Administrative Expenses', 'rowsKey' => 'adminRows', 'totalKey' => 'admin_expenses', 'sign' => -1, 'empty' => 'No administrative expenses', ], [ 'title' => 'Finance Costs', 'rowsKey' => 'financeRows', 'totalKey' => 'finance_costs', 'sign' => -1, 'empty' => 'No finance costs', ], ]; @endphp @foreach($groups as $group) @php $groupAmount = $totals[$group['totalKey']] * $group['sign']; $groupComparison = $comparisonValue($group['totalKey'], $group['sign']); $rows = collect($statement[$group['rowsKey']] ?? []); $comparisonMap = $comparisonRowsByCode($group['rowsKey']); @endphp @if($comparisonEnabled) @endif @forelse($rows as $row) @php $rowKey = $group['rowsKey'] . '-' . $row['account_id']; $currentAmount = ((float) $row['amount']) * $group['sign']; $matchedComparison = $comparisonMap->get($row['account_code']); $rowComparison = ((float) ($matchedComparison['amount'] ?? 0)) * $group['sign']; @endphp @if($comparisonEnabled) @endif @empty @if($comparisonEnabled) @endif @endforelse @if($group['totalKey'] === 'cost_of_revenue') @if($comparisonEnabled) @endif @endif @if($group['totalKey'] === 'admin_expenses') @if($comparisonEnabled) @endif @endif @endforeach @if($comparisonEnabled) @endif @if($comparisonEnabled) @endif @if($comparisonEnabled) @endif @if($comparisonEnabled) @endif @if($comparisonEnabled) @endif
Statement Line Note Current Period {{ $filters['from_date'] }} - {{ $filters['to_date'] }} Comparison Period {{ $comparisonFilters['from_date'] ?? '-' }} - {{ $comparisonFilters['to_date'] ?? '-' }}
{{ $group['title'] }} {{ $formatAmount($groupAmount) }}{{ $formatAmount($groupComparison) }}
@forelse($row['movements'] as $movement) @php($movementAmount = ((float) $movement['amount']) * $group['sign']) @empty @endforelse
Date Entry Description Cost Center Amount
{{ optional($movement['date'])->format('Y-m-d') ?: '-' }} #{{ $movement['journal_entry_id'] }} {{ $movement['description'] }} {{ $movement['cost_center']?->title ?: '-' }} {{ $formatAmount($movementAmount) }}
No movements found.
Gross Profit {{ $formatAmount($totals['gross_profit']) }}{{ $formatAmount($comparisonTotals['gross_profit'] ?? 0) }}
Operating Profit (Loss) {{ $formatAmount($totals['operating_profit']) }}{{ $formatAmount($comparisonTotals['operating_profit'] ?? 0) }}
Profit (Loss) Before Tax {{ $formatAmount($totals['profit_before_tax']) }}{{ $formatAmount($comparisonTotals['profit_before_tax'] ?? 0) }}
Income Tax ({{ number_format($taxRate, 2) }}%) {{ $formatAmount(-$totals['income_tax']) }}{{ $formatAmount(-($comparisonTotals['income_tax'] ?? 0)) }}
{{ $totals['period_result'] >= 0 ? 'Profit for the Period' : 'Loss for the Period' }} {{ $formatAmount($totals['period_result']) }}{{ $formatAmount($comparisonTotals['period_result'] ?? 0) }}
Other Comprehensive Income --
Total Comprehensive Income for the Period {{ $formatAmount($totals['total_comprehensive_income']) }}{{ $formatAmount($comparisonTotals['total_comprehensive_income'] ?? 0) }}
@endsection @push('styles') @endpush @push('scripts') @endpush