Skip to content

Commit 1d730a4

Browse files
Merge pull request #4692 from Evarisk/develop
22.1.0
2 parents ac83813 + 6488611 commit 1d730a4

13 files changed

Lines changed: 700 additions & 200 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
## Informations
44

55
- Numéro du module : 436302
6-
- Dernière mise à jour : 25/02/2026
6+
- Dernière mise à jour : 18/03/2026
77
- Éditeur : [Evarisk](https://evarisk.com)
88
- Thème : Eldy Menu
99
- Licence : GPLv3
1010
- Disponible sur : Windows - MacOS - Linux
1111

1212
### Version
1313

14-
- Version : 22.0.0
14+
- Version : 22.1.0
1515
- PHP : 7.4.33
1616
- Compatibilité : Dolibarr 21.0.0 - 22.0.4
1717
- Saturne Framework : 22.0.0

class/accident.class.php

Lines changed: 232 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,30 @@ public function LibStatut(int $status, int $mode = 0): string
438438
*/
439439
public function load_dashboard(): array
440440
{
441-
global $langs, $conf;
441+
global $langs, $conf, $db;
442+
443+
// echo '<pre>'; print_r(getDolGlobalInt('SOCIETE_FISCAL_MONTH_START')); echo '</pre>'; exit;
442444

443445
$confName = dol_strtoupper($this->module) . '_DASHBOARD_CONFIG';
444446
$dashboardConfig = json_decode(getDolUserString($confName));
445-
$array = ['graphs' => [], 'disabledGraphs' => []];
447+
$array = ['graphs' => [], 'lists' => [], 'disabledGraphs' => []];
448+
449+
$yearType = !empty($dashboardConfig->filters->yearType) ? $dashboardConfig->filters->yearType : 'calendar';
450+
$year = !empty($dashboardConfig->filters->year) ? $dashboardConfig->filters->year : -1;
451+
452+
$now = dol_now('tzuserrel');
453+
$date = dol_getdate($now);
454+
$startDate = dol_mktime(-1, -1, -1, $yearType == 'calendar' ? 1 : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START'), 1, $year == -1 ? $date['year'] : $year);
455+
if ($startDate > $now) {
456+
$startDate = dol_time_plus_duree($startDate, -1, 'y');
457+
}
458+
$endDate = dol_time_plus_duree($startDate, 1, 'y');
446459

447460
$join = ' LEFT JOIN ' . MAIN_DB_PREFIX . $this->table_element . ' as a ON a.rowid = t.fk_accident';
448-
$accidentsWithWorkStops = saturne_fetch_all_object_type('AccidentWorkStop', 'DESC', 't.rowid', 0, 0, [], 'AND', false, true, false, $join);
449-
$accidents = $this->fetchAll('', '', 0, 0, ['customsql' => ' t.status > ' . self::STATUS_DRAFT]);
461+
$accidentsWithWorkStops = saturne_fetch_all_object_type('AccidentWorkStop', 'DESC', 't.rowid', 0, 0, $year == -1 ? [] : ['customsql' => ' t.date_start_workstop >= \'' . dol_print_date($startDate, '%Y/%m/%d') . '\' AND t.date_start_workstop < \'' . dol_print_date($endDate, '%Y/%m/%d') . '\''], 'AND', false, true, false, $join);
462+
$accidents = $this->fetchAll('', '', 0, 0, ['customsql' => ' t.status > ' . self::STATUS_DRAFT . ($year == -1 ? '' : ' AND t.accident_date >= \'' . dol_print_date($startDate, '%Y/%m/%d') . '\' AND t.accident_date < \'' . dol_print_date($endDate, '%Y/%m/%d') . '\'')]);
463+
$digiriskElement = new DigiriskElement($db);
464+
$digiriskElements = $digiriskElement->fetchDigiriskElementFlat(0);
450465

451466
if (empty($accidents) && !is_array($accidents)) {
452467
$accidents = [];
@@ -468,6 +483,29 @@ public function load_dashboard(): array
468483
$arrayFrequencyRate = $this->getFrequencyRate($accidentsWithWorkStops);
469484
$arrayGravityRate = $this->getGravityRate($accidentsWithWorkStops);
470485

486+
// dol_time_plus_duree
487+
488+
$currentYear = (int) dol_print_date(dol_now('tzuserrel'), '%Y');
489+
$years = range($currentYear, $currentYear - 10);
490+
491+
492+
$array['graphsFilters'] = [
493+
'yearType' => [
494+
'title' => $langs->transnoentities('YearType'),
495+
'type' => 'selectarray',
496+
'filter' => 'yearType',
497+
'values' => ['calendar' => $langs->transnoentities('CalendarYear'), 'fiscal' => $langs->transnoentities('FiscalYear')],
498+
'currentValue' => $yearType
499+
],
500+
'year' => [
501+
'title' => $langs->transnoentities('Year'),
502+
'type' => 'selectarray',
503+
'filter' => 'year',
504+
'values' => array_combine(array_merge([-1], $years), array_merge([$langs->transnoentities('AllYears')], array_map('strval', $years))),
505+
'currentValue' => $year
506+
]
507+
];
508+
471509
$array['widgets'] = [
472510
'accident' => [
473511
'title' => $langs->transnoentities('Accidents'),
@@ -489,18 +527,35 @@ public function load_dashboard(): array
489527
(($conf->global->DIGIRISKDOLIBARR_NB_WORKED_HOURS > 0 && $conf->global->DIGIRISKDOLIBARR_MANUAL_INPUT_NB_WORKED_HOURS) ? $langs->transnoentities('GravityRateTooltip') . '<br>' . $langs->transnoentities('NbWorkedHoursTooltip') : $langs->transnoentities('GravityRateTooltip'))
490528
],
491529
'widgetName' => $langs->transnoentities('AccidentRateIndicator')
492-
]
530+
],
493531
];
494532

495533
if (empty($dashboardConfig->graphs->AccidentRepartition->hide)) {
496534
$array['graphs'][] = $this->getNbAccidents($accidents, $accidentsWithWorkStops);
497535
} else {
498536
$array['disabledGraphs']['AccidentRepartition'] = $langs->transnoentities('AccidentRepartition');
499537
}
500-
if (empty($dashboardConfig->graphs->AccidentByYear->hide)) {
501-
$array['graphs'][] = $this->getNbAccidentsLast3years($accidents);
538+
if ($year == -1) {
539+
if (empty($dashboardConfig->graphs->AccidentByYear->hide)) {
540+
$array['graphs'][] = $this->getNbAccidentsLast3years($accidents);
541+
} else {
542+
$array['disabledGraphs']['AccidentByYear'] = $langs->transnoentities('AccidentByYear');
543+
}
544+
}
545+
if (empty($dashboardConfig->graphs->AccidentRegister->hide)) {
546+
$array['graphs'][] = $this->getAccidentRegister($accidents);
547+
} else {
548+
$array['disabledGraphs']['AccidentRegister'] = $langs->transnoentities('AccidentRegister');
549+
}
550+
if (empty($dashboardConfig->graphs->AccidentsByWorkStops->hide)) {
551+
$array['graphs'][] = $this->getNbAccidentsByWorkStops($accidents, $accidentsWithWorkStops);
502552
} else {
503-
$array['disabledGraphs']['AccidentByYear'] = $langs->transnoentities('AccidentByYear');
553+
$array['disabledGraphs']['AccidentsByWorkStops'] = $langs->transnoentities('AccidentsByWorkStops');
554+
}
555+
if (empty($dashboardConfig->graphs->AccidentsWorkStopByDigiriskElem->hide)) {
556+
$array['graphs'][] = $this->getAccidentsWorkStopByDigiriskElem($accidents, $accidentsWithWorkStops, $digiriskElements);
557+
} else {
558+
$array['disabledGraphs']['AccidentsWorkStopByDigiriskElem'] = $langs->transnoentities('AccidentsWorkStopByDigiriskElem');
504559
}
505560

506561
return $array;
@@ -798,6 +853,175 @@ public function getGravityRate(array $accidentsWithWorkStops = []): array
798853
return $array;
799854
}
800855

856+
/**
857+
* Get graph of AccidentRegister
858+
*
859+
* @param array $accident Array of accidents
860+
* @return array
861+
*/
862+
public function getAccidentRegister(array $accident = []): array
863+
{
864+
global $langs;
865+
866+
$accidentWithoutRegister = count(array_filter($accident, function($elem) {
867+
return $elem->fk_ticket === null;
868+
}));
869+
$array = [];
870+
871+
$array['title'] = $langs->transnoentities('AccidentRegister');
872+
$array['name'] = 'AccidentRegister';
873+
$array['picto'] = $this->picto;
874+
875+
// Graph parameters
876+
$array['width'] = '100%';
877+
$array['height'] = 400;
878+
$array['type'] = 'pie';
879+
$array['showlegend'] = 2;
880+
$array['dataset'] = 1;
881+
882+
$array['labels'] = [
883+
[
884+
'label' => $langs->transnoentities('AccidentWithoutRegister'),
885+
'color' => '#9567aa'
886+
],
887+
[
888+
'label' => $langs->transnoentities('AccidentWithRegister'),
889+
'color' => '#4f9ebe'
890+
],
891+
];
892+
893+
$array['data'] = [$accidentWithoutRegister, count($accident) - $accidentWithoutRegister];
894+
return $array;
895+
}
896+
897+
/**
898+
* Get graph of NbAccidentsByWorkStops
899+
*
900+
* @param array $accidents Array of accidents
901+
* @param array $accidentsWithWorkStop Array of work stops
902+
* @return array
903+
*/
904+
public function getNbAccidentsByWorkStops(array $accidents = [], array $accidentsWithWorkStop = []): array
905+
{
906+
global $langs;
907+
908+
$array['title'] = $langs->transnoentities('WorkStopDurationDistribution');
909+
$array['name'] = 'WorkStopDurationDistribution';
910+
$array['picto'] = $this->picto;
911+
912+
// Graph parameters
913+
$array['width'] = '100%';
914+
$array['height'] = 400;
915+
$array['type'] = 'pie';
916+
$array['showlegend'] = 2;
917+
$array['dataset'] = 1;
918+
919+
$array['labels'] = [
920+
'noAbsence' => [
921+
'label' => $langs->transnoentities('NoAbsence'),
922+
'color' => '#4caf50'
923+
],
924+
'upTo4Days' => [
925+
'label' => $langs->transnoentities('UpTo4Days'),
926+
'color' => '#8bc34a'
927+
],
928+
'upTo21Days' => [
929+
'label' => $langs->transnoentities('UpTo21Days'),
930+
'color' => '#ffc107'
931+
],
932+
'upTo3Months' => [
933+
'label' => $langs->transnoentities('UpTo3Months'),
934+
'color' => '#ff9800'
935+
],
936+
'upTo6Months' => [
937+
'label' => $langs->transnoentities('UpTo6Months'),
938+
'color' => '#ff5722'
939+
],
940+
'moreThan6Months' => [
941+
'label' => $langs->transnoentities('MoreThan6Months'),
942+
'color' => '#f44336'
943+
],
944+
];
945+
$array['data'] = [
946+
'noAbsence' => 0,
947+
'upTo4Days' => 0,
948+
'upTo21Days' => 0,
949+
'upTo3Months' => 0,
950+
'upTo6Months' => 0,
951+
'moreThan6Months' => 0,
952+
];
953+
954+
$nbAccidensWithWorkStop = [];
955+
foreach ($accidentsWithWorkStop as $workstop) {
956+
$days = abs($workstop->date_end_workstop - $workstop->date_start_workstop) / 86400;
957+
958+
if ($days < 4) {
959+
$array['data']['upTo4Days']++;
960+
} elseif ($days < 21) {
961+
$array['data']['upTo21Days']++;
962+
} elseif ($days < 90) {
963+
$array['data']['upTo3Months']++;
964+
} elseif ($days < 180) {
965+
$array['data']['upTo6Months']++;
966+
} else {
967+
$array['data']['moreThan6Months']++;
968+
}
969+
$nbAccidensWithWorkStop[$workstop->fk_accident] = $workstop->fk_accident;
970+
}
971+
foreach ($accidents as $accident) {
972+
if (!in_array($accident->id, $nbAccidensWithWorkStop)) {
973+
$array['data']['noAbsence']++;
974+
}
975+
}
976+
return $array;
977+
}
978+
979+
/**
980+
* Get graph of AccidentsWorkStopByDigiriskElem
981+
*
982+
* @param array $accidents Array of accidents
983+
* @param array $accidentsWithWorkStop Array of work stops
984+
* @param array $digiriskElements Array of digirisk elements
985+
* @return array
986+
*/
987+
public function getAccidentsWorkStopByDigiriskElem(array $accidents = [], array $accidentsWithWorkStop = [], array $digiriskElements = []): array
988+
{
989+
global $langs;
990+
991+
$array['title'] = $langs->transnoentities('WorkStopDurationDistributionDigiriskElem');
992+
$array['name'] = 'WorkStopDurationDistributionDigiriskElem';
993+
$array['picto'] = $this->picto;
994+
995+
// Graph parameters
996+
$array['width'] = '100%';
997+
$array['height'] = 400;
998+
$array['type'] = 'pie';
999+
$array['showlegend'] = 2;
1000+
$array['dataset'] = 1;
1001+
1002+
$array['data'] = [];
1003+
foreach ($accidentsWithWorkStop as $workstop) {
1004+
if (!empty($accidents[$workstop->fk_accident])) {
1005+
$accident = $accidents[$workstop->fk_accident];
1006+
if (empty($array['data'][$accident->fk_element])) {
1007+
$array['data'][$accident->fk_element] = 0;
1008+
}
1009+
$array['data'][$accident->fk_element] += abs($workstop->date_end_workstop - $workstop->date_start_workstop) / 86400;
1010+
}
1011+
}
1012+
unset($array['data'][null]);
1013+
1014+
$array['labels'] = [];
1015+
foreach (array_keys($array['data']) as $digiriskElemId) {
1016+
$digiriskElem = $digiriskElements[$digiriskElemId]['object'];
1017+
$array['labels'][$digiriskElemId] = [
1018+
'label' => $digiriskElem->ref . ' - ' . $digiriskElem->label,
1019+
];
1020+
}
1021+
1022+
return $array;
1023+
}
1024+
8011025
/**
8021026
* Get user victim object.
8031027
*

class/actions_digiriskdolibarr.class.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ public function printCommonFooter($parameters)
241241
</script>
242242
<?php
243243

244+
$digiriskelement = new DigiriskElement($db);
245+
$res = $digiriskelement->fetch($object->array_options['options_digiriskdolibarr_ticket_service']);
246+
if ($res > 0) {
247+
$outDigiriskElement = $digiriskelement->getNomUrl(1, 'blank', 0, '', -1, 1);
248+
?>
249+
<script>
250+
jQuery('td[id*="digiriskdolibarr_ticket_service"]').html('<?= $outDigiriskElement ?>');
251+
</script>
252+
<?php
253+
}
254+
255+
244256
if (!empty($object->id)) {
245257
$signatory = new SaturneSignature($db, 'digiriskdolibarr', $object->element);
246258
$signatories = $signatory->fetchSignatory('Attendant', $object->id, $object->element);
@@ -489,6 +501,32 @@ public function printCommonFooter($parameters)
489501
print '<script src="../custom/digiriskdolibarr/js/digiriskdolibarr.js"></script>';
490502
}
491503

504+
if (strpos($parameters['context'], 'ticketlist')) {
505+
?>
506+
<script>
507+
//$('table tr.oddeven td').css('padding', 2);
508+
509+
var titles = ["Sujet"];
510+
511+
// Récupère les index correspondants
512+
var indexes = {};
513+
514+
titles.forEach(function(title) {
515+
var index = $('th[title="' + title + '"]').index();
516+
if (index !== -1) {
517+
indexes[index] = title.replace(" ", "_");
518+
}
519+
});
520+
521+
// Applique le traitement sur chaque colonne trouvée
522+
Object.entries(indexes).forEach(([index, title]) => {
523+
var cells = $('table tr').find('td:eq(' + index + ')');
524+
cells.removeClass('tdoverflowmax250 ');
525+
});
526+
</script>
527+
528+
<?php
529+
}
492530
return 0; // or return 1 to replace standard code
493531
}
494532

@@ -1253,4 +1291,46 @@ public function saturneAddAttendantRow($parameters)
12531291

12541292
return 0;
12551293
}
1294+
1295+
public function printFieldListValue($parameters, $object, $action)
1296+
{
1297+
global $db;
1298+
1299+
if (strpos($parameters['context'], 'ticketlist') && isModEnabled('categorie')) {
1300+
$obj = $parameters['object'];
1301+
1302+
$categorie = new Categorie($db);
1303+
$categories = $categorie->getListForItem($obj->id, $obj->element);
1304+
1305+
$out = '';
1306+
1307+
foreach ($categories as $cat) {
1308+
$out .= '<div class="noborderoncategories paddingleft marginbottom" style="background: #'. (empty($cat['color']) ? 'bbb' : $cat['color']) .'">';
1309+
$out .= '<div class="categtextwhite" data-catid="' . $cat['id'] . '" style="cursor: pointer;"><span class="fas fa-tag paddingright" style=""></span>' . addslashes($cat['label']) . '</div></div>';
1310+
}
1311+
1312+
?>
1313+
<script>
1314+
$('[data-key="ticket.ticket_categories"]').eq(<?= $parameters['i'] ?>).html('<?= $out ?>')
1315+
$('[data-key="ticket.ticket_categories"]').eq(<?= $parameters['i'] ?>).find('.categtextwhite').on('click', function() {
1316+
$('#search_category_ticket_list').val($(this).data('catid')).trigger('change');
1317+
$('button[name="button_search_x"]').click();
1318+
});
1319+
</script>
1320+
<?php
1321+
1322+
$serviceId = $parameters['obj']->options_digiriskdolibarr_ticket_service;
1323+
1324+
$digiriskelement = new DigiriskElement($db);
1325+
$res = $digiriskelement->fetch($serviceId);
1326+
if ($res > 0) {
1327+
$out = $digiriskelement->getNomUrl(1, 'blank', 0, '', -1, 1);
1328+
?>
1329+
<script>
1330+
$('[data-key="ticket.digiriskdolibarr_ticket_service"]').eq(<?= $parameters['i'] ?>).html('<?= $out ?>')
1331+
</script>
1332+
<?php
1333+
}
1334+
}
1335+
}
12561336
}

0 commit comments

Comments
 (0)