From 37e589807d6ae1e6178d281a56f68068ff7aefbd Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 23 Mar 2022 14:01:30 +0100 Subject: [PATCH 1/8] add trigger create on expensereportdet --- .../class/expensereport.class.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index be49b0a8c0c..fa8f9a6e1a8 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -2752,6 +2752,17 @@ class ExpenseReportLine if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'expensereport_det'); + + if (!$error && !$notrigger) { + // Call triggers + $result = $this->call_trigger('EXPENSE_REPORT_DET_CREATE', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + + if (!$fromaddline) { $tmpparent = new ExpenseReport($this->db); $tmpparent->fetch($this->fk_expensereport); @@ -2908,4 +2919,40 @@ class ExpenseReportLine return -2; } } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Call trigger based on this instance. + * Some context information may also be provided into array property this->context. + * NB: Error from trigger are stacked in interface->errors + * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. + * + * @param string $triggerName trigger's name to execute + * @param User $user Object user + * @return int Result of run_triggers + */ + public function call_trigger($triggerName, $user) + { + // phpcs:enable + global $langs, $conf; + + if (!is_object($langs)) { // If lang was not defined, we set it. It is required by run_triggers. + include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php'; + $langs = new Translate('', $conf); + } + + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; + $interface = new Interfaces($this->db); + $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf); + + if ($result < 0) { + if (!empty($this->errors)) { + $this->errors = array_unique(array_merge($this->errors, $interface->errors)); // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice. + } else { + $this->errors = $interface->errors; + } + } + return $result; + } + } From a577956b737813fb4625496361a0431afd82cc9c Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 23 Mar 2022 14:57:30 +0100 Subject: [PATCH 2/8] ajout de nom de class dans les entes de ligne det en affichage --- htdocs/expensereport/card.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 307294d5422..696faf88514 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2043,24 +2043,24 @@ if ($action == 'create') { $i = 0; $total = 0; print ''; - print ''.$langs->trans('LineNb').''; + print ''.$langs->trans('LineNb').''; //print ''.$langs->trans('Piece').''; - print ''.$langs->trans('Date').''; + print ''.$langs->trans('Date').''; if (!empty($conf->projet->enabled)) { - print ''.$langs->trans('Project').''; + print ''.$langs->trans('Project').''; } - print ''.$langs->trans('Type').''; + print ''.$langs->trans('Type').''; if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { - print ''.$langs->trans('CarCategory').''; + print ''.$langs->trans('CarCategory').''; } - print ''.$langs->trans('Description').''; - print ''.$langs->trans('VAT').''; - print ''.$langs->trans('PriceUHT').''; - print ''.$langs->trans('PriceUTTC').''; - print ''.$langs->trans('Qty').''; + print ''.$langs->trans('Description').''; + print ''.$langs->trans('VAT').''; + print ''.$langs->trans('PriceUHT').''; + print ''.$langs->trans('PriceUTTC').''; + print ''.$langs->trans('Qty').''; if ($action != 'editline') { - print ''.$langs->trans('AmountHT').''; - print ''.$langs->trans('AmountTTC').''; + print ''.$langs->trans('AmountHT').''; + print ''.$langs->trans('AmountTTC').''; } // Picture print ''; From 4bc75f6487a83db12b85dd91d7b8457bc6e3bcc1 Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 23 Mar 2022 15:05:38 +0100 Subject: [PATCH 3/8] ajout class name on create det --- htdocs/expensereport/card.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 696faf88514..14b0b381ba7 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2473,21 +2473,21 @@ if ($action == 'create') { include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php'; include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php'; - print ''; + print ''; print ''; - print ''.$langs->trans('Date').''; + print ''.$langs->trans('Date').''; if (!empty($conf->projet->enabled)) { print ''.$form->textwithpicto($langs->trans('Project'), $langs->trans("ClosedProjectsAreHidden")).''; } - print ''.$langs->trans('Type').''; + print ''.$langs->trans('Type').''; if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { print ''.$langs->trans('CarCategory').''; } - print ''.$langs->trans('Description').''; - print ''.$langs->trans('VAT').''; - print ''.$langs->trans('PriceUHT').''; - print ''.$langs->trans('PriceUTTC').''; - print ''.$langs->trans('Qty').''; + print ''.$langs->trans('Description').''; + print ''.$langs->trans('VAT').''; + print ''.$langs->trans('PriceUHT').''; + print ''.$langs->trans('PriceUTTC').''; + print ''.$langs->trans('Qty').''; print ''; print ''; print ''; From 7be3c8b64d7577b7419cd65e2995019d2a91f6b6 Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 23 Mar 2022 17:21:11 +0100 Subject: [PATCH 4/8] ajout de class pour les --- htdocs/expensereport/card.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 14b0b381ba7..79dd5e3b1c1 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2042,7 +2042,7 @@ if ($action == 'create') { if (!empty($object->lines)) { $i = 0; $total = 0; - print ''; + print ''; print ''.$langs->trans('LineNb').''; //print ''.$langs->trans('Piece').''; print ''.$langs->trans('Date').''; @@ -2080,19 +2080,19 @@ if ($action == 'create') { $numline = $i + 1; if ($action != 'editline' || $line->rowid != GETPOST('rowid', 'int')) { - print ''; + print ''; // Num - print ''; + print ''; print $numline; print ''; // Date - print ''.dol_print_date($db->jdate($line->date), 'day').''; + print ''.dol_print_date($db->jdate($line->date), 'day').''; // Project if (!empty($conf->projet->enabled)) { - print ''; + print ''; if ($line->fk_project > 0) { $projecttmp->id = $line->fk_project; $projecttmp->ref = $line->projet_ref; @@ -2118,26 +2118,26 @@ if ($action == 'create') { } // Type of fee - print ''; + print ''; $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code)); print $labeltype; print ''; // IK if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { - print ''; + print ''; print dol_getIdFromCode($db, $line->fk_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label'); print ''; } // Comment - print ''.dol_nl2br($line->comments).''; + print ''.dol_nl2br($line->comments).''; // VAT rate - print ''.vatrate($line->vatrate.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''), true).''; + print ''.vatrate($line->vatrate.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''), true).''; // Unit price HT - print ''; + print ''; if (!empty($line->value_unit_ht)) { print price($line->value_unit_ht); } else { @@ -2147,13 +2147,13 @@ if ($action == 'create') { } print ''; - print ''.price($line->value_unit).''; + print ''.price($line->value_unit).''; - print ''.dol_escape_htmltag($line->qty).''; + print ''.dol_escape_htmltag($line->qty).''; if ($action != 'editline') { - print ''.price($line->total_ht).''; - print ''.price($line->total_ttc).''; + print ''.price($line->total_ht).''; + print ''.price($line->total_ttc).''; } // Column with preview From 71c1f2de3cb2474928bf7a0039495e230e6e4576 Mon Sep 17 00:00:00 2001 From: jpb Date: Thu, 24 Mar 2022 09:38:23 +0100 Subject: [PATCH 5/8] add class td --- htdocs/expensereport/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 79dd5e3b1c1..1f874acca91 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2420,7 +2420,7 @@ if ($action == 'create') { // Add line with link to add new file or attach to an existing file print ''; - print ''; + print ''; print ''.$langs->trans("UploadANewFileNow"); print img_picto($langs->trans("UploadANewFileNow"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly'); print ''; From 671ab9a412b64cd926c08158cf2b3ab605f6f56b Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 24 Mar 2022 08:55:18 +0000 Subject: [PATCH 6/8] Fixing style errors. --- htdocs/expensereport/class/expensereport.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index fa8f9a6e1a8..b85691c586d 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -2954,5 +2954,4 @@ class ExpenseReportLine } return $result; } - } From fdfbf05705751fd852e4957bd262c92d48fb8ddd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Mar 2022 12:00:11 +0100 Subject: [PATCH 7/8] Update card.php --- htdocs/expensereport/card.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 1f874acca91..1718425e907 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2080,15 +2080,15 @@ if ($action == 'create') { $numline = $i + 1; if ($action != 'editline' || $line->rowid != GETPOST('rowid', 'int')) { - print ''; + print ''; // Num - print ''; + print ''; print $numline; print ''; // Date - print ''.dol_print_date($db->jdate($line->date), 'day').''; + print ''.dol_print_date($db->jdate($line->date), 'day').''; // Project if (!empty($conf->projet->enabled)) { @@ -2118,26 +2118,26 @@ if ($action == 'create') { } // Type of fee - print ''; + print ''; $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code)); print $labeltype; print ''; // IK if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { - print ''; + print ''; print dol_getIdFromCode($db, $line->fk_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label'); print ''; } // Comment - print ''.dol_nl2br($line->comments).''; + print ''.dol_nl2br($line->comments).''; // VAT rate - print ''.vatrate($line->vatrate.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''), true).''; + print ''.vatrate($line->vatrate.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''), true).''; // Unit price HT - print ''; + print ''; if (!empty($line->value_unit_ht)) { print price($line->value_unit_ht); } else { @@ -2147,17 +2147,17 @@ if ($action == 'create') { } print ''; - print ''.price($line->value_unit).''; + print ''.price($line->value_unit).''; - print ''.dol_escape_htmltag($line->qty).''; + print ''.dol_escape_htmltag($line->qty).''; if ($action != 'editline') { - print ''.price($line->total_ht).''; - print ''.price($line->total_ttc).''; + print ''.price($line->total_ht).''; + print ''.price($line->total_ttc).''; } // Column with preview - print ''; + print ''; if ($line->fk_ecm_files > 0) { $modulepart = 'expensereport'; $maxheightmini = 32; @@ -2227,13 +2227,13 @@ if ($action == 'create') { } print ''; - print ''; + print ''; print !empty($line->rule_warning_message) ? img_warning(html_entity_decode($line->rule_warning_message)) : ' '; print ''; // Ajout des boutons de modification/suppression if (($object->status < ExpenseReport::STATUS_VALIDATED || $object->status == ExpenseReport::STATUS_REFUSED) && $user->rights->expensereport->creer) { - print ''; + print ''; print 'rowid.'">'; print img_edit(); From ea4b842c865d40cf61c9b224cb81e0e0615228a6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Mar 2022 12:01:53 +0100 Subject: [PATCH 8/8] Update card.php --- htdocs/expensereport/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 1718425e907..9d9eebae245 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2080,7 +2080,7 @@ if ($action == 'create') { $numline = $i + 1; if ($action != 'editline' || $line->rowid != GETPOST('rowid', 'int')) { - print ''; + print ''; // Num print '';