HFC : fix par trajet rearrange ligne trajet

This commit is contained in:
narindraezway 2025-08-01 16:37:10 +03:00
parent 563d5bf2de
commit d8ff187d08
4 changed files with 87 additions and 21 deletions

View File

@ -181,5 +181,8 @@ return [
//invoice controller
['name' => 'invoice#sendInvoicePdfViaMail', 'url' => '/invoice/{factureId}/sendInvoicePdfViaMail', 'verb' => 'POST'],
['name' => 'invoice#getInvoicePdfContent', 'url' => '/invoice/{factureId}/getInvoicePdfContent', 'verb' => 'GET'],
['name' => 'page#updateDevisLigneTrajet', 'url' => '/updateDevisLigneTrajet', 'verb' => 'POST'],
]
];

View File

@ -3211,13 +3211,30 @@ class PageController extends Controller {
public function deleteUnusedLigneTrajet($idNextcloud ,$mois , $annee){
$dateOfMonths = DateHelpers::getDatesOfMonth($annee,$mois);
$thanato = $this->myDb->getThanatoByUserUuid($idNextcloud);
$trajet = $this->myDb->getTrajetByThanatoAndMonthYear($thanato['id'], $mois, $annee);
if($trajet == null){
return;
}
foreach($dateOfMonths as $currentDate){
$currentDateFormatted = $currentDate->format('Y-m-d');
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->myDb->thereIsThanatoDevisRattachedToLigneTrajetForADate($currentDateFormatted, $idNextcloud );
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->myDb->thereIsThanatoDevisRattachedToLigneTrajetForADate($currentDateFormatted, $trajet['id']);
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
$this->myDb->deleteThanatoLigneTrajetForADateWithoutDevis($currentDateFormatted, $idNextcloud );
$this->myDb->deleteThanatoLigneTrajetForADateWithoutDevisByTrajetId($currentDateFormatted, $trajet['id'] );
}else{
$devisRelatedToLigneTrajetButNotRelatedToCurrentThanato = $this->myDb->getLigneTrajetsWithDevisNotRelatedToThanato($currentDateFormatted,$thanato['id'],$trajet['id']);
if($devisRelatedToLigneTrajetButNotRelatedToCurrentThanato != null && count($devisRelatedToLigneTrajetButNotRelatedToCurrentThanato) > 0){
foreach($devisRelatedToLigneTrajetButNotRelatedToCurrentThanato as $currentLigneTrajet){
$this->myDb->gestion_delete('ligne_trajet', $currentLigneTrajet['id'], $idNextcloud);
}
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->myDb->thereIsThanatoDevisRattachedToLigneTrajetForADate($currentDateFormatted, $trajet['id']);
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
$this->myDb->deleteThanatoLigneTrajetForADateWithoutDevisByTrajetId($currentDateFormatted, $trajet['id'] );
}
}
}
}
}
}

View File

