@extends('layouts.app') @section('title', $chantier->nom) @section('breadcrumb', 'Chantiers / '.$chantier->nom) @php $coutTotal = $achatTotal + $depenseTotal + $rhTotal; $marge = $caTotal - $coutTotal; $tauxMarge = $caTotal > 0 ? ($marge / $caTotal) * 100 : 0; $budgetPct = $chantier->budget > 0 ? ($coutTotal / $chantier->budget) * 100 : 0; $statutColors = ['demarrage'=>'badge-muted','en_cours'=>'badge-warning','pause'=>'badge-info','cloture'=>'badge-success','sav'=>'badge-danger']; $statutLabel = ['demarrage'=>'Démarrage','en_cours'=>'En cours','pause'=>'En pause','cloture'=>'Clôturé','sav'=>'SAV']; $activeTab = session('tab', 'indicateurs'); @endphp @section('content') {{-- Page header --}} @if(session('success'))
{{ session('success') }}
@endif {{-- Infos rapides --}}
Début
{{ $chantier->date_debut?->format('d/m/Y') ?? '—' }}
Fin prévue
{{ $chantier->date_fin?->format('d/m/Y') ?? '—' }}
Budget
{{ number_format($chantier->budget,3,',',' ') }} TND
Avancement
{{ $avancement }}%
@if($chantier->notes)
Notes
{{ $chantier->notes }}
@endif
{{-- KPI Cards --}}
{{ number_format($caTotal,3,',',' ') }}
CA Facturé
{{ number_format($achatTotal,3,',',' ') }}
Achats
{{ number_format($depenseTotal,3,',',' ') }}
Dépenses
{{ number_format($rhTotal,3,',',' ') }}
Coût RH
{{ number_format($marge,3,',',' ') }}
Marge nette
{{-- Tabs --}}
{{-- Tab nav --}}
@foreach([ ['indicateurs', 'fas fa-chart-pie', 'Indicateurs'], ['etapes', 'fas fa-list-check', 'Étapes (' . $chantier->etapes->count() . ')'], ['ventes', 'fas fa-file-invoice-dollar', 'Ventes (' . $chantier->venteDocuments->count() . ')'], ['achats', 'fas fa-cart-shopping', 'Achats (' . $chantier->achatDocuments->count() . ')'], ['depenses', 'fas fa-receipt', 'Dépenses (' . $chantier->depenses->count() . ')'], ['rh', 'fas fa-hard-hat', 'RH (' . $chantier->rhAffectations->count() . ')'], ['vehicules', 'fas fa-car-side', 'Véhicules (' . $chantier->vehicules->count() . ')'], ['materiels', 'fas fa-toolbox', 'Matériel (' . $chantier->materiels->count() . ')'], ['soustraitance', 'fas fa-handshake', 'Sous-traitance (' . $chantier->soustraitants->count() . ')'], ['sav', 'fas fa-shield-halved', 'SAV (' . $chantier->savContrats->count() . ')'], ] as [$key, $icon, $label]) @endforeach
{{-- Tab content wrapper --}}
{{-- ══════════════════════════════════════════════════════════════ TAB: INDICATEURS ══════════════════════════════════════════════════════════════ --}}
{{-- Marge --}}
Marge Nette
{{ number_format($marge,3,',',' ') }} TND
Taux de marge : {{ number_format($tauxMarge,1) }}%
{{ $tauxMarge >= 20 ? 'Rentable' : ($tauxMarge >= 0 ? 'Marginalement rentable' : 'Non rentable') }}
{{-- Avancement & Budget --}}
Avancement & Budget
Avancement étapes{{ $avancement }}%
Budget consommé{{ number_format($budgetPct,1) }}%
Budget: {{ number_format($chantier->budget,3,',',' ') }} | Consommé: {{ number_format($coutTotal,3,',',' ') }} | Reste: {{ number_format($chantier->budget - $coutTotal,3,',',' ') }}
{{-- Décomposition coûts --}} @if($coutTotal > 0)
Décomposition des coûts
{{ number_format($coutTotal > 0 ? ($achatTotal/$coutTotal)*100 : 0,0) }}%
Achats — {{ number_format($achatTotal,3,',',' ') }}
{{ number_format($coutTotal > 0 ? ($depenseTotal/$coutTotal)*100 : 0,0) }}%
Dépenses — {{ number_format($depenseTotal,3,',',' ') }}
{{ number_format($coutTotal > 0 ? ($rhTotal/$coutTotal)*100 : 0,0) }}%
RH — {{ number_format($rhTotal,3,',',' ') }}
{{ number_format($coutTotal > 0 ? ($caTotal/max($coutTotal,1))*100 : 0,0) }}%
Rendement — {{ number_format($caTotal,3,',',' ') }} CA
@else
Aucune donnée financière encore enregistrée
@endif
{{-- ══════════════════════════════════════════════════════════════ TAB: ÉTAPES ══════════════════════════════════════════════════════════════ --}}
Étapes du chantier — {{ $chantier->etapes->where('done',true)->count() }}/{{ $chantier->etapes->count() }} terminées
@csrf
@forelse($chantier->etapes as $etape)
@csrf @method('PATCH')
{{ $etape->titre }}
@if($etape->description)
{{ $etape->description }}
@endif
@if($etape->date_debut) {{ $etape->date_debut->format('d/m/Y') }}@endif @if($etape->date_fin) {{ $etape->date_fin->format('d/m/Y') }}@endif
@csrf @method('DELETE')
@empty
Aucune étape définie
@endforelse
{{-- ══════════════════════════════════════════════════════════════ TAB: VENTES ══════════════════════════════════════════════════════════════ --}}
Documents vente liés ({{ $chantier->venteDocuments->count() }})
@csrf

