Skip to content

Commit

Permalink
BF:Restore 'requested'=>'cancelled' transition. Fix #185
Browse files Browse the repository at this point in the history
  • Loading branch information
bbalet committed Aug 8, 2017
1 parent c8bd15f commit e634769
Show file tree
Hide file tree
Showing 20 changed files with 910 additions and 0 deletions.
1 change: 1 addition & 0 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
$route['leaves/create'] = 'leaves/create';
$route['leaves/edit/(:num)'] = 'leaves/edit/$1';
$route['leaves/request/(:num)'] = 'leaves/requestLeave/$1';
$route['leaves/cancel/(:num)'] = 'leaves/cancel/$1';
$route['leaves/update'] = 'leaves/update';
$route['leaves/delete/(:num)'] = 'leaves/delete/$1';
$route['leaves/(:num)/history'] = 'leaves/history/$1';
Expand Down
67 changes: 67 additions & 0 deletions application/controllers/Leaves.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,41 @@ private function sendMailOnLeaveRequestCreation($id, $reminder=FALSE) {
}
}
}

/**
* Send a notification to the manager of the connected employee when the
* leave request has been canceled by its collaborator.
* @param int $id Leave request identifier
* @author Benjamin BALET <[email protected]>
*/
private function sendMailOnLeaveRequestCanceled($id) {
$this->load->model('users_model');
$this->load->model('types_model');
$this->load->model('delegations_model');
//We load everything from DB as the LR can be edited from HR/Employees
$leave = $this->leaves_model->getLeaves($id);
$user = $this->users_model->getUsers($leave['employee']);
$manager = $this->users_model->getUsers($user['manager']);
if (empty($manager['email'])) {
//TODO: create specific error message when the employee has no manager
$this->session->set_flashdata('msg', lang('leaves_cancel_flash_msg_error'));
} else {
//Send an e-mail to the manager
$this->load->library('email');
$this->load->library('polyglot');
$usr_lang = $this->polyglot->code2language($manager['language']);

//We need to instance an different object as the languages of connected user may differ from the UI lang
$lang_mail = new CI_Lang();
$lang_mail->load('email', $usr_lang);
$lang_mail->load('global', $usr_lang);

$this->sendGenericMail($leave, $user, $manager, $lang_mail,
$lang_mail->line('email_leave_request_cancellation_title'),
$lang_mail->line('email_leave_request_cancellation_subject'),
'cancelled');
}
}

/**
* Send a leave request cancellation email to the manager of the connected employee
Expand Down Expand Up @@ -612,6 +647,38 @@ public function cancellation($id) {
}
}
}

/**
* Allows the employee to cancel a requested leave request.
* Only the connected user can reject its own requests.
* Send a notification to the line manager.
* Next status is 'Canceled'
* @param int $id identifier of the leave request
* @author Benjamin BALET <[email protected]>
*/
public function cancel($id) {
//Test if the leave request exists
$leave = $this->leaves_model->getLeaves($id);
if (empty($leave)) {
redirect('notfound');
} else {
//Only the connected user can reject its own requests
if ($this->user_id != $leave['employee']){
$this->session->set_flashdata('msg', lang('leaves_cancellation_flash_msg_error'));
redirect('leaves');
}
//We can cancel a leave request only with a status 'Requested'
if ($leave['status'] == LMS_REQUESTED) {
$this->leaves_model->switchStatus($id, LMS_CANCELED);
$this->sendMailOnLeaveRequestCanceled($id);
$this->session->set_flashdata('msg', lang('requests_cancellation_accept_flash_msg_success'));
redirect('leaves');
} else {
$this->session->set_flashdata('msg', lang('leaves_cancellation_flash_msg_error'));
redirect('leaves');
}
}
}

