@php
$activeFiscaliteValue = null;
$activeFiscaliteLabel = null;
foreach ($tabs as $index => $tab) {
$paneId = $tab['pane_id'] ?? null;
if (! $paneId || $paneId !== $activePaneId) {
continue;
}
$result = $tab['result'] ?? [];
$activeFiscaliteValue = $result['fiscalites'][$index]['value'] ?? ($result['fiscalite_utilisee']['value'] ?? null);
if (! $activeFiscaliteValue && ($result['sans_fiscalite'] ?? false)) {
$activeFiscaliteValue = 'sans_fiscalite';
}
$activeFiscaliteLabel = $tab['tab_label'] ?? ('Fiscalité '.($index + 1));
break;
}
if ($activeFiscaliteLabel === null) {
$activeFiscaliteLabel = 'Fiscalité';
}
@endphp
@foreach ($tabs as $tab)
@php
$paneId = $tab['pane_id'];
$isActive = $paneId === $activePaneId;
$result = $tab['result'] ?? [];
$note = $result['note'] ?? null;
$total = (float) ($result['total'] ?? 0);
$lignes = is_array($result['lignes'] ?? null) ? $result['lignes'] : [];
$financement = is_array($result['financement'] ?? null) ? $result['financement'] : [];
// Masquer les lignes "Prix des annexes" si (inclus + non inclus) = 0
$annexesNonInclus = 0.0;
$annexesInclus = 0.0;
foreach ($lignes as $ligne) {
$code = (string) ($ligne['code'] ?? '');
if ($code === 'annexes_ttc') {
$annexesNonInclus = (float) ($ligne['montant'] ?? 0);
} elseif ($code === 'annexes_ttc_inclus') {
$annexesInclus = (float) ($ligne['montant'] ?? 0);
}
}
$hideAnnexesSection = ($annexesNonInclus <= 0) && ($annexesInclus <= 0);
if ($hideAnnexesSection) {
$lignes = array_values(array_filter($lignes, function ($ligne): bool {
$code = (string) ($ligne['code'] ?? '');
return ! str_starts_with($code, 'annexes_');
}));
}
// Masquer les lignes annexes à 0 (non incluses / incluses)
$lignes = array_values(array_filter($lignes, function ($ligne): bool {
$code = (string) ($ligne['code'] ?? '');
if (! str_starts_with($code, 'annexes_')) {
return true;
}
return (float) ($ligne['montant'] ?? 0) > 0;
}));
$sections = [
'Prix immo' => [],
'Prix du foncier' => [],
'Prix des travaux' => [],
'Prix des annexes' => [],
'Autres' => [],
];
foreach ($lignes as $ligne) {
$code = (string) ($ligne['code'] ?? '');
if (str_starts_with($code, 'immo_')) {
$sections['Prix immo'][] = $ligne;
continue;
}
if (str_starts_with($code, 'foncier_')) {
$sections['Prix du foncier'][] = $ligne;
continue;
}
if (str_starts_with($code, 'travaux_')) {
$sections['Prix des travaux'][] = $ligne;
continue;
}
if (str_starts_with($code, 'annexes_')) {
$sections['Prix des annexes'][] = $ligne;
continue;
}
$sections['Autres'][] = $ligne;
}
$finLignes = is_array($financement['lignes'] ?? null) ? $financement['lignes'] : [];
$finAnnexesNonInclus = 0.0;
$finAnnexesInclus = 0.0;
foreach ($finLignes as $ligne) {
$code = (string) ($ligne['code'] ?? '');
if ($code === 'annexes_ttc') {
$finAnnexesNonInclus = (float) ($ligne['montant'] ?? 0);
} elseif ($code === 'annexes_ttc_inclus') {
$finAnnexesInclus = (float) ($ligne['montant'] ?? 0);
}
}
$hideFinAnnexesSection = ($finAnnexesNonInclus <= 0) && ($finAnnexesInclus <= 0);
if ($hideFinAnnexesSection) {
$finLignes = array_values(array_filter($finLignes, function ($ligne): bool {
$code = (string) ($ligne['code'] ?? '');
return ! str_starts_with($code, 'annexes_');
}));
}
// Masquer les lignes annexes à 0 (non incluses / incluses)
$finLignes = array_values(array_filter($finLignes, function ($ligne): bool {
$code = (string) ($ligne['code'] ?? '');
if (! str_starts_with($code, 'annexes_')) {
return true;
}
return (float) ($ligne['montant'] ?? 0) > 0;
}));
$finSections = [
'Prix du lot' => [],
'Prix du foncier' => [],
'Prix des annexes' => [],
'Frais' => [],
'Autres' => [],
];
foreach ($finLignes as $ligne) {
$code = (string) ($ligne['code'] ?? '');
if ($code === 'prix_vente_total') {
$finSections['Prix du lot'][] = $ligne;
continue;
}
if (str_starts_with($code, 'foncier_')) {
$finSections['Prix du foncier'][] = $ligne;
continue;
}
if (str_starts_with($code, 'annexes_')) {
$finSections['Prix des annexes'][] = $ligne;
continue;
}
if ($code === 'frais_notaire') {
$finSections['Frais'][] = $ligne;
continue;
}
$finSections['Autres'][] = $ligne;
}
@endphp
@endforeach