From ed4e42f044da6a34934dbc09e977a42231a9ab65 Mon Sep 17 00:00:00 2001 From: Tiavina Date: Mon, 30 Dec 2024 08:00:46 +0300 Subject: [PATCH] get client statistique a year --- gestion/lib/Controller/PageController.php | 2 -- gestion/lib/Db/Bdd.php | 4 +-- .../Service/ExportClientStatisticService.php | 33 ++++++++++--------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index 4cea15b..69cbc06 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -2598,8 +2598,6 @@ class PageController extends Controller { return ""; } $exportData = $this->myDb->getExportClientStatData($clientIdsToExport); - var_dump($exportData); - die; if(empty($exportData)){ return ""; } diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index d1fb10e..47e1789 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -1923,9 +1923,9 @@ class Bdd { produit_devis.id, produit_devis.produit_id, produit_devis.quantite, - produit_devis.discount + produit_devis.discount, produit.prix_unitaire as produit_price - FROM $this->tableprefix.produit_devis as produit_devis + FROM ".$this->tableprefix ."produit_devis as produit_devis LEFT JOIN ".$this->tableprefix."produit as produit on produit_devis.produit_id = produit.id WHERE produit_devis.devis_id = ?;"; diff --git a/gestion/lib/Service/ExportClientStatisticService.php b/gestion/lib/Service/ExportClientStatisticService.php index a10d8e3..d1e16c1 100644 --- a/gestion/lib/Service/ExportClientStatisticService.php +++ b/gestion/lib/Service/ExportClientStatisticService.php @@ -67,18 +67,16 @@ class ExportClientStatisticService { public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{ foreach($exportData as $clientId => $clientData){ - foreach($clientData as $data){ - $clientName = $data["client_name"]; - $clientStatPerMonth = $data["client_data"]; - $totalPrice = 0; - if(!empty($clientStatPerMonth)){ - foreach($clientStatPerMonth as $month => $stat){ - $stat["client_name"] = $clientName; - $totalPrice+=$stat["total_price"]; - $fileContent = $this->populateClientStatDataIntoFileContent($fileContent,$month,$stat); - } - $fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice); + $clientName = $clientData["client_name"]; + $clientStatPerMonth = $clientData["client_data"]; + $totalPrice = 0; + if(!empty($clientStatPerMonth)){ + foreach($clientStatPerMonth as $month => $stat){ + $stat["client_name"] = $clientName; + $totalPrice+=$stat["total_price"]; + $fileContent = $this->populateClientStatDataIntoFileContent($fileContent,$month,$stat); } + $fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice); } } return $fileContent; @@ -96,13 +94,18 @@ class ExportClientStatisticService { } private function populateClientStatDataIntoFileContent(string $fileContent,$month,array $statPerMonth){ + $yearValue = $statPerMonth["year"]; + $defuntCount = $statPerMonth["defunt_count"]; + $productCount = $statPerMonth["produit_count"]; + $totalPrice = $statPerMonth["total_price"]; + $fileContent = $fileContent. utf8_decode(html_entity_decode($statPerMonth['client_name'])).';'. utf8_decode(html_entity_decode("$month")).';'. - utf8_decode(html_entity_decode($statPerMonth["year"])).';'. - utf8_decode(html_entity_decode($statPerMonth["defunt_count"])).';'. - utf8_decode(html_entity_decode($statPerMonth["produit_count"])).';'. - utf8_decode(html_entity_decode($statPerMonth["total_price"])).';'."\n"; + utf8_decode(html_entity_decode("$yearValue")).';'. + utf8_decode(html_entity_decode("$defuntCount")).';'. + utf8_decode(html_entity_decode("$productCount")).';'. + utf8_decode(html_entity_decode("$totalPrice")).';'."\n"; return $fileContent;