fix trajet hfc
This commit is contained in:
parent
d29b5ecad9
commit
563d5bf2de
@ -5,6 +5,7 @@ use \FPDF;
|
|||||||
use \Datetime;
|
use \Datetime;
|
||||||
use Exception;
|
use Exception;
|
||||||
use OCA\Gestion\Constants\DevisExportTypeConstant;
|
use OCA\Gestion\Constants\DevisExportTypeConstant;
|
||||||
|
use OCA\Gestion\Helpers\DateHelpers;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
defined("TAB1") or define("TAB1", "\t");
|
defined("TAB1") or define("TAB1", "\t");
|
||||||
@ -3164,4 +3165,59 @@ class PageController extends Controller {
|
|||||||
'logo' => $this->getLogo()
|
'logo' => $this->getLogo()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
* @param int $defuntId
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function updateDevisLigneTrajet($idNextcloud ,$mois , $annee){
|
||||||
|
//get all devis id from month and year
|
||||||
|
if(!$idNextcloud || !$mois || !$mois){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$idsNextcloud = explode(',', $idNextcloud);
|
||||||
|
foreach($idsNextcloud as $id){
|
||||||
|
$this->updateLigneTrajet($id, $mois, $annee);
|
||||||
|
}
|
||||||
|
return "update successfully";
|
||||||
|
|
||||||
|
}
|
||||||
|
public function updateLigneTrajet ($idNextcloud ,$mois , $annee){
|
||||||
|
$all_devis = $this->myDb->getAllDevisByMonthAndYear($idNextcloud,$mois,$annee);
|
||||||
|
|
||||||
|
foreach($all_devis as $devis){
|
||||||
|
|
||||||
|
$ligne_trajet = json_decode($this->myDb->getOneTrajetdetails_byIdDevis($devis['id'], $idNextcloud))[0];
|
||||||
|
|
||||||
|
|
||||||
|
if($ligne_trajet != NULL) {
|
||||||
|
$this->myDb->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud);
|
||||||
|
$ligne_trajet = NULL;
|
||||||
|
}
|
||||||
|
$devisObject = json_decode($this->myDb->getOneDevis($devis['id'], $idNextcloud))[0];
|
||||||
|
|
||||||
|
$this->myDb->generate_ligneTrajet($devisObject, $idNextcloud);
|
||||||
|
$ligne_trajet = json_decode( json: $this->myDb->getOneTrajetdetails_byIdDevis($devisObject->devisid, $idNextcloud))[0];
|
||||||
|
$this->myDb->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
||||||
|
$this->myDb->calculer_distance_trajet(numtrajet: $ligne_trajet->id_trajet, idNextcloud: $idNextcloud);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->deleteUnusedLigneTrajet($idNextcloud ,$mois , $annee);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteUnusedLigneTrajet($idNextcloud ,$mois , $annee){
|
||||||
|
$dateOfMonths = DateHelpers::getDatesOfMonth($annee,$mois);
|
||||||
|
|
||||||
|
foreach($dateOfMonths as $currentDate){
|
||||||
|
$currentDateFormatted = $currentDate->format('Y-m-d');
|
||||||
|
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->myDb->thereIsThanatoDevisRattachedToLigneTrajetForADate($currentDateFormatted, $idNextcloud );
|
||||||
|
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
|
||||||
|
$this->myDb->deleteThanatoLigneTrajetForADateWithoutDevis($currentDateFormatted, $idNextcloud );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1773,6 +1773,18 @@ class Bdd {
|
|||||||
|
|
||||||
if($ligne_trajet != NULL) {
|
if($ligne_trajet != NULL) {
|
||||||
$this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud);
|
$this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud);
|
||||||
|
|
||||||
|
$oldThanatoId = $devis->id_thanato;
|
||||||
|
$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'] );
|
||||||
|
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
|
||||||
|
//delete all ligne trajet for this date
|
||||||
|
$this->deleteThanatoLigneTrajetForADate($devis->date, $oldThanato['fk_user_uuid'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$this->generate_ligneTrajet($updated_devis, $idNextcloud);
|
$this->generate_ligneTrajet($updated_devis, $idNextcloud);
|
||||||
$ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($updated_devis->devisid, $idNextcloud))[0];
|
$ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($updated_devis->devisid, $idNextcloud))[0];
|
||||||
@ -1994,7 +2006,13 @@ class Bdd {
|
|||||||
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
||||||
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
||||||
|
|
||||||
} else {
|
}else if(strcmp($table, "trajet")==0) {
|
||||||
|
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE `id_trajet` = ?";
|
||||||
|
$this->execSQLNoData($sql, array($id));
|
||||||
|
$sql = "DELETE FROM ".$this->tableprefix.$table." WHERE `id` = ?";
|
||||||
|
$this->execSQLNoData($sql, array($id));
|
||||||
|
|
||||||
|
}else {
|
||||||
$sql = "DELETE FROM ".$this->tableprefix.$table." WHERE `id` = ?";
|
$sql = "DELETE FROM ".$this->tableprefix.$table." WHERE `id` = ?";
|
||||||
$this->execSQLNoData($sql, array($id));
|
$this->execSQLNoData($sql, array($id));
|
||||||
}
|
}
|
||||||
@ -5193,4 +5211,76 @@ COMMENTAIRES: ".$comment;
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThanatoByThanatoId($thanatoId){
|
||||||
|
$sql = "SELECT *
|
||||||
|
FROM ".$this->tableprefix."thanato as thanato
|
||||||
|
WHERE thanato.id = ?";
|
||||||
|
$res = $this->execSQLNoJsonReturn($sql,array($thanatoId));
|
||||||
|
if($res){
|
||||||
|
return $res[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteLigneTrajetByDevisId($devisId){
|
||||||
|
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE id_devis = ?;";
|
||||||
|
$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,"-"));
|
||||||
|
if(!empty($ligneTrajet)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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 = ?";
|
||||||
|
$res = $this->execSQLNoJsonReturn($sql,array($userUuid));
|
||||||
|
if($res){
|
||||||
|
return $res[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reArrangeLigneTrajetyByDevisId($devisId,$idNextcloud){
|
||||||
|
$ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($devisId, $idNextcloud))[0];
|
||||||
|
if($ligne_trajet != NULL) {
|
||||||
|
$this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud);
|
||||||
|
$ligne_trajet = NULL;
|
||||||
|
}
|
||||||
|
$devisObject = json_decode($this->getOneDevis($devisId, $idNextcloud))[0];
|
||||||
|
|
||||||
|
$this->generate_ligneTrajet($devisObject, $idNextcloud);
|
||||||
|
$ligne_trajet = json_decode( json: $this->getOneTrajetdetails_byIdDevis($devisObject->devisid, $idNextcloud))[0];
|
||||||
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
||||||
|
$this->calculer_distance_trajet(numtrajet: $ligne_trajet->id_trajet, idNextcloud: $idNextcloud);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllDevisByMonthAndYear($idNextcloud,$mois, $annee ){
|
||||||
|
$thanato = $this->getThanatoByUserUuid($idNextcloud);
|
||||||
|
if($thanato == null){
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
$sql = "SELECT * FROM {$this->tableprefix}devis WHERE MONTH(date) = ? AND YEAR(date) = ? AND id_thanato = ?;";
|
||||||
|
return $this->execSQLNoJsonReturn($sql,array( $mois , $annee, $thanato['id'] ));
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -280,11 +280,22 @@ class GestionService
|
|||||||
if ($devis != null) {
|
if ($devis != null) {
|
||||||
$userPrincipalName = $this->gestionBdd->getCalendarPrincipalNameByCalendarId($targetCalendarId);
|
$userPrincipalName = $this->gestionBdd->getCalendarPrincipalNameByCalendarId($targetCalendarId);
|
||||||
if ($userPrincipalName != null) {
|
if ($userPrincipalName != null) {
|
||||||
$thanatoId = $this->gestionBdd->getThanatoIdByUserUuid($userPrincipalName);
|
$thanato = $this->gestionBdd->getThanatoByUserUuid($userPrincipalName);
|
||||||
if ($thanatoId != null) {
|
if ($thanato != null) {
|
||||||
$thanatoHasBeenChanged = $thanatoId != $devis["id_thanato"];
|
$thanatoHasBeenChanged = $thanato['id'] != $devis["id_thanato"];
|
||||||
if ($thanatoHasBeenChanged) {
|
if ($thanatoHasBeenChanged) {
|
||||||
$this->gestionBdd->updateDevisThanato($devis['id'], $thanatoId);
|
$oldThanato = $this->gestionBdd->getThanatoByThanatoId($devis['id_thanato']);
|
||||||
|
$oldThanatoUserUuid = $oldThanato['fk_user_uuid'];
|
||||||
|
//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 );
|
||||||
|
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
|
||||||
|
//delete all ligne trajet for this date
|
||||||
|
$this->gestionBdd->deleteThanatoLigneTrajetForADate($devis['date'], $oldThanatoUserUuid );
|
||||||
|
}
|
||||||
|
$this->gestionBdd->updateDevisThanato($devis['id'], $thanato['id']);
|
||||||
|
$this->gestionBdd->reArrangeLigneTrajetyByDevisId($devis['id'], $userPrincipalName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user