138 lines
4.3 KiB
PHP
138 lines
4.3 KiB
PHP
<?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 OCA\Gestion\Helpers\FileExportHelpers;
|
|
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 getFilename(array $thanatoIds){
|
|
$thanatoList = $this->gestionBdd->getThanatoByIds($thanatoIds);
|
|
$currentYear = date('Y');
|
|
$currentMonth = date('m');
|
|
$filename = "$currentYear-$currentMonth-";
|
|
foreach($thanatoList as $thanato){
|
|
$filename .= $thanato['thanato_nom'] . '-' . $thanato['thanato_prenom'] . '--';
|
|
}
|
|
$filename = rtrim($filename, '-');
|
|
$filename = str_replace(' ','-', $filename);
|
|
$filename = str_replace(' ','-', $filename);
|
|
return $filename;
|
|
}
|
|
|
|
public function getExportThanatoFileHeader(): string{
|
|
$fileHeader =
|
|
'THANATOPRACTEUR'.';'.
|
|
'DATE'.';'.
|
|
'HEURE DE DEBUT'.';'.
|
|
'HEURE DE FIN'.';'.
|
|
'SOINS'.';'.
|
|
'JOUR/FERIE'.';'.
|
|
'NOM ET PRENOM'.';'.
|
|
'LIEU'.';'.
|
|
'POMPES FUNEBRES'.';'.
|
|
'ADRESSE'.';'.
|
|
'DISTANCE TOTALE 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 getFormatDevisProduitsAsString($devisProduits){
|
|
$result = '';
|
|
foreach ($devisProduits as $produit) {
|
|
$result .= $produit['produit_reference'] . '-' . $produit['produit_description'] . '--';
|
|
}
|
|
// Remove the trailing "--" at the end
|
|
$result = rtrim($result, '-');
|
|
return $result;
|
|
}
|
|
|
|
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){
|
|
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
|
$fileContent = $fileContent.
|
|
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;
|
|
|
|
}
|
|
}
|