fix export thanato header, add articles on export client
This commit is contained in:
parent
30e5c7852a
commit
1a254879d9
@ -2618,7 +2618,7 @@ class PageController extends Controller {
|
||||
catch(\OCP\Files\NotPermittedException $e) {
|
||||
|
||||
}
|
||||
$fileHeader = $this->exportClientStatisticService->getExportClientFileHeader($exportData);
|
||||
$fileHeader = $this->exportClientStatisticService->getExportClientFileHeader();
|
||||
$fileContent = $this->exportClientStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
|
||||
$fileName = $this->exportClientStatisticService->getFileName($clientIdsToExport);
|
||||
$fileNamePath = $_clean_folder."STAT-CLIENTS-" . $fileName .'.csv';
|
||||
|
||||
@ -1981,31 +1981,6 @@ class Bdd {
|
||||
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){
|
||||
$sql = "SELECT
|
||||
produit_devis.id,
|
||||
@ -2027,13 +2002,25 @@ class Bdd {
|
||||
return $produitList;
|
||||
}
|
||||
|
||||
private function getProduitsDevisStatistic($devisId,$produitId){
|
||||
$produitQuantity = 0;
|
||||
$devisProduit = $this->getDevisProduitByDevisAndProduit($devisId,$produitId);
|
||||
if($devisProduit){
|
||||
$produitQuantity = $devisProduit["quantite"];
|
||||
private function getDevisProductsQuantityByDevisListAndProductId($devisList,$productId){
|
||||
if(empty($devisList)){
|
||||
return 0;
|
||||
}
|
||||
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){
|
||||
@ -2061,26 +2048,28 @@ class Bdd {
|
||||
$sql,
|
||||
[$currentYear,$monthValue,$clientId]);
|
||||
|
||||
$defuntCount = count($factureList);
|
||||
$produitsCount = 0;
|
||||
$produitsPrice = 0;
|
||||
$statisticForeachProduct = [];
|
||||
$factureDevisIds = [];
|
||||
foreach($factureList as $facture){
|
||||
$factureDevisIds[] = $facture['devis_id'];
|
||||
}
|
||||
|
||||
$defuntCount = count($factureList);
|
||||
$produitsPrice = 0;
|
||||
$statisticForeachProductPerMonth = [];
|
||||
foreach($produitList as $produit){
|
||||
$devisProduitStat = $this->getProduitsDevisStatistic($facture["devis_id"],$produit['id']);
|
||||
if(!isset($statisticForeachProduct[$produit['reference']])){
|
||||
$statisticForeachProduct[$produit['reference']] = [];
|
||||
if(!isset($statisticForeachProductPerMonth[$produit['id']])){
|
||||
$statisticForeachProductPerMonth[$produit['id']] = 0;
|
||||
}
|
||||
$statisticForeachProduct[$produit['reference']]
|
||||
}
|
||||
$produitsCount+= $devisProduitStat["count"];
|
||||
$produitsPrice+= $devisProduitStat["total_price"];
|
||||
$productTotalCount = $this->getDevisProductsQuantityByDevisListAndProductId($factureDevisIds,$produit['id']);
|
||||
$totalWithoutVat = $productTotalCount * $produit["prix_unitaire"];
|
||||
$statisticForeachProductPerMonth[$produit['id']] += $productTotalCount;
|
||||
$produitsPrice += $totalWithoutVat;
|
||||
}
|
||||
$data[$monthValue] = [
|
||||
"defunt_count" => $defuntCount,
|
||||
"produit_count" => $produitsCount,
|
||||
"total_price" => $produitsPrice,
|
||||
"year" => $currentYear
|
||||
"year" => $currentYear,
|
||||
"products" => $statisticForeachProductPerMonth
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
|
||||
14
gestion/lib/Helpers/FileExportHelpers.php
Normal file
14
gestion/lib/Helpers/FileExportHelpers.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,6 +27,7 @@ declare(strict_types=1);
|
||||
namespace OCA\Gestion\Service;
|
||||
|
||||
use OCA\Gestion\Db\Bdd;
|
||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ExportClientStatisticService {
|
||||
@ -55,20 +56,18 @@ class ExportClientStatisticService {
|
||||
return $filename;
|
||||
}
|
||||
|
||||
public function getExportClientFileHeader($exportData): string{
|
||||
public function getExportClientFileHeader(): string{
|
||||
$fileHeader =
|
||||
'Client'.';'.
|
||||
'Mois'.';'.
|
||||
utf8_decode(html_entity_decode('Année')).';'.
|
||||
utf8_decode(html_entity_decode('Nb défunts')).';'.
|
||||
'Nb articles'.';'.
|
||||
'Total HT'.';';
|
||||
'CLIENT'.';'.
|
||||
'MOIS'.';'.
|
||||
'ANNEE'.';'.
|
||||
'NB DE DEFUNTS'.';';
|
||||
|
||||
$produitList = $this->gestionBdd->getProduitsListAsArray();
|
||||
foreach($produitList as $produit){
|
||||
$fileHeader .= $produit['reference'].';';
|
||||
$fileHeader .= FileExportHelpers::FormatTextForExport($produit['reference']).';';
|
||||
}
|
||||
$fileHeader .= "\n";
|
||||
$fileHeader .= 'TOTAL HT'.';'."\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
|
||||
@ -83,37 +82,41 @@ class ExportClientStatisticService {
|
||||
$totalPrice+=$stat["total_price"];
|
||||
$fileContent = $this->populateClientStatDataIntoFileContent($fileContent,$month,$stat);
|
||||
}
|
||||
$fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice);
|
||||
$fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice,count($stat["products"]));
|
||||
}
|
||||
}
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function populateTotalPriceIntoFileContent(string $fileContent,$price){
|
||||
private function populateTotalPriceIntoFileContent(string $fileContent,$totalPrice,$productsCount){
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
utf8_decode(html_entity_decode("$price"))."\n";
|
||||
''.';';
|
||||
while($productsCount > 0){
|
||||
$fileContent .= ''.';';
|
||||
$productsCount--;
|
||||
}
|
||||
$fileContent .= "$totalPrice".";"."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function populateClientStatDataIntoFileContent(string $fileContent,$month,array $statPerMonth){
|
||||
$yearValue = $statPerMonth["year"];
|
||||
$defuntCount = $statPerMonth["defunt_count"];
|
||||
$productCount = $statPerMonth["produit_count"];
|
||||
$totalPrice = $statPerMonth["total_price"];
|
||||
$products = $statPerMonth["products"];
|
||||
|
||||
$fileContent = $fileContent.
|
||||
utf8_decode(html_entity_decode($statPerMonth['client_name'])).';'.
|
||||
utf8_decode(html_entity_decode("$month")).';'.
|
||||
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";
|
||||
FileExportHelpers::FormatTextForExport($statPerMonth['client_name']).';'.
|
||||
"$month".';'.
|
||||
"$yearValue".';'.
|
||||
"$defuntCount".';';
|
||||
|
||||
foreach($products as $productCount){
|
||||
$fileContent .= "$productCount".";";
|
||||
}
|
||||
$fileContent .= "\n";
|
||||
return $fileContent;
|
||||
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ declare(strict_types=1);
|
||||
namespace OCA\Gestion\Service;
|
||||
|
||||
use OCA\Gestion\Db\Bdd;
|
||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ExportThanatoStatisticService {
|
||||
@ -59,17 +60,17 @@ class ExportThanatoStatisticService {
|
||||
|
||||
public function getExportThanatoFileHeader(): string{
|
||||
$fileHeader =
|
||||
'Thanatopracteur'.';'.
|
||||
'Date'.';'.
|
||||
utf8_decode(html_entity_decode('Heure de début')).';'.
|
||||
'Heure de fin'.';'.
|
||||
'Soins'.';'.
|
||||
utf8_decode(html_entity_decode('Jour/Férié')).';'.
|
||||
utf8_decode(html_entity_decode('Nom et Prénom')).';'.
|
||||
'Lieu'.';'.
|
||||
utf8_decode(html_entity_decode('Pompe funèbre')).';'.
|
||||
utf8_decode(html_entity_decode('Pompe funèbre adresse')).';'.
|
||||
'Distance Totale (km)'.';'.
|
||||
'THANATOPRACTEUR'.';'.
|
||||
'DATE'.';'.
|
||||
'HEURE DE DEBUT'.';'.
|
||||
'HEURE DE FIN'.';'.
|
||||
'SOINS'.';'.
|
||||
'JOUR/FERIE'.';'.
|
||||
'NOM ET PRENOM'.';'.
|
||||
'LIEU'.';'.
|
||||
'POMPES FUNEBRES'.';'.
|
||||
'ADRESSE'.';'.
|
||||
'DISTANCE TOTALE KM'.';'.
|
||||
"\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
@ -119,16 +120,16 @@ class ExportThanatoStatisticService {
|
||||
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){
|
||||
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
||||
$fileContent = $fileContent.
|
||||
utf8_decode(html_entity_decode($devis['nom_thanato'] . ' ' . $devis['prenom_thanatho'])).';'.
|
||||
utf8_decode(html_entity_decode($devis["date"])).';'.
|
||||
utf8_decode(html_entity_decode($devis["startTime"])).';'.
|
||||
utf8_decode(html_entity_decode($devis["endTime"])).';'.
|
||||
utf8_decode(html_entity_decode($produitAsString)).';'.
|
||||
utf8_decode(html_entity_decode($devis["dayType"])).';'.
|
||||
utf8_decode(html_entity_decode($devis["nom_defunt"])).';'.
|
||||
utf8_decode(html_entity_decode($devis["nom_lieu"] ?? "")).';'.
|
||||
utf8_decode(html_entity_decode($devis["nom_client"] ?? "")).';'.
|
||||
utf8_decode(html_entity_decode($devis["client_adresse"] ?? ""))."\n";
|
||||
FileExportHelpers::FormatTextForExport($devis['nom_thanato'] . ' ' . $devis['prenom_thanatho']).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["date"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["startTime"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["endTime"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($produitAsString).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["dayType"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_defunt"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "")."\n";
|
||||
|
||||
return $fileContent;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user