diff --git a/class/digiriskdolibarrdocuments/firepermitdocument.class.php b/class/digiriskdolibarrdocuments/firepermitdocument.class.php index 71ad64e6d..1620c8318 100644 --- a/class/digiriskdolibarrdocuments/firepermitdocument.class.php +++ b/class/digiriskdolibarrdocuments/firepermitdocument.class.php @@ -24,6 +24,10 @@ // Load Saturne libraries. require_once __DIR__ . '/../../../saturne/class/saturnedocuments.class.php'; +// Load DigiriskDolibarr libraries +require_once __DIR__ . '/../digiriskdocuments.class.php'; +require_once __DIR__ . '/../digiriskresources.class.php'; + /** * Class for FirePermitDocument. */ @@ -72,7 +76,11 @@ public function FirePermitDocumentFillJSON() $id = GETPOST('id'); if ($id > 0) { $firepermit->fetch($id); - } + } else { + $track_id = GETPOST('track_id', 'alpha'); + $signatory->fetch(0, '', ' AND signature_url =' . "'" . $track_id . "'"); + $firepermit->fetch($signatory->fk_object); + } $firepermitlines = $firepermitline->fetchAll('', '', 0, 0, array(), 'AND', GETPOST('id')); $preventionplanlines = $preventionplanline->fetchAll('', '', 0, 0, array(), 'AND', $firepermit->fk_preventionplan); diff --git a/class/firepermit.class.php b/class/firepermit.class.php index c688b95f2..ecda70221 100644 --- a/class/firepermit.class.php +++ b/class/firepermit.class.php @@ -27,6 +27,7 @@ // Load Saturne libraries. require_once __DIR__ . '/../../saturne/class/saturneobject.class.php'; +require_once __DIR__ . '/../../saturne/class/saturneschedules.class.php'; // Load DigiriskDolibarr libraries. @@ -66,7 +67,7 @@ class FirePermit extends SaturneObject */ public string $picto = 'fontawesome_fa-fire-alt_fas_#d35968'; - const STATUS_DELETED = 0; + const STATUS_DELETED = -1; const STATUS_DRAFT = 1; const STATUS_VALIDATED = 2; const STATUS_LOCKED = 3; @@ -77,25 +78,24 @@ class FirePermit extends SaturneObject */ public $lines = []; - /** - * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. - */ - public array $fields = [ - 'rowid' => ['type' => 'integer', 'label' => 'TechnicalID', 'enabled' => '1', 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => '1', 'index' => 1, 'comment' => "Id"], - 'ref' => ['type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => 1, 'noteditable' => '1', 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => '1', 'comment' => "Reference of object"], - 'ref_ext' => ['type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => '1', 'position' => 20, 'notnull' => 0, 'visible' => 0,], - 'entity' => ['type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 30, 'notnull' => 1, 'visible' => 0,], - 'date_creation' => ['type' => 'datetime', 'label' => 'DateCreation', 'enabled' => '1', 'position' => 40, 'notnull' => 1, 'visible' => 0,], - 'tms' => ['type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 50, 'notnull' => 0, 'visible' => 0,], - 'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => '1', 'position' => 70, 'notnull' => 0, 'visible' => 1, 'index' => 0,], - 'label' => ['type' => 'varchar(255)', 'label' => 'Label', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth200', 'help' => "Help text", 'showoncombobox' => '1',], - 'date_start' => ['type' => 'datetime', 'label' => 'StartDate', 'enabled' => '1', 'position' => 90, 'notnull' => -1, 'visible' => 1,], - 'date_end' => ['type' => 'datetime', 'label' => 'EndDate', 'enabled' => '1', 'position' => 100, 'notnull' => -1, 'visible' => 1,], - 'last_email_sent_date' => ['type' => 'datetime', 'label' => 'LastEmailSentDate', 'enabled' => '1', 'position' => 110, 'notnull' => -1, 'visible' => -2,], - 'fk_project' => ['type' => 'integer:Project:projet/class/project.class.php', 'label' => 'Project', 'enabled' => '1', 'position' => 115, 'notnull' => 1, 'visible' => 1,], - 'fk_user_creat' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => '1', 'position' => 120, 'notnull' => 1, 'visible' => 0, 'foreignkey' => 'user.rowid',], - 'fk_user_modif' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => '1', 'position' => 130, 'notnull' => -1, 'visible' => 0,], - 'fk_preventionplan' => ['type' => 'integer', 'label' => 'PreventionPlan', 'enabled' => '1', 'position' => 140, 'notnull' => -1, 'visible' => -2,], + /** + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor + */ + public $fields = [ + 'rowid' => ['type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'Id'], + 'ref' => ['type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' =>1, 'searchall' => 1, 'showoncombobox' => 1, 'validate' => 1, 'comment' => 'Reference of object'], + 'ref_ext' => ['type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'position' => 20, 'notnull' => 0, 'visible' => 0], + 'entity' => ['type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 0, 'index' => 1], + 'date_creation' => ['type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 40, 'notnull' => 1, 'visible' => 0], + 'tms' => ['type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 0], + 'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 180, 'notnull' => 1, 'visible' => 2, 'default' => 0, 'index' => 1, 'arrayofkeyval' => [1 => 'InProgress', 2 => 'ValidatePendingSignature', 3 => 'Locked', 4 => 'Archived']], + 'label' => ['type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 60, 'notnull' => 1, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'showoncombobox' => 2, 'validate' => 1, 'autofocusoncreate' => 1], + 'date_start' => ['type' => 'date', 'label' => 'DateStart', 'enabled' => 1, 'position' => 70, 'notnull' => 0, 'visible' => 1], + 'date_end' => ['type' => 'date', 'label' => 'DateEnd', 'enabled' => 1, 'position' => 80, 'notnull' => 0, 'visible' => 1], + 'fk_user_creat' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'picto' => 'user', 'enabled' => 1, 'position' => 140, 'notnull' => 1, 'visible' => 0, 'foreignkey' => 'user.rowid'], + 'fk_user_modif' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'picto' => 'user', 'enabled' => 1, 'position' => 150, 'notnull' => 0, 'visible' => 0, 'foreignkey' => 'user.rowid'], + 'fk_project' => ['type' => 'integer:Project:projet/class/project.class.php:1', 'label' => 'Project', 'picto' => 'project', 'enabled' => '$conf->project->enabled', 'position' => 85, 'notnull' => 1, 'visible' => 1, 'index' => 1, 'css' => 'maxwidth500 widthcentpercentminusxx', 'validate' => 1, 'foreignkey' => 'projet.rowid'], + 'fk_preventionplan' => ['type' => 'integer:PreventionPlan:digiriskdolibarr/class/preventionplan.class.php:1', 'label' => 'PreventionPlan', 'picto' => 'project', 'enabled' => 1, 'position' => 160, 'notnull' => 1, 'visible' => 1, 'index' => 1, 'css' => 'maxwidth500 widthcentpercentminusxx', 'validate' => 1, 'foreignkey' => 'preventionplan.rowid'], ]; public $rowid; @@ -108,11 +108,15 @@ class FirePermit extends SaturneObject public $label; public $date_start; public $date_end; - public $last_email_sent_date; public $fk_project; public $fk_user_creat; public $fk_user_modif; - public $fkPreventionPlan; + public $fk_preventionplan; + + /** + * @var string Name of subtable line + */ + public $table_element_line = 'digiriskdolibarr_firepermitdet'; /** * Constructor. @@ -124,151 +128,124 @@ public function __construct(DoliDB $db) parent::__construct($db, $this->module, $this->element); } - /** - * Clone an object into another one - * - * @param User $user User that creates - * @param int $fromid Id of object to clone - * @param $options - * @return mixed New object created, <0 if KO - * @throws Exception - */ - public function createFromClone(User $user, $fromid, $options) - { - global $conf, $moduleNameLowerCase; - $error = 0; + /** + * Clone an object into another one. + * + * @param User $user User that creates + * @param int $fromID ID of object to clone + * @param array $options Options array + * @return int New object created, <0 if KO + * @throws Exception + */ + public function createFromClone(User $user, int $fromID, array $options): int + { + global $conf, $moduleNameLowerCase; - $signatory = new SaturneSignature($this->db, $this->module, $this->element); - $digiriskresources = new DigiriskResources($this->db); - $saturneSchedules = new SaturneSchedules($this->db); + dol_syslog(__METHOD__, LOG_DEBUG); - dol_syslog(__METHOD__, LOG_DEBUG); + $object = new self($this->db); + $signatory = new SaturneSignature($this->db, $this->module, $this->element); + $digiriskResources = new DigiriskResources($this->db); - $object = new self($this->db); + $this->db->begin(); - $this->db->begin(); + // Load source object + $object->fetch($fromID); - // Load source object - $result = $object->fetchCommon($fromid); - if ($result > 0 && ! empty($object->table_element_line)) { - $object->fetchLines(); - } + // Load signatory and ressources form source object + $signatories = $signatory->fetchSignatory('', $fromID, $object->element); + $resources = $digiriskResources->fetchResourcesFromObject('', $object); - // Load openinghours form source object - $morewhere = ' AND element_id = ' . $object->id; - $morewhere .= ' AND element_type = ' . "'" . $object->element . "'"; - $morewhere .= ' AND status = 1'; - - $saturneSchedules->fetch(0, '', $morewhere); - - // Load signatory and ressources form source object - $signatories = $signatory->fetchSignatory("", $fromid, 'firepermit'); - $resources = $digiriskresources->fetchResourcesFromObject('', $object); - - if ( ! empty($signatories) && $signatories > 0) { - foreach ($signatories as $arrayRole) { - foreach ($arrayRole as $signatoryRole) { - $signatoriesID[$signatoryRole->role] = $signatoryRole->id; - if ($signatoryRole->role == 'ExtSocietyAttendant') { - $extIntervenantsIds[] = $signatoryRole->id; - } - } - } - } + if (!empty($signatories) && $signatories > 0) { + foreach ($signatories as $arrayRole) { + foreach ($arrayRole as $signatoryRole) { + $signatoriesID[$signatoryRole->role] = $signatoryRole->id; + if ($signatoryRole->role == 'ExtSocietyAttendant') { + $extIntervenantsIds[] = $signatoryRole->id; + } + } + } + } - // Load numbering modules - $numberingModules = [ - 'digiriskelement/' . $objectLine->element => $conf->global->DIGIRISKDOLIBARR_FIREPERMITDET_ADDON, - ]; + // Load numbering modules + $numberingModules = [ + 'digiriskelement/firepermit' => $conf->global->DIGIRISKDOLIBARR_FIREPERMIT_ADDON, + 'digiriskelement/firepermitdet' => $conf->global->DIGIRISKDOLIBARR_FIREPERMITDET_ADDON, + ]; + + list($refFirePermitMod, $refFirePermitDetMod) = saturne_require_objects_mod($numberingModules, $moduleNameLowerCase); + + // Reset some properties + unset($object->id); + unset($object->fk_user_creat); + unset($object->import_key); + + // Clear fields + $object->ref = $refFirePermitMod->getNextValue($object); + $object->label = $options['clone_label']; + $object->date_creation = dol_now(); + $object->status = self::STATUS_DRAFT; + + // Create clone + $object->context['createfromclone'] = 'createfromclone'; + $firePermitID = $object->create($user); + + if ($firePermitID > 0) { + $digiriskResources->setDigiriskResources($this->db, $user->id, 'ExtSociety', 'societe', [array_shift($resources['ExtSociety'])->id], $conf->entity, 'firepermit', $firePermitID, 1); + $digiriskResources->setDigiriskResources($this->db, $user->id, 'LabourInspector', 'societe', [array_shift($resources['LabourInspector'])->id], $conf->entity, 'firepermit', $firePermitID, 1); + $digiriskResources->setDigiriskResources($this->db, $user->id, 'LabourInspectorAssigned', 'socpeople', [array_shift($resources['LabourInspectorAssigned'])->id], $conf->entity, 'firepermit', $firePermitID, 1); + if (!empty($signatoriesID)) { + $signatory->createFromClone($user, $signatoriesID['MasterWorker'], $firePermitID); + $signatory->createFromClone($user, $signatoriesID['ExtSocietyResponsible'], $firePermitID); + } - list($refFirePermitDetMod) = saturne_require_objects_mod($numberingModules, $moduleNameLowerCase); + if (!empty($options['schedule'])) { + $saturneSchedules = new SaturneSchedules($this->db); - // Reset some properties - unset($object->id); - unset($object->fk_user_creat); - unset($object->import_key); + // Load openinghours form source object + $moreWhere = ' AND element_id = ' . $fromID; + $moreWhere .= ' AND element_type = ' . "'" . $object->element . "'"; + $moreWhere .= ' AND status = 1'; - // Clear fields - if (property_exists($object, 'ref')) { - $object->ref = $refFirePermitDetMod->getNextValue($object); - } - if (property_exists($object, 'ref_ext')) { - $object->ref_ext = 'digirisk_' . $object->ref; - } - if (property_exists($object, 'label')) { - $object->label = $options['clone_label']; - } - if (property_exists($object, 'date_creation')) { - $object->date_creation = dol_now(); - } - if (property_exists($object, 'status')) { - $object->status = 1; - } - - // Create clone - $object->context['createfromclone'] = 'createfromclone'; - $firepermtid = $object->create($user); - - if ($firepermtid > 0) { - $digiriskresources->setDigiriskResources($this->db, $user->id, 'ExtSociety', 'societe', array(array_shift($resources['ExtSociety'])->id), $conf->entity, 'firepermit', $firepermtid, 1); - $digiriskresources->setDigiriskResources($this->db, $user->id, 'LabourInspector', 'societe', array(array_shift($resources['LabourInspector'])->id), $conf->entity, 'firepermit', $firepermtid, 1); - $digiriskresources->setDigiriskResources($this->db, $user->id, 'LabourInspectorAssigned', 'socpeople', array(array_shift($resources['LabourInspectorAssigned'])->id), $conf->entity, 'firepermit', $firepermtid, 1); - if (!empty($signatoriesID)) { - $signatory->createFromClone($user, $signatoriesID['MasterWorker'], $firepermtid); - $signatory->createFromClone($user, $signatoriesID['ExtSocietyResponsible'], $firepermtid); - } - - if ( ! empty($options['schedule'])) { - if ( ! empty($saturneSchedules)) { - $saturneSchedules->element_id = $firepermtid; - $saturneSchedules->create($user); - } - } - - if ( ! empty($options['attendants'])) { - if ( ! empty($extIntervenantsIds) && $extIntervenantsIds > 0) { - foreach ($extIntervenantsIds as $extintervenant_id) { - $signatory->createFromClone($user, $extintervenant_id, $firepermtid); - } - } - } - - if ( ! empty($options['firepermit_risk'])) { - $num = (!empty($object->lines) ? count($object->lines) : 0); - for ($i = 0; $i < $num; $i++) { - $line = $object->lines[$i]; - if (property_exists($line, 'ref')) { - $line->ref = $line->getNextNumRef(); - } - $line->category = empty($line->category) ? 0 : $line->category; - $line->fk_firepermit = $firepermtid; - - $result = $line->insert($user, 1); - if ($result < 0) { - $this->error = $this->db->lasterror(); - $this->db->rollback(); - return -1; - } - } - } - } else { - $error++; - $this->error = $object->error; - $this->errors = $object->errors; - } + $saturneSchedules->fetch(0, '', $moreWhere); + if (!empty($saturneSchedules)) { + $saturneSchedules->element_type = 'firepermit'; + $saturneSchedules->element_id = $firePermitID; + $saturneSchedules->create($user); + } + } - unset($object->context['createfromclone']); + if (!empty($options['attendants'])) { + if (!empty($extIntervenantsIds) && $extIntervenantsIds > 0) { + foreach ($extIntervenantsIds as $extIntervenantID) { + $signatory->createFromClone($user, $extIntervenantID, $firePermitID); + } + } + } - // End - if ( ! $error) { - $this->db->commit(); - return $firepermtid; - } else { - $this->db->rollback(); - return -1; - } - } + if (!empty($options['firepermit_risk'])) { + if (is_array($object->lines) && !empty($object->lines)) { + foreach ($object->lines as $line) { + $line->ref = $refFirePermitDetMod->getNextValue($line); + $line->fk_firepermit = $firePermitID; + $line->create($user, 1); + } + } + } + } else { + $this->error = $object->error; + $this->errors = $object->errors; + } + // End + if (!$this->error) { + $this->db->commit(); + return $firePermitID; + } else { + $this->db->rollback(); + return -1; + } + } /** * Set in progress status @@ -398,22 +375,26 @@ class FirePermitLine extends SaturneObject */ public $table_element = 'digiriskdolibarr_firepermitdet'; - /** - * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. - */ - public $fields = array( - 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => '1', 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => '1', 'index' => 1, 'comment' => "Id"), - 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => 1, 'noteditable' => '1', 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => '1', 'comment' => "Reference of object"), - 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => '1', 'position' => 20, 'notnull' => 0, 'visible' => 0,), - 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 30, 'notnull' => 1, 'visible' => 0,), - 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => '1', 'position' => 40, 'notnull' => 1, 'visible' => 0,), - 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 50, 'notnull' => 0, 'visible' => 0,), - 'category' => array('type' => 'integer', 'label' => 'INRSRisk', 'enabled' => '1', 'position' => 60, 'notnull' => -1, 'visible' => -1,), - 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => '1', 'position' => 70, 'notnull' => -1, 'visible' => -1,), - 'used_equipment' => array('type' => 'text', 'label' => 'UsedEquipment', 'enabled' => '1', 'position' => 80, 'notnull' => -1, 'visible' => -1,), - 'fk_firepermit' => array('type' => 'integer', 'label' => 'FkPreventionPlan', 'enabled' => '1', 'position' => 90, 'notnull' => 1, 'visible' => 0,), - 'fk_element' => array('type' => 'integer', 'label' => 'FkElement', 'enabled' => '1', 'position' => 100, 'notnull' => 1, 'visible' => 0,), - ); + const STATUS_DELETED = -1; + const STATUS_VALIDATED = 1; + + /** + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. + */ + public $fields = [ + 'rowid' => ['type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'Id'], + 'ref' => ['type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' =>1, 'searchall' => 1, 'showoncombobox' => 1, 'validate' => 1, 'comment' => 'Reference of object'], + 'ref_ext' => ['type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'position' => 20, 'notnull' => 0, 'visible' => 0], + 'entity' => ['type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 0, 'index' => 1], + 'date_creation' => ['type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 40, 'notnull' => 1, 'visible' => 0], + 'tms' => ['type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 0], + 'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 110, 'notnull' => 1, 'visible' => 0, 'default' => 0, 'index' => 1], + 'category' => ['type' => 'integer', 'label' => 'INRSRisk', 'enabled' => 1, 'position' => 60, 'notnull' => -1, 'visible' => -1,], + 'description' => ['type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 70, 'notnull' => -1, 'visible' => -1,], + 'used_equipment' => ['type' => 'text', 'label' => 'UsedEquipment', 'enabled' => 1, 'position' => 80, 'notnull' => -1, 'visible' => -1,], + 'fk_firepermit' => ['type' => 'integer', 'label' => 'FkFirePermit', 'enabled' => 1, 'position' => 90, 'notnull' => 1, 'visible' => 0,], + 'fk_element' => ['type' => 'integer', 'label' => 'FkElement', 'enabled' => 1, 'position' => 100, 'notnull' => 1, 'visible' => 0,], + ]; public $rowid; public $ref; @@ -421,6 +402,7 @@ class FirePermitLine extends SaturneObject public $entity; public $date_creation; public $tms; + public $status; public $category; public $description; public $used_equipment; diff --git a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/firepermitdocument/doc_firepermitdocument_odt.modules.php b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/firepermitdocument/doc_firepermitdocument_odt.modules.php index 8e2d6e326..c2e1c59be 100644 --- a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/firepermitdocument/doc_firepermitdocument_odt.modules.php +++ b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/firepermitdocument/doc_firepermitdocument_odt.modules.php @@ -35,6 +35,7 @@ require_once __DIR__ . '/../../../../../class/riskanalysis/risk.class.php'; require_once __DIR__ . '/../../../../../class/riskanalysis/riskassessment.class.php'; require_once __DIR__ . '/../../../../../class/riskanalysis/risksign.class.php'; +require_once __DIR__ . '/../../../../../class/preventionplan.class.php'; /** * Class to build documents using ODF templates generator @@ -137,12 +138,8 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo $tmpArray['key_unique'] = $line->ref; $tmpArray['unite_travail'] = $digiriskelement->ref . " - " . $digiriskelement->label; $tmpArray['action'] = $line->description; - $tmpArray['risk_photo'] = DOL_DOCUMENT_ROOT . '/custom/digiriskdolibarr/img/categorieDangers/' . $risk->getDangerCategory( - $line - ) . '.png'; - $tmpArray['nomPicto'] = (!empty($conf->global->DIGIRISKDOLIBARR_DOCUMENT_SHOW_PICTO_NAME) ? $risk->getDangerCategoryName( - $line - ) : ' '); + $tmpArray['risk_photo'] = DOL_DOCUMENT_ROOT . '/custom/digiriskdolibarr/img/categorieDangers/' . $risk->getDangerCategory($line) . '.png'; + $tmpArray['nomPicto'] = (!empty($conf->global->DIGIRISKDOLIBARR_DOCUMENT_SHOW_PICTO_NAME) ? $risk->getDangerCategoryName($line) : ' '); $tmpArray['prevention'] = $line->prevention_method; $this->setTmpArrayVars($tmpArray, $listLines, $outputLangs); @@ -170,12 +167,8 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo $tmpArray['key_unique'] = $line->ref; $tmpArray['unite_travail'] = $digiriskelement->ref . " - " . $digiriskelement->label; $tmpArray['action'] = $line->description; - $tmpArray['type_de_travaux_photo'] = DOL_DOCUMENT_ROOT . '/custom/digiriskdolibarr/img/categorieDangers/' . $risk->getDangerCategory( - $line - ) . '.png'; - $tmpArray['nomPicto'] = (!empty($conf->global->DIGIRISKDOLIBARR_DOCUMENT_SHOW_PICTO_NAME) ? $risk->getDangerCategoryName( - $line - ) : ' '); + $tmpArray['type_de_travaux_photo'] = DOL_DOCUMENT_ROOT . '/custom/digiriskdolibarr/img/typeDeTravaux/' . $risk->getFirePermitDangerCategory($line) . '.png'; + $tmpArray['nomPictoT'] = (!empty($conf->global->DIGIRISKDOLIBARR_DOCUMENT_SHOW_PICTO_NAME) ? $risk->getFirePermitDangerCategoryName($line) : ' '); $tmpArray['materiel'] = $line->used_equipment; $this->setTmpArrayVars($tmpArray, $listLines, $outputLangs); @@ -279,205 +272,212 @@ public function setAttendantsSegment(Odf $odfHandler, Translate $outputLangs, ar } } - /** - * Function to build a document on disk. - * - * @param SaturneDocuments $objectDocument Object source to build document. - * @param Translate $outputLangs Lang object to use for output. - * @param string $srcTemplatePath Full path of source filename for generator using a template file. - * @param int $hideDetails Do not show line details. - * @param int $hideDesc Do not show desc. - * @param int $hideRef Do not show ref. - * @param array $moreParam More param (Object/user/etc). - * @return int 1 if OK, <=0 if KO. - * @throws Exception - */ - public function write_file(SaturneDocuments $objectDocument, Translate $outputLangs, string $srcTemplatePath, int $hideDetails = 0, int $hideDesc = 0, int $hideRef = 0, array $moreParam): int - { - global $conf, $langs, $moduleNameLowerCase; - - $object = $moreParam['object']; - - $saturneSchedules = new SaturneSchedules($this->db); - $firepermitline = new FirePermitLine($this->db); - $preventionplan = new PreventionPlan($this->db); - - $preventionplan->fetch($object->fk_preventionplan); - - $firepermitlines = $firepermitline->fetchAll('', '', 0, 0, ['fk_firepermit' => $object->id]); - - $tmpArray = []; - - $objectDocument->DigiriskFillJSON(); - - $objectDocument->element = $objectDocument->element . '@digiriskdolibarr'; - complete_substitutions_array($tmpArray, $outputLangs, $objectDocument); - $objectDocument->element = $objectDocument->element; - - $arrayData = json_decode($objectDocument->json); - $arrayData = (array) $arrayData->FirePermit; - - if (is_array($firepermitlines) && !empty($firepermitlines)) { - $tmpArray['interventions_info'] = count($firepermitlines) . ' ' . $langs->trans('FirePermitLine'); - } else { - $tmpArray['interventions_info'] = 0; - } - - if ( ! empty($extsocietyintervenants) && $extsocietyintervenants > 0 && is_array($extsocietyintervenants)) { - $tmpArray['intervenants_info'] = count($extsocietyintervenants); - } else { - $tmpArray['intervenants_info'] = 0; - } - - $tmpArray['pompier_number'] = $arrayData['pompier_number']; - $tmpArray['samu_number'] = $arrayData['samu_number']; - $tmpArray['emergency_number'] = $arrayData['emergency_number']; - $tmpArray['police_number'] = $arrayData['police_number']; - - $tmpArray['moyen_generaux_mis_disposition'] = $arrayData['moyen_generaux_mis_disposition']; - $tmpArray['consigne_generale'] = $arrayData['consigne_generale']; - $tmpArray['premiers_secours'] = $arrayData['premiers_secours']; - - $tmpArray['titre_permis_feu'] = $object->ref; - $tmpArray['raison_du_permis_feu'] = $object->label; - $tmpArray['titre_plan_prevention'] = $object->ref; - $tmpArray['raison_plan_prevention'] = $object->label; - - $tmpArray['prior_visit_date'] = dol_print_date($object->prior_visit_date, 'dayhoursec'); - $tmpArray['prior_visit_text'] = $object->prior_visit_text; - - $tmpArray['date_start_intervention_PPP'] = dol_print_date($preventionplan->date_start, 'dayhoursec'); - $tmpArray['date_end_intervention_PPP'] = dol_print_date($preventionplan->date_end, 'dayhoursec'); - - $tmpArray['date_start_intervention_FP'] = dol_print_date($object->date_start, 'dayhoursec'); - $tmpArray['date_end_intervention_FP'] = dol_print_date($object->date_end, 'dayhoursec'); - - $morewhere = ' AND element_id = ' . $object->id; - $morewhere .= ' AND element_type = ' . "'" . $object->element . "'"; - $morewhere .= ' AND status = 1'; - - $saturneSchedules->fetch(0, '', $morewhere); - - $opening_hours_monday = explode(' ', $saturneSchedules->monday); - $opening_hours_tuesday = explode(' ', $saturneSchedules->tuesday); - $opening_hours_wednesday = explode(' ', $saturneSchedules->wednesday); - $opening_hours_thursday = explode(' ', $saturneSchedules->thursday); - $opening_hours_friday = explode(' ', $saturneSchedules->friday); - $opening_hours_saturday = explode(' ', $saturneSchedules->saturday); - $opening_hours_sunday = explode(' ', $saturneSchedules->sunday); - - $tmpArray['lundi_matinF'] = $opening_hours_monday[0]; - $tmpArray['lundi_apremF'] = $opening_hours_monday[1]; - $tmpArray['mardi_matinF'] = $opening_hours_tuesday[0]; - $tmpArray['mardi_apremF'] = $opening_hours_tuesday[1]; - $tmpArray['mercredi_matinF'] = $opening_hours_wednesday[0]; - $tmpArray['mercredi_apremF'] = $opening_hours_wednesday[1]; - $tmpArray['jeudi_matinF'] = $opening_hours_thursday[0]; - $tmpArray['jeudi_apremF'] = $opening_hours_thursday[1]; - $tmpArray['vendredi_matinF'] = $opening_hours_friday[0]; - $tmpArray['vendredi_apremF'] = $opening_hours_friday[1]; - $tmpArray['samedi_matinF'] = $opening_hours_saturday[0]; - $tmpArray['samedi_apremF'] = $opening_hours_saturday[1]; - $tmpArray['dimanche_matinF'] = $opening_hours_sunday[0]; - $tmpArray['dimanche_apremF'] = $opening_hours_sunday[1]; - - $saturneSchedules = new SaturneSchedules($this->db); - - $morewherePreventionPlan = ' AND element_id = ' . $preventionplan->id; - $morewherePreventionPlan .= ' AND element_type = ' . "'" . $preventionplan->element . "'"; - $morewherePreventionPlan .= ' AND status = 1'; - - $saturneSchedules->fetch(0, '', $morewherePreventionPlan); - - $opening_hours_monday = explode(' ', $saturneSchedules->monday); - $opening_hours_tuesday = explode(' ', $saturneSchedules->tuesday); - $opening_hours_wednesday = explode(' ', $saturneSchedules->wednesday); - $opening_hours_thursday = explode(' ', $saturneSchedules->thursday); - $opening_hours_friday = explode(' ', $saturneSchedules->friday); - $opening_hours_saturday = explode(' ', $saturneSchedules->saturday); - $opening_hours_sunday = explode(' ', $saturneSchedules->sunday); - - $tmpArray['lundi_matin'] = $opening_hours_monday[0]; - $tmpArray['lundi_aprem'] = $opening_hours_monday[1]; - $tmpArray['mardi_matin'] = $opening_hours_tuesday[0]; - $tmpArray['mardi_aprem'] = $opening_hours_tuesday[1]; - $tmpArray['mercredi_matin'] = $opening_hours_wednesday[0]; - $tmpArray['mercredi_aprem'] = $opening_hours_wednesday[1]; - $tmpArray['jeudi_matin'] = $opening_hours_thursday[0]; - $tmpArray['jeudi_aprem'] = $opening_hours_thursday[1]; - $tmpArray['vendredi_matin'] = $opening_hours_friday[0]; - $tmpArray['vendredi_aprem'] = $opening_hours_friday[1]; - $tmpArray['samedi_matin'] = $opening_hours_saturday[0]; - $tmpArray['samedi_aprem'] = $opening_hours_saturday[1]; - $tmpArray['dimanche_matin'] = $opening_hours_sunday[0]; - $tmpArray['dimanche_aprem'] = $opening_hours_sunday[1]; - - - //Informations entreprise extérieure - $extsociety = $arrayData['society_outside']; - - if ( ! empty($extsociety) && $extsociety > 0) { - $tmpArray['society_title'] = $extsociety->name; - $tmpArray['society_siret_id'] = $extsociety->idprof2; - $tmpArray['society_address'] = $extsociety->address; - $tmpArray['society_postcode'] = $extsociety->zip; - $tmpArray['society_town'] = $extsociety->town; - } - - if ( ! empty($extsocietyintervenants) && $extsocietyintervenants > 0 && is_array($extsocietyintervenants)) { - $tmpArray['intervenants_info'] = count($extsocietyintervenants); - } else { - $tmpArray['intervenants_info'] = 0; - } - - $tempdir = $conf->digiriskdolibarr->multidir_output[isset($object->entity) ? $object->entity : 1] . '/temp/'; - - $maitreoeuvre = $arrayData['maitre_oeuvre']; - - //Signatures - if ( ! empty($maitreoeuvre) && $maitreoeuvre > 0) { - $tmpArray['maitre_oeuvre_lname'] = $maitreoeuvre->lastname; - $tmpArray['maitre_oeuvre_fname'] = $maitreoeuvre->firstname; - $tmpArray['maitre_oeuvre_email'] = $maitreoeuvre->email; - $tmpArray['maitre_oeuvre_phone'] = $maitreoeuvre->phone; - - $tmpArray['maitre_oeuvre_signature_date'] = dol_print_date($maitreoeuvre->signature_date, 'dayhoursec'); - if ((!preg_match('/specimen/i', $tempfilepath[1]) && $object->status >= $object::STATUS_LOCKED)) { - $encoded_image = explode(",", $maitreoeuvre->signature)[1]; - $decoded_image = base64_decode($encoded_image); - file_put_contents($tempdir . "signature.png", $decoded_image); - $tmpArray['maitre_oeuvre_signature'] = $tempdir . "signature.png"; - } else { - $tmpArray['maitre_oeuvre_signature'] = ''; - } - } - - $extsocietyresponsible = $arrayData['responsable_exterieur']; - - if ( ! empty($extsocietyresponsible) && $extsocietyresponsible > 0) { - $tmpArray['intervenant_exterieur_lname'] = $extsocietyresponsible->lastname; - $tmpArray['intervenant_exterieur_fname'] = $extsocietyresponsible->firstname; - $tmpArray['intervenant_exterieur_email'] = $extsocietyresponsible->email; - $tmpArray['intervenant_exterieur_phone'] = $extsocietyresponsible->phone; - - $tmpArray['intervenant_exterieur_signature_date'] = dol_print_date($extsocietyresponsible->signature_date, 'dayhoursec'); - if ((!preg_match('/specimen/i', $tempfilepath[1]) && $object->status >= $object::STATUS_LOCKED)) { - $encoded_image = explode(",", $extsocietyresponsible->signature)[1]; - $decoded_image = base64_decode($encoded_image); - file_put_contents($tempdir . "signature2.png", $decoded_image); - $tmpArray['intervenant_exterieur_signature'] = $tempdir . "signature2.png"; - } else { - $tmpArray['intervenant_exterieur_signature'] = ''; - } - } - - $moreParam['tmparray'] = $tmpArray; - - $moreParam['tmparray'] = $tmpArray; - $moreParam['subDir'] = 'digiriskdolibarrdocuments/'; - $moreParam['hideTemplateName'] = 1; - - return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam); - } - + /** + * Function to build a document on disk + * + * @param SaturneDocuments $objectDocument Object source to build document + * @param Translate $outputLangs Lang object to use for output + * @param string $srcTemplatePath Full path of source filename for generator using a template file + * @param int $hideDetails Do not show line details + * @param int $hideDesc Do not show desc + * @param int $hideRef Do not show ref + * @param array $moreParam More param (Object/user/etc) + * @return int 1 if OK, <=0 if KO + * @throws Exception + */ + public function write_file(SaturneDocuments $objectDocument, Translate $outputLangs, string $srcTemplatePath, int $hideDetails = 0, int $hideDesc = 0, int $hideRef = 0, array $moreParam): int + { + global $conf, $langs; + + $object = $moreParam['object']; + + $saturneSchedules = new SaturneSchedules($this->db); + $preventionPlan = new PreventionPlan($this->db); + + $preventionPlan->fetch($object->fk_preventionplan); + + $tmpArray = []; + + $objectDocument->DigiriskFillJSON(); + + $objectDocument->element = $objectDocument->element . '@digiriskdolibarr'; + complete_substitutions_array($tmpArray, $outputLangs, $objectDocument); + $objectDocument->element = $objectDocument->element; + + $arrayData = json_decode($objectDocument->json); + $arrayData = (array) $arrayData->FirePermit; + + $tmpArray['titre_permis_feu'] = $object->ref; + $tmpArray['raison_du_permis_feu'] = $object->label; + + $tmpArray['pompier_number'] = $arrayData['pompier_number']; + $tmpArray['samu_number'] = $arrayData['samu_number']; + $tmpArray['emergency_number'] = $arrayData['emergency_number']; + $tmpArray['police_number'] = $arrayData['police_number']; + + $tmpArray['moyen_generaux_mis_disposition'] = $arrayData['moyen_generaux_mis_disposition']; + $tmpArray['consigne_generale'] = $arrayData['consigne_generale']; + $tmpArray['premiers_secours'] = $arrayData['premiers_secours']; + + $tmpArray['titre_plan_prevention'] = $preventionPlan->ref; + $tmpArray['raison_plan_prevention'] = $preventionPlan->label; + $tmpArray['date_start_intervention_PPP'] = dol_print_date($preventionPlan->date_start, 'dayhour'); + $tmpArray['date_end_intervention_PPP'] = dol_print_date($preventionPlan->date_end, 'dayhour'); + + $moreWhere = ' AND element_id = ' . $preventionPlan->id; + $moreWhere .= ' AND element_type = ' . "'" . $preventionPlan->element . "'"; + $moreWhere .= ' AND status = 1'; + + $saturneSchedules->fetch(0, '', $moreWhere); + + $opening_hours_monday = explode(' ', $saturneSchedules->monday); + $opening_hours_tuesday = explode(' ', $saturneSchedules->tuesday); + $opening_hours_wednesday = explode(' ', $saturneSchedules->wednesday); + $opening_hours_thursday = explode(' ', $saturneSchedules->thursday); + $opening_hours_friday = explode(' ', $saturneSchedules->friday); + $opening_hours_saturday = explode(' ', $saturneSchedules->saturday); + $opening_hours_sunday = explode(' ', $saturneSchedules->sunday); + + $tmpArray['lundi_matin'] = $opening_hours_monday[0]; + $tmpArray['lundi_aprem'] = $opening_hours_monday[1]; + $tmpArray['mardi_matin'] = $opening_hours_tuesday[0]; + $tmpArray['mardi_aprem'] = $opening_hours_tuesday[1]; + $tmpArray['mercredi_matin'] = $opening_hours_wednesday[0]; + $tmpArray['mercredi_aprem'] = $opening_hours_wednesday[1]; + $tmpArray['jeudi_matin'] = $opening_hours_thursday[0]; + $tmpArray['jeudi_aprem'] = $opening_hours_thursday[1]; + $tmpArray['vendredi_matin'] = $opening_hours_friday[0]; + $tmpArray['vendredi_aprem'] = $opening_hours_friday[1]; + $tmpArray['samedi_matin'] = $opening_hours_saturday[0]; + $tmpArray['samedi_aprem'] = $opening_hours_saturday[1]; + $tmpArray['dimanche_matin'] = $opening_hours_sunday[0]; + $tmpArray['dimanche_aprem'] = $opening_hours_sunday[1]; + + if (is_array($preventionPlan->lines) && !empty($preventionPlan->lines)) { + $tmpArray['interventions_info'] = count($preventionPlan->lines) . ' ' . $langs->trans('PreventionPlanLine'); + } else { + $tmpArray['interventions_info'] = 0; + } + + $tmpArray['date_start_intervention_FP'] = dol_print_date($object->date_start, 'dayhour'); + $tmpArray['date_end_intervention_FP'] = dol_print_date($object->date_end, 'dayhour'); + + if (is_array($object->lines) && !empty($object->lines)) { + $tmpArray['interventions_info_FP'] = count($object->lines) . ' ' . $langs->trans('FirePermitLine'); + } else { + $tmpArray['interventions_info_FP'] = 0; + } + + $moreWhere = ' AND element_id = ' . $object->id; + $moreWhere .= ' AND element_type = ' . "'" . $object->element . "'"; + $moreWhere .= ' AND status = 1'; + + $saturneSchedules->fetch(0, '', $moreWhere); + + $opening_hours_monday = explode(' ', $saturneSchedules->monday); + $opening_hours_tuesday = explode(' ', $saturneSchedules->tuesday); + $opening_hours_wednesday = explode(' ', $saturneSchedules->wednesday); + $opening_hours_thursday = explode(' ', $saturneSchedules->thursday); + $opening_hours_friday = explode(' ', $saturneSchedules->friday); + $opening_hours_saturday = explode(' ', $saturneSchedules->saturday); + $opening_hours_sunday = explode(' ', $saturneSchedules->sunday); + + $tmpArray['lundi_matinF'] = $opening_hours_monday[0]; + $tmpArray['lundi_apremF'] = $opening_hours_monday[1]; + $tmpArray['mardi_matinF'] = $opening_hours_tuesday[0]; + $tmpArray['mardi_apremF'] = $opening_hours_tuesday[1]; + $tmpArray['mercredi_matinF'] = $opening_hours_wednesday[0]; + $tmpArray['mercredi_apremF'] = $opening_hours_wednesday[1]; + $tmpArray['jeudi_matinF'] = $opening_hours_thursday[0]; + $tmpArray['jeudi_apremF'] = $opening_hours_thursday[1]; + $tmpArray['vendredi_matinF'] = $opening_hours_friday[0]; + $tmpArray['vendredi_apremF'] = $opening_hours_friday[1]; + $tmpArray['samedi_matinF'] = $opening_hours_saturday[0]; + $tmpArray['samedi_apremF'] = $opening_hours_saturday[1]; + $tmpArray['dimanche_matinF'] = $opening_hours_sunday[0]; + $tmpArray['dimanche_apremF'] = $opening_hours_sunday[1]; + + // Information external society + $extSociety = $arrayData['society_outside']; + if (!empty($extSociety) && $extSociety > 0) { + $tmpArray['society_title'] = $extSociety->name; + $tmpArray['society_siret_id'] = $extSociety->idprof2; + $tmpArray['society_address'] = $extSociety->address; + $tmpArray['society_postcode'] = $extSociety->zip; + $tmpArray['society_town'] = $extSociety->town; + } + + $extSocietyIntervenants = (array) $arrayData['intervenant_exterieur']; + if (!empty($extSocietyIntervenants)) { + $tmpArray['intervenants_info'] = count($extSocietyIntervenants); + } else { + $tmpArray['intervenants_info'] = 0; + } + + $tempDir = $conf->digiriskdolibarr->multidir_output[$object->entity ?? 1] . '/temp/'; + + // MasterWorker + $masterWorker = $arrayData['maitre_oeuvre']; + if (!empty($masterWorker) && $masterWorker > 0) { + $tmpArray['maitre_oeuvre_lname'] = strtoupper($masterWorker->lastname); + $tmpArray['maitre_oeuvre_fname'] = ucfirst($masterWorker->firstname); + $tmpArray['maitre_oeuvre_email'] = $masterWorker->email; + $tmpArray['maitre_oeuvre_phone'] = $masterWorker->phone; + $tmpArray['maitre_oeuvre_signature_date'] = dol_print_date($masterWorker->signature_date, 'dayhour', 'tzuser'); + } else { + $tmpArray['maitre_oeuvre_lname'] = ''; + $tmpArray['maitre_oeuvre_fname'] = ''; + $tmpArray['maitre_oeuvre_email'] = ''; + $tmpArray['maitre_oeuvre_phone'] = ''; + $tmpArray['maitre_oeuvre_signature_date'] = ''; + } + + if (dol_strlen($masterWorker->signature) > 0 && $masterWorker->signature != $langs->transnoentities('FileGenerated')) { + if ($moreParam['specimen'] == 0 || ($moreParam['specimen'] == 1 && $conf->global->DIGIRISKDOLIBARR_SHOW_SIGNATURE_SPECIMEN == 1)) { + $encodedImage = explode(',', $masterWorker->signature)[1]; + $decodedImage = base64_decode($encodedImage); + file_put_contents($tempDir . 'signature.png', $decodedImage); + $tmpArray['maitre_oeuvre_signature'] = $tempDir . 'signature.png'; + } else { + $tmpArray['maitre_oeuvre_signature'] = ''; + } + } else { + $tmpArray['maitre_oeuvre_signature'] = ''; + } + + // External society responsible + $extSocietyResponsible = $arrayData['responsable_exterieur']; + if (!empty($extSocietyResponsible) && $extSocietyResponsible > 0) { + $tmpArray['intervenant_exterieur_lname'] = strtoupper($extSocietyResponsible->lastname); + $tmpArray['intervenant_exterieur_fname'] = ucfirst($extSocietyResponsible->firstname); + $tmpArray['intervenant_exterieur_email'] = $extSocietyResponsible->email; + $tmpArray['intervenant_exterieur_phone'] = $extSocietyResponsible->phone; + $tmpArray['intervenant_exterieur_signature_date'] = dol_print_date($extSocietyResponsible->signature_date, 'dayhour', 'tzuser'); + } else { + $tmpArray['intervenant_exterieur_lname'] = ''; + $tmpArray['intervenant_exterieur_fname'] = ''; + $tmpArray['intervenant_exterieur_email'] = ''; + $tmpArray['intervenant_exterieur_phone'] = ''; + $tmpArray['intervenant_exterieur_signature_date'] = ''; + } + + if (dol_strlen($extSocietyResponsible->signature) > 0 && $extSocietyResponsible->signature != $langs->transnoentities('FileGenerated')) { + if ($moreParam['specimen'] == 0 || ($moreParam['specimen'] == 1 && $conf->global->DIGIRISKDOLIBARR_SHOW_SIGNATURE_SPECIMEN == 1)) { + $encodedImage = explode(',', $extSocietyResponsible->signature)[1]; + $decodedImage = base64_decode($encodedImage); + file_put_contents($tempDir . 'signature2.png', $decodedImage); + $tmpArray['intervenant_exterieur_signature'] = $tempDir . 'signature2.png'; + } else { + $tmpArray['intervenant_exterieur_signature'] = ''; + } + } else { + $tmpArray['intervenant_exterieur_signature'] = ''; + } + + $moreParam['tmparray'] = $tmpArray; + $moreParam['subDir'] = 'digiriskdolibarrdocuments/'; + $moreParam['hideTemplateName'] = 1; + + return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam); + } } diff --git a/sql/firepermit/llx_digiriskdolibarr_firepermit.sql b/sql/firepermit/llx_digiriskdolibarr_firepermit.sql index 7cf0a649c..d68e1f2da 100644 --- a/sql/firepermit/llx_digiriskdolibarr_firepermit.sql +++ b/sql/firepermit/llx_digiriskdolibarr_firepermit.sql @@ -14,19 +14,18 @@ -- along with this program. If not, see https://www.gnu.org/licenses/. CREATE TABLE llx_digiriskdolibarr_firepermit( - rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, - ref varchar(128) NOT NULL, - ref_ext varchar(128), - entity integer DEFAULT 1 NOT NULL, - date_creation datetime NOT NULL, - tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - status smallint, - label varchar(255) NOT NULL, - date_start datetime NOT NULL, - date_end datetime, - last_email_sent_date datetime DEFAULT NULL, - fk_project integer, - fk_user_creat integer NOT NULL, - fk_user_modif integer, - fk_preventionplan integer + rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, + ref varchar(128) NOT NULL, + ref_ext varchar(128), + entity integer DEFAULT 1 NOT NULL, + date_creation datetime NOT NULL, + tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + status integer NOT NULL, + label varchar(255) NOT NULL, + date_start datetime, + date_end datetime, + fk_user_creat integer NOT NULL, + fk_user_modif integer, + fk_project integer NOT NULL, + fk_preventionplan integer NOT NULL ) ENGINE=innodb; diff --git a/sql/firepermit/llx_digiriskdolibarr_firepermitdet.sql b/sql/firepermit/llx_digiriskdolibarr_firepermitdet.sql index 90edc2dfe..79584ae07 100644 --- a/sql/firepermit/llx_digiriskdolibarr_firepermitdet.sql +++ b/sql/firepermit/llx_digiriskdolibarr_firepermitdet.sql @@ -14,15 +14,16 @@ -- along with this program. If not, see https://www.gnu.org/licenses/. CREATE TABLE llx_digiriskdolibarr_firepermitdet( - rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, - ref varchar(128) NOT NULL, - ref_ext varchar(128), - entity integer DEFAULT 1 NOT NULL, - date_creation datetime NOT NULL, - tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - description text, - category varchar(255), - used_equipment text, - fk_firepermit integer NOT NULL, - fk_element integer NOT NULL + rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, + ref varchar(128) NOT NULL, + ref_ext varchar(128), + entity integer DEFAULT 1 NOT NULL, + date_creation datetime NOT NULL, + tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + status integer NOT NULL, + description text, + category varchar(255), + used_equipment text, + fk_firepermit integer NOT NULL, + fk_element integer NOT NULL ) ENGINE=innodb; diff --git a/sql/update.sql b/sql/update.sql index 903940c8f..10824b042 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -196,6 +196,13 @@ ALTER TABLE llx_digiriskdolibarr_preventionplan CHANGE `fk_project` `fk_project` ALTER TABLE llx_digiriskdolibarr_preventionplan DROP COLUMN `last_email_sent_date`; ALTER TABLE llx_digiriskdolibarr_preventionplandet ADD status INTEGER NOT NULL AFTER tms; +-- ALTER TABLE llx_digiriskdolibarr_firepermit CHANGE `status` `status` INT(11) NOT NULL; +ALTER TABLE llx_digiriskdolibarr_firepermit CHANGE `date_start` `date_start` DATETIME NULL; +ALTER TABLE llx_digiriskdolibarr_firepermit CHANGE `fk_project` `fk_project` INT(11) NOT NULL; +ALTER TABLE llx_digiriskdolibarr_firepermit CHANGE `fk_preventionplan` `fk_preventionplan` INT(11) NOT NULL; +ALTER TABLE llx_digiriskdolibarr_firepermit DROP COLUMN `last_email_sent_date`; +ALTER TABLE llx_digiriskdolibarr_firepermitdet ADD status INTEGER NOT NULL AFTER tms; + ALTER TABLE llx_c_accident_investigation_attendants_role RENAME TO llx_c_accidentinvestigation_attendants_role; ALTER TABLE llx_categorie_accident_investigation RENAME TO llx_categorie_accidentinvestigation; ALTER TABLE llx_categorie_accidentinvestigation CHANGE `fk_accident_investigation` `fk_accidentinvestigation`; diff --git a/view/firepermit/firepermit_card.php b/view/firepermit/firepermit_card.php index c26fe71e6..65905d4fc 100644 --- a/view/firepermit/firepermit_card.php +++ b/view/firepermit/firepermit_card.php @@ -170,6 +170,7 @@ $object->import_key = ""; $object->status = 1; $object->label = $label; + $object->status = FirePermit::STATUS_DRAFT; $object->description = $description; $object->fk_project = $project; @@ -386,6 +387,7 @@ $objectLine->date_creation = $object->db->idate($now); $objectLine->ref = $refFirePermitDetMod->getNextValue($objectLine); $objectLine->entity = $conf->entity; + $objectLine->status = FirePermitLine::STATUS_VALIDATED; $objectLine->description = $actionsDescription; $objectLine->category = $riskCategoryId; $objectLine->used_equipment = $usedEquipment; @@ -469,7 +471,7 @@ // Action to delete line if ($action == 'deleteline' && $permissiontodelete) { $objectLine->fetch($lineid); - $result = $objectLine->delete($user, false); + $result = $objectLine->delete($user, false, false); if ($result > 0) { // Deletion fire permit line OK setEventMessages($langs->trans('DeleteFirePermitLine') . ' ' . $objectLine->ref . ' ' . $langs->trans('FirePermitMessage'), array()); @@ -484,6 +486,8 @@ } } + // Actions set_thirdparty, set_project + require_once __DIR__ . '/../../../saturne/core/tpl/actions/banner_actions.tpl.php'; // Actions builddoc, forcebuilddoc, remove_file. require_once __DIR__ . '/../../../saturne/core/tpl/documents/documents_action.tpl.php'; @@ -640,12 +644,12 @@ //Project -- projet print '