From 0dae918b76c14425ae1c4bfaf22673e5f3d18d32 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 30 Sep 2021 17:09:49 +0200 Subject: [PATCH 1/4] NEW: expense reports: make project field required on lines --- htdocs/admin/expensereport.php | 17 ++++++++++++++- htdocs/core/modules/modProjet.class.php | 4 ++++ htdocs/expensereport/card.php | 28 ++++++++++++++++++------- htdocs/langs/en_US/admin.lang | 1 + 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/htdocs/admin/expensereport.php b/htdocs/admin/expensereport.php index f7c9a84c5d1..8368c679b3c 100644 --- a/htdocs/admin/expensereport.php +++ b/htdocs/admin/expensereport.php @@ -145,7 +145,14 @@ if ($action == 'updateMask') { $draft = GETPOST('EXPENSEREPORT_DRAFT_WATERMARK', 'alpha'); $res2 = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity); - if (!$res1 > 0 || !$res2 > 0) { + if ($conf->projet->enabled) { + $projects = GETPOST('EXPENSEREPORT_PROJECT_IS_REQUIRED', 'int'); + $res3 = dolibarr_set_const($db, 'EXPENSEREPORT_PROJECT_IS_REQUIRED', intval($projects), 'chaine', 0, '', $conf->entity); + } else { + $res3 = dolibarr_del_const($this->db, 'EXPENSEREPORT_PROJECT_IS_REQUIRED', $conf->entity); + } + + if (!$res1 > 0 || !$res2 > 0 || !$res3 > 0) { $error++; } @@ -458,6 +465,14 @@ print $form->textwithpicto($langs->trans("WatermarkOnDraftExpenseReports"), $htm print ''; print ''."\n"; +if ($conf->projet->enabled) { + print ''; + print $langs->trans('ProjectIsRequiredOnExpenseReports'); + print ''; + print $form->selectyesno('EXPENSEREPORT_PROJECT_IS_REQUIRED', empty($conf->global->EXPENSEREPORT_PROJECT_IS_REQUIRED) ? 0 : 1, 1); + print ''; +} + print ''; print $form->buttonsSaveCancel("Save", ''); diff --git a/htdocs/core/modules/modProjet.class.php b/htdocs/core/modules/modProjet.class.php index deefea6c2e8..7faa2232b0a 100644 --- a/htdocs/core/modules/modProjet.class.php +++ b/htdocs/core/modules/modProjet.class.php @@ -330,6 +330,10 @@ class modProjet extends DolibarrModules { global $conf, $langs; + if (dolibarr_del_const($this->db, 'EXPENSEREPORT_PROJECT_IS_REQUIRED', $conf->entity) < 0) { + return 0; + } + // Permissions $this->remove($options); diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index f982b046793..18f8256784e 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -106,6 +106,8 @@ $permissiontoadd = $user->rights->expensereport->creer; // Used by the include o $upload_dir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($object->ref); +$projectRequired = $conf->projet->enabled && ! empty($conf->global->EXPENSEREPORT_PROJECT_IS_REQUIRED); + if ($object->id > 0) { // Check current user can read this expense report $canread = 0; @@ -1132,6 +1134,12 @@ if (empty($reshook)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors'); } + // If no project entered + if ($projectRequired && $fk_project <= 0) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors'); + } + if (!$error) { $type = 0; // TODO What if service ? We should take the type product/service from the type of expense report llx_c_type_fees @@ -1265,6 +1273,12 @@ if (empty($reshook)) { setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings'); } + // If no project entered + if ($projectRequired && $projet_id <= 0) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors'); + } + if (!$error) { // TODO Use update method of ExpenseReportLine $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files); @@ -2075,7 +2089,7 @@ if ($action == 'create') { } else { $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $line->vatrate)); $pricenettoshow = price2num($line->value_unit / (1 + $tmpvat / 100), 'MU'); - print $pricenettoshow; + print price($pricenettoshow); } print ''; @@ -2252,7 +2266,7 @@ if ($action == 'create') { // Select project if (!empty($conf->projet->enabled)) { print ''; - $formproject->select_projects(-1, $line->fk_project, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300'); + $formproject->select_projects(-1, $line->fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300'); print ''; } @@ -2426,11 +2440,11 @@ if ($action == 'create') { print ''; // Select project - if (!empty($conf->projet->enabled)) { - print ''; - $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300'); - print ''; - } + if (!empty($conf->projet->enabled)) { + print ''; + $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300'); + print ''; + } // Select type print ''; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 48887552e7e..ff5b017a834 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -517,6 +517,7 @@ Field=Field ProductDocumentTemplates=Document templates to generate product document FreeLegalTextOnExpenseReports=Free legal text on expense reports WatermarkOnDraftExpenseReports=Watermark on draft expense reports +ProjectIsRequiredOnExpenseReports=Require selecting a project on expense reports AttachMainDocByDefault=Set this to 1 if you want to attach main document to email by default (if applicable) FilesAttachedToEmail=Attach file SendEmailsReminders=Send agenda reminders by emails From e1777a62669a5c038297259a164b53c97b3ce765 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 30 Sep 2021 15:12:36 +0000 Subject: [PATCH 2/4] Fixing style errors. --- htdocs/expensereport/card.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 18f8256784e..29f008b42b0 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2440,11 +2440,11 @@ if ($action == 'create') { print ''; // Select project - if (!empty($conf->projet->enabled)) { - print ''; - $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300'); - print ''; - } + if (!empty($conf->projet->enabled)) { + print ''; + $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300'); + print ''; + } // Select type print ''; From 88d93a4da5199caa7d930e59cbb51bfb23f23741 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 5 Oct 2021 15:59:29 +0200 Subject: [PATCH 3/4] FIX: expense reports: no need to delete const at project module activation --- htdocs/core/modules/modProjet.class.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/htdocs/core/modules/modProjet.class.php b/htdocs/core/modules/modProjet.class.php index 7faa2232b0a..deefea6c2e8 100644 --- a/htdocs/core/modules/modProjet.class.php +++ b/htdocs/core/modules/modProjet.class.php @@ -330,10 +330,6 @@ class modProjet extends DolibarrModules { global $conf, $langs; - if (dolibarr_del_const($this->db, 'EXPENSEREPORT_PROJECT_IS_REQUIRED', $conf->entity) < 0) { - return 0; - } - // Permissions $this->remove($options); From 6b5ab8025c95dcbdcde16b02965e5d847fc69462 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 6 Oct 2021 14:30:47 +0200 Subject: [PATCH 4/4] Update admin.lang --- htdocs/langs/en_US/admin.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index ff5b017a834..e63323e6c33 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -517,7 +517,7 @@ Field=Field ProductDocumentTemplates=Document templates to generate product document FreeLegalTextOnExpenseReports=Free legal text on expense reports WatermarkOnDraftExpenseReports=Watermark on draft expense reports -ProjectIsRequiredOnExpenseReports=Require selecting a project on expense reports +ProjectIsRequiredOnExpenseReports=The project is mandatory for entering an expense report AttachMainDocByDefault=Set this to 1 if you want to attach main document to email by default (if applicable) FilesAttachedToEmail=Attach file SendEmailsReminders=Send agenda reminders by emails