finish export thanato statistiic on backend

This commit is contained in:
Tiavina 2024-12-26 08:29:21 +03:00
parent 1a37d63b55
commit 82da31c2e5
3 changed files with 119 additions and 52 deletions

View File

@ -17,6 +17,7 @@ use \Datetime;
use \DatetimeImmutable;
use \IntlDateFormatter;
use \FPDF;
use OCA\Gestion\Service\ExportThanatoStatisticService;
use Ramsey\Uuid\Uuid;
date_default_timezone_set('Europe/Paris');
@ -36,6 +37,9 @@ class PageController extends Controller {
private $user;
private $groups = [];
/** @var ExportThanatoStatisticService */
private $exportThanatoStatisticService;
/**
* Constructor
*/
@ -48,7 +52,8 @@ class PageController extends Controller {
IMailer $mailer,
Iconfig $config,
IUserSession $userSession,
IGroupManager $groupManager){
IGroupManager $groupManager,
ExportThanatoStatisticService $exportThanatoStatisticService) {
parent::__construct($AppName, $request);
@ -57,6 +62,7 @@ class PageController extends Controller {
$this->urlGenerator = $urlGenerator;
$this->mailer = $mailer;
$this->config = $config;
$this->exportThanatoStatisticService = $exportThanatoStatisticService;
//$this->fpdf = $fpdf;
if ($userSession->isLoggedIn()) {
@ -2545,39 +2551,18 @@ class PageController extends Controller {
if(empty($exportData)){
return null;
}
die;
try{
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
$clean_folder = html_entity_decode($current_config[0]->path).'/';
$_clean_folder = $clean_folder.'STATISTIQUES/';
try {
$this->storage->newFolder($_clean_folder);
} catch(\OCP\Files\NotPermittedException $e) { }
}
catch(\OCP\Files\NotPermittedException $e) {
$fileContent =
'Thanatopracteur'.';'.
'Date'.';'.
'Nom et Prenoms'.';'.
'Lieu'.';'.
'Pompe funebre'.';'.
'Pompe funebre adresse'.';'.
'Distance Total (km)'.';'.
"\n";
foreach($exportData as $thanatoId => $devisPerThanato){
foreach($devisPerThanato as $devisDate => $devisData){
$distanceTotal = $devisData["total_distance"];
$devisList = $devisData["devis"];
if(!empty($devisList)){
foreach($devisList as $devis){
$fileContent = $this->populateDevisDataIntoThanatoExportFileContent($fileContent,$devis);
}
$fileContent = $this->populateDistanceTotalIntoThanatoExportFileContent($fileContent,$distanceTotal);
}
}
}
$fileHeader = $this->exportThanatoStatisticService->getExportThanatoFileHeader();
$fileContent = $this->exportThanatoStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
$thanatoIdsString = implode('-', $thanatoIdsToExport);
$uuid = Uuid::uuid4()->toString();
$fileNamePath = $_clean_folder."STAT-ThanatoIds-" . $thanatoIdsString . '-' . $uuid . '.csv';
@ -2589,29 +2574,4 @@ class PageController extends Controller {
catch(\OCP\Files\NotFoundException $e) { }
}
private function populateDistanceTotalIntoThanatoExportFileContent(string $fileContent,$distance){
$fileContent = $fileContent.
''.';'.
''.';'.
''.';'.
''.';'.
''.';'.
''.';'.
utf8_decode(html_entity_decode($distance))."\n";
return $fileContent;
}
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){
$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["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_entreprise"]))."\n";
return $fileContent;
}
}

View File

@ -1742,14 +1742,22 @@ class Bdd {
if (!isset($devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate])) {
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate] = [
'total_distance' => 0,
"devis" => []
"devis" => [],
"devisId" => []
];
}
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate]["devis"][] = $devis;
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate]["devisId"][] = $devis['id'];
}
return $devisListGroupedByDateAndThenByThanato;
}
public function getDistanceTotalByDevisIdList(array $devisIdList){
$ligneTrajetList = $this->getLigneTrajetsByDevisIdList($devisIdList);
$distanceTotal = $this->getLigneTrajetsListDistance($ligneTrajetList);
return $distanceTotal;
}
private function getLigneTrajetsListDistance(array $ligneTrajetList){
$distanceCumul = 0;
$last_point = NULL;

View File

@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Gestion\Service;
use OCA\Gestion\Db\Bdd;
use Psr\Log\LoggerInterface;
class ExportThanatoStatisticService {
/** @var Bdd */
private $gestionBdd;
/** @var LoggerInterface */
private $logger;
public function __construct(
Bdd $gestionBdd,
LoggerInterface $logger) {
$this->logger = $logger;
$this->gestionBdd = $gestionBdd;
}
public function getExportThanatoFileHeader(): string{
$fileHeader =
'Thanatopracteur'.';'.
'Date'.';'.
'Nom et Prenoms'.';'.
'Lieu'.';'.
'Pompe funebre'.';'.
'Pompe funebre adresse'.';'.
'Distance Total (km)'.';'.
"\n";
return $fileHeader;
}
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
foreach($exportData as $thanatoId => $devisPerThanato){
foreach($devisPerThanato as $devisDate => $devisData){
$distanceTotal = $this->gestionBdd->getDistanceTotalByDevisIdList($devisData["devisId"]);
$devisList = $devisData["devis"];
if(!empty($devisList)){
foreach($devisList as $devis){
$fileContent = $this->populateDevisDataIntoThanatoExportFileContent($fileContent,$devis);
}
$fileContent = $this->populateDistanceTotalIntoThanatoExportFileContent($fileContent,$distanceTotal);
}
}
}
return $fileContent;
}
private function populateDistanceTotalIntoThanatoExportFileContent(string $fileContent,$distance){
$fileContent = $fileContent.
''.';'.
''.';'.
''.';'.
''.';'.
''.';'.
''.';'.
utf8_decode(html_entity_decode("$distance"))."\n";
return $fileContent;
}
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){
$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["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_entreprise"] ?? ""))."\n";
return $fileContent;
}
}