92 lines
2.8 KiB
PHP
92 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Projects;
|
|
|
|
use App\Controllers\BaseController;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
|
|
class EmployeeHoursController extends BaseController
|
|
{
|
|
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
|
|
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
|
die('NO ACCESS');
|
|
}
|
|
}
|
|
|
|
public function getEmployeehours(int $month, int $year, int $employeeID): ResponseInterface
|
|
{
|
|
$sql = \EmployeehoursMonthly::fire($month, $year, $employeeID);
|
|
|
|
$db = \Config\Database::connect();
|
|
$query = $db->query($sql);
|
|
|
|
$result = $query->getResult();
|
|
|
|
return $this->json($result);
|
|
}
|
|
|
|
public function getHourtypes(): ResponseInterface
|
|
{
|
|
$hourtypes = \Hourtype::all();
|
|
|
|
return $this->json($hourtypes);
|
|
}
|
|
|
|
public function saveEmployeehour(): ResponseInterface
|
|
{
|
|
// TODO: validatie inbouwen
|
|
$data = $this->request->getPost();
|
|
|
|
$employeehourID = $data['id'];
|
|
$hourType = $data['hourType'];
|
|
$projectID = $data['project_id'];
|
|
unset($data['id']);
|
|
unset($data['hourType']);
|
|
unset($data['project_id']);
|
|
|
|
if ($hourType == 'OFFERS') {
|
|
$data['offer_id'] = $projectID;
|
|
}
|
|
|
|
$data['hourdate'] = date2mysql($data['hourdate']);
|
|
|
|
if ($hourType == 'PROJECTS') {
|
|
$projectemployee = \Projectemployee::select('id')
|
|
->whereUserId($data['employee_id'])
|
|
->whereProjectId($projectID)
|
|
->first();
|
|
$data['projectemployee_id'] = $projectemployee->id;
|
|
unset($data['employee_id']);
|
|
|
|
$data['hourtype_id'] = $data['hourtype_id'] - 8;
|
|
|
|
$employeehourID = \Projecthour::saveProjecthour($data);
|
|
} elseif ($hourType == 'OFFERS') {
|
|
$data['projectemployee_id'] = $data['employee_id'];
|
|
unset($data['employee_id']);
|
|
$data['hourtype_id'] = $data['hourtype_id'] - 8;
|
|
|
|
$employeehourID = \Projecthour::saveProjecthour($data);
|
|
} else {
|
|
$employeehourID = \Employeehour::saveEmployeehour($data);
|
|
}
|
|
|
|
return $this->json(['employeehourID' => $employeehourID]);
|
|
}
|
|
|
|
public function removeEmployeehour(int $employeehourID, string $hourType): ResponseInterface
|
|
{
|
|
// TODO: check op delete
|
|
if ($hourType == 'OVERHEAD') {
|
|
\Employeehour::whereId($employeehourID)->delete();
|
|
} else {
|
|
\Projecthour::whereId($employeehourID)->delete();
|
|
}
|
|
|
|
return $this->json(['result' => true]);
|
|
}
|
|
}
|