diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 62adb70..2ff2667 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -2,7 +2,7 @@ namespace OCA\Gestion\Db; -use \Datetime; +use Datetime; use OCA\Gestion\Helpers\MailHelpers; use OCP\IL10N; use OCP\IDBConnection; @@ -21,8 +21,8 @@ use OCA\Gestion\Constants\VCalendarPropertyConstant; use OCA\Gestion\Constants\ClientTemplateTypeConstant; use OCA\Gestion\Constants\MultipleFactureTypeConstant; -class Bdd { - +class Bdd +{ private String $charset = 'utf8mb4'; public const DEFAULT_CALENDAR_UUID_FOR_DEVIS = "not-related"; @@ -36,22 +36,23 @@ class Bdd { private $l; /** @var LoggerInterface */ - private $logger; + private $logger; - public function __construct(IDbConnection $db, IL10N $l, LoggerInterface $logger) { + public function __construct(IDbConnection $db, IL10N $l, LoggerInterface $logger) + { - $this->whiteColumn = array("date", "num", "id_client", "id_thanato", "entreprise", "nom", "prenom", "legal_one", "telephone", "mail", "adresse", "produit_id", - "quantite", "is_tva", "date_paiement", "type_paiement", "id_devis", "reference", "description", "prix_unitaire", "legal_two", "path", "tva_default", "coefficient_ik", - "mentions_default", "version", "mentions", "comment", "status_paiement", "devise", "auto_invoice_number", "changelog", "format", "comment", "user_id", + $this->whiteColumn = array("date", "num", "id_client", "id_thanato", "entreprise", "nom", "prenom", "legal_one", "telephone", "mail", "adresse", "produit_id", + "quantite", "is_tva", "date_paiement", "type_paiement", "id_devis", "reference", "description", "prix_unitaire", "legal_two", "path", "tva_default", "coefficient_ik", + "mentions_default", "version", "mentions", "comment", "status_paiement", "devise", "auto_invoice_number", "changelog", "format", "comment", "user_id", "facture_prefixe", "arrivee", "depart", "latitude", "longitude", "id_lieu", "rang", "mois", "annee", "id_trajet", "commentaire","source", "date_habilitation", "sexe", "observations_generales", "ref_pacemaker", "id_defunt", "article_id", "corpulence", "date_naissance", "heure_debut", "heure_fin", "rigidite", "lividite", "observations_corps", "acces", "acces_recherche", "acces_etat", "injection", "injection_diffusion", "injection_qte", "preinjection", "preinjection_qte", "coinjection", "coinjection_qte", "drainage", "drainage_qte", "drainage_etat", "ponction", "ponction_qte", "cavite", "cavite_qte", "desinfection", "lavage", - "rasage", "presentation_cosmetique", "presentation_sur", "hypodermiques", "hypodermiques_sur", "local", "local_sur", "contenu", + "rasage", "presentation_cosmetique", "presentation_sur", "hypodermiques", "hypodermiques_sur", "local", "local_sur", "contenu", "commentaire", "designation", "hypodermiques_text1", "hypodermiques_text2", "qte", "endroit", "fk_client_group_id","fk_produit_id","ht_amount","client_group_name", - "fk_client_group_facturation_id","group_facturation_name", + "fk_client_group_facturation_id","group_facturation_name", "fk_product_type_id", "portal_code","alarm_code","funeral_code", "product_brand","product_reference", @@ -69,7 +70,8 @@ class Bdd { $this->logger = $logger; } - public function getConfiguration($idNextcloud){ + public function getConfiguration($idNextcloud) + { $sql = "SELECT * FROM `".$this->tableprefix."configuration` WHERE id_nextcloud = ?"; return $this->execSQL($sql, array($idNextcloud)); @@ -121,24 +123,23 @@ class Bdd { } } - public function getClients($idNextcloud){ + public function getClients($idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."client;"; - $clients = $this->execSQLNoJsonReturn($sql,[]); - foreach($clients as &$client){ - if($client['fk_client_group_id'] == null){ + $clients = $this->execSQLNoJsonReturn($sql, []); + foreach($clients as &$client) { + if($client['fk_client_group_id'] == null) { $client['client_group_name'] = ''; - } - else{ + } else { $clientGroup = $this->getClientGroupById($client['fk_client_group_id']); $client['client_group_name'] = $clientGroup != null ? $clientGroup['client_group_name'] : ''; } - if($client['fk_client_group_facturation_id'] == null){ + if($client['fk_client_group_facturation_id'] == null) { $client['client_group_facturation_name'] = ''; - } - else{ + } else { $clientGroupFacturation = $this->getClientGroupFacturationById($client['fk_client_group_facturation_id']); $client['client_group_facturation_name'] = $clientGroupFacturation != null ? $clientGroupFacturation['group_facturation_name'] : ''; } @@ -146,40 +147,45 @@ class Bdd { return json_encode($clients); } - private function getClientGroupById($clientGroupId){ + private function getClientGroupById($clientGroupId) + { $sql = "SELECT * FROM ".$this->tableprefix."client_group as client_group WHERE client_group.id = ? ;"; $clientGroup = $this->execSQLNoJsonReturn($sql, array($clientGroupId)); - if(!empty($clientGroup)){ + if(!empty($clientGroup)) { return $clientGroup[0]; } return null; } - public function getClientsName(){ + public function getClientsName() + { $sql = "SELECT client.nom, client.prenom, client.id FROM ".$this->tableprefix."client as client ORDER BY client.id DESC"; return $this->execSQL($sql, array()); } - - public function getClient($id,$idNextcloud){ + + public function getClient($id, $idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."client WHERE id = ?"; return $this->execSQL($sql, array($id)); } - public function getClientbyiddevis($id, $idNextcloud){ + public function getClientbyiddevis($id, $idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."devis as d, ".$this->tableprefix."client as c WHERE d.id_client = c.id AND d.id = ?"; return $this->execSQL($sql, array($id)); } - public function getThanatopracteurs($idNextcloud){ + public function getThanatopracteurs($idNextcloud) + { $sql = "SELECT thanato.*, @@ -191,9 +197,10 @@ class Bdd { return $this->execSQL($sql, array()); } - public function getThanatoByIds(array $thanatoIds){ + public function getThanatoByIds(array $thanatoIds) + { - if(empty($thanatoIds)){ + if(empty($thanatoIds)) { return []; } @@ -206,20 +213,23 @@ class Bdd { FROM ".$this->tableprefix."thanato as thanato WHERE thanato.id IN ($sqlConditionsPlaceholder)"; $thanatoList = $this->execSQLNoJsonReturn( - $sql, - $thanatoIds); + $sql, + $thanatoIds + ); return $thanatoList; } - public function getBibliotheques($idNextcloud) { + public function getBibliotheques($idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."bibliotheque;"; return $this->execSQL($sql, array()); } - public function getTrajets($idNextcloud) { + public function getTrajets($idNextcloud) + { // $sql_delete = "DELETE FROM ".$this->tableprefix."ligne_trajet"; // $this->execSQL($sql_delete, array()); @@ -233,7 +243,8 @@ class Bdd { return $this->execSQL($sql, array()); } - public function getTrajetById($numtrajet, $idNextcloud) { + public function getTrajetById($numtrajet, $idNextcloud) + { $sql = "SELECT trajet.id, trajet.mois, trajet.annee, trajet.distance, trajet.id_nextcloud, trajet.user_id, thanato.id as id_thanato, thanato.nom as nom_thanato, thanato.prenom as prenom_thanato @@ -243,7 +254,8 @@ class Bdd { return $this->execSQL($sql, array($numtrajet)); } - public function getTrajetsdetails($numtrajet, $idNextcloud) { + public function getTrajetsdetails($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, @@ -260,7 +272,8 @@ class Bdd { return $this->execSQL($sql, array($numtrajet)); } - public function getTrajetsdetails_orderByDate($numtrajet, $idNextcloud) { + 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, @@ -273,25 +286,29 @@ class Bdd { return $this->execSQL($sql, array($numtrajet)); } - public function getOneTrajetdetails($id, $idNextcloud) { + public function getOneTrajetdetails($id, $idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."ligne_trajet WHERE ".$this->tableprefix."ligne_trajet.id = ?;"; return $this->execSQL($sql, array($id)); } - public function getOneTrajetdetails_byIdDevis($id_devis, $idNextcloud) { + public function getOneTrajetdetails_byIdDevis($id_devis, $idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."ligne_trajet WHERE ".$this->tableprefix."ligne_trajet.id_devis = ? AND ".$this->tableprefix."ligne_trajet.source LIKE 'devis';"; return $this->execSQL($sql, array($id_devis)); } - public function getOneTrajetdetails_byRang($id_trajet, $rang, $idNextcloud) { + public function getOneTrajetdetails_byRang($id_trajet, $rang, $idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."ligne_trajet WHERE ".$this->tableprefix."ligne_trajet.id_trajet = ? AND ".$this->tableprefix."ligne_trajet.rang = ?;"; return $this->execSQL($sql, array($id_trajet, $rang)); } - public function getOneTrajet($id, $idNextcloud) { + public function getOneTrajet($id, $idNextcloud) + { $sql = "SELECT trajet.id, trajet.mois, trajet.annee, trajet.distance, trajet.id_nextcloud, trajet.user_id, thanato.id as id_thanato, thanato.nom as nom_thanato, thanato.prenom as prenom_thanato @@ -301,7 +318,8 @@ class Bdd { return $this->execSQL($sql, array()); } - public function getLieux($idNextcloud){ + public function getLieux($idNextcloud) + { $sql = "SELECT lieu.nom, lieu.adresse, lieu.latitude,lieu.longitude, lieu.user_id, lieu.id, lieu.portal_code,lieu.alarm_code,lieu.funeral_code @@ -310,18 +328,20 @@ class Bdd { return $this->execSQL($sql, array()); } - public function getLieu($id,$idNextcloud){ + public function getLieu($id, $idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."lieu WHERE id = ?"; return $this->execSQL($sql, array($id)); } - public function getDevis($idNextcloud,$mentionFilters = []){ + public function getDevis($idNextcloud, $mentionFilters = []) + { $sql = "SELECT ".$this->tableprefix."devis.id, ".$this->tableprefix."devis.id as devisid, ".$this->tableprefix."devis.user_id,".$this->tableprefix."devis.id_nextcloud ,".$this->tableprefix."devis.comment ," .$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, ".$this->tableprefix."client.id as cid, ".$this->tableprefix."client.id as id_client,".$this->tableprefix."client.is_tva as tva, " .$this->tableprefix."client.adresse as adresse_cli,".$this->tableprefix."client.mail as mail_cli,".$this->tableprefix."client.telephone as telephone_cli,".$this->tableprefix."client.legal_one as legalone_cli," - .$this->tableprefix."client.fk_client_group_facturation_id as fk_client_group_facturation_id," + .$this->tableprefix."client.fk_client_group_facturation_id as fk_client_group_facturation_id," .$this->tableprefix."thanato.nom as nom_thanato, ".$this->tableprefix."thanato.prenom as prenom_thanato, ".$this->tableprefix."thanato.id as tid, " .$this->tableprefix."devis.num, ".$this->tableprefix."devis.date, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.mentions, " .$this->tableprefix."devis.order_number, ".$this->tableprefix."devis.case_number, " @@ -335,7 +355,7 @@ class Bdd { LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id"; $conditions = []; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " WHERE ". $this->tableprefix."devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); @@ -344,24 +364,26 @@ class Bdd { return $this->execSQL($sql, $conditions); } - public function getDevisWithProduits($idNextcloud){ + public function getDevisWithProduits($idNextcloud) + { $devis = $this->getDevis($idNextcloud); $devisList = json_decode($devis); - foreach($devisList as $currentDevis){ + foreach($devisList as $currentDevis) { $produits = $this->getProduitsDevisByDevisId($currentDevis->devisid); $currentDevis->produits = $produits; } return json_encode($devisList); } - public function getDevisEmmanuelle($idNextcloud){ + public function getDevisEmmanuelle($idNextcloud) + { $sql = "SELECT ".$this->tableprefix."devis.id, ".$this->tableprefix."devis.id as devisid, ".$this->tableprefix."devis.user_id,".$this->tableprefix."devis.id_nextcloud ,".$this->tableprefix."devis.comment ," .$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, ".$this->tableprefix."client.id as cid, ".$this->tableprefix."client.id as id_client, " .$this->tableprefix."client.adresse as adresse_cli,".$this->tableprefix."client.mail as mail_cli,".$this->tableprefix."client.telephone as telephone_cli,".$this->tableprefix."client.legal_one as legalone_cli," .$this->tableprefix."thanato.nom as nom_thanato, ".$this->tableprefix."thanato.prenom as prenom_thanato, ".$this->tableprefix."thanato.id as tid, " - .$this->tableprefix."devis.num, ".$this->tableprefix."devis.date, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.mentions, " + .$this->tableprefix."devis.num, ".$this->tableprefix."devis.date, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.mentions, " .$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,".$this->tableprefix."devis.id_lieu, " .$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt FROM (".$this->tableprefix."devis @@ -373,13 +395,14 @@ class Bdd { return $this->execSQL($sql, array()); } - public function getDevisDelphine($idtrajetdetails, $idNextcloud) { + public function getDevisDelphine($idtrajetdetails, $idNextcloud) + { $ligne_trajet = json_decode($this->getOneTrajetdetails($idtrajetdetails, $idNextcloud))[0]; $sql = "SELECT ".$this->tableprefix."devis.id, ".$this->tableprefix."devis.user_id,".$this->tableprefix."devis.id_nextcloud ," .$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, ".$this->tableprefix."client.id as cid, " .$this->tableprefix."thanato.nom as nom_thanato, ".$this->tableprefix."thanato.prenom as prenom_thanato, ".$this->tableprefix."thanato.id as tid, " - .$this->tableprefix."devis.num, ".$this->tableprefix."devis.date, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.mentions, " + .$this->tableprefix."devis.num, ".$this->tableprefix."devis.date, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.mentions, " .$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."devis.id_lieu FROM (".$this->tableprefix."devis LEFT JOIN ".$this->tableprefix."client on id_client = ".$this->tableprefix."client.id @@ -387,9 +410,13 @@ class Bdd { LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id ) WHERE LOWER(".$this->tableprefix."devis.id_nextcloud) LIKE 'delphine' AND ".$this->tableprefix."devis.date LIKE '".$ligne_trajet->date."'"; - - if($ligne_trajet->id_client != NULL) $sql = $sql." AND ".$this->tableprefix."devis.id_client = ".$ligne_trajet->id_client; - if($ligne_trajet->id_lieu != NULL) $sql = $sql." AND ".$this->tableprefix."devis.id_lieu = ".$ligne_trajet->id_lieu; + + if($ligne_trajet->id_client != null) { + $sql = $sql." AND ".$this->tableprefix."devis.id_client = ".$ligne_trajet->id_client; + } + if($ligne_trajet->id_lieu != null) { + $sql = $sql." AND ".$this->tableprefix."devis.id_lieu = ".$ligne_trajet->id_lieu; + } @@ -399,18 +426,20 @@ class Bdd { return $this->execSQL($sql, array()); } - private function getClientsWithClientType(bool $includeClientInsideGroup = true){ + private function getClientsWithClientType(bool $includeClientInsideGroup = true) + { $sql = "SELECT client.*,'client' as client_type FROM ".$this->tableprefix."client as client"; - if($includeClientInsideGroup == false){ + if($includeClientInsideGroup == false) { $sql .= " WHERE client.fk_client_group_facturation_id IS NULL"; } $sql .= ";"; - $clientsWithClientType = $this->execSQLNoJsonReturn($sql,[]); + $clientsWithClientType = $this->execSQLNoJsonReturn($sql, []); return $clientsWithClientType; } - public function getClientsAndClientGroupFacturations(bool $includeClientInsideGroup = true){ + public function getClientsAndClientGroupFacturations(bool $includeClientInsideGroup = true) + { $clients = $this->getClientsWithClientType($includeClientInsideGroup); $clientGroupFacturations = $this->getClientGroupFacturationsWithType(); @@ -418,7 +447,8 @@ class Bdd { return json_encode($result); } - public function getFacturesListWithDependencies(){ + public function getFacturesListWithDependencies() + { $sql = "SELECT facture.id, @@ -477,7 +507,8 @@ class Bdd { return $result; } - public function getFactures($idNextcloud){ + public function getFactures($idNextcloud) + { $sql = "SELECT ".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, " .$this->tableprefix."facture.fk_facture_status_key, ".$this->tableprefix."facture.fk_facture_payment_type_id, ".$this->tableprefix."facture.payment_date, " @@ -509,18 +540,20 @@ class Bdd { return $result; } - public function getFacturesWithProduits(){ + public function getFacturesWithProduits() + { $factures = $this->getFacturesListWithDependencies(); $facturesList = json_decode($factures); - foreach($facturesList as $currentFacture){ + foreach($facturesList as $currentFacture) { $produits = $this->getProduitsDevisByDevisId($currentFacture->id_devis); $currentFacture->produits = $produits; } return json_encode($facturesList); } - private function getClientFacturesByClientIdListAndDate($clientIdList,$date) { + private function getClientFacturesByClientIdListAndDate($clientIdList, $date) + { $clientIdsSqlPlaceholder = implode(',', array_fill(0, count($clientIdList), '?')); $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month," @@ -544,22 +577,25 @@ class Bdd { WHERE YEAR(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[2]." AND MONTH(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[1]." AND ".$this->tableprefix."client.id IN($clientIdsSqlPlaceholder) ORDER BY date_soin ASC"; $result = $this->execSQL( - sql: $sql, - conditions: $clientIdList ); + sql: $sql, + conditions: $clientIdList + ); return $result; } - public function getClientFacturesByClientGroupFacturationIdAndDate($clientGroupFacturationId,$date){ + public function getClientFacturesByClientGroupFacturationIdAndDate($clientGroupFacturationId, $date) + { $clientIds = $this->getClientIdsByClientGroupFacturationId($clientGroupFacturationId); - if(empty($clientIds)){ + if(empty($clientIds)) { return []; } - return $this->getClientFacturesByClientIdListAndDate($clientIds,$date); + return $this->getClientFacturesByClientIdListAndDate($clientIds, $date); } - public function getClientFacturesByClientIdAndDate($clientId,$date){ + public function getClientFacturesByClientIdAndDate($clientId, $date) + { $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month," .$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, " @@ -591,7 +627,8 @@ class Bdd { return $result; } - public function getCurrentMonthFactures_byClient($idNextcloud, $date, $idclient) { + public function getCurrentMonthFactures_byClient($idNextcloud, $date, $idclient) + { $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month," .$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, " @@ -609,16 +646,17 @@ class Bdd { LEFT JOIN ".$this->tableprefix."defunt on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id WHERE YEAR(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[2]." AND MONTH(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[1]." AND ".$this->tableprefix."client.id = ".$idclient." ORDER BY year DESC, month DESC;"; - // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id + // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id // WHERE YEAR(".$this->tableprefix."facture.date_paiement) = YEAR(CURRENT_DATE) AND MONTH(".$this->tableprefix."facture.date_paiement) = MONTH(CURRENT_DATE) // ORDER BY year DESC, month DESC;"; - // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id + // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id // ORDER BY year DESC, month DESC;"; $result = $this->execSQL($sql, array()); return $result; } - public function getCurrentMonthFactures($idNextcloud, $date) { + public function getCurrentMonthFactures($idNextcloud, $date) + { $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month," .$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, " @@ -636,16 +674,17 @@ class Bdd { LEFT JOIN ".$this->tableprefix."defunt on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id WHERE YEAR(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[2]." AND MONTH(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[1]." ORDER BY year DESC, month DESC;"; - // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id + // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id // WHERE YEAR(".$this->tableprefix."facture.date_paiement) = YEAR(CURRENT_DATE) AND MONTH(".$this->tableprefix."facture.date_paiement) = MONTH(CURRENT_DATE) // ORDER BY year DESC, month DESC;"; - // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id + // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id // ORDER BY year DESC, month DESC;"; $result = $this->execSQL($sql, array()); return $result; } - public function getCurrentMonthFactures_COGF($idNextcloud, $date) { + public function getCurrentMonthFactures_COGF($idNextcloud, $date) + { $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month," .$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, " @@ -662,16 +701,17 @@ class Bdd { LEFT JOIN ".$this->tableprefix."defunt on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id WHERE YEAR(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[2]." AND MONTH(".$this->tableprefix."facture.date_paiement) = ".explode('-', $date)[1]." AND LOWER(".$this->tableprefix."client.entreprise) LIKE LOWER('COGF') ORDER BY year DESC, month DESC;"; - - // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id - // WHERE LOWER(".$this->tableprefix."client.entreprise) LIKE LOWER('COGF') + + // $sql = "SELECT YEAR(".$this->tableprefix."facture.date_paiement) AS year, MONTH(".$this->tableprefix."facture.date_paiement) AS month,".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, ".$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, nom, prenom, entreprise, ".$this->tableprefix."facture.version, status_paiement FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id + // WHERE LOWER(".$this->tableprefix."client.entreprise) LIKE LOWER('COGF') // ORDER BY year DESC, month DESC;"; - + $result = $this->execSQL($sql, array()); return $result; } - public function getCurrentMonthTrajet($idNextcloud, $date) { + public function getCurrentMonthTrajet($idNextcloud, $date) + { $sql = "SELECT t.id_nextcloud, t.date, t.distance, depart.nom as lieu_depart, arrivee.nom as lieu_arrivee, depart_c.nom as depart_cnom, depart_c.prenom as depart_cprenoms, arrivee_c.nom as arrivee_cnom, arrivee_c.prenom as arrivee_cprenoms, @@ -687,7 +727,8 @@ class Bdd { return $result; } - public function getOneFacture($numfacture, $idNextcloud){ + public function getOneFacture($numfacture, $idNextcloud) + { $sql = "SELECT ".$this->tableprefix."facture.id," . $this->tableprefix . "facture.version," . $this->tableprefix . "facture.num, " . $this->tableprefix . "facture.facture_number, " .$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum, comment, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom, prenom, entreprise," @@ -712,7 +753,8 @@ class Bdd { return $this->execSQL($sql, array($numfacture)); } - public function getProduits($idNextcloud,$orderDirection = 'DESC'){ + public function getProduits($idNextcloud, $orderDirection = 'DESC') + { $sql = "SELECT produit.id, @@ -730,7 +772,8 @@ class Bdd { return $this->execSQL($sql, array()); } - private function getThanatoByIdNextcloud($idNextcloud){ + private function getThanatoByIdNextcloud($idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."thanato as thanato @@ -738,29 +781,32 @@ class Bdd { ORDER BY thanato.id ASC;"; $thanato = $this->execSQLNoJsonReturn($sql, array($idNextcloud)); - if(!empty($thanato)){ + if(!empty($thanato)) { return $thanato[0]; } return null; } - private function getDefuntIdsRelatedToThanato($thanatoId){ + private function getDefuntIdsRelatedToThanato($thanatoId) + { $devis = $this->getDevisMadeByAThanato($thanatoId); $defuntIds = $this->getDefuntIdsFromDevisList($devis); return $defuntIds; } - private function getDefuntIdsFromDevisList($devisList){ + private function getDefuntIdsFromDevisList($devisList) + { $defuntIds = []; - foreach($devisList as $devis){ + foreach($devisList as $devis) { $defuntIds[] = $devis["id_defunt"]; } return $defuntIds; } - private function getDevisMadeByAThanato($thanatoId){ + private function getDevisMadeByAThanato($thanatoId) + { $sql = "SELECT devis.id, @@ -773,7 +819,7 @@ class Bdd { return $devisList; } - public function getDefunts($idNextcloud, $isUserThanatoOnly = false) + public function getDefunts($idNextcloud, $isUserThanatoOnly = false) { $sql = "SELECT ".$this->tableprefix."defunt.id, ".$this->tableprefix."defunt.nom, ".$this->tableprefix."defunt.date_naissance, ".$this->tableprefix."defunt.ref_pacemaker, ".$this->tableprefix."defunt.sexe, " .$this->tableprefix."client.nom as nom_client, ".$this->tableprefix."client.id as id_client, " @@ -786,14 +832,14 @@ class Bdd { LEFT JOIN ".$this->tableprefix."lieu ON ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id"; $conditions = []; - if($isUserThanatoOnly){ + if($isUserThanatoOnly) { $thanato = $this->getThanatoByIdNextcloud($idNextcloud); - if($thanato == null){ + if($thanato == null) { return json_encode([]); } $thanatoId = $thanato["id"]; $defuntsIdRelatedToThanato = $this->getDefuntIdsRelatedToThanato($thanatoId); - if(empty($defuntsIdRelatedToThanato)){ + if(empty($defuntsIdRelatedToThanato)) { return json_encode([]); } $defuntListConditionPlaceholder = implode(',', array_fill(0, count($defuntsIdRelatedToThanato), '?')); @@ -802,13 +848,13 @@ class Bdd { } $sql .= " ORDER BY ".$this->tableprefix."defunt.id DESC;"; - $defuntsList = $this->execSQLNoJsonReturn($sql,$conditions); - foreach($defuntsList as &$defunt){ + $defuntsList = $this->execSQLNoJsonReturn($sql, $conditions); + foreach($defuntsList as &$defunt) { $defunt["product_cover_description"] = null; $defuntHasDevis = $defunt["id_devis"] != null; - if($defuntHasDevis){ + if($defuntHasDevis) { $productCover = $this->getProductCoverByDevisId($defunt["id_devis"]); - if($productCover != null){ + if($productCover != null) { $defunt["product_cover_description"] = $productCover["description"]; } } @@ -816,7 +862,8 @@ class Bdd { return json_encode($defuntsList); } - public function getUnusedDefunts($idNextcloud) { + public function getUnusedDefunts($idNextcloud) + { $sql = "SELECT ".$this->tableprefix."defunt.id, ".$this->tableprefix."defunt.nom, ".$this->tableprefix."defunt.date_naissance, ".$this->tableprefix."defunt.ref_pacemaker, ".$this->tableprefix."defunt.sexe," .$this->tableprefix."devis.user_id as user_id @@ -827,7 +874,8 @@ class Bdd { return $this->execSQL($sql, array()); } - public function getOneDevis($numdevis,$idNextcloud){ + 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,case_number,order_number," @@ -848,7 +896,8 @@ class Bdd { return $this->execSQL($sql, array($numdevis)); } - public function getOneDefunt($numdefunt,$idNextcloud,$includeDefuntProductCover = false){ + public function getOneDefunt($numdefunt, $idNextcloud, $includeDefuntProductCover = false) + { $sql = "SELECT ".$this->tableprefix."defunt.id, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.comment, ".$this->tableprefix."devis.date, num," .$this->tableprefix."devis.id as id_devis,".$this->tableprefix."devis.id_client, id_lieu, id_thanato,".$this->tableprefix."devis.user_id as user_id, " @@ -903,14 +952,14 @@ class Bdd { LEFT JOIN ".$this->tableprefix."thanato on ".$this->tableprefix."devis.id_thanato = ".$this->tableprefix."thanato.id WHERE ".$this->tableprefix."defunt.id = ?"; - $defunts = $this->execSQLNoJsonReturn($sql,[$numdefunt]); - if($includeDefuntProductCover){ - foreach($defunts as &$defunt){ + $defunts = $this->execSQLNoJsonReturn($sql, [$numdefunt]); + if($includeDefuntProductCover) { + foreach($defunts as &$defunt) { $defunt["product_cover_id"] = null; $defuntHasDevis = $defunt["id_devis"] != null; - if($defuntHasDevis){ + if($defuntHasDevis) { $productCover = $this->getProductCoverByDevisId($defunt["id_devis"]); - if($productCover != null){ + if($productCover != null) { $defunt["product_cover_id"] = $productCover["produit_id"]; } } @@ -919,7 +968,8 @@ class Bdd { return json_encode($defunts); } - public function getListProduit($numdevis, $idNextcloud){ + public function getListProduit($numdevis, $idNextcloud) + { $sql = "SELECT ". $this->tableprefix."produit.id as pid," @@ -929,25 +979,26 @@ class Bdd { FROM ".$this->tableprefix."produit, ".$this->tableprefix."devis, ".$this->tableprefix."produit_devis WHERE ".$this->tableprefix."produit.id = produit_id AND ".$this->tableprefix."devis.id = devis_id AND ".$this->tableprefix."devis.id = ?"; - $produits = $this->execSQLNoJsonReturn($sql,[$numdevis]); + $produits = $this->execSQLNoJsonReturn($sql, [$numdevis]); - if(!empty($produits)){ + if(!empty($produits)) { $clientId = $produits[0]["id_client"]; $client = $this->getClientById($clientId); - foreach($produits as &$produit){ - $productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$produit['pid']); + foreach($produits as &$produit) { + $productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'], $produit['pid']); $produit['prix_unitaire'] = $productPrice ?? $produit['prix_unitaire']; } } return json_encode($produits); } - public function getListArticle($numdevis, $idNextcloud) { + public function getListArticle($numdevis, $idNextcloud) + { $sql = "SELECT ".$this->tableprefix."article.id as aid,".$this->tableprefix."article_devis.id as adid, reference, description,".$this->tableprefix."article_devis.comment, quantite, prix_unitaire FROM ".$this->tableprefix."article, ".$this->tableprefix."devis, ".$this->tableprefix."article_devis WHERE ".$this->tableprefix."article.id = article_id AND ".$this->tableprefix."devis.id = devis_id AND ".$this->tableprefix."devis.id = ?"; return $this->execSQL($sql, array($numdevis)); } - + /** * Récupère le statut TVA du client associé au devis * @param int $numdevis ID du devis @@ -967,19 +1018,22 @@ class Bdd { return isset($clientData[0]->is_tva) ? (int)$clientData[0]->is_tva : 1; // Par défaut TVA = 1 si non trouvé } - public function getArticles($idNextcloud){ + public function getArticles($idNextcloud) + { $sql = "SELECT * FROM ".$this->tableprefix."article"; return $this->execSQL($sql, array()); } - private function getFunctionCall(){ + private function getFunctionCall() + { $trace = debug_backtrace(); return $trace[2]['function']; } - public function getListObservations($numdefunt, $idNextcloud) { + public function getListObservations($numdefunt, $idNextcloud) + { $sql = "SELECT ".$this->tableprefix."obs_defunt.id as odid, designation, commentaire FROM " .$this->tableprefix."obs_defunt, ".$this->tableprefix."defunt @@ -987,7 +1041,8 @@ class Bdd { return $this->execSQL($sql, array($numdefunt)); } - public function getListBijoux($numdefunt, $idNextcloud) { + public function getListBijoux($numdefunt, $idNextcloud) + { $sql = "SELECT ".$this->tableprefix."bijou_defunt.id as bdid, designation, commentaire,photo,photo_name,taker_name FROM " .$this->tableprefix."bijou_defunt, ".$this->tableprefix."defunt @@ -995,7 +1050,8 @@ class Bdd { return $this->execSQL($sql, array($numdefunt)); } - public function getListHypodermiques($numdefunt, $idNextcloud) { + public function getListHypodermiques($numdefunt, $idNextcloud) + { $sql = "SELECT ".$this->tableprefix."hypo_defunt.id as hdid, designation, qte, endroit FROM " .$this->tableprefix."hypo_defunt, ".$this->tableprefix."defunt @@ -1007,10 +1063,13 @@ class Bdd { * INSERT client * @$idnextcloud */ - public function insertClient($idNextcloud){ + public function insertClient($idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."client` (`id_nextcloud`,`nom`,`prenom`,`legal_one`,`entreprise`,`telephone`,`mail`,`adresse`) VALUES (?,?,?,?,?,?,?,?)"; - $this->execSQLNoData($sql,array($idNextcloud, + $this->execSQLNoData( + $sql, + array($idNextcloud, $this->l->t('Last name'), @@ -1021,33 +1080,37 @@ class Bdd { $this->l->t('Email'), $this->l->t('Address') ) - ); + ); return true; } /** - * + * */ - public function insertThanatopracteur($idNextcloud) { + public function insertThanatopracteur($idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."thanato` (`id_nextcloud`,`nom`,`prenom`,`reference`,`date_habilitation`) VALUES (?,?,?,?,NOW())"; - $this->execSQLNoData($sql,array($idNextcloud, + $this->execSQLNoData( + $sql, + array($idNextcloud, $this->l->t('Last name'), $this->l->t('First name'), 'reference', ) - ); + ); return true; } /** * Insert lieu */ - public function insertTrajet($id_thanato, $mois, $annee, $idNextcloud){ + public function insertTrajet($id_thanato, $mois, $annee, $idNextcloud) + { - $last=0; + $last = 0; $last = $this->lastinsertid("trajet", $idNextcloud) + 1; // $sql = "INSERT INTO `".$this->tableprefix."trajet` ( `id_nextcloud`, @@ -1059,7 +1122,7 @@ class Bdd { // `id_lieu_arrivee`, // `distance`, // `user_id` - // ) + // ) // VALUES (?,NOW(),?,?,0,0,0,0,?);"; $sql = "INSERT INTO `".$this->tableprefix."trajet` ( `id_nextcloud`, `date`, @@ -1077,9 +1140,10 @@ class Bdd { /** * Insert lieu */ - public function insertTrajetdetails($numtrajet, $idNextcloud){ + public function insertTrajetdetails($numtrajet, $idNextcloud) + { - $last=0; + $last = 0; $last = $this->lastinsertid("ligne_trajet", $idNextcloud) + 1; $rang = $this->get_last_rang_trajetdetails($numtrajet, $idNextcloud); @@ -1099,14 +1163,15 @@ class Bdd { `user_id` ) VALUES (?,?,0,0,?,?,'','lieu',?);"; - $this->execSQLNoData($sql, array($idNextcloud,$trajetdetails[sizeof($trajetdetails)-1]->date,$numtrajet,$rang+1,$last)); + $this->execSQLNoData($sql, array($idNextcloud,$trajetdetails[sizeof($trajetdetails) - 1]->date,$numtrajet,$rang + 1,$last)); return true; } - public function insertTrajetdetails_h2f($numtrajet, $date, $idNextcloud,$lieuSiege = "siege",$devisId = 0){ + public function insertTrajetdetails_h2f($numtrajet, $date, $idNextcloud, $lieuSiege = "siege", $devisId = 0) + { $lieuSiege = strtolower($lieuSiege); - $last=0; + $last = 0; $last = $this->lastinsertid("ligne_trajet", $idNextcloud) + 1; $rang = $this->get_last_rang_trajetdetails($numtrajet, $idNextcloud); @@ -1119,7 +1184,7 @@ class Bdd { $response_h2f = $this->execSQL($sql_h2f, array($lieuSiege)); $h2f = json_decode($response_h2f)[0]; - $id_h2f = ($h2f!=NULL)?$h2f->id:0; + $id_h2f = ($h2f != null) ? $h2f->id : 0; $sql = "INSERT INTO `".$this->tableprefix."ligne_trajet` ( `id_nextcloud`, `date`, @@ -1132,16 +1197,17 @@ class Bdd { `user_id` ) VALUES (?,?,?,?,?,?,'','siege',?);"; - $this->execSQLNoData($sql, array($idNextcloud,$date,$devisId,$id_h2f,$numtrajet,$rang+1,$last)); + $this->execSQLNoData($sql, array($idNextcloud,$date,$devisId,$id_h2f,$numtrajet,$rang + 1,$last)); return true; } /** * Insert lieu */ - public function insertTrajetdetails_byDevis($numtrajet, $devis, $idNextcloud){ + public function insertTrajetdetails_byDevis($numtrajet, $devis, $idNextcloud) + { - $last=0; + $last = 0; $last = $this->lastinsertid("ligne_trajet", $idNextcloud) + 1; $rang = $this->get_last_rang_trajetdetails($numtrajet, $idNextcloud); @@ -1150,8 +1216,8 @@ class Bdd { $trajetdetails = json_decode($this->getTrajetsdetails_orderByDate($numtrajet, $idNextcloud)); - $id_client = ($devis->id_client != NULL)?$devis->id_client:0; - $id_lieu = ($devis->id_lieu != NULL)?$devis->id_lieu:0; + $id_client = ($devis->id_client != null) ? $devis->id_client : 0; + $id_lieu = ($devis->id_lieu != null) ? $devis->id_lieu : 0; $sql = "INSERT INTO `".$this->tableprefix."ligne_trajet` ( `id_nextcloud`, `date`, @@ -1165,16 +1231,19 @@ class Bdd { `user_id` ) VALUES (?,?,?,?,?,?,?,'','devis',?);"; - $this->execSQLNoData($sql, array($idNextcloud,$devis->date,$devis->devisid,$id_client,$id_lieu,$numtrajet,$rang+1,$last)); + $this->execSQLNoData($sql, array($idNextcloud,$devis->date,$devis->devisid,$id_client,$id_lieu,$numtrajet,$rang + 1,$last)); return true; } - public function get_last_rang_trajetdetails($numtrajet, $idNextcloud) { + public function get_last_rang_trajetdetails($numtrajet, $idNextcloud) + { $trajetdetails = json_decode($this->getTrajetsdetails($numtrajet, $idNextcloud)); $rang_max = 0; foreach ($trajetdetails as $key => $details) { - if($rang_max<=$details->rang) $rang_max = $details->rang; + if($rang_max <= $details->rang) { + $rang_max = $details->rang; + } } @@ -1184,7 +1253,8 @@ class Bdd { /** * Insert Defunt */ - public function insertDefunt($idNextcloud) { + public function insertDefunt($idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."defunt` ( `id_nextcloud`, `nom`, `sexe`, `date_naissance`, `ref_pacemaker`, `date`, @@ -1197,7 +1267,8 @@ class Bdd { /** * Insert Defunt */ - public function insertDefuntByName($name) { + public function insertDefuntByName($name) + { $sql = "INSERT INTO `".$this->tableprefix."defunt` ( `id_nextcloud`, `nom`, `sexe`, `date_naissance`, `ref_pacemaker`, `date`, @@ -1207,104 +1278,115 @@ class Bdd { return true; } - public function insertDefuntByNameAndReturnId($name) { + public function insertDefuntByNameAndReturnId($name) + { $this->insertDefuntByName($name); return $this->getLastDefuntIdByName($name); } - public function getLastDefuntIdByName( $name ) { + public function getLastDefuntIdByName($name) + { $sql = "SELECT max(id) as LAST_INSERT_ID FROM ".$this->tableprefix."defunt WHERE nom = ?"; - $res = $this->execSQLNoJsonReturn($sql,array($name)); - if($res){ + $res = $this->execSQLNoJsonReturn($sql, array($name)); + if($res) { return $res[0]['LAST_INSERT_ID']; } return null; } - public function getLastClientIdByName($name) { + public function getLastClientIdByName($name) + { $sql = "SELECT max(id) as LAST_INSERT_ID FROM ".$this->tableprefix."client WHERE nom = ?"; - $res = $this->execSQLNoJsonReturn($sql,array($name)); - if($res){ + $res = $this->execSQLNoJsonReturn($sql, array($name)); + if($res) { return $res[0]['LAST_INSERT_ID']; } return null; } - public function getLastLocationIdByName($name) { + public function getLastLocationIdByName($name) + { $sql = "SELECT max(id) as LAST_INSERT_ID FROM ".$this->tableprefix."lieu WHERE nom = ?"; - $res = $this->execSQLNoJsonReturn($sql,array($name)); - if($res){ + $res = $this->execSQLNoJsonReturn($sql, array($name)); + if($res) { return $res[0]['LAST_INSERT_ID']; } return null; } - public function getOrCreateThanatoIdByLastName($name){ + public function getOrCreateThanatoIdByLastName($name) + { $thanatoId = $this->getLastThanatoIdByName($name); - if($thanatoId == null){ + if($thanatoId == null) { $this->createThanatoByLastName($name); $thanatoId = $this->getLastThanatoIdByName($name); } return $thanatoId; } - private function createThanatoByLastName($name){ + private function createThanatoByLastName($name) + { $idNextcloud = "admin"; $sql = "INSERT INTO `".$this->tableprefix."thanato` (`id_nextcloud`,`nom`,`prenom`,`reference`,`date_habilitation`) VALUES (?,?,?,?,NOW())"; - $this->execSQLNoData($sql,array($idNextcloud, + $this->execSQLNoData( + $sql, + array($idNextcloud, $name, $this->l->t('First name'), 'reference', ) - ); + ); return true; } - public function getLastThanatoIdByName($name) { + public function getLastThanatoIdByName($name) + { $sql = "SELECT max(id) as LAST_INSERT_ID FROM ".$this->tableprefix."thanato WHERE nom = ?"; - $res = $this->execSQLNoJsonReturn($sql,array($name)); - if($res){ + $res = $this->execSQLNoJsonReturn($sql, array($name)); + if($res) { return $res[0]['LAST_INSERT_ID']; } return null; } - public function getFirstThanatoIdByName($name) { + public function getFirstThanatoIdByName($name) + { $sql = "SELECT min(id) as FIRST_INSERT_ID FROM ".$this->tableprefix."thanato WHERE nom = ?"; - $res = $this->execSQLNoJsonReturn($sql,array($name)); - if($res){ + $res = $this->execSQLNoJsonReturn($sql, array($name)); + if($res) { return $res[0]['FIRST_INSERT_ID']; } return null; } - public function getThanatoIdByUserUuid($userUuid){ + public function getThanatoIdByUserUuid($userUuid) + { $sql = "SELECT min(id) as FIRST_INSERT_ID FROM ".$this->tableprefix."thanato WHERE fk_user_uuid = ?"; - $res = $this->execSQLNoJsonReturn($sql,array($userUuid)); - if($res){ + $res = $this->execSQLNoJsonReturn($sql, array($userUuid)); + if($res) { return $res[0]['FIRST_INSERT_ID']; } return null; @@ -1313,9 +1395,10 @@ class Bdd { /** * Insert lieu */ - public function insertLieu($idNextcloud){ + public function insertLieu($idNextcloud) + { - $last=0; + $last = 0; $last = $this->lastinsertid("lieu", $idNextcloud) + 1; // $sql = "INSERT INTO `".$this->tableprefix."lieu` ( `id_nextcloud`, @@ -1329,7 +1412,7 @@ class Bdd { // `depart`, // `arrivee`, // `user_id` - // ) + // ) // VALUES (?,?,NOW(),0,'',?,?,0,'','',?);"; $sql = "INSERT INTO `".$this->tableprefix."lieu` ( `id_nextcloud`, @@ -1346,9 +1429,10 @@ class Bdd { /** * Insert quote */ - public function insertDevis($idNextcloud){ + public function insertDevis($idNextcloud) + { - $last=0; + $last = 0; $last = $this->lastinsertid("devis", $idNextcloud) + 1; $sql = "INSERT INTO `".$this->tableprefix."devis` ( `date`, @@ -1375,41 +1459,42 @@ class Bdd { return true; } - private function getLastDevisNumberByMonthAndYear($month,$year){ + private function getLastDevisNumberByMonthAndYear($month, $year) + { $sql = "SELECT - max(devis.devis_number) as LAST_DEVIS_NUMBER, devis.date FROM " + max(devis.devis_number) as LAST_DEVIS_NUMBER, devis.date FROM " . $this->tableprefix."devis as devis WHERE YEAR(devis.date) = ? AND MONTH(devis.date) = ?;"; - $res = $this->execSQLNoJsonReturn($sql,array($year,$month)); + $res = $this->execSQLNoJsonReturn($sql, array($year,$month)); $lastNumber = 0; - if(!empty($res)){ + if(!empty($res)) { $lastNumber = $res[0]['LAST_DEVIS_NUMBER']; } return $lastNumber; } - public function insertDevisFromVCalendarAndReturnId($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid = self::DEFAULT_CALENDAR_UUID_FOR_DEVIS,$date = null,$devisComment = "Commentaire"){ + public function insertDevisFromVCalendarAndReturnId($thanatoId, $clientId, $locationId, $defuntId, $calendarUuid = self::DEFAULT_CALENDAR_UUID_FOR_DEVIS, $date = null, $devisComment = "Commentaire") + { - if($date == null){ + if($date == null) { $dateTime = new Datetime(); $date = $dateTime->format('Y-m-d'); - } - else{ + } else { $dateTime = new DateTime($date); } $idNextcloud = "admin"; - $last=0; + $last = 0; $last = $this->lastinsertid("devis", "admin") + 1; $dateMonth = $dateTime->format('m'); $dateYear = $dateTime->format('Y'); - $devisLastNumber = $this->getLastDevisNumberByMonthAndYear($dateMonth,$dateYear); + $devisLastNumber = $this->getLastDevisNumberByMonthAndYear($dateMonth, $dateYear); $devisNumber = $devisLastNumber + 1; - $devisFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($dateTime,$devisNumber,'DEV'); + $devisFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($dateTime, $devisNumber, 'DEV'); $sql = "INSERT INTO `".$this->tableprefix."devis` ( `date`, `id_nextcloud`, @@ -1426,7 +1511,9 @@ class Bdd { `devis_full_number` ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);"; - $this->execSQLNoData($sql, array( + $this->execSQLNoData( + $sql, + array( $date, @@ -1444,29 +1531,31 @@ class Bdd { $devisFullNumber ) ); - - return $this->getLastDevisIdFromVCalendarProperty($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid); + + return $this->getLastDevisIdFromVCalendarProperty($thanatoId, $clientId, $locationId, $defuntId, $calendarUuid); } - public function getLastDevisIdFromVCalendarProperty($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid=self::DEFAULT_CALENDAR_UUID_FOR_DEVIS){ + public function getLastDevisIdFromVCalendarProperty($thanatoId, $clientId, $locationId, $defuntId, $calendarUuid = self::DEFAULT_CALENDAR_UUID_FOR_DEVIS) + { $sql = "SELECT max(id) as LAST_INSERT_ID FROM ".$this->tableprefix."devis WHERE id_defunt = ? AND id_lieu = ? AND id_client = ? AND id_thanato = ? AND num = ?"; - $res = $this->execSQLNoJsonReturn($sql,array( + $res = $this->execSQLNoJsonReturn($sql, array( $defuntId, $locationId, $clientId, $thanatoId, $calendarUuid )); - if($res){ + if($res) { return $res[0]['LAST_INSERT_ID']; } - return null; + return null; } - public function getArticlesIdFromArticlesNameArray(array $articles): array { + public function getArticlesIdFromArticlesNameArray(array $articles): array + { $articleIds = []; foreach ($articles as $article) { @@ -1479,18 +1568,20 @@ class Bdd { return $articleIds; } - public function insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds) { + public function insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds) + { if (!empty($articleIds)) { $idNextcloud = "admin"; foreach ($articleIds as $articleId) { - $this->insertDevisArticle(devisId: $devisId, articleId: $articleId,idNextcloud: $idNextcloud); + $this->insertDevisArticle(devisId: $devisId, articleId: $articleId, idNextcloud: $idNextcloud); } } return true; } - private function insertDevisArticle($devisId,$articleId,$idNextcloud){ + private function insertDevisArticle($devisId, $articleId, $idNextcloud) + { $sql = "INSERT INTO ".$this->tableprefix."produit_devis (devis_id, produit_id, quantite, discount, comment,id_nextcloud) VALUES (?, ?, 1, 0, '-',?)"; $this->execSQLNoData($sql, array($devisId, $articleId,$idNextcloud)); @@ -1500,28 +1591,30 @@ class Bdd { /** * Insert invoice */ - public function insertFacture($idNextcloud){ + public function insertFacture($idNextcloud) + { $last = 0; $last = $this->lastNumFacture($idNextcloud); - $pref = $this->execSQLNoJsonReturn("SELECT * FROM ".$this->tableprefix."configuration WHERE id_nextcloud LIKE ?",array($idNextcloud)); + $pref = $this->execSQLNoJsonReturn("SELECT * FROM ".$this->tableprefix."configuration WHERE id_nextcloud LIKE ?", array($idNextcloud)); $sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`) VALUES (?,?,?,NOW(),?,0,?,?,?);"; $date_temp = new DateTime(); $date = $date_temp->format('Y-m-d'); $dateMonth = $date_temp->format('m'); $dateYear = $date_temp->format('Y'); - $factureLastNumber = $this->getLastFactureNumberByMonthAndYear($dateMonth,$dateYear); + $factureLastNumber = $this->getLastFactureNumberByMonthAndYear($dateMonth, $dateYear); $factureNumber = $factureLastNumber + 1; - $factureFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($date_temp,$factureNumber,'FAC'); - + $factureFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($date_temp, $factureNumber, 'FAC'); + $datesplit = explode('-', $date); - $this->execSQLNoData($sql, array($date , $idNextcloud, $factureFullNumber,"Comptant",$last+1,"Ajouter un lieu",$factureNumber)); + $this->execSQLNoData($sql, array($date , $idNextcloud, $factureFullNumber,"Comptant",$last + 1,"Ajouter un lieu",$factureNumber)); return $last; } - private function getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter,$devisListId){ + private function getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter, $devisListId) + { if (empty($devisListId)) { return []; @@ -1533,23 +1626,25 @@ class Bdd { WHERE devis.id IN ($placeholders) AND mentions IN ($mentionsFilterPlaceholders)"; - $result = $this->execSQLNoJsonReturn($sql,array_merge( - $devisListId, - $mentionsFilter)); + $result = $this->execSQLNoJsonReturn($sql, array_merge( + $devisListId, + $mentionsFilter + )); return $result; } - public function insertFactureForeEachDevisId($idNextCloud,$devisIdArray,$facturationDate = null){ + public function insertFactureForeEachDevisId($idNextCloud, $devisIdArray, $facturationDate = null) + { $mentionsFilter = [ DevisMentionConstant::NEW, DevisMentionConstant::MENTION ]; - $devisIdListFiltered = $this->getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter,$devisIdArray); + $devisIdListFiltered = $this->getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter, $devisIdArray); $factureIdsGenerated = []; - foreach($devisIdListFiltered as $devis){ - $factureId = $this->insertFactureByDevisId($idNextCloud,$devis['id'],$devis['devis_date'],$facturationDate); + foreach($devisIdListFiltered as $devis) { + $factureId = $this->insertFactureByDevisId($idNextCloud, $devis['id'], $devis['devis_date'], $facturationDate); $factureIdsGenerated[] = $factureId; } return $factureIdsGenerated; @@ -1558,55 +1653,58 @@ class Bdd { /** * Insert invoice with a devis */ - public function insertFactureByDevisId($idNextcloud,$devisId,$devisDate = null,$facturationDate = null){ + public function insertFactureByDevisId($idNextcloud, $devisId, $devisDate = null, $facturationDate = null) + { - if($facturationDate == null || $facturationDate == ""){ + if($facturationDate == null || $facturationDate == "") { $datetimeNow = new Datetime(); $facturationDate = DateHelpers::GetLastDayOfTheMonthOfADate($datetimeNow); - $facturationDate = $facturationDate->format('Y-m-d'); - } - else{ - $facturationDate = Datetime::createFromFormat('Y-m-d',$facturationDate); - $facturationDate = $facturationDate->format('Y-m-d'); + $facturationDate = $facturationDate->format('Y-m-d'); + } else { + $facturationDate = Datetime::createFromFormat('Y-m-d', $facturationDate); + $facturationDate = $facturationDate->format('Y-m-d'); } $devisDatetime = new Datetime(); - if($devisDate != null){ + if($devisDate != null) { $devisDatetime = new Datetime($devisDate); } $factureDate = $devisDatetime->format('Y-m-d'); $factureNumber = $this->getFactureNumberByDate($devisDatetime); $facturePrefix = "FAC"; $devis = json_decode($this->getOneDevis($devisId, $idNextcloud))[0]; - $isDevisNegative = $this->isDevisNegative($devisId,clientId: $devis->clientid); - if($isDevisNegative){ + $isDevisNegative = $this->isDevisNegative($devisId, clientId: $devis->clientid); + if($isDevisNegative) { $facturePrefix = "AVO"; } - - $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($devisDatetime,$factureNumber,$facturePrefix); + + $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($devisDatetime, $factureNumber, $facturePrefix); $last = 0; $last = $this->lastNumFacture($idNextcloud); $sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`) VALUES (?,?,?,?,?,?,?,?,?);"; - $this->execSQLNoData($sql, array( + $this->execSQLNoData( + $sql, + array( - $factureDate , - $idNextcloud, + $factureDate , + $idNextcloud, $fullFactureNumber, $facturationDate, "Comptant", $devisId, - $last+1, + $last + 1, "Ajouter un lieu", $factureNumber) ); $factureId = $this->getFactureIdByDevisId($devisId); //update devis status - $this->gestion_update('devis','mentions',DevisMentionConstant::FACTURED_FORMATTED,$devisId,$idNextcloud); + $this->gestion_update('devis', 'mentions', DevisMentionConstant::FACTURED_FORMATTED, $devisId, $idNextcloud); return $factureId; } - private function getFactureIdByDevisId($devisId){ + private function getFactureIdByDevisId($devisId) + { $sql = "SELECT facture.id @@ -1614,69 +1712,78 @@ class Bdd { WHERE facture.id_devis = ? ORDER BY facture.id DESC;"; $facture = $this->execSQLNoJsonReturn( - $sql, - [$devisId]); + $sql, + [$devisId] + ); - if(!empty($facture)){ + if(!empty($facture)) { return $facture[0]['id']; } return null; } - - public function insertProduit($idNextcloud){ + + public function insertProduit($idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."produit` (`id_nextcloud`,`reference`,`description`,`prix_unitaire`) VALUES (?,?,?,0);"; $this->execSQLNoData($sql, array($idNextcloud,$this->l->t('Reference'),$this->l->t('Designation'))); return true; } - public function insertProduitDevis($id,$idNextcloud){ + public function insertProduitDevis($id, $idNextcloud) + { $res = $this->searchMaxIdProduit($idNextcloud); $sql = "INSERT INTO `".$this->tableprefix."produit_devis` (`devis_id`, `id_nextcloud`,`produit_id`,`quantite`,`discount`) VALUES (?,?,?,1,0);"; - $this->execSQLNoData($sql, array($id,$idNextcloud,($res[0]['id']==NULL)?0:$res[0]['id'])); + $this->execSQLNoData($sql, array($id,$idNextcloud,($res[0]['id'] == null) ? 0 : $res[0]['id'])); return true; } - public function insertArticle($idNextcloud){ + public function insertArticle($idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."article` (`id_nextcloud`,`reference`,`description`,`prix_unitaire`) VALUES (?,?,?,0);"; $this->execSQLNoData($sql, array($idNextcloud,$this->l->t('Reference'),$this->l->t('Designation'))); return true; } - public function insertArticleDevis($id,$idNextcloud){ + public function insertArticleDevis($id, $idNextcloud) + { $res = $this->searchMaxIdArticle($idNextcloud); $sql = "INSERT INTO `".$this->tableprefix."article_devis` (`devis_id`, `id_nextcloud`,`article_id`,`quantite`,`discount`, `comment`) VALUES (?,?,?,1,0,'-');"; - $this->execSQLNoData($sql, array($id,$idNextcloud,($res[0]['id']==NULL)?0:$res[0]['id'])); + $this->execSQLNoData($sql, array($id,$idNextcloud,($res[0]['id'] == null) ? 0 : $res[0]['id'])); return true; } - public function insertObservationDefunt($id,$idNextcloud){ + public function insertObservationDefunt($id, $idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."obs_defunt` (`defunt_id`, `id_nextcloud`,`designation`,`commentaire`) VALUES (?,?,?,?);"; $this->execSQLNoData($sql, array($id,$idNextcloud,'inserer une observation', 'inserer un commentaire')); return true; } - public function insertBijouDefunt($id,$idNextcloud){ + public function insertBijouDefunt($id, $idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."bijou_defunt` (`defunt_id`, `id_nextcloud`,`designation`,`commentaire`) VALUES (?,?,?,?);"; $this->execSQLNoData($sql, array($id,$idNextcloud,'', '')); return true; } - public function insertHypoDefunt($id,$idNextcloud){ + public function insertHypoDefunt($id, $idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."hypo_defunt` (`defunt_id`, `id_nextcloud`,`designation`,`qte`, `endroit`) VALUES (?,?,?,?,?);"; $this->execSQLNoData($sql, array($id,$idNextcloud,'', 0, '')); return true; } - public function searchMaxIdProduit($idNextcloud){ + public function searchMaxIdProduit($idNextcloud) + { // $sqlSearchMax = "SELECT MIN(id) as id FROM `".$this->tableprefix."produit` WHERE id_nextcloud = ?"; $sqlSearchMax = "SELECT MIN(id) as id FROM `".$this->tableprefix."produit`"; @@ -1684,31 +1791,34 @@ class Bdd { return $this->execSQLNoJsonReturn($sqlSearchMax, array()); } - public function searchMaxIdArticle($idNextcloud){ + public function searchMaxIdArticle($idNextcloud) + { $sqlSearchMax = "SELECT MIN(id) as id FROM `".$this->tableprefix."article`"; return $this->execSQLNoJsonReturn($sqlSearchMax, array()); } - public function insertBibliotheque($idNextcloud){ + public function insertBibliotheque($idNextcloud) + { $sql = "INSERT INTO `".$this->tableprefix."bibliotheque` (`id_nextcloud`,`contenu`) VALUES (?,?);"; $this->execSQLNoData($sql, array($idNextcloud,'inserer un texte ici')); return true; } - private function isDevisNegative($devisId,$clientId){ + private function isDevisNegative($devisId, $clientId) + { $sql = "SELECT produit_devis.quantite,produit.prix_unitaire,produit.id FROM ".$this->tableprefix."produit_devis as produit_devis LEFT JOIN ".$this->tableprefix."produit as produit ON produit_devis.produit_id = produit.id WHERE produit_devis.devis_id = ?;"; - $devisProduits = $this->execSQLNoJsonReturn($sql,array($devisId)); + $devisProduits = $this->execSQLNoJsonReturn($sql, array($devisId)); $total = 0; - if(!empty($devisProduits)){ - foreach($devisProduits as $currentProduit){ - if($currentProduit['id'] != null){ - $produitPrice = $this->getProductPriceByClient($currentProduit['id'],$clientId,$currentProduit['prix_unitaire']); + if(!empty($devisProduits)) { + foreach($devisProduits as $currentProduit) { + if($currentProduit['id'] != null) { + $produitPrice = $this->getProductPriceByClient($currentProduit['id'], $clientId, $currentProduit['prix_unitaire']); $total += $produitPrice * $currentProduit['quantite']; } } @@ -1716,122 +1826,124 @@ class Bdd { return $total < 0; } - private function getProduitDevisById($produitDevisId){ + private function getProduitDevisById($produitDevisId) + { $sql = "SELECT * FROM ".$this->tableprefix."produit_devis as produit_devis WHERE produit_devis.id = ?;"; - $result = $this->execSQLNoJsonReturn($sql,[$produitDevisId]);; + $result = $this->execSQLNoJsonReturn($sql, [$produitDevisId]); + ; - if(!empty($result)){ + if(!empty($result)) { return $result[0]; } return null; } - private function getFactureByDevisId($devisId){ + private function getFactureByDevisId($devisId) + { $sql = "SELECT * FROM ".$this->tableprefix."facture as facture WHERE facture.id_devis = ?"; - $result = $this->execSQLNoJsonReturn($sql,[$devisId]); - if(!empty($result)){ + $result = $this->execSQLNoJsonReturn($sql, [$devisId]); + if(!empty($result)) { return $result[0]; } return null; } - + /** * UPDATE */ - public function gestion_update($table, $column, $data, $id, $idNextcloud){ - - if(in_array($table, $this->whiteTable) && in_array($column, $this->whiteColumn)){ - if(strcmp($table, "facture")==0 && strcmp($column, "date_paiement")==0) { + public function gestion_update($table, $column, $data, $id, $idNextcloud) + { + + if(in_array($table, $this->whiteTable) && in_array($column, $this->whiteColumn)) { + if(strcmp($table, "facture") == 0 && strcmp($column, "date_paiement") == 0) { $facture = $this->getFactureByFactureId($id); - if($facture['date_paiement'] != $data){ - $facturationDatetime = Datetime::createFromFormat('Y-m-d',$data); + if($facture['date_paiement'] != $data) { + $facturationDatetime = Datetime::createFromFormat('Y-m-d', $data); $factureNumber = $this->getFactureNumberByDate($facturationDatetime); $facturePrefix = "FAC"; - if($facture['id_devis']){ + if($facture['id_devis']) { $devis = json_decode($this->getOneDevis($facture['id_devis'], $idNextcloud))[0]; - $isDevisNegative = $this->isDevisNegative($facture['id_devis'],$devis->clientid); - if($isDevisNegative){ + $isDevisNegative = $this->isDevisNegative($facture['id_devis'], $devis->clientid); + if($isDevisNegative) { $facturePrefix = "AVO"; } } - $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime,$factureNumber,$facturePrefix); + $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime, $factureNumber, $facturePrefix); $sql = "UPDATE ".$this->tableprefix.$table." SET `facture_number`= ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($factureNumber, $id)); $sql = "UPDATE ".$this->tableprefix.$table." SET $column = ?, `num`= ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($data, $fullFactureNumber, $id)); } - - } else if(strcmp($table, "facture")==0 && strcmp($column, "id_devis")==0) { - + + } elseif(strcmp($table, "facture") == 0 && strcmp($column, "id_devis") == 0) { + $facture = json_decode($this->getOneFacture($id, $idNextcloud))[0]; $devis = json_decode($this->getOneDevis(htmlentities(rtrim($data)), $idNextcloud))[0]; $sql = "UPDATE ".$this->tableprefix.$table." SET $column = ?, `date`= ?, `version`= ? WHERE `id` = ?"; $this->execSQLNoData($sql, array(htmlentities(rtrim($data)), $devis->date, html_entity_decode($devis->version),$id)); $facturePrefix = "FAC"; $factureNumber = $facture->facture_number; - $isDevisNegative = $this->isDevisNegative($devis->devisid,$devis->clientid); - if($isDevisNegative){ + $isDevisNegative = $this->isDevisNegative($devis->devisid, $devis->clientid); + if($isDevisNegative) { $facturePrefix = "AVO"; } $facturationDatetime = new Datetime($facture->date); - $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime,$factureNumber,$facturePrefix); + $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime, $factureNumber, $facturePrefix); $sql = "UPDATE ".$this->tableprefix.$table." SET `num`= ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($fullFactureNumber, $id)); - } else if(strcmp($table, "lieu")==0 && (strcmp($column, "latitude")==0 || strcmp($column, "longitude")==0)) { - + } elseif(strcmp($table, "lieu") == 0 && (strcmp($column, "latitude") == 0 || strcmp($column, "longitude") == 0)) { + $lieu = json_decode($this->getLieu($id, $idNextcloud))[0]; - if(floatval($data)!=0) { + if(floatval($data) != 0) { $sql = "UPDATE ".$this->tableprefix.$table." SET $column = ? WHERE `id` = ?"; - $this->execSQLNoData($sql, array(htmlentities(rtrim(floatval($data))), $id)); + $this->execSQLNoData($sql, array(htmlentities(rtrim(floatval($data))), $id)); $lieu = json_decode($this->getLieu($id, $idNextcloud))[0]; - if(floatval($lieu->latitude)!=0 && floatval($lieu->longitude)!=0) { + if(floatval($lieu->latitude) != 0 && floatval($lieu->longitude) != 0) { $adresse = $this->recuperer_adresse(floatval($lieu->latitude), floatval($lieu->longitude)); $sql = "UPDATE ".$this->tableprefix.$table." SET adresse = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($adresse, $id)); } } - - } else if(strcmp($table, "devis")==0 && (strcmp($column, "id_lieu")==0 || strcmp($column, "date")==0 || strcmp($column, "id_client")==0 || strcmp($column, "id_thanato")==0)) { + + } elseif(strcmp($table, "devis") == 0 && (strcmp($column, "id_lieu") == 0 || strcmp($column, "date") == 0 || strcmp($column, "id_client") == 0 || strcmp($column, "id_thanato") == 0)) { $devis = json_decode($this->getOneDevis($id, $idNextcloud))[0]; $this->update_lieu_date_devis($devis, $column, htmlentities(rtrim($data)), $idNextcloud); - - } else if(strcmp($table, "ligne_trajet")==0 && (strcmp($column, "id_devis")==0 || strcmp($column, "date")==0 || strcmp($column, "id_lieu")==0 || strcmp($column, "rang")==0)) { + + } elseif(strcmp($table, "ligne_trajet") == 0 && (strcmp($column, "id_devis") == 0 || strcmp($column, "date") == 0 || strcmp($column, "id_lieu") == 0 || strcmp($column, "rang") == 0)) { $ligne_trajet = json_decode($this->getOneTrajetdetails($id, $idNextcloud))[0]; $this->update_lieu_date_devis_rang_ligneTrajet($ligne_trajet, $column, htmlentities(rtrim($data)), $idNextcloud); - } - else if(strcmp($table,"produit_devis") == 0 && (strcmp($column,"quantite") == 0)){ + } elseif(strcmp($table, "produit_devis") == 0 && (strcmp($column, "quantite") == 0)) { $sql = "UPDATE ".$this->tableprefix.$table." SET $column = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array(trim(string: $data), $id)); $produitDevis = $this->getProduitDevisById($id); - if($produitDevis){ + if($produitDevis) { $devisId = $produitDevis['devis_id']; $devis = json_decode($this->getOneDevis($devisId, $idNextcloud))[0]; - if($devis){ + if($devis) { $facture = $this->getFactureByDevisId($devisId); - $isDevisNegative = $this->isDevisNegative($devisId,$devis->clientid); - if($isDevisNegative){ + $isDevisNegative = $this->isDevisNegative($devisId, $devis->clientid); + if($isDevisNegative) { $factureNumber = $facture["facture_number"]; $facturePrefix = "AVO"; $facturationDatetime = new Datetime($facture["date"]); - $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime,$factureNumber,$facturePrefix); + $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime, $factureNumber, $facturePrefix); $sql = "UPDATE ".$this->tableprefix."facture SET `num`= ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($fullFactureNumber, $facture['id'])); } } } - } - else { + } else { $sql = "UPDATE ".$this->tableprefix.$table." SET $column = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array(trim($data), $id)); } @@ -1840,7 +1952,8 @@ class Bdd { return false; } - public function init_trajets_data($idNextcloud) { + public function init_trajets_data($idNextcloud) + { // supprimer d'abord les lignes de trajet ainsi que les trajets existants $sqldeletelignetrajet = "DELETE FROM ".$this->tableprefix."ligne_trajet;"; @@ -1852,25 +1965,27 @@ class Bdd { // $all_devis = json_decode($this->getDevisEmmanuelle($idNextcloud)); $all_devis = json_decode($this->getDevis($idNextcloud)); foreach ($all_devis as $key => $devis) { - if($devis->id_lieu != NULL) { + if($devis->id_lieu != null) { $this->update_lieu_date_devis($devis, 'id_lieu', $devis->id_lieu, $idNextcloud); } } } - public function createDevisTrajetFromVCalendar($devisId,$idNextcloud = "admin"){ + public function createDevisTrajetFromVCalendar($devisId, $idNextcloud = "admin") + { $devis = json_decode($this->getOneDevis($devisId, $idNextcloud))[0]; $this->generate_ligneTrajet($devis, $idNextcloud); $ligne_trajet = json_decode(json: $this->getOneTrajetdetails_byIdDevis($devis->devisid, $idNextcloud))[0]; - $this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud,$devis->devisid); + $this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud, $devis->devisid); $this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud); } /** * update lieu et date devis */ - public function update_lieu_date_devis($devis, $column, $data, $idNextcloud) { + public function update_lieu_date_devis($devis, $column, $data, $idNextcloud) + { $ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($devis->devisid, $idNextcloud))[0]; switch ($column) { @@ -1879,13 +1994,13 @@ class Bdd { $this->execSQLNoData($sql, array($data, $devis->devisid)); $updated_devis = json_decode($this->getOneDevis($devis->devisid, $idNextcloud))[0]; - if($ligne_trajet != NULL) { // si il existe déja une ligne trajet + if($ligne_trajet != null) { // si il existe déja une ligne trajet $sql = "UPDATE ".$this->tableprefix."ligne_trajet SET $column = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($data, $ligne_trajet->id)); $this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud); $this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud); } else { - if($updated_devis->id_lieu!=0) { + if($updated_devis->id_lieu != 0) { // ajouter le devis dans trajet s'il n'existe pas encore $this->generate_ligneTrajet($updated_devis, $idNextcloud); $ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($updated_devis->devisid, $idNextcloud))[0]; @@ -1900,10 +2015,12 @@ class Bdd { $this->execSQLNoData($sql, array($data, $devis->devisid)); $updated_devis = json_decode($this->getOneDevis($devis->devisid, $idNextcloud))[0]; - if($devis->id_lieu!=NULL) { + if($devis->id_lieu != null) { if(strcmp(explode('-', $devis->date)[1], explode('-', $updated_devis->date)[1]) != 0) { // si le mois a changé // deplacer la ligne de trajet - if($ligne_trajet != NULL) $this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud); + if($ligne_trajet != null) { + $this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud); + } $this->generate_ligneTrajet($updated_devis, $idNextcloud); @@ -1912,7 +2029,7 @@ class Bdd { $this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud); } else { // mettre a jour ligne_trajet - if($ligne_trajet != NULL) { + if($ligne_trajet != null) { $sql = "UPDATE ".$this->tableprefix."ligne_trajet SET $column = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($data, $ligne_trajet->id)); $this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud); @@ -1921,20 +2038,20 @@ class Bdd { } } break; - + case 'id_lieu': // mettre a jour devis et ligne_trajet $sql = "UPDATE ".$this->tableprefix."devis SET $column = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($data, $devis->devisid)); $updated_devis = json_decode($this->getOneDevis($devis->devisid, $idNextcloud))[0]; - if($ligne_trajet != NULL) { + if($ligne_trajet != null) { $sql = "UPDATE ".$this->tableprefix."ligne_trajet SET $column = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($data, $ligne_trajet->id)); $this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud); $this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud); } else { - if($updated_devis->id_lieu!=0 && $updated_devis->id_thanato!=0) { + if($updated_devis->id_lieu != 0 && $updated_devis->id_thanato != 0) { // ajouter le devis dans trajet s'il n'existe pas encore $this->generate_ligneTrajet($updated_devis, $idNextcloud); $ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($updated_devis->devisid, $idNextcloud))[0]; @@ -1943,14 +2060,14 @@ class Bdd { } } break; - + case 'id_thanato': // mettre a jour devis et ligne_trajet $sql = "UPDATE ".$this->tableprefix."devis SET $column = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($data, $devis->devisid)); $updated_devis = json_decode($this->getOneDevis($devis->devisid, $idNextcloud))[0]; - - if($ligne_trajet != NULL) { + + if($ligne_trajet != null) { $this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud); } $this->generate_ligneTrajet($updated_devis, $idNextcloud); @@ -1961,7 +2078,8 @@ class Bdd { } } - public function update_lieu_date_devis_rang_ligneTrajet($ligne_trajet, $column, $data, $idNextcloud) { + public function update_lieu_date_devis_rang_ligneTrajet($ligne_trajet, $column, $data, $idNextcloud) + { switch ($column) { case 'id_devis': @@ -1986,9 +2104,9 @@ class Bdd { break; case 'rang': $ligneTrajet_surLeRang = json_decode($this->getOneTrajetdetails_byRang($ligne_trajet->id_trajet, $data, $idNextcloud))[0]; - if($ligneTrajet_surLeRang != NULL) { + if($ligneTrajet_surLeRang != null) { $this->update_ligneTrajet('ligne_trajet', 'rang', intval($data), $ligne_trajet->id, $idNextcloud); - $this->update_ligneTrajet('ligne_trajet', 'rang', intval($data)+1, $ligneTrajet_surLeRang->id, $idNextcloud); + $this->update_ligneTrajet('ligne_trajet', 'rang', intval($data) + 1, $ligneTrajet_surLeRang->id, $idNextcloud); $this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud); $this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud); } else { @@ -2003,13 +2121,14 @@ class Bdd { /** * generer une ligne de trajet par un devis */ - public function generate_ligneTrajet($devis, $idNextcloud) { + public function generate_ligneTrajet($devis, $idNextcloud) + { $date_devis_split = explode('-', $devis->date); // creer le trajet s'il n'existe pas $trajet = json_decode($this->getOneTrajet_byThanatoMonthYear($devis->id_thanato, $date_devis_split[1], $date_devis_split[0]))[0]; - if($trajet == NULL) { + if($trajet == null) { $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]; } @@ -2021,16 +2140,17 @@ class Bdd { * 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,$devisId = 0) { + public function range_ligneTrajet($id_trajet, $idNextcloud, $devisId = 0) + { $lignes = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud)); $nb_jour = 0; - if(sizeof($lignes)>0) { + if(sizeof($lignes) > 0) { $nb_jour = 1; - $dates = array(0=>$lignes[0]->date); + $dates = array(0 => $lignes[0]->date); $date_temp = $lignes[0]->date; foreach ($lignes as $key => $ligne) { - if(strcmp($date_temp, string2: $ligne->date)!=0) { + if(strcmp($date_temp, string2: $ligne->date) != 0) { $date_temp = $ligne->date; array_push($dates, $date_temp); $nb_jour++; @@ -2038,9 +2158,9 @@ class Bdd { } // on verifie si le nombre de ligne ets correspond à 2*nb_jour (debut et fin de journee) - $reste = (2*$nb_jour) - (sizeof(array_filter($lignes, function($ligne) {return strcmp($ligne->source,'siege')==0;}))); - while ($reste>0) { - $this->insertTrajetdetails_h2f($id_trajet, $lignes[0]->date, $idNextcloud,$idNextcloud,$devisId); + $reste = (2 * $nb_jour) - (sizeof(array_filter($lignes, function ($ligne) {return strcmp($ligne->source, 'siege') == 0;}))); + while ($reste > 0) { + $this->insertTrajetdetails_h2f($id_trajet, $lignes[0]->date, $idNextcloud, $idNextcloud, $devisId); $reste--; } @@ -2049,56 +2169,66 @@ class Bdd { // 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,'siege')==0) array_push($array_siege, $ligne); + if(strcmp($ligne->source, 'siege') == 0) { + array_push($array_siege, $ligne); + } } - - $j=0; - for ($i=0; $i < sizeof($dates); $i++) { + + $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; + $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); + $this->update_ligneTrajet('ligne_trajet', 'rang', $key + 1, $line->id, $idNextcloud); } } } - public function update_ligneTrajet($table, $column, $data, $id, $idNextcloud){ + public function update_ligneTrajet($table, $column, $data, $id, $idNextcloud) + { - - if(in_array($table, $this->whiteTable) && in_array($column, $this->whiteColumn)){ + + if(in_array($table, $this->whiteTable) && in_array($column, $this->whiteColumn)) { $sql = "UPDATE ".$this->tableprefix.$table." SET $column = ? WHERE `id` = ?"; $this->execSQLNoData($sql, array($data, $id)); } } - public function calculer_distance_trajet($numtrajet, $idNextcloud) { + public function calculer_distance_trajet($numtrajet, $idNextcloud) + { $trajetdetails = json_decode($this->getTrajetsdetails_orderByDate($numtrajet, $idNextcloud)); $distance_temp = 0; $distances = array(); - $last_point = NULL; - for ($i=0; $i < sizeof($trajetdetails); $i++) { - if(strcmp(explode('-', $trajetdetails[$i]->date)[2], explode('-', $trajetdetails[$i+1]->date)[2])!=0) { + $last_point = null; + for ($i = 0; $i < sizeof($trajetdetails); $i++) { + if(strcmp(explode('-', $trajetdetails[$i]->date)[2], explode('-', $trajetdetails[$i + 1]->date)[2]) != 0) { array_push($distances, $distance_temp); $distance_temp = 0; - $last_point = NULL; + $last_point = null; } else { - if($trajetdetails[$i]->lid != NULL) $last_point = $trajetdetails[$i]; - if($last_point->lid != NULL && $trajetdetails[$i+1]->lid != NULL) $distance_temp += $this->calcul_distance(floatval($last_point->latitude), floatval($last_point->longitude), floatval($trajetdetails[$i+1]->latitude), floatval($trajetdetails[$i+1]->longitude)); + if($trajetdetails[$i]->lid != null) { + $last_point = $trajetdetails[$i]; + } + if($last_point->lid != null && $trajetdetails[$i + 1]->lid != null) { + $distance_temp += $this->calcul_distance(floatval($last_point->latitude), floatval($last_point->longitude), floatval($trajetdetails[$i + 1]->latitude), floatval($trajetdetails[$i + 1]->longitude)); + } } } - if(sizeof($trajetdetails)>1 && sizeof($distances)==0) array_push($distances, $distance_temp); + if(sizeof($trajetdetails) > 1 && sizeof($distances) == 0) { + array_push($distances, $distance_temp); + } @@ -2111,7 +2241,8 @@ class Bdd { $this->execSQLNoData($sql, array($distance_final, $numtrajet)); } - public function getOneTrajet_byThanatoMonthYear($id_thanato, $mois, $annee) { + public function getOneTrajet_byThanatoMonthYear($id_thanato, $mois, $annee) + { $sql = "SELECT " . $this->tableprefix . "trajet.id, " . $this->tableprefix . "trajet.distance, " . $this->tableprefix . "trajet.date, " . $this->tableprefix . "trajet.mois, " . $this->tableprefix . "trajet.annee FROM " . $this->tableprefix . "trajet @@ -2119,7 +2250,8 @@ class Bdd { return $this->execSQL($sql, array()); } - public function recuperer_adresse($latitude, $longitude) { + public function recuperer_adresse($latitude, $longitude) + { $curl = curl_init(); @@ -2150,13 +2282,14 @@ class Bdd { /** * Calcul la distance entre les deux points à vol d'oiseau */ - public function calcul_distance($lat1, $lon1, $lat2, $lon2) { + public function calcul_distance($lat1, $lon1, $lat2, $lon2) + { $R = 6371; // Rayon moyen de la Terre en kilomètres $dLat = deg2rad($lat2 - $lat1); $dLon = deg2rad($lon2 - $lon1); - $a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2) * sin($dLon/2); - $c = 2 * atan2(sqrt($a), sqrt(1-$a)); + $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon / 2) * sin($dLon / 2); + $c = 2 * atan2(sqrt($a), sqrt(1 - $a)); $d = $R * $c; return round($d, 2); } @@ -2164,7 +2297,8 @@ class Bdd { /** * Verification si la valeur d'un coordonnees est valide */ - private function is_valid_gps($latitude, $longitude) { + private function is_valid_gps($latitude, $longitude) + { // Vérifie si les valeurs sont des nombres décimaux valides entre -90 et 90 pour la latitude et -180 et 180 pour la longitude if (is_numeric($latitude) && is_numeric($longitude) && $latitude >= -90 && $latitude <= 90 && $longitude >= -180 && $longitude <= 180) { @@ -2177,10 +2311,11 @@ class Bdd { /** * DELETE */ - public function gestion_delete($table, $id, $idNextcloud){ + public function gestion_delete($table, $id, $idNextcloud) + { - if(in_array($table, $this->whiteTable)){ - if(strcmp($table, "ligne_trajet")==0) { + if(in_array($table, $this->whiteTable)) { + if(strcmp($table, "ligne_trajet") == 0) { $distance = 0; $ligne_trajet = json_decode($this->getOneTrajetdetails($id, $idNextcloud))[0]; @@ -2204,13 +2339,16 @@ class Bdd { * Check * TODO Translation */ - public function checkConfig($idNextcloud){ + public function checkConfig($idNextcloud) + { $sql = "SELECT count(*) as res FROM `".$this->tableprefix."configuration` WHERE `id_nextcloud` = ?"; $res = json_decode($this->execSQL($sql, array($idNextcloud)))[0]->res; - if ( $res < 1 ){ + if ($res < 1) { $sql = "INSERT INTO `".$this->tableprefix."configuration` (`entreprise`, `nom`, `prenom`, `legal_one`, `legal_two`, `mail`, `telephone`, `adresse`, `path`, `id_nextcloud`,`mentions_default`,`tva_default`,`devise`,`facture_prefixe`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, '', ?, ?, '0',?,?);"; - $this->execSQLNoData($sql, array($this->l->t('Your company name'), + $this->execSQLNoData( + $sql, + array($this->l->t('Your company name'), $this->l->t('Your company contact last name'), @@ -2225,12 +2363,13 @@ class Bdd { $this->l->t('EUR'), $this->l->t('INVOICE') ) - ); + ); } return $res; } - public function isConfig($idNextcloud){ + public function isConfig($idNextcloud) + { $changelog = 9; //+1 if you want changelog appear for everybody one time ! @@ -2238,16 +2377,16 @@ class Bdd { $res = json_decode($this->execSQL($sql, array($idNextcloud)))[0]->res; // Utilisateur jamais utilisé l'application - if ( $res < 1 ){ + if ($res < 1) { return false; - }else{ + } else { $sql = "SELECT id as id, changelog as res FROM `".$this->tableprefix."configuration` WHERE `id_nextcloud` = ?"; $res = json_decode($this->execSQL($sql, array($idNextcloud)))[0]->res; $id = json_decode($this->execSQL($sql, array($idNextcloud)))[0]->id; - if($res < $changelog){ - $this->gestion_update("configuration","changelog",$changelog,$id,$idNextcloud); + if($res < $changelog) { + $this->gestion_update("configuration", "changelog", $changelog, $id, $idNextcloud); return false; - }else{ + } else { return true; } } @@ -2256,7 +2395,8 @@ class Bdd { /** * Number client */ - public function numberClient($idNextcloud){ + public function numberClient($idNextcloud) + { // $sql = "SELECT count(*) as c from ".$this->tableprefix."client WHERE `id_nextcloud` = ?;"; $sql = "SELECT count(*) as c from ".$this->tableprefix."client;"; @@ -2267,7 +2407,8 @@ class Bdd { /** * Number thanatopracteur */ - public function numberThanato($idNextcloud){ + public function numberThanato($idNextcloud) + { // $sql = "SELECT count(*) as c from ".$this->tableprefix."thanato WHERE `id_nextcloud` = ?;"; $sql = "SELECT count(*) as c from ".$this->tableprefix."thanato;"; @@ -2278,7 +2419,8 @@ class Bdd { /** * Number devis */ - public function numberDevis($idNextcloud){ + public function numberDevis($idNextcloud) + { // $sql = "SELECT count(*) as c from ".$this->tableprefix."devis WHERE `id_nextcloud` = ? AND `mentions` NOT LIKE 'facturé';"; // $sql = "SELECT count(*) as c from ".$this->tableprefix."devis WHERE `mentions` NOT LIKE 'facturé';"; @@ -2287,11 +2429,12 @@ class Bdd { // return $this->execSQL($sql, array($idNextcloud)); return $this->execSQL($sql, array()); } - + /** * Number facture */ - public function numberFacture($idNextcloud){ + public function numberFacture($idNextcloud) + { // $sql = "SELECT count(*) as c from ".$this->tableprefix."facture WHERE `id_nextcloud` = ?;"; $sql = "SELECT count(*) as c from ".$this->tableprefix."facture;"; @@ -2302,7 +2445,8 @@ class Bdd { /** * Number lieu */ - public function numberLieu($idNextcloud){ + public function numberLieu($idNextcloud) + { $sql = "SELECT count(*) as c from ".$this->tableprefix."lieu;"; return $this->execSQL($sql, array()); @@ -2311,7 +2455,8 @@ class Bdd { /** * Number trajet */ - public function numberTrajet($idNextcloud){ + public function numberTrajet($idNextcloud) + { $sql = "SELECT count(*) as c from ".$this->tableprefix."trajet;"; return $this->execSQL($sql, array()); @@ -2320,7 +2465,8 @@ class Bdd { /** * Number produit */ - public function numberProduit($idNextcloud){ + public function numberProduit($idNextcloud) + { // $sql = "SELECT count(*) as c from ".$this->tableprefix."produit WHERE `id_nextcloud` = ?;"; $sql = "SELECT count(*) as c from ".$this->tableprefix."produit;"; @@ -2331,7 +2477,8 @@ class Bdd { /** * Number article */ - public function numberArticle($idNextcloud){ + public function numberArticle($idNextcloud) + { $sql = "SELECT count(*) as c from ".$this->tableprefix."article;"; return $this->execSQL($sql, array()); @@ -2340,19 +2487,19 @@ class Bdd { /** * Number défunt */ - public function numberDefunt($idNextcloud, $isUserThanatoOnly = false){ + public function numberDefunt($idNextcloud, $isUserThanatoOnly = false) + { $defuntCount = 0; - if($isUserThanatoOnly == false){ + if($isUserThanatoOnly == false) { $sql = "SELECT count(*) as c from ".$this->tableprefix."defunt;"; $defuntCountBythanato = $this->execSQLNoJsonReturn($sql, array()); - if(!empty($defuntCountBythanato)){ + if(!empty($defuntCountBythanato)) { $defuntCount = $defuntCountBythanato[0]['c']; } - } - else{ + } else { $thanato = $this->getThanatoByIdNextcloud($idNextcloud); - if($thanato != null){ + if($thanato != null) { $thanatoId = $thanato["id"]; $defuntsIdRelatedToThanato = $this->getDefuntIdsRelatedToThanato($thanatoId); $defuntCount = count($defuntsIdRelatedToThanato); @@ -2364,13 +2511,15 @@ class Bdd { /** * Number bibliotheque */ - public function numberBibliotheque($idNextcloud){ + public function numberBibliotheque($idNextcloud) + { $sql = "SELECT count(*) as c from ".$this->tableprefix."bibliotheque;"; return $this->execSQL($sql, array()); } - public function retrieveTotalInvoicesForTheYear(){ + public function retrieveTotalInvoicesForTheYear() + { $sql = "SELECT EXTRACT(YEAR FROM devis.date) AS y, @@ -2398,9 +2547,9 @@ class Bdd { EXTRACT(MONTH FROM devis.`date`) ORDER BY EXTRACT(YEAR FROM devis.`date`) DESC, - EXTRACT(MONTH FROM devis.`date`);"; + EXTRACT(MONTH FROM devis.`date`);"; - return $this->execSQL($sql, [ + return $this->execSQL($sql, [ DevisMentionConstant::FACTURED, DevisMentionConstant::FACTURED_FORMATTED ]); @@ -2409,7 +2558,8 @@ class Bdd { /** * Annual turnover per month without VAT */ - public function getAnnualTurnoverPerMonthNoVat($idNextcloud){ + public function getAnnualTurnoverPerMonthNoVat($idNextcloud) + { $sql = "SELECT EXTRACT(YEAR FROM facture.date_paiement) AS y, @@ -2441,7 +2591,8 @@ class Bdd { return $this->execSQLNoJsonReturn($sql, array()); } - public function getStatArticleAnnuel($idNextcloud, $annee) { + public function getStatArticleAnnuel($idNextcloud, $annee) + { $sql = "SELECT p.id, p.reference, COALESCE(SUM(CASE WHEN MONTH(d.date) = 1 THEN pd.quantite ELSE 0 END), 0) AS janvier, @@ -2468,7 +2619,8 @@ class Bdd { ]); } - public function getStatSoinsThanatoAnnuel($idNextcloud, $annee) { + public function getStatSoinsThanatoAnnuel($idNextcloud, $annee) + { $sql = "SELECT thanato.nom AS nom_thanato, @@ -2498,7 +2650,8 @@ class Bdd { ]); } - public function getStatSoinsThanatoWeekend($idNextcloud, $annee, $mois) { + public function getStatSoinsThanatoWeekend($idNextcloud, $annee, $mois) + { /** * stat nombre de soins samedis et dimanches @@ -2543,60 +2696,64 @@ class Bdd { /** * Get last insert id */ - public function lastinsertid($table,$idNextcloud){ + public function lastinsertid($table, $idNextcloud) + { // $sql = "SELECT max(user_id) as LAST_INSERT_ID FROM `" . $this->tableprefix . $table . "` WHERE " . $this->tableprefix . $table .".id_nextcloud = ?;"; // $res = $this->execSQLNoJsonReturn($sql,array($idNextcloud)); $sql = "SELECT max(user_id) as LAST_INSERT_ID FROM `" . $this->tableprefix . $table. "`;"; - $res = $this->execSQLNoJsonReturn($sql,array()); + $res = $this->execSQLNoJsonReturn($sql, array()); return $res[0]['LAST_INSERT_ID']; } - public function lastNumFacture($idNextcloud) { + public function lastNumFacture($idNextcloud) + { $lastFactureId = $this->getLastFactureId(); return $lastFactureId; } - private function getLastFactureId(){ + private function getLastFactureId() + { $sql = "SELECT - max(facture.id) as LAST_FACTURE_ID FROM " + max(facture.id) as LAST_FACTURE_ID FROM " . $this->tableprefix."facture as facture;"; - $res = $this->execSQLNoJsonReturn($sql,[]); + $res = $this->execSQLNoJsonReturn($sql, []); $lastId = 0; - if(!empty($res)){ + if(!empty($res)) { $lastId = $res[0]['LAST_FACTURE_ID']; } return $lastId; } - public function backup(){ + public function backup() + { $res = array(); $res[] = array("===client==="); $sql = "SELECT * FROM ".$this->tableprefix."client"; $res = array_merge($res, $this->execSQLNoJsonReturn($sql, array())); - + $res[] = array("===devis==="); $sql = "SELECT * FROM ".$this->tableprefix."devis"; - $res = array_merge($res,$this->execSQLNoJsonReturn($sql, array())); + $res = array_merge($res, $this->execSQLNoJsonReturn($sql, array())); $res[] = array("===facture==="); $sql = "SELECT * FROM ".$this->tableprefix."facture"; - $res = array_merge($res,$this->execSQLNoJsonReturn($sql, array())); + $res = array_merge($res, $this->execSQLNoJsonReturn($sql, array())); $res[] = array("===produit==="); $sql = "SELECT * FROM ".$this->tableprefix."produit"; - $res = array_merge($res,$this->execSQLNoJsonReturn($sql, array())); + $res = array_merge($res, $this->execSQLNoJsonReturn($sql, array())); $res[] = array("===produit_devis==="); $sql = "SELECT * FROM ".$this->tableprefix."produit_devis"; - $res = array_merge($res,$this->execSQLNoJsonReturn($sql, array())); + $res = array_merge($res, $this->execSQLNoJsonReturn($sql, array())); $res[] = array("===configuration==="); $sql = "SELECT * FROM ".$this->tableprefix."configuration"; - $res = array_merge($res,$this->execSQLNoJsonReturn($sql, array())); + $res = array_merge($res, $this->execSQLNoJsonReturn($sql, array())); return $res; } @@ -2605,7 +2762,8 @@ class Bdd { * @sql * @array() //prepare statement */ - private function execSQL($sql, $conditions){ + private function execSQL($sql, $conditions) + { $stmt = $this->pdo->prepare($sql); $stmt->execute($conditions); @@ -2614,14 +2772,16 @@ class Bdd { return json_encode($data); } - private function execSQLNoData($sql, $conditions){ + private function execSQLNoData($sql, $conditions) + { $stmt = $this->pdo->prepare($sql); $stmt->execute($conditions); $stmt->closeCursor(); } - private function execSQLNoJsonReturn($sql, $conditions){ + private function execSQLNoJsonReturn($sql, $conditions) + { $stmt = $this->pdo->prepare($sql); $stmt->execute($conditions); @@ -2630,7 +2790,8 @@ class Bdd { return $data; } - private function getThanatoDevisListByDate($thanatoId,$date){ + private function getThanatoDevisListByDate($thanatoId, $date) + { $dateFormatted = $date->format('Y-m-d'); $sql = "SELECT @@ -2665,38 +2826,42 @@ class Bdd { (devis.mentions = ? OR devis.mentions = ?) ORDER BY devis.date ASC;"; $devisList = $this->execSQLNoJsonReturn( - $sql, - [$dateFormatted,$thanatoId,DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED]); + $sql, + [$dateFormatted,$thanatoId,DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED] + ); return $devisList; } - public function getThanatoById($thanatoId){ + public function getThanatoById($thanatoId) + { $sql = "SELECT id, nom, prenom,fk_user_uuid FROM ".$this->tableprefix."thanato WHERE id = ? LIMIT 1;"; - $thanato = $this->execSQLNoJsonReturn($sql,[$thanatoId]); - if(!empty($thanato)){ + $thanato = $this->execSQLNoJsonReturn($sql, [$thanatoId]); + if(!empty($thanato)) { return $thanato[0]; } return null; } - private function getCalendarByThanatoIdNextcloud($idNextCloud){ + private function getCalendarByThanatoIdNextcloud($idNextCloud) + { $searchString = "%principals/users/$idNextCloud%"; $sql = "SELECT * FROM ".self::DEFAULT_TABLE_PREFIX."calendars as calendar WHERE calendar.principaluri LIKE ? LIMIT 1;"; - $calendar = $this->execSQLNoJsonReturn($sql,[$searchString]); - if(!empty($calendar)){ + $calendar = $this->execSQLNoJsonReturn($sql, [$searchString]); + if(!empty($calendar)) { return $calendar[0]; } return null; } - - private function getThanatoLeaveByCalendarAndDate($calendarId,$date){ + + private function getThanatoLeaveByCalendarAndDate($calendarId, $date) + { $isLeaveConditionAsString = "ABSENCETYPE:"; - + $datetimeFormatted = $date->format('Ymd'); $dateCondition = "%DTSTART%".$datetimeFormatted."%"; $conditions = []; @@ -2716,76 +2881,77 @@ class Bdd { calendarobject.calendardata LIKE ? AND calendarobject.deleted_at IS NULL AND (" . implode(" OR ", $conditions) . ");"; - $leaves = $this->execSQLNoJsonReturn($sql,$params); + $leaves = $this->execSQLNoJsonReturn($sql, $params); return $leaves; } - - public function getThanatoDevisPerDateInAMonthYear($thanatoId,$month,$year){ - $dateOfMonths = DateHelpers::getDatesOfMonth($year,$month); + public function getThanatoDevisPerDateInAMonthYear($thanatoId, $month, $year) + { + + $dateOfMonths = DateHelpers::getDatesOfMonth($year, $month); $devisListPerThanatoPerDate = []; $thanato = $this->getThanatoById($thanatoId); $thanatoName = $thanato["nom"]; $thanatoCalendar = $this->getCalendarByThanatoIdNextcloud($thanato["fk_user_uuid"] ?? $thanato["nom"]); - if($thanatoCalendar == null){ + if($thanatoCalendar == null) { return []; } $thanatoCalendarId = $thanatoCalendar["id"]; - foreach($dateOfMonths as $currentDate){ + foreach($dateOfMonths as $currentDate) { $currentDateFormatted = $currentDate->format('Y-m-d'); $isPublicHoliday = DateHelpers::isPublicHoliday($currentDateFormatted); - $devisList = $this->getThanatoDevisListByDate($thanatoId,$currentDate); + $devisList = $this->getThanatoDevisListByDate($thanatoId, $currentDate); $thereIsNoDevisForCurrentDate = empty($devisList); - if($thereIsNoDevisForCurrentDate){ + if($thereIsNoDevisForCurrentDate) { $devisListPerThanatoPerDate[$currentDateFormatted]["hasDevis"] = false; - $thanatoLeavesThisDay = $this->getThanatoLeaveByCalendarAndDate($thanatoCalendarId,$currentDate); - if(empty($thanatoLeavesThisDay)){ + $thanatoLeavesThisDay = $this->getThanatoLeaveByCalendarAndDate($thanatoCalendarId, $currentDate); + if(empty($thanatoLeavesThisDay)) { $devisListPerThanatoPerDate[$currentDateFormatted]["leaves"][] = [ "onLeave" => false, "startTime" => null, "endTime" => null, - "thanatoName"=>$thanatoName, + "thanatoName" => $thanatoName, "date" => $currentDateFormatted, "totalHours" => 0, "totalWorkedHours" => 8, "isPublicHoliday" => $isPublicHoliday ]; - } - else{ - foreach($thanatoLeavesThisDay as $currentLeave){ + } else { + foreach($thanatoLeavesThisDay as $currentLeave) { $leaveTime = VCalendarHelpers::GetStartAndEndTimeFromVCalendarString($currentLeave['calendardata']); - $absenceType = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::ABSENCE_TYPE,$currentLeave['calendardata']); + $absenceType = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::ABSENCE_TYPE, $currentLeave['calendardata']); $absenceTypeKey = null; $absenceTypeLabel = null; - if($absenceType){ + if($absenceType) { $absenceTypeKey = $absenceType; $absenceTypeLabel = FileExportHelpers::GetAbsenceTypeLabelFromKey($absenceType); - }else{ + } else { //get is leave - $isLeave = VCalendarHelpers::GetValueFromKeyInVCalendarString(BddConstant::ISLEAVEPROPERTYONVCALENDAR,$currentLeave['calendardata']); - if ( $isLeave ) { + $isLeave = VCalendarHelpers::GetValueFromKeyInVCalendarString(BddConstant::ISLEAVEPROPERTYONVCALENDAR, $currentLeave['calendardata']); + if ($isLeave) { $absenceTypeKey = AbsenceTypeConstant::LEAVE; - $absenceTypeLabel = VCalendarPropertyConstant::ABSENCE_TYPES_KEYS_VALUES[$absenceTypeKey]; ; + $absenceTypeLabel = VCalendarPropertyConstant::ABSENCE_TYPES_KEYS_VALUES[$absenceTypeKey]; + ; } } $startTimeValueWithMinutes = ""; $endTimeValueWithMinutes = ""; - if($leaveTime["datetimeStart"]){ + if($leaveTime["datetimeStart"]) { $startTimeValueWithMinutes = $leaveTime["datetimeStart"]->format('H\hi'); } - if($leaveTime["datetimeEnd"]){ + if($leaveTime["datetimeEnd"]) { $endTimeValueWithMinutes = $leaveTime["datetimeEnd"]->format('H\hi'); } - + $devisListPerThanatoPerDate[$currentDateFormatted]["leaves"][] = [ "onLeave" => true, "startTime" => $startTimeValueWithMinutes, "endTime" => $endTimeValueWithMinutes, - "thanatoName"=>$thanatoName, + "thanatoName" => $thanatoName, "date" => $currentDateFormatted, "totalHours" => $leaveTime["totalHours"], "totalWorkedHours" => $leaveTime["totalWorkedHours"], @@ -2795,9 +2961,8 @@ class Bdd { ]; } } - } - else{ - foreach($devisList as $devis){ + } else { + foreach($devisList as $devis) { $devis = $this->setDevisStartAndEndTime($devis); $devis = $this->setDevisIsPublicHolidayOrNotText($devis); $devis = $this->setDevisProduitsList($devis); @@ -2814,29 +2979,30 @@ class Bdd { $devisListPerThanatoPerDate[$currentDateFormatted]["devisId"][] = $devis['id']; } $devisListPerThanatoPerDate[$currentDateFormatted]["leaves"] = []; - $thanatoLeavesThisDay = $this->getThanatoLeaveByCalendarAndDate($thanatoCalendarId,$currentDate); - foreach($thanatoLeavesThisDay as $currentLeave){ + $thanatoLeavesThisDay = $this->getThanatoLeaveByCalendarAndDate($thanatoCalendarId, $currentDate); + foreach($thanatoLeavesThisDay as $currentLeave) { $leaveTime = VCalendarHelpers::GetStartAndEndTimeFromVCalendarString($currentLeave['calendardata']); $startTimeValueWithMinutes = ""; $endTimeValueWithMinutes = ""; - if($leaveTime["datetimeStart"]){ + if($leaveTime["datetimeStart"]) { $startTimeValueWithMinutes = $leaveTime["datetimeStart"]->format('H\hi'); } - if($leaveTime["datetimeEnd"]){ + if($leaveTime["datetimeEnd"]) { $endTimeValueWithMinutes = $leaveTime["datetimeEnd"]->format('H\hi'); } - $absenceType = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::ABSENCE_TYPE,$currentLeave['calendardata']); + $absenceType = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::ABSENCE_TYPE, $currentLeave['calendardata']); $absenceTypeKey = null; $absenceTypeLabel = null; - if($absenceType){ + if($absenceType) { $absenceTypeKey = $absenceType; $absenceTypeLabel = FileExportHelpers::GetAbsenceTypeLabelFromKey($absenceType); - }else{ + } else { //get is leave - $isLeave = VCalendarHelpers::GetValueFromKeyInVCalendarString(BddConstant::ISLEAVEPROPERTYONVCALENDAR,$currentLeave['calendardata']); - if ( $isLeave ) { + $isLeave = VCalendarHelpers::GetValueFromKeyInVCalendarString(BddConstant::ISLEAVEPROPERTYONVCALENDAR, $currentLeave['calendardata']); + if ($isLeave) { $absenceTypeKey = AbsenceTypeConstant::LEAVE; - $absenceTypeLabel = VCalendarPropertyConstant::ABSENCE_TYPES_KEYS_VALUES[$absenceTypeKey]; ; + $absenceTypeLabel = VCalendarPropertyConstant::ABSENCE_TYPES_KEYS_VALUES[$absenceTypeKey]; + ; } } @@ -2844,7 +3010,7 @@ class Bdd { "onLeave" => true, "startTime" => $startTimeValueWithMinutes, "endTime" => $endTimeValueWithMinutes, - "thanatoName"=>$thanatoName, + "thanatoName" => $thanatoName, "date" => $currentDateFormatted, "totalHours" => $leaveTime["totalHours"], "totalWorkedHours" => $leaveTime["totalWorkedHours"], @@ -2856,13 +3022,15 @@ class Bdd { return $devisListPerThanatoPerDate; } - public function getExportThanatoStatisticData($thanatoId,$month,$year){ + public function getExportThanatoStatisticData($thanatoId, $month, $year) + { - $devisList = $this->getThanatoDevisPerDateInAMonthYear($thanatoId,$month,$year); + $devisList = $this->getThanatoDevisPerDateInAMonthYear($thanatoId, $month, $year); return $devisList; } - public function getProduitsDevisByDevisId($devisId){ + public function getProduitsDevisByDevisId($devisId) + { $sql = "SELECT produit_devis.id as produit_devis_id, @@ -2873,24 +3041,26 @@ class Bdd { LEFT JOIN ".$this->tableprefix."produit as produit on produit_devis.produit_id = produit.id WHERE produit_devis.devis_id = ?;"; $produitsList = $this->execSQLNoJsonReturn( - $sql, - [$devisId]); + $sql, + [$devisId] + ); $finalProduitList = []; - foreach($produitsList as $produit){ - if($produit['produit_id'] != null){ + foreach($produitsList as $produit) { + if($produit['produit_id'] != null) { $finalProduitList[] = $produit; } } return $finalProduitList; } - private function getDevisListGroupedByDateAndThenByThanato(array $devisListPerDate){ + private function getDevisListGroupedByDateAndThenByThanato(array $devisListPerDate) + { $devisListGroupedByThanatoAndThenByDate = []; - foreach($devisListPerDate as $date => $devisList){ - foreach($devisList as $devis){ + foreach($devisListPerDate as $date => $devisList) { + foreach($devisList as $devis) { $devisDate = $devis["date"]; $devisThanatoId = $devis["id_thanato"]; $devis = $this->setDevisStartAndEndTime($devis); @@ -2914,10 +3084,11 @@ class Bdd { return $devisListGroupedByThanatoAndThenByDate; } - private function setDevisProduitsList($devis){ + private function setDevisProduitsList($devis) + { $produitsList = $this->getProduitsDevisByDevisId($devis['id']); - foreach($produitsList as $produit){ + foreach($produitsList as $produit) { if (!isset($devis['produits'])) { $devis['produits'] = []; } @@ -2926,23 +3097,25 @@ class Bdd { return $devis; } - private function setDevisIsPublicHolidayOrNotText($devis){ + private function setDevisIsPublicHolidayOrNotText($devis) + { $isPublicHoliday = DateHelpers::isPublicHoliday($devis['date']); $devis["dayType"] = DateHelpers::getPublicHolidayText($isPublicHoliday); return $devis; } - public function setDevisStartAndEndTime($devis){ + public function setDevisStartAndEndTime($devis) + { $calendarData = $this->getCalendarDataByCalendarObjectUuid($devis["calendar_uuid"]); $devisTimeValue = VCalendarHelpers::GetStartAndEndTimeFromVCalendarString($calendarData); $startTimeValueWithMinutes = ""; $endTimeValueWithMinutes = ""; - if($devisTimeValue["datetimeStart"]){ + if($devisTimeValue["datetimeStart"]) { $startTimeValueWithMinutes = $devisTimeValue["datetimeStart"]->format('H\hi'); } - if($devisTimeValue["datetimeEnd"]){ + if($devisTimeValue["datetimeEnd"]) { $endTimeValueWithMinutes = $devisTimeValue["datetimeEnd"]->format('H\hi'); } $devis["startTime"] = $startTimeValueWithMinutes; @@ -2952,9 +3125,10 @@ class Bdd { return $devis; } - public function getRouteLinesByDevisIdList(array $devisIdList){ + public function getRouteLinesByDevisIdList(array $devisIdList) + { - if(empty($devisIdList)){ + if(empty($devisIdList)) { return []; } $sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisIdList), '?')); @@ -2968,12 +3142,13 @@ class Bdd { return $this->execSQLNoJsonReturn($sql, $devisIdList); } - private function getDevisListByThanatoIds(array $thanatoIds){ + private function getDevisListByThanatoIds(array $thanatoIds) + { - if(empty($thanatoIds)){ + if(empty($thanatoIds)) { return []; } - $currentYear = date('Y'); + $currentYear = date('Y'); $currentMonth = date('m'); $sqlConditionsPlaceholder = implode(',', array_fill(0, count($thanatoIds), '?')); @@ -3008,17 +3183,19 @@ class Bdd { (devis.mentions = ? OR devis.mentions = ?) ORDER BY devis.date ASC;"; $devisList = $this->execSQLNoJsonReturn( - $sql, - array_merge([$currentYear, $currentMonth],$thanatoIds,[DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED])); + $sql, + array_merge([$currentYear, $currentMonth], $thanatoIds, [DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED]) + ); return $devisList; } - public function getCalendarDataByCalendarObjectUuid(string $calendarObjectUuid){ + public function getCalendarDataByCalendarObjectUuid(string $calendarObjectUuid) + { $sql = "SELECT * FROM ".self::DEFAULT_TABLE_PREFIX."calendarobjects WHERE uid = ?;"; $calendarObjectList = $this->execSQLNoJsonReturn($sql, [$calendarObjectUuid]); - if(!empty($calendarObjectList)){ + if(!empty($calendarObjectList)) { $calendarDataBlob = $calendarObjectList[0]['calendardata']; $calendarDataString = VCalendarHelpers::ReadVCalendarDataBlob($calendarDataBlob); return $calendarDataString; @@ -3026,65 +3203,72 @@ class Bdd { return ""; } - public function getCalendarPrincipalNameByCalendarId($calendarId){ + public function getCalendarPrincipalNameByCalendarId($calendarId) + { $calendar = $this->getCalendarById($calendarId); - if($calendar != null){ + if($calendar != null) { $principalUri = $calendar["principaluri"]; - $organizerName = str_replace('principals/users/','',$principalUri); + $organizerName = str_replace('principals/users/', '', $principalUri); $organizerName = trim($organizerName); return $organizerName; } return null; } - public function getCalendarOrganizerNameByCalendarObjectUuid(string $calendarObjectUuid){ + public function getCalendarOrganizerNameByCalendarObjectUuid(string $calendarObjectUuid) + { $calendarObject = $this->getCalendarObjectByUuid($calendarObjectUuid); - if($calendarObject != null){ + if($calendarObject != null) { return $this->getCalendarPrincipalNameByCalendarId($calendarObject['calendarid']); } return null; } - public function getCalendarObjectByUuid(string $calendarObjectUuid){ + public function getCalendarObjectByUuid(string $calendarObjectUuid) + { $sql = "SELECT * FROM ".self::DEFAULT_TABLE_PREFIX."calendarobjects WHERE uid = ?;"; $calendarObjectList = $this->execSQLNoJsonReturn($sql, [$calendarObjectUuid]); - if(!empty($calendarObjectList)){ + if(!empty($calendarObjectList)) { $calendarData = $calendarObjectList[0]; return $calendarData; } return null; } - public function getCalendarById(int $calendarId){ + public function getCalendarById(int $calendarId) + { $sql = "SELECT * FROM ".self::DEFAULT_TABLE_PREFIX."calendars WHERE id = ?;"; $calendarList = $this->execSQLNoJsonReturn($sql, [$calendarId]); - if(!empty($calendarList)){ + if(!empty($calendarList)) { $calendarData = $calendarList[0]; return $calendarData; } return null; } - public function getProduitDevisByDevisId($devisId){ + public function getProduitDevisByDevisId($devisId) + { $sql = "SELECT * FROM ".$this->tableprefix ."produit_devis as produit_devis WHERE produit_devis.devis_id = ?;"; $produitDevisList = $this->execSQLNoJsonReturn( - $sql, - [$devisId]); + $sql, + [$devisId] + ); return $produitDevisList; } - public function getDevisProduits($devisId){ + public function getDevisProduits($devisId) + { $sql = "SELECT produit_devis.id, @@ -3104,15 +3288,16 @@ class Bdd { WHERE produit_devis.devis_id = ?;"; $produitList = $this->execSQLNoJsonReturn( - $sql, - [$devisId]); + $sql, + [$devisId] + ); - - if(!empty($produitList)){ + + if(!empty($produitList)) { $clientId = $produitList[0]["devis_client_id"]; $client = $this->getClientById($clientId); - foreach($produitList as &$produit){ - $productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$produit['produit_id']); + foreach($produitList as &$produit) { + $productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'], $produit['produit_id']); $produit['produit_price'] = $productPrice ?? $produit['produit_price']; } } @@ -3120,7 +3305,8 @@ class Bdd { return $produitList; } - public function getProductPriceByClientGroupId($clientGroupId,$productId){ + public function getProductPriceByClientGroupId($clientGroupId, $productId) + { $sql = "SELECT * FROM ".$this->tableprefix ."client_group_discount as client_group_discount @@ -3128,28 +3314,31 @@ class Bdd { client_group_discount.fk_produit_id = ?; "; $clientGroupDiscount = $this->execSQLNoJsonReturn( - $sql, - [$clientGroupId,$productId]); + $sql, + [$clientGroupId,$productId] + ); - if(!empty($clientGroupDiscount)){ + if(!empty($clientGroupDiscount)) { return $clientGroupDiscount[0]['ht_amount']; } return null; } - private function getProductPriceByClient($productId,$clientId,$productInitialPrice){ + private function getProductPriceByClient($productId, $clientId, $productInitialPrice) + { $client = $this->getClientById($clientId); - if($client != null){ - $productDiscountPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$productId); + if($client != null) { + $productDiscountPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'], $productId); $productInitialPrice = $productDiscountPrice ?? $productInitialPrice; } return $productInitialPrice; } - private function getDevisProductsQuantityByDevisListAndProductId($devisList,$productId){ + private function getDevisProductsQuantityByDevisListAndProductId($devisList, $productId) + { - if(empty($devisList)){ + if(empty($devisList)) { return 0; } $sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisList), '?')); @@ -3160,23 +3349,25 @@ class Bdd { produit_devis.produit_id = ?;"; $produitList = $this->execSQLNoJsonReturn( - $sql, - array_merge($devisList,array($productId))); + $sql, + array_merge($devisList, array($productId)) + ); - if(!empty($produitList)){ + if(!empty($produitList)) { return $produitList[0]['total_quantity']; } return 0; } - private function getClientFactureStatisticPerMonth($clientId,array $produitList){ + private function getClientFactureStatisticPerMonth($clientId, array $produitList) + { - $currentYear = date('Y'); - $monthLists = range(1,12); + $currentYear = date('Y'); + $monthLists = range(1, 12); $data = [] ; - foreach($monthLists as $monthValue){ - if(!isset($data[$monthValue])){ + foreach($monthLists as $monthValue) { + if(!isset($data[$monthValue])) { $data[$monthValue] = []; } $sql = "SELECT @@ -3195,23 +3386,24 @@ class Bdd { (devis.mentions = ? OR devis.mentions = ?) ORDER BY facture.date_paiement ASC;"; $factureList = $this->execSQLNoJsonReturn( - $sql, - [$currentYear,$monthValue,$clientId,DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED]); + $sql, + [$currentYear,$monthValue,$clientId,DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED] + ); $factureDevisIds = []; - foreach($factureList as $facture){ + foreach($factureList as $facture) { $factureDevisIds[] = $facture['devis_id']; } $defuntCount = count($factureList); $produitsPrice = 0; $statisticForeachProductPerMonth = []; - foreach($produitList as $produit){ - if(!isset($statisticForeachProductPerMonth[$produit['id']])){ + foreach($produitList as $produit) { + if(!isset($statisticForeachProductPerMonth[$produit['id']])) { $statisticForeachProductPerMonth[$produit['id']] = 0; } - $productTotalCount = $this->getDevisProductsQuantityByDevisListAndProductId($factureDevisIds,$produit['id']); + $productTotalCount = $this->getDevisProductsQuantityByDevisListAndProductId($factureDevisIds, $produit['id']); $totalWithoutVat = $productTotalCount * $produit["prix_unitaire"]; $statisticForeachProductPerMonth[$produit['id']] += $productTotalCount; $produitsPrice += $totalWithoutVat; @@ -3226,28 +3418,29 @@ class Bdd { return $data; } - public function getExportClientStatData(array $clientIds){ + public function getExportClientStatData(array $clientIds) + { $data = []; $produitList = $this->getProduitsListAsArray(); - foreach($clientIds as $clientId){ - if(!isset($data[$clientId])){ + foreach($clientIds as $clientId) { + if(!isset($data[$clientId])) { $data[$clientId] = []; } //get client name $clientName = "Default client name"; $client = $this->getClientById($clientId); - if($client != null){ + if($client != null) { $clientName = trim($client["client_nom"]) . '-' .trim($client['client_entreprise']); } $data[$clientId]["client_name"] = $clientName; - $data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId,$produitList); + $data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId, $produitList); } return $data; } - private function getClientById($clientId){ - + private function getClientById($clientId) + { $sql = "SELECT client.id, client.nom as client_nom, @@ -3256,25 +3449,27 @@ class Bdd { client.legal_one as client_legal_one, client.adresse as client_address, client.mail as client_mail, - + client.is_tva as tva, client.fk_client_group_id as fk_client_group_id FROM ".$this->tableprefix."client as client WHERE client.id = ?;"; $clientList = $this->execSQLNoJsonReturn( - $sql, - [$clientId]); + $sql, + [$clientId] + ); - if(!empty($clientList)){ + if(!empty($clientList)) { return $clientList[0]; } return null; } - public function getClientsByClientsID(array $clientIds){ + public function getClientsByClientsID(array $clientIds) + { - if(empty($clientIds)){ + if(empty($clientIds)) { return []; } @@ -3287,14 +3482,16 @@ class Bdd { FROM ".$this->tableprefix."client as client WHERE client.id IN ($sqlConditionsPlaceholder);"; $clientList = $this->execSQLNoJsonReturn( - $sql, - $clientIds); + $sql, + $clientIds + ); return $clientList; } - private function getInvoiceGroupDevisDatasByFactureId($factureId){ + private function getInvoiceGroupDevisDatasByFactureId($factureId) + { $sql = "SELECT devis_facture.id as devis_facture_id, @@ -3336,21 +3533,23 @@ class Bdd { WHERE devis_facture.fk_facture_id = ? ;"; $devis = $this->execSQLNoJsonReturn( - $sql, - [$factureId]); + $sql, + [$factureId] + ); return $devis; } - public function getFactureByFactureId($factureId){ + public function getFactureByFactureId($factureId) + { $sql = "SELECT * FROM ".$this->tableprefix."facture as facture WHERE facture.id = ? LIMIT 1; "; - $result = $this->execSQLNoJsonReturn($sql,[$factureId]); - if(!empty($result)){ + $result = $this->execSQLNoJsonReturn($sql, [$factureId]); + if(!empty($result)) { return $result[0]; } return null; @@ -3358,50 +3557,52 @@ class Bdd { public function getInvoicePdfData($factureId, $configuration) - { - $factureData = $this->getFactureByIdWithDevis($factureId); - if($factureData == null) { - return null; - } - - $products = $this->getDevisProduits($factureData["devis_id"]); - $isDevisNegative = $this->isDevisNegative($factureData['devis_id'], $factureData['client_id']); - $factureData = $this->setDevisStartAndEndTime($factureData); + { + $factureData = $this->getFactureByIdWithDevis($factureId); + if($factureData == null) { + return null; + } - $factureData["products"] = $products; - $factureData["configuration"] = $configuration; + $products = $this->getDevisProduits($factureData["devis_id"]); + $isDevisNegative = $this->isDevisNegative($factureData['devis_id'], $factureData['client_id']); + $factureData = $this->setDevisStartAndEndTime($factureData); - // Récupération des informations client et gestion TVA - $client = $this->getClientById($factureData['client_id']); - $hasTva = ($client && isset($client['tva'])) ? ($client['tva'] == 1) : true; - $groupClient = $this->getTvaItracomuIdClient($factureData['client_id']); - - $isClientInsideGroup = $factureData["group_id"] != null; - if($isClientInsideGroup) { - $factureData["client_real_adress"] = $factureData["group_address"]; - $factureData["client_adress_city"] = $factureData["group_postal_code"]." ".$factureData["group_city"]; - $factureData["client_mail"] = $factureData["group_email"]; - $factureData["siret"] = $factureData["group_siret_number"]; - } else { - $factureData["siret"] = $factureData["client_legal_one"]; - $clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($factureData["client_adresse"]); - $factureData["client_real_adress"] = $clientAdresses["address"]; - $factureData["client_adress_city"] = $clientAdresses["city"]; - } - - $factureData['is_negative'] = $isDevisNegative; - $factureData["is_tva"] = $hasTva; - $factureData["client_tva_intracommu"] = $groupClient["tva_intracommu"]; + $factureData["products"] = $products; + $factureData["configuration"] = $configuration; - $configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse); - $factureData["configuration_adresse"] = $configurationAdresses["address"]; - $factureData["configuration_adresse_city"] = $configurationAdresses["city"]; - - return $factureData; - } - private function getDevisByClientIdsListAndMonthYear($clientIds,$month,$year){ + // Récupération des informations client et gestion TVA + $client = $this->getClientById($factureData['client_id']); + $hasTva = ($client && isset($client['tva'])) ? ($client['tva'] == 1) : true; + $groupClient = $this->getTvaItracomuIdClient($factureData['client_id']); - if(empty($clientIds)){ + $isClientInsideGroup = $factureData["group_id"] != null; + if($isClientInsideGroup) { + $factureData["client_real_adress"] = $factureData["group_address"]; + $factureData["client_adress_city"] = $factureData["group_postal_code"]." ".$factureData["group_city"]; + $factureData["client_mail"] = $factureData["group_email"]; + $factureData["siret"] = $factureData["group_siret_number"]; + } else { + $factureData["siret"] = $factureData["client_legal_one"]; + $clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($factureData["client_adresse"]); + $factureData["client_real_adress"] = $clientAdresses["address"]; + $factureData["client_adress_city"] = $clientAdresses["city"]; + } + + $factureData['is_negative'] = $isDevisNegative; + $factureData["is_tva"] = $hasTva; + $factureData["client_tva_intracommu"] = $groupClient["tva_intracommu"]; + + $configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse); + $factureData["configuration_adresse"] = $configurationAdresses["address"]; + $factureData["configuration_adresse_city"] = $configurationAdresses["city"]; + + return $factureData; + } + + private function getDevisByClientIdsListAndMonthYear($clientIds, $month, $year) + { + + if(empty($clientIds)) { return []; } $clientSqlPlaceholders = implode(',', array_fill(0, count($clientIds), '?')); @@ -3438,25 +3639,27 @@ class Bdd { LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id WHERE devis.id_client IN ($clientSqlPlaceholders) AND YEAR(devis.date) = ?"; - + $conditions = array_merge( $clientIds, [$year] ); - if($month != 0){ + if($month != 0) { $conditions[] = $month; $sql .= " AND MONTH(devis.date) = ?"; } $sql .= ";"; $devisList = $this->execSQLNoJsonReturn( - $sql, - $conditions); + $sql, + $conditions + ); return $devisList; } - private function getDevisByClientAndMonthYear($clientId,$month,$year){ + private function getDevisByClientAndMonthYear($clientId, $month, $year) + { $sql = "SELECT devis.id as devis_id, @@ -3468,7 +3671,7 @@ class Bdd { client.nom as client_nom, client.entreprise as client_entreprise, client.adresse as client_adresse, - + client.is_tva as tva, defunt.nom as defunt_nom, defunt.sexe as defunt_sexe, lieu.nom as lieu_nom, @@ -3497,50 +3700,53 @@ class Bdd { $conditions[] = $year; $sql .= " AND YEAR(devis.date) = ?"; } - if($month != 0){ + if($month != 0) { $conditions[] = $month; $sql .= " AND MONTH(devis.date) = ?"; } $sql .= ";"; $devisList = $this->execSQLNoJsonReturn( - $sql, - $conditions); + $sql, + $conditions + ); return $devisList; } - public function getDevisPdfDataByClientGroupFacturationAndMonthYear($clientGroupFacturationId,$month,$year,$configuration){ + public function getDevisPdfDataByClientGroupFacturationAndMonthYear($clientGroupFacturationId, $month, $year, $configuration) + { $clientIds = $this->getClientIdsByClientGroupFacturationId($clientGroupFacturationId); - $devisList = $this->getDevisByClientIdsListAndMonthYear($clientIds,$month,$year); + $devisList = $this->getDevisByClientIdsListAndMonthYear($clientIds, $month, $year); return $devisList; } - public function getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$configuration){ + public function getDevisPdfDataByClientAndMonthYear($clientId, $month, $year, $configuration) + { - $devisList = $this->getDevisByClientAndMonthYear($clientId,$month,$year); + $devisList = $this->getDevisByClientAndMonthYear($clientId, $month, $year); return $devisList; } - public function getInvoicePdfDataByClientAndMonthYear($filter,$month,$year,$configuration,$filterType){ + public function getInvoicePdfDataByClientAndMonthYear($filter, $month, $year, $configuration, $filterType) + { $isFilterByClient = $filterType === MultipleFactureTypeConstant::CLIENT_FILTER_TYPE; - if($isFilterByClient){ + if($isFilterByClient) { $invoices = $this->getInvoiceByClientAndMonthYear( clientId: $filter, month: $month, year: $year ); - } - else{ + } else { $invoices = $this->getInvoiceByClientGroupFacturationAndMonthYear( clientGroupFacturationId: $filter, month: $month, year: $year ); } - foreach($invoices as &$invoice){ + foreach($invoices as &$invoice) { $products = $this->getDevisProduits($invoice["devis_id"]); $invoice["products"] = $products; $invoice["configuration"] = $configuration; @@ -3553,13 +3759,12 @@ class Bdd { $invoice["is_tva"] = $hasTva; $isClientInsideGroup = $invoice["group_id"] != null; - if($isClientInsideGroup){ + if($isClientInsideGroup) { $invoice["client_real_adress"] = $invoice["group_address"]; $invoice["client_adress_city"] = $invoice["group_postal_code"]." ".$invoice["group_city"]; $invoice["client_mail"] = $invoice["group_email"]; $invoice["siret"] = $invoice["group_siret_number"]; - } - else{ + } else { $invoice["siret"] = $invoice["client_legal_one"]; $clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($invoice["client_adresse"]); $invoice["client_real_adress"] = $clientAdresses["address"]; @@ -3573,7 +3778,8 @@ class Bdd { return $invoices; } - private function getClientIdsByClientGroupFacturationId($clientGroupFacturationId){ + private function getClientIdsByClientGroupFacturationId($clientGroupFacturationId) + { $sql = "SELECT client.id FROM ".$this->tableprefix."client as client @@ -3581,19 +3787,21 @@ class Bdd { $clientIds = []; $clients = $this->execSQLNoJsonReturn( - $sql, - [$clientGroupFacturationId]); + $sql, + [$clientGroupFacturationId] + ); - if(!empty($clients)){ - foreach($clients as $client){ + if(!empty($clients)) { + foreach($clients as $client) { $clientIds[] = $client["id"]; } } return $clientIds; } - private function getInvoiceByClientIdsListAndMonthYear($clientIds,$month,$year){ + private function getInvoiceByClientIdsListAndMonthYear($clientIds, $month, $year) + { $clientIdsSqlPlaceholder = implode(',', array_fill(0, count($clientIds), '?')); @@ -3641,31 +3849,34 @@ class Bdd { LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id WHERE client.id IN ($clientIdsSqlPlaceholder) AND YEAR(facture.date_paiement) = ?"; - - $conditions = array_merge($clientIds,[$year]); - if($month != 0){ + + $conditions = array_merge($clientIds, [$year]); + if($month != 0) { $conditions[] = $month; $sql .= " AND MONTH(facture.date_paiement) = ?"; } $sql .= ";"; $factures = $this->execSQLNoJsonReturn( - $sql, - $conditions); + $sql, + $conditions + ); return $factures; } - private function getInvoiceByClientGroupFacturationAndMonthYear($clientGroupFacturationId,$month, $year){ + private function getInvoiceByClientGroupFacturationAndMonthYear($clientGroupFacturationId, $month, $year) + { $clientIdsInsideClientFacturationGroup = $this->getClientIdsByClientGroupFacturationId($clientGroupFacturationId); - if(empty($clientIdsInsideClientFacturationGroup)){ + if(empty($clientIdsInsideClientFacturationGroup)) { return []; } - return $this->getInvoiceByClientIdsListAndMonthYear($clientIdsInsideClientFacturationGroup,$month,$year); + return $this->getInvoiceByClientIdsListAndMonthYear($clientIdsInsideClientFacturationGroup, $month, $year); } - private function getInvoiceByClientAndMonthYear($clientId,$month,$year){ + private function getInvoiceByClientAndMonthYear($clientId, $month, $year) + { $sql = "SELECT facture.id, @@ -3719,21 +3930,23 @@ class Bdd { $conditions[] = $year; $sql .= " AND YEAR(facture.date_paiement) = ?"; } - if($month != 0){ + if($month != 0) { $conditions[] = $month; $sql .= " AND MONTH(facture.date_paiement) = ?"; } $sql .= ";"; $factures = $this->execSQLNoJsonReturn( - $sql, - $conditions); + $sql, + $conditions + ); return $factures; } - public function getDevisPdfDataByDevisId($devisId){ + public function getDevisPdfDataByDevisId($devisId) + { $sql = "SELECT devis.id as devis_id, @@ -3759,16 +3972,18 @@ class Bdd { WHERE devis.id = ? ;"; $devis = $this->execSQLNoJsonReturn( - $sql, - [$devisId]); + $sql, + [$devisId] + ); - if(!empty($devis)){ + if(!empty($devis)) { return $devis[0]; } return null; } - private function getFactureByIdWithDevis($factureId){ + private function getFactureByIdWithDevis($factureId) + { $sql = "SELECT facture.id, @@ -3813,28 +4028,32 @@ class Bdd { WHERE facture.id = ? ;"; $facture = $this->execSQLNoJsonReturn( - $sql, - [$factureId]); + $sql, + [$factureId] + ); - if(!empty($facture)){ + if(!empty($facture)) { return $facture[0]; } return null; } - public function getProduitsListAsArray(){ + public function getProduitsListAsArray() + { $sql = "SELECT * FROM ".$this->tableprefix."produit as produit;"; $produitList = $this->execSQLNoJsonReturn( - $sql, - []); + $sql, + [] + ); return $produitList; } - public function getArticleIdsByArticleReferences(array $articleReferences){ + public function getArticleIdsByArticleReferences(array $articleReferences) + { $articleIds = []; foreach ($articleReferences as $reference) { @@ -3848,114 +4067,129 @@ class Bdd { return $articleIds; } - public function addNumberColumnOnDevis(){ + public function addNumberColumnOnDevis() + { $sql = "ALTER TABLE ". $this->tableprefix."devis ADD devis_number INT DEFAULT 1;" ; $this->execSQLNoJsonReturn( - $sql, - []); + $sql, + [] + ); $sql = "ALTER TABLE ". $this->tableprefix."devis ADD devis_full_number VARCHAR(255);" ; $this->execSQLNoJsonReturn( - $sql, - []); + $sql, + [] + ); $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.devis_full_number = CONCAT('DEV', YEAR(devis.date) % 100, LPAD(MONTH(devis.date), 2, '0'), LPAD(devis.devis_number, 2, '0'));"; $this->execSQLNoJsonReturn( - $sql, - []); + $sql, + [] + ); + - return true; } - public function addNumberColumnOnFacture(){ + public function addNumberColumnOnFacture() + { $sql = "ALTER TABLE ". $this->tableprefix."facture ADD facture_number INT DEFAULT 1;" ; $this->execSQLNoJsonReturn( - $sql, - []); + $sql, + [] + ); $sql = "UPDATE ".$this->tableprefix."facture as facture SET facture.num = CONCAT('FAC', YEAR(facture.date) % 100, LPAD(MONTH(facture.date), 2, '0'), LPAD(facture.facture_number, 2, '0'));"; $this->execSQLNoJsonReturn( - $sql, - []); + $sql, + [] + ); + - return true; } - private function getLastFactureNumberByMonthAndYear($month,$year){ + private function getLastFactureNumberByMonthAndYear($month, $year) + { $sql = "SELECT - max(facture.facture_number) as LAST_FACTURE_NUMBER, facture.date FROM " + max(facture.facture_number) as LAST_FACTURE_NUMBER, facture.date FROM " . $this->tableprefix."facture as facture WHERE YEAR(facture.date) = ? AND MONTH(facture.date) = ?;"; - $res = $this->execSQLNoJsonReturn($sql,array($year,$month)); + $res = $this->execSQLNoJsonReturn($sql, array($year,$month)); $lastNumber = 0; - if(!empty($res)){ + if(!empty($res)) { $lastNumber = $res[0]['LAST_FACTURE_NUMBER']; } return $lastNumber; } - public function getFactureNumberByDate($datetime){ + public function getFactureNumberByDate($datetime) + { $month = $datetime->format('m'); $year = $datetime->format('Y'); - $lastFactureNumber = $this->getLastFactureNumberByMonthAndYear($month,$year); + $lastFactureNumber = $this->getLastFactureNumberByMonthAndYear($month, $year); $factureNumber = $lastFactureNumber + 1; return $factureNumber; } - public function getFactureFullNumberByDate($datetime){ + public function getFactureFullNumberByDate($datetime) + { $factureNumber = $this->getFactureNumberByDate($datetime); - $factureFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($datetime,$factureNumber,'FAC'); + $factureFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($datetime, $factureNumber, 'FAC'); return $factureFullNumber; } - public function getDevisNumberByDate($datetime){ + public function getDevisNumberByDate($datetime) + { $month = $datetime->format('m'); $year = $datetime->format('Y'); - $lastDevisNumber = $this->getLastDevisNumberByMonthAndYear($month,$year); + $lastDevisNumber = $this->getLastDevisNumberByMonthAndYear($month, $year); $devisNumber = $lastDevisNumber + 1; return $devisNumber; } - public function getDevisFullNumberByDate($datetime){ + public function getDevisFullNumberByDate($datetime) + { $devisNumber = $this->getDevisNumberByDate($datetime); - $devisFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($datetime,$devisNumber,'DEV'); + $devisFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($datetime, $devisNumber, 'DEV'); return $devisFullNumber; } - public function getFirstClient(){ + public function getFirstClient() + { $sql = "SELECT * FROM ".$this->tableprefix."client as client LIMIT 1;"; $client = $this->execSQLNoJsonReturn( - $sql, - []); + $sql, + [] + ); - if(!empty($client)){ + if(!empty($client)) { return $client[0]; } - + return null; } - public function getClientGroupDiscounts(){ + public function getClientGroupDiscounts() + { $sql = "SELECT @@ -3972,61 +4206,68 @@ class Bdd { LEFT JOIN ".$this->tableprefix."produit as produit on client_group_discount.fk_produit_id = produit.id ORDER BY client_group_discount.id DESC "; - + $clientGroupDiscounts = $this->execSQL( - $sql, - []); + $sql, + [] + ); return $clientGroupDiscounts; } - public function getClientGroups(){ + public function getClientGroups() + { $sql = "SELECT * FROM ".$this->tableprefix."client_group as client_group ORDER BY client_group.id DESC;"; - $clientGroups = $this->execSQL($sql,[]); + $clientGroups = $this->execSQL($sql, []); return $clientGroups; } - public function createDefaultClientGroup(){ + public function createDefaultClientGroup() + { $sql = "INSERT INTO `".$this->tableprefix."client_group` (`client_group_name`) VALUES (?);"; $this->execSQLNoData($sql, array(self::DEFAULT_CLIENT_GROUP_NAME)); return true; } - public function createDefaultClientGroupDiscount(){ + public function createDefaultClientGroupDiscount() + { $sql = "INSERT INTO `".$this->tableprefix."client_group_discount` (`fk_client_group_id`,`fk_produit_id`,`ht_amount`) VALUES (0,0,0);"; $this->execSQLNoData($sql, array()); return true; } - public function getClientGroupCount(){ + public function getClientGroupCount() + { $sql = "SELECT count(*) as c from ".$this->tableprefix."client_group;"; return $this->execSQL($sql, array()); } - public function getClientGroupDiscountCount(){ + public function getClientGroupDiscountCount() + { $sql = "SELECT count(*) as c from ".$this->tableprefix."client_group_discount;"; return $this->execSQL($sql, array()); } - public function addClientGroupDiscountFeatureTables(){ + public function addClientGroupDiscountFeatureTables() + { $createTableClientGroupSQL = "CREATE TABLE oc_gestion_client_group ( id INT PRIMARY KEY AUTO_INCREMENT, client_group_name VARCHAR(255) DEFAULT '' );"; - $this->execSQLNoData($createTableClientGroupSQL,[]); + $this->execSQLNoData($createTableClientGroupSQL, []); - $addColumnFkClientGroupIdIntoClientTableSQL= "ALTER TABLE oc_gestion_client + $addColumnFkClientGroupIdIntoClientTableSQL = "ALTER TABLE oc_gestion_client ADD fk_client_group_id INT NULL;"; - $this->execSQLNoData($addColumnFkClientGroupIdIntoClientTableSQL,[]); + $this->execSQLNoData($addColumnFkClientGroupIdIntoClientTableSQL, []); $createTableClientGroupDiscountSQL = "CREATE TABLE oc_gestion_client_group_discount ( id INT PRIMARY KEY AUTO_INCREMENT, @@ -4035,12 +4276,13 @@ class Bdd { ht_amount FLOAT NOT NULL );"; - $this->execSQLNoData($createTableClientGroupDiscountSQL,[]); + $this->execSQLNoData($createTableClientGroupDiscountSQL, []); return true; } - public function getDevisOfDefunt($defuntId){ + public function getDevisOfDefunt($defuntId) + { $sql = "SELECT devis.id as id, @@ -4071,17 +4313,18 @@ class Bdd { LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id WHERE devis.id_defunt = ? ;"; - - $devisOfDefunt = $this->execSQLNoJsonReturn($sql, [$defuntId]); - if(!empty( $devisOfDefunt)){ + $devisOfDefunt = $this->execSQLNoJsonReturn($sql, [$defuntId]); + + if(!empty($devisOfDefunt)) { return $devisOfDefunt[0]; } return null; } - - private function getDefuntById($defuntId){ + + private function getDefuntById($defuntId) + { $sql = "SELECT defunt.id as id, @@ -4092,27 +4335,29 @@ class Bdd { WHERE defunt.id = ? LIMIT 1;"; - $defunt = $this->execSQLNoJsonReturn($sql,[$defuntId]); - if(!empty($defunt)){ + $defunt = $this->execSQLNoJsonReturn($sql, [$defuntId]); + if(!empty($defunt)) { return $defunt[0]; } return null; } - private function getProductAsDefuntCoverProduct($productCoverId){ + private function getProductAsDefuntCoverProduct($productCoverId) + { $product = $this->getProductByProductId($productCoverId); - if($product == null){ + if($product == null) { return null; } $productCoverType = $this->getProductTypeByKey(ProductConstant::PRODUCT_COVER_TYPE_KEY); - if($product["fk_product_type_id"] == $productCoverType["id"]){ + if($product["fk_product_type_id"] == $productCoverType["id"]) { return $product; } return null; } - private function isProductAlreadyExistInDevis($productId,$devisId){ + private function isProductAlreadyExistInDevis($productId, $devisId) + { $sql = "SELECT produit_devis.id @@ -4121,24 +4366,26 @@ class Bdd { produit_devis.devis_id = ? LIMIT 1;"; - $product = $this->execSQLNoJsonReturn($sql,[$productId,$devisId]); - if(!empty($product)){ + $product = $this->execSQLNoJsonReturn($sql, [$productId,$devisId]); + if(!empty($product)) { return true; } return false; } - private function removeProductFromDevis($productId,$devisId){ + private function removeProductFromDevis($productId, $devisId) + { $sql = "DELETE FROM ". $this->tableprefix."produit_devis WHERE devis_id = ? AND produit_id = ? "; - $this->execSQLNoData($sql,[$devisId,$productId]); + $this->execSQLNoData($sql, [$devisId,$productId]); } - private function getProductByReference($productReference){ + private function getProductByReference($productReference) + { $sql = "SELECT produit.id, @@ -4147,31 +4394,34 @@ class Bdd { WHERE produit.reference = ? LIMIT 1;"; - $product = $this->execSQLNoJsonReturn($sql,[$productReference]); - if(!empty($product)){ + $product = $this->execSQLNoJsonReturn($sql, [$productReference]); + if(!empty($product)) { return $product[0]; } return null; } - private function removeProductFromDevisByProductReference($productReference,$devisId){ + private function removeProductFromDevisByProductReference($productReference, $devisId) + { $product = $this->getProductByReference($productReference); - if($product != null){ - $this->removeProductFromDevis($product["id"],$devisId); + if($product != null) { + $this->removeProductFromDevis($product["id"], $devisId); } } - private function createProductDevisIfNotExist($productId,$devisId){ + private function createProductDevisIfNotExist($productId, $devisId) + { - $isProductDevisAlreadyExist = $this->isProductAlreadyExistInDevis($productId,$devisId); - if(!$isProductDevisAlreadyExist){ + $isProductDevisAlreadyExist = $this->isProductAlreadyExistInDevis($productId, $devisId); + if(!$isProductDevisAlreadyExist) { $idNextcloud = "admin"; - $this->insertDevisArticle(devisId: $devisId, articleId: $productId,idNextcloud: $idNextcloud); + $this->insertDevisArticle(devisId: $devisId, articleId: $productId, idNextcloud: $idNextcloud); } } - private function getProductByProductId($productId){ + private function getProductByProductId($productId) + { $sql = "SELECT produit.id, @@ -4180,59 +4430,61 @@ class Bdd { FROM ".$this->tableprefix."produit as produit WHERE produit.id = ? LIMIT 1;"; - - $result = $this->execSQLNoJsonReturn($sql,[$productId]); - if(!empty($result)){ + + $result = $this->execSQLNoJsonReturn($sql, [$productId]); + if(!empty($result)) { return $result[0]; } return null; } - private function deleteProductsInDevisByProductType($devisId,$productTypeId){ + private function deleteProductsInDevisByProductType($devisId, $productTypeId) + { $sql = "DELETE produit_devis FROM ".$this->tableprefix."produit_devis as produit_devis LEFT JOIN ".$this->tableprefix."produit as produit ON produit_devis.produit_id = produit.id WHERE produit_devis.devis_id = ? AND produit.fk_product_type_id = ?;"; - $this->execSQLNoData($sql,[$devisId,$productTypeId]); + $this->execSQLNoData($sql, [$devisId,$productTypeId]); } - public function setDefuntCover($defuntId, $productCoverId){ + public function setDefuntCover($defuntId, $productCoverId) + { $defunt = $this->getDefuntById($defuntId); - if($defunt == null){ + if($defunt == null) { return null; } - if($defunt["devis_id"] == null){ + if($defunt["devis_id"] == null) { return null; } - if($productCoverId == null){ + if($productCoverId == null) { $productTypeCover = $this->getProductTypeByKey(ProductConstant::PRODUCT_COVER_TYPE_KEY); - $this->deleteProductsInDevisByProductType($defunt["devis_id"],$productTypeCover['id']); + $this->deleteProductsInDevisByProductType($defunt["devis_id"], $productTypeCover['id']); return true; } $product = $this->getProductAsDefuntCoverProduct($productCoverId); - if($product == null){ + if($product == null) { return null; } - + $coverProductList = $this->getProductsByProductTypeKey(ProductConstant::PRODUCT_COVER_TYPE_KEY); $coverProductList = json_decode($coverProductList); - foreach($coverProductList as $currentCoverProduct){ - if($currentCoverProduct->id == $product["id"]){ - $this->createProductDevisIfNotExist($product["id"],$defunt["devis_id"]); - } - else{ - $this->removeProductFromDevis($currentCoverProduct->id,$defunt["devis_id"]); + foreach($coverProductList as $currentCoverProduct) { + if($currentCoverProduct->id == $product["id"]) { + $this->createProductDevisIfNotExist($product["id"], $defunt["devis_id"]); + } else { + $this->removeProductFromDevis($currentCoverProduct->id, $defunt["devis_id"]); } } return true; } - private function getProductsByProductTypeKey(string $productTypeKey){ + private function getProductsByProductTypeKey(string $productTypeKey) + { $sql = "SELECT produit.id, @@ -4242,16 +4494,18 @@ class Bdd { LEFT JOIN ".$this->tableprefix."product_type as product_type on produit.fk_product_type_id = product_type.id WHERE product_type.product_type_key = ?;"; - $products = $this->execSQL($sql,[$productTypeKey]); + $products = $this->execSQL($sql, [$productTypeKey]); return $products; } - public function getCoverProducts(){ + public function getCoverProducts() + { return $this->getProductsByProductTypeKey(ProductConstant::PRODUCT_COVER_TYPE_KEY); } - private function getProductTypeByKey(string $key){ + private function getProductTypeByKey(string $key) + { $sql = "SELECT product_type.id, @@ -4260,14 +4514,15 @@ class Bdd { FROM ".$this->tableprefix."product_type as product_type WHERE product_type.product_type_key = ?;"; - $productType = $this->execSQLNoJsonReturn($sql,[$key]); - if(!empty($productType)){ + $productType = $this->execSQLNoJsonReturn($sql, [$key]); + if(!empty($productType)) { return $productType[0]; } return null; } - private function getProductCoverByDevisId($devisId){ + private function getProductCoverByDevisId($devisId) + { $coverProductType = $this->getProductTypeByKey(ProductConstant::PRODUCT_COVER_TYPE_KEY); @@ -4281,33 +4536,34 @@ class Bdd { LEFT JOIN ".$this->tableprefix."produit as produit on produit_devis.produit_id = produit.id WHERE produit_devis.devis_id = ? AND produit.fk_product_type_id = ? LIMIT 1"; - - $productCover = $this->execSQLNoJsonReturn($sql,[$devisId,$coverProductType["id"]]); - if($productCover){ + + $productCover = $this->execSQLNoJsonReturn($sql, [$devisId,$coverProductType["id"]]); + if($productCover) { return $productCover[0]; } return null; } - private function getDevisByIdWithCalendarDataAndProducts($devisId,$idNextcloud){ + private function getDevisByIdWithCalendarDataAndProducts($devisId, $idNextcloud) + { - $devis = $this->getOneDevis($devisId,$idNextcloud); - $devis= json_decode($devis); - if(empty($devis)){ + $devis = $this->getOneDevis($devisId, $idNextcloud); + $devis = json_decode($devis); + if(empty($devis)) { return null; } $devis = $devis[0]; - if(isset($devis->numm) && $devis->num == null){ + if(isset($devis->numm) && $devis->num == null) { return null; } $calendarData = $this->getCalendarDataByCalendarObjectUuid($devis->num); $devisTimeValue = VCalendarHelpers::GetStartAndEndTimeFromVCalendarString($calendarData); $startTimeValueWithMinutes = ""; $endTimeValueWithMinutes = ""; - if($devisTimeValue["datetimeStart"]){ + if($devisTimeValue["datetimeStart"]) { $startTimeValueWithMinutes = $devisTimeValue["datetimeStart"]->format('H\hi'); } - if($devisTimeValue["datetimeEnd"]){ + if($devisTimeValue["datetimeEnd"]) { $endTimeValueWithMinutes = $devisTimeValue["datetimeEnd"]->format('H\hi'); } $devis->startTime = $startTimeValueWithMinutes; @@ -4319,37 +4575,40 @@ class Bdd { return $devis; } - private function getDevisTalkRoomProductSectionMessage($devisProducts){ + private function getDevisTalkRoomProductSectionMessage($devisProducts) + { - if(empty($devisProducts)){ + if(empty($devisProducts)) { return ""; } $productMessage = "ACTE A FAIRE : "; - foreach($devisProducts as $product){ - $productMessage.= html_entity_decode($product->produit_reference).", "; + foreach($devisProducts as $product) { + $productMessage .= html_entity_decode($product->produit_reference).", "; } - $productMessage = trim( $productMessage ); - $productMessage = rtrim($productMessage,","); + $productMessage = trim($productMessage); + $productMessage = rtrim($productMessage, ","); return $productMessage; } - private function getDevisTalkRoomClientContent($clientPrenom){ + private function getDevisTalkRoomClientContent($clientPrenom) + { $message = "Pour PF: "; $clientNameContent = "aucun"; $clientPrenomIsSet = $clientPrenom != null && $clientPrenom != "" && $clientPrenom != "-"; - if($clientPrenomIsSet){ + if($clientPrenomIsSet) { $clientNameContent = html_entity_decode($clientPrenom); } $message .= $clientNameContent; return $message; } - - public function getDevisTalkRoomMessage($devisId,$idNextcloud){ - $devis = $this->getDevisByIdWithCalendarDataAndProducts($devisId,$idNextcloud); - if($devis == null){ + public function getDevisTalkRoomMessage($devisId, $idNextcloud) + { + + $devis = $this->getDevisByIdWithCalendarDataAndProducts($devisId, $idNextcloud); + if($devis == null) { return null; } $devisDate = new Datetime($devis->date); @@ -4369,7 +4628,7 @@ le '.$devisDate; $message .= ' '.$productMessage; $comment = "aucun"; - if(strtolower($devis->comment) != "commentaire" && $devis->comment != ""){ + if(strtolower($devis->comment) != "commentaire" && $devis->comment != "") { $comment = html_entity_decode($devis->comment); } $message .= " @@ -4380,9 +4639,9 @@ COMMENTAIRES: ".$comment; "Code funéraire" => $devis->funeral_code ]; $locationCodeMessageContent = ""; - foreach($locationCodes as $label => $code){ + foreach($locationCodes as $label => $code) { $value = "Aucun"; - if($code != null && trim($code) != ""){ + if($code != null && trim($code) != "") { $value = $code; } $locationCodeMessageContent .= $label. ": ".$value.". "; @@ -4393,9 +4652,10 @@ COMMENTAIRES: ".$comment; return $message; } - public function getDevisByCalendarUuid($calendarUuid){ + public function getDevisByCalendarUuid($calendarUuid) + { - if($calendarUuid === self::DEFAULT_CALENDAR_UUID_FOR_DEVIS){ + if($calendarUuid === self::DEFAULT_CALENDAR_UUID_FOR_DEVIS) { return null; } $sql = "SELECT @@ -4414,38 +4674,40 @@ COMMENTAIRES: ".$comment; WHERE devis.num = ? ;"; $devis = $this->execSQLNoJsonReturn($sql, array($calendarUuid)); - if(empty($devis)){ + if(empty($devis)) { return null; } return $devis[0]; } - - public function updateDevisMentionToCanceled($devisId){ - $sql= "UPDATE ".$this->tableprefix."devis as devis + public function updateDevisMentionToCanceled($devisId) + { + + $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.mentions = ? WHERE devis.id = ?"; - $this->execSQLNoData($sql,[DevisMentionConstant::CANCELED,$devisId]); + $this->execSQLNoData($sql, [DevisMentionConstant::CANCELED,$devisId]); } - private function updateDefuntByName($defuntId,$requestedDefuntName){ + private function updateDefuntByName($defuntId, $requestedDefuntName) + { - $sql= "UPDATE ".$this->tableprefix."defunt as defunt + $sql = "UPDATE ".$this->tableprefix."defunt as defunt SET defunt.nom = ? WHERE defunt.id = ?"; - $this->execSQLNoData($sql,[$requestedDefuntName,$defuntId]); + $this->execSQLNoData($sql, [$requestedDefuntName,$defuntId]); } - public function createOrUpdateDefuntByNameAndReturnDefuntId($defuntId,$currentDefuntName,$requestedDefuntName){ + public function createOrUpdateDefuntByNameAndReturnDefuntId($defuntId, $currentDefuntName, $requestedDefuntName) + { - if($defuntId != null){ + if($defuntId != null) { $defuntNameIsUpdated = $currentDefuntName != $requestedDefuntName; - if($defuntNameIsUpdated){ - $this->updateDefuntByName($defuntId,$requestedDefuntName); + if($defuntNameIsUpdated) { + $this->updateDefuntByName($defuntId, $requestedDefuntName); } - } - else{ + } else { $this->insertDefuntByName($requestedDefuntName); $defunt = $this->getLastDefuntIdByName($requestedDefuntName); $defuntId = $defunt['id']; @@ -4453,157 +4715,172 @@ COMMENTAIRES: ".$comment; return $defuntId; } - public function updateDevisDefunt($devisId,$requestedDefuntId,$currentDefuntId = null){ + public function updateDevisDefunt($devisId, $requestedDefuntId, $currentDefuntId = null) + { $defuntIsUpdated = $currentDefuntId != $requestedDefuntId; - if($defuntIsUpdated){ - $sql= "UPDATE ".$this->tableprefix."devis as devis + if($defuntIsUpdated) { + $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.id_defunt = ? WHERE devis.id = ?"; - $this->execSQLNoData($sql,[$requestedDefuntId,$devisId]); + $this->execSQLNoData($sql, [$requestedDefuntId,$devisId]); } } - public function updateDevisThanato($devisId,$requestedThanatoId){ + public function updateDevisThanato($devisId, $requestedThanatoId) + { - $sql= "UPDATE ".$this->tableprefix."devis as devis + $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.id_thanato = ? WHERE devis.id = ?"; - $this->execSQLNoData($sql,[$requestedThanatoId,$devisId]); + $this->execSQLNoData($sql, [$requestedThanatoId,$devisId]); } - public function updateDevisClient($devisId,$requestedClientId,$currentClientId = null){ + public function updateDevisClient($devisId, $requestedClientId, $currentClientId = null) + { $clientIsUpdated = $currentClientId != $requestedClientId; - if($clientIsUpdated){ - $sql= "UPDATE ".$this->tableprefix."devis as devis + if($clientIsUpdated) { + $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.id_client = ? WHERE devis.id = ?"; - $this->execSQLNoData($sql,[$requestedClientId,$devisId]); + $this->execSQLNoData($sql, [$requestedClientId,$devisId]); } } - public function updateDevisLieu($devisId,$requestedLieuId,$currentLieuId = null){ + public function updateDevisLieu($devisId, $requestedLieuId, $currentLieuId = null) + { $lieuIsUpdated = $currentLieuId != $requestedLieuId; - if($lieuIsUpdated){ - $sql= "UPDATE ".$this->tableprefix."devis as devis + if($lieuIsUpdated) { + $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.id_lieu = ? WHERE devis.id = ?"; - $this->execSQLNoData($sql,[$requestedLieuId,$devisId]); + $this->execSQLNoData($sql, [$requestedLieuId,$devisId]); } } - public function updateDevisComment($devisId,$requestedComment,$currentComment = null){ + public function updateDevisComment($devisId, $requestedComment, $currentComment = null) + { $commentIsUpdated = $currentComment != $requestedComment; - if($commentIsUpdated){ - $sql= "UPDATE ".$this->tableprefix."devis as devis + if($commentIsUpdated) { + $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.comment = ? WHERE devis.id = ?"; - $this->execSQLNoData($sql,[$requestedComment,$devisId]); + $this->execSQLNoData($sql, [$requestedComment,$devisId]); } } - public function updateDevisDate($devisId,$requestedDate){ + public function updateDevisDate($devisId, $requestedDate) + { - $sql= "UPDATE ".$this->tableprefix."devis as devis + $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.date = ? WHERE devis.id = ?"; - $this->execSQLNoData($sql,[$requestedDate,$devisId]); + $this->execSQLNoData($sql, [$requestedDate,$devisId]); } - public function deleteDevisProduit($devisProductId){ + public function deleteDevisProduit($devisProductId) + { $sql = "DELETE FROM ".$this->tableprefix."produit_devis WHERE id = ?;"; $this->execSQLNoData($sql, array($devisProductId)); } - public function updateDevisArticles($devisId,$requestedArticlesIds){ + public function updateDevisArticles($devisId, $requestedArticlesIds) + { $currentDevisProducts = $this->getDevisProduits($devisId); $currentDevisProduitIds = []; //delete old product - foreach($currentDevisProducts as $devisProduct){ + foreach($currentDevisProducts as $devisProduct) { $currentDevisProduitIds[] = $devisProduct['produit_id']; - $currentProductIsNotPartOfRequestedDevisProduct = !in_array($devisProduct['produit_id'],$requestedArticlesIds); - if($currentProductIsNotPartOfRequestedDevisProduct){ + $currentProductIsNotPartOfRequestedDevisProduct = !in_array($devisProduct['produit_id'], $requestedArticlesIds); + if($currentProductIsNotPartOfRequestedDevisProduct) { $this->deleteDevisProduit($devisProduct['id']); } } - + //add new requested product - foreach($requestedArticlesIds as $requestedArticleId){ - $currentRequestedArticleIsNewArticleForDevis = !in_array($requestedArticleId,$currentDevisProduitIds); - if($currentRequestedArticleIsNewArticleForDevis){ - $this->insertDevisArticle(devisId: $devisId, articleId: $requestedArticleId,idNextcloud: BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); + foreach($requestedArticlesIds as $requestedArticleId) { + $currentRequestedArticleIsNewArticleForDevis = !in_array($requestedArticleId, $currentDevisProduitIds); + if($currentRequestedArticleIsNewArticleForDevis) { + $this->insertDevisArticle(devisId: $devisId, articleId: $requestedArticleId, idNextcloud: BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); } } } - public function addClientGroupFacturationFeatureTables(){ + public function addClientGroupFacturationFeatureTables() + { $createTableClientGroupSQL = "CREATE TABLE oc_gestion_client_group_facturation ( id INT PRIMARY KEY AUTO_INCREMENT, group_facturation_name VARCHAR(255) DEFAULT '' );"; - $this->execSQLNoData($createTableClientGroupSQL,[]); + $this->execSQLNoData($createTableClientGroupSQL, []); - $addColumnFkClientGroupFacturationIdIntoClientTableSQL= "ALTER TABLE oc_gestion_client + $addColumnFkClientGroupFacturationIdIntoClientTableSQL = "ALTER TABLE oc_gestion_client ADD fk_client_group_facturation_id INT NULL;"; - $this->execSQLNoData($addColumnFkClientGroupFacturationIdIntoClientTableSQL,[]); + $this->execSQLNoData($addColumnFkClientGroupFacturationIdIntoClientTableSQL, []); return true; } - private function getClientGroupFacturationsWithType(){ + private function getClientGroupFacturationsWithType() + { $sql = "SELECT client_group_facturation.id as id, client_group_facturation.group_facturation_name as nom, 'group' as client_type FROM ".$this->tableprefix."client_group_facturation as client_group_facturation ORDER BY client_group_facturation.id DESC;"; - $clientGroupFacturations = $this->execSQLNoJsonReturn($sql,[]); + $clientGroupFacturations = $this->execSQLNoJsonReturn($sql, []); return $clientGroupFacturations; } - public function getClientGroupFacturations(){ + public function getClientGroupFacturations() + { $sql = "SELECT * FROM ".$this->tableprefix."client_group_facturation as client_group_facturation ORDER BY client_group_facturation.id DESC;"; - $clientGroupFacturations = $this->execSQL($sql,[]); + $clientGroupFacturations = $this->execSQL($sql, []); return $clientGroupFacturations; } - public function createDefaultGroupFacturation(){ + public function createDefaultGroupFacturation() + { $sql = "INSERT INTO `".$this->tableprefix."client_group_facturation` (`group_facturation_name`) VALUES (?);"; $this->execSQLNoData($sql, array(self::DEFAULT_CLIENT_GROUP_FACTURATION_NAME)); return true; } - public function getClientGroupFacturationById($clientGroupFacturationId){ + public function getClientGroupFacturationById($clientGroupFacturationId) + { $sql = "SELECT * FROM ".$this->tableprefix."client_group_facturation as client_group_facturation WHERE client_group_facturation.id = ? ;"; $clientGroupFacturation = $this->execSQLNoJsonReturn($sql, array($clientGroupFacturationId)); - if(!empty($clientGroupFacturation)){ + if(!empty($clientGroupFacturation)) { return $clientGroupFacturation[0]; } return null; } - public function getClientGroupFacturationCount(){ + public function getClientGroupFacturationCount() + { $sql = "SELECT count(*) as c from ".$this->tableprefix."client_group_facturation;"; return $this->execSQL($sql, array()); } - - public function addProductTypeTables(){ + + public function addProductTypeTables() + { $sql = "CREATE TABLE oc_gestion_product_type ( id INT PRIMARY KEY AUTO_INCREMENT, @@ -4611,48 +4888,52 @@ COMMENTAIRES: ".$comment; product_type_name VARCHAR(255) DEFAULT '' );"; - $this->execSQLNoData($sql,[]); + $this->execSQLNoData($sql, []); $sql = "ALTER TABLE oc_gestion_produit ADD fk_product_type_id INT NULL;"; - - $this->execSQLNoData($sql,[]); + + $this->execSQLNoData($sql, []); $sql = "INSERT INTO oc_gestion_product_type (product_type_key,product_type_name) VALUES (?,?);"; - $this->execSQLNoData($sql,[ProductConstant::PRODUCT_COVER_TYPE_KEY,ProductConstant::PRODUCT_COVER_TYPE_NAME]); + $this->execSQLNoData($sql, [ProductConstant::PRODUCT_COVER_TYPE_KEY,ProductConstant::PRODUCT_COVER_TYPE_NAME]); } - public function getProductTypes(){ + public function getProductTypes() + { $sql = "SELECT * FROM ".$this->tableprefix."product_type;"; - $productTypes = $this->execSQL($sql,[]); + $productTypes = $this->execSQL($sql, []); return $productTypes; } - public function addLocationCodesColumn(){ + public function addLocationCodesColumn() + { $sql = "ALTER TABLE oc_gestion_lieu ADD portal_code VARCHAR(255) DEFAULT NULL;"; - $this->execSQLNoData($sql,[]); + $this->execSQLNoData($sql, []); $sql = "ALTER TABLE oc_gestion_lieu ADD alarm_code VARCHAR(255) DEFAULT NULL;"; - $this->execSQLNoData($sql,[]); + $this->execSQLNoData($sql, []); $sql = "ALTER TABLE oc_gestion_lieu ADD funeral_code VARCHAR(255) DEFAULT NULL;"; - $this->execSQLNoData($sql,[]); + $this->execSQLNoData($sql, []); } - public function updateDevisMention(int $devisId,string $mention){ + public function updateDevisMention(int $devisId, string $mention) + { $sql = "UPDATE ".$this->tableprefix."devis as devis SET devis.mentions = ? WHERE devis.id = ?;"; - $this->execSQLNoData($sql,[$mention,$devisId]); + $this->execSQLNoData($sql, [$mention,$devisId]); } - public function getBijouxWithDefuntByBijouxId($bijouxId){ + public function getBijouxWithDefuntByBijouxId($bijouxId) + { $sql = "SELECT bijou.id, @@ -4665,72 +4946,80 @@ COMMENTAIRES: ".$comment; LEFT JOIN ".$this->tableprefix."defunt as defunt on bijou.defunt_id = defunt.id WHERE bijou.id = ? ;"; - $bijoux = $this->execSQLNoJsonReturn($sql,[$bijouxId,]); - if(!empty($bijoux)){ + $bijoux = $this->execSQLNoJsonReturn($sql, [$bijouxId,]); + if(!empty($bijoux)) { return $bijoux[0]; } return null; } - public function saveBijouxPhoto($bijouxId,$photo,$photoRealName){ + public function saveBijouxPhoto($bijouxId, $photo, $photoRealName) + { $sql = "UPDATE ".$this->tableprefix."bijou_defunt as bijou_defunt SET bijou_defunt.photo = ?,bijou_defunt.photo_name = ? WHERE bijou_defunt.id = ? ;"; $this->execSQLNoData( - $sql, - [$photo,$photoRealName,$bijouxId]); + $sql, + [$photo,$photoRealName,$bijouxId] + ); + - return true; } - public function saveDefuntPacemakerPhoto($defuntId,$photo,$photoRealName){ + public function saveDefuntPacemakerPhoto($defuntId, $photo, $photoRealName) + { $sql = "UPDATE ".$this->tableprefix."defunt as defunt SET defunt.product_photo = ?,defunt.product_photo_name = ? WHERE defunt.id = ? ;"; $this->execSQLNoData( - $sql, - [$photo,$photoRealName,$defuntId]); + $sql, + [$photo,$photoRealName,$defuntId] + ); + - return true; } - private function getFacturePaymentTypeById($facturePaymentTypeId){ + private function getFacturePaymentTypeById($facturePaymentTypeId) + { $sql = "SELECT * FROM ".$this->tableprefix."facture_payment_type as facture_payment_type WHERE facture_payment_type.id = ? LIMIT 1 "; - $facturePaymentType = $this->execSQLNoJsonReturn($sql,[$facturePaymentTypeId]); - if(!empty($facturePaymentType)){ + $facturePaymentType = $this->execSQLNoJsonReturn($sql, [$facturePaymentTypeId]); + if(!empty($facturePaymentType)) { return $facturePaymentType[0]; } return null; } - public function getFacturePaymentList(){ + public function getFacturePaymentList() + { $sql = "SELECT * FROM ".$this->tableprefix."facture_payment_type"; - return $this->execSQL($sql,[]); + return $this->execSQL($sql, []); } - public function payInvoices($factureIds,$facturePaymentTypeId,$paymentDate){ + public function payInvoices($factureIds, $facturePaymentTypeId, $paymentDate) + { $facturePaymentType = $this->getFacturePaymentTypeById($facturePaymentTypeId); - if($facturePaymentType == null){ + if($facturePaymentType == null) { return null; } - $paymentDate = Datetime::createFromFormat('Y-m-d',$paymentDate); - $paymentDate = $paymentDate->format('Y-m-d'); - foreach($factureIds as $factureId){ - $this->payAnInvoice($factureId,$facturePaymentTypeId,$paymentDate); + $paymentDate = Datetime::createFromFormat('Y-m-d', $paymentDate); + $paymentDate = $paymentDate->format('Y-m-d'); + foreach($factureIds as $factureId) { + $this->payAnInvoice($factureId, $facturePaymentTypeId, $paymentDate); } return true; } - private function payAnInvoice($factureId,$facturePaymentTypeId,$paymentDate){ + private function payAnInvoice($factureId, $facturePaymentTypeId, $paymentDate) + { $sql = "UPDATE ".$this->tableprefix."facture as facture SET facture.fk_facture_status_key = ?, @@ -4738,7 +5027,7 @@ COMMENTAIRES: ".$comment; facture.fk_facture_payment_type_id = ? WHERE facture.id = ? "; - $this->execSQLNoData($sql,[ + $this->execSQLNoData($sql, [ FactureStatusConstant::PAID_KEY, $paymentDate, $facturePaymentTypeId, @@ -4747,7 +5036,8 @@ COMMENTAIRES: ".$comment; return true; } - public function getUsersNotLinkedToThanato(){ + public function getUsersNotLinkedToThanato() + { $sql = "SELECT users.uid, @@ -4760,12 +5050,13 @@ COMMENTAIRES: ".$comment; thanato.fk_user_uuid IS NULL; "; - return $this->execSQL($sql,[BddConstant::DEFAULT_THANATOS_GROUP_NAME]); + return $this->execSQL($sql, [BddConstant::DEFAULT_THANATOS_GROUP_NAME]); } - public function doDevisIdsListIdsBelongsToTheSameClientFacturationGroup(array $devisIds){ + public function doDevisIdsListIdsBelongsToTheSameClientFacturationGroup(array $devisIds) + { - if(empty($devisIds)){ + if(empty($devisIds)) { return []; } $sqlPlacholders = implode(',', array_fill(0, count($devisIds), '?')); @@ -4778,90 +5069,96 @@ COMMENTAIRES: ".$comment; devis.id_client IS NOT NULL AND devis.id IN($sqlPlacholders);"; - $results = $this->execSQLNoJsonReturn($sql,$devisIds); + $results = $this->execSQLNoJsonReturn($sql, $devisIds); $clientGroupFacturationsIds = []; - foreach($results as $currentResult){ - if($currentResult['fk_client_group_facturation_id'] == null){ + foreach($results as $currentResult) { + if($currentResult['fk_client_group_facturation_id'] == null) { return false; } $clientGroupFacturationsIds[] = $currentResult['fk_client_group_facturation_id']; } $uniqueClientGroupFacturation = array_unique($clientGroupFacturationsIds); - return $uniqueClientGroupFacturation > 1; - + return $uniqueClientGroupFacturation > 1; + } - private function doesDevisFactureGroupAlreadyExist($factureId,$devisId){ + private function doesDevisFactureGroupAlreadyExist($factureId, $devisId) + { $sql = "SELECT count(*) as DEVIS_FACTURE_COUNT FROM ".$this->tableprefix."devis_facture as devis_facture WHERE devis_facture.fk_devis_id = ? AND devis_facture.fk_facture_id = ?"; - $result = $this->execSQLNoJsonReturn($sql,[$devisId,$factureId]); - if(!empty($result)){ + $result = $this->execSQLNoJsonReturn($sql, [$devisId,$factureId]); + if(!empty($result)) { return $result[0]["DEVIS_FACTURE_COUNT"] > 0; } return false; } - private function createFactureGroupDevis($factureId,$devisId){ + private function createFactureGroupDevis($factureId, $devisId) + { - $doesDevisFactureGroupAlreadyExist = $this->doesDevisFactureGroupAlreadyExist($factureId,$devisId); - if(!$doesDevisFactureGroupAlreadyExist){ + $doesDevisFactureGroupAlreadyExist = $this->doesDevisFactureGroupAlreadyExist($factureId, $devisId); + if(!$doesDevisFactureGroupAlreadyExist) { $sql = "INSERT INTO `".$this->tableprefix."devis_facture` (`fk_devis_id`,`fk_facture_id`) VALUES (?,?);"; $this->execSQLNoData($sql, [$devisId,$factureId]); - $this->gestion_update('devis','mentions',DevisMentionConstant::FACTURED_FORMATTED,$devisId,BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); + $this->gestion_update('devis', 'mentions', DevisMentionConstant::FACTURED_FORMATTED, $devisId, BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); } } - public function createFactureGroupForDevisList($factureId,$devisIds){ + public function createFactureGroupForDevisList($factureId, $devisIds) + { - foreach($devisIds as $devis){ - $this->createFactureGroupDevis($factureId,$devis['id']); + foreach($devisIds as $devis) { + $this->createFactureGroupDevis($factureId, $devis['id']); } } - private function getFactureIdByFactureNumber($factureNumber){ + private function getFactureIdByFactureNumber($factureNumber) + { $sql = "SELECT max(facture.id) AS FACTURE_ID FROM ".$this->tableprefix."facture as facture WHERE facture.num = ? ;"; - $result = $this->execSQLNoJsonReturn($sql,[$factureNumber]); - if(!empty($result)){ + $result = $this->execSQLNoJsonReturn($sql, [$factureNumber]); + if(!empty($result)) { return $result[0]['FACTURE_ID']; } return null; } - public function createFactureAndReturnFactureId($facturationDate,$type,$month = null,$year = null,$fkClientId = null,$fkClientGroupFacturationId = null){ + public function createFactureAndReturnFactureId($facturationDate, $type, $month = null, $year = null, $fkClientId = null, $fkClientGroupFacturationId = null) + { $datetimeNow = new Datetime(); $month = $month ?? $datetimeNow->format('m'); $year = $year ?? $datetimeNow->format('Y'); - if($facturationDate == null || $facturationDate == ""){ + if($facturationDate == null || $facturationDate == "") { $facturationDatetime = DateHelpers::GetLastDayOfTheMonthOfADate($datetimeNow); + } else { + $facturationDatetime = Datetime::createFromFormat('Y-m-d', $facturationDate); } - else{ - $facturationDatetime = Datetime::createFromFormat('Y-m-d',$facturationDate); - } - $facturationDate = $facturationDatetime->format('Y-m-d'); + $facturationDate = $facturationDatetime->format('Y-m-d'); $factureDate = $facturationDate; $factureNumber = $this->getFactureNumberByDate($facturationDatetime); - $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime,$factureNumber,"FAC"); + $fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($facturationDatetime, $factureNumber, "FAC"); $last = 0; $last = $this->lastNumFacture(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); $sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`,`facture_type`,`month`,`year`,`fk_client_id`,`fk_client_group_facturation_id`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; - $this->execSQLNoData($sql, array( + $this->execSQLNoData( + $sql, + array( - $factureDate, - BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD, + $factureDate, + BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD, $fullFactureNumber, $facturationDate, "", 0, - $last+1, + $last + 1, "", $factureNumber, $type, @@ -4875,33 +5172,36 @@ COMMENTAIRES: ".$comment; } - public function generateGroupFactureForMultipleDevis($devisToFacture,$paymentDate){ + public function generateGroupFactureForMultipleDevis($devisToFacture, $paymentDate) + { $mentionsFilter = [ DevisMentionConstant::NEW, DevisMentionConstant::MENTION ]; - $devisIdListFiltered = $this->getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter,$devisToFacture); - $factureId = $this->createFactureAndReturnFactureId($paymentDate,FactureTypeConstant::TYPE_GROUP); - $this->createFactureGroupForDevisList($factureId,$devisIdListFiltered); + $devisIdListFiltered = $this->getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter, $devisToFacture); + $factureId = $this->createFactureAndReturnFactureId($paymentDate, FactureTypeConstant::TYPE_GROUP); + $this->createFactureGroupForDevisList($factureId, $devisIdListFiltered); return [$factureId]; } - public function getFactureTypeByFactureId($factureId): mixed{ + public function getFactureTypeByFactureId($factureId): mixed + { $sql = "SELECT facture.facture_type FROM ".$this->tableprefix."facture as facture WHERE facture.id = ? LIMIT 1;"; - $result = $this->execSQLNoJsonReturn($sql,[$factureId]); - if(!empty($result)){ + $result = $this->execSQLNoJsonReturn($sql, [$factureId]); + if(!empty($result)) { return $result[0]['facture_type']; } return FactureTypeConstant::TYPE_SINGLE; } - public function getDevisByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId,$month,$year,$mentionsFilters = []){ + public function getDevisByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId, $month, $year, $mentionsFilters = []) + { $sql = "SELECT devis.id ,devis.id_client,client.fk_client_group_id FROM ".$this->tableprefix."devis as devis @@ -4913,21 +5213,22 @@ COMMENTAIRES: ".$comment; "; $conditions = [$clientGroupFacturationId,$year,$month]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND ". $this->tableprefix."devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= ";"; - $result = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= ";"; + $result = $this->execSQLNoJsonReturn($sql, $conditions); return $result; } - public function getDevisIdsByClientGroupFacturationIdAnDate($clientGroupFacturationId,$facturationDate , $mentionFilters = []){ + public function getDevisIdsByClientGroupFacturationIdAnDate($clientGroupFacturationId, $facturationDate, $mentionFilters = []) + { - $dateTime = Datetime::createFromFormat('Y-m-d',$facturationDate); + $dateTime = Datetime::createFromFormat('Y-m-d', $facturationDate); $month = $dateTime->format('m'); $year = $dateTime->format('Y'); @@ -4942,22 +5243,23 @@ COMMENTAIRES: ".$comment; $conditions = [$clientGroupFacturationId,$year,$month ,$facturationDate]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= ";"; - $result = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= ";"; + $result = $this->execSQLNoJsonReturn($sql, $conditions); $devisIds = []; - foreach($result as $currentResult){ + foreach($result as $currentResult) { $devisIds[] = $currentResult['id']; } return $devisIds; } //OLD concept - public function getDevisIdsByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId,$month,$year,$mentionFilters = []){ + public function getDevisIdsByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId, $month, $year, $mentionFilters = []) + { $sql = "SELECT devis.id FROM ".$this->tableprefix."devis as devis @@ -4969,22 +5271,23 @@ COMMENTAIRES: ".$comment; "; $conditions = [$clientGroupFacturationId,$year,$month]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND ". $this->tableprefix."devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= ";"; - $result = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= ";"; + $result = $this->execSQLNoJsonReturn($sql, $conditions); $devisIds = []; - foreach($result as $currentResult){ + foreach($result as $currentResult) { $devisIds[] = $currentResult['id']; } return $devisIds; } - public function getDevisByClientIdAndMonthYear($clientId,$month,$year,$mentionFilters = []){ + public function getDevisByClientIdAndMonthYear($clientId, $month, $year, $mentionFilters = []) + { $sql = "SELECT devis.id,devis.id_client,client.fk_client_group_id FROM ".$this->tableprefix."devis as devis @@ -4995,17 +5298,18 @@ COMMENTAIRES: ".$comment; MONTH(devis.date) = ?"; $conditions = [$clientId,$year,$month]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= ";"; - $result = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= ";"; + $result = $this->execSQLNoJsonReturn($sql, $conditions); return $result; } - public function getDevisByClientIdByFactureId($factureId , $mentionFilters = []){ + public function getDevisByClientIdByFactureId($factureId, $mentionFilters = []) + { $sql = "SELECT devis.id,devis.id_client,client.fk_client_group_id FROM ".$this->tableprefix."devis as devis @@ -5013,23 +5317,24 @@ COMMENTAIRES: ".$comment; WHERE devis.fk_facture_id = ? "; $conditions = [$factureId]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= ";"; - $result = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= ";"; + $result = $this->execSQLNoJsonReturn($sql, $conditions); return $result; } - public function getDevisIdsByClientIdAndDate($clientId,$date,$mentionFilters = [] ){ + public function getDevisIdsByClientIdAndDate($clientId, $date, $mentionFilters = []) + { - $dateTime = Datetime::createFromFormat('Y-m-d',$date); + $dateTime = Datetime::createFromFormat('Y-m-d', $date); $month = $dateTime->format('m'); $year = $dateTime->format('Y'); - + $sql = "SELECT devis.id,devis.id_client,client.fk_client_group_id FROM ".$this->tableprefix."devis as devis LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id @@ -5040,22 +5345,23 @@ COMMENTAIRES: ".$comment; devis.date <= ? "; $conditions = [$clientId,$year,$month ,$date]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= ";"; - $result = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= ";"; + $result = $this->execSQLNoJsonReturn($sql, $conditions); $devisIds = []; - foreach($result as $currentResult){ + foreach($result as $currentResult) { $devisIds[] = $currentResult['id']; } return $devisIds; - + } - public function getDevisIdsByClientIdAndMonthYear($clientId,$month,$year,$mentionFilters = []){ + public function getDevisIdsByClientIdAndMonthYear($clientId, $month, $year, $mentionFilters = []) + { $sql = "SELECT devis.id,devis.id_client,client.fk_client_group_id FROM ".$this->tableprefix."devis as devis @@ -5066,23 +5372,24 @@ COMMENTAIRES: ".$comment; MONTH(devis.date) = ?"; $conditions = [$clientId,$year,$month]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= ";"; - $result = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= ";"; + $result = $this->execSQLNoJsonReturn($sql, $conditions); $devisIds = []; - foreach($result as $currentResult){ + foreach($result as $currentResult) { $devisIds[] = $currentResult['id']; } return $devisIds; - + } - public function getFactureIdByClientIdAndDate($clientId,$facturationDate){ + public function getFactureIdByClientIdAndDate($clientId, $facturationDate) + { $sql = "SELECT @@ -5093,19 +5400,20 @@ COMMENTAIRES: ".$comment; facture.facture_type = ? AND facture.date_paiement = ? "; - $result = $this->execSQLNoJsonReturn($sql,[ + $result = $this->execSQLNoJsonReturn($sql, [ $clientId, FactureTypeConstant::TYPE_GROUP, $facturationDate, ]); - - if(!empty($result)){ + + if(!empty($result)) { return $result[0]['facture_id']; } return null; } - public function getFactureIdByClientGroupFacturationIdAndDate($clientId,$facturationDate){ + public function getFactureIdByClientGroupFacturationIdAndDate($clientId, $facturationDate) + { $sql = "SELECT facture.id as facture_id @@ -5114,21 +5422,22 @@ COMMENTAIRES: ".$comment; facture.fk_client_group_facturation_id = ? AND facture.facture_type = ? AND facture.date_paiement = ? "; - - $result = $this->execSQLNoJsonReturn($sql,[ + + $result = $this->execSQLNoJsonReturn($sql, [ $clientId, FactureTypeConstant::TYPE_GROUP, $facturationDate ]); - - if(!empty($result)){ + + if(!empty($result)) { return $result[0]['facture_id']; } return null; } - public function invoiceListOfDevisIds($devisIds ,$factureId){ + public function invoiceListOfDevisIds($devisIds, $factureId) + { $sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisIds), '?')); $sql = "UPDATE ".$this->tableprefix."devis as devis @@ -5140,10 +5449,11 @@ COMMENTAIRES: ".$comment; $devisIds ); - $this->execSQLNoData($sql,$conditions); + $this->execSQLNoData($sql, $conditions); } - private function getDevisDataByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId,$month,$year,$mentionFilters = []){ + private function getDevisDataByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId, $month, $year, $mentionFilters = []) + { $sql = "SELECT devis.id as devis_id, @@ -5188,18 +5498,19 @@ COMMENTAIRES: ".$comment; MONTH(devis.date) = ?"; $conditions = [$clientGroupFacturationId,$year,$month]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= " ORDER BY devis.date ASC;"; - $devisList = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= " ORDER BY devis.date ASC;"; + $devisList = $this->execSQLNoJsonReturn($sql, $conditions); return $devisList; } - public function getDevisDataGroupByFactureId($factureId ,$mentionFilters = []){ + public function getDevisDataGroupByFactureId($factureId, $mentionFilters = []) + { $sql = "SELECT devis.id as devis_id, @@ -5241,17 +5552,18 @@ COMMENTAIRES: ".$comment; WHERE devis.fk_facture_id = ? "; $conditions = [$factureId]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= " ORDER BY devis.date ASC;"; - $devisList = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= " ORDER BY devis.date ASC;"; + $devisList = $this->execSQLNoJsonReturn($sql, $conditions); return $devisList; } - private function getDevisDataByClientIdAndMonthYear($clientId,$month,$year,$mentionFilters = []){ + private function getDevisDataByClientIdAndMonthYear($clientId, $month, $year, $mentionFilters = []) + { $sql = "SELECT devis.id as devis_id, @@ -5295,33 +5607,36 @@ COMMENTAIRES: ".$comment; MONTH(devis.date) = ?"; $conditions = [$clientId,$year,$month]; - if(!empty($mentionFilters)){ + if(!empty($mentionFilters)) { $mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?')); $sql .= " AND devis.mentions IN ($mentionsFilterPlaceholders)"; $conditions = array_merge($conditions, $mentionFilters); } - $sql.= " ORDER BY devis.date ASC;"; - $devisList = $this->execSQLNoJsonReturn($sql,$conditions); + $sql .= " ORDER BY devis.date ASC;"; + $devisList = $this->execSQLNoJsonReturn($sql, $conditions); return $devisList; } - public function getClientTemplateTypes(){ + public function getClientTemplateTypes() + { $sql = "SELECT * FROM ".$this->tableprefix."client_template_type as client_template_type"; - return $this->execSQL($sql,[]); + return $this->execSQL($sql, []); } - public function getDevisByFkFactureId($factureId){ + public function getDevisByFkFactureId($factureId) + { $sql = "SELECT * FROM ".$this->tableprefix."devis as devis WHERE devis.fk_facture_id = ? LIMIT 1;"; - $result = $this->execSQLNoJsonReturn($sql,[$factureId]); - if(!empty($result)){ + $result = $this->execSQLNoJsonReturn($sql, [$factureId]); + if(!empty($result)) { return $result[0]; } return null; } - public function getFactureGroupById($factureId){ + public function getFactureGroupById($factureId) + { $sql = "SELECT facture.id, @@ -5339,21 +5654,22 @@ COMMENTAIRES: ".$comment; facture.facture_type = ? ;"; - $result = $this->execSQLNoJsonReturn($sql,[$factureId,FactureTypeConstant::TYPE_GROUP]); - if(!empty($result)){ + $result = $this->execSQLNoJsonReturn($sql, [$factureId,FactureTypeConstant::TYPE_GROUP]); + if(!empty($result)) { return $result[0]; } return null; } - public function getFactureGroupByFactureIdWithDetails($factureId){ + public function getFactureGroupByFactureIdWithDetails($factureId) + { $facture = $this->getFactureGroupById($factureId); $configuration = $this->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); $configuration = json_decode($configuration); $currentConfig = $configuration[0]; - $isFactureSingleClient = $facture['fk_client_id'] != null + $isFactureSingleClient = $facture['fk_client_id'] != null && $facture['fk_client_id'] != 0; $devisMentionFilters = [ @@ -5383,9 +5699,9 @@ COMMENTAIRES: ".$comment; $tvaValue = 0; } } - - if($isFactureSingleClient){ + + if($isFactureSingleClient) { $client = $this->getClientById($facture['fk_client_id']); $facture['group_name'] = $client["client_nom"]; $facture['client_name'] = $client["client_prenom"]; @@ -5400,16 +5716,15 @@ COMMENTAIRES: ".$comment; $facture['year'], $devisMentionFilters ); - - }else{ - $devisList = $this->getDevisDataGroupByFactureId( $factureId,$devisMentionFilters); + + } else { + $devisList = $this->getDevisDataGroupByFactureId($factureId, $devisMentionFilters); } - } - else{ + } else { $clientGroupFacturation = $this->getClientGroupFacturationById($facture['fk_client_group_facturation_id']); $facture['group_name'] = $clientGroupFacturation["group_facturation_name"]; $facture['client_name'] = $clientGroupFacturation["group_facturation_name"]; - $facture['client_address'] = $clientGroupFacturation["address"] . ' - ' .$clientGroupFacturation["postal_code"] . ' ' . $clientGroupFacturation['city']; + $facture['client_address'] = $clientGroupFacturation["address"] . ' - ' .$clientGroupFacturation["postal_code"] . ' ' . $clientGroupFacturation['city']; $facture['siret'] = $clientGroupFacturation["siret_number"]; $facture['mail'] = $clientGroupFacturation["email"]; @@ -5420,22 +5735,22 @@ COMMENTAIRES: ".$comment; $facture['year'], $devisMentionFilters ); - }else{ - $devisList = $this->getDevisDataGroupByFactureId( $factureId,$devisMentionFilters); + } else { + $devisList = $this->getDevisDataGroupByFactureId($factureId, $devisMentionFilters); } } - $factureTotalHt= 0; + $factureTotalHt = 0; $factureTotalTva = 0; $factureTotalTtc = 0; - foreach($devisList as &$currentDevis){ + foreach($devisList as &$currentDevis) { $totalHt = 0; $totalTva = 0; $totalTtc = 0; $devisProducts = $this->getDevisProduits($currentDevis['devis_id']); - foreach($devisProducts as $currentProduct){ + foreach($devisProducts as $currentProduct) { $valueHt = $currentProduct['produit_price'] * $currentProduct['quantite']; // CALCUL SIMPLE : TVA OU PAS TVA @@ -5643,30 +5958,33 @@ COMMENTAIRES: ".$comment; $factureData["client_tva_intracommu"] = $groupClient["tva_intracommu"]; return $factureData; } - - public function setFactureGeneratedDate($factureId){ + + public function setFactureGeneratedDate($factureId) + { $datetimeNow = new Datetime(); $dateNow = $datetimeNow->format("Y-m-d"); $sql = "UPDATE ".$this->tableprefix."facture set document_generated_date = ? WHERE id = ?"; - $this->execSQLNoData($sql,[ + $this->execSQLNoData($sql, [ $dateNow, $factureId ]); } - public function setFactureSentDate($factureId){ + public function setFactureSentDate($factureId) + { $datetimeNow = new Datetime(); $dateNow = $datetimeNow->format("Y-m-d"); $sql = "UPDATE ".$this->tableprefix."facture set document_sent_date = ? WHERE id = ?"; - $this->execSQLNoData($sql,[ + $this->execSQLNoData($sql, [ $dateNow, $factureId ]); } - public function getFactureClientMailByFactureId($factureId){ + public function getFactureClientMailByFactureId($factureId) + { $sql = "SELECT facture.id, @@ -5694,18 +6012,17 @@ COMMENTAIRES: ".$comment; LIMIT 1;"; $mail = null; - $result = $this->execSQLNoJsonReturn($sql,[$factureId]); - if(!empty($result)){ + $result = $this->execSQLNoJsonReturn($sql, [$factureId]); + if(!empty($result)) { $facture = $result[0]; $factureIsSingle = $facture["facture_type"] == FactureTypeConstant::TYPE_SINGLE; - if($factureIsSingle){ - $mail = $facture["fk_client_group_facturation_id"] != null ? + if($factureIsSingle) { + $mail = $facture["fk_client_group_facturation_id"] != null ? $facture["devis_client_group_mail"] : $facture["devis_client_mail"]; - } - else{ + } else { $factureIsClientWithoutGroup = $facture["facture_client_id"] != null && $facture["facture_client_id"] != 0; - $mail = $factureIsClientWithoutGroup ? + $mail = $factureIsClientWithoutGroup ? $facture["facture_client_mail"] : $facture["facture_client_group_mail"]; } @@ -5733,7 +6050,7 @@ COMMENTAIRES: ".$comment; } return null; } - + public function getTvaItracomuIdClient($clientId) { $sql = "SELECT diff --git a/gestion/lib/Service/InvoicePdfHandler.php b/gestion/lib/Service/InvoicePdfHandler.php index e9a1822..48679c0 100644 --- a/gestion/lib/Service/InvoicePdfHandler.php +++ b/gestion/lib/Service/InvoicePdfHandler.php @@ -35,7 +35,6 @@ use OCA\Gestion\Helpers\PriceHelpers; class InvoicePdfHandler extends FPDF { - private $multipleFactureData = []; private $factureData = []; private $logo = null; @@ -51,7 +50,7 @@ class InvoicePdfHandler extends FPDF public $interLigneHeader = 5; public $hasTva = true; - function Header() + public function Header() { if ($this->logo != "nothing") { $this->Image($this->logoPath . "logo.png", 4, 2, 50, 35); @@ -129,7 +128,7 @@ class InvoicePdfHandler extends FPDF $this->factureData = $factureData; $this->logo = $logo; // Déterminer si la TVA est applicable - $this->hasTva = isset($factureData['tva']) ? $factureData['tva'] : true; + $this->hasTva = isset($factureData['is_tva']) ? $factureData['is_tva'] : true; } public function MutlipleInvoicePdfFactory(array $multipleInvoiceData, $logo = null)