@extends('layouts.app') @section('title', 'Factures') @section('page-title', 'Factures') @php $clientsOptions = collect($impayes->items()) ->map(fn($c) => $c->client) ->filter() ->unique('id') ->sortBy('nom') ->values() ->map(fn($c) => ['value' => $c->nom, 'label' => $c->nom]) ->all(); $clientsOptions = array_merge([['value' => '', 'label' => 'Tous les clients']], $clientsOptions); $facturesData = collect($impayes->items()) ->map(function ($c) { $vente = $c->vente; $client = $c->client; $produit = $vente?->produit; $magasin = $vente?->magasin; $montant = (float) ($vente?->montant ?? 0); $reste = (float) ($c->montant_restant ?? 0); $paye = max(0, $montant - $reste); $dateVente = $vente?->date_vente; return [ 'reference' => $vente?->reference ?? ('CR-' . $c->id), 'client' => $client?->nom ?? '—', 'produit' => $produit?->designation ?? '—', 'magasin' => $magasin?->nom ?? '—', 'montant' => $montant, 'montant_paye' => $paye, 'montant_restant' => $reste, 'statut_paiement' => $vente?->statut_paiement ?? 'en_attente', 'date' => $dateVente ? $dateVente->format('d/m/Y') : '—', 'dateObj' => $dateVente ? $dateVente->format('Y-m-d') : null, ]; }) ->values() ->all(); @endphp @section('content')
| N° Facture | Client | Produit | Magasin | Montant | Date | Statut paiement | Actions |
|---|---|---|---|---|---|---|---|
Payé:
Reste à payer: