Compare commits

..

No commits in common. "master" and "creatingNewEmployeeFromView" have entirely different histories.

30 changed files with 112 additions and 4579 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
# payroll_manager

View File

@ -1,71 +0,0 @@
=================
Payroll manager
=================
|codebuild|
This is a simple system to keep a record of employees where they will perform different tasks within the company and will be paid accordingly in a monthly bases.
.. contents::
Getting started
-----------------
The system requires the following:
- Ubuntu 16.04
- php 7.0
- composer
- docker
- docker-compose
- mysql 5.7
Installation
-----------------
Alternatively to installing all the packages and configuring the server it's possible to start up an instance of the system with docker-compose
To install docker
.. code-block:: bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
apt-cache policy docker-ce
sudo apt-get install -y docker-ce
To install docker compose
.. code-block:: bash
sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
And finally the containers can be initialized by running
.. code-block:: bash
sudo docker-compose up --build -d
Sign in
-----------------
The login page can be accessed at **http://localhost:8085/public/html/login.php**
To access the platform the user is **sloth** and the pasword **slothness**
Further reading
-----------------
To further read about the api and it's front-end
`api-payroll <https://github.com/PootisPenserHere/payroll_manager/blob/master/api-payroll/README.rst>`_
More about the database `database <https://github.com/PootisPenserHere/payroll_manager/blob/master/database/README.rst>`_
Data volumes
-----------------
Since the application is designed to run within containers a number of volumes has been created to persist the data, they can be found in the volumes directory on the root of the project
.. |codebuild| image:: https://s3.amazonaws.com/codefactory-us-east-1-prod-default-build-badges/passing.svg
:target: https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiWm42eW80VzA2OXRTc2xIMXErZ1hlS1RpNnFCaDVMWENqSSsyU2x3dUpReEpCRUtaZGRmbklYaFN0anVEWW9NaGYvQ21PNk9tR25rZGtZMjNvR1ArbGdVPSIsIml2UGFyYW1ldGVyU3BlYyI6IjVXYjl3TWZnUVQ1MFZDQ0kiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master
:alt: Build status of the master branch on amazon codebuild

27
api-payroll/README.md Normal file
View File

@ -0,0 +1,27 @@
# Slim Framework 3 Skeleton Application
Use this skeleton application to quickly setup and start working on a new Slim Framework 3 application. This application uses the latest Slim 3 with the PHP-View template renderer. It also uses the Monolog logger.
This skeleton application was built for Composer. This makes setting up a new Slim Framework application quick and easy.
## Install the Application
Run this command from the directory in which you want to install your new Slim Framework application.
php composer.phar create-project slim/slim-skeleton [my-app-name]
Replace `[my-app-name]` with the desired directory name for your new application. You'll want to:
* Point your virtual host document root to your new application's `public/` directory.
* Ensure `logs/` is web writeable.
To run the application in development, you can run these commands
cd [my-app-name]
php composer.phar start
Run this command in the application directory to run the test suite
php composer.phar test
That's it! Now go build something cool.

View File

@ -1,34 +0,0 @@
=======
The api
=======
.. contents::
About
-------
The project has been built with slim in the backed and jquery with bootstrap for the front, both of them share the public folder from which they can be accessed by the general public.
Auth
------
The system uses cookie based sessions which are handled by a midleware, have a time to live of 10 minutes and are refreshed each time a new request is made to the api, further more the contents of the session itself has been secured with openssl.
Database
---------
To connect to the database pdo is used, its configuration can be found at **src/settings.php** under the mysql section. The following settings are set as default:
- **PDO::ATTR_EMULATE_PREPARES** Has been set to true in order to lower the strain on the database by processing the prepare statements on the server side, if cache performance is desired this option should be changed to false
- **PDO::ATTR_ERRMODE** Uses **PDO::ERRMODE_EXCEPTION** which will return all mysql errors as exceptions to prevent further execution of the software
- **PDO::ATTR_DEFAULT_FETCH_MODE** uses **PDO::FETCH_ASSOC** and as such the query ouput system wide is expected as an associative array
Data protection
----------------
| Encryption has been applied to sensitive data, passwords are protected with with bcrypt and it's configuration can be found in the settings.php file, by default a cost of 12 is used for the hashing as well as a 16 characters randomly generated string (128 bits) as an iv.
| For data that needs to be both read and written such as names AES in mode cbc with 256 block size has been used.
| The reason to have choosen AES is the desire to make the process of securing the data both secure and affordable since many hardware manufacturers already have architectures designed to improce the speed of AES.
| **Important note**: While in this project the encryption password has been saved into the settings.php file it's adviced that in a real use case it's stored more securely or else where entirely such as a key management service.
Error handling
---------------
Should an exception be encountered it'll be caught by a middleware that will form a new response body, returning it with a 500 http code and a json object containing the keys status set to error as well as a message key that will contain the exception that was raised.

View File

