Merge branch 'staging-HFC' into production-hfc
This commit is contained in:
commit
8bfd45b80f
@ -181,5 +181,8 @@ return [
|
|||||||
//invoice controller
|
//invoice controller
|
||||||
['name' => 'invoice#sendInvoicePdfViaMail', 'url' => '/invoice/{factureId}/sendInvoicePdfViaMail', 'verb' => 'POST'],
|
['name' => 'invoice#sendInvoicePdfViaMail', 'url' => '/invoice/{factureId}/sendInvoicePdfViaMail', 'verb' => 'POST'],
|
||||||
['name' => 'invoice#getInvoicePdfContent', 'url' => '/invoice/{factureId}/getInvoicePdfContent', 'verb' => 'GET'],
|
['name' => 'invoice#getInvoicePdfContent', 'url' => '/invoice/{factureId}/getInvoicePdfContent', 'verb' => 'GET'],
|
||||||
|
|
||||||
|
|
||||||
|
['name' => 'page#updateDevisLigneTrajet', 'url' => '/updateDevisLigneTrajet', 'verb' => 'POST'],
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
@ -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,76 @@ 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);
|
||||||
|
$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, $trajet['id']);
|
||||||
|
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
|
||||||
|
$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'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1773,6 +1773,23 @@ 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) {
|
||||||
|
$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->deleteThanatoLigneTrajetForADateByIdTrajet($devis->date, $trajet['id'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$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 +2011,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 +5216,109 @@ 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,$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 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 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -280,11 +280,30 @@ 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
|
||||||
|
$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){
|
||||||
|
$this->gestionBdd->deleteThanatoLigneTrajetForADateByIdTrajet($devis['date'], $oldThanatoTrajet['id'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->gestionBdd->updateDevisThanato($devis['id'], $thanato['id']);
|
||||||
|
$this->gestionBdd->reArrangeLigneTrajetyByDevisId($devis['id'], $userPrincipalName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user