wip thanato statistique
This commit is contained in:
parent
81635aae5f
commit
ba5dc3230d
@ -2333,14 +2333,18 @@ class PageController extends Controller {
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @param array $thanatoIdsToExport
|
||||
* @param string $month
|
||||
* @param string $year
|
||||
*
|
||||
*/
|
||||
|
||||
public function exportThanatoStatistic($thanatoIdsToExport){
|
||||
public function exportThanatoStatistic($thanatoIdsToExport,$month,$year){
|
||||
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).'/';
|
||||
|
||||
@ -2148,10 +2148,95 @@ class Bdd {
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getExportThanatoStatisticData(array $thanatoIds){
|
||||
$devisList = $this->getDevisListByThanatoIds($thanatoIds);
|
||||
$devisListGroupedByDateAndThenByThanato = $this->getDevisListGroupedByDateAndThenByThanato($devisList);
|
||||
return $devisListGroupedByDateAndThenByThanato;
|
||||
private function getThanatosDevisListByDate(array $thanatoIds,$date){
|
||||
if(empty($thanatoIds)){
|
||||
return [];
|
||||
}
|
||||
|
||||
$dateFormatted = $date->format('Y-m-d');
|
||||
|
||||
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($thanatoIds), '?'));
|
||||
$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,
|
||||
facture.num as facture_num
|
||||
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
|
||||
WHERE devis.date = ? AND
|
||||
devis.id_thanato IN ($sqlConditionsPlaceholder) AND
|
||||
(devis.mentions = ? OR devis.mentions = ?)
|
||||
ORDER BY devis.date ASC;";
|
||||
$devisList = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
array_merge([$dateFormatted],$thanatoIds,[DevisMentionConstant::FACTURED,DevisMentionConstant::FACTURED_FORMATTED]));
|
||||
return $devisList;
|
||||
}
|
||||
|
||||
public function getThanatoDevisPerDateInAMonthYear(array $thanatoIds,$month,$year){
|
||||
$dateOfMonths = DateHelpers::getDatesOfMonth($year,$month);
|
||||
$devisListPerThanatoPerDate = [];
|
||||
foreach($dateOfMonths as $currentDate){
|
||||
$currentDateFormatted = $currentDate->format('Y-m-d');
|
||||
$devisList = $this->getThanatosDevisListByDate($thanatoIds,$currentDate);
|
||||
if(empty($devisList)){
|
||||
//get if on leave
|
||||
//if on leave set hours
|
||||
//else set
|
||||
foreach($thanatoIds as $thanatoId){
|
||||
$devisListPerThanatoPerDate[$thanatoId][$currentDateFormatted] = [
|
||||
"onLeave" => false,
|
||||
"leaveTimeStart" => null,
|
||||
"leaveTimeEnd" => null
|
||||
];
|
||||
}
|
||||
}
|
||||
else{
|
||||
foreach($devisList as $devis){
|
||||
$devisThanatoId = $devis["id_thanato"];
|
||||
$devis = $this->setDevisStartAndEndTime($devis);
|
||||
$devis = $this->setDevisIsWeekendOrNotText($devis);
|
||||
$devis = $this->setDevisProduitsList($devis);
|
||||
//set devis articles list into devis data
|
||||
if (!isset($devisListPerThanatoPerDate[$devisThanatoId])) {
|
||||
$devisListPerThanatoPerDate[$devisThanatoId] = [];
|
||||
}
|
||||
if (!isset($devisListPerThanatoPerDate[$devisThanatoId][$currentDateFormatted])) {
|
||||
$devisListPerThanatoPerDate[$devisThanatoId][$currentDateFormatted] = [
|
||||
'total_distance' => 0,
|
||||
"devis" => [],
|
||||
"devisId" => []
|
||||
];
|
||||
}
|
||||
$devisListPerThanatoPerDate[$devisThanatoId][$currentDateFormatted]["devis"][] = $devis;
|
||||
$devisListPerThanatoPerDate[$devisThanatoId][$currentDateFormatted]["devisId"][] = $devis['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $devisListPerThanatoPerDate;
|
||||
}
|
||||
|
||||
public function getExportThanatoStatisticData(array $thanatoIds,$month,$year){
|
||||
$devisList = $this->getThanatoDevisPerDateInAMonthYear($thanatoIds,$month,$year);
|
||||
return $devisList;
|
||||
}
|
||||
|
||||
public function getProduitsDevisByDevisId($devisId){
|
||||
@ -2169,29 +2254,31 @@ class Bdd {
|
||||
return $produitsList;
|
||||
}
|
||||
|
||||
private function getDevisListGroupedByDateAndThenByThanato(array $devisList){
|
||||
$devisListGroupedByDateAndThenByThanato = [];
|
||||
foreach($devisList as $devis){
|
||||
$devisDate = $devis["date"];
|
||||
$devisThanatoId = $devis["id_thanato"];
|
||||
$devis = $this->setDevisStartAndEndTime($devis);
|
||||
$devis = $this->setDevisIsWeekendOrNotText($devis);
|
||||
$devis = $this->setDevisProduitsList($devis);
|
||||
//set devis articles list into devis data
|
||||
if (!isset($devisListGroupedByDateAndThenByThanato[$devisThanatoId])) {
|
||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId] = [];
|
||||
private function getDevisListGroupedByDateAndThenByThanato(array $devisListPerDate){
|
||||
$devisListGroupedByThanatoAndThenByDate = [];
|
||||
foreach($devisListPerDate as $date => $devisList){
|
||||
foreach($devisList as $devis){
|
||||
$devisDate = $devis["date"];
|
||||
$devisThanatoId = $devis["id_thanato"];
|
||||
$devis = $this->setDevisStartAndEndTime($devis);
|
||||
$devis = $this->setDevisIsWeekendOrNotText($devis);
|
||||
$devis = $this->setDevisProduitsList($devis);
|
||||
//set devis articles list into devis data
|
||||
if (!isset($devisListGroupedByThanatoAndThenByDate[$devisThanatoId])) {
|
||||
$devisListGroupedByThanatoAndThenByDate[$devisThanatoId] = [];
|
||||
}
|
||||
if (!isset($devisListGroupedByThanatoAndThenByDate[$devisThanatoId][$devisDate])) {
|
||||
$devisListGroupedByThanatoAndThenByDate[$devisThanatoId][$devisDate] = [
|
||||
'total_distance' => 0,
|
||||
"devis" => [],
|
||||
"devisId" => []
|
||||
];
|
||||
}
|
||||
$devisListGroupedByThanatoAndThenByDate[$devisThanatoId][$date]["devis"][] = $devis;
|
||||
$devisListGroupedByThanatoAndThenByDate[$devisThanatoId][$date]["devisId"][] = $devis['id'];
|
||||
}
|
||||
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;
|
||||
return $devisListGroupedByThanatoAndThenByDate;
|
||||
}
|
||||
|
||||
private function setDevisProduitsList($devis){
|
||||
|
||||
@ -64,4 +64,20 @@ class DateHelpers
|
||||
return $lastDay;
|
||||
}
|
||||
|
||||
public static function getDatesOfMonth($year, $month) {
|
||||
$dates = [];
|
||||
$daysInMonth = self::getDaysCountInAMonthAndYear($month, $year);
|
||||
|
||||
for ($day = 1; $day <= $daysInMonth; $day++) {
|
||||
$dateString = sprintf("%04d-%02d-%02d", $year, $month, $day);
|
||||
$dates[] = new DateTime($dateString);
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
public static function getDaysCountInAMonthAndYear($month,$year){
|
||||
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -76,16 +76,41 @@ class ExportThanatoStatisticService {
|
||||
return $fileHeader;
|
||||
}
|
||||
|
||||
private function populateNoDevisDataInADay(string $fileContent,string $dateAsString){
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
''.';'.
|
||||
$dateAsString.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
|
||||
// var_dump($exportData);
|
||||
// die;
|
||||
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);
|
||||
$currentDevisIsNotDevis = array_key_exists('onLeave',$devisData);
|
||||
if($currentDevisIsNotDevis){
|
||||
$fileContent = $this->populateNoDevisDataInADay($fileContent,$devisDate);
|
||||
}
|
||||
else{
|
||||
$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);
|
||||
}
|
||||
$fileContent = $this->populateDistanceTotalIntoThanatoExportFileContent($fileContent,$distanceTotal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user