@ -17,8 +17,7 @@
"slim/php-view": "^2.0", "slim/php-view": "^2.0",
"monolog/monolog": "^1.17", "monolog/monolog": "^1.17",
"respect/validation": "^1.1", "respect/validation": "^1.1",
"tuupola/cors-middleware": "^0.5.2", "tuupola/cors-middleware": "^0.5.2"
"adbario/slim-secure-session-middleware": "^1.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": ">=4.8 < 6.0" "phpunit/phpunit": ">=4.8 < 6.0"

View File

@ -4,96 +4,9 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "19bc193d641803843178e87bf0465afe", "hash": "93a9656f4e6eb0e25be1bad59ac6f487",
"content-hash": "9eb8d110ad374a60767f92d76018504a", "content-hash": "a3fc18885cc45d2733b77fa2081bdc72",
"packages": [ "packages": [
{
"name": "adbario/php-dot-notation",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/adbario/php-dot-notation.git",
"reference": "5e4b1fe29a8ae1140e370d520ed8b85dd5130a1f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/adbario/php-dot-notation/zipball/5e4b1fe29a8ae1140e370d520ed8b85dd5130a1f",
"reference": "5e4b1fe29a8ae1140e370d520ed8b85dd5130a1f",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"type": "library",
"autoload": {
"psr-4": {
"Adbar\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Riku Särkinen",
"email": "riku@adbar.io"
}
],
"description": "PHP dot notation array access",
"homepage": "https://github.com/adbario/php-dot-notation",
"keywords": [
"ArrayAccess",
"dotnotation",
"php"
],
"time": "2017-03-26 17:44:47"
},
{
"name": "adbario/slim-secure-session-middleware",
"version": "1.3.4",
"source": {
"type": "git",
"url": "https://github.com/adbario/slim-secure-session-middleware.git",
"reference": "f107191506b2c362f06f201f998891f315d6aaec"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/adbario/slim-secure-session-middleware/zipball/f107191506b2c362f06f201f998891f315d6aaec",
"reference": "f107191506b2c362f06f201f998891f315d6aaec",
"shasum": ""
},
"require": {
"adbario/php-dot-notation": "~1.2.0",
"paragonie/random_compat": "^2.0",
"php": ">=5.5",
"slim/slim": "~3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Adbar\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Riku Särkinen",
"email": "riku@adbar.io"
}
],
"description": "Secure session middleware for Slim 3 framework",
"homepage": "https://github.com/adbario/slim-secure-session-middleware",
"keywords": [
"middleware",
"session",
"slim"
],
"time": "2017-08-04 13:51:00"
},
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
"version": "1.2.0", "version": "1.2.0",
@ -304,55 +217,6 @@
], ],
"time": "2018-02-13 20:26:39" "time": "2018-02-13 20:26:39"
}, },
{
"name": "paragonie/random_compat",
"version": "v2.0.17",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/29af24f25bab834fcbb38ad2a69fa93b867e070d",
"reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d",
"shasum": ""
},
"require": {
"php": ">=5.2.0"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"autoload": {
"files": [
"lib/random.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"polyfill",
"pseudorandom",
"random"
],
"time": "2018-07-04 16:31:37"
},
{ {
"name": "pimple/pimple", "name": "pimple/pimple",
"version": "v3.2.3", "version": "v3.2.3",

View File

@ -1,4 +1,4 @@
<script src="../js/newEmployee.js"></script> <script src="../js/NewEmployee.js"></script>
<script src="../js/getBaseUrl.js"></script> <script src="../js/getBaseUrl.js"></script>
<form class="form-horizontal" id="newEmployeeForm"> <form class="form-horizontal" id="newEmployeeForm">
@ -85,7 +85,6 @@
<div class="row col-md-offset-6"> <div class="row col-md-offset-6">
<div class="form-group"> <div class="form-group">
<a href="#" class="btn btn-lg btn-success " onclick="saveNewEmployee();">Create</a> <a href="#" class="btn btn-lg btn-success " onclick="saveNewEmployee();">Create</a>
<a href="#" class="btn btn-lg btn-primary " onclick="loadView(currentView);">Clear</a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,113 +0,0 @@
<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>
<a href="#" class="btn btn-lg btn-primary " onclick="loadView(currentView);">Clear</a>
<a href="#" class="btn btn-lg btn-danger " onclick="deleteEmployee();">Delete</a>
</div>
</div>
</div>
</div>
</div>
</form>

View File

@ -1,3 +1,12 @@
<?php
session_start();
if(!isset($_SESSION['userName'])){
header("Location: ./login.php");
exit();
}
?>
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="../css/bootstrap.min.css"> <link rel="stylesheet" href="../css/bootstrap.min.css">
@ -22,14 +31,18 @@
<li class="dropdown"> <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> <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"> <ul class="dropdown-menu">
<li><a href="#" data-nav_accion="newEmployee.php"> New 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> <li><a href="#" data-nav_accion="EditEmployee.php"> Modify employee</a></li>
</ul> </ul>
</li> </li>
<li> <li>
<a href="#" data-nav_accion="registerWorkDays.php" ><span class="glyphicon glyphicon-tasks"></span> Management</a> <a href="#" onclick="loadView();"><span class="glyphicon glyphicon-tasks"></span> Management</a>
</li>
<li>
<a href="#" onclick="loadView();"><span class="glyphicon glyphicon-wrench"></span> Change password</a>
</li> </li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
@ -213,7 +226,6 @@
<script src="../js/getBaseUrl.js"></script> <script src="../js/getBaseUrl.js"></script>
<script src="../js/landing.js"></script> <script src="../js/landing.js"></script>
<script src="../js/bootstrap-datepicker.min.js"></script> <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/bootstrap-datepicker.min.css" rel="stylesheet">
<link href="../css/landing.css" rel="stylesheet"> <link href="../css/landing.css" rel="stylesheet">

View File

@ -1,3 +1,12 @@
<?php
session_start();
if(isset($_SESSION['userName'])){
header("Location: ./landing.php");
exit();
}
?>
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="../css/bootstrap.min.css"> <link rel="stylesheet" href="../css/bootstrap.min.css">

View File

@ -1,143 +0,0 @@
<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>
<a href="#" class="btn btn-lg btn-primary " onclick="loadView(currentView);">Clear</a>
</div>
</div>
</div>
</div>
</form>

View File

@ -11,6 +11,8 @@ if (PHP_SAPI == 'cli-server') {
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
session_start();
// Instantiate the app // Instantiate the app
$settings = require __DIR__ . '/../src/settings.php'; $settings = require __DIR__ . '/../src/settings.php';
$app = new \Slim\App($settings); $app = new \Slim\App($settings);

View File

@ -1,217 +0,0 @@
/**
* 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');
}
},
});
}
/**
* Will change the status of an employee to remove them from the
* active employee list
*/
function deleteEmployee(){
let baseUrl = getbaseUrl();
let code = $('#editEmployeeCode').val();
$.ajax({
url: baseUrl + '/api/employee/' + code,
type: 'DELETE',
dataType: 'json',
success:function(data){
$('#modalServerResponseSuccess').modal('show');
document.getElementById('serverResponseSuccess').innerHTML = 'The employee ' + data['firstName'] + ' ' + data['middleName'] + ' ' + data['lastName'] + ' has been deleted.';
},
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

@ -1,6 +1,3 @@
// will contain the current loaded view
let currentView;
/** /**
* Destorys the session for the current user and redirects * Destorys the session for the current user and redirects
* back to the login form * back to the login form
@ -16,15 +13,12 @@ function logout() {
window.location.replace(baseUrl + '/html/login.php'); window.location.replace(baseUrl + '/html/login.php');
}, },
error:function(x,e) { error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) { if (x.status==0) {
$('#modalErrorInternetConnection').modal('show'); $('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) { } else if(x.status==404) {
$('#modalError404').modal('show'); $('#modalError404').modal('show');
} else if(x.status==500) { } else if(x.status==500) {
$('#modalServerResponseError').modal('show'); $('#modalError500').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') { } else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show'); $('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){ } else if(e=='timeout'){
@ -62,20 +56,15 @@ function loadView(requestedView){
url: baseUrl + '/html/' + requestedView, url: baseUrl + '/html/' + requestedView,
type: 'get', type: 'get',
success:function(data){ success:function(data){
currentView = requestedView;
$("#newViewBody").hide().html(data).show('slow'); $("#newViewBody").hide().html(data).show('slow');
}, },
error:function(x,e) { error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) { if (x.status==0) {
$('#modalErrorInternetConnection').modal('show'); $('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) { } else if(x.status==404) {
$('#modalError404').modal('show'); $('#modalError404').modal('show');
} else if(x.status==500) { } else if(x.status==500) {
$('#modalServerResponseError').modal('show'); $('#modalError500').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') { } else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show'); $('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){ } else if(e=='timeout'){
@ -86,11 +75,3 @@ function loadView(requestedView){
}, },
}); });
} }
/**
* Reloads the last view that was accessed as a way of fully clearing and
* resetting the values of the form
*/
function clearView(view){
loadView(view);
}

View File

@ -1,359 +0,0 @@
/**
* 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,7 +1,6 @@
<?php <?php
namespace App\Application; namespace App\Application;
use Exception;
use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\Integer;
class EmployeeApplication{ class EmployeeApplication{
@ -9,35 +8,19 @@ class EmployeeApplication{
private $cryptographyService; private $cryptographyService;
private $asserts; private $asserts;
private $settings; private $settings;
private $session;
/** function __construct($employeeSettings, $mysql, $cryptographyService, $asserts){
* EmployeeApplication constructor.
* @param $employeeSettings
* @param $mysql
* @param $cryptographyService
* @param $asserts
* @param $session
* @throws Exception
*/
function __construct($employeeSettings, $mysql, $cryptographyService, $asserts, $session){
$this->settings = $employeeSettings; $this->settings = $employeeSettings;
$this->cryptographyService = $cryptographyService; $this->cryptographyService = $cryptographyService;
$this->pdo = $mysql; $this->pdo = $mysql;
$this->asserts = $asserts; $this->asserts = $asserts;
$this->session = $session;
if(!$this->session->verifySession()){ $this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.';
throw new Exception('A session is requited to access this resouerce.');
};
} }
/** /**
* A list of the types of employee used in the system
*
* @return array * @return array
* @throws Exception
*/ */
function listEmployeeTypes(){ function listEmployeeTypes(){
$stmt = $this->pdo->prepare("SELECT $stmt = $this->pdo->prepare("SELECT
@ -51,7 +34,7 @@ class EmployeeApplication{
$results = $stmt->fetchAll(); $results = $stmt->fetchAll();
if(!$results){ if(!$results){
throw new Exception("The types of employees could not be found.."); exit($this->databaseSelectQueryErrorMessage);
} }
$stmt = null; $stmt = null;
@ -71,13 +54,11 @@ class EmployeeApplication{
* @param $email string * @param $email string
* @param $phone string * @param $phone string
* @return integer * @return integer
* @throws Exception
*/ */
function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){ function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){
$this->asserts->isNotEmpty($firstName, "The first name can't be empty."); $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($middleName, "The middle name can't be empty.");
$this->asserts->isNotEmpty($birthDate, "The birth date 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($email, "The email can't be empty.");
$this->asserts->isNotEmpty($phone, "The phone number can't be empty."); $this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
@ -96,6 +77,7 @@ class EmployeeApplication{
} catch( PDOExecption $e ) { } catch( PDOExecption $e ) {
$this->pdo->rollback(); $this->pdo->rollback();
throw new Exception('There was an error while trying to save a new person.'); throw new Exception('There was an error while trying to save a new person.');
$this->logger->warning("There was an error in the EmployeeApplication->saveNewPerson caused by: $e ");
} }
} }
@ -105,7 +87,6 @@ class EmployeeApplication{
* @param $code string * @param $code string
* @param $contractType string * @param $contractType string
* @return mixed * @return mixed
* @throws Exception
*/ */
function savePersonAsEmployee($idEmployeeType, $idPerson, $code, $contractType){ function savePersonAsEmployee($idEmployeeType, $idPerson, $code, $contractType){
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0"); $this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
@ -134,7 +115,6 @@ class EmployeeApplication{
/** /**
* @param $requestData object * @param $requestData object
* @return array * @return array
* @throws Exception
*/ */
function saveNewEmployee($requestData){ function saveNewEmployee($requestData){
// Getting and validating the data // Getting and validating the data
@ -154,7 +134,6 @@ class EmployeeApplication{
$birthDate = $requestData['birthDate']; $birthDate = $requestData['birthDate'];
$this->asserts->isNotEmpty($birthDate, "The birth date 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.");
$email = $requestData['email']; $email = $requestData['email'];
$this->asserts->isNotEmpty($email, "The email can't be empty."); $this->asserts->isNotEmpty($email, "The email can't be empty.");
@ -166,11 +145,7 @@ class EmployeeApplication{
$this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters."); $this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters.");
$idEmployeeType = $requestData{'idEmployeeType'}; $idEmployeeType = $requestData{'idEmployeeType'};
$this->asserts->higherThanZero($idEmployeeType, 'idEmployeeType must be higher than zero.');
$contractType = $requestData{'contractType'}; $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 // Encrypting the sensitive data
$securedFirstName = $this->cryptographyService->encryptString($firstName); $securedFirstName = $this->cryptographyService->encryptString($firstName);
@ -205,7 +180,6 @@ class EmployeeApplication{
/** /**
* @param $idEmployee * @param $idEmployee
* @return Integer * @return Integer
* @throws Exception
*/ */
function getIdPersonByIdEmployee($idEmployee){ function getIdPersonByIdEmployee($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
@ -222,7 +196,7 @@ class EmployeeApplication{
$stmt->execute(array(':idEmployee' => $idEmployee)); $stmt->execute(array(':idEmployee' => $idEmployee));
$results = $stmt->fetchAll(); $results = $stmt->fetchAll();
if(!$results){ if(!$results){
throw new Exception("An error occurred while trying to find the person associated with the employee.."); exit($this->databaseSelectQueryErrorMessage);
} }
$stmt = null; $stmt = null;
@ -232,7 +206,6 @@ class EmployeeApplication{
/** /**
* @param $code string * @param $code string
* @return integer * @return integer
* @throws Exception
*/ */
function getIdEmployeeTypeByCode($code){ function getIdEmployeeTypeByCode($code){
$this->asserts->isNotEmpty($code, "The code can't be empty."); $this->asserts->isNotEmpty($code, "The code can't be empty.");
@ -249,35 +222,7 @@ class EmployeeApplication{
$stmt->execute(array(':code' => $code)); $stmt->execute(array(':code' => $code));
$results = $stmt->fetchAll(); $results = $stmt->fetchAll();
if(!$results){ if(!$results){
throw new Exception("The employee could not be found."); exit($this->databaseSelectQueryErrorMessage);
}
$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; $stmt = null;
@ -289,22 +234,18 @@ class EmployeeApplication{
* *
* @param $idEmployee * @param $idEmployee
* @return array * @return array
* @throws Exception
*/ */
function getEmployeeDataById($idEmployee){ function getEmployeeDataById($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); $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.id AS idPerson,
p.firstName, p.firstName,
p.middleName, p.middleName,
IFNULL(p.lastName, '') AS lastName, IFNULL(p.lastName, '') AS lastName,
p.birthDate,
p.email, p.email,
p.phone, p.phone,
e.code, e.code,
e.idEmployeeType,
e.contractType e.contractType
FROM FROM
employees e employees e
@ -316,7 +257,7 @@ class EmployeeApplication{
$stmt->execute(array(':idEmployee' => $idEmployee)); $stmt->execute(array(':idEmployee' => $idEmployee));
$results = $stmt->fetchAll(); $results = $stmt->fetchAll();
if(!$results){ if(!$results){
throw new Exception("The employee could not be found."); exit($this->databaseSelectQueryErrorMessage);
} }
$stmt = null; $stmt = null;
@ -329,7 +270,6 @@ class EmployeeApplication{
* *
* @param $idEmployee * @param $idEmployee
* @return array * @return array
* @throws Exception
*/ */
function proxyGetEmployeeDataById($idEmployee){ function proxyGetEmployeeDataById($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
@ -337,7 +277,6 @@ class EmployeeApplication{
$employeeData = $this->getEmployeeDataById($idEmployee); $employeeData = $this->getEmployeeDataById($idEmployee);
$response = array( $response = array(
"idEmployee" => (int)$employeeData['idEmployee'],
"idPerson" => (int)$employeeData['idPerson'], "idPerson" => (int)$employeeData['idPerson'],
"firstName" => $this->cryptographyService->decryptString($employeeData['firstName']), "firstName" => $this->cryptographyService->decryptString($employeeData['firstName']),
"middleName" => $this->cryptographyService->decryptString($employeeData['middleName']), "middleName" => $this->cryptographyService->decryptString($employeeData['middleName']),
@ -346,11 +285,9 @@ class EmployeeApplication{
? $this->cryptographyService->decryptString($employeeData['lastName']) ? $this->cryptographyService->decryptString($employeeData['lastName'])
: '', : '',
"birthDate" => $employeeData['birthDate'],
"email" => $this->cryptographyService->decryptString($employeeData['email']), "email" => $this->cryptographyService->decryptString($employeeData['email']),
"phone" => $employeeData['phone'], "phone" => $employeeData['phone'],
"code" => $employeeData['code'], "code" => $employeeData['code'],
"idEmployeeType" => $employeeData['idEmployeeType'],
"contractType" => $employeeData['contractType'] "contractType" => $employeeData['contractType']
); );
@ -361,12 +298,11 @@ class EmployeeApplication{
/** /**
* @param $code string * @param $code string
* @return array * @return array
* @throws Exception
*/ */
function getEmployeeDataByCode($code){ function getEmployeeDataByCode($code){
$this->asserts->isNotEmpty($code, "The code can't be empty."); $this->asserts->isNotEmpty($code, "The code can't be empty.");
$idEmployee = $this->getIdEmployeeByCode($code); $idEmployee = $this->getIdEmployeeTypeByCode($code);
return $this->proxyGetEmployeeDataById($idEmployee); return $this->proxyGetEmployeeDataById($idEmployee);
} }
@ -385,7 +321,6 @@ class EmployeeApplication{
$this->asserts->isNotEmpty($firstName, "The first name can't be empty."); $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($middleName, "The middle name can't be empty.");
$this->asserts->isNotEmpty($birthDate, "The birth date 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($email, "The email can't be empty.");
$this->asserts->isNotEmpty($phone, "The phone number can't be empty."); $this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
@ -445,16 +380,18 @@ class EmployeeApplication{
/** /**
* @param $requestData object * @param $requestData object
* @return array * @return array
* @throws Exception
*/ */
function updateEmployeeData($requestData){ function updateEmployeeData($requestData){
// Getting and validating the data // 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']; $code = $requestData['code'];
$this->asserts->isNotEmpty($code, "The code can't be empty."); $this->asserts->isNotEmpty($code, "The code can't be empty.");
$idEmployee = $this->getIdEmployeeByCode($code);
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
$firstName = $requestData['firstName']; $firstName = $requestData['firstName'];
$this->asserts->isNotEmpty($firstName, "The first name can't be empty."); $this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
$this->asserts->isString($firstName, "The first name must be a string."); $this->asserts->isString($firstName, "The first name must be a string.");
@ -469,7 +406,6 @@ class EmployeeApplication{
$birthDate = $requestData['birthDate']; $birthDate = $requestData['birthDate'];
$this->asserts->isNotEmpty($birthDate, "The birth date 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.");
$email = $requestData['email']; $email = $requestData['email'];
$this->asserts->isNotEmpty($email, "The email can't be empty."); $this->asserts->isNotEmpty($email, "The email can't be empty.");
@ -485,7 +421,6 @@ class EmployeeApplication{
$contractType = $requestData{'contractType'}; $contractType = $requestData{'contractType'};
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty."); $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 // Encrypting the sensitive data
$securedFirstName = $this->cryptographyService->encryptString($firstName); $securedFirstName = $this->cryptographyService->encryptString($firstName);
@ -518,19 +453,9 @@ class EmployeeApplication{
return $response; return $response;
} }
/** function disableEmployeeRecord($idEmployee){
* @param $code string
* @return array
* @throws Exception
*/
function disableEmployeeRecord($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"); $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$employeeData = $this->proxyGetEmployeeDataById($idEmployee);
try { try {
$stmt = $this->pdo->prepare("UPDATE employees $stmt = $this->pdo->prepare("UPDATE employees
SET SET
@ -542,12 +467,8 @@ class EmployeeApplication{
$this->pdo->commit(); $this->pdo->commit();
$stmt = null; $stmt = null;
return $employeeData;
} catch( PDOExecption $e ) { } catch( PDOExecption $e ) {
$this->pdo->rollback(); $this->pdo->rollback();
throw new Exception("The employee you tried to delete could not be found.");
} }
} }
@ -558,7 +479,6 @@ class EmployeeApplication{
* currently active in the system * currently active in the system
* *
* @return array * @return array
* @throws Exception
*/ */
function getIdEmployeeFromAllActiveEmployees(){ function getIdEmployeeFromAllActiveEmployees(){
$stmt = $this->pdo->prepare("SELECT $stmt = $this->pdo->prepare("SELECT
@ -572,7 +492,7 @@ class EmployeeApplication{
$results = $stmt->fetchAll(); $results = $stmt->fetchAll();
if(!$results){ if(!$results){
throw new Exception("The employee could not be found."); exit($this->databaseSelectQueryErrorMessage);
} }
$stmt = null; $stmt = null;
@ -580,11 +500,7 @@ class EmployeeApplication{
} }
/** /**
* Uses an already existing method to create and array containing the details of
* all currently active employees
*
* @return array * @return array
* @throws Exception
*/ */
function listAllActiveEmployees(){ function listAllActiveEmployees(){
$ids = $this->getIdEmployeeFromAllActiveEmployees(); $ids = $this->getIdEmployeeFromAllActiveEmployees();
@ -592,604 +508,10 @@ class EmployeeApplication{
$result = array(); $result = array();
foreach($ids as $row){ foreach($ids as $row){
$currentEmployee = $this->proxyGetEmployeeDataById($row['id']); $result[] = $this->proxyGetEmployeeDataById($row['id']);
$result[] = array(
'fullName' => $currentEmployee['firstName']." ".
$currentEmployee['middleName']." ".
$currentEmployee['lastName'],
'code' => $currentEmployee['code']
);
} }
return $result; 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

@ -4,24 +4,23 @@ namespace App\Application;
use Exception; use Exception;
class SessionApplication{ class SessionApplication{
private $session;
private $pdo; private $pdo;
private $cryptographyService; private $cryptographyService;
private $asserts; private $asserts;
function __construct($session, $mysql, $cryptographyService, $asserts){ function __construct($mysql, $cryptographyService, $asserts){
$this->session = $session;
$this->cryptographyService = $cryptographyService; $this->cryptographyService = $cryptographyService;
$this->pdo = $mysql; $this->pdo = $mysql;
$this->asserts = $asserts; $this->asserts = $asserts;
$this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.';
} }
/** /**
* @return bool * @return bool
*/ */
function verifySession(){ function verifySession(){
$userName = $this->session->get('userName'); return isset($_SESSION['userName']);
return isset($userName);
} }
/** /**
@ -33,7 +32,7 @@ class SessionApplication{
$session['loggedIn'] = $this->verifySession(); $session['loggedIn'] = $this->verifySession();
if($this->verifySession()){ if($this->verifySession()){
$session['userName'] = $this->session->get('userName'); $session['userName'] = $_SESSION['userName'];
} }
return $session; return $session;
@ -86,12 +85,7 @@ class SessionApplication{
} }
if($this->cryptographyService->decryptPassword($password, $storedPassword)){ if($this->cryptographyService->decryptPassword($password, $storedPassword)){
$this->session->set('userName', $userName); $_SESSION['userName'] = $userName;
if(!$this->verifySession()){
throw new Exception('An error occurred while trying to create the session.');
}
return true; return true;
} }
else{ else{
@ -124,14 +118,9 @@ class SessionApplication{
/** /**
* @return array * @return array
* @throws Exception
*/ */
function destroySession(){ function destroySession(){
$this->session->clear(); session_destroy();
if($this->verifySession()){
throw new Exception('An error occurred while trying to end the session.');
}
return array('status' => 'success', 'message' => 'Successfully logged out.'); return array('status' => 'success', 'message' => 'Successfully logged out.');
} }

View File

@ -18,13 +18,6 @@ $container['logger'] = function ($c) {
return $logger; return $logger;
}; };
// Session handler
$container['session'] = function ($container) {
return new \Adbar\Session(
$container->get('settings')['session']['namespace']
);
};
// Mysql connection // Mysql connection
$container['mysql'] = function ($c) { $container['mysql'] = function ($c) {
$mysqlSettings = $c->get('settings')['mysql']; $mysqlSettings = $c->get('settings')['mysql'];
@ -67,8 +60,7 @@ $container['asserts'] = function ($c) {
// The session application // The session application
$container['sessionApplication'] = function ($c) { $container['sessionApplication'] = function ($c) {
$sessionApplication = new App\Application\SessionApplication($c['session'], $c['mysql'], $sessionApplication = new App\Application\SessionApplication($c['mysql'], $c['cryptographyService'], $c['asserts']);
$c['cryptographyService'], $c['asserts']);
return $sessionApplication; return $sessionApplication;
}; };
@ -76,6 +68,6 @@ $container['sessionApplication'] = function ($c) {
$container['employeeApplication'] = function ($c) { $container['employeeApplication'] = function ($c) {
$employeeSettings = $c->get('settings')['employee']; $employeeSettings = $c->get('settings')['employee'];
$employeeApplication = new App\Application\EmployeeApplication($employeeSettings, $employeeApplication = new App\Application\EmployeeApplication($employeeSettings,
$c['mysql'], $c['cryptographyService'], $c['asserts'], $c['sessionApplication']); $c['mysql'], $c['cryptographyService'], $c['asserts']);
return $employeeApplication; return $employeeApplication;
}; };

View File

@ -20,5 +20,3 @@ $app->add(new \Tuupola\Middleware\Cors([
->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); ->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
} }
])); ]));
$app->add(new \Adbar\SessionMiddleware($app->getContainer()->get('settings')['session']));

View File

@ -41,12 +41,10 @@ $app->get('/api/employee/types', function (Request $request, Response $response,
->write(json_encode($this->employeeApplication->listEmployeeTypes())); ->write(json_encode($this->employeeApplication->listEmployeeTypes()));
}); });
$app->get('/api/employee/find/{partialName}', function (Request $request, Response $response, array $args) { $app->get('/api/employee/all', function (Request $request, Response $response, array $args) {
$partialName = $args['partialName'];
return $response->withStatus(200) return $response->withStatus(200)
->withHeader('Content-Type', 'application/json') ->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->findEmployeeByFullName($partialName))); ->write(json_encode($this->employeeApplication->listAllActiveEmployees()));
}); });
$app->post('/api/employee', function ($request, $response) { $app->post('/api/employee', function ($request, $response) {
@ -65,12 +63,12 @@ $app->put('/api/employee', function ($request, $response) {
->write(json_encode($this->employeeApplication->updateEmployeeData($requestData))); ->write(json_encode($this->employeeApplication->updateEmployeeData($requestData)));
}); });
$app->DELETE('/api/employee/{code}', function (Request $request, Response $response, array $args) { $app->DELETE('/api/employee/{idEmployee}', function (Request $request, Response $response, array $args) {
$code = $args['code']; $idEmployee = $args['idEmployee'];
return $response->withStatus(200) return $response->withStatus(200)
->withHeader('Content-Type', 'application/json') ->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->disableEmployeeRecord($code))); ->write(json_encode($this->employeeApplication->disableEmployeeRecord($idEmployee)));
}); });
$app->get('/api/employee/type/{code}', function (Request $request, Response $response, array $args) { $app->get('/api/employee/type/{code}', function (Request $request, Response $response, array $args) {
@ -96,36 +94,3 @@ $app->get('/api/employee/code/{code}', function (Request $request, Response $res
->withHeader('Content-Type', 'application/json') ->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->getEmployeeDataByCode($code))); ->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

@ -69,42 +69,5 @@ class Asserts{
throw new Exception($errorMessage); 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

@ -16,35 +16,6 @@ return [
'level' => \Monolog\Logger::DEBUG, 'level' => \Monolog\Logger::DEBUG,
], ],
// Session handle settings
'session' => [
// Session cookie settings
'name' => 'payroll-laziness-rocks',
'lifetime' => 10,
'path' => '/',
'domain' => null,
'secure' => false,
'httponly' => true,
// Set session cookie path, domain and secure automatically
'cookie_autoset' => true,
// Path where session files are stored, PHP's default path will be used if set null
'save_path' => null,
// Session cache limiter
'cache_limiter' => 'nocache',
// Extend session lifetime after each user activity
'autorefresh' => true,
// Encrypt session data if string is set
'encryption_key' => '7de431684c34cf2c898268cff71392f38c4175dde050c9ee69502b81571484e0',
// Session namespace
'namespace' => 'slim'
],
// Cryptography settings // Cryptography settings
'cryptography' => [ 'cryptography' => [
'encryptionAlgorithm' => 'AES-256-CBC', 'encryptionAlgorithm' => 'AES-256-CBC',
@ -74,19 +45,6 @@ return [
// Employee settings // Employee settings
'employee' => [ 'employee' => [
'codeLength' => '3', '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

@ -20,7 +20,7 @@ class BaseTestCase extends \PHPUnit_Framework_TestCase
* *
* @var bool * @var bool
*/ */
protected $withMiddleware = false; protected $withMiddleware = true;
/** /**
* Process the application given a request method and URI * Process the application given a request method and URI

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

View File

@ -1,22 +0,0 @@
================
``The database``
================
.. contents::
About the container
--------------------
The database container is created in two stages to bypass some limitations with docker, firstly a new image will be created based on the Dockerfile which will be based on mysql 5.7 and it'll be passed the .sql scripts to initialize the database as well as a config file to configure the port that will be exposed.
Initializing
-------------
When the database is being created as an image it'll take all the scripts in the **/docker-entrypoint-initdb.d** directory and execute them in alphabetical order which will result in the database with its tables and initial data being created.
Accession
----------
The newly created container will have two users *root** and **sloth** both of which will have the password **12345678** and it'll be accessible in the port 3307
Persistence
-----------
A volume containing the data from **/var/lib/mysql** will be created to persist the information, once its created running the container build again will execute the starting scripts

View File

@ -71,44 +71,5 @@ CREATE TABLE IF NOT EXISTS `employees` (
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created', `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', `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`), PRIMARY KEY (`id`),
INDEX `idx_contractType` (`contractType`),
UNIQUE (`code`) 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)
);

View File

@ -1,99 +0,0 @@
================
Documentation
================
.. contents::
Requirements
----------------------------------
Funtional:
- A user name and password auth
- Encrypted sensitive data
- The employee need to have their full name captured
- The last name must tolerate being null
- An email will be needed for the employee
- The email format must be formated
- Employees will need a phone number
- Searching employees despite the encryption
- Employees must have a unique code to reference them
- Being able to modify the name, email and phone values of already existing employees
- Having the values for the different payments parametrized
- Allowing for employees to perform other roles during their work day
- Only for the auxiliary personnel
- Taking into account only the current month for the salary
- Reducing the taxes for the salary
- If it goes beyond the threshold a different percentage is paid in taxes
- The way the extra tax is handled should be parametrized
Funtional:
- Session management
- Data integrity
- Data security
- Accessible through web
- Containerized
Software behaivor
-----------------
In:
- Employee details
- First name
- Middle name
- Last name
- Birth date
- Email
- Phone number
- Work per day
- Number of deliveries
- Rol performed
Process:
- Register a new employee
- Modify employee
- Search employee
- Add new work day for employee
- Calculate monthly payment for employee
Out:
- Upon registering
- Employee code
- In the work days registry
- Raw salary for the the month
- Taxes discounted
- Real salary for the month
- Vouchers (if applicable)
Calculating the monthly salary
--------------------------------
.. image:: https://raw.githubusercontent.com/PootisPenserHere/payroll_manager/master/documentation/calculatingSalary.bmp
Tests cases
-----------------
+----+----------------------------------------------------------------------------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+
| Id | Description | Input | Expected output |
+----+----------------------------------------------------------------------------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+
| 1 | Displaying current salary for the outgoing month | Selecting an employee from the search field | On the right side of the window a break down of the employee's salary for the month will be displayed |
+----+----------------------------------------------------------------------------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+
| 2 | Submitting incomplete form | All of the input but one of the fields | An error shown in a red modal describing the missing field |
+----+----------------------------------------------------------------------------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+
| 3 | Altering the sent data to change the performed rol to one that can't be done by the employee | A employee other than aux performing a different rol than their own | An error displaying that the employee can't perform that task |
+----+----------------------------------------------------------------------------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+
Executed tests
---------------
+----+----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------+------------------+
| Id | Description | Result | What went wrong? |
+----+----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------+------------------+
| 1 | Displaying current salary for the outgoing month | When the employee was selected the current salary was loaded succesfully | |
+----+----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------+------------------+
| 2 | Submitting incomplete form | Got the error "The number of deliveries cannot be empty or 0" | |
+----+----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------+------------------+
| 3 | Altering the sent data to change the performed rol to one that can't be done by the employee | Got the error "The selected rol can't be done by this type of employee" | |
+----+----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------+------------------+
Tools
----------------------------------
The following tools and software were used:
- phpstorm
- git
- docker && docker-compose
- Ubuntu 16

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB