@extends('layouts.app') @section('title', 'États & Rapports') @section('breadcrumb', 'États') @section('content') @php function fmtNum($v){ return number_format($v,3,',',' '); } $statutColors = ['en_cours'=>'warning','pause'=>'muted','cloture'=>'success','sav'=>'info','demarrage'=>'muted']; @endphp {{-- Filtres globaux --}}
Filtrer : Réinitialiser
{{-- Onglets --}}
@foreach([ ['journal_vente', 'Journal Vente'], ['journal_achat', 'Journal Achat'], ['balance_clients', 'Balances Clients'], ['balance_fournisseurs', 'Balances Fournisseurs'], ['recap_depenses', 'Récap Dépenses'], ['rentabilite', 'Rentabilité Chantiers'], ] as [$key, $label]) @endforeach
{{-- =================== JOURNAL VENTE =================== --}}
@php $totVHT = $journalVente->sum('total_ht'); $totVTVA = $journalVente->sum('total_tva'); $totVTTC = $journalVente->sum('total_ttc'); $exportParams = array_filter(['deb'=>$deb,'fin'=>$fin,'annee'=>$annee]); @endphp
Exporter CSV
@forelse($journalVente as $d) @empty @endforelse @if($journalVente->count()) @endif
DateN° FactureClientChantier HTTVATTC
{{ \Carbon\Carbon::parse($d->date)->format('d/m/Y') }} {{ $d->numero }} {{ $d->client?->nom ?? '—' }} @if($d->chantier){{ $d->chantier->nom }}@else —@endif {{ fmtNum($d->total_ht) }} {{ fmtNum($d->total_tva) }} {{ fmtNum($d->total_ttc) }}
Aucune écriture
TOTAL ({{ $journalVente->count() }}) {{ fmtNum($totVHT) }} {{ fmtNum($totVTVA) }} {{ fmtNum($totVTTC) }}
{{-- =================== JOURNAL ACHAT =================== --}}
@php $totAHT = $journalAchat->sum('total_ht'); $totATVA = $journalAchat->sum('total_tva'); $totATTC = $journalAchat->sum('total_ttc'); @endphp
Exporter CSV
@forelse($journalAchat as $d) @empty @endforelse @if($journalAchat->count()) @endif
DateN° FactureFournisseurChantier HTTVATTC
{{ \Carbon\Carbon::parse($d->date)->format('d/m/Y') }} {{ $d->numero }} {{ $d->fournisseur?->nom ?? '—' }} @if($d->chantier){{ $d->chantier->nom }}@else —@endif {{ fmtNum($d->total_ht) }} {{ fmtNum($d->total_tva) }} {{ fmtNum($d->total_ttc) }}
Aucune écriture
TOTAL ({{ $journalAchat->count() }}) {{ fmtNum($totAHT) }} {{ fmtNum($totATVA) }} {{ fmtNum($totATTC) }}
{{-- =================== BALANCE CLIENTS =================== --}}
@php $totBCFact=0; $totBCAvoir=0; $totBCRegle=0; @endphp
Exporter CSV
@forelse($balanceClients as $c) @php $factures = $c->venteDocuments->where('type','facture_vente')->sum('total_ttc'); $avoirs = $c->venteDocuments->where('type','avoir_vente')->sum('total_ttc'); $regle = $reglClientsMap[$c->id] ?? 0; $solde = $c->solde ?? ($factures - $avoirs - $regle); $totBCFact += $factures; $totBCAvoir += $avoirs; $totBCRegle += $regle; @endphp @empty @endforelse @if($balanceClients->count()) @endif
CodeClientGroupe CA Facturé TTC Avoirs TTC Réglé Solde
{{ $c->code }} {{ $c->nom }} {{ $c->groupe?->nom ?? '—' }} {{ fmtNum($factures) }} {{ fmtNum($avoirs) }} {{ fmtNum($regle) }} {{ fmtNum($solde) }}
Aucun client
TOTAL ({{ $balanceClients->count() }}) {{ fmtNum($totBCFact) }} {{ fmtNum($totBCAvoir) }} {{ fmtNum($totBCRegle) }} {{ fmtNum($totBCFact-$totBCAvoir-$totBCRegle) }}
{{-- =================== BALANCE FOURNISSEURS =================== --}}
@php $totBFAchat=0; $totBFAvoir=0; $totBFRegle=0; @endphp
Exporter CSV
@forelse($balanceFournisseurs as $f) @php $achats = $f->achatDocuments->where('type','facture_achat')->sum('total_ttc'); $avoirs = $f->achatDocuments->where('type','avoir_achat')->sum('total_ttc'); $regle = $reglFouMap[$f->id] ?? 0; $solde = $f->solde ?? ($achats - $avoirs - $regle); $totBFAchat += $achats; $totBFAvoir += $avoirs; $totBFRegle += $regle; @endphp @empty @endforelse @if($balanceFournisseurs->count()) @endif
CodeFournisseurGroupe Achats TTC Avoirs TTC Réglé Solde
{{ $f->code }} {{ $f->nom }} {{ $f->groupe?->nom ?? '—' }} {{ fmtNum($achats) }} {{ fmtNum($avoirs) }} {{ fmtNum($regle) }} {{ fmtNum($solde) }}
Aucun fournisseur
TOTAL ({{ $balanceFournisseurs->count() }}) {{ fmtNum($totBFAchat) }} {{ fmtNum($totBFAvoir) }} {{ fmtNum($totBFRegle) }} {{ fmtNum($totBFAchat-$totBFAvoir-$totBFRegle) }}
{{-- =================== RÉCAP DÉPENSES =================== --}}
Exporter CSV
@if($recapDepenses->isEmpty())

