From 6160b30a835f43dc259ba4b137613f3d45e8f85b Mon Sep 17 00:00:00 2001 From: Tiavina Date: Tue, 4 Feb 2025 12:32:21 +0300 Subject: [PATCH] add discount price in document recap if exist --- gestion/lib/Db/Bdd.php | 6 +++--- .../InvoiceRecap/InvoiceRecapService.php | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 563ef30..44942f0 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -378,7 +378,7 @@ class Bdd { .$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.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," @@ -411,7 +411,7 @@ class Bdd { .$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.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," @@ -2551,7 +2551,7 @@ class Bdd { return $produitList; } - private function getProductPriceByClientGroupId($clientGroupId,$productId){ + 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 diff --git a/gestion/lib/Service/InvoiceRecap/InvoiceRecapService.php b/gestion/lib/Service/InvoiceRecap/InvoiceRecapService.php index 3ea4935..27144bf 100644 --- a/gestion/lib/Service/InvoiceRecap/InvoiceRecapService.php +++ b/gestion/lib/Service/InvoiceRecap/InvoiceRecapService.php @@ -124,7 +124,14 @@ class InvoiceRecapService { $produits = json_decode($this->gestionBdd->getListProduit($facture->id_devis,$idNextcloud)); $produitsReferenceArray = []; foreach ($produits as $key => $produit) { - $facture_temp['montant_htc'] += $produit->prix_unitaire * $produit->quantite; + $htPrice = $produit->prix_unitaire; + if($facture->fk_client_group_id != null){ + $price = $this->gestionBdd->getProductPriceByClientGroupId($facture->fk_client_group_id,$produit->id); + if($price != null){ + $htPrice = $price; + } + } + $facture_temp['montant_htc'] += $htPrice * $produit->quantite; $produitsReferenceArray[] = $produit->reference; }; $produitsReferenceArray = array_unique($produitsReferenceArray); @@ -449,7 +456,14 @@ class InvoiceRecapService { $produits = json_decode($this->gestionBdd->getListProduit($facture->id_devis,$idNextcloud)); $produitsReferenceArray = []; foreach ($produits as $key => $produit) { - $facture_temp['montant_htc'] += $produit->prix_unitaire * $produit->quantite; + $htPrice = $produit->prix_unitaire; + if($facture->fk_client_group_id != null){ + $price = $this->gestionBdd->getProductPriceByClientGroupId($facture->fk_client_group_id,$produit->id); + if($price != null){ + $htPrice = $price; + } + } + $facture_temp['montant_htc'] += $htPrice * $produit->quantite; $produitsReferenceArray[] = $produit->reference; }; $produitsReferenceArray = array_unique($produitsReferenceArray);