From 771113c66d865de8dd6f5ff89be4c16a9b9fa721 Mon Sep 17 00:00:00 2001 From: Tolotsoa Date: Thu, 22 Jan 2026 11:51:55 +0300 Subject: [PATCH] fix change get id_lieu --- gestion/lib/Controller/PageController.php | 55 ++++++++++++----------- gestion/lib/Db/Bdd.php | 5 ++- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index 36bcf17..5e51178 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -1744,44 +1744,55 @@ class PageController extends Controller $trajet = json_decode($this->myDb->getOneTrajet($numtrajet, $this->idNextcloud))[0]; $formatter_ds = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::NONE); - // Set the pattern for the formatter to "d-MMMM" to display the day and month name in French $formatter_ds->setPattern('dd-MMM'); - $monthName = $this->month_toString(intval($trajet->mois)); $fullnameThanato = (($trajet->nom_thanato != null) ? $trajet->nom_thanato : '').' '.(($trajet->prenom_thanato != null) ? $trajet->prenom_thanato : ''); - $_clean_folder = $clean_folder.'INDEMNITES KILOMETRIQUES/'.$trajet->annee.'/'.strtoupper($fullnameThanato).'/'; try { $this->storage->newFolder($_clean_folder); } catch(\OCP\Files\NotPermittedException $e) { } - - - $trajetdetails = json_decode($this->myDb->getTrajetsdetails_orderByDate($numtrajet, $idNextcloud)); + $trajetdetails = json_decode($this->myDb->getTrajetsdetails_orderByDate($numtrajet, $this->idNextcloud)); $distance_temp = 0; $distances = array(); $last_point = null; - $ik_temp = 'CLIENTS'.';'.'JOUR'.';'.'LIEU'.';'.'TOTAL'."\n"; - for ($i = 0; $i < sizeof($trajetdetails); $i++) { + + $total_rows = sizeof($trajetdetails); + + for ($i = 0; $i < $total_rows; $i++) { $date_temp = new DateTime($trajetdetails[$i]->date); - if(strcmp(explode('-', $trajetdetails[$i]->date)[2], explode('-', $trajetdetails[$i + 1]->date)[2]) != 0) { + + // Vérifier si c'est la dernière ligne OU si le jour change + $is_last_row = ($i == $total_rows - 1); + $day_changes = !$is_last_row && (strcmp(explode('-', $trajetdetails[$i]->date)[2], explode('-', $trajetdetails[$i + 1]->date)[2]) != 0); + + if($is_last_row || $day_changes) { + // Calculer la distance du retour pour la dernière ligne du jour + if($last_point != null && $last_point->lid != null && $trajetdetails[$i]->lid != null) { + $currentDistance = $this->myDb->calcul_distance(floatval($last_point->latitude), floatval($last_point->longitude), floatval($trajetdetails[$i]->latitude), floatval($trajetdetails[$i]->longitude)); + $distance_temp += $currentDistance; + } + + // Dernière ligne du jour : afficher le total cumulé array_push($distances, $distance_temp); - $ik_temp = $ik_temp.utf8_decode(html_entity_decode($trajetdetails[$i]->cprenoms.' '.$trajetdetails[$i]->cnom)).';'.utf8_decode($formatter_ds->format($date_temp)).';'.utf8_decode(html_entity_decode($trajetdetails[$i]->lieu)).';'.$distance_temp."\n"; + $ik_temp .= utf8_decode(html_entity_decode($trajetdetails[$i]->cprenoms.' '.$trajetdetails[$i]->cnom)).';'.utf8_decode($formatter_ds->format($date_temp)).';'.utf8_decode(html_entity_decode($trajetdetails[$i]->lieu)).';'.$distance_temp."\n"; $distance_temp = 0; $last_point = null; } else { + // Calculer la distance depuis last_point vers le point COURANT $currentDistance = 0; + if($last_point != null && $last_point->lid != null && $trajetdetails[$i]->lid != null) { + $currentDistance = $this->myDb->calcul_distance(floatval($last_point->latitude), floatval($last_point->longitude), floatval($trajetdetails[$i]->latitude), floatval($trajetdetails[$i]->longitude)); + $distance_temp += $currentDistance; + } + + // Mettre à jour last_point avec le point actuel if($trajetdetails[$i]->lid != null) { $last_point = $trajetdetails[$i]; } - if($last_point->lid != null && $trajetdetails[$i + 1]->lid != null) { - - $currentDistance = $this->myDb->calcul_distance(floatval($last_point->latitude), floatval($last_point->longitude), floatval($trajetdetails[$i + 1]->latitude), floatval($trajetdetails[$i + 1]->longitude)); - $distance_temp += $currentDistance; - } - $ik_temp = $ik_temp.utf8_decode(html_entity_decode($trajetdetails[$i]->cprenoms.' '.$trajetdetails[$i]->cnom)).';'.utf8_decode($formatter_ds->format($date_temp)).';'.utf8_decode(html_entity_decode($trajetdetails[$i]->lieu)).';'.$currentDistance."\n"; + $ik_temp .= utf8_decode(html_entity_decode($trajetdetails[$i]->cprenoms.' '.$trajetdetails[$i]->cnom)).';'.utf8_decode($formatter_ds->format($date_temp)).';'.utf8_decode(html_entity_decode($trajetdetails[$i]->lieu)).';'.$currentDistance."\n"; } } @@ -1790,23 +1801,17 @@ class PageController extends Controller foreach ($distances as $key => $valdistance) { $distance_final += $valdistance; } - - $ik_temp = $ik_temp."\n\n\n\n".''.';'.''.';'.'sous total'.';'.$distance_final; - + $ik_temp .= "\n\n\n\n".''.';'.''.';'.'sous total'.';'.$distance_final; $total_ik = $distance_final * floatval($current_config[0]->coefficient_ik); - $ik_temp = $ik_temp."\n\n".''.';'.'TOTAL'.';'.$current_config[0]->coefficient_ik.';'.$total_ik; - $ik_temp = $ik_temp."\n".''.';'.'ELECTRIQUE'.';'.''.';'.round($total_ik, 2); - + $ik_temp .= "\n\n".''.';'.'TOTAL'.';'.$current_config[0]->coefficient_ik.';'.$total_ik; + $ik_temp .= "\n".''.';'.'ELECTRIQUE'.';'.''.';'.round($total_ik, 2); $nom_thanato = html_entity_decode($trajet->nom_thanato).' '.html_entity_decode($trajet->prenom_thanato); $ff = $_clean_folder.'IK_'.$trajet->annee.'_'.$monthName.'_'.strtoupper($fullnameThanato).'_'.strtoupper($nom_thanato).'.csv'; $this->storage->newFile($ff); $file = $this->storage->get($ff); $file->putContent($ik_temp); - } catch(\OCP\Files\NotFoundException $e) { } - - return true; } diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index da196de..6bf0271 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -1197,8 +1197,9 @@ class Bdd $trajetdetails = json_decode($this->getTrajetsdetails_orderByDate($numtrajet, $idNextcloud)); - $sql_h2f = "SELECT * FROM ".$this->tableprefix."lieu WHERE LOWER(".$this->tableprefix."lieu.nom) = ?"; - $response_h2f = $this->execSQL($sql_h2f, array($lieuSiege)); + $sql_h2f = "SELECT * FROM ".$this->tableprefix."lieu WHERE LOWER(nom) LIKE ? LIMIT 1"; + $response_h2f = $this->execSQL($sql_h2f, array('%' . strtolower($lieuSiege) . '%')); + $h2f = json_decode($response_h2f)[0]; $id_h2f = ($h2f != null) ? $h2f->id : 0;