@foreach($clients as $client)
@php
// Récupérer tous les abonnements actifs du client
$abonnementsActifs = $client->abonnements_actifs;
$hasMultipleAbonnements = $abonnementsActifs->count() > 1;
$principalAbonnement = $abonnementsActifs->first();
// Préparer les données pour le modal
$abonnementsData = [];
foreach ($abonnementsActifs as $abonnement) {
$now = \Carbon\Carbon::now();
$dateFin = \Carbon\Carbon::parse($abonnement->date_fin);
$joursTotal = $abonnement->date_debut->diffInDays($abonnement->date_fin);
$joursRestants = $now->diffInDays($dateFin, false);
$pourcentageTemps = $joursRestants > 0 ?
min(100, ($joursTotal - $joursRestants) / $joursTotal * 100) : 100;
$totalPaye = $abonnement->paiements->sum('montant');
$difference = $totalPaye - $abonnement->prix;
if ($joursRestants < 0) {
$couleur = 'text-red-500';
$icon = 'fa-exclamation-triangle';
} elseif ($joursRestants <= 7) {
$couleur = 'text-orange-500';
$icon = 'fa-clock';
} else {
$couleur = 'text-green-500';
$icon = 'fa-check-circle';
}
if ($joursRestants < 0) {
$formatJours = 'Expiré';
} else {
$mois = floor($joursRestants / 30);
$semaines = floor(($joursRestants % 30) / 7);
$jours = $joursRestants % 7;
$formatJours = '';
if ($mois > 0) $formatJours .= $mois . 'M ';
if ($semaines > 0) $formatJours .= $semaines . 'S ';
if ($jours > 0 || ($mois == 0 && $semaines == 0)) $formatJours .= $jours . 'J';
$formatJours = trim($formatJours);
}
$abonnementsData[] = [
'id' => $abonnement->id,
'type_abonnement' => $abonnement->type_abonnement,
'prix' => number_format($abonnement->prix, 0, '', ' '),
'total_paye' => number_format($totalPaye, 0, '', ' '),
'difference' => $difference,
'date_debut' => $abonnement->date_debut->format('d/m/Y'),
'date_fin' => $abonnement->date_fin->format('d/m/Y'),
'pourcentage_temps' => round($pourcentageTemps),
'couleur' => $couleur,
'icon' => $icon,
'jours_restants' => $formatJours,
'prix_num' => $abonnement->prix,
'total_paye_num' => $totalPaye
];
}
if ($principalAbonnement) {
$now = \Carbon\Carbon::now();
$dateFin = \Carbon\Carbon::parse($principalAbonnement->date_fin);
$joursTotal = $principalAbonnement->date_debut->diffInDays($principalAbonnement->date_fin);
$joursRestants = $now->diffInDays($dateFin, false);
// Calcul du pourcentage de progression temporelle
$pourcentageTemps = $joursRestants > 0 ? min(100, ($joursTotal - $joursRestants) / $joursTotal * 100) : 100;
// Calcul du ratio paiement/abonnement
$totalPaye = $principalAbonnement->paiements->sum('montant');
$prixAbonnement = $principalAbonnement->prix;
$ratioPaiement = $prixAbonnement > 0 ? min(100, ($totalPaye / $prixAbonnement) * 100) : 0;
$difference = $totalPaye - $prixAbonnement;
// Format des jours restants
if ($joursRestants < 0) {
$formatJours = 'Expiré';
} else {
$mois = floor($joursRestants / 30);
$semaines = floor(($joursRestants % 30) / 7);
$jours = $joursRestants % 7;
$formatJours = '';
if ($mois > 0) $formatJours .= $mois . 'M ';
if ($semaines > 0) $formatJours .= $semaines . 'S ';
if ($jours > 0 || ($mois == 0 && $semaines == 0)) $formatJours .= $jours . 'J';
$formatJours = trim($formatJours);
}
// Déterminer la couleur en fonction des jours restants
if ($joursRestants < 0) {
$couleur = 'text-red-500';
$couleurBg = 'bg-red-500';
$couleurStatut = 'bg-red-100 text-red-800';
$texteStatut = 'Expiré';
$icon = 'fa-exclamation-triangle';
} elseif ($joursRestants <= 7) {
$couleur = 'text-orange-500';
$couleurBg = 'bg-orange-500';
$couleurStatut = 'bg-orange-100 text-orange-800';
$texteStatut = $formatJours;
$icon = 'fa-clock';
} else {
$couleur = 'text-green-500';
$couleurBg = 'bg-green-500';
$couleurStatut = 'bg-green-100 text-green-800';
$texteStatut = $formatJours;
$icon = 'fa-check-circle';
}
}
@endphp
@if($hasMultipleAbonnements)
@endif
@if($principalAbonnement)
{{ number_format($pourcentageTemps, 0) }}%
@else
@endif
{{ $client->prenom }} {{ $client->nom }}
{{ $client->contact }}
{{ $client->engin_type }}
@if($principalAbonnement)
{{ $texteStatut }}
{{ $principalAbonnement->date_fin->format('d/m/Y') }}
@else
Sans abonnement
@endif
@if($principalAbonnement)
Payé: {{ number_format($totalPaye, 0) }} F
Abmt: {{ number_format($prixAbonnement, 0) }} F
@if($totalPaye >= $prixAbonnement)
@if($difference > 0)
@endif
@else
@endif
@if($difference >= 0)
Solde: +{{ number_format($difference, 0) }} F
@else
Dû: {{ number_format(abs($difference), 0) }} F
@endif
@endif
@if($principalAbonnement)
@else
Abonnement
@endif
@if($abonnementsActifs->count() > 0)
@endif
@endforeach
Guide de lecture
Cercles de progression
Temps écoulé
70% du temps passé
Presque expiré
20% du temps restant
Barres de progression
Payé: 15 000 F
Abmt: 10 000 F
Solde: +5 000 F
Excédent de paiement (bleu)
Payé: 7 000 F
Abmt: 10 000 F
Dû: 3 000 F
Paiement incomplet