This commit is contained in:
2026-04-02 16:58:58 +02:00
parent eff1628115
commit 2882c682f0
3 changed files with 36 additions and 20 deletions
+20 -12
View File
@@ -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;
@@ -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
+10
View File
@@ -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;
<span style="color:#94a3b8; font-size:1.1rem; cursor:grab; user-select:none;">☰</span>
<div class="hol-cp-title" onclick="panMapTo(<?= $step['lat'] ?>, <?= $step['lng'] ?>)" title="<?= htmlspecialchars($step['location_name']) ?>">
📍 <?= htmlspecialchars($step['location_name']) ?>
<?php if (!empty($step['is_return'])): ?>
<span style="background: #fff7ed; color: #ea580c; padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: bold; margin-left: 5px; border: 1px solid #ffedd5; vertical-align: middle;">🏁 Retour</span>
<?php endif; ?>
<?php if (!empty($step['step_start_date']) && !empty($step['step_end_date'])): ?>
<div style="font-size:0.75rem; color:#64748b; font-weight:normal; margin-top:2px;">
Du <?= date('d/m', strtotime($step['step_start_date'])) ?> au <?= date('d/m', strtotime($step['step_end_date'])) ?>
@@ -252,6 +256,12 @@ $pctSaved = $cost > 0 ? min(100 - $pctPaid, ($saved / $cost) * 100) : 0;
<label class="pf-label">Départ le (Optionnel)</label>
<input type="date" name="step_end_date" id="cp_end_date" class="pf-input">
</div>
<div style="margin-bottom: 15px; padding-left: 5px;">
<label style="display:flex; align-items:center; cursor:pointer; font-size:0.9rem; color:#d97706; font-weight:600;">
<input type="checkbox" name="is_return" id="cp_is_return" value="1" style="margin-right:8px; width:16px; height:16px;">
🏁 Trajet retour
</label>
</div>
</div>
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:10px;">