finish thanato stat , wip vehicule
This commit is contained in:
parent
9253a69ade
commit
26ab3baffb
File diff suppressed because one or more lines are too long
@ -2592,25 +2592,33 @@ class PageController extends Controller {
|
||||
if(empty($thanatoIdsToExport)){
|
||||
return "";
|
||||
}
|
||||
$exportData = $this->myDb->getExportThanatoStatisticData($thanatoIdsToExport);
|
||||
$month = $month ?? date('m');
|
||||
$year = $year ?? date('Y');
|
||||
$exportData = $this->myDb->getExportThanatoStatisticData($thanatoIdsToExport,$month,$year);
|
||||
try{
|
||||
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
||||
$clean_folder = html_entity_decode($current_config[0]->path).'/';
|
||||
$_clean_folder = $clean_folder.'STATISTIQUES/THANATOS/';
|
||||
try {
|
||||
$this->storage->newFolder($_clean_folder);
|
||||
}
|
||||
catch(\OCP\Files\NotPermittedException $e) {
|
||||
|
||||
}
|
||||
$thanatoList = $this->myDb->getThanatoByIds($thanatoIdsToExport);
|
||||
$thanatoFolders = $this->exportThanatoStatisticService->getThanatoStatisticFolders($thanatoList,$year);
|
||||
$fileHeader = $this->exportThanatoStatisticService->getExportThanatoFileHeader();
|
||||
$fileContent = $this->exportThanatoStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
|
||||
$filename = $this->exportThanatoStatisticService->getFilename($thanatoIdsToExport);
|
||||
$fileNamePath = $_clean_folder."STAT-THANATOS-" . $filename . '.csv';
|
||||
$this->storage->newFile($fileNamePath);
|
||||
$file = $this->storage->get($fileNamePath);
|
||||
$file->putContent($fileContent);
|
||||
return $fileNamePath;
|
||||
$filename = $this->exportThanatoStatisticService->getFilename($thanatoList,$month,$year);
|
||||
$filenames = [];
|
||||
foreach($thanatoFolders as $thanatoFolder){
|
||||
$fullPath = $clean_folder.$thanatoFolder;
|
||||
try {
|
||||
$this->storage->newFolder($fullPath);
|
||||
}
|
||||
catch(\OCP\Files\NotPermittedException $e) {
|
||||
|
||||
}
|
||||
$fileNamePath = $fullPath."STAT-THANATOS-" . $filename . '.csv';
|
||||
$this->storage->newFile($fileNamePath);
|
||||
$file = $this->storage->get($fileNamePath);
|
||||
$file->putContent($fileContent);
|
||||
$filenames[] = $fileNamePath;
|
||||
}
|
||||
return $filenames;
|
||||
}
|
||||
catch(\OCP\Files\NotFoundException $e) { }
|
||||
|
||||
|
||||
@ -1754,7 +1754,8 @@ class Bdd {
|
||||
$sql = "SELECT
|
||||
thanato.id,
|
||||
thanato.nom as thanato_nom,
|
||||
thanato.prenom as thanato_prenom
|
||||
thanato.prenom as thanato_prenom,
|
||||
thanato.fk_thanato_type_key as fk_thanato_type_key
|
||||
FROM ".$this->tableprefix."thanato as thanato
|
||||
WHERE thanato.id IN ($sqlConditionsPlaceholder)";
|
||||
$thanatoList = $this->execSQLNoJsonReturn(
|
||||
@ -2019,18 +2020,16 @@ class Bdd {
|
||||
$this->calculer_distance_trajet($ligne_trajet->id_trajet, $idNextcloud);
|
||||
}
|
||||
|
||||
public function getExportThanatoStatisticData(array $thanatoIds){
|
||||
$devisList = $this->getDevisListByThanatoIds($thanatoIds);
|
||||
public function getExportThanatoStatisticData(array $thanatoIds,$month,$year){
|
||||
$devisList = $this->getDevisListByThanatoIds($thanatoIds,$month,$year);
|
||||
$devisListGroupedByDateAndThenByThanato = $this->getDevisListGroupedByDateAndThenByThanato($devisList);
|
||||
return $devisListGroupedByDateAndThenByThanato;
|
||||
}
|
||||
|
||||
private function getDevisListByThanatoIds(array $thanatoIds){
|
||||
private function getDevisListByThanatoIds(array $thanatoIds,$month,$year){
|
||||
if(empty($thanatoIds)){
|
||||
return [];
|
||||
}
|
||||
$currentYear = date('Y');
|
||||
$currentMonth = date('m');
|
||||
|
||||
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($thanatoIds), '?'));
|
||||
$sql = "SELECT
|
||||
@ -2044,6 +2043,7 @@ class Bdd {
|
||||
devis.id_thanato as id_thanato,
|
||||
thanato.nom as nom_thanato,
|
||||
thanato.prenom as prenom_thanato,
|
||||
thanato.fk_thanato_type_key as fk_thanato_type_key,
|
||||
defunt.nom as nom_defunt,
|
||||
lieu.nom as nom_lieu,
|
||||
lieu.latitude as lieu_latitude,
|
||||
@ -2051,21 +2051,26 @@ class Bdd {
|
||||
client.nom as nom_client,
|
||||
client.entreprise as client_entreprise,
|
||||
client.adresse as client_adresse,
|
||||
facture.num as facture_num
|
||||
facture.num as facture_num,
|
||||
orders.id as order_id,
|
||||
orders.order_full_number,
|
||||
orders.fk_order_status_key,
|
||||
orders.fk_order_type_key
|
||||
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
|
||||
LEFT JOIN ".$this->tableprefix."facture as facture on devis.id = facture.id_devis
|
||||
LEFT JOIN ".$this->tableprefix."orders as orders on devis.id = orders.fk_devis_id
|
||||
WHERE YEAR(devis.date) = ? AND
|
||||
MONTH(devis.date) = ? AND
|
||||
devis.id_thanato IN ($sqlConditionsPlaceholder) AND
|
||||
devis.mentions = ?
|
||||
(devis.mentions = ? OR devis.mentions = ?)
|
||||
ORDER BY devis.date ASC;";
|
||||
$devisList = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
array_merge([$currentYear, $currentMonth],$thanatoIds,["facturé"]));
|
||||
array_merge([$year, $month],$thanatoIds,[DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED]));
|
||||
return $devisList;
|
||||
}
|
||||
|
||||
@ -2085,7 +2090,7 @@ class Bdd {
|
||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate] = [
|
||||
'total_distance' => 0,
|
||||
"devis" => [],
|
||||
"devisId" => []
|
||||
"devisId" => [],
|
||||
];
|
||||
}
|
||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate]["devis"][] = $devis;
|
||||
@ -2095,13 +2100,16 @@ class Bdd {
|
||||
}
|
||||
|
||||
private function setDevisProduitsList($devis){
|
||||
$produitsList = $this->getProduitsDevisByDevisId($devis['id']);
|
||||
$produitsList = $this->getDevisProduits($devis['id']);
|
||||
$totalPrice = 0;
|
||||
foreach($produitsList as $produit){
|
||||
if (!isset($devis['produits'])) {
|
||||
$devis['produits'] = [];
|
||||
}
|
||||
$devis['produits'][] = $produit;
|
||||
$totalPrice += $produit['produit_price'];
|
||||
}
|
||||
$devis['total_price'] = $totalPrice;
|
||||
return $devis;
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace OCA\Gestion\Service;
|
||||
|
||||
use OCA\Gestion\Constants\OrderTypeConstant;
|
||||
use OCA\Gestion\Constants\ThanatoTypeConstant;
|
||||
use OCA\Gestion\Db\Bdd;
|
||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -44,11 +46,19 @@ class ExportThanatoStatisticService {
|
||||
$this->gestionBdd = $gestionBdd;
|
||||
}
|
||||
|
||||
public function getFilename(array $thanatoIds){
|
||||
$thanatoList = $this->gestionBdd->getThanatoByIds($thanatoIds);
|
||||
$currentYear = date('Y');
|
||||
$currentMonth = date('m');
|
||||
$filename = "$currentYear-$currentMonth-";
|
||||
public function getThanatoStatisticFolders($thanatoList,$year){
|
||||
$thanatoStatFolders = ['STATISTIQUES/THANATOS/'];
|
||||
foreach($thanatoList as $thanato){
|
||||
if($thanato['fk_thanato_type_key'] == ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR){
|
||||
$thanatoStatFolders[] = 'STATISTIQUES/FOURNISSEURS/'.$year.'/';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $thanatoStatFolders;
|
||||
}
|
||||
|
||||
public function getFilename(array $thanatoList,$month,$year){
|
||||
$filename = "$year-$month-";
|
||||
foreach($thanatoList as $thanato){
|
||||
$filename .= $thanato['thanato_nom'] . '-' . $thanato['thanato_prenom'] . '--';
|
||||
}
|
||||
@ -71,6 +81,8 @@ class ExportThanatoStatisticService {
|
||||
'LIEU'.';'.
|
||||
'POMPES FUNEBRES'.';'.
|
||||
'ADRESSE'.';'.
|
||||
'BON DE COMMANDE'.';'.
|
||||
'TOTAL ACHAT'.';'.
|
||||
'DISTANCE TOTALE KM'.';'.
|
||||
"\n";
|
||||
return $fileHeader;
|
||||
@ -105,6 +117,8 @@ class ExportThanatoStatisticService {
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
utf8_decode(html_entity_decode("$distance"))."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
@ -121,6 +135,15 @@ class ExportThanatoStatisticService {
|
||||
|
||||
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){
|
||||
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
||||
$orderFullNumber = "";
|
||||
$totalOrderPrice = "";
|
||||
$isDevisDoneBySubContractor = $devis['fk_order_type_key'] == OrderTypeConstant::ORDER_TYPE_DEVIS &&
|
||||
$devis['order_id'] != null && $devis["fk_thanato_type_key"] == ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR;
|
||||
|
||||
if($isDevisDoneBySubContractor){
|
||||
$orderFullNumber = $devis["order_full_number"];
|
||||
$totalOrderPrice = $devis["total_price"];
|
||||
}
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($devis["facture_num"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis['nom_thanato'] . ' ' . $devis['prenom_thanatho']).';'.
|
||||
@ -132,7 +155,10 @@ class ExportThanatoStatisticService {
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_defunt"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "")."\n";
|
||||
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($orderFullNumber).';'.
|
||||
"$totalOrderPrice".';'.
|
||||
''.';'."\n";
|
||||
|
||||
return $fileContent;
|
||||
|
||||
|
||||
81
gestion/src/js/listener/thanatoListener.js
Normal file
81
gestion/src/js/listener/thanatoListener.js
Normal file
@ -0,0 +1,81 @@
|
||||
import {showError, showSuccess } from "@nextcloud/dialogs";
|
||||
import {baseUrl,showLoader,hideLoader} from "../modules/mainFunction.mjs";
|
||||
import { Devis } from "../objects/devis.mjs";
|
||||
import DataTable from "datatables.net";
|
||||
import { Thanatopracteur } from "../objects/thanatopracteur.mjs";
|
||||
window.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
const today = new Date();
|
||||
const currentMonth = today.getMonth() + 1;
|
||||
const currentYear = today.getFullYear();
|
||||
this.document.getElementById("monthSelect").value = currentMonth;
|
||||
this.document.getElementById("yearSelect").value = currentYear;
|
||||
});
|
||||
|
||||
$('body').on('click', '#showExportThanatoModal', 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){
|
||||
showError(t('gestion', "Veuillez choisir au moins une ligne de thanato"));
|
||||
return;
|
||||
}
|
||||
$('#exportThanatoModal').show();
|
||||
});
|
||||
|
||||
$('body').on('click', '#closeExportThanatoModal', function () {
|
||||
$('#exportThanatoModal').hide();
|
||||
});
|
||||
|
||||
$('body').on('click', '#exportThanatosStat', 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){
|
||||
$('#exportThanatoModal').hide();
|
||||
showError(t('gestion', "Veuillez choisir au moins une ligne de thanato"));
|
||||
return;
|
||||
}
|
||||
|
||||
var today = new Date();
|
||||
var monthValue = document.getElementById("monthSelect").value ?? today.getMonth() + 1;
|
||||
var yearValue = document.getElementById("yearSelect").value ?? today.getFullYear();
|
||||
let exportThanatoPayload = {
|
||||
thanatoIdsToExport: thanatoIdsToExport,
|
||||
month: monthValue,
|
||||
year: yearValue
|
||||
}
|
||||
|
||||
showLoader();
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/thanatopracteur/exportThanatoStatistic',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(exportThanatoPayload)
|
||||
}).done(function (response) {
|
||||
$('#exportThanatoModal').hide();
|
||||
let datatable = new DataTable('.tabledt');
|
||||
Thanatopracteur.loadThanatoDT(datatable);
|
||||
if(response.length == 0){
|
||||
showError(t('gestion', "Erreur dans l'export des statistiques"));
|
||||
}
|
||||
else{
|
||||
response.forEach(fileName => {
|
||||
showSuccess('Sauvegardé dans' + fileName);
|
||||
});
|
||||
}
|
||||
}).always(function () {
|
||||
hideLoader();
|
||||
});
|
||||
});
|
||||
@ -2,7 +2,7 @@ import "@nextcloud/dialogs/dist/index.css";
|
||||
import "datatables.net-dt/css/jquery.dataTables.css";
|
||||
import "../css/mycss.css";
|
||||
import "./listener/main_listener";
|
||||
|
||||
import "./listener/thanatoListener";
|
||||
import DataTable from "datatables.net";
|
||||
import { globalConfiguration, optionDatatable } from "./modules/mainFunction.mjs";
|
||||
import { Thanatopracteur } from "./objects/thanatopracteur.mjs";
|
||||
|
||||
@ -13,8 +13,10 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex jsutify-content-end">
|
||||
<button class="btn btn-secondary" id="exportThanatoData">Export thanato stat</button>
|
||||
<div class="d-flex justify-content-end">
|
||||
<button id="showExportThanatoModal" class="btn btn-secondary" data-toggle="modal" data-target="#exportThanatoModal">
|
||||
Export stat
|
||||
</button>
|
||||
</div>
|
||||
<table id="client" class="display tabledt" style="font-size:11px;">
|
||||
<thead>
|
||||
@ -33,4 +35,44 @@
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="modal" id="exportThanatoModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Choisir le mois et l'année pour l'export</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<select class="form-select w-auto" name="month" id="monthSelect">
|
||||
<option value="1">Janvier</option>
|
||||
<option value="2">Février</option>
|
||||
<option value="3">Mars</option>
|
||||
<option value="4">Avril</option>
|
||||
<option value="5">Mai</option>
|
||||
<option value="6">Juin</option>
|
||||
<option value="7">Juillet</option>
|
||||
<option value="8">Août</option>
|
||||
<option value="9">Septembre</option>
|
||||
<option value="10">Octobre</option>
|
||||
<option value="11">Novembre</option>
|
||||
<option value="12">Décembre</option>
|
||||
</select>
|
||||
<select class="form-select w-auto" name="year" id="yearSelect">
|
||||
<?php
|
||||
$currentYear = date('Y');
|
||||
for ($year = $currentYear; $year >= $currentYear - 10; $year--) {
|
||||
echo '<option value="' . $year . '"';
|
||||
echo '>' . $year . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="closeExportThanatoModal" type="button" class="btn btn-secondary">Annuler</button>
|
||||
<button id="exportThanatosStat" type="button" class="btn btn-primary">Exporter</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -13,6 +13,7 @@
|
||||
<div id="app-content-wrapper">
|
||||
<?php print_unescaped($this->inc('content/changelog')); ?>
|
||||
<?php print_unescaped($this->inc('content/thanatopracteur')); ?>
|
||||
<?php print_unescaped($this->inc('loader')); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
x
Reference in New Issue
Block a user