Merge branch 'fixes/fix-thanato-export-adress' into staging

This commit is contained in:
Tiavina 2024-12-31 00:32:15 +03:00
commit 3d573145ec
4 changed files with 114 additions and 65 deletions

View File

@ -2005,22 +2005,28 @@ class Bdd {
return $produitList; return $produitList;
} }
private function getProduitsDevisStatistic($devisId){ private function getDevisProductsQuantityByDevisListAndProductId($devisList,$productId){
$produitList = $this->getDevisProduits($devisId); if(empty($devisList)){
$productsCount = count($produitList); return 0;
$productsPrice = 0;
foreach($produitList as $produit){
$productsPrice += $produit["quantite"] * $produit["produit_price"];
} }
$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 = ?;";
return [ $produitList = $this->execSQLNoJsonReturn(
"count" => $productsCount, $sql,
"total_price" => $productsPrice array_merge($devisList,array($productId)));
];
if(!empty($produitList)){
return $produitList[0]['total_quantity'];
}
return 0;
} }
private function getClientFactureStatisticPerMonth($clientId){ private function getClientFactureStatisticPerMonth($clientId,array $produitList){
$currentYear = date('Y'); $currentYear = date('Y');
$monthLists = range(1,12); $monthLists = range(1,12);
$data = [] ; $data = [] ;
@ -2045,19 +2051,28 @@ class Bdd {
$sql, $sql,
[$currentYear,$monthValue,$clientId]); [$currentYear,$monthValue,$clientId]);
$defuntCount = count($factureList); $factureDevisIds = [];
$produitsCount = 0;
$produitsPrice = 0;
foreach($factureList as $facture){ foreach($factureList as $facture){
$devisProduitStat = $this->getProduitsDevisStatistic($facture["devis_id"]); $factureDevisIds[] = $facture['devis_id'];
$produitsCount+= $devisProduitStat["count"]; }
$produitsPrice+= $devisProduitStat["total_price"];
$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] = [ $data[$monthValue] = [
"defunt_count" => $defuntCount, "defunt_count" => $defuntCount,
"produit_count" => $produitsCount,
"total_price" => $produitsPrice, "total_price" => $produitsPrice,
"year" => $currentYear "year" => $currentYear,
"products" => $statisticForeachProductPerMonth
]; ];
} }
return $data; return $data;
@ -2065,6 +2080,7 @@ class Bdd {
public function getExportClientStatData(array $clientIds){ public function getExportClientStatData(array $clientIds){
$data = []; $data = [];
$produitList = $this->getProduitsListAsArray();
foreach($clientIds as $clientId){ foreach($clientIds as $clientId){
if(!isset($data[$clientId])){ if(!isset($data[$clientId])){
$data[$clientId] = []; $data[$clientId] = [];
@ -2076,7 +2092,7 @@ class Bdd {
$clientName = trim($client["client_nom"]) . '-' .trim($client['client_entreprise']); $clientName = trim($client["client_nom"]) . '-' .trim($client['client_entreprise']);
} }
$data[$clientId]["client_name"] = $clientName; $data[$clientId]["client_name"] = $clientName;
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId); $data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId,$produitList);
} }
return $data; return $data;
} }
@ -2167,4 +2183,14 @@ class Bdd {
return null; return null;
} }
public function getProduitsListAsArray(){
$sql = "SELECT * FROM ".$this->tableprefix."produit as produit;";
$produitList = $this->execSQLNoJsonReturn(
$sql,
[]);
return $produitList;
}
} }

View File

