Compare commits

...

40 Commits

Author SHA1 Message Date
ee168bd637 [add] Updating work days from front end 2018-08-15 02:36:23 -06:00
b233346795 [add] Worked day modified through api 2018-08-15 02:26:41 -06:00
ca80abc389 [add] Validations for work day abstracted to their own method 2018-08-15 01:40:36 -06:00
e3dfaf9f26 [add] Validating future dates 2018-08-15 00:51:10 -06:00
477ac28212 [mod] Exits changed to exceptions 2018-08-15 00:38:05 -06:00
3ad687f797 [add] Data loaded to be edited 2018-08-15 00:31:18 -06:00
b84b9fa2fb [add] Returning details per pay day 2018-08-14 16:35:30 -06:00
f2851ec56a [add] Work day details 2018-08-14 15:39:55 -06:00
03cbcce59f [add] Basic endpoint for workday data 2018-08-14 11:52:57 -06:00
f864e74247 Merge pull request #22 from PootisPenserHere/retrievingrySalary
Retrievingry salary
2018-08-14 07:40:19 -06:00
6b22fc4694 [add] Loading salary data 2018-08-14 07:38:25 -06:00
caa31136f1 [add] Endpoint to calculate salary 2018-08-14 04:06:36 -06:00
c97421df32 Merge pull request #21 from PootisPenserHere/registeringNewWorkDay
Registering new work day
2018-08-14 02:31:46 -06:00
568c6d23a9 [add] Validating date isn't duplicated 2018-08-14 02:30:56 -06:00
15a7ea5ef5 [add] Saving worked day 2018-08-14 02:11:07 -06:00
93099d316f [add] Sending new work day data to backend 2018-08-14 00:26:25 -06:00
e9f80a9989 [add] Enabling covered rol for aux 2018-08-14 00:16:06 -06:00
6ce90bd318 [add] Loading basic employee data 2018-08-14 00:08:05 -06:00
69e3a31d52 [add] Layout new work day 2018-08-14 00:00:47 -06:00
1ee650e020 [add] Instantiating the new view 2018-08-13 23:20:37 -06:00
61eb809204 [add] Database and settings 2018-08-13 22:58:49 -06:00
b98b4077b4 Merge pull request #20 from PootisPenserHere/updatingEmployeeDataFromView
Updating employee data from view
2018-08-12 23:18:47 -06:00
a8148bbb93 [add] Employee updated 2018-08-12 23:17:20 -06:00
b0a19c6daa [add] Loading employee data 2018-08-12 22:55:00 -06:00
38d3466f16 [fix] Returning idEmployeeType instead of name type 2018-08-12 22:49:32 -06:00
68723e82fe [add] Searching for full employee data by code
Corrected a logical  error where the wrong method was being called to get data by code and also made it so the search function only returns names and codes
2018-08-12 22:22:33 -06:00
6615e5471a [add] Bloodhound in local files 2018-08-12 21:51:09 -06:00
49e114c18a [add] Bloodhoung search 2018-08-12 21:45:50 -06:00
e9effb7fcc [add] Finding employees by name 2018-08-12 21:01:46 -06:00
a5a1656518 [add] New asserts 2018-08-12 19:48:34 -06:00
19d1f57240 [mod] File naming 2018-08-12 19:28:50 -06:00
99a020024e Merge pull request #19 from PootisPenserHere/creatingNewEmployeeFromView
Creating new employee from view
2018-08-12 19:22:13 -06:00
abd8168dbf [add] Asserting email type 2018-08-12 17:15:39 -06:00
79059fb91b [mod] Updated html and css references 2018-08-12 16:59:46 -06:00
1b2484fbf2 [fix] Phone number length in database 2018-08-12 16:27:05 -06:00
168a6a352e [add] Displaying data post save 2018-08-12 16:25:23 -06:00
8185a42331 [add] Saving new employee 2018-08-12 15:54:56 -06:00
64a6ddafb5 [add] Datepicker 2018-08-12 15:38:09 -06:00
54ef088fe0 [add] New employee form layout 2018-08-12 14:39:47 -06:00
dc45f02ad2 Merge pull request #18 from PootisPenserHere/loadingViews
Loading views
2018-08-12 11:36:52 -06:00
21 changed files with 4308 additions and 117 deletions

File diff suppressed because one or more lines are too long

View File

@@ -54,15 +54,12 @@ body {
background: #C6E97C;
}
#modal_header_error{
.modalHeaderError{
background-color: #d9534f;
}
#modal_header_respuesa_servidor_error{
background-color: #d9534f;
}
#modal_header_respuesa_servidor_success{
.modalHeaderSuccess{
background-color: #5bc0de;
}

View File

@@ -1,38 +0,0 @@
<script src="../js/NewEmployee.js"></script>
<form class="form-horizontal" id="newEmployeeForm">
<div class="col-md-12">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">New employee</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeFirstName">First name</label>
<div class="col-md-5">
<input id="newEmployeeFirstName" name="newEmployeeFirstName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeMiddleName">Middle name</label>
<div class="col-md-5">
<input id="newEmployeeMiddleName" name="newEmployeeMiddleName" type="number" class="form-control input-md">
</div>
</div>
</div>
<div class="col-md-12">
<div class="row">
<div class="form-group">
<a href="#" class="btn btn-lg btn-success" onclick="saveNewEmployee();">Save</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>

View File

@@ -0,0 +1,111 @@
<script src="../js/getBaseUrl.js"></script>
<script src="../js/editEmployee.js"></script>
<form class="form-horizontal" id="editEmployee">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Edit employee</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmploySearch">Employee</label>
<div class="col-md-5">
<input id="editEmploySearch" name="editEmploySearch" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeeFirstName">First name</label>
<div class="col-md-5">
<input id="editEmployeeFirstName" name="editEmployeeFirstName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeeMiddleName">Middle name</label>
<div class="col-md-5">
<input id="editEmployeeMiddleName" name="editEmployeeMiddleName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeeLastName">Last name</label>
<div class="col-md-5">
<input id="editEmployeeLastName" name="editEmployeeLastName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeeBirthDate">Birth date</label>
<div class="col-md-5">
<input id="editEmployeeBirthDate" name="editEmployeeBirthDate" type="text" class="form-control input-md datepicker">
</div>
</div>
</div>
<div class="row" id="hidenEmployeeCode">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeeCode">Code</label>
<div class="col-md-5">
<input id="editEmployeeCode" name="editEmployeeCode" type="text" class="form-control input-md">
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeeEmail">Email</label>
<div class="col-md-5">
<input id="editEmployeeEmail" name="editEmployeeEmail" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeePhone">Phone</label>
<div class="col-md-5">
<input id="editEmployeePhone" name="editEmployeePhone" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeeType">Rol</label>
<div class="col-md-5">
<select class="form-control input-md" name="editEmployeeType" id="editEmployeeType">
<option>Employee type</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="editEmployeeContractType">Contract type</label>
<div class="col-md-5">
<select class="form-control input-md" name="editEmployeeContractType" id="editEmployeeContractType">
<option>Contract type</option>
<option value="INTERNO">interno</option>
<option value="EXTERNO">Externo</option>
</select>
</div>
</div>
</div>
</div>
<div class="row col-md-offset-6">
<div class="form-group">
<a href="#" class="btn btn-lg btn-success " onclick="updateEmployee();">Update</a>
</div>
</div>
</div>
</div>
</div>
</form>

View File

