Merge pull request #20484 from atm-jpb/NEW_Trigger_expense_report_udpate_delete

add trigger update and delete on expense report det
This commit is contained in:
Laurent Destailleur 2022-03-31 15:58:30 +02:00 committed by GitHub
commit 643a3b1740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 16 deletions

View File

@ -2265,7 +2265,7 @@ if ($action == 'create') {
print $numline;
print '</td>';
print '<td colspan="'.($colspan - 1).'" class="liste_titre">';
print '<td colspan="'.($colspan - 1).'" class="liste_titre"> ';
print '<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans("UploadANewFileNow");
print img_picto($langs->trans("UploadANewFileNow"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly');
print '</a>';
@ -2493,6 +2493,8 @@ if ($action == 'create') {
print '<td></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
print '</tr>';
print '<tr class="oddeven nohover">';
@ -2501,19 +2503,19 @@ if ($action == 'create') {
print '<td></td>';
// Select date
print '<td class="center">';
print '<td class="center inputdate">';
print $form->selectDate($date ? $date : -1, 'date', 0, 0, 0, '', 1, 1);
print '</td>';
// Select project
if (!empty($conf->projet->enabled)) {
print '<td>';
print '<td class="inputproject">';
$formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300');
print '</td>';
}
// Select type
print '<td class="center">';
print '<td class="center inputtype">';
print $formexpensereport->selectTypeExpenseReport($fk_c_type_fees, 'fk_c_type_fees', 1);
print '</td>';
@ -2525,12 +2527,12 @@ if ($action == 'create') {
}
// Add comments
print '<td>';
print '<td class="inputcomment">';
print '<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.'">'.dol_escape_htmltag($comments, 0, 1).'</textarea>';
print '</td>';
// Select VAT
print '<td class="right">';
print '<td class="right inputvat">';
$defaultvat = -1;
if (!empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) {
$conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none';
@ -2539,17 +2541,17 @@ if ($action == 'create') {
print '</td>';
// Unit price net
print '<td class="right">';
print '<td class="right inputpricenet">';
print '<input type="text" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag($value_unit_ht).'"'.$taxlessUnitPriceDisabled.' />';
print '</td>';
// Unit price with tax
print '<td class="right">';
print '<td class="right inputtax">';
print '<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag($value_unit).'">';
print '</td>';
// Quantity
print '<td class="right">';
print '<td class="right inputqty">';
print '<input type="text" min="0" class="right maxwidth50" name="qty" value="'.dol_escape_htmltag($qty ? $qty : 1).'">'; // We must be able to enter decimal qty
print '</td>';
@ -2561,7 +2563,7 @@ if ($action == 'create') {
print '<td class="right"></td>';
}
print '<td class="center">';
print '<td class="center inputbuttons">';
print $form->buttonsSaveCancel("Add", '', '', 1);
print '</td>';

View File

@ -2063,7 +2063,7 @@ class ExpenseReport extends CommonObject
* @param int $fk_ecm_files Id of ECM file to link to this expensereport line
* @return int <0 if KO, >0 if OK
*/
public function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id, $fk_c_exp_tax_cat = 0, $fk_ecm_files = 0)
public function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id, $fk_c_exp_tax_cat = 0, $fk_ecm_files = 0, $notrigger = 0)
{
global $user, $mysoc;
@ -2153,9 +2153,19 @@ class ExpenseReport extends CommonObject
$this->applyOffset();
$this->checkRules();
$error = 0;
$result = $this->line->update($user);
if ($result > 0) {
if ($result > 0 && !$notrigger) {
// Call triggers
$result = $this->call_trigger('EXPENSE_REPORT_DET_UPDATE', $user);
if ($result < 0) {
$error++;
}
// End call triggers
}
if ($result > 0 && $error == 0) {
$this->db->commit();
return 1;
} else {
@ -2174,16 +2184,29 @@ class ExpenseReport extends CommonObject
* @param User $fuser User
* @return int <0 if KO, >0 if OK
*/
public function deleteline($rowid, $fuser = '')
public function deleteline($rowid, $fuser = '', $notrigger = 0)
{
$error=0;
$this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line;
if (!$notrigger) {
// Call triggers
$result = $this->call_trigger('EXPENSE_REPORT_DET_DELETE', $fuser);
if ($result < 0) {
$error++;
}
// End call triggers
}
$sql = ' DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql .= ' WHERE rowid = '.((int) $rowid);
dol_syslog(get_class($this)."::deleteline sql=".$sql);
$result = $this->db->query($sql);
if (!$result) {
if (!$result || $error > 0 ) {
$this->error = $this->db->error();
dol_syslog(get_class($this)."::deleteline Error ".$this->error, LOG_ERR);
$this->db->rollback();