@ -1778,10 +1778,15 @@ class Bdd {
$oldThanato = $this->getThanatoByThanatoId($oldThanatoId);
// Supprimer les lignes trajet qui n' ont pas devis sur cette date
if($oldThanato != NULL) {
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->thereIsThanatoDevisRattachedToLigneTrajetForADate($updated_devis->date, $oldThanato['fk_user_uuid'] );
$month = explode('-', $updated_devis->date)[1];
$year = explode('-', $updated_devis->date)[0];
$trajet = $this->getTrajetByThanatoAndMonthYear($oldThanatoId,$month,$year);
if($trajet != NULL) {
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->thereIsThanatoDevisRattachedToLigneTrajetForADate($updated_devis->date, $trajet['id'] );
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
//delete all ligne trajet for this date
$this->deleteThanatoLigneTrajetForADate($devis->date, $oldThanato['fk_user_uuid'] );
$this->deleteThanatoLigneTrajetForADateByIdTrajet($devis->date, $trajet['id'] );
}
}
}
@ -5229,26 +5234,45 @@ COMMENTAIRES: ".$comment;
$this->execSQLNoData($sql, array($devisId));
}
public function thereIsThanatoDevisRattachedToLigneTrajetForADate($date,$idNextcloud){
$sql = "SELECT * FROM ".$this->tableprefix."ligne_trajet WHERE date = ? AND id_nextcloud = ? AND id_devis != 0 AND id_devis != NULL AND id_devis != ?;";
$ligneTrajet = $this->execSQLNoJsonReturn($sql, array($date,$idNextcloud,"-"));
public function thereIsThanatoDevisRattachedToLigneTrajetForADate($date,$trajetId){
$sql = "
SELECT ligne_trajet.*
FROM ".$this->tableprefix."ligne_trajet as ligne_trajet
WHERE ligne_trajet.date = ? AND ligne_trajet.id_devis != 0 AND ligne_trajet.id_devis IS NOT NULL AND ligne_trajet.id_devis != ?
AND ligne_trajet.id_trajet = ?;";
$ligneTrajet = $this->execSQLNoJsonReturn($sql, array($date,"-",$trajetId));
if(!empty($ligneTrajet)){
return true;
}
return false;
}
public function getLigneTrajetsWithDevisNotRelatedToThanato($date,$idThanato,$trajetId){
$sql = "
SELECT ligne_trajet.id as id FROM ".$this->tableprefix."ligne_trajet as ligne_trajet
LEFT JOIN ".$this->tableprefix."devis as devis ON devis.id = ligne_trajet.id_devis
WHERE ligne_trajet.date = ? AND ligne_trajet.id_devis != 0 AND ligne_trajet.id_devis IS NOT NULL AND ligne_trajet.id_devis != ?
AND ligne_trajet.id_trajet = ?
AND devis.id_thanato != ?;
";
$ligneTrajets = $this->execSQLNoJsonReturn($sql, array($date,"-",$trajetId,$idThanato));
if(!empty($ligneTrajets)){
return $ligneTrajets;
}
return [];
}
public function deleteThanatoLigneTrajetForADate($date,$thanatoUserUuid){
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE date = ? AND id_nextcloud = ?;";
$this->execSQLNoData($sql, array($date,$thanatoUserUuid));
}
public function deleteThanatoLigneTrajetForADateByIdTrajet($date,$idTrajet){
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE date = ? AND id_trajet = ?;";
$this->execSQLNoData($sql, array($date,$idTrajet));
}
public function getThanatoByUserUuid($userUuid){
$sql = "SELECT *
FROM ".$this->tableprefix."thanato as thanato
LEFT JOIN ".$this->tableprefix."thanato_type as thanato_type
ON thanato.fk_thanato_type_key = thanato_type.thanato_type_key
WHERE thanato.fk_user_uuid = ?";
$sql = "SELECT * FROM ".$this->tableprefix."thanato as thanato WHERE thanato.fk_user_uuid = ?";
$res = $this->execSQLNoJsonReturn($sql,array($userUuid));
if($res){
return $res[0];
@ -5280,7 +5304,21 @@ COMMENTAIRES: ".$comment;
}
public function deleteThanatoLigneTrajetForADateWithoutDevis($date,$thanatoUserUuid){
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE date = ? AND id_nextcloud = ? AND id_devis = NULL;";
$this->execSQLNoData($sql, array($date,$thanatoUserUuid));
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE date = ? AND id_nextcloud = ? AND (id_devis = NULL or id_devis = 0 or id_devis = ?) ;";
$this->execSQLNoData($sql, array($date,$thanatoUserUuid,"-"));
}
public function deleteThanatoLigneTrajetForADateWithoutDevisByTrajetId($date,$trajetId){
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE date = ? AND id_trajet = ? AND (id_devis = NULL or id_devis = 0 or id_devis = ?) ;";
$this->execSQLNoData($sql, array($date,$trajetId,"-"));
}
public function getTrajetByThanatoAndMonthYear($thanatoId, $month, $year){
$sql = "SELECT * FROM ".$this->tableprefix."trajet WHERE mois = ? AND annee = ? AND id_thanato = ?;";
$result = $this->execSQLNoJsonReturn($sql, array($month, $year, $thanatoId));
if(!empty($result)){
return $result[0];
}
return null;
}
}

View File

@ -289,10 +289,18 @@ class GestionService
//delete ligne trajet from old devis
$this->gestionBdd->deleteLigneTrajetByDevisId($devis['id']);
//delete from home and to home trajet if there is no devis at all for this date
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->gestionBdd->thereIsThanatoDevisRattachedToLigneTrajetForADate($devis['date'], $oldThanatoUserUuid );
$month = explode('-', $devis['date'])[1];
$year = explode('-', $devis['date'])[0];
$oldThanatoTrajet = $this->gestionBdd->getTrajetByThanatoAndMonthYear(
$devis['id_thanato'],
$month,
$year
);
if($oldThanatoTrajet != null){
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->gestionBdd->thereIsThanatoDevisRattachedToLigneTrajetForADate($devis['date'], $oldThanatoTrajet['id'] );
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
//delete all ligne trajet for this date
$this->gestionBdd->deleteThanatoLigneTrajetForADate($devis['date'], $oldThanatoUserUuid );
$this->gestionBdd->deleteThanatoLigneTrajetForADateByIdTrajet($devis['date'], $oldThanatoTrajet['id'] );
}
}
$this->gestionBdd->updateDevisThanato($devis['id'], $thanato['id']);
$this->gestionBdd->reArrangeLigneTrajetyByDevisId($devis['id'], $userPrincipalName);