This commit is contained in:
Narindra ezway 2025-04-07 18:06:46 +03:00
parent 26d0ecaa70
commit 3a7c6d0610
2 changed files with 190 additions and 39 deletions

View File

@ -230,6 +230,25 @@ class Bdd {
return $this->execSQL($sql, array($numtrajet));
}
public function getTrajetsDetailsByDateAndSource($numtrajet,$date,$source=null){
$sql = "SELECT ligne_trajet.id, ligne_trajet.rang, ligne_trajet.id_nextcloud, ligne_trajet.date, ligne_trajet.user_id, ligne_trajet.commentaire, ligne_trajet.source,
lieu.id as lid, lieu.nom as lieu, lieu.latitude as latitude, lieu.longitude as longitude,
client.nom as cnom, client.id as cid, client.prenom as cprenoms
FROM (".$this->tableprefix."ligne_trajet as ligne_trajet
LEFT JOIN ".$this->tableprefix."lieu as lieu on ligne_trajet.id_lieu = lieu.id
LEFT JOIN ".$this->tableprefix."client as client on ligne_trajet.id_client = client.id)
WHERE ligne_trajet.id_trajet = ? AND
ligne_trajet.date = ?";
$conditions = [$numtrajet,$date];
if($source != null){
$sql .= " AND ligne_trajet.source = ?";
$conditions[] = $source;
}
$sql .= " ORDER BY ligne_trajet.rang ASC;";
return $this->execSQL($sql, $conditions);
}
public function getTrajetsdetails_orderByDate($numtrajet, $idNextcloud) {
$sql = "SELECT ligne_trajet.id, ligne_trajet.rang, ligne_trajet.id_nextcloud, ligne_trajet.date, ligne_trajet.user_id, ligne_trajet.commentaire, ligne_trajet.source,
lieu.id as lid, lieu.nom as lieu, lieu.latitude as latitude, lieu.longitude as longitude,
@ -586,7 +605,7 @@ class Bdd {
public function getOneDevis($numdevis,$idNextcloud){
$sql = "SELECT ".$this->tableprefix."devis.id as devisid, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.comment, ".$this->tableprefix."devis.date, num,"
.$this->tableprefix."devis.id_nextcloud as didnextcloud,".$this->tableprefix."devis.id_client, id_lieu, id_thanato,"
.$this->tableprefix."devis.id_nextcloud as didnextcloud,".$this->tableprefix."devis.id_client, id_lieu, id_thanato, go_to_siege, "
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
.$this->tableprefix."client.id as clientid, ".$this->tableprefix."client.nom, "
.$this->tableprefix."client.prenom, legal_one, entreprise, telephone, mail, ".$this->tableprefix."client.adresse,"
@ -825,7 +844,7 @@ class Bdd {
return true;
}
public function insertTrajetdetails_h2f($numtrajet, $date, $idNextcloud){
public function insertTrajetDetails_h2f($numtrajet, $date, $idNextcloud ,$devisId = 0 ){
$last=0;
$last = $this->lastinsertid("ligne_trajet", $idNextcloud) + 1;
@ -851,8 +870,8 @@ class Bdd {
`source`,
`user_id`
)
VALUES (?,?,0,?,?,?,'','h2f',?);";
$this->execSQLNoData($sql, array($idNextcloud,$date,$id_h2f,$numtrajet,$rang+1,$last));
VALUES (?,?,?,?,?,?,'','h2f',?);";
$this->execSQLNoData($sql, array($idNextcloud,$date,$devisId , $id_h2f,$numtrajet,$rang+1,$last));
return true;
}
@ -1273,57 +1292,187 @@ class Bdd {
$this->insertTrajet($devis->id_thanato, $date_devis_split[1], $date_devis_split[0], $idNextcloud);
$trajet = json_decode($this->getOneTrajet_byThanatoMonthYear($devis->id_thanato, $date_devis_split[1], $date_devis_split[0]))[0];
}
$devis->go_to_siege =true ;
$this->insertTrajetdetails_byDevis($trajet->id, $devis, $idNextcloud);
if($devis->go_to_siege){
$hasDepartH2f = $this->check_has_depart_h2f($devis->date,$trajet->id);
if(!$hasDepartH2f) {
$this->insertTrajetDetails_h2f($trajet->id, $devis->date, $idNextcloud);
}
$hasAlreadyReturnToSiege = $this->check_if_return_to_siege_already_exist( $devis->date , $trajet->id , $devis->devisid);
if(!$hasAlreadyReturnToSiege) {
$this->insertTrajetDetails_h2f($trajet->id, $devis->date, $idNextcloud ,$devis->devisid);
}
}
}
public function check_if_return_to_siege_already_exist($date,$trajetId ,$devisId) {
$sql = "SELECT COUNT(*) AS LIGNE_COUNT FROM `".$this->tableprefix."ligne_trajet` WHERE id_trajet = ? AND date = ? AND id_devis = ? AND source = ?;";
$response = $this->execSQL($sql, array($trajetId,$date, $devisId, 'h2f'));
$response = json_decode($response)[0];
if($response->LIGNE_COUNT > 0) {
return true;
} else {
return false;
}
}
public function check_has_depart_h2f($date,$trajetId) {
$sql = "SELECT COUNT(*) AS LIGNE_COUNT FROM `".$this->tableprefix."ligne_trajet` WHERE id_trajet = ? AND date = ? AND source = ?;";
$response = $this->execSQL($sql, array($trajetId,$date,'h2f'));
$response = json_decode($response)[0];
if($response->LIGNE_COUNT > 0 ) {
return true;
} else {
return false;
}
}
public function insertTrajetGoHome($date,$trajetId , $idNextcloud) {
/** Ceci est un nouveau concept. Après tout ce temps, nous devons préciser la date d'application de la nouvelle demande. pour la go to thanatho */
$dateTime = new DateTime($date);
$dateTimeForFunctionalityGoToHome = new DateTime('2025-04-07');
if ( $dateTime <= $dateTimeForFunctionalityGoToHome) {
return;
}
$last = 0;
$last = $this->lastinsertid("ligne_trajet", $idNextcloud) + 1;
$rang = $this->get_last_rang_trajetdetails($trajetId, $idNextcloud);
$sqlLocation = "SELECT * FROM ".$this->tableprefix."lieu WHERE LOWER(".$this->tableprefix."lieu.nom) LIKE ?;";
$responseLocation = $this->execSQL($sqlLocation, array(strtolower($idNextcloud)));
$responseLocation = json_decode($responseLocation)[0];
$lieuId = $responseLocation != null ? $responseLocation->id : 0;
$sql = "INSERT INTO `".$this->tableprefix."ligne_trajet` ( `id_nextcloud`,
`date`,
`id_devis`,
`id_client`,
`id_lieu`,
`id_trajet`,
`rang`,
`commentaire`,
`source`,
`user_id`
)
VALUES (?,?,?,?,?,?,?,'',?,?);";
$this->execSQLNoData($sql, array($idNextcloud,$date,0 ,0,$lieuId,$trajetId,$rang+1,$idNextcloud,$last));
}
public function range_ligneTrajetV2($id_trajet, $idNextcloud) {
}
/**
* ranger les lignes de trajet dans un trajet par date et par rang
* inserer ligne siege au debut et fin de chaque journee s'il n'existe pas
*/
public function range_ligneTrajet($id_trajet, $idNextcloud) {
$lignes = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud));
$nb_jour = 0;
$datesLignes = [];
$lastRangOfTrajetPossible = 200;
if(sizeof($lignes)>0) {
$nb_jour = 1;
$dates = array(0=>$lignes[0]->date);
$date_temp = $lignes[0]->date;
foreach ($lignes as $key => $ligne) {
if(strcmp($date_temp, $ligne->date)!=0) {
$date_temp = $ligne->date;
array_push($dates, $date_temp);
$nb_jour++;
}
}
// on verifie si le nombre de ligne h2f correspond à 2*nb_jour (debut et fin de journee)
$reste = (2*$nb_jour) - (sizeof(array_filter($lignes, function($ligne) {return strcmp($ligne->source,'h2f')==0;})));
while ($reste>0) {
$this->insertTrajetdetails_h2f($id_trajet, $lignes[0]->date, $idNextcloud);
$reste--;
}
$current_lines = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud));
// ici le nombre de ligne h2f est egale au nb_jour*2
$array_siege = array();
foreach ($current_lines as $key => $ligne) {
if(strcmp($ligne->source,'h2f')==0) array_push($array_siege, $ligne);
$datesLignes[$ligne->date][] = $ligne;
}
$j=0;
for ($i=0; $i < sizeof($dates); $i++) {
$this->update_ligneTrajet('ligne_trajet', 'rang', 0, $array_siege[$j]->id, $idNextcloud);
$this->update_ligneTrajet('ligne_trajet', 'date', $dates[$i], $array_siege[$j]->id, $idNextcloud);
$this->update_ligneTrajet('ligne_trajet', 'rang', sizeof($current_lines)+1, $array_siege[$j+1]->id, $idNextcloud);
$this->update_ligneTrajet('ligne_trajet', 'date', $dates[$i], $array_siege[$j+1]->id, $idNextcloud);
$j+=2;
foreach($datesLignes as $date => $currentDateLignes){
$dateTime = new DateTime($date);
$dateTimeForFunctionalityGoToHome = new DateTime('2025-04-07');
if ( $dateTime <= $dateTimeForFunctionalityGoToHome) {
$reste = 2 - (sizeof(array_filter($currentDateLignes, function($ligne) {return strcmp($ligne->source,'h2f')==0;})));
while ($reste > 0) {
$this->insertTrajetDetails_h2f($id_trajet, $date, $idNextcloud);
$reste--;
}
$currentDateLignesUpdated = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date, 'h2f'));
$ordered_lines = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date));
for ($i= 0; $i < 2; $i++) {
if($i== 0) {
$this->update_ligneTrajet('ligne_trajet', 'rang', 0, $currentDateLignesUpdated[$i]->id, $idNextcloud);
} else {
$this->update_ligneTrajet('ligne_trajet', 'rang', $lastRangOfTrajetPossible, $currentDateLignesUpdated[$i]->id, $idNextcloud);
}
}
}else{
//Nouvelle fonctionnalité
$resteH2f = 1 - (sizeof(array_filter($currentDateLignes, function($ligne) {return strcmp($ligne->source,'h2f')==0;})));
if ($resteH2f > 0 ) {
$this->insertTrajetDetails_h2f($id_trajet, $date, $idNextcloud);
}
$resteGoHome = 1 - (sizeof(array_filter($currentDateLignes, function($ligne ) use ($idNextcloud) {return strcmp($ligne->source, $idNextcloud)==0;})));
if ($resteGoHome > 0 ) {
$this->insertTrajetGoHome($date ,$id_trajet,$idNextcloud);
}
$h2fLinge = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date, 'h2f'));
$ligneGoHome = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date, $idNextcloud));
$ordered_lines = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date));
$this->update_ligneTrajet('ligne_trajet', 'rang', 0, $h2fLinge[0]->id, $idNextcloud);
$this->update_ligneTrajet('ligne_trajet', 'rang', $lastRangOfTrajetPossible, $ligneGoHome[0]->id, $idNextcloud);
}
$ordered_lines = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date));
foreach ($ordered_lines as $key => $line) {
$this->update_ligneTrajet('ligne_trajet', 'rang', $key+1, $line->id, $idNextcloud);
}
}
$ordered_lines = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud));
foreach ($ordered_lines as $key => $line) {
$this->update_ligneTrajet('ligne_trajet', 'rang', $key+1, $line->id, $idNextcloud);
}
// on verifie si le nombre de ligne h2f correspond à 2*nb_jour (debut et fin de journee)
// $reste = (2*$nb_jour) - (sizeof(array_filter($lignes, function($ligne) {return strcmp($ligne->source,'h2f')==0;})));
// while ($reste>0) {
// $this->insertTrajetDetails_h2f($id_trajet, $lignes[0]->date, $idNextcloud);
// $reste--;
// }
// $current_lines = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud));
// // ici le nombre de ligne h2f est egale au nb_jour*2
// $array_siege = array();
// $array_home = array();
// foreach ($current_lines as $key => $ligne) {
// if(strcmp($ligne->source,'h2f') == 0) {
// array_push($array_siege, $ligne);
// }else{
// if(strcmp($ligne->source, $idNextcloud ) == 0 ) {
// array_push($array_home, $ligne);
// }
// }
// }
// $j=0;
// for ($i=0; $i < sizeof($dates); $i++) {
// $this->update_ligneTrajet('ligne_trajet', 'rang', 0, $array_siege[$j]->id, $idNextcloud);
// $this->update_ligneTrajet('ligne_trajet', 'date', $dates[$i], $array_siege[$j]->id, $idNextcloud);
// $this->update_ligneTrajet('ligne_trajet', 'rang', sizeof($current_lines)+1, $array_siege[$j+1]->id, $idNextcloud);
// $this->update_ligneTrajet('ligne_trajet', 'date', $dates[$i], $array_siege[$j+1]->id, $idNextcloud);
// $j+=2;
// }
// $ordered_lines = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud));
// foreach ($ordered_lines as $key => $line) {
// $this->update_ligneTrajet('ligne_trajet', 'rang', $key+1, $line->id, $idNextcloud);
// }
}
}

View File

@ -0,0 +1,2 @@
ALTER TABLE oc_gestion_devis
ADD COLUMN go_to_siege BOOLEAN DEFAULT FALSE;