Le document sera créé en brouillon — ouvrez-le ensuite pour compléter les lignes et la TVA.

@if($chantier->venteDocuments->count()) @php $typeColors = ['devis'=>'badge-muted','commande_vente'=>'badge-info','bl'=>'badge-warning','facture_vente'=>'badge-success','avoir_vente'=>'badge-danger']; $typeLabels = ['devis'=>'Devis','commande_vente'=>'Commande','bl'=>'BL','facture_vente'=>'Facture','avoir_vente'=>'Avoir']; @endphp
@foreach($chantier->venteDocuments->sortByDesc('date') as $doc) @endforeach
TypeDateStatutMontant TTCActions
{{ $doc->numero }} {{ $typeLabels[$doc->type] ?? $doc->type }} {{ $doc->date->format('d/m/Y') }} {{ $doc->statut }} {{ number_format($doc->total_ttc,3,',',' ') }}
TOTAL CA FACTURÉ (Factures + BL) {{ number_format($caTotal,3,',',' ') }}
@else
Aucun document vente lié à ce chantier
@endif
{{-- ══════════════════════════════════════════════════════════════ TAB: ACHATS ══════════════════════════════════════════════════════════════ --}}
Documents achat liés ({{ $chantier->achatDocuments->count() }})
@csrf

Le document sera créé en brouillon — ouvrez-le ensuite pour compléter les lignes et la TVA.

