@props([ 'objectiveKey', 'objectiveData', 'usesDailyMetrics' => false, 'usdToTndRate' => 4, ]) @php $isConversion = $objectiveKey === 'conversion'; $label = $isConversion ? 'Couverture' : 'Interaction'; $resultLabel = $isConversion ? 'Couverture' : 'Interactions'; $adsWithMetrics = $objectiveData['ads_with_metrics'] ?? []; $groupedReportAds = collect($adsWithMetrics)->groupBy(fn ($row) => (string) $row['ad']->post_name); $postTotalsByName = collect($objectiveData['by_post'] ?? [])->keyBy('post_name'); $headerBg = $isConversion ? '#ecfdf5' : '#f5f3ff'; $headerColor = $isConversion ? '#065f46' : '#5b21b6'; $pubBg = $isConversion ? '#d1fae5' : '#ede9fe'; $subtotalBg = $isConversion ? '#a7f3d0' : '#ddd6fe'; $totalBg = $isConversion ? '#059669' : '#7c3aed'; $rowAltBg = $isConversion ? '#f0fdf4' : '#f5f3ff'; $barSpendColor = '#E83646'; $barResultColor = $isConversion ? '#16a34a' : '#7c3aed'; if ($usesDailyMetrics && ($objectiveData['daily'] ?? []) !== []) { $chartRows = collect($objectiveData['daily'])->map(fn (array $row) => [ 'label' => (string) $row['date'], 'spend' => (float) $row['spend'], 'results' => (int) $row['results'], ]); } else { $chartRows = collect($objectiveData['by_post'] ?? [])->map(fn (array $row) => [ 'label' => (string) $row['post_name'], 'spend' => (float) $row['spend'], 'results' => $isConversion ? (int) $row['conversions'] : (int) $row['interactions'], ]); } $maxSpend = max($chartRows->pluck('spend')->all() ?: [1]); $maxResults = max($chartRows->pluck('results')->all() ?: [1]); if ($maxSpend <= 0) { $maxSpend = 1; } if ($maxResults <= 0) { $maxResults = 1; } @endphp @if ($adsWithMetrics !== [])
{{ $label }} {{ count($adsWithMetrics) }} ad{{ count($adsWithMetrics) > 1 ? 's' : '' }}  ·  Spend {{ number_format($objectiveData['totals']['spend'], 2, ',', ' ') }} $ ({{ number_format($objectiveData['totals']['spend'] * $usdToTndRate, 2, ',', ' ') }} TND)  ·  {{ $resultLabel }} {{ number_format($objectiveData['totals']['results'], 0, ',', ' ') }}
Graphique
@if ($chartRows->isNotEmpty()) @foreach ($chartRows as $chartRow) @php $spendWidth = max(4, (int) round(($chartRow['spend'] / $maxSpend) * 100)); $resultWidth = max(4, (int) round(($chartRow['results'] / $maxResults) * 100)); @endphp @endforeach
Spend (TND) {{ $resultLabel }}
{{ \Illuminate\Support\Str::limit($chartRow['label'], 14) }}
   
   
{{ number_format($chartRow['spend'] * $usdToTndRate, 0, ',', ' ') }} TND
{{ number_format($chartRow['spend'], 0, ',', ' ') }} $
{{ number_format($chartRow['results'], 0, ',', ' ') }}
@else
Aucune donnee
@endif
@foreach ($groupedReportAds as $postName => $postRows) @foreach ($postRows as $index => $reportRow) @php($reportAd = $reportRow['ad']) @php($resultValue = $isConversion ? $reportRow['conversions'] : $reportRow['interactions']) @endforeach @php($postTotals = $postTotalsByName->get($postName)) @php($postResult = $isConversion ? (int) ($postTotals['conversions'] ?? 0) : (int) ($postTotals['interactions'] ?? 0)) @endforeach
Publication / Ad Campagne Spend {{ $resultLabel }}
{{ $postName }}
{{ $reportAd->ad_name ?: 'Sans nom' }} {{ \Illuminate\Support\Str::limit($reportAd->campaign_name ?: '—', 32) }} @include('integrations.meta.partials.spend-amount-pdf', [ 'amount' => $reportRow['spend'], 'usdToTndRate' => $usdToTndRate, ]) {{ number_format($resultValue, 0, ',', ' ') }}
Sous-total @include('integrations.meta.partials.spend-amount-pdf', [ 'amount' => (float) ($postTotals['spend'] ?? 0), 'usdToTndRate' => $usdToTndRate, ]) {{ number_format($postResult, 0, ',', ' ') }}
Total {{ $label }} @include('integrations.meta.partials.spend-amount-pdf', [ 'amount' => $objectiveData['totals']['spend'], 'usdToTndRate' => $usdToTndRate, 'mutedColor' => 'rgba(255,255,255,0.8)', 'textColor' => '#ffffff', ]) {{ number_format($objectiveData['totals']['results'], 0, ',', ' ') }}
@endif