fix export thanato header, add articles on export client

This commit is contained in:
Tiavina 2024-12-31 00:27:28 +03:00
parent 30e5c7852a
commit 1a254879d9
5 changed files with 97 additions and 90 deletions

View File

@ -2618,7 +2618,7 @@ class PageController extends Controller {
catch(\OCP\Files\NotPermittedException $e) { catch(\OCP\Files\NotPermittedException $e) {
} }
$fileHeader = $this->exportClientStatisticService->getExportClientFileHeader($exportData); $fileHeader = $this->exportClientStatisticService->getExportClientFileHeader();
$fileContent = $this->exportClientStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader); $fileContent = $this->exportClientStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
$fileName = $this->exportClientStatisticService->getFileName($clientIdsToExport); $fileName = $this->exportClientStatisticService->getFileName($clientIdsToExport);
$fileNamePath = $_clean_folder."STAT-CLIENTS-" . $fileName .'.csv'; $fileNamePath = $_clean_folder."STAT-CLIENTS-" . $fileName .'.csv';

View File

@ -1981,31 +1981,6 @@ class Bdd {
return null; return null;
} }
private function getDevisProduitByDevisAndProduit($devisId,$produitId){
$sql = "SELECT
produit_devis.id,
produit_devis.produit_id,
produit_devis.quantite,
produit_devis.discount,
produit.prix_unitaire as produit_price,
produit.reference as produit_reference,
produit.description as produit_description,
produit.vat as produit_vat
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 = ? AND
produit.id = ?;";
$produitList = $this->execSQLNoJsonReturn(
$sql,
[$devisId,$produitId]);
if(!empty($produitList)){
return $produitList[0];
}
return null;
}
private function getDevisProduits($devisId){ private function getDevisProduits($devisId){
$sql = "SELECT $sql = "SELECT
produit_devis.id, produit_devis.id,
@ -2027,13 +2002,25 @@ class Bdd {
return $produitList; return $produitList;
} }
private function getProduitsDevisStatistic($devisId,$produitId){ private function getDevisProductsQuantityByDevisListAndProductId($devisList,$productId){
$produitQuantity = 0; if(empty($devisList)){
$devisProduit = $this->getDevisProduitByDevisAndProduit($devisId,$produitId); return 0;
if($devisProduit){
$produitQuantity = $devisProduit["quantite"];
} }
return $produitQuantity; $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;
} }
private function getClientFactureStatisticPerMonth($clientId,array $produitList){ private function getClientFactureStatisticPerMonth($clientId,array $produitList){
@ -2061,26 +2048,28 @@ class Bdd {
$sql, $sql,
[$currentYear,$monthValue,$clientId]); [$currentYear,$monthValue,$clientId]);
$defuntCount = count($factureList); $factureDevisIds = [];
$produitsCount = 0;
$produitsPrice = 0;
$statisticForeachProduct = [];
foreach($factureList as $facture){ foreach($factureList as $facture){
foreach($produitList as $produit){ $factureDevisIds[] = $facture['devis_id'];
$devisProduitStat = $this->getProduitsDevisStatistic($facture["devis_id"],$produit['id']); }
if(!isset($statisticForeachProduct[$produit['reference']])){
$statisticForeachProduct[$produit['reference']] = []; $defuntCount = count($factureList);
} $produitsPrice = 0;
$statisticForeachProduct[$produit['reference']] $statisticForeachProductPerMonth = [];
foreach($produitList as $produit){
if(!isset($statisticForeachProductPerMonth[$produit['id']])){
$statisticForeachProductPerMonth[$produit['id']] = 0;
} }
$produitsCount+= $devisProduitStat["count"]; $productTotalCount = $this->getDevisProductsQuantityByDevisListAndProductId($factureDevisIds,$produit['id']);
$produitsPrice+= $devisProduitStat["total_price"]; $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;

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 {
@ -55,20 +56,18 @@ class ExportClientStatisticService {
return $filename; return $filename;
} }
public function getExportClientFileHeader($exportData): 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(); $produitList = $this->gestionBdd->getProduitsListAsArray();
foreach($produitList as $produit){ foreach($produitList as $produit){
$fileHeader .= $produit['reference'].';'; $fileHeader .= FileExportHelpers::FormatTextForExport($produit['reference']).';';
} }
$fileHeader .= "\n"; $fileHeader .= 'TOTAL HT'.';'."\n";
return $fileHeader; return $fileHeader;
} }
@ -83,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,17 +60,17 @@ class ExportThanatoStatisticService {
public function getExportThanatoFileHeader(): string{ public function getExportThanatoFileHeader(): string{
$fileHeader = $fileHeader =
'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;
} }
@ -119,16 +120,16 @@ 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['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;