@extends('layouts.app') @section('title', 'Achat') @section('breadcrumb', 'Commercial / Achat') @section('content') @php $aTypes = ['' => 'Tous', 'demande_achat' => 'D. Achat', 'commande_achat' => 'Commande', 'br' => 'Bon Réc.', 'facture_achat' => 'Facture', 'avoir_achat' => 'Avoir']; $tabIcons = ['' => 'fa-th-list', 'demande_achat' => 'fa-file-alt', 'commande_achat' => 'fa-shopping-basket', 'br' => 'fa-boxes', 'facture_achat' => 'fa-file-invoice', 'avoir_achat' => 'fa-undo-alt']; $activeTab = request('type', ''); $tabBase = request()->except(['type', 'page']); $achatColors = ['demande_achat'=>'btn-secondary','commande_achat'=>'btn-primary','br'=>'btn-success','facture_achat'=>'btn-warning']; $achatLabels = ['demande_achat'=>'D. Achat','commande_achat'=>'Commande','br'=>'Bon Réc.','facture_achat'=>'Facture']; // Pre-compute JS data — @json() cannot span multiple lines in Blade $amFournisseurs = $fournisseurs->map(fn($f) => ['id' => $f->id, 'nom' => $f->nom])->values(); $amProduits = $produits->map(fn($p) => ['id' => $p->id, 'nom' => $p->nom, 'code_article' => $p->code_article, 'prix_achat_ht' => (float) $p->prix_achat_ht, 'tva_id' => (string) ($p->tva_achat_id ?? '')])->values(); $amTvaList = $tvaList->map(fn($t) => ['id' => $t->id, 'taux' => (float) $t->taux])->values(); $amChantiers = $chantiers->map(fn($c) => ['id' => $c->id, 'nom' => $c->nom])->values(); $amEmplacements = $emplacements->map(fn($e) => ['id' => $e->id, 'label' => $e->label, 'children' => $e->enfants->map(fn($c) => ['id' => $c->id, 'label' => $c->label])->values()])->values(); @endphp {{-- ── Page data injected once for Alpine ── --}} {{-- ── Page header ── --}} {{-- ── Type tabs (pill Q-ACHAT) ── --}}
@foreach($aTypes as $t => $l) @php $isActive = $activeTab === $t; $href = $t ? route('achat.index', array_merge($tabBase, ['type' => $t])) : ($tabBase ? route('achat.index', $tabBase) : route('achat.index')); $cnt = $t ? ($typeCounts[$t] ?? 0) : $typeCounts->sum(); @endphp {{ $l }} {{ $cnt }} @endforeach
{{-- ── Filters ── --}}
@if($activeTab)@endif
{{-- ── Table ── --}}
@forelse($docs as $doc) @empty @endforelse
NuméroTypeFournisseurDateTotal TTCStatutActions
{{ $doc->numero }} {{ $doc->type_libelle }} {{ $doc->fournisseur?->nom ?? '-' }} {{ $doc->date->format('d/m/Y') }} {{ number_format($doc->total_ttc,3,',',' ') }} {{ ucfirst($doc->statut) }}
@if($doc->statut !== 'annule') @endif @php $achatRowAllowed = ['demande_achat'=>['commande_achat'=>'Commande Achat','br'=>'Bon de Réception','facture_achat'=>'Facture Achat'],'commande_achat'=>['br'=>'Bon de Réception','facture_achat'=>'Facture Achat'],'br'=>['facture_achat'=>'Facture Achat'],'facture_achat'=>['avoir_achat'=>'Avoir Achat']]; $rowCibles = !$doc->converted ? ($achatRowAllowed[$doc->type] ?? []) : []; @endphp @if(count($rowCibles) > 0) @endif @if($doc->type === 'commande_achat' && !in_array($doc->statut, ['annule', 'recu']))
@csrf @method('DELETE')
@endif
Aucun document
@if($docs->hasPages())
{{ $docs->links() }}
@endif
{{-- ═══════════════════════════════════════════════════════ MODAL ACHAT — création + modification (Alpine inline) ═══════════════════════════════════════════════════════ --}}
{{-- Overlay --}} {{-- Modal --}} {{-- /modal --}}
{{-- /amWrap --}} @push('scripts') @endpush {{-- ═══════════════════════════════════════════════════════ MODAL CONVERSION — partagé pour la liste achat ═══════════════════════════════════════════════════════ --}}
@endsection