[add] Validations for work day abstracted to their own method
This commit is contained in:
parent
e3dfaf9f26
commit
ca80abc389
@ -671,14 +671,17 @@ class EmployeeApplication{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes the data from the front end for the new worked day for a
|
* Takes the data from the front end for the work day, this coulld be
|
||||||
* employee and saves it
|
* 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
|
* @param $requestData object
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function SaveNewWorkDay($requestData){
|
function validateDataForStorageWorkDay($requestData){
|
||||||
$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.");
|
||||||
|
|
||||||
@ -729,14 +732,43 @@ class EmployeeApplication{
|
|||||||
$bonusTime = $perHourBonus * $this->settings['hoursPerWorkDay'];
|
$bonusTime = $perHourBonus * $this->settings['hoursPerWorkDay'];
|
||||||
$bonusDeliveries = $deliveries * $this->settings['bonusPerDelivery'];
|
$bonusDeliveries = $deliveries * $this->settings['bonusPerDelivery'];
|
||||||
|
|
||||||
$idPaymentPerEmployeePerDay = $this->saveWorkedDay($idEmployee, $date, $baseAmountPaid,
|
|
||||||
$bonusTime, $bonusDeliveries);
|
|
||||||
|
|
||||||
$contractType = $this->getContractTypeByEmployee($idEmployee);
|
$contractType = $this->getContractTypeByEmployee($idEmployee);
|
||||||
|
|
||||||
$this->storeWorkDayDetails($idPaymentPerEmployeePerDay, $idEmployeeType, $idEmployeeTypePerformed,
|
$result = array(
|
||||||
$contractType, $this->settings['hoursPerWorkDay'], $this->settings['paymentPerHour'],
|
'idEmployee' => (int)$idEmployee,
|
||||||
$perHourBonus, $deliveries, $this->settings['bonusPerDelivery']);
|
'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);
|
||||||
|
|
||||||
|
$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);
|
return array('status' => 'success', 'message' => 'The worked day has been saved.', 'data' => $requestData);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ $app->post('/api/employee/workday', function ($request, $response) {
|
|||||||
|
|
||||||
return $response->withStatus(200)
|
return $response->withStatus(200)
|
||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->write(json_encode($this->employeeApplication->SaveNewWorkDay($requestData)));
|
->write(json_encode($this->employeeApplication->newWorkedDay($requestData)));
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/api/employee/salary/{code}', function (Request $request, Response $response, array $args) {
|
$app->get('/api/employee/salary/{code}', function (Request $request, Response $response, array $args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user