Skip to content

Commit

Permalink
Merge pull request #3546 from evarisk-theo/add_accident_register_docu…
Browse files Browse the repository at this point in the history
…ment

#3540 [Accident] add: accident register document
  • Loading branch information
evarisk-theo committed Nov 30, 2023
2 parents 1c6ab1d + d93456b commit c74d842
Show file tree
Hide file tree
Showing 29 changed files with 1,403 additions and 458 deletions.
2 changes: 1 addition & 1 deletion admin/ticket/ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
print '</tr>';
print '</form>';

if (getDolGlobalInt('DIGIRISKDOLIBARR_TICKET_EXTRAFIELDS') > 0) {
if (dolibarr_get_const($db, 'DIGIRISKDOLIBARR_TICKET_EXTRAFIELDS', 0)) {
print load_fiche_titre($langs->transnoentities("PublicInterfaceConfiguration"), '', '');

print '<div class="div-table-responsive-no-min">';
Expand Down
55 changes: 36 additions & 19 deletions class/accident.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class Accident extends SaturneObject
'tms' => ['type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 50, 'notnull' => 0, 'visible' => 0,],
'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => '1', 'position' => 70, 'notnull' => 1, 'visible' => 2, 'index' => 0, 'arrayofkeyval' => [1 => 'InProgress', 2 => 'Locked']],
'label' => ['type' => 'varchar(255)', 'label' => 'Label', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth200', 'help' => "Help text", 'showoncombobox' => '1',],
'fk_user_victim' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserVictim', 'enabled' => '1', 'position' => 81, 'notnull' => -1, 'visible' => 1,],
'fk_user_employer' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserEmployer', 'enabled' => '1', 'position' => 82, 'notnull' => -1, 'visible' => 1,],
'accident_type' => ['type' => 'text', 'label' => 'AccidentType', 'enabled' => '1', 'position' => 90, 'notnull' => -1, 'visible' => 1, 'css' => 'minwidth150',],
'fk_element' => ['type' => 'integer', 'label' => 'AccidentLocation', 'enabled' => '1', 'position' => 91, 'notnull' => -1, 'visible' => 1, 'css' => 'minwidth150',],
Expand Down Expand Up @@ -194,7 +193,6 @@ class Accident extends SaturneObject
public $fk_standard;
public $fk_ticket;
public $fk_soc;
public $fk_user_victim;
public $fk_user_employer;

/**
Expand Down Expand Up @@ -255,7 +253,7 @@ public function createFromClone(User $user, int $fromID, array $options): int
$object->date_creation = dol_now();
}
if (property_exists($object, 'status')) {
$object->status = self::STATUS_VALIDATED;
$object->status = self::STATUS_DRAFT;
}
if (empty($options['photos'])) {
$object->photo = '';
Expand Down Expand Up @@ -362,26 +360,27 @@ public function LibStatut(int $status, int $mode = 0): string
global $langs;

$this->labelStatus[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted');
$this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InProgress');
$this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InProgress');
$this->labelStatus[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked');

$this->labelStatusShort[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted');
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InProgress');
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InProgress');
$this->labelStatusShort[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked');

}

$statusType = 'status' . $status;

if ($status == self::STATUS_VALIDATED) {
$statusType = 'status4';
}
if ($status == self::STATUS_LOCKED) {
$statusType = 'status6';
}
if ($status == self::STATUS_DELETED) {
$statusType = 'status9';
}
$statusType = 'status' . $status;
if ($status == self::STATUS_VALIDATED) {
$statusType = 'status4';
}
if ($status == self::STATUS_LOCKED) {
$statusType = 'status6';
}
if ($status == self::STATUS_DELETED) {
$statusType = 'status9';
}

return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
Expand Down Expand Up @@ -681,6 +680,24 @@ public function getGravityRate() {
return $array;
}

/**
* Get user victim object.
*
* @return User
*/
public function getUserVictim():User {
$user = new User($this->db);
$signatory = new SaturneSignature($this->db);

$victimSignatory = $signatory->fetchSignatory('Victim', $this->id, 'accident');

if (is_array($victimSignatory) && !empty($victimSignatory)) {
$victimSignatory = array_shift($victimSignatory);
$user->fetch($victimSignatory->element_id);
}
return $user;
}

/**
* Write information of trigger description
*
Expand All @@ -693,9 +710,9 @@ public function getTriggerDescription(SaturneObject $object): string

require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';

$userVictim = new User($this->db);
$userEmployer = new User($this->db);
$userVictim->fetch($object->fk_user_victim);
$userEmployer = new User($this->db);
$userVictim = $this->getUserVictim();

$userEmployer->fetch($object->fk_user_employer);

//1 : Accident in DU / GP, 2 : Accident in society, 3 : Accident in another location
Expand Down
4 changes: 4 additions & 0 deletions class/actions_digiriskdolibarr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,10 @@ public function SaturneAdminDocumentData(array $parameters): int
'documentType' => 'informationssharing',
'picto' => 'fontawesome_fa-comment-dots_fas_#d35968'
],
'RegisterDocument' => [
'documentType' => 'registerdocument',
'picto' => 'fontawesome_fa-ticket-alt_fas_#d35968'
],
'ListingRisksAction' => [
'documentType' => 'listingrisksaction',
'picto' => 'fontawesome_fa-images_fas_#d35968'
Expand Down
163 changes: 163 additions & 0 deletions class/digiriskdolibarrdocuments/registerdocument.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php
/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* \file class/digiriskdocuments/registerdocument.class.php
* \ingroup digiriskdolibarr
* \brief This file is a class file for RegisterDocument
*/

// Load DigiriskDolibarr libraries
require_once __DIR__ . '/../digiriskdocuments.class.php';

/**
* Class for RegisterDocument
*/
class RegisterDocument extends DigiriskDocuments
{
/**
* @var string Module name.
*/
public $module = 'digiriskdolibarr';

/**
* @var string Element type of object.
*/
public $element = 'registerdocument';

/**
* Constructor.
*
* @param DoliDb $db Database handler.
*/
public function __construct(DoliDB $db)
{
parent::__construct($db, $this->module, $this->element);
}

/**
* Function for JSON filling before saving in database
*
* @return false|string
* @throws Exception
*/
public function RegisterDocumentFillJSON()
{
global $conf;

$resources = new DigiriskResources($this->db);
$digirisk_resources = $resources->fetchDigiriskResources();
$json = array();

// *** JSON FILLING ***
if (!empty ($digirisk_resources)) {
$labour_doctor_contact = new Contact($this->db);
$result = $labour_doctor_contact->fetch($digirisk_resources['LabourDoctorContact']->id[0]);
if ($result > 0) {
$json['RegisterDocument']['occupational_health_service']['id'] = $labour_doctor_contact->id;
$json['RegisterDocument']['occupational_health_service']['name'] = $labour_doctor_contact->firstname . " " . $labour_doctor_contact->lastname;
$json['RegisterDocument']['occupational_health_service']['phone'] = $labour_doctor_contact->phone_pro;
}

$labourInspectorContact = new Contact($this->db);
$result = $labourInspectorContact->fetch($digirisk_resources['LabourInspectorContact']->id[0]);

if ($result > 0) {
$json['RegisterDocument']['detective_work']['id'] = $labourInspectorContact->id;
$json['RegisterDocument']['detective_work']['name'] = $labourInspectorContact->firstname . " " . $labourInspectorContact->lastname;
$json['RegisterDocument']['detective_work']['phone'] = $labourInspectorContact->phone_pro;
}

$harassment_officer = new User($this->db);
$result = $harassment_officer->fetch($digirisk_resources['HarassmentOfficer']->id[0]);

if ($result > 0) {
$json['RegisterDocument']['harassment_officer']['id'] = $harassment_officer->id;
$json['RegisterDocument']['harassment_officer']['name'] = $harassment_officer->getFullName($langs);
$json['RegisterDocument']['harassment_officer']['phone'] = $harassment_officer->office_phone;
}

$harassment_officer_cse = new User($this->db);
$result = $harassment_officer_cse->fetch($digirisk_resources['HarassmentOfficerCSE']->id[0]);

if ($result > 0) {
$json['RegisterDocument']['harassment_officer_cse']['id'] = $harassment_officer_cse->id;
$json['RegisterDocument']['harassment_officer_cse']['name'] = $harassment_officer_cse->getFullName($langs);
$json['RegisterDocument']['harassment_officer_cse']['phone'] = $harassment_officer_cse->office_phone;
}

$json['RegisterDocument']['delegues_du_personnels_date'] = (dol_strlen($conf->global->DIGIRISKDOLIBARR_DP_ELECTION_DATE) > 0 && $conf->global->DIGIRISKDOLIBARR_DP_ELECTION_DATE != '--' ? $conf->global->DIGIRISKDOLIBARR_DP_ELECTION_DATE : '');
$json['RegisterDocument']['delegues_du_personnels_titulaires'] = '';
if (!empty ($digirisk_resources['TitularsDP']->id )) {
foreach ($digirisk_resources['TitularsDP']->id as $dp_titular) {

$dp_titulars = new User($this->db);
$result = $dp_titulars->fetch($dp_titular);
if ($result > 0) {
$json['RegisterDocument']['delegues_du_personnels_titulaires'] .= $dp_titulars->firstname . " " . $dp_titulars->lastname . '<br>';
$json['RegisterDocument']['delegues_du_personnels_titulairesFullName'] .= $dp_titulars->getNomUrl(1) . '<br>';
}
}
}

$json['RegisterDocument']['delegues_du_personnels_suppleants'] = '';
if (!empty ($digirisk_resources['AlternatesDP']->id )) {
foreach ($digirisk_resources['AlternatesDP']->id as $dp_alternate) {

$dp_alternates = new User($this->db);
$result = $dp_alternates->fetch($dp_alternate);
if ($result > 0) {
$json['RegisterDocument']['delegues_du_personnels_suppleants'] .= $dp_alternates->firstname . " " . $dp_alternates->lastname . '<br>';
$json['RegisterDocument']['delegues_du_personnels_suppleantsFullName'] .= $dp_alternates->getNomUrl(1) . '<br>';
}
}
}

// CSE
$json['RegisterDocument']['membres_du_comite_entreprise_date'] = (dol_strlen($conf->global->DIGIRISKDOLIBARR_CSE_ELECTION_DATE) > 0 && $conf->global->DIGIRISKDOLIBARR_CSE_ELECTION_DATE != '--' ? $conf->global->DIGIRISKDOLIBARR_CSE_ELECTION_DATE : '');
$json['RegisterDocument']['membres_du_comite_entreprise_titulaires'] = '';
if (!empty ($digirisk_resources['TitularsCSE']->id )) {
foreach ($digirisk_resources['TitularsCSE']->id as $cse_titular) {
$cse_titulars = new User($this->db);
$result = $cse_titulars->fetch($cse_titular);
if ($result > 0) {
$json['RegisterDocument']['membres_du_comite_entreprise_titulaires'] .= $cse_titulars->firstname . " " . $cse_titulars->lastname . '<br>';
$json['RegisterDocument']['membres_du_comite_entreprise_titulairesFullName'] .= $cse_titulars->getNomUrl(1) . '<br>';
}
}
}

$json['RegisterDocument']['membres_du_comite_entreprise_suppleants'] = '';
if (!empty ($digirisk_resources['AlternatesCSE']->id )) {
foreach ($digirisk_resources['AlternatesCSE']->id as $cse_alternate) {
$cse_alternates = new User($this->db);
$result = $cse_alternates->fetch($cse_alternate);
if ($result > 0) {
$json['RegisterDocument']['membres_du_comite_entreprise_suppleants'] .= $cse_alternates->firstname . " " . $cse_alternates->lastname . '<br>';
$json['RegisterDocument']['membres_du_comite_entreprise_suppleantsFullName'] .= $cse_alternates->getNomUrl(1) . '<br>';
}
}
}

$json = json_encode($json, JSON_UNESCAPED_UNICODE);
return $json;
}
else {
return -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,12 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa
$object = $moreParam['object'];
$accident = new Accident($this->db);
$accidentMetadata = new AccidentMetaData($this->db);
$victim = new User($this->db);
$signatory = new SaturneSignature($this->db, $this->module, $object->element);
$now = dol_now();

$accident->fetch($object->fk_accident);
$accidentMetadata->fetch(0, '', 'AND status = 1 AND fk_accident = ' . $accident->id);
$victim->fetch($accident->fk_user_victim);
$victim = $accident->getUserVictim();

$actionTask = saturne_fetch_all_object_type('SaturneTask', '', '', 2, 0, ['customsql' => 'fk_task_parent = ' . $object->fk_task]);
$curativeActionTask = array_shift($actionTask);
Expand Down
Loading

0 comments on commit c74d842

Please sign in to comment.