From 54edb5ed585e57731af66a2d6934232c9a8e3016 Mon Sep 17 00:00:00 2001 From: "fefe.clochette" Date: Tue, 5 May 2026 19:17:42 +0200 Subject: [PATCH] gift revamp --- gift-list.php | 719 ++++++++++++++---------------- includes/lang/ca.php | 7 +- includes/lang/fr.php | 9 +- modules/gift-list/gift-list.css | 754 +++++++++----------------------- 4 files changed, 545 insertions(+), 944 deletions(-) diff --git a/gift-list.php b/gift-list.php index 81f95ee..7ec0637 100644 --- a/gift-list.php +++ b/gift-list.php @@ -4,37 +4,21 @@ require __DIR__ . '/includes/auth.php'; require_login('/login.php'); require __DIR__ . '/includes/db.php'; -require_once __DIR__ . '/includes/i18n.php'; // Toujours s'assurer que tr() est dispo +require_once __DIR__ . '/includes/i18n.php'; if (session_status() === PHP_SESSION_NONE) { session_start(); } // --- 1. CONFIGURATION & DONNÉES --- - $year = (int)date('Y'); $pageTitle = tr('gift_page_title'); $activePage = "gift-list"; $bodyClass = "pf-gift-list"; $pageCss = "/modules/gift-list/gift-list.css"; -// Personnes $baseAdults = ['Laia', 'Laura', 'Avi Iaia']; $children = ['Pol', 'Pep', 'Elna', 'Bru', 'Guim']; - -// Configuration des Vues -$VIEWS = [ - 'nadal' => ['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), @@ -43,7 +27,17 @@ $adultsByChildForAnniv = [ 'Guim' => $baseAdults, ]; -// Labels & Icônes (Utilisation des clés de traduction pour l'affichage) +$VIEWS = [ + 'nadal' => ['TIO', 'NOEL', 'ROIS'], + 'anniversary' => ['ANNIV', 'SANT'], +]; + +$currentView = strtolower($_GET['view'] ?? ($_SESSION['gift_view'] ?? 'nadal')); +if (!isset($VIEWS[$currentView])) $currentView = 'nadal'; +$_SESSION['gift_view'] = $currentView; + +$allowedOccasions = $VIEWS[$currentView]; + $allOccasionLabels = [ 'TIO' => tr('gift_occ_tio'), 'NOEL' => tr('gift_occ_noel'), @@ -60,30 +54,40 @@ $occasionIcons = [ '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"; +// Le tri SQL regroupe par Occasion, puis par Enfant, puis par Adulte +$sql = "SELECT * FROM pf_gifts WHERE year = ? AND occasion IN ($inMarks) ORDER BY occasion ASC, child_name ASC, adult_name ASC, created_at DESC"; $stmt = $pdo->prepare($sql); -$params = array_merge([$year], $allowedOccasions); -$stmt->execute($params); +$stmt->execute(array_merge([$year], $allowedOccasions)); $gifts = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: []; -$byOccasion = []; -foreach ($gifts as $gift) { - $byOccasion[$gift['occasion']][$gift['child_name']][$gift['adult_name']][] = $gift; +$dataByOccasion = []; +$adultsInView = []; + +foreach ($gifts as $g) { + $occ = $g['occasion']; + $child = $g['child_name']; + $adult = $g['adult_name']; + + // Groupement structuré : Occasion -> Enfant -> Cadeaux + $dataByOccasion[$occ][$child]['gifts'][] = $g; + + // Totaux pour les petites pills sous le nom de l'enfant + if (!isset($dataByOccasion[$occ][$child]['totals'][$adult])) { + $dataByOccasion[$occ][$child]['totals'][$adult] = 0; + } + $dataByOccasion[$occ][$child]['totals'][$adult] += (float)$g['amount']; + + $adultsInView[$adult] = true; } +$allAdultsList = array_keys($adultsInView); +sort($allAdultsList); $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))); +// --- 3. CALCUL TRICOUNT (Bilan financier global de la vue) --- +$people = array_values(array_unique(array_merge($baseAdults, array_column($gifts, 'adult_name'), array_column($gifts, 'payer_name')))); $people = array_filter($people); $matrix = []; @@ -97,9 +101,7 @@ foreach ($gifts as $g) { $amt = (float)$g['amount']; if ($amt > 0 && $adult && $payer && $adult !== $payer) { - if (isset($matrix[$adult][$payer])) { - $matrix[$adult][$payer] += $amt; - } + $matrix[$adult][$payer] += $amt; } } @@ -110,421 +112,368 @@ for ($i = 0; $i < $countPeople; $i++) { $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]; - } + 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'; ?>
-

+

-
-

+
+
🔍
+ + + +
+
-

+
+ +
-
-

+
+

-

+

-
- - [], 'totals' => []]; + $childGifts = $childData['gifts'] ?? []; + $childTotals = $childData['totals'] ?? []; + $adultsForChild = ($currentView === 'anniversary') ? ($adultsByChildForAnniv[$childName] ?? $baseAdults) : $baseAdults; + + // Sécurisation du JSON pour éviter l'erreur "openGiftModal is not defined" + $addBtnData = json_encode([ + 'child' => $childName, + 'occ' => $occCode, + 'adults' => array_values($adultsForChild) + ], JSON_HEX_APOS | JSON_HEX_QUOT); + ?> +
+
+

👦

+ +
- $lists = []; - $totals = []; - foreach ($adultsForChild as $adultName) { - $lists[$adultName] = $byOccasion[$occCode][$childName][$adultName] ?? []; - $totals[$adultName] = array_sum(array_column($lists[$adultName], 'amount')); - } - - $counts = array_map('count', $lists); - $maxRowsChild = !empty($counts) ? max($counts) : 0; - ?> - - - - - - - + +
+ $tot): ?> + + 👤 : + + +
+ - - - - - - - - - + + + +
+ - - - - - - - - - - - - - - - - - - -
- - -
-
- - + +

+ + +
+ +
+
+

+ + + 🔗 + +

+ +
+ 👤
-
- - -
-
- - - - - - -
- ( €) - - - - -
-
- - - () - -
- - - -
- -
+ +
+ +
+ +
+ -
-

- 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, ',', ' ') . ' €'; - ?> - - - - - -
-
- -

+
+

⚖️

+ -

+

-
    +
      -
    • +
    • + à + +
    -
-
-

-
- - - - - - +
+ +
+
+ - - - - - - + + - - -
- - 🔗 - - \
-
+ + + + + + + + + + + + + +
- - -