wip thanato statistique
This commit is contained in:
parent
81635aae5f
commit
ba5dc3230d
@ -2333,14 +2333,18 @@ class PageController extends Controller {
|
|||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
* @param array $thanatoIdsToExport
|
* @param array $thanatoIdsToExport
|
||||||
|
* @param string $month
|
||||||
|
* @param string $year
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function exportThanatoStatistic($thanatoIdsToExport){
|
public function exportThanatoStatistic($thanatoIdsToExport,$month,$year){
|
||||||
if(empty($thanatoIdsToExport)){
|
if(empty($thanatoIdsToExport)){
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
$exportData = $this->myDb->getExportThanatoStatisticData($thanatoIdsToExport);
|
$month = $month ?? date('m');
|
||||||
|
$year = $year ?? date('Y');
|
||||||
|
$exportData = $this->myDb->getExportThanatoStatisticData($thanatoIdsToExport,$month,$year);
|
||||||
try{
|
try{
|
||||||
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
||||||
$clean_folder = html_entity_decode($current_config[0]->path).'/';
|
$clean_folder = html_entity_decode($current_config[0]->path).'/';
|
||||||
|
|||||||
@ -2148,10 +2148,95 @@ class Bdd {
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getExportThanatoStatisticData(array $thanatoIds){
|
private function getThanatosDevisListByDate(array $thanatoIds,$date){
|
||||||
$devisList = $this->getDevisListByThanatoIds($thanatoIds);
|
if(empty($thanatoIds)){
|
||||||
$devisListGroupedByDateAndThenByThanato = $this->getDevisListGroupedByDateAndThenByThanato($devisList);
|
return [];
|
||||||
return $devisListGroupedByDateAndThenByThanato;
|
}
|
||||||
|
|
||||||
|
$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){
|
public function getProduitsDevisByDevisId($devisId){
|
||||||
@ -2169,8 +2254,9 @@ class Bdd {
|
|||||||
return $produitsList;
|
return $produitsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDevisListGroupedByDateAndThenByThanato(array $devisList){
|
private function getDevisListGroupedByDateAndThenByThanato(array $devisListPerDate){
|
||||||
$devisListGroupedByDateAndThenByThanato = [];
|
$devisListGroupedByThanatoAndThenByDate = [];
|
||||||
|
foreach($devisListPerDate as $date => $devisList){
|
||||||
foreach($devisList as $devis){
|
foreach($devisList as $devis){
|
||||||
$devisDate = $devis["date"];
|
$devisDate = $devis["date"];
|
||||||
$devisThanatoId = $devis["id_thanato"];
|
$devisThanatoId = $devis["id_thanato"];
|
||||||
@ -2178,20 +2264,21 @@ class Bdd {
|
|||||||
$devis = $this->setDevisIsWeekendOrNotText($devis);
|
$devis = $this->setDevisIsWeekendOrNotText($devis);
|
||||||
$devis = $this->setDevisProduitsList($devis);
|
$devis = $this->setDevisProduitsList($devis);
|
||||||
//set devis articles list into devis data
|
//set devis articles list into devis data
|
||||||
if (!isset($devisListGroupedByDateAndThenByThanato[$devisThanatoId])) {
|
if (!isset($devisListGroupedByThanatoAndThenByDate[$devisThanatoId])) {
|
||||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId] = [];
|
$devisListGroupedByThanatoAndThenByDate[$devisThanatoId] = [];
|
||||||
}
|
}
|
||||||
if (!isset($devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate])) {
|
if (!isset($devisListGroupedByThanatoAndThenByDate[$devisThanatoId][$devisDate])) {
|
||||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate] = [
|
$devisListGroupedByThanatoAndThenByDate[$devisThanatoId][$devisDate] = [
|
||||||
'total_distance' => 0,
|
'total_distance' => 0,
|
||||||
"devis" => [],
|
"devis" => [],
|
||||||
"devisId" => []
|
"devisId" => []
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate]["devis"][] = $devis;
|
$devisListGroupedByThanatoAndThenByDate[$devisThanatoId][$date]["devis"][] = $devis;
|
||||||
$devisListGroupedByDateAndThenByThanato[$devisThanatoId][$devisDate]["devisId"][] = $devis['id'];
|
$devisListGroupedByThanatoAndThenByDate[$devisThanatoId][$date]["devisId"][] = $devis['id'];
|
||||||
}
|
}
|
||||||
return $devisListGroupedByDateAndThenByThanato;
|
}
|
||||||
|
return $devisListGroupedByThanatoAndThenByDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setDevisProduitsList($devis){
|
private function setDevisProduitsList($devis){
|
||||||
|
|||||||
@ -64,4 +64,20 @@ class DateHelpers
|
|||||||
return $lastDay;
|
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,9 +76,33 @@ class ExportThanatoStatisticService {
|
|||||||
return $fileHeader;
|
return $fileHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function populateNoDevisDataInADay(string $fileContent,string $dateAsString){
|
||||||
|
$fileContent = $fileContent.
|
||||||
|
''.';'.
|
||||||
|
''.';'.
|
||||||
|
$dateAsString.';'.
|
||||||
|
''.';'.
|
||||||
|
''.';'.
|
||||||
|
''.';'.
|
||||||
|
''.';'.
|
||||||
|
''.';'.
|
||||||
|
''.';'.
|
||||||
|
''.';'.
|
||||||
|
''.';'.
|
||||||
|
''.';'."\n";
|
||||||
|
return $fileContent;
|
||||||
|
}
|
||||||
|
|
||||||
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
|
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
|
||||||
|
// var_dump($exportData);
|
||||||
|
// die;
|
||||||
foreach($exportData as $thanatoId => $devisPerThanato){
|
foreach($exportData as $thanatoId => $devisPerThanato){
|
||||||
foreach($devisPerThanato as $devisDate => $devisData){
|
foreach($devisPerThanato as $devisDate => $devisData){
|
||||||
|
$currentDevisIsNotDevis = array_key_exists('onLeave',$devisData);
|
||||||
|
if($currentDevisIsNotDevis){
|
||||||
|
$fileContent = $this->populateNoDevisDataInADay($fileContent,$devisDate);
|
||||||
|
}
|
||||||
|
else{
|
||||||
$distanceTotal = $this->gestionBdd->getDistanceTotalByDevisIdList($devisData["devisId"]);
|
$distanceTotal = $this->gestionBdd->getDistanceTotalByDevisIdList($devisData["devisId"]);
|
||||||
$devisList = $devisData["devis"];
|
$devisList = $devisData["devis"];
|
||||||
if(!empty($devisList)){
|
if(!empty($devisList)){
|
||||||
@ -89,6 +113,7 @@ class ExportThanatoStatisticService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $fileContent;
|
return $fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user