Merge branch 'features/feature-export-thanato-stat' into staging
This commit is contained in:
commit
3042362ea6
@ -29,6 +29,7 @@ return [
|
||||
|
||||
['name' => 'page#getThanatopracteurs', 'url' => '/getThanatopracteurs', 'verb' => 'PROPFIND'],
|
||||
['name' => 'page#insertThanatopracteur', 'url' => '/thanatopracteur/insert', 'verb' => 'POST'],
|
||||
['name' => 'page#exportThanatoStatistic', 'url' => '/thanatopracteur/exportThanatoStatistic', 'verb' => 'POST'],
|
||||
|
||||
['name' => 'page#getDevis', 'url' => '/getDevis', 'verb' => 'PROPFIND'],
|
||||
['name' => 'page#getDevisDelphine', 'url' => '/getDevisDelphine/{idtrajetdetails}', 'verb' => 'PROPFIND'],
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -17,6 +17,8 @@ use \Datetime;
|
||||
use \DatetimeImmutable;
|
||||
use \IntlDateFormatter;
|
||||
use \FPDF;
|
||||
use OCA\Gestion\Service\ExportThanatoStatisticService;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
@ -35,6 +37,9 @@ class PageController extends Controller {
|
||||
private $user;
|
||||
private $groups = [];
|
||||
|
||||
/** @var ExportThanatoStatisticService */
|
||||
private $exportThanatoStatisticService;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@ -47,7 +52,8 @@ class PageController extends Controller {
|
||||
IMailer $mailer,
|
||||
Iconfig $config,
|
||||
IUserSession $userSession,
|
||||
IGroupManager $groupManager){
|
||||
IGroupManager $groupManager,
|
||||
ExportThanatoStatisticService $exportThanatoStatisticService) {
|
||||
|
||||
parent::__construct($AppName, $request);
|
||||
|
||||
@ -56,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()) {
|
||||
@ -2527,4 +2534,44 @@ class PageController extends Controller {
|
||||
return $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @param array $thanatoIdsToExport
|
||||
*
|
||||
*/
|
||||
|
||||
public function exportThanatoStatistic($thanatoIdsToExport){
|
||||
if(empty($thanatoIdsToExport)){
|
||||
return "";
|
||||
}
|
||||
$exportData = $this->myDb->getExportThanatoStatisticData($thanatoIdsToExport);
|
||||
if(empty($exportData)){
|
||||
return "";
|
||||
}
|
||||
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) {
|
||||
|
||||
}
|
||||
$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';
|
||||
$this->storage->newFile($fileNamePath);
|
||||
$file = $this->storage->get($fileNamePath);
|
||||
$file->putContent($fileContent);
|
||||
return $fileNamePath;
|
||||
}
|
||||
catch(\OCP\Files\NotFoundException $e) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1725,4 +1725,111 @@ class Bdd {
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getExportThanatoStatisticData(array $thanatoIds){
|
||||
$devisList = $this->getDevisListByThanatoIds($thanatoIds);
|
||||
$devisListGroupedByDateAndThenByThanato = $this->getDevisListGroupedByDateAndThenByThanato($devisList);
|
||||
return $devisListGroupedByDateAndThenByThanato;
|
||||
}
|
||||
|
||||
private function getDevisListGroupedByDateAndThenByThanato(array $devisList){
|
||||
$devisListGroupedByDateAndThenByThanato = [];
|
||||
foreach($devisList as $devis){
|
||||
$devisDate = $devis["date"];
|
||||
$devisThanatoId = $devis["id_thanato"];
|
||||
if (!isset($devisListGroupedByDateAndThenByThanato[$devisThanatoId])) {
|
||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId] = [];
|
||||
}
|
||||
if (!isset($devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate])) {
|
||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate] = [
|
||||
'total_distance' => 0,
|
||||
"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;
|
||||
for ($i=0; $i < sizeof($ligneTrajetList); $i++) {
|
||||
$currentDistance = 0;
|
||||
if($ligneTrajetList[$i]['lieu_id'] != NULL){
|
||||
$last_point = $ligneTrajetList[$i];
|
||||
}
|
||||
if($last_point['lieu_id'] != NULL && $ligneTrajetList[$i+1]['lieu_id'] != NULL){
|
||||
$currentDistance = $this->calcul_distance(
|
||||
floatval(value: $last_point['latitude']),
|
||||
floatval($last_point['longitude']),
|
||||
floatval($ligneTrajetList[$i+1]['latitude']),
|
||||
floatval($ligneTrajetList[$i+1]['longitude'])
|
||||
);
|
||||
}
|
||||
$distanceCumul += $currentDistance;
|
||||
}
|
||||
return $distanceCumul;
|
||||
}
|
||||
|
||||
private function getLigneTrajetsByDevisIdList(array $devisIdList){
|
||||
if(empty($devisIdList)){
|
||||
return [];
|
||||
}
|
||||
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisIdList), '?'));
|
||||
$sql = "SELECT ligne_trajet.id, ligne_trajet.rang, ligne_trajet.id_nextcloud, ligne_trajet.date, ligne_trajet.user_id, ligne_trajet.commentaire, ligne_trajet.source,
|
||||
lieu.id as lieu_id, lieu.nom as lieu, lieu.latitude as latitude, lieu.longitude as longitude
|
||||
FROM (".$this->tableprefix."ligne_trajet as ligne_trajet
|
||||
LEFT JOIN ".$this->tableprefix."lieu as lieu on ligne_trajet.id_lieu = lieu.id)
|
||||
WHERE ligne_trajet.id_devis IN ($sqlConditionsPlaceholder)
|
||||
ORDER BY ligne_trajet.date ASC, ligne_trajet.rang ASC;";
|
||||
return $this->execSQLNoJsonReturn($sql, $devisIdList);
|
||||
}
|
||||
|
||||
private function getDevisListByThanatoIds(array $thanatoIds){
|
||||
if(empty($thanatoIds)){
|
||||
return [];
|
||||
}
|
||||
$currentYear = date('Y');
|
||||
$currentMonth = date('m');
|
||||
|
||||
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($thanatoIds), '?'));
|
||||
$sql = "SELECT
|
||||
devis.id,
|
||||
devis.date,
|
||||
devis.mentions,
|
||||
devis.id_defunt as id_defunt,
|
||||
devis.id_lieu as id_lieu,
|
||||
devis.id_client as id_client,
|
||||
devis.id_thanato as id_thanato,
|
||||
thanato.nom as nom_thanato,
|
||||
thanato.prenom as prenom_thanato,
|
||||
defunt.nom as nom_defunt,
|
||||
lieu.nom as nom_lieu,
|
||||
lieu.latitude as lieu_latitude,
|
||||
lieu.longitude as lieu_longitude,
|
||||
client.nom as nom_client,
|
||||
client.entreprise as client_entreprise
|
||||
FROM ".$this->tableprefix."devis as devis
|
||||
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
||||
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
||||
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
|
||||
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
|
||||
WHERE YEAR(devis.date) = ? AND
|
||||
MONTH(devis.date) = ? AND
|
||||
devis.id_thanato IN ($sqlConditionsPlaceholder)
|
||||
ORDER BY devis.date ASC;";
|
||||
$devisList = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
array_merge([$currentYear, $currentMonth],$thanatoIds));
|
||||
return $devisList;
|
||||
}
|
||||
|
||||
}
|
||||
99
gestion/lib/Service/ExportThanatoStatisticService.php
Normal file
99
gestion/lib/Service/ExportThanatoStatisticService.php
Normal 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;
|
||||
|
||||
}
|
||||
}
|
||||
@ -416,4 +416,37 @@ $('body').on('click', '#exportDevisToFacture', function () {
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
$('body').on('click', '#exportThanatoData', function () {
|
||||
var oTable = $('.tabledt').dataTable();
|
||||
var rowcollection = oTable.$(".thanatoToExport:checked", {"page": "all"});
|
||||
let thanatoIdsToExport = [];
|
||||
rowcollection.each(function(index,elem){
|
||||
var checkbox_value = $(elem).val();
|
||||
thanatoIdsToExport.push(checkbox_value);
|
||||
});
|
||||
|
||||
if(thanatoIdsToExport.length == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
let exportThanatoPayload = {
|
||||
thanatoIdsToExport: thanatoIdsToExport
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/thanatopracteur/exportThanatoStatistic',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(exportThanatoPayload)
|
||||
}).done(function (response) {
|
||||
let datatable = new DataTable('.tabledt');
|
||||
Thanatopracteur.loadThanatoDT(datatable);
|
||||
showSuccess(t('gestion', "Statistic exported : " + response));
|
||||
}).fail(function (response, code) {
|
||||
showError(t('gestion', "Please select thanato to export"));
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@ -20,6 +20,7 @@ export class Thanatopracteur {
|
||||
*/
|
||||
getDTRow() {
|
||||
let myrow = [
|
||||
'<input class="thanatoToExport" data-id= '+ this.id + ' type="checkbox" name="thanatoToExport" value="' + this.id + '"/>',
|
||||
'<div class="editable" data-table="thanato" data-column="prenom" data-id="' + this.id + '">' + this.prenom + '</div>',
|
||||
'<div class="editable" data-table="thanato" data-column="nom" data-id="' + this.id + '">' + this.nom + '</div>',
|
||||
'<div class="editable" data-table="thanato" data-column="reference" data-id="' + this.id + '">' + this.reference + '</div>',
|
||||
|
||||
@ -13,9 +13,13 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex jsutify-content-end">
|
||||
<button class="btn btn-secondary" id="exportThanatoData">Export thanato data</button>
|
||||
</div>
|
||||
<table id="client" class="display tabledt" style="font-size:11px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php p($l->t('To Export'));?></th>
|
||||
<th><?php p($l->t('First name'));?></th>
|
||||
<th><?php p($l->t('Last name'));?></th>
|
||||
<th>Référence</th>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user