Comparaison des offres

{{ $brief->title }} @if($brief->project?->client) · {{ $brief->project->client->name ?: $brief->project->client->company_name }} @endif

@if($brief->canGenerateOffreDePrix()) Offre de prix @endif Retour
@php $comparisonClient = $brief->project?->client; $canSelectOffer = auth()->user()->hasRole('admin') || auth()->user()->can('select_brief_offer'); $supplierColumns = collect($supplierTotals ?? [])->map(function ($item) { return [ 'supplier_id' => $item['supplier_id'] ?? null, 'supplier_name' => $item['supplier_name'] ?? '-', ]; }); if ($supplierColumns->isEmpty()) { $supplierColumns = collect($comparisonRows ?? []) ->flatMap(fn ($row) => collect($row['entries'] ?? [])) ->map(fn ($entry) => [ 'supplier_id' => $entry['supplier_id'] ?? null, 'supplier_name' => $entry['supplier_name'] ?? '-', ]) ->unique('supplier_id') ->values(); } $productionSummaryParts = []; if ($brief->primary_type === 'production') { if ($brief->production_designation) { $productionSummaryParts[] = 'Designation: '.(\App\Models\Brief::PRODUCTION_DESIGNATIONS[$brief->production_designation] ?? $brief->production_designation); } if ($brief->production_format) { $productionSummaryParts[] = 'Format: '.$brief->production_format; } if ($brief->production_papier) { $productionSummaryParts[] = 'Papier: '.$brief->production_papier; } if ($brief->production_impression) { $productionSummaryParts[] = 'Impression: '.$brief->production_impression; } if ($brief->production_finition) { $productionSummaryParts[] = 'Finition: '.$brief->production_finition; } } $comparisonCompanySetting = $companySetting ?? null; $comparisonCompanyLogoUrl = ($comparisonCompanySetting && filled($comparisonCompanySetting->logo_path)) ? asset('storage/'.$comparisonCompanySetting->logo_path) : asset('images/sidebar-logo.png'); $selectedOffer = $brief->selectedOffer; $chargesTotal = (float) ($brief->charges?->sum('amount') ?? 0); $supplierCost = $brief->primary_type === 'production' ? $brief->resolvedSupplierCost() : 0.0; $estimatedPrice = (float) ($brief->estimated_price ?? 0); $sellingPrice = (float) ($brief->selling_price ?? 0); $margin = $sellingPrice > 0 ? ($sellingPrice - $estimatedPrice) : null; $marginPctVsSelling = $margin !== null && $sellingPrice > 0 ? round(($margin / $sellingPrice) * 100, 1) : null; $offersById = $brief->offers->mapWithKeys(fn ($o) => [ $o->id => [ 'id' => $o->id, 'name' => $o->name, 'supplier_id' => $o->supplier_id, 'supplier_name' => $o->supplier?->name ?? '', 'price' => (float) $o->price, 'pricing_tiers' => $o->pricing_tiers ?? [], ], ]); $offersQueryParams = array_filter([ 'return' => request('return'), 'project_id' => request('project_id'), 'from' => 'comparison', ], fn ($value) => $value !== null && $value !== ''); $restoreSelect = null; if ($canSelectOffer && session('select_offer_id') && $errors->hasAny(['quantity', 'selling_price', 'margin_percentage'])) { $restoreSelect = [ 'id' => (int) session('select_offer_id'), 'quantity' => old('quantity'), 'selling_price' => old('selling_price'), 'margin_percentage' => old('margin_percentage'), ]; } $initialRetainedKey = null; if ($restoreSelect) { $initialRetainedKey = ((int) $restoreSelect['id']).'-'.((int) ($restoreSelect['quantity'] ?? 0)); } elseif ($selectedOffer && $brief->production_quantity) { $initialRetainedKey = ((int) $selectedOffer->id).'-'.((int) $brief->production_quantity); } @endphp {{-- Bandeau impression uniquement (logo = paramètres entreprise) --}}

Fiche de comparaison

Nom du client

{{ $comparisonClient ? ($comparisonClient->name ?: $comparisonClient->company_name) : '—' }}

Téléphone

{{ $comparisonClient?->phone_number ?: '—' }}

