@extends('layouts.app') @section('title', $invoice->number) @section('content') @if(session('status'))
{{ session('status') }}
@endif @php $bank = \App\Models\TenantSetting::group(auth()->user()->tenant_id, 'bank-transfer'); $hasBank = ! empty($bank['iban']); $editable = ! in_array($invoice->status, [ \App\Models\TenantUserInvoice::STATUS_PAID, \App\Models\TenantUserInvoice::STATUS_VOID, ], true); $emailable = $invoice->status !== \App\Models\TenantUserInvoice::STATUS_VOID; // Group lines by analysis_type for the bulk "apply to all of type" helper. $byType = $invoice->lines->groupBy('analysis_type'); // Pre-built array passed to the Alpine editor — kept out of the x-data // attribute to avoid Blade's directive parser tripping on nested brackets. $editorLines = $invoice->lines->map(fn ($l) => [ 'id' => $l->id, 'qty' => (int) $l->quantity, 'unit' => (float) $l->unit_amount, 'type' => $l->analysis_type, ])->values(); // Email send history pulled from snapshot.emails (set by controller after each send). $emailHistory = collect($invoice->snapshot['emails'] ?? []) ->map(fn ($e) => [ 'at' => isset($e['at']) ? \Carbon\Carbon::parse($e['at']) : null, 'to' => $e['to'] ?? null, ]) ->filter(fn ($e) => $e['at'] && $e['to']) ->sortByDesc(fn ($e) => $e['at']->getTimestamp()) ->values(); $lastEmail = $emailHistory->first(); @endphp
← {{ __('All invoices') }} @if($emailable) @endif @if($invoice->status === 'issued')
@csrf
@endif @if($invoice->status !== 'void')
@csrf
@endif @if($lastEmail) {{ __('Last sent') }}: {{ $lastEmail['at']->translatedFormat('d M Y · H:i') }} {{ __('to') }} {{ $lastEmail['to'] }} @endif
@if($emailable)
@csrf

{{ __('Defaults to the client email — override if needed.') }}

{{ $invoice->number }} · {{ $invoice->period_start->format('Y-m-d') }} → {{ $invoice->period_end->format('Y-m-d') }} · {{ number_format((float) $invoice->total, 2, ',', ' ') }} {{ $invoice->currency }}
@if($emailHistory->count() > 1)
{{ __('Send history') }} ({{ $emailHistory->count() }})
    @foreach($emailHistory as $e)
  • {{ $e['at']->translatedFormat('d M Y · H:i') }} → {{ $e['to'] }}
  • @endforeach
@endif
@endif
@if($errors->any())
@endif
{{ __('Number') }}
{{ $invoice->number }}
{{ __('Client') }}
{{ $invoice->user?->name }}
{{ $invoice->user?->email }}
{{ __('Period') }}
{{ $invoice->period_start->format('Y-m-d') }} → {{ $invoice->period_end->format('Y-m-d') }}
{{ __('Status') }}
{{ ucfirst($invoice->status) }}
@if($editable)
@csrf @method('PATCH') {{-- Per-type bulk price helper — only shown when more than one line of that type exists. --}} @php $typesWithMultiple = $byType->filter(fn($g) => $g->count() > 1); @endphp @if($typesWithMultiple->isNotEmpty())
{{ __('Price per analysis type') }}

{{ __('Set one price and apply it to every line of that type.') }}

@foreach($typesWithMultiple as $type => $linesOfType) @php $label = $type === '_floor' ? __('Monthly minimum') : __(config('finance_analyses.types.'.$type.'.label', $type)); @endphp
{{ $label }} ({{ $linesOfType->count() }})
@endforeach
@endif
@foreach($invoice->lines as $i => $line) @endforeach
{{ __('Description') }} {{ __('Qty') }} {{ __('Unit') }} {{ __('Amount') }}
{{ $line->description }} {{ $line->quantity }}
{{ __('Subtotal') }}
{{ __('VAT') }} ({{ rtrim(rtrim(number_format((float)$invoice->vat_rate,2),'0'),'.') }}%)
{{ __('Total') }}
{{ __('Reset') }}
@else
@foreach($invoice->lines as $line) @endforeach
{{ __('Description') }} {{ __('Qty') }} {{ __('Unit') }} {{ __('Amount') }}
{{ $line->description }} {{ $line->quantity }} {{ number_format((float)$line->unit_amount, 2) }} {{ number_format((float)$line->amount, 2) }}
{{ __('Subtotal') }}{{ number_format((float)$invoice->subtotal, 2) }} {{ $invoice->currency }}
{{ __('VAT') }} ({{ rtrim(rtrim(number_format((float)$invoice->vat_rate,2),'0'),'.') }}%){{ number_format((float)$invoice->vat_amount, 2) }}
{{ __('Total') }}{{ number_format((float)$invoice->total, 2) }} {{ $invoice->currency }}
@endif @if($hasBank)
{{ __('Bank-transfer details') }}
@if(! empty($bank['account_holder']))
{{ __('Holder') }}: {{ $bank['account_holder'] }}
@endif
{{ __('IBAN') }}: {{ $bank['iban'] }}
@if(! empty($bank['bic']))
BIC: {{ $bank['bic'] }}
@endif @if(! empty($bank['bank_name']))
{{ __('Bank') }}: {{ $bank['bank_name'] }}
@endif
{{ __('Reference') }}: {{ str_replace(':invoice_number', $invoice->number, $bank['reference_template'] ?? ':invoice_number') }}
@if(! empty($bank['notes']))

{{ $bank['notes'] }}

@endif
@endif
@if($editable) @push('scripts') @endpush @endif @endsection