* * @author Anna Larch * @author Richard Steinmetz * * 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 . * */ namespace OCA\Gestion\Service; use OCA\Gestion\Db\Bdd; use Psr\Log\LoggerInterface; class ExportClientStatisticService { /** @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 $clientIds){ $filename = ""; $clients = $this->gestionBdd->getClientsByClientsID($clientIds); foreach($clients as $client){ $filename .= $client['client_nom'] . '-' . $client['client_entreprise'] . '--'; } $filename = rtrim($filename, '-'); return $filename; } public function getExportClientFileHeader(): string{ $fileHeader = 'Client'.';'. 'Mois'.';'. 'Année'.';'. 'Nb defunts'.';'. 'Nb articles'.';'. 'Total HT'.';'. "\n"; return $fileHeader; } public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{ foreach($exportData as $clientId => $clientData){ $clientName = $clientData["client_name"]; $clientStatPerMonth = $clientData["client_data"]; $totalPrice = 0; if(!empty($clientStatPerMonth)){ foreach($clientStatPerMonth as $month => $stat){ $stat["client_name"] = $clientName; $totalPrice+=$stat["total_price"]; $fileContent = $this->populateClientStatDataIntoFileContent($fileContent,$month,$stat); } $fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice); } } return $fileContent; } private function populateTotalPriceIntoFileContent(string $fileContent,$price){ $fileContent = $fileContent. ''.';'. ''.';'. ''.';'. ''.';'. ''.';'. utf8_decode(html_entity_decode("$price"))."\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"]; $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"; return $fileContent; } }