/**
* Export the list of all leaves into an Excel file
Expand Down
49 changes: 49 additions & 0 deletions application/views/emails/cs/cancelled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Email template.You can change the content of this template
* @copyright Copyright (c) 2014-2017 Benjamin BALET
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
* @link https://github.com/bbalet/jorani
* @since 0.1.0
*/
?>
<html lang="cs">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="UTF-8">
<style>
table {width:50%;margin:5px;border-collapse:collapse;}
table, th, td {border: 1px solid black;}
th, td {padding: 20px;}
h5 {color:red;}
</style>
</head>
<body>
<h3>{Title}</h3>
{Firstname} {Lastname} cancelled a requested time off. See the <a href="{BaseUrl}leaves/leaves/{LeaveId}">details</a> below:<br />
<table border="0">
<tr>
<td>From &nbsp;</td><td>{StartDate}&nbsp;({StartDateType})</td>
</tr>
<tr>
<td>To &nbsp;</td><td>{EndDate}&nbsp;({EndDateType})</td>
</tr>
<tr>
<td>Type &nbsp;</td><td>{Type}</td>
</tr>
<tr>
<td>Duration &nbsp;</td><td>{Duration}</td>
</tr>
<tr>
<td>Balance &nbsp;</td><td>{Balance}</td>
</tr>
<tr>
<td>Reason &nbsp;</td><td>{Reason}</td>
</tr>
</table>
<br />
You can check the <a href="{BaseUrl}hr/counters/collaborators/{UserId}">leave balance</a> before validating the leave request.
<hr>
<h5>*** This is an automatically generated message, please do not reply to this message ***</h5>
</body>
</html>
49 changes: 49 additions & 0 deletions application/views/emails/de/cancelled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Email template.You can change the content of this template
* @copyright Copyright (c) 2014-2017 Benjamin BALET
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
* @link https://github.com/bbalet/jorani
* @since 0.1.0
*/
?>
<html lang="de">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="UTF-8">
<style>
table {width:50%;margin:5px;border-collapse:collapse;}
table, th, td {border: 1px solid black;}
th, td {padding: 20px;}
h5 {color:red;}
</style>
</head>
<body>
<h3>{Title}</h3>
{Firstname} {Lastname} cancelled a requested time off. See the <a href="{BaseUrl}leaves/leaves/{LeaveId}">details</a> below:<br />
<table border="0">
<tr>
<td>From &nbsp;</td><td>{StartDate}&nbsp;({StartDateType})</td>
</tr>
<tr>
<td>To &nbsp;</td><td>{EndDate}&nbsp;({EndDateType})</td>
</tr>
<tr>
<td>Type &nbsp;</td><td>{Type}</td>
</tr>
<tr>
<td>Duration &nbsp;</td><td>{Duration}</td>
</tr>
<tr>
<td>Balance &nbsp;</td><td>{Balance}</td>
</tr>
<tr>
<td>Reason &nbsp;</td><td>{Reason}</td>
</tr>
</table>
<br />
You can check the <a href="{BaseUrl}hr/counters/collaborators/{UserId}">leave balance</a> before validating the leave request.
<hr>
<h5>*** This is an automatically generated message, please do not reply to this message ***</h5>
</body>
</html>
49 changes: 49 additions & 0 deletions application/views/emails/el/cancelled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Email template.You can change the content of this template
* @copyright Copyright (c) 2014-2017 Benjamin BALET
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
* @link https://github.com/bbalet/jorani
* @since 0.1.0
*/
?>
<html lang="el">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="UTF-8">
<style>
table {width:50%;margin:5px;border-collapse:collapse;}
table, th, td {border: 1px solid black;}
th, td {padding: 20px;}
h5 {color:red;}
</style>
</head>
<body>
<h3>{Title}</h3>
{Firstname} {Lastname} cancelled a requested time off. See the <a href="{BaseUrl}leaves/leaves/{LeaveId}">details</a> below:<br />
<table border="0">
<tr>
<td>From &nbsp;</td><td>{StartDate}&nbsp;({StartDateType})</td>
</tr>
<tr>
<td>To &nbsp;</td><td>{EndDate}&nbsp;({EndDateType})</td>
</tr>
<tr>
<td>Type &nbsp;</td><td>{Type}</td>
</tr>
<tr>
<td>Duration &nbsp;</td><td>{Duration}</td>
</tr>
<tr>
<td>Balance &nbsp;</td><td>{Balance}</td>
</tr>
<tr>
<td>Reason &nbsp;</td><td>{Reason}</td>
</tr>
</table>
<br />
You can check the <a href="{BaseUrl}hr/counters/collaborators/{UserId}">leave balance</a> before validating the leave request.
<hr>
<h5>*** This is an automatically generated message, please do not reply to this message ***</h5>
</body>
</html>
49 changes: 49 additions & 0 deletions application/views/emails/en-gb/cancelled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Email template.You can change the content of this template
* @copyright Copyright (c) 2014-2017 Benjamin BALET
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
* @link https://github.com/bbalet/jorani
* @since 0.1.0
*/
?>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="UTF-8">
<style>
table {width:50%;margin:5px;border-collapse:collapse;}
table, th, td {border: 1px solid black;}
th, td {padding: 20px;}
h5 {color:red;}
</style>
</head>
<body>
<h3>{Title}</h3>
{Firstname} {Lastname} cancelled a requested time off. See the <a href="{BaseUrl}leaves/leaves/{LeaveId}">details</a> below:<br />
<table border="0">
<tr>
<td>From &nbsp;</td><td>{StartDate}&nbsp;({StartDateType})</td>
</tr>
<tr>
<td>To &nbsp;</td><td>{EndDate}&nbsp;({EndDateType})</td>
</tr>
<tr>
<td>Type &nbsp;</td><td>{Type}</td>
</tr>
<tr>
<td>Duration &nbsp;</td><td>{Duration}</td>
</tr>
<tr>
<td>Balance &nbsp;</td><td>{Balance}</td>
</tr>
<tr>
<td>Reason &nbsp;</td><td>{Reason}</td>
</tr>
</table>
<br />
You can check the <a href="{BaseUrl}hr/counters/collaborators/{UserId}">leave balance</a> before validating the leave request.
<hr>
<h5>*** This is an automatically generated message, please do not reply to this message ***</h5>
</body>
</html>
49 changes: 49 additions & 0 deletions application/views/emails/en/cancelled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Email template.You can change the content of this template
* @copyright Copyright (c) 2014-2017 Benjamin BALET
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
* @link https://github.com/bbalet/jorani
* @since 0.1.0
*/
?>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="UTF-8">
<style>
table {width:50%;margin:5px;border-collapse:collapse;}
table, th, td {border: 1px solid black;}
th, td {padding: 20px;}
h5 {color:red;}
</style>
</head>
<body>
<h3>{Title}</h3>
{Firstname} {Lastname} cancelled a requested time off. See the <a href="{BaseUrl}leaves/leaves/{LeaveId}">details</a> below:<br />
<table border="0">
<tr>
<td>From &nbsp;</td><td>{StartDate}&nbsp;({StartDateType})</td>
</tr>
<tr>
<td>To &nbsp;</td><td>{EndDate}&nbsp;({EndDateType})</td>
</tr>
<tr>
<td>Type &nbsp;</td><td>{Type}</td>
</tr>
<tr>
<td>Duration &nbsp;</td><td>{Duration}</td>
</tr>
<tr>
<td>Balance &nbsp;</td><td>{Balance}</td>
</tr>
<tr>
<td>Reason &nbsp;</td><td>{Reason}</td>
</tr>
</table>
<br />
You can check the <a href="{BaseUrl}hr/counters/collaborators/{UserId}">leave balance</a> before validating the leave request.
<hr>
<h5>*** This is an automatically generated message, please do not reply to this message ***</h5>
</body>
</html>
49 changes: 49 additions & 0 deletions application/views/emails/es/cancelled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Email template.You can change the content of this template
* @copyright Copyright (c) 2014-2017 Benjamin BALET
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0
* @link https://github.com/bbalet/jorani
* @since 0.1.0
*/
?>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="UTF-8">
<style>
table {width:50%;margin:5px;border-collapse:collapse;}
table, th, td {border: 1px solid black;}
th, td {padding: 20px;}
h5 {color:red;}
</style>
</head>
<body>
<h3>{Title}</h3>
{Firstname} {Lastname} cancelled a requested time off. See the <a href="{BaseUrl}leaves/leaves/{LeaveId}">details</a> below:<br />
<table border="0">
<tr>
<td>From &nbsp;</td><td>{StartDate}&nbsp;({StartDateType})</td>
</tr>
<tr>
<td>To &nbsp;</td><td>{EndDate}&nbsp;({EndDateType})</td>
</tr>
<tr>
<td>Type &nbsp;</td><td>{Type}</td>
</tr>
<tr>
<td>Duration &nbsp;</td><td>{Duration}</td>
</tr>
<tr>
<td>Balance &nbsp;</td><td>{Balance}</td>
</tr>
<tr>
<td>Reason &nbsp;</td><td>{Reason}</td>
</tr>
</table>
<br />
You can check the <a href="{BaseUrl}hr/counters/collaborators/{UserId}">leave balance</a> before validating the leave request.
<hr>
<h5>*** This is an automatically generated message, please do not reply to this message ***</h5>
</body>
</html>
Loading

0 comments on commit e634769

Please sign in to comment.