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