Aucune dépense

@else
@foreach($recapDepenses as $cat => $montant)
{{ fmtNum($montant) }}
{{ $cat }}
@endforeach
Total dépenses : {{ fmtNum($totalDepenses) }} TND
@foreach($recapDepenses->sortDesc() as $cat => $montant) @endforeach
CatégorieMontant TTC%
{{ $cat }} {{ fmtNum($montant) }} TND {{ $totalDepenses > 0 ? number_format($montant/$totalDepenses*100,1,',','') . '%' : '—' }}
@endif
{{-- =================== RENTABILITÉ CHANTIERS =================== --}}
Exporter CSV
@if($chantiers->isEmpty())

Aucun chantier

@else
@foreach($chantiers as $ch) @php $ca = $ch->venteDocuments->sum('total_ttc'); $achats = $ch->achatDocuments->sum('total_ttc'); $deps = $ch->depenses->sum('montant_ttc'); $rh = $ch->rhAffectations->sum(function($a) { $emp = $a->employe; if (!$emp) return 0; if ($a->type_calc === 'horaire') return ($emp->taux_horaire ?? 0) * ($a->heures ?? 0); return (($emp->salaire_brut ?? 0) / 26) * ($a->jours ?? 0); }); $cout = $achats + $deps + $rh; $marge = $ca - $cout; $taux = $ca > 0 ? ($marge / $ca * 100) : 0; $tauxColor = $taux >= 20 ? 'var(--success)' : ($taux >= 0 ? 'var(--warning)' : 'var(--danger)'); $statLabel = ['en_cours'=>'En cours','pause'=>'Pause','cloture'=>'Clôturé','sav'=>'SAV','demarrage'=>'Démarrage'][$ch->statut] ?? $ch->statut; @endphp @endforeach
CodeChantierClient CA Facturé Achats Dépenses RH Coût Total Marge Taux % Statut
{{ $ch->code }} {{ $ch->nom }} {{ $ch->client?->nom ?? '—' }} {{ fmtNum($ca) }} {{ fmtNum($achats) }} {{ fmtNum($deps) }} {{ fmtNum($rh) }} {{ fmtNum($cout) }} {{ fmtNum($marge) }} {{ number_format($taux,1,',','') }}% {{ $statLabel }}
@endif
{{-- end x-data --}} @endsection