Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3540 [Accident] add: accident register document #3546

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8b20f53
#35540 [Accident] add: accident register document
Nov 17, 2023
48b22b8
#1665 [RegisterDocument] fix: odt template
Nov 17, 2023
7c2e32b
#3540 [Accident] fix: move lesions to first page and add counter in g…
Nov 17, 2023
862a119
#3540 [Accident] add: attendants tab & workflow
Nov 17, 2023
88992b1
#3540 [Accident] add: odt first version
Nov 17, 2023
235a86c
Merge remote-tracking branch 'evarisk-theo/add_ticket_register_accide…
Nov 20, 2023
6d9946e
#35540 [RegisterDocument] fix: register document data
Nov 20, 2023
b0b4cd3
#3540 [Accident] fix: add lesions and workstop conditions
Nov 23, 2023
8a42383
#3540 [Accident] fix: draft status color
Nov 23, 2023
6365cec
#3540 [Accident] fix: remove fk_user_victim field & backward compatib…
Nov 23, 2023
2f0d57f
#3540 [RegisterDocument] add: controllers table
Nov 24, 2023
116909c
#3540 [AccidentLesion] fix: module numref
evarisk-theo Nov 30, 2023
06f4ac2
#3540 [AccidentLesion] fix: accident status permissions for edition &…
evarisk-theo Nov 30, 2023
d91e115
#3540 [RegisterDocument] fix: document creation date
evarisk-theo Nov 30, 2023
2d1a290
#3540 [Ticket] fix: condition to show ticket extrafields configuration
evarisk-theo Nov 30, 2023
33edc04
#3540 [Ticket] fix: remove duplicate confs
evarisk-theo Nov 30, 2023
7efe9b1
#3540 [Ticket] fix: conf ticket extrafields on entity 0
evarisk-theo Nov 30, 2023
37c0dd3
#3540 [Accident] fix: formconfirm bold
evarisk-theo Nov 30, 2023
04d613d
#3540 [Accident] fix: button labels
evarisk-theo Nov 30, 2023
be9c91c
#3540 [AccidentInvestigation] fix: victim fetch
evarisk-theo Nov 30, 2023
d3c1082
#3540 [Accident] fix: fk_user_victim backward compatibility
evarisk-theo Nov 30, 2023
d3dac1d
#3540 [Ticket] fix: remove accident lesion tab
evarisk-theo Nov 30, 2023
27bc5e7
#3540 [AccidentInvestigation] fix: get user victim
evarisk-theo Nov 30, 2023
16d066e
#3540 [RegisterDocument] fix: set empty values in doc
evarisk-theo Nov 30, 2023
3b853eb
#3540 [RegisterDocument] fix: event on generation
evarisk-theo Nov 30, 2023
d93456b
Merge branch 'develop' into add_accident_register_document
evarisk-theo Nov 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -351,26 +349,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 @@ -670,6 +669,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 @@ -682,9 +699,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 @@ -898,6 +898,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;
}
}
}
Loading