['TIO', 'NOEL', 'ROIS'], 'anniversary' => ['ANNIV', 'SANT'], ]; // Vue courante $currentView = strtolower($_GET['view'] ?? ($_SESSION['gift_view'] ?? 'nadal')); if (!isset($VIEWS[$currentView])) $currentView = 'nadal'; $_SESSION['gift_view'] = $currentView; $allowedOccasions = $VIEWS[$currentView]; // Logique spécifique : Adultes supplémentaires pour Anniversaires $extraAdults = ['Pauline', 'Papy JC', 'Mamy Caro']; $adultsByChildForAnniv = [ 'Pol' => array_merge($baseAdults, $extraAdults), 'Pep' => array_merge($baseAdults, $extraAdults), 'Elna' => $baseAdults, 'Bru' => $baseAdults, 'Guim' => $baseAdults, ]; // Labels & Icônes (Utilisation des clés de traduction pour l'affichage) $allOccasionLabels = [ 'TIO' => tr('gift_occ_tio'), 'NOEL' => tr('gift_occ_noel'), 'ROIS' => tr('gift_occ_rois'), 'ANNIV' => tr('gift_occ_anniv'), 'SANT' => tr('gift_occ_sant'), ]; $occasionIcons = [ 'TIO' => '/modules/gift-list/assets/img/tio.png', 'NOEL' => '/modules/gift-list/assets/img/santa.png', 'ROIS' => '/modules/gift-list/assets/img/reis.png', 'ANNIV' => '/modules/gift-list/assets/img/corona.png', 'SANT' => '/modules/gift-list/assets/img/sant.png', ]; $tableGifts = 'pf_gifts'; // --- 2. RÉCUPÉRATION DES DONNÉES --- $inMarks = implode(',', array_fill(0, count($allowedOccasions), '?')); $sql = "SELECT * FROM {$tableGifts} WHERE year = ? AND occasion IN ($inMarks) ORDER BY adult_name, child_name, occasion, created_at"; $stmt = $pdo->prepare($sql); $params = array_merge([$year], $allowedOccasions); $stmt->execute($params); $gifts = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: []; $byOccasion = []; foreach ($gifts as $gift) { $byOccasion[$gift['occasion']][$gift['child_name']][$gift['adult_name']][] = $gift; } $occasionsToShow = array_values(array_intersect(array_keys($allOccasionLabels), $allowedOccasions)); // --- 3. CALCUL TRICOUNT --- $people = $baseAdults; $adultsInDb = array_column($gifts, 'adult_name'); $payersInDb = array_column($gifts, 'payer_name'); $people = array_values(array_unique(array_merge($people, $adultsInDb, $payersInDb))); $people = array_filter($people); $matrix = []; foreach ($people as $p1) { foreach ($people as $p2) $matrix[$p1][$p2] = 0.0; } foreach ($gifts as $g) { $adult = $g['adult_name']; $payer = $g['payer_name'] ?? $g['adult_name']; $amt = (float)$g['amount']; if ($amt > 0 && $adult && $payer && $adult !== $payer) { if (isset($matrix[$adult][$payer])) { $matrix[$adult][$payer] += $amt; } } } $settlements = []; $countPeople = count($people); for ($i = 0; $i < $countPeople; $i++) { for ($j = $i + 1; $j < $countPeople; $j++) { $a = $people[$i]; $b = $people[$j]; $net = $matrix[$a][$b] - $matrix[$b][$a]; if ($net > 0.01) { $settlements[] = ['from' => $a, 'to' => $b, 'amount' => $net]; } elseif ($net < -0.01) { $settlements[] = ['from' => $b, 'to' => $a, 'amount' => -$net]; } } } // --- 4. DÉBUT DU RENDU HTML --- require __DIR__ . '/header.php'; ?>

( €)
()

prepare("SELECT adult_name, child_name, occasion, SUM(amount) AS total FROM {$tableGifts} WHERE year = ? AND occasion IN ($inMarks) GROUP BY adult_name, child_name, occasion ORDER BY adult_name, child_name, occasion"); $stmtSum->execute($params); $sums = $stmtSum->fetchAll(PDO::FETCH_ASSOC); ?>
Total

Tricount

0 ? 'cl-mtx-owe' : 'cl-mtx-empty'); $display = $isDiag || $val == 0 ? '—' : number_format($val, 0, ',', ' ') . ' €'; ?>

🔗