@extends('layouts.provider') @section('title', 'Détail de la facture') @section('page-title', 'Finances > Détail de la facture') @section('content')

{{ $invoice->invoice_number ?? $invoice->reference }}

{{ $invoice->client->full_name ?? 'N/A' }}

Faite: {{ $invoice->payment_date->format('d/m/Y') }} @if($invoice->due_date) · Échéance: {{ $invoice->due_date->format('d/m/Y') }} @endif
@if($invoice->notes)

{{ $invoice->notes }}

@endif
@if($invoice->canBeModified()) @endif @if($invoice->canBeModified()) @else @endif @if($invoice->isDraft()) @endif @if($invoice->isOpen() || $invoice->isInvoicePaid()) @endif
Total HT
{{ format_currency($invoice->amount) }} {{ $invoice->currency }}
@php $withholdingTaxes = $invoice->invoiceTaxes->filter(function($invoiceTax) { return $invoiceTax->tax && $invoiceTax->tax->is_withholding_tax; }); $otherTaxes = $invoice->invoiceTaxes->filter(function($invoiceTax) { return !$invoiceTax->tax || !$invoiceTax->tax->is_withholding_tax; }); @endphp @if($invoice->total_vat > 0)
TVA ({{ number_format(($invoice->total_vat / $invoice->amount) * 100, 0) }}%)
+{{ format_currency($invoice->total_vat) }} {{ $invoice->currency }}
@endif
Total TTC
{{ format_currency($invoice->total_ttc) }} {{ $invoice->currency }}
@foreach($withholdingTaxes as $invoiceTax)
{{ $invoiceTax->label_snapshot ?? ucfirst(str_replace('_', ' ', $invoiceTax->name_snapshot)) }} ({{ number_format(abs($invoiceTax->value_snapshot), 2) }}%)
{{ $invoiceTax->sign_snapshot }}{{ format_currency(abs($invoiceTax->amount_snapshot)) }} {{ $invoice->currency }}
@endforeach @foreach($otherTaxes as $invoiceTax)
{{ $invoiceTax->label_snapshot ?? ucfirst(str_replace('_', ' ', $invoiceTax->name_snapshot)) }} @if($invoiceTax->type_snapshot === 'percent') ({{ number_format($invoiceTax->value_snapshot, 0) }}%)@endif
{{ $invoiceTax->sign_snapshot }}{{ format_currency($invoiceTax->amount_snapshot) }} {{ $invoice->currency }}
@endforeach
Net à payer
{{ format_currency($invoice->net_amount) }} {{ $invoice->currency }}
Payé
{{ format_currency($invoice->paid_amount) }} {{ $invoice->currency }}
Restant
{{ format_currency($invoice->remaining_amount) }} {{ $invoice->currency }}
Progression du paiement {{ number_format($invoice->payment_percentage, 1) }}%
@if($invoice->is_overdue) EN RETARD ({{ $invoice->days_overdue }} jours) @else @switch($invoice->status) @case('non_payee') Non payée @break @case('partiellement_payee') Partiellement payée @break @case('payee') Payée @break @case('annulee') Annulée @break @endswitch @endif
@php $withholdingCount = $invoice->invoicePayments->filter(fn($p) => $p->payment_method === 'retenue_source')->count(); $normalPaymentsCount = $invoice->invoicePayments->filter(function($p) { return $p->payment_method !== 'retenue_source'; })->count(); @endphp

Paiements enregistrés ({{ $normalPaymentsCount + $withholdingCount }})

@if($invoice->remaining_amount > 0 && !$invoice->isDraft()) @endif
@if($normalPaymentsCount > 0 || $withholdingCount > 0)
@php $paymentNumber = 0; $paymentNumbers = []; $reversalReferences = []; // Pré-calculer les numéros pour TOUS les paiements (y compris retenues et annulations) foreach($invoice->invoicePayments->sortBy('id') as $p) { $paymentNumber++; $paymentNumbers[$p->id] = $paymentNumber; // Si c'est une annulation, stocker la référence ANN-XX if ($p->isReversal() && $p->reversal_of_payment_id) { $originalNumber = $paymentNumbers[$p->reversal_of_payment_id] ?? 0; $reversalReferences[$p->id] = 'ANN-' . str_pad($originalNumber, 2, '0', STR_PAD_LEFT); } } @endphp @foreach($invoice->invoicePayments->sortByDesc('id') as $payment) @if($payment->payment_method !== 'retenue_source') @endif @endforeach @foreach($invoice->invoicePayments->sortByDesc('payment_date')->filter(fn($p) => $p->payment_method === 'retenue_source') as $withholdingPayment) @endforeach
Date Compte Méthode Montant Référence Actions
@if($payment->isReversal()) {{ str_pad($paymentNumbers[$payment->id] ?? 0, 2, '0', STR_PAD_LEFT) }} @else {{ str_pad($paymentNumbers[$payment->id] ?? 0, 2, '0', STR_PAD_LEFT) }} @endif {{ $payment->payment_date->format('d/m/Y') }} @if($payment->isReversed()) (Annulé) @endif {{ $payment->treasuryAccount->name ?? '-' }} @switch($payment->payment_method) @case('cash') Espèces @break @case('bank_transfer') Virement @break @case('check') Chèque @break @case('card') Carte @break @endswitch {{ $payment->amount < 0 ? '-' : '' }}{{ format_currency(abs($payment->amount)) }}{{ $invoice->currency }} @if($payment->isReversal()) {{ $reversalReferences[$payment->id] ?? '' }} @else {{ $payment->reference ?? '-' }} @endif @if($payment->isReversal() && $payment->reversal_reason)
{{ Str::limit($payment->reversal_reason, 30) }}
@endif
@if($payment->canBeReversed()) @endif
{{ str_pad($paymentNumbers[$withholdingPayment->id] ?? 0, 2, '0', STR_PAD_LEFT) }} {{ $withholdingPayment->payment_date->format('d/m/Y') }} - {{ $withholdingPayment->notes ?? 'Retenue' }} -{{ format_currency($withholdingPayment->amount) }}{{ $invoice->currency }} {{ $withholdingPayment->reference ?? '-' }} -
@else

Aucun paiement enregistré

@endif
@if($invoice->appointments->count() > 0)

Rendez-vous ({{ $invoice->appointments->count() }})

@endif
@if($invoice->is_overdue && $invoice->remaining_amount > 0)
Facture en retard de {{ $invoice->days_overdue }} jours
@if($invoice->reminders->count() > 0)
Dernière relance: {{ $invoice->reminders->last()->sent_at->format('d/m/Y à H:i') }}
@endif
@csrf
@endif
@foreach($invoice->invoicePayments->where('payment_method', '!=', 'retenue_source') as $payment) @if($payment->canBeReversed()) @endif @endforeach @endsection