Projet : {{ $brief->project?->name ?? '—' }} | Brief : {{ $brief->title }} | Date : {{ now()->format('d/m/Y H:i') }}

@if(count($productionSummaryParts) > 0)

{{ implode(' | ', $productionSummaryParts) }}

@endif
@forelse($comparisonRows as $row) @php $entryBySupplier = collect($row['entries'])->keyBy('supplier_id'); $colspan = max(1, $supplierColumns->count() * 2); $selectedSupplierId = (int) ($selectedOffer?->supplier_id ?? 0); $selectedQuantity = (int) ($brief->production_quantity ?? 0); $rowQuantity = (int) round((float) ($row['quantity'] ?? 0)); $isSelectedQuantityRow = $selectedQuantity > 0 && $rowQuantity === $selectedQuantity; @endphp
@foreach($supplierColumns as $supplierCol) @php($isSelectedSupplierColumn = $selectedSupplierId > 0 && (int) ($supplierCol['supplier_id'] ?? 0) === $selectedSupplierId) @php($isSelectedChoice = $isSelectedQuantityRow && $isSelectedSupplierColumn) @endforeach @foreach($supplierColumns as $supplierCol) @php($isSelectedSupplierColumn = $selectedSupplierId > 0 && (int) ($supplierCol['supplier_id'] ?? 0) === $selectedSupplierId) @php($isSelectedChoice = $isSelectedQuantityRow && $isSelectedSupplierColumn) @endforeach @foreach($supplierColumns as $supplierCol) @php($entry = $entryBySupplier->get($supplierCol['supplier_id'])) @php($isSelectedSupplierColumn = $selectedSupplierId > 0 && (int) ($supplierCol['supplier_id'] ?? 0) === $selectedSupplierId) @php($isSelectedChoice = $isSelectedQuantityRow && $isSelectedSupplierColumn) @endforeach @foreach($supplierColumns as $supplierCol) @php($entry = $entryBySupplier->get($supplierCol['supplier_id'])) @php($isSelectedSupplierColumn = $selectedSupplierId > 0 && (int) ($supplierCol['supplier_id'] ?? 0) === $selectedSupplierId) @php($isSelectedChoice = $isSelectedQuantityRow && $isSelectedSupplierColumn) @endforeach @foreach($supplierColumns as $supplierCol) @php($entry = $entryBySupplier->get($supplierCol['supplier_id'])) @php($isSelectedSupplierColumn = $selectedSupplierId > 0 && (int) ($supplierCol['supplier_id'] ?? 0) === $selectedSupplierId) @php($isSelectedChoice = $isSelectedQuantityRow && $isSelectedSupplierColumn) @endforeach @foreach($supplierColumns as $supplierCol) @php($entry = $entryBySupplier->get($supplierCol['supplier_id'])) @php($isSelectedSupplierColumn = $selectedSupplierId > 0 && (int) ($supplierCol['supplier_id'] ?? 0) === $selectedSupplierId) @php($isSelectedChoice = $isSelectedQuantityRow && $isSelectedSupplierColumn) @endforeach
@empty
Aucune comparaison disponible. Ajoutez des offres avec des paliers quantite/prix pour generer le tableau.
@endforelse @if($selectedOffer)

Offre retenue - marge

Fournisseur : {{ $selectedOffer->supplier?->name ?? '—' }} @if($selectedOffer->name) · {{ $selectedOffer->name }} @endif

Quantite Prix d'achat Charges Cout total Majoration % marge agence Prix vente Marge agence en TND
{{ $brief->production_quantity ? number_format((int) $brief->production_quantity, 0, ',', ' ').' pcs' : '—' }} {{ number_format($supplierCost, 3, ',', ' ') }} DT {{ number_format($chargesTotal, 3, ',', ' ') }} DT {{ number_format($estimatedPrice, 3, ',', ' ') }} DT {{ $marginPctVsSelling !== null ? ($marginPctVsSelling >= 0 ? '+' : '').$marginPctVsSelling.'%' : '—' }} {{ $sellingPrice > 0 ? number_format($sellingPrice, 3, ',', ' ').' DT' : '—' }} {{ $margin !== null ? number_format($margin, 3, ',', ' ').' DT' : '—' }}
@endif
@if($canSelectOffer) @endif