Skip to content

Commit

Permalink
Evarisk#3693 [ODT] fix: rename conf and improve ODT write file
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Mar 21, 2024
1 parent 6dc425f commit 7b0ba5b
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 187 deletions.
44 changes: 22 additions & 22 deletions admin/config/riskassessmentdocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@
'description' => 'ShowRiskAssessmentDateDescription',
'code' => 'DIGIRISKDOLIBARR_SHOW_RISKASSESSMENT_DATE',
],
'ShowRiskAssessmentDateOnDocument' => [
'name' => 'ShowRiskAssessmentDateOnDocument',
'description' => 'ShowDocumentDateDescription',
'code' => 'DIGIRISKDOLIBARR_SHOW_DOCUMENT_RISKASSESSMENT_DATE',
],
'RiskAssessmentHideDateInDocument' => [
'name' => 'RiskAssessmentHideDateInDocument',
'description' => 'RiskAssessmentHideDateInDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_RISKASSESSMENT_HIDE_DATE_IN_DOCUMENT',
]
];

require __DIR__ . '/../../../saturne/core/tpl/admin/object/object_const_view.tpl.php';
Expand Down Expand Up @@ -323,26 +323,26 @@
'description' => 'ShowAllTasksDescription',
'code' => 'DIGIRISKDOLIBARR_SHOW_ALL_TASKS',
],
'HideRefTaskDocument' => [
'name' => 'HideRefTaskDocument',
'description' => 'HideRefTaskDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_HIDE_TASK_REF_DOCUMENT',
],
'HideResponsibleTaskDocument' => [
'name' => 'HideResponsibleTaskDocument',
'description' => 'HideResponsibleTaskDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_HIDE_TASK_RESPONSIBLE_DOCUMENT',
'TaskHideRefInDocument' => [
'name' => 'TaskHideRefInDocument',
'description' => 'TaskHideRefInDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_TASK_HIDE_REF_IN_DOCUMENT',
],
'HideDateTaskDocument' => [
'name' => 'HideDateTaskDocument',
'description' => 'HideDateTaskDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_HIDE_TASK_DATE_DOCUMENT',
'TaskHideResponsibleInDocument' => [
'name' => 'TaskHideResponsibleInDocument',
'description' => 'TaskHideResponsibleInDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_TASK_HIDE_RESPONSIBLE_IN_DOCUMENT',
],
'HideBudgetTaskDocument' => [
'name' => 'HideBudgetTaskDocument',
'description' => 'HideBudgetTaskDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_HIDE_TASK_BUDGET_DOCUMENT',
'TaskHideDateInDocument' => [
'name' => 'TaskHideDateInDocument',
'description' => 'TaskHideDateInDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_TASK_HIDE_DATE_IN_DOCUMENT',
],
'TaskHideBudgetInDocument' => [
'name' => 'TaskHideBudgetInDocument',
'description' => 'TaskHideBudgetInDocumentDescription',
'code' => 'DIGIRISKDOLIBARR_TASK_HIDE_BUDGET_IN_DOCUMENT',
]
];

require __DIR__ . '/../../../saturne/core/tpl/admin/object/object_const_view.tpl.php';
Expand Down
20 changes: 10 additions & 10 deletions class/digiriskdocuments.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ public function fillRiskData($odfHandler, $object, $outputlangs, $tmparray, $fil
$tmparray['quotationRisque'] = $lastEvaluation->cotation ?: 0;
$tmparray['descriptionRisque'] = $line->description;

if (getDolGlobalInt('DIGIRISKDOLIBARR_SHOW_DOCUMENT_RISKASSESSMENT_DATE') > 0 && !empty($lastEvaluation->comment)) {
$tmparray['commentaireEvaluation'] = dol_print_date((getDolGlobalInt('DIGIRISKDOLIBARR_SHOW_RISKASSESSMENT_DATE') > 0 && !empty($lastEvaluation->date_riskassessment) ? $lastEvaluation->date_riskassessment : $lastEvaluation->date_creation), 'dayreduceformat') . ': ';
if (!getDolGlobalInt('DIGIRISKDOLIBARR_RISKASSESSMENT_HIDE_DATE_IN_DOCUMENT') && dol_strlen($lastEvaluation->comment)) {
$tmparray['commentaireEvaluation'] = dol_print_date((getDolGlobalInt('DIGIRISKDOLIBARR_SHOW_RISKASSESSMENT_DATE') && !empty($lastEvaluation->date_riskassessment) ? $lastEvaluation->date_riskassessment : $lastEvaluation->date_creation), 'dayreduceformat') . ': ';
} else {
$tmparray['commentaireEvaluation'] = '';
}
Expand Down Expand Up @@ -291,13 +291,13 @@ public function fillRiskData($odfHandler, $object, $outputlangs, $tmparray, $fil

if ($task_progress == 100) {
if ($conf->global->DIGIRISKDOLIBARR_WORKUNITDOCUMENT_SHOW_TASK_DONE > 0) {
if (empty(getDolGlobalInt('DIGIRISKDOLIBARR_HIDE_TASK_REF_DOCUMENT'))) {
if (!getDolGlobalInt('DIGIRISKDOLIBARR_TASK_HIDE_REF_IN_DOCUMENT')) {
(($related_task->ref) ? $tmparray['actionPreventionCompleted'] .= $langs->trans('Ref') . ' : ' . $related_task->ref . "\n" : '');
}
if (empty(getDolGlobalInt('DIGIRISKDOLIBARR_HIDE_TASK_RESPONSIBLE_DOCUMENT'))) {
if (!getDolGlobalInt('DIGIRISKDOLIBARR_TASK_HIDE_RESPONSIBLE_IN_DOCUMENT')) {
(($responsible) ? $tmparray['actionPreventionCompleted'] .= $langs->trans('Responsible') . ' : ' . $responsible . "\n" : '');
}
if (empty(getDolGlobalInt('DIGIRISKDOLIBARR_HIDE_TASK_DATE_DOCUMENT'))) {
if (!getDolGlobalInt('DIGIRISKDOLIBARR_TASK_HIDE_DATE_IN_DOCUMENT')) {
$tmparray['actionPreventionCompleted'] .= $langs->trans('DateStart') . ' : ';
if ($conf->global->DIGIRISKDOLIBARR_SHOW_TASK_START_DATE && !empty($related_task->dateo)) {
$tmparray['actionPreventionCompleted'] .= dol_print_date(($related_task->dateo), 'dayreduceformat');
Expand All @@ -310,7 +310,7 @@ public function fillRiskData($odfHandler, $object, $outputlangs, $tmparray, $fil
$tmparray['actionPreventionCompleted'] .= ' - ' . $langs->transnoentities('Deadline') . ' : ' . $langs->trans('NoData') . "\n";
}
}
if (empty(getDolGlobalInt('DIGIRISKDOLIBARR_HIDE_TASK_BUDGET_DOCUMENT'))) {
if (!getDolGlobalInt('DIGIRISKDOLIBARR_TASK_HIDE_BUDGET_IN_DOCUMENT')) {
$tmparray['actionPreventionCompleted'] .= $langs->trans('Budget') . ' : ' . price($related_task->budget_amount, 0, $langs, 1, 0, 0, $conf->currency) . "\n";
}
(($AllInitiales) ? $tmparray['actionPreventionCompleted'] .= $langs->trans('ContactsAction') . ' : ' . $AllInitiales . "\n" : '');
Expand All @@ -321,13 +321,13 @@ public function fillRiskData($odfHandler, $object, $outputlangs, $tmparray, $fil
$tmparray['actionPreventionCompleted'] = $langs->transnoentities('ActionPreventionCompletedTaskDone');
}
} else {
if (empty(getDolGlobalInt('DIGIRISKDOLIBARR_HIDE_TASK_REF_DOCUMENT'))) {
if (!getDolGlobalInt('DIGIRISKDOLIBARR_TASK_HIDE_REF_IN_DOCUMENT')) {
(($related_task->ref) ? $tmparray['actionPreventionUncompleted'] .= $langs->trans('Ref') . ' : ' . $related_task->ref . "\n" : '');
}
if (empty(getDolGlobalInt('DIGIRISKDOLIBARR_HIDE_TASK_RESPONSIBLE_DOCUMENT'))) {
if (!getDolGlobalInt('DIGIRISKDOLIBARR_TASK_HIDE_RESPONSIBLE_IN_DOCUMENT')) {
(($responsible) ? $tmparray['actionPreventionUncompleted'] .= $langs->trans('Responsible') . ' : ' . $responsible . "\n" : '');
}
if (empty(getDolGlobalInt('DIGIRISKDOLIBARR_HIDE_TASK_DATE_DOCUMENT'))) {
if (!getDolGlobalInt('DIGIRISKDOLIBARR_TASK_HIDE_DATE_IN_DOCUMENT')) {
$tmparray['actionPreventionUncompleted'] .= $langs->trans('DateStart') . ' : ';
if ($conf->global->DIGIRISKDOLIBARR_SHOW_TASK_START_DATE && !empty($related_task->dateo)) {
$tmparray['actionPreventionUncompleted'] .= dol_print_date(($related_task->dateo), 'dayreduceformat');
Expand All @@ -341,7 +341,7 @@ public function fillRiskData($odfHandler, $object, $outputlangs, $tmparray, $fil
}

}
if (empty(getDolGlobalInt('DIGIRISKDOLIBARR_HIDE_TASK_BUDGET_DOCUMENT'))) {
if (!getDolGlobalInt('DIGIRISKDOLIBARR_TASK_HIDE_BUDGET_IN_DOCUMENT')) {
$tmparray['actionPreventionUncompleted'] .= $langs->trans('Budget') . ' : ' . price($related_task->budget_amount, 0, $langs, 1, 0, 0, $conf->currency) . ' - ';
}
$tmparray['actionPreventionUncompleted'] .= $langs->trans('DigiriskProgress') . ' : ' . ($task_progress ?: 0) . ' %' . "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,34 +282,11 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa
$tmpArray['photo'] = DOL_DOCUMENT_ROOT . $noPhoto;
}

// Get security responsible
$resources = new DigiriskResources($this->db);
$user = new User($this->db);
$allLinks = $resources->fetchDigiriskResources();

$responsibleResources = $allLinks['Responsible'];
$user->fetch($responsibleResources->id[0]);

// Get QRCode to public interface
if (isModEnabled('multicompany')) {
$qrCodePath = DOL_DATA_ROOT . "/digiriskdolibarr/multicompany/ticketqrcode/";
} else {
$qrCodePath = $conf->digiriskdolibarr->multidir_output[$conf->entity ?: 1] . "/ticketqrcode/";
}
$QRCodeList = dol_dir_list($qrCodePath);
if (is_array($QRCodeList) && !empty($QRCodeList)) {
$QRCode = array_shift($QRCodeList);
$QRCodeImagePath = $QRCode['fullname'];
if (isset($moreParam['tmparray']) && is_array($moreParam['tmparray'])) {
$moreParam['tmparray'] = array_merge($moreParam['tmparray'], $tmpArray);
} else {
$QRCodeImagePath = DOL_DOCUMENT_ROOT . '/public/theme/common/nophoto.png';
$moreParam['tmparray'] = $tmpArray;
}

$tmpArray['helpUrl'] = DOL_MAIN_URL_ROOT . '/custom/digiriskdolibarr/public/ticket/create_ticket.php';
// The keyword "signature" is needed because we want the image to be cropped to fit in the table
$tmpArray['signatureQRCodeTicket'] = $QRCodeImagePath;
$tmpArray['securityResponsible'] = (!empty($user) ? dol_strtoupper($user->lastname) . ' ' . $user->firstname : '');

$moreParam['tmparray'] = $tmpArray;
$moreParam['objectDocument'] = $objectDocument;
$moreParam['hideTemplateName'] = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

// Load DigiriskDolibarr libraries
require_once __DIR__ . '/../digiriskelementdocument/modules_digiriskelementdocument.php';
require_once __DIR__ . '/../../../../../class/digiriskresources.class.php';

/**
* Class to build documents using ODF templates generator
Expand Down Expand Up @@ -75,4 +76,52 @@ public function info(Translate $langs): string
{
return parent::info($langs);
}

/**
* 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;

$resources = new DigiriskResources($this->db);
$userTmp = new User($this->db);

// Get QRCode to public interface
if (isModEnabled('multicompany')) {
$qrCodePath = DOL_DATA_ROOT . '/digiriskdolibarr/multicompany/ticketqrcode/';
} else {
$qrCodePath = $conf->digiriskdolibarr->multidir_output[$conf->entity ?: 1] . '/ticketqrcode/';
}
$QRCodeList = dol_dir_list($qrCodePath);
if (is_array($QRCodeList) && !empty($QRCodeList)) {
$QRCode = array_shift($QRCodeList);
$QRCodeImagePath = $QRCode['fullname'];
} else {
$QRCodeImagePath = DOL_DOCUMENT_ROOT . '/public/theme/common/nophoto.png';
}

$allLinks = $resources->fetchDigiriskResources();
$responsibleResources = $allLinks['Responsible'];
$userTmp->fetch($responsibleResources->id[0]);

// @todo The keyword "signature" is needed because we want the image to be cropped to fit in the table
$tmpArray['helpUrl'] = DOL_MAIN_URL_ROOT . '/custom/digiriskdolibarr/public/ticket/create_ticket.php';
$tmpArray['signatureQRCodeTicket'] = $QRCodeImagePath;
$tmpArray['securityResponsible'] = (!empty($userTmp) ? dol_strtoupper($userTmp->lastname) . ' ' . ucfirst($userTmp->firstname) : '');

$moreParam['tmparray'] = $tmpArray;

return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam);
}
}
16 changes: 8 additions & 8 deletions core/modules/modDigiriskDolibarr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,12 +659,12 @@ public function __construct($db)
$i++ => ['DIGIRISKDOLIBARR_MOVE_RISKS', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SORT_LISTINGS_BY_COTATION', 'integer', 1, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_RISK_DESCRIPTION_PREFILL', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_RISK_ORIGIN', 'integer', 1, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_RISKS', 'integer', 1, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_RISK_LIST_PARENT_VIEW', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_INHERITED_RISKS_IN_DOCUMENTS', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_INHERITED_RISKS_IN_LISTINGS', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_SHARED_RISKS', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_RISK_ORIGIN', 'integer', 1, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_RISK_LIST_PARENT_VIEW', 'integer', 0, '', 0, 'current'],

// CONST RISK ASSESSMENT
$i++ => ['DIGIRISKDOLIBARR_MAIN_AGENDA_ACTIONAUTO_RISKASSESSMENT_CREATE', 'integer', 1, '', 0, 'current'],
Expand All @@ -673,9 +673,9 @@ public function __construct($db)
$i++ => ['DIGIRISKDOLIBARR_RISKASSESSMENT_ADDON', 'chaine', 'mod_riskassessment_standard', '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_MULTIPLE_RISKASSESSMENT_METHOD', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_ADVANCED_RISKASSESSMENT_METHOD', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_RISKASSESSMENT_DATE', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_DOCUMENT_RISKASSESSMENT_DATE', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_ALL_RISKASSESSMENTS', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_RISKASSESSMENT_DATE', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_RISKASSESSMENT_HIDE_DATE_IN_DOCUMENT', 'integer', 0, '', 0, 'current'],

// CONST RISK SIGN
$i++ => ['DIGIRISKDOLIBARR_MAIN_AGENDA_ACTIONAUTO_RISKSIGN_CREATE', 'integer', 1, '', 0, 'current'],
Expand Down Expand Up @@ -703,10 +703,10 @@ public function __construct($db)
$i++ => ['DIGIRISKDOLIBARR_SHOW_TASK_CALCULATED_PROGRESS', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_ALL_TASKS', 'integer', 1, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TASK_TIMESPENT_DURATION', 'integer', 15, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_HIDE_TASK_REF_DOCUMENT', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_HIDE_TASK_RESPONSIBLE_DOCUMENT', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_HIDE_TASK_DATE_DOCUMENT', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_HIDE_TASK_BUDGET_DOCUMENT', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TASK_HIDE_REF_IN_DOCUMENT', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TASK_HIDE_RESPONSIBLE_IN_DOCUMENT', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TASK_HIDE_DATE_IN_DOCUMENT', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TASK_HIDE_BUDGET_IN_DOCUMENT', 'integer', 0, '', 0, 'current'],

// CONST TASK TIMESPENT
$i++ => ['DIGIRISKDOLIBARR_MAIN_AGENDA_ACTIONAUTO_TASK_TIMESPENT_CREATE', 'integer', 1, '', 0, 'current'],
Expand Down
Loading

0 comments on commit 7b0ba5b

Please sign in to comment.