Close #18302 : Mass action leave requests
This commit is contained in:
parent
a4843f7d10
commit
1cef6d31e8
@ -1544,6 +1544,126 @@ if (!$error && ($massaction == 'disable' || ($action == 'disable' && $confirm ==
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $confirm == 'yes')) && $permissiontoapprove) {
|
||||
$db->begin();
|
||||
|
||||
$objecttmp = new $objectclass($db);
|
||||
$nbok = 0;
|
||||
foreach ($toselect as $toselectid) {
|
||||
$result = $objecttmp->fetch($toselectid);
|
||||
if ($result>0) {
|
||||
if ($objecttmp->statut == Holiday::STATUS_VALIDATED && $user->id == $objecttmp->fk_validator) {
|
||||
$objecttmp->oldcopy = dol_clone($objecttmp);
|
||||
|
||||
$objecttmp->date_valid = dol_now();
|
||||
$objecttmp->fk_user_valid = $user->id;
|
||||
$objecttmp->statut = Holiday::STATUS_APPROVED;
|
||||
|
||||
$db->begin();
|
||||
|
||||
$verif = $objecttmp->approve($user);
|
||||
if ($verif <= 0) {
|
||||
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
// If no SQL error, we redirect to the request form
|
||||
if (!$error) {
|
||||
// Calculcate number of days consummed
|
||||
$nbopenedday = num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday);
|
||||
$soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type);
|
||||
$newSolde = ($soldeActuel - $nbopenedday);
|
||||
|
||||
// The modification is added to the LOG
|
||||
$result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv("Holidays"), $newSolde, $objecttmp->fk_type);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
setEventMessages(null, $objecttmp->errors, 'errors');
|
||||
}
|
||||
|
||||
// Update balance
|
||||
$result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
setEventMessages(null, $objecttmp->errors, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
// To
|
||||
$destinataire = new User($db);
|
||||
$destinataire->fetch($objecttmp->fk_user);
|
||||
$emailTo = $destinataire->email;
|
||||
|
||||
if (!$emailTo) {
|
||||
dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
|
||||
} else {
|
||||
// From
|
||||
$expediteur = new User($db);
|
||||
$expediteur->fetch($objecttmp->fk_validator);
|
||||
//$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
|
||||
$emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
|
||||
// Subject
|
||||
$societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
|
||||
if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
|
||||
$societeName = $conf->global->MAIN_APPLICATION_TITLE;
|
||||
}
|
||||
|
||||
$subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysValidated");
|
||||
|
||||
// Content
|
||||
$message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
|
||||
$message .= "\n";
|
||||
|
||||
$message .= $langs->transnoentities("HolidaysValidatedBody", dol_print_date($objecttmp->date_debut, 'day'), dol_print_date($objecttmp->date_fin, 'day'))."\n";
|
||||
|
||||
$message .= "- ".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
|
||||
|
||||
$message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$objecttmp->id."\n\n";
|
||||
$message .= "\n";
|
||||
|
||||
$trackid = 'leav'.$objecttmp->id;
|
||||
|
||||
$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);
|
||||
|
||||
// Sending email
|
||||
$result = $mail->sendfile();
|
||||
|
||||
if (!$result) {
|
||||
setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
$nbok++;
|
||||
} else {
|
||||
$db->rollback();
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
if ($nbok > 1) {
|
||||
setEventMessages($langs->trans("RecordsApproved", $nbok), null, 'mesgs');
|
||||
} else {
|
||||
setEventMessages($langs->trans("RecordAproved"), null, 'mesgs');
|
||||
}
|
||||
$db->commit();
|
||||
} else {
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
$parameters['toselect'] = $toselect;
|
||||
$parameters['uploaddir'] = $uploaddir;
|
||||
$parameters['massaction'] = $massaction;
|
||||
|
||||
@ -202,6 +202,10 @@ if ($massaction == 'predisable') {
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDisabling"), $langs->trans("ConfirmMassDisablingQuestion", count($toselect)), "disable", null, '', 0, 200, 500, 1);
|
||||
}
|
||||
|
||||
if ($massaction == 'preapproveleave') {
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassLeaveApproval"), $langs->trans("ConfirmMassLeaveApprovalQuestion", count($toselect)), "approveleave", null, '', 0, 200, 500, 1);
|
||||
}
|
||||
|
||||
// Allow Pre-Mass-Action hook (eg for confirmation dialog)
|
||||
$parameters = array(
|
||||
'toselect' => $toselect,
|
||||
|
||||
@ -213,6 +213,7 @@ if (empty($reshook)) {
|
||||
$objectlabel = 'Holiday';
|
||||
$permissiontoread = $user->rights->holiday->read;
|
||||
$permissiontodelete = $user->rights->holiday->delete;
|
||||
$permissiontoapprove = $user->rights->holiday->approve;
|
||||
$uploaddir = $conf->holiday->dir_output;
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
|
||||
}
|
||||
@ -441,6 +442,9 @@ if ($resql) {
|
||||
if (!empty($user->rights->holiday->delete)) {
|
||||
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
|
||||
}
|
||||
if (!empty($user->rights->holiday->approve)) {
|
||||
$arrayofmassactions['preapproveleave'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Approve");
|
||||
}
|
||||
if (in_array($massaction, array('presend', 'predelete'))) {
|
||||
$arrayofmassactions = array();
|
||||
}
|
||||
|
||||
@ -1149,3 +1149,7 @@ RecordEnabled=Record enabled
|
||||
RecordDisabled=Record disabled
|
||||
Forthcoming=Forthcoming
|
||||
Currently=Currently
|
||||
ConfirmMassLeaveApprovalQuestion=Are you sure you want to approve the %s selected record(s)?
|
||||
ConfirmMassLeaveApproval=Mass leave approval confirmation
|
||||
RecordAproved=Record approved
|
||||
RecordsApproved=%s Record(s) approved
|
||||
|
||||
@ -1147,3 +1147,7 @@ RecordsEnabled=%s enregistrement(s) activé(s)
|
||||
RecordsDisabled=%s enregistrement(s) désactivé(s)
|
||||
RecordEnabled=Enregistrement activé
|
||||
RecordDisabled=Enregistrement désactivé
|
||||
ConfirmMassLeaveApprovalQuestion=Êtes-vous sur de vouloir approuver les %s enregistrement(s) sélectionné(s) ?
|
||||
ConfirmMassLeaveApproval=Confirmation d'approbation de congé en masse
|
||||
RecordAproved=Enregistrement approuvé
|
||||
RecordsApproved=%s enregistrement(s) approuvé(s)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user