Conversie codeigniter 4

This commit is contained in:
2026-01-09 11:41:28 +01:00
parent dbd8c8aed2
commit f0b9c6ad40
242 changed files with 20034 additions and 346 deletions
@@ -0,0 +1,57 @@
<?php
namespace App\Controllers\Projects;
use App\Controllers\BaseController;
use CodeIgniter\HTTP\ResponseInterface;
class CommentsController 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 index()
{
// Default action
}
public function getComments(int $foreignID, string $tablename): ResponseInterface
{
$comments = \Comment::getComments($foreignID, $tablename);
return $this->json($comments);
}
public function getComment(int $commentID): ResponseInterface
{
$comment = \Comment::find($commentID);
$comment->comment = base64_decode($comment->comment);
return $this->json($comment);
}
public function addComment(int $foreignID, string $tablename): ResponseInterface
{
$commentID = \Comment::addComment($foreignID, $tablename);
return $this->json($commentID);
}
public function saveComment(int $commentID): ResponseInterface
{
$comment = $this->request->getPost('comment');
$comment = base64_encode($comment);
\Comment::whereId($commentID)->update(['comment' => $comment]);
return $this->json(['success' => true]);
}
}
@@ -0,0 +1,55 @@
<?php
namespace App\Controllers\Projects;
use App\Controllers\BaseController;
use CodeIgniter\HTTP\ResponseInterface;
class DocumentsController 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 getDocuments(int $foreignID): ResponseInterface
{
$documents = \Document::getDocuments($foreignID);
return $this->json($documents);
}
public function downloadDocument(int $documentID): ResponseInterface
{
$document = \Document::find($documentID);
$filePath = ROOTPATH . 'documents/' . $document->storagename;
if (!file_exists($filePath)) {
return $this->json(['error' => 'File not found']);
}
$data = file_get_contents($filePath);
return $this->response->download($document->originalname, $data);
}
public function removeDocument(int $documentID): ResponseInterface
{
$document = \Document::find($documentID);
$filePath = ROOTPATH . 'documents/' . $document->storagename;
if (file_exists($filePath)) {
unlink($filePath);
}
\Document::whereId($documentID)->delete();
return $this->json(['success' => true]);
}
}
@@ -0,0 +1,91 @@
<?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]);
}
}
@@ -0,0 +1,99 @@
<?php
namespace App\Controllers\Projects;
use App\Controllers\BaseController;
use CodeIgniter\HTTP\ResponseInterface;
class OffersController 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 index()
{
// Default action
}
public function getAllOffers(): ResponseInterface
{
$projectID = $this->cleanInput('projectID');
$archive = $this->cleanInput('archive');
$search = $this->cleanInput('search');
$order = $this->cleanInput('order');
$direction = $this->cleanInput('direction');
$offers = \Offer::getAllOffers($projectID, $archive, $search, $order, $direction);
return $this->json($offers);
}
public function getOffersWithoutProject(): ResponseInterface
{
$offersWithoutProject = \Offer::getOffersWithoutProject();
return $this->json($offersWithoutProject);
}
public function saveOffer(): ResponseInterface
{
$offerValidation = new \OfferValidation();
if (!$offerValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $offerValidation->getErrorMessages()
]);
}
$offer = $this->request->getPost();
$offerID = $offer['id'];
unset($offer['id']);
$offerID = \Offer::saveOffer($offerID, $offer);
$createProject = $this->checkCreateproject($offerID);
return $this->json(['success' => true, 'offerID' => $offerID, 'createProject' => $createProject]);
}
public function archiveOffer(int $offerID, string $status): ResponseInterface
{
\Offer::whereId($offerID)->update(['archive' => $status]);
return $this->json(['success' => true]);
}
public function removeOffer(int $offerID): ResponseInterface
{
$removeOffer = new \RemoveOffer($offerID);
if ($removeOffer->getRemoveAllowed() === false) {
return $this->json(['result' => false]);
}
\Offer::removeOffer($offerID);
return $this->json(['result' => true]);
}
private function checkCreateproject(int $offerID): bool
{
$offer = \Offer::find($offerID);
if (is_int($offer->project_id)) {
return false;
}
if (is_null($offer->accepteddate)) {
return false;
}
return true;
}
}
@@ -0,0 +1,399 @@
<?php
namespace App\Controllers\Projects;
use App\Controllers\BaseController;
use CodeIgniter\HTTP\ResponseInterface;
class ProjectsController 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 index()
{
// Default action
}
public function getAllProjects(): ResponseInterface
{
$archive = $this->cleanInput('archive');
$search = $this->cleanInput('search');
$order = $this->cleanInput('order');
$direction = $this->cleanInput('direction');
$projects = \Project::getAllProjects($archive, $search, $order, $direction);
return $this->json($projects);
}
public function getProject(int $projectID): ResponseInterface
{
$project = \Project::getProject($projectID);
// Get invoice details using the Invoices_model equivalent
$db = \Config\Database::connect();
$builder = $db->table('invoices');
$project->invoiceDetails = $builder
->selectSum('invoiceamount', 'invoiceTotal')
->selectSum('forecastamount', 'forecastTotal')
->where('project_id', $project->id)
->get()
->getRow();
$project->hourTotals = \Projecthour::getTotalHoursPerProject($project->id);
return $this->json($project);
}
public function getAvailableEmployees(int $projectID): ResponseInterface
{
$availableEmployees = \Projectemployee::getAvailableEmployees($projectID);
return $this->json($availableEmployees);
}
public function addProject(): ResponseInterface
{
$projectID = \Project::createProject();
return $this->json($projectID);
}
public function creatProjectFromOffer(int $offerID): ResponseInterface
{
$offer = \Offer::find($offerID);
$offernumber = $offer->offernumber;
$projectnumber = 'P' . substr($offernumber, 1);
$data = [
'projectnumber' => $projectnumber,
'projectname' => $offer->offername,
'projectleader_id' => $offer->offerleader_id,
'startdate' => $offer->accepteddate,
'customer_id' => $offer->customer_id
];
$project = \Project::create($data);
\Offer::whereId($offerID)->update(['project_id' => $project->id]);
\Projectemployee::firstOrCreateProjectemployee($offer->offerleader_id, $project->id);
$offerteHours = \Employeehour::whereOfferId($offerID)->get();
foreach ($offerteHours as $offerteHour) {
$projectemployee = \Projectemployee::firstOrCreateProjectemployee($offerteHour->employee_id, $project->id);
$data = [
'projectemployee_id' => $projectemployee->id,
'hourtype_id' => 10,
'hourdate' => $offerteHour->hourdate,
'hours' => $offerteHour->hours
];
\Projecthour::create($data);
\Employeehour::whereId($offerteHour->id)->delete();
}
return $this->json(['success' => true, 'projectnumber' => $projectnumber]);
}
public function addProjectEmployee(int $projectID): ResponseInterface
{
\Projectemployee::createProjectEmployee($projectID);
return $this->json(['success' => true]);
}
public function saveProject(): ResponseInterface
{
$projectValidation = new \ProjectValidation();
if (!$projectValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $projectValidation->getErrorMessages()
]);
}
$project = $this->request->getPost();
$projectID = $project['id'];
unset($project['id']);
$project['startdate'] = date2mysql($project['startdate']);
$project['enddate'] = date2mysql($project['enddate']);
$projectID = \Project::saveProject($projectID, $project);
\Offer::syncProjectname($projectID);
return $this->json(['success' => true, 'projectID' => $projectID]);
}
public function saveProjectemployee(): ResponseInterface
{
$projectemployeeValidation = new \ProjectemployeeValidation();
if (!$projectemployeeValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $projectemployeeValidation->getErrorMessages()
]);
}
$projectemployee = $this->request->getPost();
$projectemployeeID = $projectemployee['id'];
unset($projectemployee['id']);
\Projectemployee::saveProjectemployee($projectemployeeID, $projectemployee);
return $this->json(['success' => true]);
}
public function saveInvoice(): ResponseInterface
{
$invoiceValidation = new \InvoiceValidation();
if (!$invoiceValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $invoiceValidation->getErrorMessages()
]);
}
$invoice = $this->request->getPost();
$invoiceID = $invoice['id'];
unset($invoice['id']);
$invoice['invoicedate'] = date2mysql($invoice['invoicedate']);
$invoice['forecastdate'] = date2mysql($invoice['forecastdate']);
$invoice['invoiceamount'] = str_replace(',', '.', $invoice['invoiceamount'] ?? '');
$invoice['forecastamount'] = str_replace(',', '.', $invoice['forecastamount'] ?? '');
$invoiceID = \Invoice::saveInvoice($invoiceID, $invoice);
return $this->json(['success' => true, 'invoiceID' => $invoiceID]);
}
public function savePayment(): ResponseInterface
{
$paymentValidation = new \PaymentValidation();
if (!$paymentValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $paymentValidation->getErrorMessages()
]);
}
$payment = $this->request->getPost();
$paymentID = $payment['id'];
unset($payment['id']);
$payment['paymentdate'] = date2mysql($payment['paymentdate']);
$payment['paymentamount'] = str_replace(',', '.', $payment['paymentamount'] ?? '');
$paymentID = \Payment::savePayment($paymentID, $payment);
return $this->json(['success' => true, 'paymentID' => $paymentID]);
}
public function saveProjectcost(): ResponseInterface
{
$projectcostValidation = new \ProjectcostValidation();
if (!$projectcostValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $projectcostValidation->getErrorMessages()
]);
}
$projectcost = $this->request->getPost();
$projectcostID = $projectcost['id'];
unset($projectcost['id']);
$projectcost['date'] = date2mysql($projectcost['date']);
$projectcostID = \Projectcost::saveProjectcost($projectcostID, $projectcost);
return $this->json(['success' => true, 'projectcostID' => $projectcostID]);
}
public function saveProjecthour(): ResponseInterface
{
$projecthourValidation = new \ProjecthourValidation();
if (!$projecthourValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $projecthourValidation->getErrorMessages()
]);
}
$projecthour = $this->request->getPost();
$projecthourID = $projecthour['id'];
unset($projecthour['id']);
$projecthour['hourdate'] = date2mysql($projecthour['hourdate']);
$paymentID = \Projecthour::saveProjecthour($projecthourID, $projecthour);
return $this->json(['success' => true, 'projecthourID' => $paymentID]);
}
public function saveForecast(): ResponseInterface
{
$forecastValidation = new \ForecastValidation();
if (!$forecastValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $forecastValidation->getErrorMessages()
]);
}
$forecast = $this->request->getPost();
$forecastID = $forecast['id'];
unset($forecast['id']);
$forecastID = \Forecast::saveForecast($forecastID, $forecast);
return $this->json(['success' => true, 'forecastID' => $forecastID]);
}
public function saveReservation(): ResponseInterface
{
$reservationValidation = new \ReservationValidation();
if (!$reservationValidation->getValidationResult()) {
return $this->json([
'success' => false,
'messages' => $reservationValidation->getErrorMessages()
]);
}
$reservation = $this->request->getPost();
$reservationID = $reservation['id'];
unset($reservation['id']);
$reservationID = \Reservation::saveReservation($reservationID, $reservation);
return $this->json(['success' => true, 'reservationID' => $reservationID]);
}
public function archiveProject(int $projectID, string $status): ResponseInterface
{
\Project::whereId($projectID)->update(['archive' => $status]);
return $this->json(['success' => true]);
}
public function removeProjectemployee(int $projectemployeeID): ResponseInterface
{
$removeProjectemployee = new \RemoveProjectemployee($projectemployeeID);
if ($removeProjectemployee->getRemoveAllowed() === false) {
return $this->json(['result' => false]);
}
\Projectemployee::removeProjectemployee($projectemployeeID);
return $this->json(['result' => true]);
}
public function removeInvoice(int $invoiceID): ResponseInterface
{
$removeInvoice = new \RemoveInvoice($invoiceID);
if ($removeInvoice->getRemoveAllowed() === false) {
return $this->json(['result' => false]);
}
\Invoice::whereId($invoiceID)->delete();
return $this->json(['result' => true]);
}
public function removeIncomingInvoice(int $invoiceID): ResponseInterface
{
\Projectcost::whereId($invoiceID)->delete();
return $this->json(['result' => true]);
}
public function removePayment(int $paymentID): ResponseInterface
{
$removePayment = new \RemovePayment($paymentID);
if ($removePayment->getAllowDelete() === false) {
return $this->json(['result' => false]);
}
\Payment::removePayment($paymentID);
return $this->json(['result' => true]);
}
public function removeProjecthour(int $projecthourID): ResponseInterface
{
$removeProjecthour = new \RemoveProjecthour($projecthourID);
if ($removeProjecthour->getAllowDelete() === false) {
return $this->json(['result' => false]);
}
\Projecthour::removeProjecthour($projecthourID);
return $this->json(['result' => true]);
}
public function removeForecast(int $forecastID): ResponseInterface
{
$removeForecast = new \RemoveForecast($forecastID);
if ($removeForecast->getAllowDelete() === false) {
return $this->json(['result' => false]);
}
\Forecast::removeForecast($forecastID);
return $this->json(['result' => true]);
}
public function removeReservation(int $reservationID): ResponseInterface
{
$removeReservation = new \RemoveReservation($reservationID);
if ($removeReservation->getAllowDelete() === false) {
return $this->json(['result' => false]);
}
\Reservation::removeReservation($reservationID);
return $this->json(['result' => true]);
}
public function removeProject(int $projectID): ResponseInterface
{
$removeProject = new \RemoveProject($projectID);
if ($removeProject->getRemoveAllowed() === false) {
return $this->json(['result' => false]);
}
\Project::removeProject($projectID);
return $this->json(['result' => true]);
}
}