@ -0,0 +1,14 @@
<?php
namespace OCA\Gestion\Helpers;
class FileExportHelpers
{
public static function FormatTextForExport(string $text){
$textFormatted = utf8_decode(html_entity_decode($text));
return $textFormatted;
}
}

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCA\Gestion\Service; namespace OCA\Gestion\Service;
use OCA\Gestion\Db\Bdd; use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\FileExportHelpers;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class ExportClientStatisticService { class ExportClientStatisticService {
@ -57,13 +58,16 @@ class ExportClientStatisticService {
public function getExportClientFileHeader(): string{ public function getExportClientFileHeader(): string{
$fileHeader = $fileHeader =
'Client'.';'. 'CLIENT'.';'.
'Mois'.';'. 'MOIS'.';'.
utf8_decode(html_entity_decode('Année')).';'. 'ANNEE'.';'.
utf8_decode(html_entity_decode('Nb défunts')).';'. 'NB DE DEFUNTS'.';';
'Nb articles'.';'.
'Total HT'.';'. $produitList = $this->gestionBdd->getProduitsListAsArray();
"\n"; foreach($produitList as $produit){
$fileHeader .= FileExportHelpers::FormatTextForExport($produit['reference']).';';
}
$fileHeader .= 'TOTAL HT'.';'."\n";
return $fileHeader; return $fileHeader;
} }
@ -78,37 +82,41 @@ class ExportClientStatisticService {
$totalPrice+=$stat["total_price"]; $totalPrice+=$stat["total_price"];
$fileContent = $this->populateClientStatDataIntoFileContent($fileContent,$month,$stat); $fileContent = $this->populateClientStatDataIntoFileContent($fileContent,$month,$stat);
} }
$fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice); $fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice,count($stat["products"]));
} }
} }
return $fileContent; return $fileContent;
} }
private function populateTotalPriceIntoFileContent(string $fileContent,$price){ private function populateTotalPriceIntoFileContent(string $fileContent,$totalPrice,$productsCount){
$fileContent = $fileContent. $fileContent = $fileContent.
''.';'. ''.';'.
''.';'. ''.';'.
''.';'. ''.';'.
''.';'. ''.';';
''.';'. while($productsCount > 0){
utf8_decode(html_entity_decode("$price"))."\n"; $fileContent .= ''.';';
$productsCount--;
}
$fileContent .= "$totalPrice".";"."\n";
return $fileContent; return $fileContent;
} }
private function populateClientStatDataIntoFileContent(string $fileContent,$month,array $statPerMonth){ private function populateClientStatDataIntoFileContent(string $fileContent,$month,array $statPerMonth){
$yearValue = $statPerMonth["year"]; $yearValue = $statPerMonth["year"];
$defuntCount = $statPerMonth["defunt_count"]; $defuntCount = $statPerMonth["defunt_count"];
$productCount = $statPerMonth["produit_count"]; $products = $statPerMonth["products"];
$totalPrice = $statPerMonth["total_price"];
$fileContent = $fileContent. $fileContent = $fileContent.
utf8_decode(html_entity_decode($statPerMonth['client_name'])).';'. FileExportHelpers::FormatTextForExport($statPerMonth['client_name']).';'.
utf8_decode(html_entity_decode("$month")).';'. "$month".';'.
utf8_decode(html_entity_decode("$yearValue")).';'. "$yearValue".';'.
utf8_decode(html_entity_decode("$defuntCount")).';'. "$defuntCount".';';
utf8_decode(html_entity_decode("$productCount")).';'.
utf8_decode(html_entity_decode("$totalPrice")).';'."\n";
foreach($products as $productCount){
$fileContent .= "$productCount".";";
}
$fileContent .= "\n";
return $fileContent; return $fileContent;
} }

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCA\Gestion\Service; namespace OCA\Gestion\Service;
use OCA\Gestion\Db\Bdd; use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\FileExportHelpers;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class ExportThanatoStatisticService { class ExportThanatoStatisticService {
@ -59,18 +60,18 @@ class ExportThanatoStatisticService {
public function getExportThanatoFileHeader(): string{ public function getExportThanatoFileHeader(): string{
$fileHeader = $fileHeader =
'Facture'.';'. 'FACTURE'.';'.
'Thanatopracteur'.';'. 'THANATOPRACTEUR'.';'.
'Date'.';'. 'DATE'.';'.
utf8_decode(html_entity_decode('Heure de début')).';'. 'HEURE DE DEBUT'.';'.
'Heure de fin'.';'. 'HEURE DE FIN'.';'.
'Soins'.';'. 'SOINS'.';'.
utf8_decode(html_entity_decode('Jour/Férié')).';'. 'JOUR/FERIE'.';'.
utf8_decode(html_entity_decode('Nom et Prénom')).';'. 'NOM ET PRENOM'.';'.
'Lieu'.';'. 'LIEU'.';'.
utf8_decode(html_entity_decode('Pompe funèbre')).';'. 'POMPES FUNEBRES'.';'.
utf8_decode(html_entity_decode('Pompe funèbre adresse')).';'. 'ADRESSE'.';'.
'Distance Totale (km)'.';'. 'DISTANCE TOTALE KM'.';'.
"\n"; "\n";
return $fileHeader; return $fileHeader;
} }
@ -121,17 +122,17 @@ class ExportThanatoStatisticService {
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){ private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]); $produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
$fileContent = $fileContent. $fileContent = $fileContent.
utf8_decode(html_entity_decode($devis["facture_num"])).';'. FileExportHelpers::FormatTextForExport($devis["facture_num"]).';'.
utf8_decode(html_entity_decode($devis['nom_thanato'] . ' ' . $devis['prenom_thanatho'])).';'. FileExportHelpers::FormatTextForExport($devis['nom_thanato'] . ' ' . $devis['prenom_thanatho']).';'.
utf8_decode(html_entity_decode($devis["date"])).';'. FileExportHelpers::FormatTextForExport($devis["date"]).';'.
utf8_decode(html_entity_decode($devis["startTime"])).';'. FileExportHelpers::FormatTextForExport($devis["startTime"]).';'.
utf8_decode(html_entity_decode($devis["endTime"])).';'. FileExportHelpers::FormatTextForExport($devis["endTime"]).';'.
utf8_decode(html_entity_decode($produitAsString)).';'. FileExportHelpers::FormatTextForExport($produitAsString).';'.
utf8_decode(html_entity_decode($devis["dayType"])).';'. FileExportHelpers::FormatTextForExport($devis["dayType"]).';'.
utf8_decode(html_entity_decode($devis["nom_defunt"])).';'. FileExportHelpers::FormatTextForExport($devis["nom_defunt"]).';'.
utf8_decode(html_entity_decode($devis["nom_lieu"] ?? "")).';'. FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
utf8_decode(html_entity_decode($devis["nom_client"] ?? "")).';'. FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
utf8_decode(html_entity_decode($devis["client_adresse"] ?? ""))."\n"; FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "")."\n";
return $fileContent; return $fileContent;