@if($chantier->achatDocuments->count()) @php $achatTypeColors = ['demande_achat'=>'badge-muted','commande_achat'=>'badge-info','br'=>'badge-warning','facture_achat'=>'badge-success','avoir_achat'=>'badge-danger']; $achatTypeLabels = ['demande_achat'=>'DA','commande_achat'=>'Commande','br'=>'BR','facture_achat'=>'Facture','avoir_achat'=>'Avoir']; @endphp
@foreach($chantier->achatDocuments->sortByDesc('date') as $doc) @endforeach
TypeFournisseurDateMontant TTCActions
{{ $doc->numero }} {{ $achatTypeLabels[$doc->type] ?? $doc->type }} {{ $doc->fournisseur?->nom ?? '—' }} {{ $doc->date->format('d/m/Y') }} {{ number_format($doc->total_ttc,3,',',' ') }}
TOTAL ACHATS {{ number_format($achatTotal,3,',',' ') }}
@else
Aucun achat lié à ce chantier
@endif
{{-- ══════════════════════════════════════════════════════════════ TAB: DÉPENSES ══════════════════════════════════════════════════════════════ --}}
Dépenses ({{ $chantier->depenses->count() }}) — Total: {{ number_format($depenseTotal,3,',',' ') }} TND
@csrf
@if($chantier->depenses->count())
@foreach($chantier->depenses->sortByDesc('date') as $dep) @endforeach
DateLibelléCatégorieMontant TTC
{{ $dep->numero ?? '—' }} {{ $dep->date?->format('d/m/Y') ?? '—' }} {{ $dep->libelle }} {{ $dep->categorie?->label ?? '—' }} {{ number_format($dep->montant_ttc,3,',',' ') }}
@else
Aucune dépense pour ce chantier
@endif
{{-- ══════════════════════════════════════════════════════════════ TAB: RH ══════════════════════════════════════════════════════════════ --}}
Ressources humaines — Coût total : {{ number_format($rhTotal,3,',',' ') }} TND
@csrf
@if($chantier->rhAffectations->count())
@foreach($chantier->rhAffectations as $aff) @php $taux = $aff->type_calc === 'horaire' ? ($aff->employe?->taux_horaire ?? 0) : (($aff->employe?->salaire_brut ?? 0) / 26); $cout = $aff->type_calc === 'horaire' ? $taux * ($aff->heures ?? 0) : $taux * ($aff->jours ?? 0); @endphp @endforeach
EmployéPosteModeQuantitéTauxCoût
{{ $aff->employe?->nom ?? '—' }} {{ $aff->employe?->poste ?? '—' }} {{ $aff->type_calc === 'horaire' ? 'Horaire' : 'Journalier' }} {{ $aff->type_calc === 'horaire' ? ($aff->heures ?? 0).' h' : ($aff->jours ?? 0).' j' }} {{ number_format($taux,3,',',' ') }} TND/{{ $aff->type_calc === 'horaire' ? 'h' : 'j' }} {{ number_format($cout,3,',',' ') }} TND
@csrf @method('DELETE')
COÛT RH TOTAL {{ number_format($rhTotal,3,',',' ') }} TND
Les taux sont calculés depuis le module Ressources Humaines.
@else
Aucun employé affecté à ce chantier
@endif
{{-- ══════════════════════════════════════════════════════════════ TAB: VÉHICULES ══════════════════════════════════════════════════════════════ --}}
Véhicules affectés ({{ $chantier->vehicules->count() }})
Catalogue
@if($vehiculesCatalog->isEmpty())
Le catalogue véhicules est vide. Ajouter des véhicules d'abord.
@endif {{-- Formulaire d'affectation depuis le catalogue --}}
@csrf
@if($chantier->vehicules->count())
@foreach($chantier->vehicules as $veh) @php $vehImmat = $veh->vehicule ? $veh->vehicule->immat : $veh->immat; $vehMarque = $veh->vehicule ? $veh->vehicule->marque : $veh->marque; $vehModele = $veh->vehicule ? $veh->vehicule->modele : $veh->modele; $etatColor = ['bon'=>'badge-success','alerte'=>'badge-warning','panne'=>'badge-danger'][$veh->etat] ?? 'badge-muted'; $etatLabel = ['bon'=>'Bon état','alerte'=>'Alerte','panne'=>'En panne'][$veh->etat] ?? $veh->etat; @endphp
{{ $vehImmat }}
{{ trim($vehMarque.' '.$vehModele) ?: '—' }}
{{ $etatLabel }}
@if($veh->kilometrage)
{{ number_format($veh->kilometrage) }} km
@endif @if($veh->prochain_entretien)
Entretien : {{ $veh->prochain_entretien->format('d/m/Y') }} @if($veh->prochain_entretien->isPast())EN RETARD@endif
@endif @if($veh->notes)
{{ $veh->notes }}
@endif
@csrf @method('DELETE')
{{ $vehImmat }}{{ trim($vehMarque.' '.$vehModele) ? ' — '.trim($vehMarque.' '.$vehModele) : '' }}
@csrf @method('PUT')
@endforeach
@else
Aucun véhicule affecté à ce chantier
@endif
{{-- ══════════════════════════════════════════════════════════════ TAB: MATÉRIELS ══════════════════════════════════════════════════════════════ --}}
Matériel affecté ({{ $chantier->materiels->count() }})
Catalogue
@if($materielsCatalog->isEmpty())
Le catalogue matériels est vide. Ajouter des matériels d'abord.
@endif
@csrf
@if($chantier->materiels->count())
@foreach($chantier->materiels as $mat) @php $matNom = $mat->materiel ? $mat->materiel->nom : $mat->nom; $matRef = $mat->materiel ? $mat->materiel->ref : $mat->ref; $matEtatColor = ['bon'=>'badge-success','loue'=>'badge-info','usure'=>'badge-warning'][$mat->etat] ?? 'badge-muted'; $matEtatLabel = ['bon'=>'Bon état','loue'=>'Location','usure'=>'Usure'][$mat->etat] ?? $mat->etat; @endphp @endforeach
DésignationRéférenceQtéDate affectationÉtatCoût loc./jActions
{{ $matNom }} {{ $matRef ?: '—' }} {{ $mat->qte }} {{ $mat->date_affectation ? $mat->date_affectation->format('d/m/Y') : '—' }} {{ $matEtatLabel }} {{ $mat->cout_loc > 0 ? number_format($mat->cout_loc,3,',',' ').' TND' : '—' }}
@csrf @method('DELETE')
{{ $matNom }}{{ $matRef ? ' — '.$matRef : '' }}
@csrf @method('PUT')
@else
Aucun matériel affecté à ce chantier
@endif
{{-- ══════════════════════════════════════════════════════════════ TAB: SOUS-TRAITANCE ══════════════════════════════════════════════════════════════ --}}
@php $sstTotal = $chantier->soustraitants->sum('montant'); @endphp
Sous-traitants ({{ $chantier->soustraitants->count() }}) — Total: {{ number_format($sstTotal,3,',',' ') }} TND
Catalogue
@if($soustraitantsCatalog->isEmpty())
Le catalogue est vide. Ajouter des sous-traitants d'abord.
@endif
@csrf
@if($chantier->soustraitants->count())
@foreach($chantier->soustraitants as $sst) @php $sstNom = $sst->soustraitant ? $sst->soustraitant->nom : $sst->nom; $sstPrestation = $sst->soustraitant ? $sst->soustraitant->prestation : $sst->prestation; $sstTel = $sst->soustraitant ? $sst->soustraitant->tel : $sst->tel; $sstStatutColor = ['regle'=>'badge-success','encours'=>'badge-warning','attente'=>'badge-muted'][$sst->statut] ?? 'badge-muted'; @endphp @endforeach
Société / NomPrestationMontant TNDStatutDateTéléphoneActions
{{ $sstNom }} {{ $sstPrestation ?: '—' }} {{ number_format($sst->montant,3,',',' ') }} {{ ['regle'=>'Réglé','encours'=>'En cours','attente'=>'En attente'][$sst->statut] ?? $sst->statut }} {{ $sst->date ? $sst->date->format('d/m/Y') : '—' }} {{ $sstTel ?: '—' }}
@csrf @method('DELETE')
{{ $sstNom }}{{ $sstPrestation ? ' — '.$sstPrestation : '' }}{{ $sstTel ? ' · '.$sstTel : '' }}
@csrf @method('PUT')
@else
Aucun sous-traitant pour ce chantier
@endif
{{-- ══════════════════════════════════════════════════════════════ TAB: SAV & MAINTENANCE ══════════════════════════════════════════════════════════════ --}}
SAV & Contrats de maintenance ({{ $chantier->savContrats->count() }})
@csrf
@forelse($chantier->savContrats as $sav) @php $savStatutColor = ['actif'=>'badge-success','cloture'=>'badge-muted','attente'=>'badge-warning'][$sav->statut] ?? 'badge-muted'; @endphp
{{ $sav->titre }}
{{ $sav->type === 'sav' ? 'SAV — Intervention' : 'Contrat de maintenance' }}
{{ ['actif'=>'Actif','cloture'=>'Clôturé','attente'=>'En attente'][$sav->statut] ?? $sav->statut }}
Date
{{ $sav->date?->format('d/m/Y') ?? '—' }}
Fin contrat
{{ $sav->date_fin?->format('d/m/Y') ?? 'Sans fin' }}
Montant
{{ number_format($sav->montant,3,',',' ') }} TND
@if($sav->description)
{{ $sav->description }}
@endif
@csrf @method('DELETE')
@csrf @method('PUT')
@empty
Aucun SAV ou contrat de maintenance
@endforelse
{{-- card-body --}}
{{-- card --}}
{{-- x-data tab --}} @endsection