diff --git a/modules/holidays/holidays.js b/modules/holidays/holidays.js index 0147e26..0651145 100644 --- a/modules/holidays/holidays.js +++ b/modules/holidays/holidays.js @@ -331,25 +331,31 @@ function initDetailMap() { routePromises.push(promise); } - // 2. On attend que TOUTES les routes soient calculées pour les dessiner dans le bon ordre + // 2. On attend que TOUTES les routes soient calculées Promise.all(routePromises).then((results) => { - // On s'assure de dessiner l'Étape 1 d'abord, puis la 2, etc. results.sort((a, b) => a.index - b.index); + // NOUVEAU : On cherche quelle étape a été marquée "Retour" + let returnStartIndex = latlngs.length - 2; // Par défaut : le tout dernier segment + const customReturnStep = MAP_POINTS.findIndex((p) => p.is_return == 1); + if (customReturnStep > 0) { + // Si trouvé (et que ce n'est pas le point de départ) + returnStartIndex = customReturnStep; + } + results.forEach((res) => { const i = res.index; - // Styles par défaut (Aller / Étape 1) - let routeColor = "#3b82f6"; // Bleu - let routeWeight = 6; // Épais - let routeDash = null; // Ligne continue + let routeColor = "#3b82f6"; // Bleu (Aller) + let routeWeight = 6; + let routeDash = null; - // Modification des styles selon le segment - if (i === latlngs.length - 2) { - // DERNIER SEGMENT (Retour) - routeColor = "#f97316"; // Orange vif (Tranche parfaitement avec le bleu) - routeWeight = 3; // Plus fin pour se superposer sans cacher - routeDash = "10, 10"; // En pointillés pour laisser voir le bleu en dessous + // Application de la bonne couleur + if (i >= returnStartIndex) { + // TOUS LES SEGMENTS DEPUIS L'ÉTAPE "RETOUR" + routeColor = "#f97316"; // Orange + routeWeight = 3; + routeDash = "10, 10"; } else if (i > 0) { // SEGMENTS INTERMÉDIAIRES routeColor = "#8b5cf6"; // Violet @@ -420,6 +426,7 @@ function openCheckpointModal(mode, data = null) { document.getElementById("cp_old_sort_order").value = ""; document.getElementById("cp_name").value = ""; addCpExpenseLine(); + document.getElementById("cp_is_return").checked = false; } else if (mode === "edit" && data) { document.getElementById("cpModalTitle").innerText = "✏️ Modifier l'étape"; searchBlock.style.display = "none"; @@ -432,6 +439,7 @@ function openCheckpointModal(mode, data = null) { document.getElementById("cp_name").value = data.location_name; document.getElementById("cp_start_date").value = data.step_start_date || ""; document.getElementById("cp_end_date").value = data.step_end_date || ""; + document.getElementById("cp_is_return").checked = data.is_return == 1; if (data.items && data.items.length > 0) { let visibleCount = 0; diff --git a/modules/holidays/includes/api/save_checkpoint.php b/modules/holidays/includes/api/save_checkpoint.php index 89dcea0..667adae 100644 --- a/modules/holidays/includes/api/save_checkpoint.php +++ b/modules/holidays/includes/api/save_checkpoint.php @@ -56,10 +56,10 @@ if ($holiday_id > 0 && !empty($location_name)) { // Récupération des dates de l'étape globale $step_start = !empty($_POST['step_start_date']) ? $_POST['step_start_date'] : null; $step_end = !empty($_POST['step_end_date']) ? $_POST['step_end_date'] : null; + $is_return = isset($_POST['is_return']) ? 1 : 0; // NOUVEAU - // 3. INSERTION DES LIGNES - // Il doit y avoir EXACTEMENT 15 colonnes et 15 points d'interrogation (?) - $stmt = $pdo->prepare("INSERT INTO pf_holidays_items (holiday_id, category, name, amount, is_paid, location_name, lat, lng, sort_order, notes, item_date, item_time, step_start_date, step_end_date, duration) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + // 3. INSERTION DES LIGNES (16 Colonnes) + $stmt = $pdo->prepare("INSERT INTO pf_holidays_items (holiday_id, category, name, amount, is_paid, location_name, lat, lng, sort_order, notes, item_date, item_time, step_start_date, step_end_date, duration, is_return) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $validItemsCount = 0; if (isset($_POST['items']['name'])) { @@ -72,21 +72,19 @@ if ($holiday_id > 0 && !empty($location_name)) { $paid = (isset($_POST['items']['paid'][$i]) && (int)$_POST['items']['paid'][$i] === 1) ? 1 : 0; $note = trim($_POST['items']['notes'][$i] ?? ''); - // Récupération des données invisibles $date = !empty($_POST['items']['date'][$i]) ? $_POST['items']['date'][$i] : null; $time = !empty($_POST['items']['time'][$i]) ? $_POST['items']['time'][$i] : null; $dur = !empty($_POST['items']['duration'][$i]) ? (int)$_POST['items']['duration'][$i] : 1; - // Les 15 variables passées au tableau doivent correspondre aux 15 points d'interrogation - $stmt->execute([$holiday_id, $cat, $name ?: 'Dépense', $amount, $paid, $location_name, $lat, $lng, $target_order, $note, $date, $time, $step_start, $step_end, $dur]); + // Ajout de $is_return à la fin + $stmt->execute([$holiday_id, $cat, $name ?: 'Dépense', $amount, $paid, $location_name, $lat, $lng, $target_order, $note, $date, $time, $step_start, $step_end, $dur, $is_return]); $validItemsCount++; } } } - // Si l'étape est vide, on enregistre quand même ses dates if ($validItemsCount === 0) { - $stmt->execute([$holiday_id, 'activity', 'PF_TECHNICAL_POINT', 0, 1, $location_name, $lat, $lng, $target_order, '', null, null, $step_start, $step_end, 1]); + $stmt->execute([$holiday_id, 'activity', 'PF_TECHNICAL_POINT', 0, 1, $location_name, $lat, $lng, $target_order, '', null, null, $step_start, $step_end, 1, $is_return]); } // 4. GESTION DES FAVORIS diff --git a/modules/holidays/views/detail.php b/modules/holidays/views/detail.php index 9773f7a..f7fc3b1 100644 --- a/modules/holidays/views/detail.php +++ b/modules/holidays/views/detail.php @@ -40,6 +40,7 @@ foreach ($items as $it) { 'sort_order' => $it['sort_order'], 'step_start_date' => $it['step_start_date'], 'step_end_date' => $it['step_end_date'], + 'is_return' => (int)$it['is_return'], 'total_amount' => 0, 'items' => [] ]; @@ -151,6 +152,9 @@ $pctSaved = $cost > 0 ? min(100 - $pctPaid, ($saved / $cost) * 100) : 0; ☰