Editing worked days #23

Merged
PootisPenserHere merged 9 commits from editingWorkedDays into master 2018-08-15 08:37:49 +00:00
2 changed files with 89 additions and 1 deletions
Showing only changes of commit f2851ec56a - Show all commits

View File

@ -714,7 +714,14 @@ class EmployeeApplication{
$bonusTime = $perHourBonus * $this->settings['hoursPerWorkDay'];
$bonusDeliveries = $deliveries * $this->settings['bonusPerDelivery'];
$this->saveWorkedDay($idEmployee, $date, $baseAmountPaid, $bonusTime, $bonusDeliveries);
$idPaymentPerEmployeePerDay = $this->saveWorkedDay($idEmployee, $date, $baseAmountPaid,
$bonusTime, $bonusDeliveries);
$contractType = $this->getContractTypeByEmployee($idEmployee);
$this->storeWorkDayDetails($idPaymentPerEmployeePerDay, $idEmployeeType, $idEmployeeTypePerformed,
$contractType, $this->settings['hoursPerWorkDay'], $this->settings['paymentPerHour'],
$perHourBonus, $deliveries, $this->settings['bonusPerDelivery']);
return array('status' => 'success', 'message' => 'The worked day has been saved.', 'data' => $requestData);
}
@ -815,6 +822,64 @@ class EmployeeApplication{
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.");
}
}
function getDataWorkDayByDateAndCode($date, $code){
return array('status' => 'success', 'message' => 'Successfully did the thing.');
}

View File

@ -71,6 +71,7 @@ CREATE TABLE IF NOT EXISTS `employees` (
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
PRIMARY KEY (`id`),
INDEX `idx_contractType` (`contractType`),
UNIQUE (`code`)
);
@ -89,3 +90,25 @@ CREATE TABLE IF NOT EXISTS `paymentsPerEmployeePerDay` (
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)
);