[add] Basic endpoint for workday data
This commit is contained in:
parent
f864e74247
commit
03cbcce59f
@ -26,7 +26,7 @@ class EmployeeApplication{
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function listEmployeeTypes(){
|
function listEmployeeTypes(){
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
id, name
|
id, name
|
||||||
FROM
|
FROM
|
||||||
employeeType
|
employeeType
|
||||||
@ -67,7 +67,7 @@ class EmployeeApplication{
|
|||||||
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone)
|
$stmt = $this->pdo->prepare("INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone)
|
||||||
VALUES (:firstName, :middleName, :lastName, :birthDate, :email, :phone)");
|
VALUES (:firstName, :middleName, :lastName, :birthDate, :email, :phone)");
|
||||||
$this->pdo->beginTransaction();
|
$this->pdo->beginTransaction();
|
||||||
$stmt->execute(array(':firstName' => $firstName, ':middleName' => $middleName, ':lastName' => $lastName,
|
$stmt->execute(array(':firstName' => $firstName, ':middleName' => $middleName, ':lastName' => $lastName,
|
||||||
@ -99,7 +99,7 @@ class EmployeeApplication{
|
|||||||
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||||
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType)
|
$stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType)
|
||||||
VALUES (:idEmployeeType, :idPerson, :code, :contractType)");
|
VALUES (:idEmployeeType, :idPerson, :code, :contractType)");
|
||||||
$this->pdo->beginTransaction();
|
$this->pdo->beginTransaction();
|
||||||
$stmt->execute(array(':idEmployeeType' => $idEmployeeType, ':idPerson' => $idPerson, ':code' => $code,
|
$stmt->execute(array(':idEmployeeType' => $idEmployeeType, ':idPerson' => $idPerson, ':code' => $code,
|
||||||
@ -194,8 +194,8 @@ class EmployeeApplication{
|
|||||||
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");
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
COALESCE((SELECT
|
COALESCE((SELECT
|
||||||
idPerson
|
idPerson
|
||||||
FROM
|
FROM
|
||||||
employees
|
employees
|
||||||
@ -220,7 +220,7 @@ class EmployeeApplication{
|
|||||||
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.");
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare("SELECT COALESCE((SELECT
|
$stmt = $this->pdo->prepare("SELECT COALESCE((SELECT
|
||||||
et.id
|
et.id
|
||||||
FROM
|
FROM
|
||||||
employees e
|
employees e
|
||||||
@ -246,8 +246,8 @@ class EmployeeApplication{
|
|||||||
function getIdEmployeeByCode($code){
|
function getIdEmployeeByCode($code){
|
||||||
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
COALESCE((SELECT
|
COALESCE((SELECT
|
||||||
id
|
id
|
||||||
FROM
|
FROM
|
||||||
employees
|
employees
|
||||||
@ -275,7 +275,7 @@ class EmployeeApplication{
|
|||||||
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,
|
e.id AS idEmployee,
|
||||||
p.id AS idPerson,
|
p.id AS idPerson,
|
||||||
p.firstName,
|
p.firstName,
|
||||||
@ -368,8 +368,8 @@ class EmployeeApplication{
|
|||||||
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("UPDATE persons
|
$stmt = $this->pdo->prepare("UPDATE persons
|
||||||
SET
|
SET
|
||||||
firstName = :firstName,
|
firstName = :firstName,
|
||||||
middleName = :middleName,
|
middleName = :middleName,
|
||||||
lastName = :lastName,
|
lastName = :lastName,
|
||||||
@ -402,8 +402,8 @@ class EmployeeApplication{
|
|||||||
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("UPDATE employees
|
$stmt = $this->pdo->prepare("UPDATE employees
|
||||||
SET
|
SET
|
||||||
idEmployeeType = :idEmployeeType,
|
idEmployeeType = :idEmployeeType,
|
||||||
code = :code,
|
code = :code,
|
||||||
contractType = :contractType
|
contractType = :contractType
|
||||||
@ -498,8 +498,8 @@ class EmployeeApplication{
|
|||||||
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("UPDATE employees
|
$stmt = $this->pdo->prepare("UPDATE employees
|
||||||
SET
|
SET
|
||||||
status = 'INACTIVE'
|
status = 'INACTIVE'
|
||||||
WHERE
|
WHERE
|
||||||
id = :idEmployee");
|
id = :idEmployee");
|
||||||
@ -522,7 +522,7 @@ class EmployeeApplication{
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function getIdEmployeeFromAllActiveEmployees(){
|
function getIdEmployeeFromAllActiveEmployees(){
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
id
|
id
|
||||||
FROM
|
FROM
|
||||||
employees
|
employees
|
||||||
@ -599,8 +599,8 @@ class EmployeeApplication{
|
|||||||
|
|
||||||
$this->asserts->isNotEmpty($date, "The code can't be empty.");
|
$this->asserts->isNotEmpty($date, "The code can't be empty.");
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
COALESCE((SELECT
|
COALESCE((SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
paymentsPerEmployeePerDay
|
paymentsPerEmployeePerDay
|
||||||
@ -638,8 +638,8 @@ class EmployeeApplication{
|
|||||||
$this->asserts->isNotEmpty($deliveries, "The payment for deliveries can't be empty.");
|
$this->asserts->isNotEmpty($deliveries, "The payment for deliveries can't be empty.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("INSERT INTO paymentsPerEmployeePerDay
|
$stmt = $this->pdo->prepare("INSERT INTO paymentsPerEmployeePerDay
|
||||||
(idEmployee, date, baseAmount, bonusTime, deliveries)
|
(idEmployee, date, baseAmount, bonusTime, deliveries)
|
||||||
VALUES (:idEmployee, :date, :baseAmount, :bonusTime, :deliveries)");
|
VALUES (:idEmployee, :date, :baseAmount, :bonusTime, :deliveries)");
|
||||||
$this->pdo->beginTransaction();
|
$this->pdo->beginTransaction();
|
||||||
$stmt->execute(array(':idEmployee' => $idEmployee, ':date' => $date, ':baseAmount' => $baseAmount,
|
$stmt->execute(array(':idEmployee' => $idEmployee, ':date' => $date, ':baseAmount' => $baseAmount,
|
||||||
@ -735,13 +735,13 @@ class EmployeeApplication{
|
|||||||
$this->asserts->higherThanZero($year, "year 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");
|
$this->asserts->higherThanZero($month, "month must be higher than 0");
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
COALESCE((SELECT
|
COALESCE((SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
paymentsPerEmployeePerDay
|
paymentsPerEmployeePerDay
|
||||||
WHERE
|
WHERE
|
||||||
idEmployee = :idEmployee
|
idEmployee = :idEmployee
|
||||||
AND YEAR(date) = :year
|
AND YEAR(date) = :year
|
||||||
AND MONTH(date) = :month
|
AND MONTH(date) = :month
|
||||||
AND status = 'ACTIVE'),
|
AND status = 'ACTIVE'),
|
||||||
@ -768,12 +768,12 @@ class EmployeeApplication{
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function getDataWorkedDaysByEmployee($idEmployee, $year, $month){
|
function getDataWorkedDaysByEmployee($idEmployee, $year, $month){
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
baseAmount, bonusTime, deliveries
|
baseAmount, bonusTime, deliveries
|
||||||
FROM
|
FROM
|
||||||
paymentsPerEmployeePerDay
|
paymentsPerEmployeePerDay
|
||||||
WHERE
|
WHERE
|
||||||
idEmployee = :idEmployee AND
|
idEmployee = :idEmployee AND
|
||||||
YEAR(date) = :year
|
YEAR(date) = :year
|
||||||
AND MONTH(date) = :month
|
AND MONTH(date) = :month
|
||||||
AND status = 'ACTIVE'");
|
AND status = 'ACTIVE'");
|
||||||
@ -798,7 +798,7 @@ class EmployeeApplication{
|
|||||||
$this->asserts->isNotEmpty($idEmployee, "The code can't be empty.");
|
$this->asserts->isNotEmpty($idEmployee, "The code can't be empty.");
|
||||||
$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
|
||||||
contractType
|
contractType
|
||||||
FROM
|
FROM
|
||||||
employees
|
employees
|
||||||
@ -815,6 +815,10 @@ class EmployeeApplication{
|
|||||||
return $results[0]['contractType'];
|
return $results[0]['contractType'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDataWorkDayByDateAndCode($date, $code){
|
||||||
|
return array('status' => 'success', 'message' => 'Successfully did the thing.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the worked days for an employee and determines how much they're
|
* Gets all the worked days for an employee and determines how much they're
|
||||||
* getting paid
|
* getting paid
|
||||||
@ -878,4 +882,4 @@ class EmployeeApplication{
|
|||||||
return $salary;
|
return $salary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -111,4 +111,13 @@ $app->get('/api/employee/salary/{code}', function (Request $request, Response $r
|
|||||||
return $response->withStatus(200)
|
return $response->withStatus(200)
|
||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->write(json_encode($this->employeeApplication->calculateSalaryByCode($code)));
|
->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)));
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user