2942 lines
154 KiB
PHP
2942 lines
154 KiB
PHP
<?php
|
|
namespace OCA\Gestion\Db;
|
|
|
|
use OCA\Gestion\Constants\BddConstant;
|
|
use OCA\Gestion\Constants\DevisMentionConstant;
|
|
use OCA\Gestion\Constants\ThanatoTypeConstant;
|
|
use OCA\Gestion\Helpers\DateHelpers;
|
|
use OCA\Gestion\Helpers\VCalendarHelpers;
|
|
use OCP\IDBConnection;
|
|
use OCP\IL10N;
|
|
use \Datetime;
|
|
use OCA\Gestion\Helpers\FileExportHelpers;
|
|
|
|
class Bdd {
|
|
private String $charset = 'utf8mb4';
|
|
|
|
public const DEFAULT_CALENDAR_UUID_FOR_DEVIS = "not-related";
|
|
public const DEFAULT_TABLE_PREFIX = "*PREFIX*";
|
|
|
|
private IDbConnection $pdo;
|
|
|
|
public const CALENDAR_TABLE_PREFIX = "*PREFIX*";
|
|
private array $whiteColumn;
|
|
private array $whiteTable;
|
|
private String $tableprefix;
|
|
private $l;
|
|
|
|
public function __construct(IDbConnection $db,
|
|
IL10N $l) {
|
|
$this->whiteColumn = array("date", "num", "id_client", "entreprise", "nom", "prenom", "legal_one", "telephone", "mail", "adresse", "produit_id", "quantite", "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",
|
|
"sexe", "date_naissance", "observations_generales", "ref_pacemaker", "id_defunt", "article_id", "corpulence", "id_thanato",
|
|
"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",
|
|
"commentaire", "designation", "hypodermiques_text1", "hypodermiques_text2", "qte", "endroit",
|
|
"fk_thanato_type_key","thanato_email","fk_user_uuid",
|
|
"fk_defunt_id","fk_lieu_id","fk_client_id","fk_thanato_id",
|
|
"fk_product_id","ht_price",
|
|
"fk_client_group_id","fk_produit_id","ht_amount","client_group_name");
|
|
$this->whiteTable = array("client", "lieu", "trajet", "devis", "produit_devis", "facture", "produit",
|
|
"configuration", "ligne_trajet", "thanato", "article", "defunt", "article_devis",
|
|
"bibliotheque", "bijou_defunt", "obs_defunt", "hypo_defunt",
|
|
"orders","thanato_product_discount",
|
|
"client_group_discount","client_group");
|
|
$this->tableprefix = '*PREFIX*' ."gestion_";
|
|
$this->pdo = $db;
|
|
$this->l = $l;
|
|
}
|
|
|
|
public function genererDefunt($idNextcloud) {
|
|
$devis = json_decode($this->getDevis($idNextcloud));
|
|
$sql_delete = "DELETE FROM ".$this->tableprefix."defunt;";
|
|
$this->execSQLNoData($sql_delete, array());
|
|
//genereation de défunts
|
|
foreach ($devis as $key => $d) {
|
|
$sql = "INSERT INTO `".$this->tableprefix."defunt` (
|
|
`id_nextcloud`, `nom`, `sexe`, `date_naissance`, `ref_pacemaker`, `date`,
|
|
`corpulence`, `observations_corps`, `observations_generales`
|
|
) VALUES (?,?,?,?,?,?,?,?,?);";
|
|
$res = $this->execSQLNoData($sql, array($idNextcloud, $d->num, 'm', '1973-11-11', 'Référence pacemaker', $d->date, '', '', ''));
|
|
$idDefunt = $this->pdo->lastInsertId($this->tableprefix . 'defunt');
|
|
$this->gestion_update('devis', 'id_defunt', $idDefunt, $d->devisid, $idNextcloud);
|
|
}
|
|
}
|
|
|
|
public function getConfiguration($idNextcloud){
|
|
$sql = "SELECT * FROM `".$this->tableprefix."configuration` WHERE id_nextcloud = ?";
|
|
return $this->execSQL($sql, array($idNextcloud));
|
|
}
|
|
|
|
public function getTotalDevis($iddevis, $idNextcloud) {
|
|
$articles = json_decode($this->getListArticle($iddevis, $idNextcloud));
|
|
$produits = json_decode($this->getListProduit($iddevis, $idNextcloud));
|
|
$total=0;
|
|
foreach($articles as $key => $article) {
|
|
$total += $article->prix_unitaire*$article->quantite;
|
|
}
|
|
foreach($produits as $key => $produit) {
|
|
$total += $produit->prix_unitaire*$produit->quantite;
|
|
}
|
|
return $total;
|
|
}
|
|
|
|
public function getClients($idNextcloud){
|
|
$sql = "SELECT * FROM ".$this->tableprefix."client;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getClientsByDateDevis($idNextcloud, $date) {
|
|
$sql = "SELECT *
|
|
FROM ".$this->tableprefix."client
|
|
WHERE ".$this->tableprefix."client.id IN (
|
|
SELECT ".$this->tableprefix."devis.id_client
|
|
FROM ".$this->tableprefix."devis
|
|
WHERE ".$this->tableprefix."devis.date = ?
|
|
);";
|
|
return $this->execSQL($sql, array($date));
|
|
}
|
|
|
|
public function getClient($id,$idNextcloud){
|
|
$sql = "SELECT * FROM ".$this->tableprefix."client WHERE id = ?";
|
|
return $this->execSQL($sql, array($id));
|
|
}
|
|
|
|
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){
|
|
$sql = "SELECT
|
|
thanato.id,
|
|
thanato.nom,
|
|
thanato.prenom,
|
|
thanato.reference,
|
|
thanato.date_habilitation,
|
|
thanato.id_nextcloud,
|
|
thanato.fk_thanato_type_key,
|
|
thanato.thanato_email,
|
|
thanato_type.thanato_type_label,
|
|
thanato.fk_user_uuid,
|
|
users.uid as user_uuid,
|
|
users.displayname as user_display_name
|
|
FROM ".$this->tableprefix."thanato as thanato
|
|
LEFT JOIN ".$this->tableprefix."thanato_type as thanato_type on thanato.fk_thanato_type_key = thanato_type.thanato_type_key
|
|
LEFT JOIN ".self::DEFAULT_TABLE_PREFIX."users as users on thanato.fk_user_uuid = users.uid
|
|
;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getBibliotheques($idNextcloud) {
|
|
$sql = "SELECT * FROM ".$this->tableprefix."bibliotheque;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getTrajets($idNextcloud) {
|
|
// $sql_delete = "DELETE FROM ".$this->tableprefix."ligne_trajet";
|
|
// $this->execSQL($sql_delete, array());
|
|
// $sql_delete = "DELETE FROM ".$this->tableprefix."trajet";
|
|
// $this->execSQL($sql_delete, array());
|
|
$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
|
|
FROM ".$this->tableprefix."trajet as trajet
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on trajet.id_thanato = thanato.id
|
|
ORDER BY trajet.annee DESC, trajet.mois DESC;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
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
|
|
FROM ".$this->tableprefix."trajet as trajet
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on trajet.id_thanato = thanato.id
|
|
WHERE trajet.id = ?";
|
|
return $this->execSQL($sql, array($numtrajet));
|
|
}
|
|
|
|
public function getTrajetsdetailsPROPRE($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,
|
|
devis.id as did, devis.num as dnum, client_devis.nom as dnom, client_devis.prenom as dprenoms, devis.id_nextcloud as didnextcloud, devis.id_defunt,
|
|
defunt.nom as nom_defunt,
|
|
client.nom as cnom, client.id as cid, client.prenom as cprenoms
|
|
FROM ".$this->tableprefix."ligne_trajet as ligne_trajet
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on ligne_trajet.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."devis as devis on ligne_trajet.id_devis = devis.id
|
|
LEFT JOIN ".$this->tableprefix."client as client_devis on devis.id_client = client_devis.id
|
|
LEFT JOIN ".$this->tableprefix."client as client on ligne_trajet.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
WHERE ligne_trajet.id_trajet = ? ORDER BY ligne_trajet.rang ASC;";
|
|
return $this->execSQL($sql, array($numtrajet));
|
|
}
|
|
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,
|
|
devis.id as did, devis.num as dnum, client_devis.nom as dnom, client_devis.prenom as dprenoms, devis.id_defunt,
|
|
defunt.nom as nom_defunt,
|
|
client.nom as cnom, client.id as cid, client.prenom as cprenoms
|
|
FROM ".$this->tableprefix."ligne_trajet as ligne_trajet
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on ligne_trajet.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."devis as devis on ligne_trajet.id_devis = devis.id
|
|
LEFT JOIN ".$this->tableprefix."client as client_devis on devis.id_client = client_devis.id
|
|
LEFT JOIN ".$this->tableprefix."client as client on ligne_trajet.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
WHERE ligne_trajet.id_trajet = ? ORDER BY ligne_trajet.rang ASC;";
|
|
return $this->execSQL($sql, array($numtrajet));
|
|
}
|
|
|
|
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,
|
|
client.nom as cnom, client.id as cid, client.prenom as cprenoms
|
|
FROM (".$this->tableprefix."ligne_trajet as ligne_trajet
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on ligne_trajet.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."client as client on ligne_trajet.id_client = client.id)
|
|
WHERE ligne_trajet.id_trajet = ?
|
|
ORDER BY ligne_trajet.date ASC, ligne_trajet.rang ASC;";
|
|
return $this->execSQL($sql, array($numtrajet));
|
|
}
|
|
|
|
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) {
|
|
$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) {
|
|
$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) {
|
|
$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
|
|
FROM ".$this->tableprefix."trajet as trajet
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on trajet.id_thanato = thanato.id
|
|
WHERE trajet.id = ".$id." ORDER BY trajet.id DESC;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getLieux($idNextcloud){
|
|
$sql = "SELECT lieu.nom, lieu.adresse, lieu.latitude,lieu.longitude, lieu.user_id, lieu.id
|
|
FROM ".$this->tableprefix."lieu as lieu
|
|
ORDER BY lieu.id DESC";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getLieu($id,$idNextcloud){
|
|
$sql = "SELECT * FROM ".$this->tableprefix."lieu WHERE id = ?";
|
|
return $this->execSQL($sql, array($id));
|
|
}
|
|
|
|
public function getDevis($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."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
|
|
LEFT JOIN ".$this->tableprefix."defunt on id_defunt = ".$this->tableprefix."defunt.id
|
|
LEFT JOIN ".$this->tableprefix."client on id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."thanato on id_thanato = ".$this->tableprefix."thanato.id
|
|
LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id
|
|
) ORDER BY ".$this->tableprefix."devis.id DESC, ".$this->tableprefix."devis.date DESC;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getDevisByThanato($idNextcloud, $idThanato) {
|
|
$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."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
|
|
LEFT JOIN ".$this->tableprefix."defunt on id_defunt = ".$this->tableprefix."defunt.id
|
|
LEFT JOIN ".$this->tableprefix."client on id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."thanato on id_thanato = ".$this->tableprefix."thanato.id
|
|
LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id
|
|
) WHERE id_thanato = ? ORDER BY ".$this->tableprefix."devis.id DESC, ".$this->tableprefix."devis.date DESC;";
|
|
return $this->execSQL($sql, array($idThanato));
|
|
}
|
|
|
|
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."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,".$this->tableprefix."devis.id_lieu
|
|
FROM (".$this->tableprefix."devis
|
|
LEFT JOIN ".$this->tableprefix."client on id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."thanato on id_thanato = ".$this->tableprefix."thanato.id
|
|
LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."defunt on id_defunt = ".$this->tableprefix."defunt.id
|
|
) WHERE LOWER(".$this->tableprefix."devis.id_nextcloud) LIKE 'emmanuelle' ORDER BY ".$this->tableprefix."devis.id DESC, ".$this->tableprefix."devis.date DESC;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
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."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
|
.$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
|
|
LEFT JOIN ".$this->tableprefix."thanato on id_thanato = ".$this->tableprefix."thanato.id
|
|
LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."defunt on id_defunt = ".$this->tableprefix."defunt.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;
|
|
|
|
$sql = $sql." ORDER BY ".$this->tableprefix."devis.id DESC, ".$this->tableprefix."devis.date DESC;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getDevisByDateByLieu($idNextcloud, $idtrajetdetails, $idclient, $date, $idlieu) {
|
|
$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."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
|
|
LEFT JOIN ".$this->tableprefix."defunt on id_defunt = ".$this->tableprefix."defunt.id
|
|
LEFT JOIN ".$this->tableprefix."client on id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."thanato on id_thanato = ".$this->tableprefix."thanato.id
|
|
LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id
|
|
) WHERE ".$this->tableprefix."devis.date = ? ".
|
|
(($idclient > 0) ? "AND ".$this->tableprefix."client.id = ? " : "").
|
|
(($idlieu > 0) ? "AND ".$this->tableprefix."lieu.id = ? " : "").
|
|
"ORDER BY ".$this->tableprefix."devis.id DESC, ".$this->tableprefix."devis.date DESC;";
|
|
$values = [$date];
|
|
if($idclient > 0) array_push($values, $idclient);
|
|
if($idlieu > 0) array_push($values, $idlieu);
|
|
return $this->execSQL($sql, $values);
|
|
}
|
|
|
|
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."devis.num as dnum, ".$this->tableprefix."devis.comment as dcomment, date_paiement, type_paiement, id_devis, entreprise, "
|
|
.$this->tableprefix."facture.version, status_paiement,"
|
|
.$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, ".$this->tableprefix."client.id as id_cli, "
|
|
.$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."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."facture
|
|
LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id)
|
|
LEFT JOIN ".$this->tableprefix."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
|
|
ORDER BY ".$this->tableprefix."facture.id DESC, ".$this->tableprefix."facture.date_paiement DESC";
|
|
$result = $this->execSQL($sql, array());
|
|
return $result;
|
|
}
|
|
|
|
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, "
|
|
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
|
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
|
.$this->tableprefix."client.mail as mail_client, ".$this->tableprefix."client.entreprise as client_entreprise, ".$this->tableprefix."client.fk_client_group_id as fk_client_group_id, "
|
|
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
|
.$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."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
|
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
|
|
// 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
|
|
// ORDER BY year DESC, month DESC;";
|
|
$result = $this->execSQL($sql, array());
|
|
return $result;
|
|
}
|
|
|
|
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, "
|
|
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
|
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
|
.$this->tableprefix."client.mail as mail_client, "
|
|
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
|
.$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."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
|
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
|
|
// 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
|
|
// ORDER BY year DESC, month DESC;";
|
|
$result = $this->execSQL($sql, array());
|
|
return $result;
|
|
}
|
|
|
|
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, "
|
|
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
|
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
|
.$this->tableprefix."client.entreprise as client_entreprise, ".$this->tableprefix."client.fk_client_group_id as fk_client_group_id, "
|
|
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
|
.$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."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
|
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')
|
|
// ORDER BY year DESC, month DESC;";
|
|
|
|
$result = $this->execSQL($sql, array());
|
|
return $result;
|
|
}
|
|
|
|
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,
|
|
thanato.id as id_thanato, thanato.nom as nom_thanato, thanato.prenom as prenom_thanato
|
|
FROM ".$this->tableprefix."trajet t
|
|
INNER JOIN ".$this->tableprefix."lieu depart ON t.id_lieu_depart = depart.id
|
|
INNER JOIN ".$this->tableprefix."lieu arrivee ON t.id_lieu_arrivee = arrivee.id
|
|
INNER JOIN ".$this->tableprefix."client depart_c ON depart.id_client = depart_c.id
|
|
INNER JOIN ".$this->tableprefix."client arrivee_c ON arrivee.id_client = arrivee_c.id
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on t.id_thanato = thanato.id
|
|
WHERE MONTH(t.date) = ".explode('-', $date)[1].";";
|
|
|
|
$result = $this->execSQL($sql, array());
|
|
return $result;
|
|
}
|
|
|
|
public function getOneFacture($numfacture, $idNextcloud){
|
|
// $sql = "SELECT ".$this->tableprefix."facture.id," . $this->tableprefix . "facture.version," . $this->tableprefix . "facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum, comment, date_paiement, type_paiement, id_devis, nom, prenom, entreprise FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id AND ".$this->tableprefix."facture.id_nextcloud = ".$this->tableprefix."devis.id_nextcloud) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id AND ".$this->tableprefix."devis.id_nextcloud = ".$this->tableprefix."client.id_nextcloud WHERE ".$this->tableprefix."facture.id = ? AND ".$this->tableprefix."facture.id_nextcloud = ?";
|
|
$sql = "SELECT ".$this->tableprefix."facture.id," . $this->tableprefix . "facture.version," . $this->tableprefix . "facture.num, "
|
|
.$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum, comment, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom, prenom, entreprise,"
|
|
.$this->tableprefix."devis.comment as dcomment,".$this->tableprefix."lieu.nom as lieu, ".$this->tableprefix."lieu.adresse as adresse_soin, "
|
|
.$this->tableprefix."defunt.nom as nom_defunt
|
|
FROM (".$this->tableprefix."facture
|
|
LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id
|
|
LEFT JOIN ".$this->tableprefix."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id)
|
|
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
|
|
WHERE ".$this->tableprefix."facture.id = ?";
|
|
// return $this->execSQL($sql, array($numfacture, $idNextcloud));
|
|
return $this->execSQL($sql, array($numfacture));
|
|
}
|
|
|
|
public function getProduits($idNextcloud){
|
|
// $sql = "SELECT * FROM ".$this->tableprefix."produit WHERE id_nextcloud = ?";
|
|
$sql = "SELECT * FROM ".$this->tableprefix."produit";
|
|
// return $this->execSQL($sql, array($idNextcloud));
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getDefunts($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."client.nom as nom_client, ".$this->tableprefix."client.id as id_client, ".$this->tableprefix."devis.user_id as user_id, "
|
|
.$this->tableprefix."devis.num as numero_devis, ".$this->tableprefix."devis.id as id_devis, "
|
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu
|
|
FROM ".$this->tableprefix."defunt
|
|
LEFT JOIN ".$this->tableprefix."devis ON ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
|
|
LEFT JOIN ".$this->tableprefix."client ON ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."lieu ON ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
|
ORDER BY ".$this->tableprefix."defunt.id DESC;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
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
|
|
FROM ".$this->tableprefix."defunt
|
|
LEFT JOIN ".$this->tableprefix."devis ON ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
|
|
LEFT JOIN ".$this->tableprefix."orders ON ".$this->tableprefix."defunt.id = ".$this->tableprefix."orders.fk_defunt_id
|
|
WHERE ".$this->tableprefix."devis.id_defunt IS NULL AND "
|
|
.$this->tableprefix."orders.fk_defunt_id IS NULL
|
|
ORDER BY ".$this->tableprefix."defunt.id DESC;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getArticles($idNextcloud){
|
|
$sql = "SELECT * FROM ".$this->tableprefix."article";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getOneDevis($numdevis,$idNextcloud){
|
|
$sql = "SELECT ".$this->tableprefix."devis.id as devisid, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.comment, ".$this->tableprefix."devis.date, num,"
|
|
.$this->tableprefix."devis.id_nextcloud as didnextcloud,".$this->tableprefix."devis.id_client, id_lieu, id_thanato,"
|
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
|
.$this->tableprefix."client.id as clientid, ".$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, legal_one, entreprise, telephone, mail, ".$this->tableprefix."client.adresse,"
|
|
.$this->tableprefix."lieu.nom as lieu, ".$this->tableprefix."lieu.adresse as adresse_soin ,"
|
|
.$this->tableprefix."thanato.nom as nom_thanato, ".$this->tableprefix."thanato.prenom as prenom_thanato
|
|
FROM ".$this->tableprefix."devis
|
|
LEFT JOIN ".$this->tableprefix."client on id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt on id_defunt = ".$this->tableprefix."defunt.id
|
|
LEFT JOIN ".$this->tableprefix."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."thanato on ".$this->tableprefix."devis.id_thanato = ".$this->tableprefix."thanato.id
|
|
WHERE ".$this->tableprefix."devis.id = ?";
|
|
return $this->execSQL($sql, array($numdevis));
|
|
}
|
|
|
|
public function getOneDefunt($numdefunt,$idNextcloud){
|
|
$sql = "SELECT ".$this->tableprefix."defunt.id, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.comment, ".$this->tableprefix."devis.date,".$this->tableprefix."devis.user_id as user_id,"
|
|
.$this->tableprefix."devis.id as id_devis,".$this->tableprefix."devis.id_client, id_lieu, id_thanato,"
|
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,".$this->tableprefix."defunt.date_naissance,".$this->tableprefix."defunt.sexe,".$this->tableprefix."defunt.ref_pacemaker,"
|
|
.$this->tableprefix."defunt.date as date_defunt,"
|
|
.$this->tableprefix."defunt.heure_debut,"
|
|
.$this->tableprefix."defunt.heure_fin,"
|
|
.$this->tableprefix."defunt.corpulence,"
|
|
.$this->tableprefix."defunt.rigidite,"
|
|
.$this->tableprefix."defunt.lividite,"
|
|
.$this->tableprefix."defunt.observations_corps,"
|
|
.$this->tableprefix."defunt.acces,"
|
|
.$this->tableprefix."defunt.acces_recherche,"
|
|
.$this->tableprefix."defunt.acces_etat,"
|
|
.$this->tableprefix."defunt.injection,"
|
|
.$this->tableprefix."defunt.injection_diffusion,"
|
|
.$this->tableprefix."defunt.injection_qte,"
|
|
.$this->tableprefix."defunt.preinjection,"
|
|
.$this->tableprefix."defunt.preinjection_qte,"
|
|
.$this->tableprefix."defunt.coinjection,"
|
|
.$this->tableprefix."defunt.coinjection_qte,"
|
|
.$this->tableprefix."defunt.drainage,"
|
|
.$this->tableprefix."defunt.drainage_qte,"
|
|
.$this->tableprefix."defunt.drainage_etat,"
|
|
.$this->tableprefix."defunt.ponction,"
|
|
.$this->tableprefix."defunt.ponction_qte,"
|
|
.$this->tableprefix."defunt.cavite,"
|
|
.$this->tableprefix."defunt.cavite_qte,"
|
|
.$this->tableprefix."defunt.desinfection,"
|
|
.$this->tableprefix."defunt.lavage,"
|
|
.$this->tableprefix."defunt.rasage,"
|
|
.$this->tableprefix."defunt.presentation_cosmetique,"
|
|
.$this->tableprefix."defunt.presentation_sur,"
|
|
.$this->tableprefix."defunt.observations_generales,"
|
|
.$this->tableprefix."client.id as clientid, ".$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, legal_one, entreprise, telephone, mail, ".$this->tableprefix."client.adresse,"
|
|
.$this->tableprefix."lieu.nom as lieu, ".$this->tableprefix."lieu.adresse as adresse_soin ,"
|
|
.$this->tableprefix."thanato.nom as nom_thanato, ".$this->tableprefix."thanato.prenom as prenom_thanato, "
|
|
.$this->tableprefix."thanato.date_habilitation, "
|
|
.$this->tableprefix."thanato.reference as reference_habilitation, "
|
|
.$this->tableprefix."lieu.adresse as adresse_lieu, "
|
|
.$this->tableprefix."lieu.nom as nom_lieu, "
|
|
.$this->tableprefix."facture.num as numero_facture
|
|
FROM ".$this->tableprefix."defunt
|
|
LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
|
|
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
|
LEFT JOIN ".$this->tableprefix."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."thanato on ".$this->tableprefix."devis.id_thanato = ".$this->tableprefix."thanato.id
|
|
LEFT JOIN ".$this->tableprefix."facture on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id
|
|
WHERE ".$this->tableprefix."defunt.id = ?";
|
|
return $this->execSQL($sql, array($numdefunt));
|
|
}
|
|
|
|
public function getListProduit($numdevis, $idNextcloud){
|
|
$sql = "SELECT ".
|
|
$this->tableprefix."produit.id as pid,"
|
|
.$this->tableprefix."produit_devis.id as pdid, reference, description,"
|
|
.$this->tableprefix."produit_devis.comment, quantite, prix_unitaire, "
|
|
.$this->tableprefix."devis.id_client
|
|
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]);
|
|
|
|
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']);
|
|
$produit['prix_unitaire'] = $productPrice ?? $produit['prix_unitaire'];
|
|
}
|
|
}
|
|
return json_encode($produits);
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
private function getFunctionCall(){
|
|
$trace = debug_backtrace();
|
|
return $trace[2]['function'];
|
|
}
|
|
|
|
public function getListObservations($numdefunt, $idNextcloud) {
|
|
$sql = "SELECT ".$this->tableprefix."obs_defunt.id as odid, designation, commentaire FROM "
|
|
.$this->tableprefix."obs_defunt, ".$this->tableprefix."defunt
|
|
WHERE ".$this->tableprefix."defunt.id = defunt_id AND ".$this->tableprefix."defunt.id = ?";
|
|
return $this->execSQL($sql, array($numdefunt));
|
|
}
|
|
|
|
public function getListBijoux($numdefunt, $idNextcloud) {
|
|
$sql = "SELECT ".$this->tableprefix."bijou_defunt.id as bdid, designation, commentaire FROM "
|
|
.$this->tableprefix."bijou_defunt, ".$this->tableprefix."defunt
|
|
WHERE ".$this->tableprefix."defunt.id = defunt_id AND ".$this->tableprefix."defunt.id = ?";
|
|
return $this->execSQL($sql, array($numdefunt));
|
|
}
|
|
|
|
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
|
|
WHERE ".$this->tableprefix."defunt.id = defunt_id AND ".$this->tableprefix."defunt.id = ?";
|
|
return $this->execSQL($sql, array($numdefunt));
|
|
}
|
|
|
|
/**
|
|
* INSERT client
|
|
* @$idnextcloud
|
|
*/
|
|
public function insertClient($idNextcloud){
|
|
$sql = "INSERT INTO `".$this->tableprefix."client` (`id_nextcloud`,`nom`,`prenom`,`legal_one`,`entreprise`,`telephone`,`mail`,`adresse`) VALUES (?,?,?,?,?,?,?,?)";
|
|
$sql = "INSERT INTO `".$this->tableprefix."client` (`id_nextcloud`,`nom`,`prenom`,`legal_one`,`entreprise`,`telephone`,`mail`,`adresse`) VALUES (?,?,?,?,?,?,?,?)";
|
|
$this->execSQLNoData($sql,array($idNextcloud,
|
|
$this->l->t('Last name'),
|
|
$this->l->t('First name'),
|
|
$this->l->t('Limited company'),
|
|
$this->l->t('Company'),
|
|
$this->l->t('Phone number'),
|
|
$this->l->t('Email'),
|
|
$this->l->t('Address')
|
|
)
|
|
);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* INSERT THANATOPRACTEUR
|
|
* @$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->l->t('Last name'),
|
|
$this->l->t('First name'),
|
|
'reference',
|
|
)
|
|
);
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* Insert Defunt
|
|
*/
|
|
public function insertDefunt($idNextcloud) {
|
|
$sql = "INSERT INTO `".$this->tableprefix."defunt` (
|
|
`id_nextcloud`, `nom`, `sexe`, `date_naissance`, `ref_pacemaker`, `date`,
|
|
`corpulence`, `observations_corps`, `observations_generales`
|
|
) VALUES (?,?,?,?,?,NOW(),?,?,?);";
|
|
$this->execSQLNoData($sql, array($idNextcloud, 'Nom du défunt', 'm', '1973-11-11', 'Référence pacemaker', '', '', ''));
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Insert article
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* Insert Trajet
|
|
*/
|
|
public function insertTrajet($id_thanato, $mois, $annee, $idNextcloud){
|
|
$last=0;
|
|
$last = $this->lastinsertid("trajet", $idNextcloud) + 1;
|
|
|
|
// $sql = "INSERT INTO `".$this->tableprefix."trajet` ( `id_nextcloud`,
|
|
// `date`,
|
|
// `annee`,
|
|
// `mois`,
|
|
// `id_client`,
|
|
// `id_lieu_depart`,
|
|
// `id_lieu_arrivee`,
|
|
// `distance`,
|
|
// `user_id`
|
|
// )
|
|
// VALUES (?,NOW(),?,?,0,0,0,0,?);";
|
|
$sql = "INSERT INTO `".$this->tableprefix."trajet` ( `id_nextcloud`,
|
|
`date`,
|
|
`annee`,
|
|
`mois`,
|
|
`distance`,
|
|
`id_thanato`,
|
|
`user_id`
|
|
)
|
|
VALUES (?,NOW(),?,?,0,?,?);";
|
|
$this->execSQLNoData($sql, array($idNextcloud,$annee, $mois, $id_thanato, $last));
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Insert lieu
|
|
*/
|
|
public function insertTrajetdetails($numtrajet, $idNextcloud){
|
|
$last=0;
|
|
$last = $this->lastinsertid("ligne_trajet", $idNextcloud) + 1;
|
|
|
|
$rang = $this->get_last_rang_trajetdetails($numtrajet, $idNextcloud);
|
|
|
|
$current_trajet = json_decode($this->getOneTrajet($numtrajet, $idNextcloud))[0];
|
|
|
|
$trajetdetails = json_decode($this->getTrajetsdetails_orderByDate($numtrajet, $idNextcloud));
|
|
|
|
$sql = "INSERT INTO `".$this->tableprefix."ligne_trajet` ( `id_nextcloud`,
|
|
`date`,
|
|
`id_devis`,
|
|
`id_lieu`,
|
|
`id_trajet`,
|
|
`rang`,
|
|
`commentaire`,
|
|
`source`,
|
|
`user_id`
|
|
)
|
|
VALUES (?,?,0,0,?,?,'','lieu',?);";
|
|
$this->execSQLNoData($sql, array($idNextcloud,$trajetdetails[sizeof($trajetdetails)-1]->date,$numtrajet,$rang+1,$last));
|
|
return true;
|
|
}
|
|
|
|
public function insertTrajetdetails_h2f($numtrajet, $date, $idNextcloud){
|
|
$last=0;
|
|
$last = $this->lastinsertid("ligne_trajet", $idNextcloud) + 1;
|
|
|
|
$rang = $this->get_last_rang_trajetdetails($numtrajet, $idNextcloud);
|
|
|
|
$current_trajet = json_decode($this->getOneTrajet($numtrajet, $idNextcloud))[0];
|
|
|
|
$trajetdetails = json_decode($this->getTrajetsdetails_orderByDate($numtrajet, $idNextcloud));
|
|
|
|
$sql_h2f = "SELECT * FROM ".$this->tableprefix."lieu WHERE LOWER(".$this->tableprefix."lieu.nom) LIKE 'h2f';";
|
|
$response_h2f = $this->execSQL($sql_h2f, array());
|
|
$h2f = json_decode($response_h2f)[0];
|
|
|
|
$id_h2f = ($h2f!=NULL)?$h2f->id:0;
|
|
|
|
$sql = "INSERT INTO `".$this->tableprefix."ligne_trajet` ( `id_nextcloud`,
|
|
`date`,
|
|
`id_devis`,
|
|
`id_lieu`,
|
|
`id_trajet`,
|
|
`rang`,
|
|
`commentaire`,
|
|
`source`,
|
|
`user_id`
|
|
)
|
|
VALUES (?,?,0,?,?,?,'','h2f',?);";
|
|
$this->execSQLNoData($sql, array($idNextcloud,$date,$id_h2f,$numtrajet,$rang+1,$last));
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Insert lieu
|
|
*/
|
|
public function insertTrajetdetails_byDevis($numtrajet, $devis, $idNextcloud){
|
|
$last=0;
|
|
$last = $this->lastinsertid("ligne_trajet", $idNextcloud) + 1;
|
|
|
|
$rang = $this->get_last_rang_trajetdetails($numtrajet, $idNextcloud);
|
|
|
|
$current_trajet = json_decode($this->getOneTrajet($numtrajet, $idNextcloud))[0];
|
|
|
|
$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;
|
|
|
|
$sql = "INSERT INTO `".$this->tableprefix."ligne_trajet` ( `id_nextcloud`,
|
|
`date`,
|
|
`id_devis`,
|
|
`id_client`,
|
|
`id_lieu`,
|
|
`id_trajet`,
|
|
`rang`,
|
|
`commentaire`,
|
|
`source`,
|
|
`user_id`
|
|
)
|
|
VALUES (?,?,?,?,?,?,?,'','devis',?);";
|
|
$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) {
|
|
$trajetdetails = json_decode($this->getTrajetsdetails($numtrajet, $idNextcloud));
|
|
$rang_max = 0;
|
|
foreach ($trajetdetails as $key => $details) {
|
|
if($rang_max<=$details->rang) $rang_max = $details->rang;
|
|
}
|
|
return $rang_max;
|
|
}
|
|
|
|
/**
|
|
* Insert lieu
|
|
*/
|
|
public function insertLieu($idNextcloud){
|
|
$last=0;
|
|
$last = $this->lastinsertid("lieu", $idNextcloud) + 1;
|
|
|
|
// $sql = "INSERT INTO `".$this->tableprefix."lieu` ( `id_nextcloud`,
|
|
// `nom`,
|
|
// `date`,
|
|
// `id_client`,
|
|
// `adresse`,
|
|
// `latitude`,
|
|
// `longitude`,
|
|
// `distance`,
|
|
// `depart`,
|
|
// `arrivee`,
|
|
// `user_id`
|
|
// )
|
|
// VALUES (?,?,NOW(),0,'',?,?,0,'','',?);";
|
|
|
|
$sql = "INSERT INTO `".$this->tableprefix."lieu` ( `id_nextcloud`,
|
|
`nom`,
|
|
`adresse`,
|
|
`latitude`,
|
|
`longitude`,
|
|
`user_id`
|
|
)
|
|
VALUES (?,?,'',?,?,?);";
|
|
$this->execSQLNoData($sql, array($idNextcloud,"Ajouter un lieu",'46.73','1.56',$last));
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Insert Devis
|
|
*/
|
|
public function insertDevis($idNextcloud){
|
|
$last=0;
|
|
$last = $this->lastinsertid("devis", $idNextcloud) + 1;
|
|
|
|
$devisDatetime = new Datetime();
|
|
$dateMonth = $devisDatetime->format('m');
|
|
$dateYear = $devisDatetime->format('Y');
|
|
$devisLastNumber = $this->getLastDevisNumberByMonthAndYear($dateMonth,$dateYear);
|
|
$devisNumber = $devisLastNumber + 1;
|
|
$devisFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($devisDatetime,$devisNumber,'DEV');
|
|
|
|
$sql = "INSERT INTO `".$this->tableprefix."devis` ( `date`,
|
|
`id_nextcloud`,
|
|
`num`,
|
|
`id_defunt`,
|
|
`id_client`,
|
|
`id_thanato`,
|
|
`version`,
|
|
`id_lieu`,
|
|
`mentions`,
|
|
`comment`,
|
|
`user_id`,
|
|
`devis_number`,
|
|
`devis_full_number`
|
|
)
|
|
VALUES (NOW(),?,?,0,0,0,?,0,?,?,?,?,?);";
|
|
$this->execSQLNoData($sql, array(
|
|
$idNextcloud,
|
|
self::DEFAULT_CALENDAR_UUID_FOR_DEVIS,
|
|
$this->l->t('New'),
|
|
'Mention',
|
|
$this->l->t('Comment'),
|
|
$last,
|
|
$devisNumber,
|
|
$devisFullNumber
|
|
));
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Insert invoice
|
|
*/
|
|
public function insertFacture($idNextcloud){
|
|
$last = 0;
|
|
$last = $this->lastNumFacture($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`) VALUES (?,?,?,NOW(),?,0,?,?);";
|
|
$date_temp = new DateTime();
|
|
$date = $date_temp->format('Y-m-d');
|
|
$datesplit = explode('-', $date);
|
|
$this->execSQLNoData($sql, array($date , $idNextcloud, "H2F".$datesplit[0]."/".$datesplit[1]."/".$last+1,"Comptant",$last+1,"Ajouter un lieu"));
|
|
|
|
return $last;
|
|
}
|
|
|
|
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){
|
|
$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']));
|
|
return true;
|
|
}
|
|
|
|
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`";
|
|
// return $this->execSQLNoJsonReturn($sqlSearchMax, array($idNextcloud));
|
|
return $this->execSQLNoJsonReturn($sqlSearchMax, array());
|
|
}
|
|
|
|
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']));
|
|
return true;
|
|
}
|
|
|
|
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){
|
|
$sql = "INSERT INTO `".$this->tableprefix."bijou_defunt` (`defunt_id`, `id_nextcloud`,`designation`,`commentaire`) VALUES (?,?,?,?);";
|
|
$this->execSQLNoData($sql, array($id,$idNextcloud,'inserer un bijou', 'inserer un commentaire'));
|
|
return true;
|
|
}
|
|
|
|
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 searchMaxIdArticle($idNextcloud){
|
|
$sqlSearchMax = "SELECT MIN(id) as id FROM `".$this->tableprefix."article`";
|
|
return $this->execSQLNoJsonReturn($sqlSearchMax, array());
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
|
|
$facture = json_decode($this->getOneFacture($id, $idNextcloud))[0];
|
|
$numfacture = explode('/', $facture->num)[2];
|
|
$datesplit = explode('-', $data);
|
|
$sql = "UPDATE ".$this->tableprefix.$table." SET $column = ?, `num`= ? WHERE `id` = ?";
|
|
$this->execSQLNoData($sql, array(htmlentities(rtrim($data)), "H2F".$datesplit[0]."/".$datesplit[1]."/".$numfacture, $id));
|
|
|
|
} else if(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));
|
|
|
|
} else if(strcmp($table, "lieu")==0 && (strcmp($column, "latitude")==0 || strcmp($column, "longitude")==0)) {
|
|
|
|
$lieu = json_decode($this->getLieu($id, $idNextcloud))[0];
|
|
|
|
if(floatval($data)!=0) {
|
|
$sql = "UPDATE ".$this->tableprefix.$table." SET $column = ? WHERE `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) {
|
|
$adresse = $this->recuperer_adresse(floatval($lieu->latitude), floatval($lieu->longitude));
|
|
$sql = "UPDATE ".$this->tableprefix.$table." SET adresse = ? WHERE `id` = ?";
|
|
$this->execSQLNoData($sql, array(htmlentities($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)) {
|
|
|
|
$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)) {
|
|
$ligne_trajet = json_decode($this->getOneTrajetdetails($id, $idNextcloud))[0];
|
|
$this->update_lieu_date_devis_rang_ligneTrajet($ligne_trajet, $column, htmlentities(rtrim($data)), $idNextcloud);
|
|
}
|
|
else {
|
|
$sql = "UPDATE ".$this->tableprefix.$table." SET $column = ? WHERE `id` = ?";
|
|
$this->execSQLNoData($sql, array(trim($data), $id));
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
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;";
|
|
$this->execSQLNoData($sqldeletelignetrajet, array());
|
|
$sqldeletetrajet = "DELETE FROM ".$this->tableprefix."trajet;";
|
|
$this->execSQLNoData($sqldeletetrajet, array());
|
|
|
|
//recuperer tous les trajets
|
|
// $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) {
|
|
$this->update_lieu_date_devis($devis, 'id_lieu', $devis->id_lieu, $idNextcloud);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* update lieu et date devis
|
|
*/
|
|
public function update_lieu_date_devis($devis, $column, $data, $idNextcloud) {
|
|
$ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($devis->devisid, $idNextcloud))[0];
|
|
switch ($column) {
|
|
case 'id_client':
|
|
$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) { // 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) {
|
|
// 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];
|
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 'date':
|
|
$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];
|
|
|
|
//update devis full number
|
|
$devisDate = $updated_devis->date;
|
|
$devisDatetime = Datetime::createFromFormat("Y-m-d",$devisDate);
|
|
$dateMonth = $devisDatetime->format('m');
|
|
$dateYear = $devisDatetime->format('Y');
|
|
$devisLastNumber = $this->getLastDevisNumberByMonthAndYear($dateMonth,$dateYear);
|
|
$devisNumber = $devisLastNumber + 1;
|
|
$devisFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($devisDatetime,$devisNumber,'DEV');
|
|
$sql = "UPDATE ".$this->tableprefix."devis SET devis_full_number = ?, devis_number = ? WHERE `id` = ?";
|
|
$this->execSQLNoData($sql, array($devisFullNumber, $devisNumber, $devis->devisid));
|
|
|
|
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);
|
|
$this->generate_ligneTrajet($updated_devis, $idNextcloud);
|
|
$ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($updated_devis->devisid, $idNextcloud))[0];
|
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
} else {
|
|
// mettre a jour ligne_trajet
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 'id_lieu':
|
|
if($ligne_trajet != NULL) {
|
|
$this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud);
|
|
$ligne_trajet = NULL;
|
|
}
|
|
// 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) {
|
|
// $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) {
|
|
// 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];
|
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
}
|
|
// }
|
|
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) {
|
|
$this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud);
|
|
}
|
|
$this->generate_ligneTrajet($updated_devis, $idNextcloud);
|
|
$ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($updated_devis->devisid, $idNextcloud))[0];
|
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function update_lieu_date_devis_rang_ligneTrajet($ligne_trajet, $column, $data, $idNextcloud) {
|
|
switch ($column) {
|
|
case 'id_devis':
|
|
$current_devis = json_decode($this->getOneDevis($data, $idNextcloud))[0];
|
|
|
|
$this->update_ligneTrajet('ligne_trajet', 'id_devis', $current_devis->devisid, $ligne_trajet->id, $idNextcloud);
|
|
$this->update_ligneTrajet('ligne_trajet', 'date', $current_devis->date, $ligne_trajet->id, $idNextcloud);
|
|
$this->update_ligneTrajet('ligne_trajet', 'id_client', $current_devis->id_client, $ligne_trajet->id, $idNextcloud);
|
|
$this->update_ligneTrajet('ligne_trajet', 'id_lieu', $current_devis->id_lieu, $ligne_trajet->id, $idNextcloud);
|
|
|
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
break;
|
|
case 'id_lieu':
|
|
$this->update_ligneTrajet('ligne_trajet', 'id_lieu', $data, $ligne_trajet->id, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
break;
|
|
case 'date':
|
|
$this->update_ligneTrajet('ligne_trajet', 'date', $data, $ligne_trajet->id, $idNextcloud);
|
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
break;
|
|
case 'rang':
|
|
$ligneTrajet_surLeRang = json_decode($this->getOneTrajetdetails_byRang($ligne_trajet->id_trajet, $data, $idNextcloud))[0];
|
|
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->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
} else {
|
|
$this->update_ligneTrajet('ligne_trajet', 'rang', $data, $ligne_trajet->id, $idNextcloud);
|
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* generer une ligne de trajet par un devis
|
|
*/
|
|
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) {
|
|
$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];
|
|
}
|
|
|
|
$this->insertTrajetdetails_byDevis($trajet->id, $devis, $idNextcloud);
|
|
}
|
|
|
|
/**
|
|
* ranger les lignes de trajet dans un trajet par date et par rang
|
|
* inserer ligne siege au debut et fin de chaque journee s'il n'existe pas
|
|
*/
|
|
public function range_ligneTrajet($id_trajet, $idNextcloud) {
|
|
$lignes = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud));
|
|
$nb_jour = 0;
|
|
if(sizeof($lignes)>0) {
|
|
$nb_jour = 1;
|
|
$dates = array(0=>$lignes[0]->date);
|
|
$date_temp = $lignes[0]->date;
|
|
foreach ($lignes as $key => $ligne) {
|
|
if(strcmp($date_temp, $ligne->date)!=0) {
|
|
$date_temp = $ligne->date;
|
|
array_push($dates, $date_temp);
|
|
$nb_jour++;
|
|
}
|
|
}
|
|
|
|
// on verifie si le nombre de ligne h2f correspond à 2*nb_jour (debut et fin de journee)
|
|
$reste = (2*$nb_jour) - (sizeof(array_filter($lignes, function($ligne) {return strcmp($ligne->source,'h2f')==0;})));
|
|
while ($reste>0) {
|
|
$this->insertTrajetdetails_h2f($id_trajet, $lignes[0]->date, $idNextcloud);
|
|
$reste--;
|
|
}
|
|
|
|
$current_lines = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud));
|
|
|
|
// ici le nombre de ligne h2f est egale au nb_jour*2
|
|
$array_siege = array();
|
|
foreach ($current_lines as $key => $ligne) {
|
|
if(strcmp($ligne->source,'h2f')==0) array_push($array_siege, $ligne);
|
|
}
|
|
|
|
$j=0;
|
|
for ($i=0; $i < sizeof($dates); $i++) {
|
|
$this->update_ligneTrajet('ligne_trajet', 'rang', 0, $array_siege[$j]->id, $idNextcloud);
|
|
$this->update_ligneTrajet('ligne_trajet', 'date', $dates[$i], $array_siege[$j]->id, $idNextcloud);
|
|
$this->update_ligneTrajet('ligne_trajet', 'rang', sizeof($current_lines)+1, $array_siege[$j+1]->id, $idNextcloud);
|
|
$this->update_ligneTrajet('ligne_trajet', 'date', $dates[$i], $array_siege[$j+1]->id, $idNextcloud);
|
|
$j+=2;
|
|
}
|
|
|
|
$ordered_lines = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud));
|
|
foreach ($ordered_lines as $key => $line) {
|
|
$this->update_ligneTrajet('ligne_trajet', 'rang', $key+1, $line->id, $idNextcloud);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public function update_ligneTrajet($table, $column, $data, $id, $idNextcloud){
|
|
|
|
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) {
|
|
$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) {
|
|
array_push($distances, $distance_temp);
|
|
$distance_temp = 0;
|
|
$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(sizeof($trajetdetails)>1 && sizeof($distances)==0) array_push($distances, $distance_temp);
|
|
$distance_final = 0;
|
|
foreach ($distances as $key => $valdistance) {
|
|
$distance_final += $valdistance;
|
|
}
|
|
$sql = "UPDATE ".$this->tableprefix."trajet SET `distance` = ? WHERE `id` = ?";
|
|
$this->execSQLNoData($sql, array($distance_final, $numtrajet));
|
|
}
|
|
|
|
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
|
|
WHERE " . $this->tableprefix . "trajet.annee = " . $annee . " AND " . $this->tableprefix . "trajet.mois = " . $mois . " AND " . $this->tableprefix . "trajet.id_thanato = " . $id_thanato . ";";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function recuperer_adresse($latitude, $longitude) {
|
|
|
|
$curl = curl_init();
|
|
|
|
curl_setopt_array($curl, array(
|
|
CURLOPT_URL => 'https://api.geoapify.com/v1/geocode/reverse?lat='.$latitude.'&lon='.$longitude.'&format=json&apiKey=8dadbe28a8894e9ebb7d0d1053b743f4',
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_ENCODING => '',
|
|
CURLOPT_MAXREDIRS => 10,
|
|
CURLOPT_TIMEOUT => 0,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
CURLOPT_CUSTOMREQUEST => 'GET',
|
|
));
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
// Vérifiez s'il y a eu une erreur lors de la requête cURL
|
|
if ($response === false) {
|
|
return '';
|
|
} else {
|
|
return (json_decode($response)->results)[0]->formatted;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Calcul la distance entre les deux points à vol d'oiseau
|
|
*/
|
|
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));
|
|
$d = $R * $c;
|
|
return round($d, 2);
|
|
}
|
|
|
|
/**
|
|
* Verification si la valeur d'un coordonnees est valide
|
|
*/
|
|
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) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* DELETE
|
|
*/
|
|
public function gestion_delete($table, $id, $idNextcloud){
|
|
if(in_array($table, $this->whiteTable)){
|
|
if(strcmp($table, "ligne_trajet")==0) {
|
|
|
|
$ligne_trajet = json_decode($this->getOneTrajetdetails($id, $idNextcloud))[0];
|
|
|
|
$sql = "DELETE FROM ".$this->tableprefix.$table." WHERE `id` = ?";
|
|
$this->execSQLNoData($sql, array($id));
|
|
|
|
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
|
|
} else if(strcmp($table, "trajet")==0) {
|
|
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE `id_trajet` = ?";
|
|
$this->execSQLNoData($sql, array($id));
|
|
$sql = "DELETE FROM ".$this->tableprefix.$table." WHERE `id` = ?";
|
|
$this->execSQLNoData($sql, array($id));
|
|
} else {
|
|
$sql = "DELETE FROM ".$this->tableprefix.$table." WHERE `id` = ?";
|
|
$this->execSQLNoData($sql, array($id));
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Check
|
|
* TODO Translation
|
|
*/
|
|
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 ){
|
|
$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->l->t('Your company contact last name'),
|
|
$this->l->t('Your company contact first name'),
|
|
$this->l->t('Company legal information line one'),
|
|
$this->l->t('Company legal information line two'),
|
|
$this->l->t('Your company email'),
|
|
$this->l->t('Your company phone'),
|
|
$this->l->t('Your company address'),
|
|
$idNextcloud,
|
|
$this->l->t('All Legal mentions, disclaimer or everything you want to place in the footer.'),
|
|
$this->l->t('EUR'),
|
|
$this->l->t('INVOICE')
|
|
)
|
|
);
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
public function isConfig($idNextcloud){
|
|
$changelog = 9; //+1 if you want changelog appear for everybody one time !
|
|
|
|
$sql = "SELECT count(*) as res FROM `".$this->tableprefix."configuration` WHERE `id_nextcloud` = ?";
|
|
$res = json_decode($this->execSQL($sql, array($idNextcloud)))[0]->res;
|
|
|
|
// Utilisateur jamais utilisé l'application
|
|
if ( $res < 1 ){
|
|
return false;
|
|
}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);
|
|
return false;
|
|
}else{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Number client
|
|
*/
|
|
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;";
|
|
return $this->execSQL($sql, array());
|
|
// return $this->execSQL($sql, array($idNextcloud));
|
|
}
|
|
|
|
/**
|
|
* Number thanatopracteur
|
|
*/
|
|
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;";
|
|
return $this->execSQL($sql, array());
|
|
// return $this->execSQL($sql, array($idNextcloud));
|
|
}
|
|
|
|
/**
|
|
* Number devis
|
|
*/
|
|
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é';";
|
|
$sql = "SELECT count(*) as c from ".$this->tableprefix."devis;";
|
|
// $sql = "SELECT count(*) as c from ".$this->tableprefix."devis WHERE `id_nextcloud` = ?;";
|
|
// return $this->execSQL($sql, array($idNextcloud));
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Number facture
|
|
*/
|
|
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;";
|
|
// return $this->execSQL($sql, array($idNextcloud));
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Number lieu
|
|
*/
|
|
public function numberLieu($idNextcloud){
|
|
$sql = "SELECT count(*) as c from ".$this->tableprefix."lieu;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Number trajet
|
|
*/
|
|
public function numberTrajet($idNextcloud){
|
|
$sql = "SELECT count(*) as c from ".$this->tableprefix."trajet;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Number produit
|
|
*/
|
|
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;";
|
|
// return $this->execSQL($sql, array($idNextcloud));
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Number article
|
|
*/
|
|
public function numberArticle($idNextcloud){
|
|
$sql = "SELECT count(*) as c from ".$this->tableprefix."article;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Number defunt
|
|
*/
|
|
public function numberDefunt($idNextcloud){
|
|
$sql = "SELECT count(*) as c from ".$this->tableprefix."defunt;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Number bibliotheque
|
|
*/
|
|
public function numberBibliotheque($idNextcloud){
|
|
$sql = "SELECT count(*) as c from ".$this->tableprefix."bibliotheque;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Annual turnover per month without VAT
|
|
*/
|
|
public function getAnnualTurnoverPerMonthNoVat($idNextcloud){
|
|
$sql = "SELECT
|
|
EXTRACT(YEAR FROM facture.date_paiement) AS y,
|
|
EXTRACT(MONTH FROM facture.date_paiement) AS m,
|
|
SUM(
|
|
COALESCE(client_group_discount.ht_amount,produit.prix_unitaire)
|
|
* produit_devis.quantite
|
|
) AS total
|
|
FROM ".$this->tableprefix."facture AS facture
|
|
JOIN ".$this->tableprefix."produit_devis AS produit_devis
|
|
ON facture.id_devis = produit_devis.devis_id
|
|
JOIN ".$this->tableprefix."produit AS produit
|
|
ON produit_devis.produit_id = produit.id
|
|
JOIN ".$this->tableprefix."devis AS devis
|
|
ON facture.id_devis = devis.id
|
|
JOIN ".$this->tableprefix."client AS client
|
|
ON devis.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."client_group AS client_group
|
|
ON client.fk_client_group_id = client_group.id
|
|
LEFT JOIN ".$this->tableprefix."client_group_discount AS client_group_discount
|
|
ON client_group.id = client_group_discount.fk_client_group_id
|
|
AND produit.id = client_group_discount.fk_produit_id
|
|
GROUP BY
|
|
EXTRACT(YEAR FROM facture.date_paiement),
|
|
EXTRACT(MONTH FROM facture.date_paiement)
|
|
ORDER BY
|
|
EXTRACT(YEAR FROM facture.date_paiement) DESC,
|
|
EXTRACT(MONTH FROM facture.date_paiement);";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getStatArticleAnnuel($idNextcloud, $annee) {
|
|
$sql = "SELECT p.id, p.reference,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 1 THEN pd.quantite ELSE 0 END), 0) AS janvier,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 2 THEN pd.quantite ELSE 0 END), 0) AS fevrier,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 3 THEN pd.quantite ELSE 0 END), 0) AS mars,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 4 THEN pd.quantite ELSE 0 END), 0) AS avril,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 5 THEN pd.quantite ELSE 0 END), 0) AS mai,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 6 THEN pd.quantite ELSE 0 END), 0) AS juin,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 7 THEN pd.quantite ELSE 0 END), 0) AS juillet,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 8 THEN pd.quantite ELSE 0 END), 0) AS aout,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 9 THEN pd.quantite ELSE 0 END), 0) AS septembre,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 10 THEN pd.quantite ELSE 0 END), 0) AS octobre,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 11 THEN pd.quantite ELSE 0 END), 0) AS novembre,
|
|
COALESCE(SUM(CASE WHEN MONTH(f.date_paiement) = 12 THEN pd.quantite ELSE 0 END), 0) AS decembre
|
|
FROM ".$this->tableprefix."produit p
|
|
LEFT JOIN ".$this->tableprefix."produit_devis pd ON p.id = pd.produit_id
|
|
LEFT JOIN ".$this->tableprefix."devis d ON pd.devis_id = d.id
|
|
LEFT JOIN ".$this->tableprefix."facture f ON f.id_devis = d.id
|
|
WHERE YEAR(f.date_paiement) = ".$annee." AND pd.devis_id IS NOT NULL
|
|
GROUP BY p.id, p.reference;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getStatSoinsThanatoAnnuel($idNextcloud, $annee) {
|
|
$sql = "SELECT
|
|
thanato.nom AS nom_thanato,
|
|
thanato.prenom AS prenom_thanato,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 1 THEN 1 ELSE 0 END), 0) AS janvier,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 2 THEN 1 ELSE 0 END), 0) AS fevrier,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 3 THEN 1 ELSE 0 END), 0) AS mars,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 4 THEN 1 ELSE 0 END), 0) AS avril,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 5 THEN 1 ELSE 0 END), 0) AS mai,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 6 THEN 1 ELSE 0 END), 0) AS juin,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 7 THEN 1 ELSE 0 END), 0) AS juillet,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 8 THEN 1 ELSE 0 END), 0) AS aout,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 9 THEN 1 ELSE 0 END), 0) AS septembre,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 10 THEN 1 ELSE 0 END), 0) AS octobre,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 11 THEN 1 ELSE 0 END), 0) AS novembre,
|
|
COALESCE(SUM(CASE WHEN MONTH(d.date) = 12 THEN 1 ELSE 0 END), 0) AS decembre
|
|
FROM ".$this->tableprefix."devis d
|
|
LEFT JOIN ".$this->tableprefix."facture f ON f.id_devis = d.id
|
|
LEFT JOIN ".$this->tableprefix."thanato thanato ON d.id_thanato = thanato.id
|
|
WHERE YEAR(d.date) = ".$annee." AND d.id_thanato IS NOT NULL
|
|
AND thanato.id IS NOT NULL
|
|
GROUP BY nom_thanato, prenom_thanato
|
|
ORDER BY nom_thanato;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getStatSoinsThanatoWeekend($idNextcloud, $annee, $mois) {
|
|
/**
|
|
* stat nombre de jours travaillés les weekends d'un mois
|
|
* */
|
|
$sql = "SELECT
|
|
thanato.id,
|
|
thanato.nom as nom_thanato,
|
|
thanato.prenom AS prenom_thanato,
|
|
COUNT(DISTINCT DATE_FORMAT(devis.date, '%Y-%m-%d')) AS weekends_travailles
|
|
FROM
|
|
".$this->tableprefix."thanato as thanato
|
|
JOIN
|
|
".$this->tableprefix."devis as devis ON thanato.id = devis.id_thanato
|
|
WHERE
|
|
MONTH(devis.date) = ".$mois."
|
|
AND YEAR(devis.date) = ".$annee."
|
|
AND DAYOFWEEK(devis.date) IN (1, 7)
|
|
GROUP BY
|
|
thanato.id, nom_thanato, prenom_thanato;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
/**
|
|
* Get last insert id
|
|
*/
|
|
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());
|
|
return $res[0]['LAST_INSERT_ID'];
|
|
}
|
|
|
|
public function lastNumFacture($idNextcloud) {
|
|
$factures = json_decode($this->getFactures($idNextcloud));
|
|
$max = 5977;
|
|
foreach ($factures as $key => $facture) {
|
|
$numsplit = explode('/', $facture->num);
|
|
$num = (int) $numsplit[2];
|
|
$max = ($max<=$num)?$num:$max;
|
|
}
|
|
return $max;
|
|
}
|
|
|
|
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("===facture===");
|
|
$sql = "SELECT * FROM ".$this->tableprefix."facture";
|
|
$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("===produit_devis===");
|
|
$sql = "SELECT * FROM ".$this->tableprefix."produit_devis";
|
|
$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()));
|
|
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* @sql
|
|
* @array() //prepare statement
|
|
*/
|
|
private function execSQL($sql, $conditions){
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute($conditions);
|
|
$data = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
$stmt->closeCursor();
|
|
return json_encode($data);
|
|
}
|
|
|
|
private function execSQLNoData($sql, $conditions){
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute($conditions);
|
|
$stmt->closeCursor();
|
|
}
|
|
|
|
private function execSQLNoJsonReturn($sql, $conditions){
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute($conditions);
|
|
$data = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
$stmt->closeCursor();
|
|
return $data;
|
|
}
|
|
|
|
public function getClientsByClientsID(array $clientIds){
|
|
if(empty($clientIds)){
|
|
return [];
|
|
}
|
|
|
|
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($clientIds), '?'));
|
|
$sql = "SELECT
|
|
client.id,
|
|
client.nom as client_nom,
|
|
client.prenom as client_prenom,
|
|
client.entreprise as client_entreprise
|
|
FROM ".$this->tableprefix."client as client
|
|
WHERE client.id IN ($sqlConditionsPlaceholder);";
|
|
$clientList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
$clientIds);
|
|
|
|
return $clientList;
|
|
}
|
|
|
|
public function getProduitsListAsArray(){
|
|
$sql = "SELECT * FROM ".$this->tableprefix."produit as produit;";
|
|
|
|
$produitList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[]);
|
|
|
|
return $produitList;
|
|
}
|
|
|
|
public function getThanatoByIds(array $thanatoIds){
|
|
if(empty($thanatoIds)){
|
|
return [];
|
|
}
|
|
|
|
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($thanatoIds), '?'));
|
|
|
|
$sql = "SELECT
|
|
thanato.id,
|
|
thanato.nom as thanato_nom,
|
|
thanato.prenom as thanato_prenom
|
|
FROM ".$this->tableprefix."thanato as thanato
|
|
WHERE thanato.id IN ($sqlConditionsPlaceholder)";
|
|
$thanatoList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
$thanatoIds);
|
|
|
|
return $thanatoList;
|
|
}
|
|
|
|
private function getLigneTrajetsByDevisIdList(array $devisIdList){
|
|
if(empty($devisIdList)){
|
|
return [];
|
|
}
|
|
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisIdList), '?'));
|
|
$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 lieu_id, lieu.nom as lieu, lieu.latitude as latitude, lieu.longitude as longitude
|
|
FROM (".$this->tableprefix."ligne_trajet as ligne_trajet
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on ligne_trajet.id_lieu = lieu.id)
|
|
WHERE ligne_trajet.id_devis IN ($sqlConditionsPlaceholder)
|
|
ORDER BY ligne_trajet.date ASC, ligne_trajet.rang ASC;";
|
|
return $this->execSQLNoJsonReturn($sql, $devisIdList);
|
|
}
|
|
|
|
private function getLigneTrajetsListDistance(array $ligneTrajetList){
|
|
$distanceCumul = 0;
|
|
$last_point = NULL;
|
|
for ($i=0; $i < sizeof($ligneTrajetList); $i++) {
|
|
$currentDistance = 0;
|
|
if($ligneTrajetList[$i]['lieu_id'] != NULL){
|
|
$last_point = $ligneTrajetList[$i];
|
|
}
|
|
if($last_point['lieu_id'] != NULL && $ligneTrajetList[$i+1]['lieu_id'] != NULL){
|
|
$currentDistance = $this->calcul_distance(
|
|
floatval(value: $last_point['latitude']),
|
|
floatval($last_point['longitude']),
|
|
floatval($ligneTrajetList[$i+1]['latitude']),
|
|
floatval($ligneTrajetList[$i+1]['longitude'])
|
|
);
|
|
}
|
|
$distanceCumul += $currentDistance;
|
|
}
|
|
return $distanceCumul;
|
|
}
|
|
|
|
public function getDistanceTotalByDevisIdList(array $devisIdList){
|
|
$ligneTrajetList = $this->getLigneTrajetsByDevisIdList($devisIdList);
|
|
$distanceTotal = $this->getLigneTrajetsListDistance($ligneTrajetList);
|
|
return $distanceTotal;
|
|
}
|
|
|
|
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){
|
|
return $res[0]['FIRST_INSERT_ID'];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function getThanatoByUserUuid($userUuid){
|
|
$sql = "SELECT *
|
|
FROM ".$this->tableprefix."thanato as thanato
|
|
WHERE thanato.fk_user_uuid = ?";
|
|
$res = $this->execSQLNoJsonReturn($sql,array($userUuid));
|
|
if($res){
|
|
return $res[0];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function 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){
|
|
return $res[0]['FIRST_INSERT_ID'];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function getCalendarOrganizerNameByCalendarObjectUuid(string $calendarObjectUuid){
|
|
$calendarObject = $this->getCalendarObjectByUuid($calendarObjectUuid);
|
|
if($calendarObject != null){
|
|
$calendar = $this->getCalendarById($calendarObject['calendarid']);
|
|
if($calendar != null){
|
|
$principalUri = $calendar["principaluri"];
|
|
$organizerName = str_replace('principals/users/','',$principalUri);
|
|
$organizerName = trim($organizerName);
|
|
return $organizerName;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function getCalendarById(int $calendarId){
|
|
$sql = "SELECT * FROM ".self::CALENDAR_TABLE_PREFIX."calendars WHERE id = ?;";
|
|
$calendarList = $this->execSQLNoJsonReturn($sql, [$calendarId]);
|
|
if(!empty($calendarList)){
|
|
$calendarData = $calendarList[0];
|
|
return $calendarData;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function getCalendarObjectByUuid(string $calendarObjectUuid){
|
|
$sql = "SELECT * FROM ".self::CALENDAR_TABLE_PREFIX."calendarobjects WHERE uid = ?;";
|
|
$calendarObjectList = $this->execSQLNoJsonReturn($sql, [$calendarObjectUuid]);
|
|
if(!empty($calendarObjectList)){
|
|
$calendarData = $calendarObjectList[0];
|
|
return $calendarData;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
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){
|
|
return $res[0]['LAST_INSERT_ID'];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
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(
|
|
$defuntId,
|
|
$locationId,
|
|
$clientId,
|
|
$thanatoId,
|
|
$calendarUuid
|
|
));
|
|
if($res){
|
|
return $res[0]['LAST_INSERT_ID'];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function insertDefuntByNameAndReturnId($name) {
|
|
$this->insertDefuntByName($name);
|
|
return $this->getLastDefuntIdByName($name);
|
|
}
|
|
|
|
public function insertDefuntByName($name) {
|
|
$sql = "INSERT INTO `".$this->tableprefix."defunt` (
|
|
`id_nextcloud`, `nom`, `sexe`, `date_naissance`, `ref_pacemaker`, `date`,
|
|
`corpulence`, `observations_corps`, `observations_generales`
|
|
) VALUES (?,?,?,?,?,NOW(),?,?,?);";
|
|
$this->execSQLNoData($sql, array('admin',$name, 'm', '1973-11-11', 'Référence pacemaker', '', '', ''));
|
|
return true;
|
|
}
|
|
|
|
public function insertDevisFromVCalendarAndReturnId($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid = self::DEFAULT_CALENDAR_UUID_FOR_DEVIS,$date = null,$idNextcloud = "admin"){
|
|
|
|
if($date == null){
|
|
$dateTime = new Datetime();
|
|
$date = $dateTime->format('Y-m-d');
|
|
}
|
|
else{
|
|
$dateTime = new DateTime($date);
|
|
}
|
|
$last=0;
|
|
$last = $this->lastinsertid("devis", "admin") + 1;
|
|
|
|
$dateMonth = $dateTime->format('m');
|
|
$dateYear = $dateTime->format('Y');
|
|
|
|
$devisLastNumber = $this->getLastDevisNumberByMonthAndYear($dateMonth,$dateYear);
|
|
$devisNumber = $devisLastNumber + 1;
|
|
$devisFullNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($dateTime,$devisNumber,'DEV');
|
|
|
|
$sql = "INSERT INTO `".$this->tableprefix."devis` ( `date`,
|
|
`id_nextcloud`,
|
|
`num`,
|
|
`id_defunt`,
|
|
`id_client`,
|
|
`id_thanato`,
|
|
`version`,
|
|
`id_lieu`,
|
|
`mentions`,
|
|
`comment`,
|
|
`user_id`,
|
|
`devis_number`,
|
|
`devis_full_number`
|
|
)
|
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
|
$this->execSQLNoData($sql, array(
|
|
$date,
|
|
$idNextcloud,
|
|
$calendarUuid,
|
|
$defuntId,
|
|
$clientId,
|
|
$thanatoId,
|
|
$this->l->t('New'),
|
|
$locationId,
|
|
$this->l->t('Mention'),
|
|
$this->l->t('Comment'),
|
|
$last,
|
|
$devisNumber,
|
|
$devisFullNumber
|
|
)
|
|
);
|
|
|
|
return $this->getLastDevisIdFromVCalendarProperty($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid);
|
|
}
|
|
|
|
private function getLastDevisNumberByMonthAndYear($month,$year){
|
|
$sql = "SELECT
|
|
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));
|
|
$lastNumber = 0;
|
|
if(!empty($res)){
|
|
$lastNumber = $res[0]['LAST_DEVIS_NUMBER'];
|
|
}
|
|
return $lastNumber;
|
|
}
|
|
|
|
public function getArticleIdsByArticleReferences(array $articleReferences){
|
|
$articleIds = [];
|
|
foreach ($articleReferences as $reference) {
|
|
$reference = trim($reference);
|
|
$sql = "SELECT id FROM ".$this->tableprefix."produit WHERE reference = ?";
|
|
$res = $this->execSQLNoJsonReturn($sql, array($reference));
|
|
if ($res) {
|
|
$articleIds[] = $res[0]['id'];
|
|
}
|
|
}
|
|
return $articleIds;
|
|
}
|
|
|
|
public function insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds) {
|
|
if (!empty($articleIds)) {
|
|
$idNextcloud = "admin";
|
|
foreach ($articleIds as $articleId) {
|
|
$this->insertDevisArticle(devisId: $devisId, articleId: $articleId,idNextcloud: $idNextcloud);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
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));
|
|
return true;
|
|
}
|
|
|
|
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);
|
|
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
|
}
|
|
|
|
public function getExportThanatoStatisticData(array $thanatoIds){
|
|
$devisList = $this->getDevisListByThanatoIds($thanatoIds);
|
|
$devisListGroupedByDateAndThenByThanato = $this->getDevisListGroupedByDateAndThenByThanato($devisList);
|
|
return $devisListGroupedByDateAndThenByThanato;
|
|
}
|
|
|
|
private function getDevisListByThanatoIds(array $thanatoIds){
|
|
if(empty($thanatoIds)){
|
|
return [];
|
|
}
|
|
$currentYear = date('Y');
|
|
$currentMonth = date('m');
|
|
|
|
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($thanatoIds), '?'));
|
|
$sql = "SELECT
|
|
devis.id,
|
|
devis.date,
|
|
devis.mentions,
|
|
devis.num as calendar_uuid,
|
|
devis.id_defunt as id_defunt,
|
|
devis.id_lieu as id_lieu,
|
|
devis.id_client as id_client,
|
|
devis.id_thanato as id_thanato,
|
|
thanato.nom as nom_thanato,
|
|
thanato.prenom as prenom_thanato,
|
|
defunt.nom as nom_defunt,
|
|
lieu.nom as nom_lieu,
|
|
lieu.latitude as lieu_latitude,
|
|
lieu.longitude as lieu_longitude,
|
|
client.nom as nom_client,
|
|
client.entreprise as client_entreprise,
|
|
client.adresse as client_adresse,
|
|
facture.num as facture_num
|
|
FROM ".$this->tableprefix."devis as devis
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."facture as facture on devis.id = facture.id_devis
|
|
WHERE YEAR(devis.date) = ? AND
|
|
MONTH(devis.date) = ? AND
|
|
devis.id_thanato IN ($sqlConditionsPlaceholder) AND
|
|
devis.mentions = ?
|
|
ORDER BY devis.date ASC;";
|
|
$devisList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
array_merge([$currentYear, $currentMonth],$thanatoIds,["facturé"]));
|
|
return $devisList;
|
|
}
|
|
|
|
private function getDevisListGroupedByDateAndThenByThanato(array $devisList){
|
|
$devisListGroupedByDateAndThenByThanato = [];
|
|
foreach($devisList as $devis){
|
|
$devisDate = $devis["date"];
|
|
$devisThanatoId = $devis["id_thanato"];
|
|
$devis = $this->setDevisStartAndEndTime($devis);
|
|
$devis = $this->setDevisIsWeekendOrNotText($devis);
|
|
$devis = $this->setDevisProduitsList($devis);
|
|
//set devis articles list into devis data
|
|
if (!isset($devisListGroupedByDateAndThenByThanato[$devisThanatoId])) {
|
|
$devisListGroupedByDateAndThenByThanato[$devisThanatoId] = [];
|
|
}
|
|
if (!isset($devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate])) {
|
|
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate] = [
|
|
'total_distance' => 0,
|
|
"devis" => [],
|
|
"devisId" => []
|
|
];
|
|
}
|
|
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate]["devis"][] = $devis;
|
|
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate]["devisId"][] = $devis['id'];
|
|
}
|
|
return $devisListGroupedByDateAndThenByThanato;
|
|
}
|
|
|
|
private function setDevisProduitsList($devis){
|
|
$produitsList = $this->getProduitsDevisByDevisId($devis['id']);
|
|
foreach($produitsList as $produit){
|
|
if (!isset($devis['produits'])) {
|
|
$devis['produits'] = [];
|
|
}
|
|
$devis['produits'][] = $produit;
|
|
}
|
|
return $devis;
|
|
}
|
|
|
|
public function getProduitsDevisByDevisId($devisId){
|
|
$sql = "SELECT
|
|
produit_devis.id as produit_devis_id,
|
|
produit.id as produit_id,
|
|
produit.reference as produit_reference,
|
|
produit.description as produit_description
|
|
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 = ?;";
|
|
$produitsList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$devisId]);
|
|
return $produitsList;
|
|
}
|
|
|
|
private function setDevisIsWeekendOrNotText($devis){
|
|
$isWeekend = DateHelpers::isWeekend($devis['date']);
|
|
$value = $isWeekend ? "Ferie" : "J";
|
|
$devis["dayType"] = $value;
|
|
return $devis;
|
|
}
|
|
|
|
public function setDevisStartAndEndTime($devis){
|
|
$calendarData = $this->getCalendarDataByCalendarObjectUuid($devis["calendar_uuid"]);
|
|
$devisTimeValue = VCalendarHelpers::GetStartAndEndTimeFromVCalendarString($calendarData);
|
|
$devis["startTime"] = $devisTimeValue["startTime"];
|
|
$devis["endTime"] = $devisTimeValue["endTime"];
|
|
return $devis;
|
|
}
|
|
|
|
public function getCalendarDataByCalendarObjectUuid(string $calendarObjectUuid){
|
|
$sql = "SELECT * FROM ".self::CALENDAR_TABLE_PREFIX."calendarobjects WHERE uid = ?;";
|
|
$calendarObjectList = $this->execSQLNoJsonReturn($sql, [$calendarObjectUuid]);
|
|
if(!empty($calendarObjectList)){
|
|
$calendarDataBlob = $calendarObjectList[0]['calendardata'];
|
|
$calendarDataString = VCalendarHelpers::ReadVCalendarDataBlob($calendarDataBlob);
|
|
return $calendarDataString;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public function getExportClientStatData(array $clientIds){
|
|
$data = [];
|
|
$produitList = $this->getProduitsListAsArray();
|
|
foreach($clientIds as $clientId){
|
|
if(!isset($data[$clientId])){
|
|
$data[$clientId] = [];
|
|
}
|
|
//get client name
|
|
$clientName = "Default client name";
|
|
$client = $this->getClientById($clientId);
|
|
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);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
private function getClientById($clientId){
|
|
$sql = "SELECT
|
|
client.id,
|
|
client.nom as client_nom,
|
|
client.prenom as client_prenom,
|
|
client.entreprise as client_entreprise
|
|
FROM ".$this->tableprefix."client as client
|
|
WHERE client.id = ?;";
|
|
$clientList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$clientId]);
|
|
|
|
if(!empty($clientList)){
|
|
return $clientList[0];
|
|
}
|
|
|
|
return $clientList;
|
|
}
|
|
|
|
private function getClientFactureStatisticPerMonth($clientId,array $produitList){
|
|
$currentYear = date('Y');
|
|
$monthLists = range(1,12);
|
|
$data = [] ;
|
|
foreach($monthLists as $monthValue){
|
|
if(!isset($data[$monthValue])){
|
|
$data[$monthValue] = [];
|
|
}
|
|
$sql = "SELECT
|
|
facture.id,
|
|
facture.date,
|
|
facture.date_paiement,
|
|
devis.id as devis_id,
|
|
devis.id_client as devis_client_id,
|
|
devis.date as devis_date
|
|
FROM ".$this->tableprefix."facture as facture
|
|
LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id
|
|
WHERE YEAR(facture.date_paiement) = ? AND
|
|
MONTH(facture.date_paiement) = ? AND
|
|
devis.id_client = ?
|
|
ORDER BY facture.date_paiement ASC;";
|
|
$factureList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$currentYear,$monthValue,$clientId]);
|
|
|
|
$factureDevisIds = [];
|
|
foreach($factureList as $facture){
|
|
$factureDevisIds[] = $facture['devis_id'];
|
|
}
|
|
|
|
$defuntCount = count($factureList);
|
|
$produitsPrice = 0;
|
|
$statisticForeachProductPerMonth = [];
|
|
foreach($produitList as $produit){
|
|
if(!isset($statisticForeachProductPerMonth[$produit['id']])){
|
|
$statisticForeachProductPerMonth[$produit['id']] = 0;
|
|
}
|
|
$productTotalCount = $this->getDevisProductsQuantityByDevisListAndProductId($factureDevisIds,$produit['id']);
|
|
$totalWithoutVat = $productTotalCount * $produit["prix_unitaire"];
|
|
$statisticForeachProductPerMonth[$produit['id']] += $productTotalCount;
|
|
$produitsPrice += $totalWithoutVat;
|
|
}
|
|
$data[$monthValue] = [
|
|
"defunt_count" => $defuntCount,
|
|
"total_price" => $produitsPrice,
|
|
"year" => $currentYear,
|
|
"products" => $statisticForeachProductPerMonth
|
|
];
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
private function getDevisProductsQuantityByDevisListAndProductId($devisList,$productId){
|
|
if(empty($devisList)){
|
|
return 0;
|
|
}
|
|
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisList), '?'));
|
|
$sql = "SELECT
|
|
SUM(produit_devis.quantite) as total_quantity
|
|
FROM ".$this->tableprefix ."produit_devis as produit_devis
|
|
WHERE produit_devis.devis_id IN ($sqlConditionsPlaceholder) AND
|
|
produit_devis.produit_id = ?;";
|
|
|
|
$produitList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
array_merge($devisList,array($productId)));
|
|
|
|
if(!empty($produitList)){
|
|
return $produitList[0]['total_quantity'];
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
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 addNumberColumnOnDevis(){
|
|
$sql = "ALTER TABLE ". $this->tableprefix."devis
|
|
ADD devis_number INT DEFAULT 1;" ;
|
|
$this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[]);
|
|
|
|
$sql = "ALTER TABLE ". $this->tableprefix."devis
|
|
ADD devis_full_number VARCHAR(255);" ;
|
|
$this->execSQLNoJsonReturn(
|
|
$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,
|
|
[]);
|
|
|
|
return true;
|
|
}
|
|
|
|
public function addNumberColumnOnFacture(){
|
|
$sql = "ALTER TABLE ". $this->tableprefix."facture
|
|
ADD facture_number INT DEFAULT 1;" ;
|
|
$this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[]);
|
|
|
|
return true;
|
|
}
|
|
|
|
private function getFactureByIdWithDevis($factureId){
|
|
$sql = "SELECT
|
|
facture.id,
|
|
facture.date,
|
|
facture.date_paiement,
|
|
facture.num,
|
|
devis.id as devis_id,
|
|
devis.date as devis_date,
|
|
devis.num as calendar_uuid,
|
|
devis.comment as devis_comment,
|
|
client.nom as client_nom,
|
|
client.prenom as client_prenom,
|
|
client.entreprise as client_entreprise,
|
|
client.adresse as client_adresse,
|
|
defunt.nom as defunt_nom,
|
|
defunt.sexe as defunt_sexe,
|
|
lieu.nom as lieu_nom,
|
|
lieu.adresse as lieu_adresse,
|
|
thanato.nom as thanato_nom,
|
|
thanato.prenom as thanato_prenom
|
|
FROM ".$this->tableprefix."facture as facture
|
|
LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id
|
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
|
WHERE facture.id = ?
|
|
;";
|
|
$facture = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$factureId]);
|
|
if(!empty($facture)){
|
|
return $facture[0];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function getDevisProduits($devisId){
|
|
$sql = "SELECT
|
|
produit_devis.id,
|
|
produit_devis.produit_id,
|
|
produit_devis.quantite,
|
|
produit_devis.discount,
|
|
produit_devis.devis_id,
|
|
produit.prix_unitaire as produit_price,
|
|
produit.reference as produit_reference,
|
|
produit.description as produit_description,
|
|
produit.vat as produit_vat,
|
|
devis.id_client as devis_client_id
|
|
FROM ".$this->tableprefix ."produit_devis as produit_devis
|
|
LEFT JOIN ".$this->tableprefix."produit as produit on produit_devis.produit_id = produit.id
|
|
LEFT JOIN ".$this->tableprefix."devis as devis on produit_devis.devis_id = devis.id
|
|
WHERE produit_devis.devis_id = ?;";
|
|
|
|
$produitList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$devisId]);
|
|
|
|
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']);
|
|
$produit['produit_price'] = $productPrice ?? $produit['produit_price'];
|
|
}
|
|
}
|
|
|
|
return $produitList;
|
|
}
|
|
|
|
public function getFirstClient(){
|
|
$sql = "SELECT * FROM ".$this->tableprefix."client as client LIMIT 1;";
|
|
$client = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[]);
|
|
|
|
if(!empty($client)){
|
|
return $client[0];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getInvoicePdfData($factureId,$configuration){
|
|
$factureData = $this->getFactureByIdWithDevis($factureId);
|
|
if($factureData == null){
|
|
return null;
|
|
}
|
|
$products = $this->getDevisProduits($factureData["devis_id"]);
|
|
$factureData = $this->setDevisStartAndEndTime($factureData);
|
|
|
|
$firstClient = $this->getFirstClient();
|
|
$factureData["siret"] = $firstClient != null ? $firstClient['legal_one'] : '';
|
|
$factureData["products"] = $products;
|
|
$factureData["configuration"] = $configuration;
|
|
|
|
$clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($factureData["client_adresse"]);
|
|
$factureData["client_real_adress"] = $clientAdresses["address"];
|
|
$factureData["client_adress_city"] = $clientAdresses["city"];
|
|
|
|
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
|
|
$factureData["configuration_adresse"] = $configurationAdresses["address"];
|
|
$factureData["configuration_adresse_city"] = $configurationAdresses["city"];
|
|
return $factureData;
|
|
}
|
|
|
|
private function getInvoiceByClientIdsAndMonthYear($clientIds,$month,$year){
|
|
$clientIdsSqlPlaceholder = implode(',', array_fill(0, count($clientIds), '?'));
|
|
$sql = "SELECT
|
|
facture.id,
|
|
facture.date,
|
|
facture.date_paiement,
|
|
facture.num,
|
|
devis.id as devis_id,
|
|
devis.date as devis_date,
|
|
devis.num as calendar_uuid,
|
|
devis.comment as devis_comment,
|
|
devis.id_client as devis_id_client,
|
|
client.nom as client_nom,
|
|
client.entreprise as client_entreprise,
|
|
client.adresse as client_adresse,
|
|
defunt.nom as defunt_nom,
|
|
defunt.sexe as defunt_sexe,
|
|
lieu.nom as lieu_nom,
|
|
lieu.adresse as lieu_adresse,
|
|
thanato.nom as thanato_nom,
|
|
thanato.prenom as thanato_prenom
|
|
FROM ".$this->tableprefix."facture as facture
|
|
LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id
|
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
|
WHERE devis.id_client IN ($clientIdsSqlPlaceholder) AND
|
|
YEAR(facture.date_paiement) = ?";
|
|
|
|
$conditions = array_merge($clientIds,[$year]);
|
|
if($month != 0){
|
|
$conditions[] = $month;
|
|
$sql .= " AND MONTH(facture.date_paiement) = ?";
|
|
}
|
|
$sql .= ";";
|
|
$factures = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
$conditions);
|
|
|
|
return $factures;
|
|
}
|
|
|
|
private function getInvoiceByClientAndMonthYear($clientId,$month,$year){
|
|
$sql = "SELECT
|
|
facture.id,
|
|
facture.date,
|
|
facture.date_paiement,
|
|
facture.num,
|
|
devis.id as devis_id,
|
|
devis.date as devis_date,
|
|
devis.num as calendar_uuid,
|
|
devis.comment as devis_comment,
|
|
devis.id_client as devis_id_client,
|
|
client.nom as client_nom,
|
|
client.entreprise as client_entreprise,
|
|
client.adresse as client_adresse,
|
|
defunt.nom as defunt_nom,
|
|
defunt.sexe as defunt_sexe,
|
|
lieu.nom as lieu_nom,
|
|
lieu.adresse as lieu_adresse,
|
|
thanato.nom as thanato_nom,
|
|
thanato.prenom as thanato_prenom
|
|
FROM ".$this->tableprefix."facture as facture
|
|
LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id
|
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
|
WHERE devis.id_client = ? AND
|
|
YEAR(facture.date_paiement) = ?";
|
|
|
|
$conditions = [$clientId,$year];
|
|
if($month != 0){
|
|
$conditions[] = $month;
|
|
$sql .= " AND MONTH(facture.date_paiement) = ?";
|
|
}
|
|
$sql .= ";";
|
|
$factures = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
$conditions);
|
|
|
|
return $factures;
|
|
}
|
|
|
|
public function getInvoicePdfDataByClientAndMonthYear($clientId,$month,$year,$configuration){
|
|
if($clientId == 0){
|
|
$clientIds = $this->getClientIdsByClientEntreprise(clientEntreprise: 'cogf');
|
|
$invoices = $this->getInvoiceByClientIdsAndMonthYear($clientIds,$month,$year);
|
|
}
|
|
else{
|
|
$invoices = $this->getInvoiceByClientAndMonthYear($clientId,$month,$year);
|
|
}
|
|
$firstClient = $this->getFirstClient();
|
|
foreach($invoices as &$invoice){
|
|
$invoice["siret"] = $firstClient != null ? $firstClient['legal_one'] : '';
|
|
$products = $this->getDevisProduits($invoice["devis_id"]);
|
|
$invoice["products"] = $products;
|
|
$invoice["configuration"] = $configuration;
|
|
|
|
$clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($invoice["client_adresse"]);
|
|
$invoice["client_real_adress"] = $clientAdresses["address"];
|
|
$invoice["client_adress_city"] = $clientAdresses["city"];
|
|
|
|
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
|
|
$invoice["configuration_adresse"] = $configurationAdresses["address"];
|
|
$invoice["configuration_adresse_city"] = $configurationAdresses["city"];
|
|
}
|
|
return $invoices;
|
|
}
|
|
public function getDevisPdfDataByDevisId($devisId){
|
|
$sql = "SELECT
|
|
devis.id as devis_id,
|
|
devis.date as devis_date,
|
|
devis.num as calendar_uuid,
|
|
devis.devis_full_number as devis_full_number,
|
|
devis.comment as devis_comment,
|
|
client.nom as client_nom,
|
|
client.prenom as client_prenom,
|
|
client.entreprise as client_entreprise,
|
|
client.adresse as client_adresse,
|
|
defunt.nom as defunt_nom,
|
|
defunt.sexe as defunt_sexe,
|
|
lieu.nom as lieu_nom,
|
|
lieu.adresse as lieu_adresse,
|
|
thanato.nom as thanato_nom,
|
|
thanato.prenom as thanato_prenom
|
|
FROM ".$this->tableprefix."devis as devis
|
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
|
WHERE devis.id = ?
|
|
;";
|
|
$devis = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$devisId]);
|
|
if(!empty($devis)){
|
|
return $devis[0];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private function getDevisByClientAndMonthYear($clientId,$month,$year){
|
|
$sql = "SELECT
|
|
devis.id as devis_id,
|
|
devis.date as devis_date,
|
|
devis.num as calendar_uuid,
|
|
devis.comment as devis_comment,
|
|
devis.id_client as devis_id_client,
|
|
devis.devis_full_number as devis_full_number,
|
|
client.nom as client_nom,
|
|
client.entreprise as client_entreprise,
|
|
client.adresse as client_adresse,
|
|
defunt.nom as defunt_nom,
|
|
defunt.sexe as defunt_sexe,
|
|
lieu.nom as lieu_nom,
|
|
lieu.adresse as lieu_adresse,
|
|
thanato.nom as thanato_nom,
|
|
thanato.prenom as thanato_prenom
|
|
FROM ".$this->tableprefix."devis as devis
|
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
|
WHERE devis.id_client = ? AND
|
|
YEAR(devis.date) = ?";
|
|
|
|
$conditions = [$clientId,$year];
|
|
if($month != 0){
|
|
$conditions[] = $month;
|
|
$sql .= " AND MONTH(devis.date) = ?";
|
|
}
|
|
$sql .= ";";
|
|
$devisList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
$conditions);
|
|
|
|
return $devisList;
|
|
}
|
|
|
|
public function getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$configuration){
|
|
$devisList = $this->getDevisByClientAndMonthYear($clientId,$month,$year);
|
|
return $devisList;
|
|
}
|
|
|
|
public function getDevisOfDefunt($defuntId){
|
|
$sql = "SELECT
|
|
devis.id as id,
|
|
devis.date as devis_date,
|
|
devis.id_defunt as defunt_id,
|
|
devis.id_lieu as lieu_id,
|
|
lieu.nom as lieu_nom,
|
|
lieu.adresse as lieu_adresse,
|
|
defunt.nom as defunt_nom,
|
|
defunt.sexe as defunt_sexe,
|
|
client.nom as client_nom,
|
|
client.prenom as client_prenom,
|
|
client.entreprise as client_entreprise,
|
|
client.adresse as client_adresse,
|
|
thanato.nom as thanato_nom,
|
|
thanato.prenom as thanato_prenom,
|
|
thanato.reference as thanato_reference,
|
|
thanato.date_habilitation as thanato_date_habilitation
|
|
FROM ".$this->tableprefix."devis as devis
|
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.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)){
|
|
return $devisOfDefunt[0];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private function getDevisIdListFilteredByMentionAndDevisListId($mentionToNotInclude,$devisListId){
|
|
if (empty($devisListId)) {
|
|
return [];
|
|
}
|
|
$placeholders = implode(',', array_fill(0, count($devisListId), '?'));
|
|
$sql = "SELECT devis.id as id,devis.date as devis_date
|
|
FROM ".$this->tableprefix."devis as devis
|
|
WHERE devis.id IN ($placeholders) AND mentions != ?";
|
|
|
|
$result = $this->execSQLNoJsonReturn($sql,array_merge($devisListId, [$mentionToNotInclude]));
|
|
return $result;
|
|
}
|
|
|
|
private function getFactureIdByDevisId($devisId){
|
|
$sql = "SELECT
|
|
facture.id
|
|
FROM ".$this->tableprefix."facture as facture
|
|
WHERE facture.id_devis = ?
|
|
ORDER BY facture.id DESC;";
|
|
$facture = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$devisId]);
|
|
if(!empty($facture)){
|
|
return $facture[0]['id'];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
/**
|
|
* Insert invoice with a devis
|
|
*/
|
|
public function insertFactureByDevisId($idNextcloud,$devisId,$devisDate = null,$paymentDate = null){
|
|
if($paymentDate == null || $paymentDate == ""){
|
|
$datetimeNow = new Datetime();
|
|
$paymentDate = DateHelpers::GetLastDayOfTheMonthOfADate($datetimeNow);
|
|
$paymentDate = $paymentDate->format('Y-m-d');
|
|
}
|
|
else{
|
|
$paymentDate = Datetime::createFromFormat('Y-m-d',$paymentDate);
|
|
$paymentDate = $paymentDate->format('Y-m-d');
|
|
}
|
|
$devisDatetime = new Datetime();
|
|
if($devisDate != null){
|
|
$devisDatetime = new Datetime($devisDate);
|
|
}
|
|
|
|
$last = 0;
|
|
$last = $this->lastNumFacture($idNextcloud);
|
|
$factureDate = $devisDatetime->format('Y-m-d');
|
|
$datesplit = explode('-', $factureDate);
|
|
$fullFactureNumber = "H2F".$datesplit[0]."/".$datesplit[1]."/".$last+1;
|
|
$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(
|
|
$factureDate,
|
|
$idNextcloud,
|
|
$fullFactureNumber,
|
|
$paymentDate,
|
|
"Comptant",
|
|
$devisId,
|
|
$last+1,
|
|
"Ajouter un lieu",
|
|
$last + 1 )
|
|
);
|
|
|
|
$factureId = $this->getFactureIdByDevisId($devisId);
|
|
//update devis status
|
|
$this->gestion_update('devis','mentions','facturé',$devisId,$idNextcloud);
|
|
return $factureId;
|
|
}
|
|
|
|
public function insertFactureForeEachDevisId($idNextCloud,$devisIdArray,$paymentDate = null){
|
|
$mentionToNotInclude = 'facturé';
|
|
$devisIdListFiltered = $this->getDevisIdListFilteredByMentionAndDevisListId($mentionToNotInclude,$devisIdArray);
|
|
$factureIdsGenerated = [];
|
|
foreach($devisIdListFiltered as $devis){
|
|
$factureId = $this->insertFactureByDevisId($idNextCloud,$devis['id'],$devis['devis_date'],$paymentDate);
|
|
$factureIdsGenerated[] = $factureId;
|
|
}
|
|
return $factureIdsGenerated;
|
|
}
|
|
|
|
public function getClientIdsByClientEntreprise($clientEntreprise){
|
|
$sql = "SELECT client.id
|
|
FROM ".$this->tableprefix."client as client
|
|
WHERE LOWER(client.entreprise) = ? ;";
|
|
|
|
$clientIds = [];
|
|
$clients = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[strtolower($clientEntreprise)]);
|
|
|
|
if(!empty($clients)){
|
|
foreach($clients as $client){
|
|
$clientIds[] = $client["id"];
|
|
}
|
|
}
|
|
return $clientIds;
|
|
}
|
|
|
|
public function getFactureByClientIdsListAndDate($clientIds,$date){
|
|
$clientIdsSqlPlaceholder = $clientIdsSqlPlaceholder = implode(',', array_fill(0, count($clientIds), '?'));
|
|
$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."devis.comment as numero_commande, "
|
|
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
|
.$this->tableprefix."client.mail as mail_client, ".$this->tableprefix."client.entreprise as client_entreprise, ".$this->tableprefix."client.fk_client_group_id as fk_client_group_id, "
|
|
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
|
.$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."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
|
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
|
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 IN ($clientIdsSqlPlaceholder) ORDER BY year DESC, month DESC;";
|
|
|
|
$result = $this->execSQL($sql, $clientIds);
|
|
return $result;
|
|
}
|
|
|
|
public function geThanatoTypes(){
|
|
$sql = "SELECT * FROM ".$this->tableprefix."thanato_type as thanato_type";
|
|
return $this->execSQL($sql,[]);
|
|
}
|
|
|
|
public function getUsersNotLinkedToThanato(){
|
|
$sql = "SELECT
|
|
users.uid,
|
|
users.uid_lower,
|
|
users.displayname
|
|
FROM ".self::DEFAULT_TABLE_PREFIX."users as users
|
|
JOIN .".self::DEFAULT_TABLE_PREFIX."group_user group_user ON users.uid = group_user.uid
|
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on users.uid = thanato.fk_user_uuid
|
|
WHERE group_user.gid = ? AND
|
|
thanato.fk_user_uuid IS NULL;
|
|
";
|
|
|
|
return $this->execSQL($sql,[BddConstant::DEFAULT_THANATOS_GROUP_NAME]);
|
|
}
|
|
|
|
public function getDevisByCalendarUuid($calendarUuid){
|
|
if($calendarUuid === self::DEFAULT_CALENDAR_UUID_FOR_DEVIS){
|
|
return null;
|
|
}
|
|
$sql = "SELECT
|
|
devis.id,
|
|
devis.id_thanato,
|
|
devis.id_defunt as defunt_id,
|
|
devis.num,
|
|
devis.comment,
|
|
devis.id_lieu as lieu_id,
|
|
devis.id_client as client_id,
|
|
defunt.nom as defunt_nom
|
|
FROM ".$this->tableprefix."devis as devis
|
|
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
|
WHERE devis.num = ? ;";
|
|
|
|
$devis = $this->execSQLNoJsonReturn($sql, array($calendarUuid));
|
|
if(empty($devis)){
|
|
return null;
|
|
}
|
|
return $devis[0];
|
|
}
|
|
|
|
public function updateDevisMentionToCanceled($devisId){
|
|
$sql= "UPDATE ".$this->tableprefix."devis as devis
|
|
SET devis.mentions = ?
|
|
WHERE devis.id = ?";
|
|
|
|
$this->execSQLNoData($sql,[DevisMentionConstant::CANCELED,$devisId]);
|
|
}
|
|
|
|
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]);
|
|
}
|
|
|
|
public function getProduitDevisByDevisId($devisId){
|
|
$sql = "SELECT *
|
|
FROM ".$this->tableprefix ."produit_devis as produit_devis
|
|
WHERE produit_devis.devis_id = ?;";
|
|
|
|
$produitDevisList = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$devisId]);
|
|
|
|
|
|
return $produitDevisList;
|
|
}
|
|
|
|
private function updateDefuntByName($defuntId,$requestedDefuntName){
|
|
$sql= "UPDATE ".$this->tableprefix."defunt as defunt
|
|
SET defunt.nom = ?
|
|
WHERE defunt.id = ?";
|
|
$this->execSQLNoData($sql,[$requestedDefuntName,$defuntId]);
|
|
}
|
|
|
|
public function createOrUpdateDefuntByNameAndReturnDefuntId($defuntId,$currentDefuntName,$requestedDefuntName){
|
|
if($defuntId != null){
|
|
$defuntNameIsUpdated = $currentDefuntName != $requestedDefuntName;
|
|
if($defuntNameIsUpdated){
|
|
$this->updateDefuntByName($defuntId,$requestedDefuntName);
|
|
}
|
|
}
|
|
else{
|
|
$this->insertDefuntByName($requestedDefuntName);
|
|
$defunt = $this->getLastDefuntIdByName($requestedDefuntName);
|
|
$defuntId = $defunt['id'];
|
|
}
|
|
return $defuntId;
|
|
}
|
|
|
|
public function updateDevisDefunt($devisId,$requestedDefuntId,$currentDefuntId = null){
|
|
$defuntIsUpdated = $currentDefuntId != $requestedDefuntId;
|
|
if($defuntIsUpdated){
|
|
$sql= "UPDATE ".$this->tableprefix."devis as devis
|
|
SET devis.id_defunt = ?
|
|
WHERE devis.id = ?";
|
|
$this->execSQLNoData($sql,[$requestedDefuntId,$devisId]);
|
|
}
|
|
}
|
|
|
|
public function updateDevisClient($devisId,$requestedClientId,$currentClientId = null){
|
|
$clientIsUpdated = $currentClientId != $requestedClientId;
|
|
if($clientIsUpdated){
|
|
$sql= "UPDATE ".$this->tableprefix."devis as devis
|
|
SET devis.id_client = ?
|
|
WHERE devis.id = ?";
|
|
$this->execSQLNoData($sql,[$requestedClientId,$devisId]);
|
|
}
|
|
}
|
|
|
|
public function updateDevisLieu($devisId,$requestedLieuId,$currentLieuId = null){
|
|
$lieuIsUpdated = $currentLieuId != $requestedLieuId;
|
|
if($lieuIsUpdated){
|
|
$sql= "UPDATE ".$this->tableprefix."devis as devis
|
|
SET devis.id_lieu = ?
|
|
WHERE devis.id = ?";
|
|
$this->execSQLNoData($sql,[$requestedLieuId,$devisId]);
|
|
}
|
|
}
|
|
|
|
public function deleteDevisProduit($devisProductId){
|
|
$sql = "DELETE FROM ".$this->tableprefix."produit_devis WHERE id = ?;";
|
|
$this->execSQLNoData($sql, array($devisProductId));
|
|
}
|
|
|
|
public function updateDevisArticles($devisId,$requestedArticlesIds){
|
|
$currentDevisProducts = $this->getDevisProduits($devisId);
|
|
$currentDevisProduitIds = [];
|
|
//delete old product
|
|
foreach($currentDevisProducts as $devisProduct){
|
|
$currentDevisProduitIds[] = $devisProduct['produit_id'];
|
|
$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);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getThanatosByType($thanatoType = ThanatoTypeConstant::THANATO_TYPE_EMPLOYEE){
|
|
$thanatoType = $thanatoType ?? ThanatoTypeConstant::THANATO_TYPE_EMPLOYEE;
|
|
$sql = "SELECT * FROM ".$this->tableprefix."thanato as thanato
|
|
WHERE thanato.fk_thanato_type_key = ?
|
|
";
|
|
|
|
return $this->execSQL($sql,[$thanatoType]);
|
|
}
|
|
|
|
public function getClientGroupDiscounts(){
|
|
|
|
$sql = "SELECT
|
|
client_group_discount.id as id,
|
|
client_group_discount.fk_client_group_id as fk_client_group_id,
|
|
client_group_discount.fk_produit_id as fk_produit_id,
|
|
client_group_discount.ht_amount as ht_amount,
|
|
client_group.client_group_name as client_group_name,
|
|
produit.id as produit_id,
|
|
produit.reference as produit_reference,
|
|
produit.prix_unitaire as prix_unitaire
|
|
FROM ".$this->tableprefix."client_group_discount as client_group_discount
|
|
LEFT JOIN ".$this->tableprefix."client_group as client_group on client_group_discount.fk_client_group_id = client_group.id
|
|
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,
|
|
[]);
|
|
|
|
return $clientGroupDiscounts;
|
|
}
|
|
|
|
public function getClientGroups(){
|
|
$sql = "SELECT * FROM ".$this->tableprefix."client_group as client_group ORDER BY client_group.id DESC;";
|
|
$clientGroups = $this->execSQL($sql,[]);
|
|
return $clientGroups;
|
|
}
|
|
|
|
public function createDefaultClientGroup(){
|
|
$sql = "INSERT INTO `".$this->tableprefix."client_group` (`client_group_name`) VALUES (?);";
|
|
$this->execSQLNoData($sql, array(BddConstant::DEFAULT_CLIENT_GROUP_NAME));
|
|
return true;
|
|
}
|
|
|
|
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(){
|
|
$sql = "SELECT count(*) as c from ".$this->tableprefix."client_group;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getClientGroupDiscountCount(){
|
|
$sql = "SELECT count(*) as c from ".$this->tableprefix."client_group_discount;";
|
|
return $this->execSQL($sql, array());
|
|
}
|
|
|
|
public function getProductPriceByClientGroupId($clientGroupId,$productId){
|
|
$sql = "SELECT *
|
|
FROM ".$this->tableprefix ."client_group_discount as client_group_discount
|
|
WHERE client_group_discount.fk_client_group_id = ? AND
|
|
client_group_discount.fk_produit_id = ?;
|
|
";
|
|
$clientGroupDiscount = $this->execSQLNoJsonReturn(
|
|
$sql,
|
|
[$clientGroupId,$productId]);
|
|
if(!empty($clientGroupDiscount)){
|
|
return $clientGroupDiscount[0]['ht_amount'];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
}
|