@extends('layouts.exat') @section('title', 'Demande '.$demande->reference) @section('subtitle', $demande->planteur->nom ?? '') @section('actions')
@if($demande->peutEtreModifieePar(auth()->user())) Modifier @endif @if($demande->statut === 'EN_VALIDATION') Traiter la validation @endif @if($demande->statut === 'VALIDEE' && app(\App\Services\PermissionModuleService::class)->peut(auth()->user(), 'A_DECAISSER', 2)) @if($demande->contrat && $demande->contrat->date_signature)
@csrf
@else {{ $demande->contrat ? 'Contrat non signé' : "Générez d'abord le contrat" }} @endif @endif @if(in_array($demande->statut, ['DECAISSEE','EN_REMBOURSEMENT','EN_DEFAUT','SOLDEE'])) Suivi remboursement @endif @if($demande->peutEtreAnnuleePar(auth()->user()))
@csrf @method('PATCH')
@endif @if($demande->peutEtreSupprimeePar(auth()->user()))
@csrf @method('DELETE')
@endif
@endsection @section('content')
{{ $demande->reference }} @if($demande->numero_pret)Réf. Ext : {{ $demande->numero_pret }}@endif @if(($demande->source ?? 'APPLICATION') === 'EXTERNE') Importé @endif @if($demande->statut === 'EN_VALIDATION' && $demande->etapeCourante) {{ $demande->circuit->libelle ?? 'Circuit —' }} · Étape : {{ $demande->etapeCourante->libelle }} @endif
@if($demande->statut === 'EN_VALIDATION') @php $prochains = app(\App\Services\WorkflowService::class)->prochainsValidateurs($demande); $seq = ($demande->etapeCourante->mode ?? '') === 'SEQUENTIEL'; @endphp @if(!empty($prochains))

{{ $seq ? 'Prochain approbateur' : 'Approbateurs' }} : {{ implode(', ', $prochains) }}

@endif @endif

Planteur

@php $p = $demande->planteur; @endphp
Nom
{{ $p->nom ?? '—' }}
Code
{{ $p->code ?? '—' }}
N° CNI
{{ $p->numero_cni ?? '—' }}
Date de naissance
{{ optional($p->date_naissance)->format('d/m/Y') ?? '—' }}
Lieu de naissance
{{ $p->lieu_naissance ?? '—' }}
Localité
{{ $p->localite ?? '—' }}
Localisation plantation
{{ $p->localisation_plantation ?? '—' }}
Superficie saignée
{{ $p->superficie_saignee_ha ? $p->superficie_saignee_ha.' ha' : '—' }}
N° Tél principal
{{ $p->telephone_principal ?? $p->telephone ?? '—' }}
N° Tél secondaire
{{ $p->telephone_secondaire ?? '—' }}

Avance

Montant demandé
{{ number_format((float) $demande->montant, 0, ',', ' ') }} FCFA
Objet
{{ $demande->objet ?? '—' }}
Mode de paiement
{{ $demande->mode_paiement ? ucfirst(strtolower($demande->mode_paiement)) : '—' }}
Usine de réception
{{ \App\Models\DemandePret::USINES_LIB[$demande->usine_reception] ?? '—' }}
N° Wave
{{ $demande->numero_wave ?? '—' }}
Réf. Ext (acompte)
{{ $demande->numero_pret ?? '—' }}
@if($demande->date_debut_prelevement)
Début de prélèvement
{{ \Illuminate\Support\Carbon::parse($demande->date_debut_prelevement)->format('d/m/Y') }}
@endif @if($demande->site_code)
Site
{{ $demande->site_code }}
@endif @if($demande->ref_paiement)
Réf. paiement
{{ $demande->ref_paiement }}
@endif
Durée
{{ $demande->duree_mois }} mois
Remboursement
{{ $demande->remboursement_personnalise ? 'Personnalisé (par échéance)' : ($demande->remboursable_mensuel ? number_format($demande->remboursable_mensuel, 0, ',', ' ').' FCFA / mois' : '—') }}
@if($demande->date_octroi)
Date d'octroi
{{ \Illuminate\Support\Carbon::parse($demande->date_octroi)->format('d/m/Y') }}
@endif @if($demande->date_echeance)
Échéance
{{ \Illuminate\Support\Carbon::parse($demande->date_echeance)->format('d/m/Y') }}
@endif
Créée par
{{ $demande->createur?->name ?? '—' }}
Ponts bascules rattachés
@forelse($demande->pontsBascules as $pb) {{ $pb->nom }}@if($pb->localite) — {{ $pb->localite }}@endif @empty @endforelse
Commentaire
{{ $demande->commentaire ?? '—' }}
{{-- Échéancier prévu (remboursement personnalisé, avant décaissement) --}} @if($demande->remboursement_personnalise && !empty($demande->echeancier_json))

Échéancier prévu (personnalisé)

@php $i = 1; $totalPrev = 0; @endphp @foreach(collect($demande->echeancier_json)->sortBy('date') as $l) @php $totalPrev += (float) ($l['montant'] ?? 0); @endphp @endforeach
Date d'échéance Montant
{{ $i++ }} {{ !empty($l['date']) ? \Illuminate\Support\Carbon::parse($l['date'])->format('d/m/Y') : '—' }} {{ number_format((float) ($l['montant'] ?? 0), 0, ',', ' ') }} FCFA
Total {{ number_format($totalPrev, 0, ',', ' ') }} FCFA

Cet échéancier sera appliqué tel quel au décaissement.

@endif {{-- Signature du planteur --}}

Signature du planteur

@if($demande->signature_planteur_path) Signature planteur @else Aucune signature @endif
@csrf
@error('signature_planteur')

{{ $message }}

@enderror
{{-- Contrat --}} @if(in_array($demande->statut, ['VALIDEE','DECAISSEE','EN_REMBOURSEMENT','SOLDEE'])) @php $peutGenererContrat = app(\App\Services\PermissionModuleService::class)->peut(auth()->user(), 'CONTRATS', 2); @endphp

Contrat

@if($demande->contrat)
{{ $demande->contrat->numero }}
Généré le {{ $demande->contrat->date_generation?->format('d/m/Y à H:i') }}
@if($demande->contrat->date_signature)
Signé le {{ $demande->contrat->date_signature->format('d/m/Y') }}
@else
Non signé
@endif
@if($peutGenererContrat) @if($demande->contrat->date_signature)
@csrf
@else
@csrf
@endif @endif Word PDF @if($peutGenererContrat)
@csrf
@endif
@if($demande->contrat->empreinte)

Empreinte SHA-256 : {{ $demande->contrat->empreinte }}

@endif @else

Aucun contrat généré pour cette demande.

@if($peutGenererContrat)
@csrf
@else Génération non autorisée. @endif
@endif
@endif {{-- Historique de validation --}} @if($demande->validations->isNotEmpty())

Historique de validation

    @foreach($demande->validations->sortBy('date_decision') as $v)
  1. @if($v->decision === 'APPROUVE') @else @endif
    {{ $v->validateur->name ?? '—' }} a {{ $v->decision === 'APPROUVE' ? 'approuvé' : 'rejeté' }} · {{ $v->etape->libelle ?? '' }}
    {{ $v->date_decision?->format('d/m/Y à H:i') }}
    @if($v->commentaire)
    « {{ $v->commentaire }} »
    @endif
  2. @endforeach
@endif
Créée le {{ $demande->created_at?->format('d/m/Y à H:i') }} par {{ $demande->createur->name ?? '—' }}.
@endsection