@@ -31,14 +31,14 @@ if(!isset($_SESSION['userName'])){
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-user"></span> Employees<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#" data-nav_accion="NewEmployee.php"> New employee</a></li>
<li><a href="#" data-nav_accion="EditEmployee.php"> Modify employee</a></li>
<li><a href="#" data-nav_accion="newEmployee.php"> New employee</a></li>
<li><a href="#" data-nav_accion="editEmployee.php"> Modify employee</a></li>
</ul>
</li>
<li>
<a href="#" onclick="loadView();"><span class="glyphicon glyphicon-tasks"></span> Management</a>
<a href="#" data-nav_accion="registerWorkDays.php" ><span class="glyphicon glyphicon-tasks"></span> Management</a>
</li>
<li>
@@ -64,11 +64,11 @@ if(!isset($_SESSION['userName'])){
=================================================================================
-->
<div id="modal_error_internet" class="modal fade" role="dialog">
<div id="modalErrorInternetConnection" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">An error has occurred</h4>
</div>
@@ -83,11 +83,11 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<div id="modal_error_404" class="modal fade" role="dialog">
<div id="modalError404" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">An error has occurred</h4>
</div>
@@ -102,11 +102,11 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<div id="modal_error_500" class="modal fade" role="dialog">
<div id="modalError500" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">An error has occurred</h4>
</div>
@@ -121,11 +121,11 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<div id="modal_error_parsererror" class="modal fade" role="dialog">
<div id="modalErrorParsererror" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">An error has occurred</h4>
</div>
@@ -140,11 +140,11 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<div id="modal_error_timeout" class="modal fade" role="dialog">
<div id="modalErrorTimeout" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">An error has occurred</h4>
</div>
@@ -159,11 +159,11 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<div id="modal_error_otro" class="modal fade" role="dialog">
<div id="modalErrorOther" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">An error has occurred</h4>
</div>
@@ -184,16 +184,16 @@ if(!isset($_SESSION['userName'])){
=================================================================================
-->
<div id="modal_server_response_error" class="modal fade" role="dialog">
<div id="modalServerResponseError" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modal_header_server_response_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">An error has occurred</h4>
</div>
<div class="modal-body">
<p id="server_response_error"></p>
<p id="modalResponseError"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -203,16 +203,16 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<div id="modal_server_response_success" class="modal fade" role="dialog">
<div id="modalServerResponseSuccess" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modal_header_server_response_success">
<div class="modal-header modalHeaderSuccess" id="modalHeaderServerResponseSuccess">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Success</h4>
</div>
<div class="modal-body">
<p id="server_response_success"></p>
<p id="serverResponseSuccess"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -225,4 +225,8 @@ if(!isset($_SESSION['userName'])){
<script src="../js/getBaseUrl.js"></script>
<script src="../js/landing.js"></script>
<link href="../css/landing.css" rel="stylesheet">
<script src="../js/bootstrap-datepicker.min.js"></script>
<script src="../js/typeahead.bundle.js"></script>
<link href="../css/bootstrap-datepicker.min.css" rel="stylesheet">
<link href="../css/landing.css" rel="stylesheet">

View File

@@ -0,0 +1,93 @@
<script src="../js/newEmployee.js"></script>
<script src="../js/getBaseUrl.js"></script>
<form class="form-horizontal" id="newEmployeeForm">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">New employee</h3>
</div>
<div class="panel-body">
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeFirstName">First name</label>
<div class="col-md-5">
<input id="newEmployeeFirstName" name="newEmployeeFirstName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeMiddleName">Middle name</label>
<div class="col-md-5">
<input id="newEmployeeMiddleName" name="newEmployeeMiddleName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeLastName">Last name</label>
<div class="col-md-5">
<input id="newEmployeeLastName" name="newEmployeeLastName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeBirthDate">Birth date</label>
<div class="col-md-5">
<input id="newEmployeeBirthDate" name="newEmployeeBirthDate" type="text" class="form-control input-md datepicker">
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeEmail">Email</label>
<div class="col-md-5">
<input id="newEmployeeEmail" name="newEmployeeEmail" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeePhone">Phone</label>
<div class="col-md-5">
<input id="newEmployeePhone" name="newEmployeePhone" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeType">Rol</label>
<div class="col-md-5">
<select class="form-control input-md" name="newEmployeeType" id="newEmployeeType">
<option>Employee type</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="NewEmpployyContractType">Contract type</label>
<div class="col-md-5">
<select class="form-control input-md" name="NewEmpployyContractType" id="NewEmpployyContractType">
<option>Contract type</option>
<option value="INTERNO">interno</option>
<option value="EXTERNO">Externo</option>
</select>
</div>
</div>
</div>
</div>
<div class="row col-md-offset-6">
<div class="form-group">
<a href="#" class="btn btn-lg btn-success " onclick="saveNewEmployee();">Create</a>
</div>
</div>
</div>
</div>
</div>
</form>

View File

@@ -0,0 +1,142 @@
<script src="../js/getBaseUrl.js"></script>
<script src="../js/registerWorkDays.js"></script>
<form class="form-horizontal" id="workDaysForm">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Managing work days</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysSearchEmployee">Search employee</label>
<div class="col-md-5">
<input id="workDaysSearchEmployee" name="workDaysSearchEmployee" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysSearchByDate">Search by date</label>
<div class="col-md-2">
<input id="workDaysSearchByDate" name="workDaysSearchByDate" type="text" class="form-control input-md datepicker">
</div>
</div>
</div>
</div>
<div id="registerWorkDaysEmployeeInfo" class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeName">Name</label>
<div class="col-md-5">
<input id="workDaysEmployeeName" name="workDaysEmployeeName" type="text" class="form-control input-md" disabled>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeRol">Rol</label>
<div class="col-md-5">
<select class="form-control input-md" name="workDaysEmployeeRol" id="workDaysEmployeeRol" disabled>
<option></option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeContractType">Contract type</label>
<div class="col-md-5">
<select class="form-control input-md" name="workDaysEmployeeContractType" id="workDaysEmployeeContractType" disabled>
<option>Contract type</option>
<option value="INTERNO">interno</option>
<option value="EXTERNO">Externo</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeWorkedDay">Date</label>
<div class="col-md-5">
<input id="workDaysEmployeeWorkedDay" name="workDaysEmployeeWorkedDay" type="text" class="form-control input-md datepicker">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeDeliveries">Deliveries</label>
<div class="col-md-5">
<input id="workDaysEmployeeDeliveries" name="workDaysEmployeeDeliveries" type="number" value="0" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeePerformedRol">Performed rol</label>
<div class="col-md-5">
<select class="form-control input-md" name="workDaysEmployeePerformedRol" id="workDaysEmployeePerformedRol" disabled>
<option>Employee type</option>
</select>
</div>
</div>
</div>
</div>
<div id="registerWorkDaysEmployeeSalary" class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeSalaryRaw">Raw</label>
<div class="col-md-5">
<input id="workDaysEmployeeSalaryRaw" name="workDaysEmployeeSalaryRaw" type="text" class="form-control input-md" disabled>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeSalaryTaxes">Taxes</label>
<div class="col-md-5">
<input id="workDaysEmployeeSalaryTaxes" name="workDaysEmployeeSalaryTaxes" type="text" class="form-control input-md" disabled>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeSalaryFinal">Final</label>
<div class="col-md-5">
<input id="workDaysEmployeeSalaryFinal" name="workDaysEmployeeSalaryFinal" type="text" class="form-control input-md" disabled>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="workDaysEmployeeSalaryVouchers">Vouchers</label>
<div class="col-md-5">
<input id="workDaysEmployeeSalaryVouchers" name="workDaysEmployeeSalaryVouchers" type="text" class="form-control input-md" disabled>
</div>
</div>
</div>
</div>
<div class="row" id="hidenEmployeeCodeForWorkDays">
<div class="form-group">
<label class="col-md-4 control-label" for="hidenEmployeeCodeForWorkDaysCode">Code</label>
<div class="col-md-5">
<input id="hidenEmployeeCodeForWorkDaysCode" name="hidenEmployeeCodeForWorkDaysCode" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row col-md-offset-6">
<div class="form-group">
<a href="#" class="btn btn-lg btn-success " onclick="processSaveActionWorkDay();">Save</a>
</div>
</div>
</div>
</div>
</form>

View File

@@ -1,3 +0,0 @@
function saveNewEmployee(){
console.log('saving...');
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,180 @@
/**
* Bootstrapping the starting actions for the module
*/
$(document).ready(function(){
let baseUrl = getbaseUrl();
loadEmployeeTypes();
$('.datepicker').datepicker({
format: "yyyy/mm/dd",
autoclose: true
});
// Not to be edited
$("#hidenEmployeeCode").hide();
// Setting up bloodhound typeahead
let employeesList = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace("name"),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
'cache': false,
url: baseUrl + '/api/employee/find',
replace: function(url, uriEncodedQuery) {
return url + '/' + uriEncodedQuery
},
wildcard: '%QUERY',
filter: function (data) {
return data;
}
}
});
employeesList.initialize();
$("#editEmploySearch").typeahead({
hint: true,
highlight: true,
minLength: 3
},
{
name: "result",
displayKey: "fullName",
source: employeesList.ttAdapter()
}).bind("typeahead:selected", function(obj, datum, name) {
$(this).data("id", datum.code);
loadEmployeeData(datum.code);
});
});
/**
* Loads the the employee types into their select option
*/
function loadEmployeeTypes(){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/employee/types',
type: 'GET',
dataType: 'json',
success:function(data){
$(data).each(function(i,v){
$('#editEmployeeType').append(
'<option value="' + v.id + '">'+ v.name + '</option>'
);
});
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
/**
* Searches the employee data by its employee code and loads it
* into the form to be edited and updated
*
* @param code string
*/
function loadEmployeeData(code){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/employee/code/' + code,
type: 'GET',
dataType: 'json',
success:function(data){
$('#editEmployeeFirstName').val(data['firstName']);
$('#editEmployeeMiddleName').val(data['middleName']);
$('#editEmployeeLastName').val(data['lastName']);
$('#editEmployeeBirthDate').val(data['birthDate']);
$('#editEmployeeCode').val(data['code']);
$('#editEmployeeEmail').val(data['email']);
$('#editEmployeePhone').val(data['phone']);
$('#editEmployeeType').val(data['idEmployeeType']);
$('#editEmployeeContractType').val(data['contractType']);
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
function updateEmployee(){
let baseUrl = getbaseUrl();
let parameters = {
"firstName":$('#editEmployeeFirstName').val(),
"middleName":$('#editEmployeeMiddleName').val(),
"lastName":$('#editEmployeeLastName').val(),
"birthDate":$('#editEmployeeBirthDate').val(),
"code":$('#editEmployeeCode').val(),
"email":$('#editEmployeeEmail').val(),
"phone":$('#editEmployeePhone').val(),
"idEmployeeType":$('#editEmployeeType').val(),
"contractType":$('#editEmployeeContractType').val()
};
$.ajax({
url: baseUrl + '/api/employee',
type: 'PUT',
dataType: 'json',
data: parameters,
success:function(data){
$('#modalServerResponseSuccess').modal('show');
document.getElementById('serverResponseSuccess').innerHTML = 'The employee ' + data['fullName'] + ' has been updated.';
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}

View File

@@ -14,15 +14,15 @@ function logout() {
},
error:function(x,e) {
if (x.status==0) {
$('#modal_error_internet').modal('show');
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modal_error_404').modal('show');
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modal_error_500').modal('show');
$('#modalError500').modal('show');
} else if(e=='parsererror') {
$('#modal_error_parsererror').modal('show');
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modal_error_timeout').modal('show');
$('#modalErrorTimeout').modal('show');
} else {
$('#modal_error_otro').modal('show');
}
@@ -60,15 +60,15 @@ function loadView(requestedView){
},
error:function(x,e) {
if (x.status==0) {
$('#modal_error_internet').modal('show');
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modal_error_404').modal('show');
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modal_error_500').modal('show');
$('#modalError500').modal('show');
} else if(e=='parsererror') {
$('#modal_error_parsererror').modal('show');
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modal_error_timeout').modal('show');
$('#modalErrorTimeout').modal('show');
} else {
$('#modal_error_otro').modal('show');
}

View File

@@ -16,9 +16,9 @@ $(document).keypress(function(e) {
* display errors to the user
*/
function processLogin() {
var baseUrl = getbaseUrl();
let baseUrl = getbaseUrl();
var parameters = {
let parameters = {
"userName":$('#userName').val(),
"password":$('#password').val()
};
@@ -29,7 +29,6 @@ function processLogin() {
dataType: 'json',
data: parameters,
success:function(data){
console.log(JSON.stringify(data));
if(data["status"] == "success"){
window.location.replace(baseUrl + '/html/landing.php');

View File

@@ -0,0 +1,94 @@
/**
* Bootstrapping the starting actions for the module
*/
$(document).ready(function(){
loadEmployeeTypes();
$('.datepicker').datepicker({
format: "yyyy/mm/dd",
autoclose: true
});
});
/**
* Loads the the enmployee types into their select option
*/
function loadEmployeeTypes(){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/employee/types',
type: 'GET',
dataType: 'json',
success:function(data){
$(data).each(function(i,v){
$('#newEmployeeType').append(
'<option value="' + v.id + '">'+ v.name + '</option>'
);
});
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
function saveNewEmployee(){
let baseUrl = getbaseUrl();
let parameters = {
"firstName":$('#newEmployeeFirstName').val(),
"middleName":$('#newEmployeeMiddleName').val(),
"lastName":$('#newEmployeeLastName').val(),
"birthDate":$('#newEmployeeBirthDate').val(),
"email":$('#newEmployeeEmail').val(),
"phone":$('#newEmployeePhone').val(),
"idEmployeeType":$('#newEmployeeType').val(),
"contractType":$('#NewEmpployyContractType').val()
};
$.ajax({
url: baseUrl + '/api/employee',
type: 'POST',
dataType: 'json',
data: parameters,
success:function(data){
$('#modalServerResponseSuccess').modal('show');
document.getElementById('serverResponseSuccess').innerHTML = 'The employee ' + data['fullName'] + ' has been created with the code ' + data['employeeCode'];
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}

View File

@@ -0,0 +1,359 @@
/**
* Bootstrapping the starting actions for the module
*/
$(document).ready(function(){
let baseUrl = getbaseUrl();
loadEmployeeTypesForWorkDays();
$('.datepicker').datepicker({
format: "yyyy-mm-dd",
autoclose: true
});
// Not to be edited
$("#hidenEmployeeCodeForWorkDays").hide();
// Setting up bloodhound typeahead
let employeesList = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace("name"),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
'cache': false,
url: baseUrl + '/api/employee/find',
replace: function(url, uriEncodedQuery) {
return url + '/' + uriEncodedQuery
},
wildcard: '%QUERY',
filter: function (data) {
return data;
}
}
});
employeesList.initialize();
$("#workDaysSearchEmployee").typeahead({
hint: true,
highlight: true,
minLength: 3
},
{
name: "result",
displayKey: "fullName",
source: employeesList.ttAdapter()
}).bind("typeahead:selected", function(obj, datum, name) {
$(this).data("id", datum.code);
loadEmployeeDataForWorkDays(datum.code);
validateEmployeeCanDoOtherRoles(datum.code);
loadSalaryDetails(datum.code);
$('#hidenEmployeeCodeForWorkDaysCode').val(datum.code); // For future reference
});
});
/**
* Loads the the employee types into their select option
*/
function loadEmployeeTypesForWorkDays(){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/employee/types',
type: 'GET',
dataType: 'json',
success:function(data){
$(data).each(function(i,v){
$('#workDaysEmployeeRol').append(
'<option value="' + v.id + '">'+ v.name + '</option>'
);
$('#workDaysEmployeePerformedRol').append(
'<option value="' + v.id + '">'+ v.name + '</option>'
);
});
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
/**
* Searches the employee data by its employee code and loads it
* into the form to be edited and saved
*
* @param code string
*/
function loadEmployeeDataForWorkDays(code){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/employee/code/' + code,
type: 'GET',
dataType: 'json',
success:function(data){
let fullName = data['firstName'] + ' ' + data['middleName'] + ' ' + data['lastName'];
$('#workDaysEmployeeName').val(fullName);
$('#workDaysEmployeeRol').val(data['idEmployeeType']);
$('#workDaysEmployeePerformedRol').val(data['idEmployeeType']);
$('#workDaysEmployeeContractType').val(data['contractType']);
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
/**
* Based on the employee code determines their type to decide if
* they should be able to cover for other roles or not
*
* @param code string
*/
function validateEmployeeCanDoOtherRoles(code){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/employee/type/' + code,
type: 'GET',
dataType: 'json',
success:function(data){
if(data == 3){
$("#workDaysEmployeePerformedRol").prop('disabled', false);
}
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
function loadSalaryDetails(code){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/employee/salary/' + code,
type: 'GET',
dataType: 'json',
success:function(data){
$('#workDaysEmployeeSalaryRaw').val(data['raw']);
$('#workDaysEmployeeSalaryTaxes').val(data['taxes']);
$('#workDaysEmployeeSalaryFinal').val(data['real']);
$('#workDaysEmployeeSalaryVouchers').val(data['vouchers']);
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
/**
* Bootstraper for the save action
*
* If the search by date function has been used it's then assumed that the
* desired action is to update else the function will attempt to create a new
* record for the worked day
*/
function processSaveActionWorkDay(){
if($('#workDaysSearchByDate').val() === ''){
saveNewWorkDay();
}else {
updateNewWorkDay();
}
}
function saveNewWorkDay(){
let baseUrl = getbaseUrl();
let parameters = {
"code":$('#hidenEmployeeCodeForWorkDaysCode').val(),
"idEmployeeTypePerformed":$('#workDaysEmployeePerformedRol').val(),
"deliveries":$('#workDaysEmployeeDeliveries').val(),
"date":$('#workDaysEmployeeWorkedDay').val(),
};
$.ajax({
url: baseUrl + '/api/employee/workday',
type: 'POST',
dataType: 'json',
data: parameters,
success:function(data){
$('#modalServerResponseSuccess').modal('show');
document.getElementById('serverResponseSuccess').innerHTML = data['message'];
loadSalaryDetails($('#hidenEmployeeCodeForWorkDaysCode').val());
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
function updateNewWorkDay(){
let baseUrl = getbaseUrl();
let parameters = {
"code":$('#hidenEmployeeCodeForWorkDaysCode').val(),
"idEmployeeTypePerformed":$('#workDaysEmployeePerformedRol').val(),
"deliveries":$('#workDaysEmployeeDeliveries').val(),
"date":$('#workDaysEmployeeWorkedDay').val(),
};
$.ajax({
url: baseUrl + '/api/employee/workday',
type: 'PUT',
dataType: 'json',
data: parameters,
success:function(data){
$('#modalServerResponseSuccess').modal('show');
document.getElementById('serverResponseSuccess').innerHTML = data['message'];
loadSalaryDetails($('#hidenEmployeeCodeForWorkDaysCode').val());
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
/**
* If the search by date field is changed from its default empty status it'll
* load the data of the given work day and enable the update mode
*/
$('#workDaysSearchByDate').on("change", function(data){
let baseUrl = getbaseUrl();
let date = $(this).val();
let code = $('#hidenEmployeeCodeForWorkDaysCode').val();
// The employee hasn't been picked
if (code === ''){
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = 'Please select an employee in the search form first.';
return false; // Exits the function
}
$.ajax({
url: baseUrl + '/api/employee/salary/date/' + date + '/code/' + code,
type: 'GET',
dataType: 'json',
success:function(data){
$('#workDaysEmployeeRol').val(data['idEmployeeType']);
$('#workDaysEmployeeContractType').val(data['contractType']);
$('#workDaysEmployeeWorkedDay').val(date);
$('#workDaysEmployeeDeliveries').val(data['deliveries']);
$('#workDaysEmployeePerformedRol').val(data['idEmployeeTypePerformed']);
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,7 @@
<?php
namespace App\Application;
use Exception;
use phpDocumentor\Reflection\Types\Integer;
class EmployeeApplication{
@@ -15,15 +16,16 @@ class EmployeeApplication{
$this->cryptographyService = $cryptographyService;
$this->pdo = $mysql;
$this->asserts = $asserts;
$this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.';
}
/**
* A list of the types of employee used in the system
*
* @return array
* @throws Exception
*/
function listEmployeeTypes(){
$stmt = $this->pdo->prepare("SELECT
$stmt = $this->pdo->prepare("SELECT
id, name
FROM
employeeType
@@ -34,7 +36,7 @@ class EmployeeApplication{
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
throw new Exception("The types of employees could not be found..");
}
$stmt = null;
@@ -54,16 +56,18 @@ class EmployeeApplication{
* @param $email string
* @param $phone string
* @return integer
* @throws Exception
*/
function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
$this->asserts->dateIsNotInTheFuture($birthDate, "The birth date can't be in the future.");
$this->asserts->isNotEmpty($email, "The email can't be empty.");
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
try {
$stmt = $this->pdo->prepare("INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone)
$stmt = $this->pdo->prepare("INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone)
VALUES (:firstName, :middleName, :lastName, :birthDate, :email, :phone)");
$this->pdo->beginTransaction();
$stmt->execute(array(':firstName' => $firstName, ':middleName' => $middleName, ':lastName' => $lastName,
@@ -87,6 +91,7 @@ class EmployeeApplication{
* @param $code string
* @param $contractType string
* @return mixed
* @throws Exception
*/
function savePersonAsEmployee($idEmployeeType, $idPerson, $code, $contractType){
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
@@ -94,7 +99,7 @@ class EmployeeApplication{
$this->asserts->isNotEmpty($code, "The code can't be empty.");
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
try {
$stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType)
$stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType)
VALUES (:idEmployeeType, :idPerson, :code, :contractType)");
$this->pdo->beginTransaction();
$stmt->execute(array(':idEmployeeType' => $idEmployeeType, ':idPerson' => $idPerson, ':code' => $code,
@@ -115,6 +120,7 @@ class EmployeeApplication{
/**
* @param $requestData object
* @return array
* @throws Exception
*/
function saveNewEmployee($requestData){
// Getting and validating the data
@@ -134,17 +140,23 @@ class EmployeeApplication{
$birthDate = $requestData['birthDate'];
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
$this->asserts->dateIsNotInTheFuture($birthDate, "The birth date can't be in the future.");
$email = $requestData['email'];
$this->asserts->isNotEmpty($email, "The email can't be empty.");
$this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters.");
$this->asserts->isEmail($email, "The email isn't in a correct format");
$phone = $requestData['phone'];
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
$this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters.");
$idEmployeeType = $requestData{'idEmployeeType'};
$this->asserts->higherThanZero($idEmployeeType, 'idEmployeeType must be higher than zero.');
$contractType = $requestData{'contractType'};
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
$this->asserts->existInArray($contractType, $this->settings['contractTypes'], 'The contract type is not a valid one.');
// Encrypting the sensitive data
$securedFirstName = $this->cryptographyService->encryptString($firstName);
@@ -179,12 +191,13 @@ class EmployeeApplication{
/**
* @param $idEmployee
* @return Integer
* @throws Exception
*/
function getIdPersonByIdEmployee($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$stmt = $this->pdo->prepare("SELECT
COALESCE((SELECT
$stmt = $this->pdo->prepare("SELECT
COALESCE((SELECT
idPerson
FROM
employees
@@ -195,7 +208,7 @@ class EmployeeApplication{
$stmt->execute(array(':idEmployee' => $idEmployee));
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
throw new Exception("An error occurred while trying to find the person associated with the employee..");
}
$stmt = null;
@@ -205,11 +218,12 @@ class EmployeeApplication{
/**
* @param $code string
* @return integer
* @throws Exception
*/
function getIdEmployeeTypeByCode($code){
$this->asserts->isNotEmpty($code, "The code can't be empty.");
$stmt = $this->pdo->prepare("SELECT COALESCE((SELECT
$stmt = $this->pdo->prepare("SELECT COALESCE((SELECT
et.id
FROM
employees e
@@ -221,7 +235,35 @@ class EmployeeApplication{
$stmt->execute(array(':code' => $code));
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
throw new Exception("The employee could not be found.");
}
$stmt = null;
return $results[0]['id'];
}
/**
* @param $code string
* @return integer
* @throws Exception
*/
function getIdEmployeeByCode($code){
$this->asserts->isNotEmpty($code, "The code can't be empty.");
$stmt = $this->pdo->prepare("SELECT
COALESCE((SELECT
id
FROM
employees
WHERE
code = :code),
0) AS id;
");
$stmt->execute(array(':code' => $code));
$results = $stmt->fetchAll();
if(!$results){
throw new Exception("The employee could not be found.");
}
$stmt = null;
@@ -233,18 +275,22 @@ class EmployeeApplication{
*
* @param $idEmployee
* @return array
* @throws Exception
*/
function getEmployeeDataById($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$stmt = $this->pdo->prepare("SELECT
$stmt = $this->pdo->prepare("SELECT
e.id AS idEmployee,
p.id AS idPerson,
p.firstName,
p.middleName,
IFNULL(p.lastName, '') AS lastName,
p.birthDate,
p.email,
p.phone,
e.code,
e.idEmployeeType,
e.contractType
FROM
employees e
@@ -256,7 +302,7 @@ class EmployeeApplication{
$stmt->execute(array(':idEmployee' => $idEmployee));
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
throw new Exception("The employee could not be found.");
}
$stmt = null;
@@ -269,6 +315,7 @@ class EmployeeApplication{
*
* @param $idEmployee
* @return array
* @throws Exception
*/
function proxyGetEmployeeDataById($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
@@ -276,6 +323,7 @@ class EmployeeApplication{
$employeeData = $this->getEmployeeDataById($idEmployee);
$response = array(
"idEmployee" => (int)$employeeData['idEmployee'],
"idPerson" => (int)$employeeData['idPerson'],
"firstName" => $this->cryptographyService->decryptString($employeeData['firstName']),
"middleName" => $this->cryptographyService->decryptString($employeeData['middleName']),
@@ -284,9 +332,11 @@ class EmployeeApplication{
? $this->cryptographyService->decryptString($employeeData['lastName'])
: '',
"birthDate" => $employeeData['birthDate'],
"email" => $this->cryptographyService->decryptString($employeeData['email']),
"phone" => $employeeData['phone'],
"code" => $employeeData['code'],
"idEmployeeType" => $employeeData['idEmployeeType'],
"contractType" => $employeeData['contractType']
);
@@ -297,11 +347,12 @@ class EmployeeApplication{
/**
* @param $code string
* @return array
* @throws Exception
*/
function getEmployeeDataByCode($code){
$this->asserts->isNotEmpty($code, "The code can't be empty.");
$idEmployee = $this->getIdEmployeeTypeByCode($code);
$idEmployee = $this->getIdEmployeeByCode($code);
return $this->proxyGetEmployeeDataById($idEmployee);
}
@@ -320,12 +371,13 @@ class EmployeeApplication{
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
$this->asserts->dateIsNotInTheFuture($birthDate, "The birth date can't be in the future.");
$this->asserts->isNotEmpty($email, "The email can't be empty.");
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
try {
$stmt = $this->pdo->prepare("UPDATE persons
SET
$stmt = $this->pdo->prepare("UPDATE persons
SET
firstName = :firstName,
middleName = :middleName,
lastName = :lastName,
@@ -358,8 +410,8 @@ class EmployeeApplication{
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
try {
$stmt = $this->pdo->prepare("UPDATE employees
SET
$stmt = $this->pdo->prepare("UPDATE employees
SET
idEmployeeType = :idEmployeeType,
code = :code,
contractType = :contractType
@@ -379,18 +431,16 @@ class EmployeeApplication{
/**
* @param $requestData object
* @return array
* @throws Exception
*/
function updateEmployeeData($requestData){
// Getting and validating the data
$idEmployee = $requestData['idEmployee'];
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
$this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0");
$code = $requestData['code'];
$this->asserts->isNotEmpty($code, "The code can't be empty.");
$idEmployee = $this->getIdEmployeeByCode($code);
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
$firstName = $requestData['firstName'];
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
$this->asserts->isString($firstName, "The first name must be a string.");
@@ -405,10 +455,12 @@ class EmployeeApplication{
$birthDate = $requestData['birthDate'];
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
$this->asserts->dateIsNotInTheFuture($birthDate, "The birth date can't be in the future.");
$email = $requestData['email'];
$this->asserts->isNotEmpty($email, "The email can't be empty.");
$this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters.");
$this->asserts->isEmail($email, "The email isn't in a correct format");
$phone = $requestData['phone'];
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
@@ -419,6 +471,7 @@ class EmployeeApplication{
$contractType = $requestData{'contractType'};
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
$this->asserts->existInArray($contractType, $this->settings['contractTypes'], 'The contract type is not a valid one.');
// Encrypting the sensitive data
$securedFirstName = $this->cryptographyService->encryptString($firstName);
@@ -455,8 +508,8 @@ class EmployeeApplication{
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
try {
$stmt = $this->pdo->prepare("UPDATE employees
SET
$stmt = $this->pdo->prepare("UPDATE employees
SET
status = 'INACTIVE'
WHERE
id = :idEmployee");
@@ -477,9 +530,10 @@ class EmployeeApplication{
* currently active in the system
*
* @return array
* @throws Exception
*/
function getIdEmployeeFromAllActiveEmployees(){
$stmt = $this->pdo->prepare("SELECT
$stmt = $this->pdo->prepare("SELECT
id
FROM
employees
@@ -490,7 +544,7 @@ class EmployeeApplication{
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
throw new Exception("The employee could not be found.");
}
$stmt = null;
@@ -498,7 +552,11 @@ class EmployeeApplication{
}
/**
* Uses an already existing method to create and array containing the details of
* all currently active employees
*
* @return array
* @throws Exception
*/
function listAllActiveEmployees(){
$ids = $this->getIdEmployeeFromAllActiveEmployees();
@@ -506,10 +564,604 @@ class EmployeeApplication{
$result = array();
foreach($ids as $row){
$result[] = $this->proxyGetEmployeeDataById($row['id']);
$currentEmployee = $this->proxyGetEmployeeDataById($row['id']);
$result[] = array(
'fullName' => $currentEmployee['firstName']." ".
$currentEmployee['middleName']." ".
$currentEmployee['lastName'],
'code' => $currentEmployee['code']
);
}
return $result;
}
/**
* Takes an array of all active employees and filters them by a string, returning
* all sub arrays that contain such string
*
* @param $partialName string
* @return array
* @throws Exception
*/
function findEmployeeByFullName($partialName){
$fullList = $this->listAllActiveEmployees();
$pattern = '/'.$partialName.'/';
$matches = array_filter($fullList, function($a) use($pattern) {
return preg_grep($pattern, $a);
});
return $matches;
}
/**
* @param $idEmployee integer
* @param $date date
* @return integer
* @throws Exception
*/
function findIdPaymentPerDayByEmployeeAndDate($idEmployee, $date){
$this->asserts->isNotEmpty($idEmployee, "The code can't be empty.");
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$this->asserts->isNotEmpty($date, "The code can't be empty.");
$this->asserts->dateIsNotInTheFuture($date, "The date can't be in the future.");
$stmt = $this->pdo->prepare("SELECT
COALESCE((SELECT
id
FROM
paymentsPerEmployeePerDay
WHERE
date = :date AND idEmployee = :idEmployee),
0) AS id;
");
$stmt->execute(array(':date' => $date, ':idEmployee' => $idEmployee));
$results = $stmt->fetchAll();
if(!$results){
throw new Exception("The registry of the worked day could not be found.");
}
$stmt = null;
return $results[0]['id'];
}
/**
* Helper to determine if the date has already been saved as a worked day for
* an employee, so long as it's currently active in the database
*
* @param $idEmployee integer
* @param $date date
* @return integer
* @throws Exception
*/
function checkDateNotUsedWorkDayPerEmployee($idEmployee, $date){
$this->asserts->isNotEmpty($idEmployee, "The code can't be empty.");
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$this->asserts->isNotEmpty($date, "The code can't be empty.");
$this->asserts->dateIsNotInTheFuture($date, "The date can't be in the future.");
$stmt = $this->pdo->prepare("SELECT
COALESCE((SELECT
COUNT(*)
FROM
paymentsPerEmployeePerDay
WHERE
date = :date AND idEmployee = :idEmployee
AND status = 'ACTIVE'),
0) AS timesDateFound");
$stmt->execute(array(':date' => $date, ':idEmployee' => $idEmployee));
$results = $stmt->fetchAll();
if(!$results){
throw new Exception('Unable to find the date of the worked days.');
}
$stmt = null;
return $results[0]['timesDateFound'];
}
/**
* Saves the new worked day for the employee
*
* @param $idEmployee integer
* @param $date date
* @param $baseAmount double
* @param $bonusTime double
* @param $deliveries double
* @return integer
* @throws Exception
*/
function saveWorkedDay($idEmployee, $date, $baseAmount, $bonusTime, $deliveries){
$this->asserts->isNotEmpty($idEmployee, "The idEmployee can't be empty.");
$this->asserts->isNotEmpty($date, "The date can't be empty.");
$this->asserts->dateIsNotInTheFuture($date, "The date can't be in the future.");
$this->asserts->isNotEmpty($baseAmount, "The base payment per day can't be empty.");
$this->asserts->isNotEmpty($bonusTime, "The bonus per worked hours can't be empty.");
$this->asserts->isNotEmpty($deliveries, "The payment for deliveries can't be empty.");
try {
$stmt = $this->pdo->prepare("INSERT INTO paymentsPerEmployeePerDay
(idEmployee, date, baseAmount, bonusTime, deliveries)
VALUES (:idEmployee, :date, :baseAmount, :bonusTime, :deliveries)");
$this->pdo->beginTransaction();
$stmt->execute(array(':idEmployee' => $idEmployee, ':date' => $date, ':baseAmount' => $baseAmount,
':bonusTime' => $bonusTime, ':deliveries' => $deliveries));
$id = $this->pdo->lastInsertId();
$this->pdo->commit();
return $id;
$stmt = null;
} catch( PDOExecption $e ) {
$this->pdo->rollback();
throw new Exception('There was an error while trying to save the worked day.');
}
}
/**
* Changes the status in the detail table for the registry of worked days so
* that it behaves as if deleted
* @param $idEmployee
* @param $date
*/
function dissablePaymentPerDayDetailsByEmployeeAndDate($idEmployee, $date){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$this->asserts->isNotEmpty($date, "The worked date cannot be empty.");
$this->asserts->dateIsNotInTheFuture($date, "The date can't be in the future.");
try {
$stmt = $this->pdo->prepare("UPDATE paymentsPerEmployeePerDayDetail a
INNER JOIN
paymentsPerEmployeePerDay b ON b.id = a.idPaymentPerEmployeePerDay
SET
a.status = 'INACTIVE'
WHERE
b.date = :date AND b.idEmployee = :idEmployee");
$this->pdo->beginTransaction();
$stmt->execute(array(':date' => $date, ':idEmployee' => $idEmployee));
$this->pdo->commit();
$stmt = null;
} catch( PDOExecption $e ) {
$this->pdo->rollback();
}
}
/**
* @param $id integer - references paymentsPerEmployeePerDay
* @param $baseAmount double
* @param $bonusTime double
* @param $deliveries double
*/
function updateWorkedDayPayments($id, $baseAmount, $bonusTime, $deliveries){
$this->asserts->higherThanZero($id, "id payment must be higher than 0");
$this->asserts->higherThanZero($baseAmount, "baseAmount must be higher than 0");
$this->asserts->higherThanZero($bonusTime, "bonusTime must be higher than 0");
$this->asserts->higherThanZero($deliveries, "deliveries must be higher than 0");
try {
$stmt = $this->pdo->prepare("UPDATE paymentsPerEmployeePerDay
SET
baseAmount = :baseAmount,
bonusTime = :bonusTime,
deliveries = :deliveries
WHERE
id = :id");
$this->pdo->beginTransaction();
$stmt->execute(array(':baseAmount' => $baseAmount, ':bonusTime' => $bonusTime, ':deliveries' => $deliveries,
':id' => $id));
$this->pdo->commit();
$stmt = null;
} catch( PDOExecption $e ) {
$this->pdo->rollback();
}
}
/**
* Takes the data from the front end for the work day, this coulld be
* for an update or a creation of a new registry
*
* The function will take the request body, validate it and pass the
* processed data back to the wrapper method
*
* @param $requestData object
* @return array
* @throws Exception
*/
function validateDataForStorageWorkDay($requestData){
$code = $requestData['code'];
$this->asserts->isNotEmpty($code, "The code can't be empty.");
$idEmployee = $this->getIdEmployeeByCode($code);
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$idEmployeeType = $this->getIdEmployeeTypeByCode($code);
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
$idEmployeeTypePerformed = $requestData['idEmployeeTypePerformed'];
$this->asserts->isNotEmpty($idEmployeeTypePerformed, "The performed rol must be provided.");
$this->asserts->higherThanZero($idEmployeeTypePerformed, "idEmployeeTypePerformed must be higher than 0");
$deliveries = $requestData['deliveries'];
$this->asserts->isNotEmpty($deliveries, "The number of deliveries cannot be empty or 0.");
$date = $requestData['date'];
$this->asserts->isNotEmpty($date, "The worked date cannot be empty.");
$this->asserts->dateIsNotInTheFuture($date, "The date can't be in the future.");
// The emplpoyee can't take that rol
if($idEmployeeType != 3 and $idEmployeeType != $idEmployeeTypePerformed){
throw new Exception("The performed rol can't be done by this type of employee.");
}
// If we're working on a different month
$this->asserts->datesHaveSameMonth($date, date('Y-m-d'), "Work days can only be registered within the same month.");
$baseAmountPaid = $this->settings['hoursPerWorkDay'] * $this->settings['paymentPerHour'];
// Getting setting data based on employee type that was performed
switch ($idEmployeeTypePerformed) {
case 1:
$perHourBonus = $this->settings['perHourBonusDriver'];
break;
case 2:
$perHourBonus = $this->settings['perHourBonusLoader'];
break;
case 3:
$perHourBonus = $this->settings['perHourBonusAux'];
break;
}
$bonusTime = $perHourBonus * $this->settings['hoursPerWorkDay'];
$bonusDeliveries = $deliveries * $this->settings['bonusPerDelivery'];
$contractType = $this->getContractTypeByEmployee($idEmployee);
$result = array(
'idEmployee' => (int)$idEmployee,
'date' => $date,
'baseAmountPaid' => $baseAmountPaid,
'bonusTime' => $bonusTime,
'bonusDeliveries' => $bonusDeliveries,
'contractType' => $contractType,
'idEmployeeType' => (int)$idEmployeeType,
'idEmployeeTypePerformed' => (int)$idEmployeeTypePerformed,
'hoursPerWorkDay' => $this->settings['hoursPerWorkDay'],
'paymentPerHour' => $this->settings['paymentPerHour'],
'perHourBonus' => $perHourBonus,
'deliveries' => $deliveries,
'bonusPerDelivery' => $this->settings['bonusPerDelivery']
);
return $result;
}
/**
* Wrapper function to store a new day that has been worked by an employee
*
* @param $requestData object
* @return array
* @throws Exception
*/
function newWorkedDay($requestData){
$data = $this->validateDataForStorageWorkDay($requestData);
if($this->checkDateNotUsedWorkDayPerEmployee($data['idEmployee'], $data['date']) > 0){
throw new Exception("This date has already been saved as a worked day.");
}
$idPaymentPerEmployeePerDay = $this->saveWorkedDay($data['idEmployee'], $data['date'],
$data['baseAmountPaid'], $data['bonusTime'], $data['bonusDeliveries']);
$this->storeWorkDayDetails($idPaymentPerEmployeePerDay, $data['idEmployeeType'],
$data['idEmployeeTypePerformed'], $data['contractType'], $data['hoursPerWorkDay'],
$data['paymentPerHour'], $data['perHourBonus'], $data['deliveries'], $data['bonusPerDelivery']);
return array('status' => 'success', 'message' => 'The worked day has been saved.', 'data' => $requestData);
}
/**
* Wrapper method to update a worked day for an employee
*
* @param $requestData object
* @return array
* @throws Exception
*/
function updateWorkDay($requestData){
$data = $this->validateDataForStorageWorkDay($requestData);
$this->dissablePaymentPerDayDetailsByEmployeeAndDate($data['idEmployee'], $data['date']);
$idPaymentPerEmployeePerDay = $this->findIdPaymentPerDayByEmployeeAndDate($data['idEmployee'], $data['date']);
$this->updateWorkedDayPayments($idPaymentPerEmployeePerDay, $data['baseAmountPaid'], $data['bonusTime'], $data['bonusDeliveries']);
$this->storeWorkDayDetails($idPaymentPerEmployeePerDay, $data['idEmployeeType'],
$data['idEmployeeTypePerformed'], $data['contractType'], $data['hoursPerWorkDay'],
$data['paymentPerHour'], $data['perHourBonus'], $data['deliveries'], $data['bonusPerDelivery']);
return array('status' => 'success', 'message' => 'The worked day has been updated.', 'data' => $requestData);
}
/**
* The number of days the employee has worked for a given year and month only
* taking into accout the active ones
*
* @param $idEmployee integer
* @param $year integer
* @param $month integer
* @return integer
* @throws Exception
*/
function findNumberWorkedOfDaysByEmployeeAndDate($idEmployee, $year, $month){
$this->asserts->isNotEmpty($idEmployee, "The code can't be empty.");
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$this->asserts->higherThanZero($year, "year must be higher than 0");
$this->asserts->higherThanZero($month, "month must be higher than 0");
$stmt = $this->pdo->prepare("SELECT
COALESCE((SELECT
COUNT(*)
FROM
paymentsPerEmployeePerDay
WHERE
idEmployee = :idEmployee
AND YEAR(date) = :year
AND MONTH(date) = :month
AND status = 'ACTIVE'),
0) AS workedDays");
$stmt->execute(array(':idEmployee' => $idEmployee, ':year' => $year, ':month' => $month));
$results = $stmt->fetchAll();
if(!$results){
throw new Exception('Unable to determine the amount of worked days.');
}
$stmt = null;
return $results[0]['workedDays'];
}
/**
* A list of the data contained from all the days the employee has worked
* for the given month and year
*
* @param $idEmployee integer
* @param $year integer
* @param $month integer
* @return array
* @throws Exception
*/
function getDataWorkedDaysByEmployee($idEmployee, $year, $month){
$stmt = $this->pdo->prepare("SELECT
baseAmount, bonusTime, deliveries
FROM
paymentsPerEmployeePerDay
WHERE
idEmployee = :idEmployee AND
YEAR(date) = :year
AND MONTH(date) = :month
AND status = 'ACTIVE'");
$stmt->execute(array(':idEmployee' => $idEmployee, ':year' => $year, ':month' => $month));
$results = $stmt->fetchAll();
if(!$results){
throw new Exception("No data of the worked days could be found.");
}
$stmt = null;
return $results;
}
/**
* @param $idEmployee integer
* @return string
* @throws Exception
*/
function getContractTypeByEmployee($idEmployee){
$this->asserts->isNotEmpty($idEmployee, "The code can't be empty.");
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$stmt = $this->pdo->prepare("SELECT
contractType
FROM
employees
WHERE
id = :idEmployee");
$stmt->execute(array(':idEmployee' => $idEmployee));
$results = $stmt->fetchAll();
if(!$results){
throw new Exception("The employee wasn't found.");
}
$stmt = null;
return $results[0]['contractType'];
}
/**
* Creates a backup of the information used to calculate the amount that the employee
* will be paid for the submitted day
*
* @param $idPaymentPerEmployeePerDay integer
* @param $idEmployeeType integer
* @param $idEmployeeTypePerformed integer
* @param $contractType string
* @param $hoursWorked double
* @param $paymentPerHour double
* @param $bonusPerHour double
* @param $deliveries integer
* @param $paymentPerDelivery double
* @return integer
* @throws Exception
*/
function storeWorkDayDetails($idPaymentPerEmployeePerDay, $idEmployeeType, $idEmployeeTypePerformed, $contractType, $hoursWorked,
$paymentPerHour, $bonusPerHour, $deliveries, $paymentPerDelivery){
$this->asserts->isNotEmpty($idPaymentPerEmployeePerDay, "The idPaymentPerEmployeePerDay can't be empty.");
$this->asserts->isNotEmpty($idEmployeeType, "The idEmployeeType can't be empty.");
$this->asserts->isNotEmpty($idEmployeeTypePerformed, "The idEmployeeTypePerformed can't be empty.");
$this->asserts->isNotEmpty($contractType, "The contractType can't be empty.");
$this->asserts->isNotEmpty($hoursWorked, "The hoursWorked can't be empty.");
$this->asserts->isNotEmpty($paymentPerHour, "The paymentPerHour can't be empty.");
$this->asserts->isNotEmpty($bonusPerHour, "The bonusPerHour can't be empty.");
$this->asserts->isNotEmpty($deliveries, "The deliveries can't be empty.");
$this->asserts->isNotEmpty($paymentPerDelivery, "The paymentPerDelivery can't be empty.");
try {
$stmt = $this->pdo->prepare("INSERT INTO paymentsPerEmployeePerDayDetail
(idPaymentPerEmployeePerDay, idEmployeeType, idEmployeeTypePerformed,
contractType, hoursWorked, paymentPerHour, bonusPerHour, deliveries, paymentPerDelivery)
VALUES
(:idPaymentPerEmployeePerDay, :idEmployeeType, :idEmployeeTypePerformed,
:contractType, :hoursWorked, :paymentPerHour, :bonusPerHour, :deliveries, :paymentPerDelivery)");
$this->pdo->beginTransaction();
$stmt->execute(array(':idPaymentPerEmployeePerDay' => $idPaymentPerEmployeePerDay,
':idEmployeeType' => $idEmployeeType,
':idEmployeeTypePerformed' => $idEmployeeTypePerformed,
':contractType' => $contractType,
':hoursWorked' => $hoursWorked,
':paymentPerHour' => $paymentPerHour,
':bonusPerHour' => $bonusPerHour,
':deliveries' => $deliveries,
':paymentPerDelivery' => $paymentPerDelivery)
);
$id = $this->pdo->lastInsertId();
$this->pdo->commit();
return $id;
$stmt = null;
} catch( PDOExecption $e ) {
$this->pdo->rollback();
throw new Exception("An error occured while saving the work day details.");
}
}
/**
* @param $date date
* @param $code string
* @return array
* @throws Exception
*/
function getDataWorkDayByDateAndCode($date, $code){
$idEmployee = $this->getIdEmployeeByCode($code);
$this->asserts->dateIsNotInTheFuture($date, "The date can't be in the future.");
$stmt = $this->pdo->prepare("SELECT
b.idPaymentPerEmployeePerDay,
b.idEmployeeType,
b.idEmployeeTypePerformed,
b.contractType,
b.hoursWorked,
b.paymentPerHour,
b.bonusPerHour,
b.deliveries,
b.paymentPerDelivery
FROM
paymentsPerEmployeePerDay a
INNER JOIN
paymentsPerEmployeePerDayDetail b ON b.idPaymentPerEmployeePerDay = a.id
WHERE
a.idEmployee = :idEmployee
AND a.date = :date
AND a.status = 'ACTIVE'
AND b.status = 'ACTIVE'
ORDER BY b.id DESC
LIMIT 1");
$stmt->execute(array(':idEmployee' => $idEmployee, ':date' => $date));
$results = $stmt->fetchAll();
if(!$results){
throw new Exception("No data of the work day was found.");
}
$stmt = null;
foreach($results as $row){
$data = array(
'idPaymentPerEmployeePerDay' => (int)$row['idPaymentPerEmployeePerDay'],
'idEmployeeType' => (int)$row['idEmployeeType'],
'idEmployeeTypePerformed' => (int)$row['idEmployeeTypePerformed'],
'contractType' => $row['contractType'],
'hoursWorked' => (int)$row['hoursWorked'],
'paymentPerHour' => (int)$row['paymentPerHour'],
'bonusPerHour' => (int)$row['bonusPerHour'],
'deliveries' => (int)$row['deliveries'],
'paymentPerDelivery' => (int)$row['paymentPerDelivery']
);
}
return $data;
}
/**
* Gets all the worked days for an employee and determines how much they're
* getting paid
*
* Will only work for the current month
*
* @param $code string
* @return array
* @throws Exception
*/
function calculateSalaryByCode($code){
$this->asserts->isNotEmpty($code, "The code can't be empty.");
$idEmployee = $this->getIdEmployeeByCode($code);
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$salary = array(
'raw' => 0,
'taxes' => 0,
'real' => 0,
'vouchers' => 0
);
// No worked days found
if($this->findNumberWorkedOfDaysByEmployeeAndDate($idEmployee, date('Y'), date('m')) <= 0){
return $salary;
}
$dataWorkedDays = $this->getDataWorkedDaysByEmployee($idEmployee, date('Y'), date('m'));
$monthlyPayment = 0;
foreach($dataWorkedDays as $row){
$monthlyPayment = $monthlyPayment + $row['baseAmount'] + $row['bonusTime'] + $row['deliveries'];
}
$salary['raw'] = $monthlyPayment;
if($monthlyPayment >= $this->settings['amountForExtraTaxes']){
$this->settings['taxesAddUp']
? $taxes = $monthlyPayment * ($this->settings['baseIsr'] + $this->settings['extraIsr'])
: $taxes = ($monthlyPayment * $this->settings['baseIsr']) + (($monthlyPayment * $this->settings['baseIsr']) * $this->settings['extraIsr']);
}else{
$taxes = $monthlyPayment * $this->settings['baseIsr'];
}
$salary['taxes'] = $taxes;
$salary['real'] = $monthlyPayment - $taxes;
$contractType = $this->getContractTypeByEmployee($idEmployee);
if($contractType == 'INTERNO'){
$vouchers = $monthlyPayment * $this->settings['percentOfPaymentForVouchers'];
}elseif ($contractType == 'EXTERNO'){
$this->settings['vouchersForAllContractTypes']
? $vouchers = $monthlyPayment * $this->settings['percentOfPaymentForVouchers']
: $vouchers = 0;
}
$salary['vouchers'] = $vouchers;
return $salary;
}
}
?>
?>

View File

@@ -12,8 +12,6 @@ class SessionApplication{
$this->cryptographyService = $cryptographyService;
$this->pdo = $mysql;
$this->asserts = $asserts;
$this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.';
}
/**

View File

@@ -41,10 +41,12 @@ $app->get('/api/employee/types', function (Request $request, Response $response,
->write(json_encode($this->employeeApplication->listEmployeeTypes()));
});
$app->get('/api/employee/all', function (Request $request, Response $response, array $args) {
$app->get('/api/employee/find/{partialName}', function (Request $request, Response $response, array $args) {
$partialName = $args['partialName'];
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->listAllActiveEmployees()));
->write(json_encode($this->employeeApplication->findEmployeeByFullName($partialName)));
});
$app->post('/api/employee', function ($request, $response) {
@@ -93,4 +95,37 @@ $app->get('/api/employee/code/{code}', function (Request $request, Response $res
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->getEmployeeDataByCode($code)));
});
});
$app->post('/api/employee/workday', function ($request, $response) {
$requestData = $request->getParsedBody();
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->newWorkedDay($requestData)));
});
$app->put('/api/employee/workday', function ($request, $response) {
$requestData = $request->getParsedBody();
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->updateWorkDay($requestData)));
});
$app->get('/api/employee/salary/{code}', function (Request $request, Response $response, array $args) {
$code = $args['code'];
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->calculateSalaryByCode($code)));
});
$app->get('/api/employee/salary/date/{date}/code/{code}', function (Request $request, Response $response, array $args) {
$date = $args['date'];
$code = $args['code'];
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->getDataWorkDayByDateAndCode($date, $code)));
});

View File

@@ -56,5 +56,55 @@ class Asserts{
throw new Exception($errorMessage);
}
}
/**
* Compares a string against a regex to determine if it's an email
*
* @param $string string
* @param $errorMessage string
* @throws Exception
*/
function isEmail($string, $errorMessage){
if(!filter_var($string, FILTER_VALIDATE_EMAIL)){
throw new Exception($errorMessage);
}
}
/**
* @param $string string
* @param $array array
* @param $errorMessage string
* @throws Exception
*/
function existInArray($string, $array, $errorMessage){
if(!in_array($string, $array)){
throw new Exception($errorMessage);
}
}
/**
* Compares two dates to dertermine if they have the same month
*
* @param $firstDate date
* @param $secondDate date
* @param $errorMessage string
* @throws Exception
*/
function datesHaveSameMonth($firstDate, $secondDate, $errorMessage){
if (date("m",strtotime($firstDate)) != date("m",strtotime($secondDate))){
throw new Exception($errorMessage);
}
}
/**
* @param $date
* @param $errorMessage
* @throws Exception
*/
function dateIsNotInTheFuture($date, $errorMessage){
if ($date > date('Y-m-d')){
throw new Exception($errorMessage);
}
}
}
?>

View File

@@ -45,6 +45,19 @@ return [
// Employee settings
'employee' => [
'codeLength' => '3',
'contractTypes' => array('INTERNO', 'EXTERNO'),
'hoursPerWorkDay' => 8,
'paymentPerHour' => 30,
'bonusPerDelivery' => 5,
'perHourBonusDriver' => 10,
'perHourBonusLoader' => 5,
'perHourBonusAux' => 0,
'baseIsr' => .09,
'extraIsr' => .03,
'taxesAddUp' => true, // If true this will be total/(9 + 3) else they're subtracted separately
'amountForExtraTaxes' => 16000,
'vouchersForAllContractTypes' => false, // Outsourced personal won't get vouchers
'percentOfPaymentForVouchers' => .04,
],
],
];

View File

@@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS `persons` (
`lastName` varbinary(500) comment 'The last name of the person',
`birthDate` DATE NOT NULL DEFAULT '1900-01-01' comment 'Date of birth of the person',
`email` varbinary(500) NOT NULL comment 'The email adress of the person',
`phone` INT(10) UNSIGNED NOT NULL comment 'The phone number of the person should be the mobile one but leaves room for home ones',
`phone` BIGINT(10) UNSIGNED NOT NULL comment 'The phone number of the person should be the mobile one but leaves room for home ones',
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
@@ -71,5 +71,44 @@ CREATE TABLE IF NOT EXISTS `employees` (
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
PRIMARY KEY (`id`),
INDEX `idx_contractType` (`contractType`),
UNIQUE (`code`)
);
DROP TABLE IF EXISTS paymentsPerEmployeePerDay;
CREATE TABLE IF NOT EXISTS `paymentsPerEmployeePerDay` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`idEmployee` INT UNSIGNED NOT NULL comment 'The employee to who this payment will be made',
`date` DATE NOT NULL DEFAULT '1900-01-01' comment 'Date of the worked day',
`baseAmount` DOUBLE(10,2) NOT NULL DEFAULT 0.0 comment 'Amount paid for the hours worked',
`bonusTime` DOUBLE(10,2) NOT NULL DEFAULT 0.0 comment 'Bonus paid for the hours worked',
`deliveries` DOUBLE(10,2) NOT NULL DEFAULT 0.0 comment 'Bonus for the number of deliveries',
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
PRIMARY KEY (`id`),
FOREIGN KEY (idEmployee) REFERENCES employees(id),
UNIQUE (`idEmployee`, `date`, `status`)
);
DROP TABLE IF EXISTS paymentsPerEmployeePerDayDetail;
CREATE TABLE IF NOT EXISTS `paymentsPerEmployeePerDayDetail` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`idPaymentPerEmployeePerDay` INT UNSIGNED NOT NULL comment 'References the payment for the work day',
`idEmployeeType` INT UNSIGNED NOT NULL comment 'The type of employee',
`idEmployeeTypePerformed` INT UNSIGNED NOT NULL comment 'The employee working for the day as',
`contractType` ENUM('INTERNO', 'EXTERNO') NOT NULL comment 'The type of contract',
`hoursWorked` DOUBLE(10,2) NOT NULL DEFAULT 0.0 comment 'Hours worked for the day',
`paymentPerHour` DOUBLE(10,2) NOT NULL DEFAULT 0.0 comment 'Payment per hour worked',
`bonusPerHour` DOUBLE(10,2) NOT NULL DEFAULT 0.0 comment 'Bonus payment per hour worked',
`deliveries` INT UNSIGNED NOT NULL DEFAULT 0 comment 'Total amount of deliveries for the day',
`paymentPerDelivery` DOUBLE(10,2) NOT NULL DEFAULT 0.0 comment 'Payment for each delivery done',
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
PRIMARY KEY (`id`),
FOREIGN KEY (idPaymentPerEmployeePerDay) REFERENCES paymentsPerEmployeePerDay(id),
FOREIGN KEY (idEmployeeType) REFERENCES employeeType(id),
FOREIGN KEY (idEmployeeTypePerformed) REFERENCES employeeType(id),
FOREIGN KEY (contractType) REFERENCES employees(contractType)
);