{{-- The cash-up as recorded, shown when one already exists for the selected date. One block per account rather than a six-column table: a difference is two counts, each with its own expected figure, plus the split between them and the reason given. That does not fit a row, and squeezing it into one is what made the page read as scattered numbers instead of an answer. A director's decision lives here too, on the difference itself. It used to sit in a second panel further down that repeated the same figures under different headings, so the same money was on screen twice, described two ways. --}} @php // Accounts that need an answer first, balanced ones are a footnote. $flagged = $existing->lines->filter(fn ($l) => $l->reason_status !== null || abs((float) $l->variance) >= 0.01); $settled = $existing->lines->reject(fn ($l) => $flagged->contains('id', $l->id)); $pendingCount = $existing->lines->where('reason_status', 'pending')->count(); @endphp {{-- Header: whose count, when, and where it stands --}}

{{ __('Cash-up for') }} {{ $existing->business_date->format('D, d M Y') }}

{{ __('Counted by') }} {{ $existing->performer?->name ?? '—' }} @if ($existing->submitted_at) · {{ $existing->submitted_at->timezone(config('app.display_timezone'))->format('H:i') }} @endif

@if (! $existing->has_variance) {{ __('Everything balanced') }} @elseif (abs((float) $existing->total_variance_base) >= 0.01) {{ __('Out by') }} {{ $baseCode }} {{ number_format((float) $existing->total_variance_base, 2) }} @else {{-- Flagged with no money out of place: the accounts total correctly but the day's takings did not. --}} {{ __('The day did not balance') }} @endif
{{-- The differences, one block each --}}
@foreach ($flagged as $line) @php $cur = $line->currency_code; $variance = (float) $line->variance; $takingsVariance = $line->takings_variance; $carried = $line->brought_forward_variance; $status = $line->reason_status; $badge = match ($status) { 'approved' => ['emerald', __('Approved')], 'rejected' => ['rose', __('Rejected')], 'queried' => ['sky', __('Sent back for correction')], 'pending' => ['amber', __('Waiting on a director')], default => null, }; @endphp

{{ $line->account?->name ?? __('Account') }}

@if ($badge) {{ $badge[1] }} @endif
{{-- The two counts, side by side, each against its own expected figure. Neither is a check on the other: one is the shift, the other is the box. --}}
@foreach ([ ['label' => __('Came in today'), 'expected' => $line->expected_takings, 'counted' => $line->counted_takings, 'diff' => $takingsVariance, 'legacy' => $line->takings_is_legacy_basis], ['label' => __('In the account, in total'), 'expected' => (float) $line->system_balance, 'counted' => (float) $line->counted_amount, 'diff' => $variance, 'legacy' => false], ] as $side) @php $d = $side['diff']; $out = $d !== null && abs((float) $d) >= 0.01; @endphp
! $out, 'bg-rose-50/50 ring-rose-200/70' => $out && (float) $d < 0, 'bg-amber-50/50 ring-amber-200/70' => $out && (float) $d > 0, ])>

{{ $side['label'] }}

@if ($side['legacy']) {{-- Counted when this figure meant the day's net. Said plainly, because the heading above it no longer describes what the number underneath is. --}}

{{ __('Counted as the day\'s net, after what was paid out or moved on.') }}

@endif @if ($side['counted'] === null)

{{ __('Not counted separately on this cash-up') }}

@else
{{ __('Expected') }}
{{ $cur }} {{ number_format((float) $side['expected'], 2) }}
{{ __('Counted') }}
{{ $cur }} {{ number_format((float) $side['counted'], 2) }}
{{ __('Difference') }}
! $out, 'text-rose-600' => $out && (float) $d < 0, 'text-amber-600' => $out && (float) $d > 0, ])> {{ (float) $d > 0 ? '+' : '' }}{{ number_format((float) $d, 2) }}
@endif
@endforeach
@if ($carried !== null && abs((float) $carried) >= 0.01)

{{ __('Of that, :amount was carried in from before today, so the balance brought forward is what is wrong.', [ 'amount' => $cur.' '.number_format(abs((float) $carried), 2), ]) }}

@endif {{-- The conversation about it, as a conversation. --}}
@include('livewire.treasury.partials.cash-up-thread', ['line' => $line])
{{-- The decision, on the difference itself rather than in a second table of the same numbers further down the page. --}} @if ($canReview && in_array($status, ['pending', 'queried'], true)) @if ($reviewingLineId === $line->id)
@error('reviewNote')

{{ $message }}

@enderror

{{ __('Approving books it to the profit and loss. Rejecting a shortage makes it recoverable from the cashier. Sending it back books nothing.') }}

@else @endif @endif
@endforeach {{-- Accounts that agreed on both counts: worth confirming, not worth a block each. --}} @if ($settled->isNotEmpty())

{{ __('Balanced') }}

@foreach ($settled as $line)
{{ $line->account?->name ?? __('Account') }} @if ($line->counted_takings !== null) {{ __('day') }} {{ $line->currency_code }} {{ number_format((float) $line->counted_takings, 2) }} · @endif {{ __('total') }} {{ $line->currency_code }} {{ number_format((float) $line->counted_amount, 2) }}
@endforeach
@endif
@if ($existing->notes)
{{ __('Notes:') }} {{ $existing->notes }}
@endif @if ($pendingCount > 0 && ! $canReview)
{{ trans_choice( '{1} :count difference is with the directors for approval.|[2,*] :count differences are with the directors for approval.', $pendingCount, ['count' => $pendingCount], ) }}
@endif