Merge branch '9.0' of git@github.com:Dolibarr/dolibarr.git into develop

Conflicts:
	htdocs/holiday/card.php
This commit is contained in:
Laurent Destailleur 2019-02-08 14:54:31 +01:00
commit 7f9d995c9c
2 changed files with 124 additions and 94 deletions

View File

@ -64,6 +64,7 @@ if (! empty($user->rights->holiday->delete)) $candelete=1;
$morefilter = 'AND employee = 1'; $morefilter = 'AND employee = 1';
if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = ''; if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = '';
$error = 0;
/* /*
* Actions * Actions
@ -431,7 +432,7 @@ if ($action == 'confirm_send')
} }
// Si Validation de la demande // Approve leave request
if ($action == 'confirm_valid') if ($action == 'confirm_valid')
{ {
$object = new Holiday($db); $object = new Holiday($db);
@ -446,25 +447,36 @@ if ($action == 'confirm_valid')
$object->fk_user_valid = $user->id; $object->fk_user_valid = $user->id;
$object->statut = Holiday::STATUS_APPROVED; $object->statut = Holiday::STATUS_APPROVED;
$db->begin();
$verif = $object->approve($user); $verif = $object->approve($user);
if ($verif <= 0)
{
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
// Si pas d'erreur SQL on redirige vers la fiche de la demande // Si pas d'erreur SQL on redirige vers la fiche de la demande
if ($verif > 0) if (! $error)
{ {
// Calculcate number of days consummed // Calculcate number of days consummed
$nbopenedday=num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday); $nbopenedday=num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
$soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type); $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
$newSolde = $soldeActuel - ($nbopenedday * $object->getConfCP('nbHolidayDeducted')); $newSolde = ($soldeActuel - $nbopenedday);
// On ajoute la modification dans le LOG // On ajoute la modification dans le LOG
$result=$object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("Holidays"), $newSolde, $object->fk_type); $result=$object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("Holidays"), $newSolde, $object->fk_type);
if ($result<0) { if ($result < 0)
{
$error++;
setEventMessages(null, $object->errors, 'errors'); setEventMessages(null, $object->errors, 'errors');
} }
// Mise à jour du solde
//Update balance
$result=$object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type); $result=$object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
if ($result<0) { if ($result < 0)
{
$error++;
setEventMessages(null, $object->errors, 'errors'); setEventMessages(null, $object->errors, 'errors');
} }
@ -476,10 +488,9 @@ if ($action == 'confirm_valid')
if (!$emailTo) if (!$emailTo)
{ {
dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email"); dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
} }
else
{
// From // From
$expediteur = new User($db); $expediteur = new User($db);
$expediteur->fetch($object->fk_validator); $expediteur->fetch($object->fk_validator);
@ -510,18 +521,22 @@ if ($action == 'confirm_valid')
if (!$result) if (!$result)
{ {
setEventMessages($mail->error, $mail->errors, 'warnings'); setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
$action=''; $action='';
} }
else }
}
if (! $error)
{ {
$db->commit();
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit; exit;
} }
}
else else
{ {
setEventMessages($object->error, $object->errors, 'errors'); $db->rollback();
$action=''; $action='';
} }
} }
@ -542,10 +557,17 @@ if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes')
$object->statut = Holiday::STATUS_REFUSED; $object->statut = Holiday::STATUS_REFUSED;
$object->detail_refuse = GETPOST('detail_refuse', 'alphanohtml'); $object->detail_refuse = GETPOST('detail_refuse', 'alphanohtml');
$db->begin();
$verif = $object->update($user); $verif = $object->update($user);
if ($verif <= 0)
{
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
// Si pas d'erreur SQL on redirige vers la fiche de la demande // Si pas d'erreur SQL on redirige vers la fiche de la demande
if ($verif > 0) if (! $error)
{ {
// To // To
$destinataire = new User($db); $destinataire = new User($db);
@ -554,10 +576,10 @@ if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes')
if (!$emailTo) if (!$emailTo)
{ {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
exit;
} }
else
{
// From // From
$expediteur = new User($db); $expediteur = new User($db);
$expediteur->fetch($object->fk_validator); $expediteur->fetch($object->fk_validator);
@ -573,7 +595,7 @@ if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes')
$message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n"; $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
$message.= "\n"; $message.= "\n";
$message.= $langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."\n"; $message.= $langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."\n";
$message.= GETPOST('detail_refuse', 'alpha')."\n\n"; $message.= GETPOST('detail_refuse','alpha')."\n\n";
$message.= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; $message.= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
@ -587,20 +609,28 @@ if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes')
// Envoi du mail // Envoi du mail
$result=$mail->sendfile(); $result=$mail->sendfile();
if (!$result) if (! $result)
{ {
setEventMessages($mail->error, $mail->errors, 'warnings'); setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
$action=''; $action='';
} }
}
}
else else
{ {
$action='';
}
if (! $error)
{
$db->commit();
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit; exit;
} }
}
else else
{ {
setEventMessages($object->error, $object->errors, 'errors'); $db->rollback();
$action=''; $action='';
} }
} }
@ -642,7 +672,7 @@ if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes')
} }
} }
// Si Validation de la demande // Si confirmation of cancellation
if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
{ {
$error = 0; $error = 0;
@ -662,13 +692,13 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
$result = $object->update($user); $result = $object->update($user);
if ($result >= 0 && $oldstatus == Holiday::STATUS_APPROVED) // holiday was already validated, status 3, so we must increase back sold if ($result >= 0 && $oldstatus == Holiday::STATUS_APPROVED) // holiday was already validated, status 3, so we must increase back the balance
{ {
// Calculcate number of days consummed // Calculcate number of days consummed
$nbopenedday=num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday); $nbopenedday=num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
$soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type); $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
$newSolde = $soldeActuel + ($nbopenedday * $object->getConfCP('nbHolidayDeducted')); $newSolde = ($soldeActuel + $nbopenedday);
// On ajoute la modification dans le LOG // On ajoute la modification dans le LOG
$result1=$object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type); $result1=$object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type);

View File

@ -697,7 +697,7 @@ class Holiday extends CommonObject
} else { } else {
$error++; $error++;
} }
$sql.= " ref = '".$num."'"; $sql.= " ref = '".$this->db->escape($num)."'";
$sql.= " WHERE rowid= ".$this->id; $sql.= " WHERE rowid= ".$this->id;
$this->db->begin(); $this->db->begin();
@ -1496,7 +1496,7 @@ class Holiday extends CommonObject
$nbHoliday = price2num($nbHoliday, 5); $nbHoliday = price2num($nbHoliday, 5);
$sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users"; $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
$sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type; $sql.= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -1507,7 +1507,7 @@ class Holiday extends CommonObject
// Update for user // Update for user
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
$sql.= " nb_holiday = ".$nbHoliday; $sql.= " nb_holiday = ".$nbHoliday;
$sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type; $sql.= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (! $result) if (! $result)
{ {
@ -1520,7 +1520,7 @@ class Holiday extends CommonObject
// Insert for user // Insert for user
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
$sql.= $nbHoliday; $sql.= $nbHoliday;
$sql.= ", '".$userID."', ".$fk_type.")"; $sql.= ", ".(int) $userID.", ".(int) $fk_type.")";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (! $result) if (! $result)
{ {