add trigger create on expensereportdet

This commit is contained in:
jpb 2022-03-23 14:01:30 +01:00
parent 4a80f35aaa
commit 37e589807d

View File

@ -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;
}
}