finish api to export thanato statistique, WIP add distance km to csv , develop frontend
This commit is contained in:
parent
bee89b8111
commit
1a37d63b55
@ -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,7 @@ use \Datetime;
|
||||
use \DatetimeImmutable;
|
||||
use \IntlDateFormatter;
|
||||
use \FPDF;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
@ -2527,4 +2528,90 @@ class PageController extends Controller {
|
||||
return $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @param array $thanatoIdsToExport
|
||||
*
|
||||
*/
|
||||
|
||||
public function exportThanatoStatistic($thanatoIdsToExport){
|
||||
if(empty($thanatoIdsToExport)){
|
||||
return null;
|
||||
}
|
||||
$exportData = $this->myDb->getExportThanatoStatisticData($thanatoIdsToExport);
|
||||
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) { }
|
||||
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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) { }
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1725,4 +1725,106 @@ 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" => []
|
||||
];
|
||||
}
|
||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate]["devis"][] = $devis;
|
||||
}
|
||||
return $devisListGroupedByDateAndThenByThanato;
|
||||
}
|
||||
|
||||
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($ligneTrajetList[$i]['lieu'] =="Antsahavola"){
|
||||
var_dump($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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 + '/exportThanatoDataThisMonth',
|
||||
// type: 'POST',
|
||||
// contentType: 'application/json',
|
||||
// data: JSON.stringify(exportThanatoPayload)
|
||||
// }).done(function (response) {
|
||||
// let datatable = new DataTable('.tabledt');
|
||||
// Devis.loadDevisDT(datatable);
|
||||
// showSuccess(t('gestion', "Devis exported to facture"));
|
||||
// }).fail(function (response, code) {
|
||||
// showError(t('gestion', "Please select devis to facture"));
|
||||
// });
|
||||
|
||||
|
||||
});
|
||||
@ -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