NEW: expense report: show link to already existing overlapping expense report
This commit is contained in:
parent
3d4bb66853
commit
6a66fcbff8
@ -266,10 +266,14 @@ if (empty($reshook)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error && empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS) && $object->periode_existe($fuser, $object->date_debut, $object->date_fin)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDoubleDeclaration"), null, 'errors');
|
||||
$action = 'create';
|
||||
if (!$error && empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS)) {
|
||||
$overlappingExpenseReportID = $object->periode_existe($fuser, $object->date_debut, $object->date_fin, true);
|
||||
|
||||
if ($overlappingExpenseReportID > 0) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDoubleDeclaration").' <a href="'.$_SERVER['PHP_SELF'].'?id='.$overlappingExpenseReportID.'">'. $langs->trans('ShowTrip').'</a>', null, 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
|
||||
@ -2195,9 +2195,10 @@ class ExpenseReport extends CommonObject
|
||||
* @param User $fuser User
|
||||
* @param integer $date_debut Start date
|
||||
* @param integer $date_fin End date
|
||||
* @param bool $return_id True to return ID of existing expense report
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function periode_existe($fuser, $date_debut, $date_fin)
|
||||
public function periode_existe($fuser, $date_debut, $date_fin, $return_id = false)
|
||||
{
|
||||
// phpcs:enable
|
||||
$sql = "SELECT rowid, date_debut, date_fin";
|
||||
@ -2213,8 +2214,6 @@ class ExpenseReport extends CommonObject
|
||||
$date_d_form = $date_debut;
|
||||
$date_f_form = $date_fin;
|
||||
|
||||
$existe = false;
|
||||
|
||||
while ($i < $num_rows) {
|
||||
$objp = $this->db->fetch_object($result);
|
||||
|
||||
@ -2222,17 +2221,13 @@ class ExpenseReport extends CommonObject
|
||||
$date_f_req = $this->db->jdate($objp->date_fin); // 4
|
||||
|
||||
if (!($date_f_form < $date_d_req || $date_d_form > $date_f_req)) {
|
||||
$existe = true;
|
||||
return $return_id ? $objp->rowid : 1;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($existe) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user