From ec0aba426c1b6eceacc624f55d8ed1abb63a0bca Mon Sep 17 00:00:00 2001 From: Tolotsoa Date: Tue, 9 Dec 2025 13:30:49 +0300 Subject: [PATCH] fix facture en double --- gestion/lib/Db/Bdd.php | 130 ++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 6452440..bdfd898 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -449,68 +449,76 @@ class Bdd public function getFacturesListWithDependencies() { - $sql = "SELECT - facture.id, - facture.user_id, - facture.num, - facture.date, - facture.fk_facture_status_key, - facture.fk_facture_payment_type_id, - facture.payment_date, - facture_payment_type.facture_payment_type_label, - facture_status.facture_status_label, - facture.facture_type, - facture.fk_client_id as facture_client_id, - facture.fk_client_group_facturation_id as facture_client_group_facturation_id, - facture.date_paiement, - facture.type_paiement, - facture.id_devis, - facture.version, - facture.status_paiement, - facture_client.nom as facture_client_name, - facture_client.entreprise as facture_client_entreprise, - facture_client.fk_client_group_id as facture_client_group_id, - facture_client_group_facturation.group_facturation_name as facture_group_name, - facture_client_group_facturation.code_comptable as group_code_comptable, - facture.document_generated_date as facture_document_generated_date, - facture.document_sent_date as facture_document_sent_date, - facture.month as facture_month, - facture.year as facture_year, - devis.num as dnum, - devis.comment as dcomment, - client.entreprise, - client.nom, - client.prenom, - client.id as id_cli, - client.entreprise as client_entreprise, - client.fk_client_group_facturation_id as fk_client_group_facturation_id, - client.adresse as adresse_cli,client.mail as mail_cli, - client.telephone as telephone_cli,client.legal_one as legalone_cli, - client.fk_client_group_id as fk_client_group_id, - COALESCE( - client.is_tva, - CASE - WHEN facture.fk_client_group_facturation_id IS NOT NULL THEN client_group_tva.is_tva - ELSE facture_client.is_tva - END - ) as tva, - defunt.id as id_defunt, - defunt.nom as nom_defunt, - lieu.id as lid, - lieu.nom as lieu, - lieu.adresse as adresse_soin,devis.id_lieu - FROM ".$this->tableprefix."facture as facture - LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id - LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.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."facture_payment_type as facture_payment_type on facture.fk_facture_payment_type_id = facture_payment_type.id - LEFT JOIN ".$this->tableprefix."facture_status as facture_status on facture.fk_facture_status_key = facture_status.facture_status_key - LEFT JOIN ".$this->tableprefix."client as facture_client on facture.fk_client_id = facture_client.id - LEFT JOIN ".$this->tableprefix."client_group_facturation as facture_client_group_facturation on facture.fk_client_group_facturation_id = facture_client_group_facturation.id - LEFT JOIN ".$this->tableprefix."client as client_group_tva ON facture.fk_client_group_facturation_id = client_group_tva.fk_client_group_facturation_id - ORDER BY facture.id DESC, facture.date_paiement DESC"; + facture.id, + facture.user_id, + facture.num, + facture.date, + facture.fk_facture_status_key, + facture.fk_facture_payment_type_id, + facture.payment_date, + facture_payment_type.facture_payment_type_label, + facture_status.facture_status_label, + facture.facture_type, + facture.fk_client_id as facture_client_id, + facture.fk_client_group_facturation_id as facture_client_group_facturation_id, + facture.date_paiement, + facture.type_paiement, + facture.id_devis, + facture.version, + facture.status_paiement, + facture_client.nom as facture_client_name, + facture_client.entreprise as facture_client_entreprise, + facture_client.fk_client_group_id as facture_client_group_id, + facture_client_group_facturation.group_facturation_name as facture_group_name, + facture_client_group_facturation.code_comptable as group_code_comptable, + facture.document_generated_date as facture_document_generated_date, + facture.document_sent_date as facture_document_sent_date, + facture.month as facture_month, + facture.year as facture_year, + devis.num as dnum, + devis.comment as dcomment, + client.entreprise, + client.nom, + client.prenom, + client.id as id_cli, + client.entreprise as client_entreprise, + client.fk_client_group_facturation_id, + client.adresse as adresse_cli, + client.mail as mail_cli, + client.telephone as telephone_cli, + client.legal_one as legalone_cli, + client.fk_client_group_id, + COALESCE( + client.is_tva, + CASE + WHEN facture.fk_client_group_facturation_id IS NOT NULL + THEN ( + SELECT is_tva + FROM ".$this->tableprefix."client + WHERE fk_client_group_facturation_id = facture.fk_client_group_facturation_id + LIMIT 1 + ) + ELSE facture_client.is_tva + END + ) as tva, + defunt.id as id_defunt, + defunt.nom as nom_defunt, + lieu.id as lid, + lieu.nom as lieu, + lieu.adresse as adresse_soin, + devis.id_lieu + FROM ".$this->tableprefix."facture as facture + LEFT JOIN ".$this->tableprefix."devis as devis ON facture.id_devis = devis.id + LEFT JOIN ".$this->tableprefix."lieu as lieu ON devis.id_lieu = lieu.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."facture_payment_type as facture_payment_type ON facture.fk_facture_payment_type_id = facture_payment_type.id + LEFT JOIN ".$this->tableprefix."facture_status as facture_status ON facture.fk_facture_status_key = facture_status.facture_status_key + LEFT JOIN ".$this->tableprefix."client as facture_client ON facture.fk_client_id = facture_client.id + LEFT JOIN ".$this->tableprefix."client_group_facturation as facture_client_group_facturation ON facture.fk_client_group_facturation_id = facture_client_group_facturation.id + ORDER BY facture.id DESC, facture.date_paiement DESC"; + $result = $this->execSQL($sql, array()); return $result; }