fix stats devis thanato

This commit is contained in:
Tolotsoa 2025-11-19 12:01:51 +03:00
parent 411cc2d5a8
commit 03784fd8e6
2 changed files with 355 additions and 275 deletions

View File

@ -2615,7 +2615,7 @@ class Bdd
return $data; return $data;
} }
private function getThanatoDevisListByDate($thanatoId, $date) private function getThanatoDevisListByDateSave($thanatoId, $date)
{ {
$dateFormatted = $date->format('Y-m-d'); $dateFormatted = $date->format('Y-m-d');
$sql = "SELECT $sql = "SELECT
@ -2656,6 +2656,42 @@ class Bdd
return $devisList; return $devisList;
} }
private function getThanatoDevisListByDate($thanatoId, $date)
{
$dateFormatted = $date->format('Y-m-d');
$sql = "SELECT
devis.id,
devis.date,
devis.mentions,
devis.num as calendar_uuid,
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,
client.adresse as client_adresse
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 devis.date = ? AND
devis.id_thanato = ?
ORDER BY devis.date ASC;";
$devisList = $this->execSQLNoJsonReturn(
$sql,
[$dateFormatted,$thanatoId]
);
return $devisList;
}
public function getThanatoById($thanatoId) public function getThanatoById($thanatoId)
{ {
$sql = "SELECT id, nom, prenom,fk_user_uuid FROM ".$this->tableprefix."thanato WHERE id = ? LIMIT 1;"; $sql = "SELECT id, nom, prenom,fk_user_uuid FROM ".$this->tableprefix."thanato WHERE id = ? LIMIT 1;";

View File

@ -34,7 +34,8 @@ use OCA\Gestion\Constants\BddConstant;
use OCA\Gestion\Helpers\FileExportHelpers; use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Constants\AbsenceTypeConstant; use OCA\Gestion\Constants\AbsenceTypeConstant;
class ExportThanatoStatisticService { class ExportThanatoStatisticService
{
/** @var Bdd */ /** @var Bdd */
private $gestionBdd; private $gestionBdd;
@ -50,14 +51,16 @@ class ExportThanatoStatisticService {
Bdd $gestionBdd, Bdd $gestionBdd,
LoggerInterface $logger, LoggerInterface $logger,
IRootFolder $rootFolder, IRootFolder $rootFolder,
GeoService $geoService) { GeoService $geoService
) {
$this->geoService = $geoService; $this->geoService = $geoService;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->logger = $logger; $this->logger = $logger;
$this->gestionBdd = $gestionBdd; $this->gestionBdd = $gestionBdd;
} }
private function getFilename($thanatoName,$thanatoLastName,$month,$year){ private function getFilename($thanatoName, $thanatoLastName, $month, $year)
{
$filename = "$year-$month-"; $filename = "$year-$month-";
$filename .= $thanatoName . '-' . $thanatoLastName; $filename .= $thanatoName . '-' . $thanatoLastName;
$filename = str_replace(' ', '-', $filename); $filename = str_replace(' ', '-', $filename);
@ -65,7 +68,8 @@ class ExportThanatoStatisticService {
return $filename; return $filename;
} }
private function exportThanatoStatistic($thanatoId,$month,$year,$idNextcloud){ private function exportThanatoStatistic($thanatoId, $month, $year, $idNextcloud)
{
$thanato = $this->gestionBdd->getThanatoById($thanatoId); $thanato = $this->gestionBdd->getThanatoById($thanatoId);
if($thanato == null) { if($thanato == null) {
return null; return null;
@ -82,8 +86,7 @@ class ExportThanatoStatisticService {
$storage = $this->rootFolder->getUserFolder($idNextcloud); $storage = $this->rootFolder->getUserFolder($idNextcloud);
try { try {
$storage->newFolder($thanatoFolder); $storage->newFolder($thanatoFolder);
} } catch(\OCP\Files\NotPermittedException $e) {
catch(\OCP\Files\NotPermittedException $e) {
} }
$filename = $this->getFilename($thanato["nom"], $thanato["prenom"], $month, $year); $filename = $this->getFilename($thanato["nom"], $thanato["prenom"], $month, $year);
@ -94,7 +97,8 @@ class ExportThanatoStatisticService {
return $fileNamePath; return $fileNamePath;
} }
public function exportThanatosListStatistic(array $thanatoIds,$month,$year,$idNextcloud){ public function exportThanatosListStatistic(array $thanatoIds, $month, $year, $idNextcloud)
{
$filenames = []; $filenames = [];
foreach($thanatoIds as $thanatoId) { foreach($thanatoIds as $thanatoId) {
$filename = $this->exportThanatoStatistic($thanatoId, $month, $year, $idNextcloud); $filename = $this->exportThanatoStatistic($thanatoId, $month, $year, $idNextcloud);
@ -105,9 +109,10 @@ class ExportThanatoStatisticService {
return $filenames; return $filenames;
} }
public function getExportThanatoFileHeader(): string{ public function getExportThanatoFileHeader(): string
{
$fileHeader = $fileHeader =
'FACTURE'.';'. 'DEVIS'.';'.
'THANATOPRACTEUR'.';'. 'THANATOPRACTEUR'.';'.
'DATE'.';'. 'DATE'.';'.
'HEURE DE DEBUT'.';'. 'HEURE DE DEBUT'.';'.
@ -133,10 +138,13 @@ class ExportThanatoStatisticService {
return $fileHeader; return $fileHeader;
} }
private function populateNoDevisDataInADay(string $fileContent,$leave){ private function populateNoDevisDataInADay(string $fileContent, $leave)
{
$startTimeValue = ""; $startTimeValue = "";
$endTimeValue = ""; $endTimeValue = "";
$leaveValue = "Non"; $leaveValue = "Non";
$restValue = "Non"; // AJOUTER CETTE LIGNE
$diseaseValue = "Non"; // AJOUTER CETTE LIGNE
if($leave["onLeave"]) { if($leave["onLeave"]) {
$startTimeValue = $leave["startTime"]; $startTimeValue = $leave["startTime"];
$endTimeValue = $leave["endTime"]; $endTimeValue = $leave["endTime"];
@ -176,7 +184,8 @@ class ExportThanatoStatisticService {
return $fileContent; return $fileContent;
} }
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{ public function populateExportDataIntoFileContent(array $exportData, string $fileContent): string
{
$g_totalDistance = 0; $g_totalDistance = 0;
$g_totalDevisHours = 0; $g_totalDevisHours = 0;
@ -216,8 +225,7 @@ class ExportThanatoStatisticService {
} }
$totalAbsenceHours = $totalLeaveHours + $totalRestHours + $totalDiseaseHours; $totalAbsenceHours = $totalLeaveHours + $totalRestHours + $totalDiseaseHours;
$totalWorkedHours -= $totalAbsenceHours; $totalWorkedHours -= $totalAbsenceHours;
} } else {
else{
$totalDevisCount += count($devisData["devisId"]); $totalDevisCount += count($devisData["devisId"]);
$routeLines = $this->gestionBdd->getRouteLinesByDevisIdList($devisData["devisId"]); $routeLines = $this->gestionBdd->getRouteLinesByDevisIdList($devisData["devisId"]);
$totalDistanceAndTotalTravelingHoursBetweenDevis = $this->geoService->getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines($routeLines); $totalDistanceAndTotalTravelingHoursBetweenDevis = $this->geoService->getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines($routeLines);
@ -258,7 +266,8 @@ class ExportThanatoStatisticService {
$totalLeaveHours, $totalLeaveHours,
$totalTravelingHoursBetweenDevisLocation, $totalTravelingHoursBetweenDevisLocation,
$totalDiseaseHours, $totalDiseaseHours,
$totalRestHours,$totalDevisCount $totalRestHours,
$totalDevisCount
); );
$g_totalDistance += $totalDistance; $g_totalDistance += $totalDistance;
@ -279,13 +288,15 @@ class ExportThanatoStatisticService {
$g_totalLeaveHours, $g_totalLeaveHours,
$g_totalTravelingHoursBetweenDevisLocation, $g_totalTravelingHoursBetweenDevisLocation,
$g_totalDiseaseHours, $g_totalDiseaseHours,
$g_totalRestHours,$g_totalDevisCount $g_totalRestHours,
$g_totalDevisCount
); );
return $fileContent; return $fileContent;
} }
private function populateLastRecapForTheLine(string $fileContent,$distance,$totalDevisHours,$totalWorkedHours,$totalLeaveHours,$totalTravelingHours ,$totalDiseaseHours = 0,$totalRestHours = 0,$totalDevisCount = 0){ private function populateLastRecapForTheLine(string $fileContent, $distance, $totalDevisHours, $totalWorkedHours, $totalLeaveHours, $totalTravelingHours, $totalDiseaseHours = 0, $totalRestHours = 0, $totalDevisCount = 0)
{
$fileContent = $fileContent. $fileContent = $fileContent.
''.';'. ''.';'.
''.';'. ''.';'.
@ -312,7 +323,8 @@ class ExportThanatoStatisticService {
return $fileContent; return $fileContent;
} }
private function getFormatDevisProduitsAsString($devisProduits){ private function getFormatDevisProduitsAsString($devisProduits)
{
$result = ''; $result = '';
foreach ($devisProduits as $produit) { foreach ($devisProduits as $produit) {
$result .= $produit['produit_reference'] . '-' . $produit['produit_description'] . '--'; $result .= $produit['produit_reference'] . '-' . $produit['produit_description'] . '--';
@ -322,7 +334,8 @@ class ExportThanatoStatisticService {
return $result; return $result;
} }
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent,array $devis){ private function populateDevisDataIntoThanatoExportFileContentSave(string $fileContent, array $devis)
{
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]); $produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
$factureNum = $devis["facture_num"] ?? $devis["facture_on_group_num"] ?? ""; $factureNum = $devis["facture_num"] ?? $devis["facture_on_group_num"] ?? "";
$fileContent = $fileContent. $fileContent = $fileContent.
@ -352,4 +365,35 @@ class ExportThanatoStatisticService {
return $fileContent; return $fileContent;
} }
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent, array $devis)
{
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
$devisNum = (string)$devis["calendar_uuid"];
$fileContent = $fileContent.
FileExportHelpers::FormatTextForExport($devisNum).';'.
FileExportHelpers::FormatTextForExport($devis['nom_thanato'] . ' ' . $devis['prenom_thanato']).';'.
FileExportHelpers::FormatTextForExport($devis["date"]).';'.
FileExportHelpers::FormatTextForExport($devis["startTime"]).';'.
FileExportHelpers::FormatTextForExport($devis["endTime"]).';'.
FileExportHelpers::FormatTextForExport($produitAsString).';'.
FileExportHelpers::FormatTextForExport($devis["dayType"]).';'.
FileExportHelpers::FormatTextForExport('Non').';'.
''.';'.
''.';'.
FileExportHelpers::FormatTextForExport($devis["nom_defunt"]).';'.
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "").
''.';'.
''.';'.
''.';'.
''.';'.
''.';'.
''.';'.
''.';'.
''.';'."\n";
return $fileContent;
}
} }