Revised database drivers, query builder, and file/inflector helpers for improved consistency and functionality. Updated copyrights, links, and standardized function names including deprecating `is_countable` in favor of `word_is_countable`. Added support for new SQL features and optimized query handling.
375 lines
9.9 KiB
PHP
375 lines
9.9 KiB
PHP
<?php
|
|
defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
|
|
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 05/01/2018
|
|
* Time: 15:03
|
|
*/
|
|
class ProjectsController extends MY_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
if ( AUTHENTICATED == FALSE ) die( 'NO ACCESS' );
|
|
|
|
$models = ['projects/Invoices_model'];
|
|
$libraries = [];
|
|
|
|
$this->load->model( $models );
|
|
$this->load->library( $libraries );
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
}
|
|
|
|
public function getAllProjects()
|
|
{
|
|
$archive = $this->clean_input( 'archive' );
|
|
$search = $this->clean_input( 'search' );
|
|
$order = $this->clean_input( 'order' );
|
|
$direction = $this->clean_input( 'direction' );
|
|
|
|
$projects = Project::getAllProjects( $archive, $search, $order, $direction );
|
|
|
|
$this->json( $projects );
|
|
}
|
|
|
|
public function getProject( $projectID )
|
|
{
|
|
$project = Project::getProject( $projectID );
|
|
|
|
$project->invoiceDetails =
|
|
$this->Invoices_model->getOutstandingPerProject( $project->id );
|
|
|
|
$project->hourTotals =
|
|
Projecthour::getTotalHoursPerProject( $project->id );
|
|
|
|
$this->json( $project );
|
|
}
|
|
|
|
public function getAvailableEmployees( $projectID )
|
|
{
|
|
$availableEmployees =
|
|
Projectemployee::getAvailableEmployees( $projectID );
|
|
|
|
$this->json( $availableEmployees );
|
|
}
|
|
|
|
public function addProject()
|
|
{
|
|
$projectID = Project::createProject();
|
|
|
|
$this->json( $projectID );
|
|
}
|
|
|
|
public function creatProjectFromOffer( $offerID )
|
|
{
|
|
$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();
|
|
}
|
|
|
|
$this->json( ['success' => TRUE, 'projectnumber' => $projectnumber] );
|
|
}
|
|
|
|
public function addProjectEmployee( $projectID )
|
|
{
|
|
Projectemployee::createProjectEmployee( $projectID );
|
|
}
|
|
|
|
public function saveProject()
|
|
{
|
|
$projectValidation = new ProjectValidation();
|
|
|
|
if ( ! $projectValidation->getValidationResult() )
|
|
return $this->json( [
|
|
'success' => FALSE, 'messages' => $projectValidation->getErrorMessages()] );
|
|
|
|
$project = $this->input->post();
|
|
|
|
$projectID = $project['id'];
|
|
unset( $project['id'] );
|
|
|
|
$project['startdate'] = date2mysql( $project['startdate'] );
|
|
$project['enddate'] = date2mysql( $project['enddate'] );
|
|
|
|
$projectID = Project::saveProject( $projectID, $project );
|
|
|
|
Offer::syncProjectname( $projectID );
|
|
|
|
$this->json( ['success' => TRUE, 'projectID' => $projectID] );
|
|
}
|
|
|
|
public function saveProjectemployee()
|
|
{
|
|
$projectemployeeValidation = new ProjectemployeeValidation();
|
|
|
|
if ( ! $projectemployeeValidation->getValidationResult() )
|
|
return $this->json( [
|
|
'success' => FALSE, 'messages' => $projectemployeeValidation->getErrorMessages()] );
|
|
|
|
$projectemployee = $this->input->post();
|
|
|
|
$projectemployeeID = $projectemployee['id'];
|
|
unset( $projectemployee['id'] );
|
|
|
|
Projectemployee::saveProjectemployee( $projectemployeeID, $projectemployee );
|
|
|
|
$this->json( ['success' => TRUE] );
|
|
}
|
|
|
|
public function saveInvoice()
|
|
{
|
|
$invoiceValidation = new InvoiceValidation();
|
|
|
|
if ( ! $invoiceValidation->getValidationResult() )
|
|
return $this->json( [
|
|
'success' => FALSE, 'messages' => $invoiceValidation->getErrorMessages()] );
|
|
|
|
$invoice = $this->input->post();
|
|
|
|
$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 );
|
|
|
|
$this->json( ['success' => TRUE, 'invoiceID' => $invoiceID] );
|
|
}
|
|
|
|
public function savePayment()
|
|
{
|
|
$paymentValidation = new PaymentValidation();
|
|
|
|
if ( ! $paymentValidation->getValidationResult() )
|
|
return $this->json( [
|
|
'success' => FALSE, 'messages' => $paymentValidation->getErrorMessages()] );
|
|
|
|
$payment = $this->input->post();
|
|
|
|
$paymentID = $payment['id'];
|
|
unset( $payment['id'] );
|
|
|
|
$payment['paymentdate'] = date2mysql( $payment['paymentdate'] );
|
|
$payment['paymentamount'] = str_replace( ',', '.', $payment['paymentamount'] ?? '' );
|
|
|
|
$paymentID = Payment::savePayment( $paymentID, $payment );
|
|
|
|
$this->json( ['success' => TRUE, 'paymentID' => $paymentID] );
|
|
}
|
|
|
|
public function saveProjectcost()
|
|
{
|
|
$projectcostValidation = new ProjectcostValidation();
|
|
|
|
if ( ! $projectcostValidation->getValidationResult() )
|
|
return $this->json( [
|
|
'success' => FALSE, 'messages' => $projectcostValidation->getErrorMessages()] );
|
|
|
|
$projectcost = $this->input->post();
|
|
|
|
$projectcostID = $projectcost['id'];
|
|
unset( $projectcost['id'] );
|
|
|
|
$projectcost['date'] = date2mysql( $projectcost['date'] );
|
|
|
|
$projectcostID = Projectcost::saveProjectcost( $projectcostID, $projectcost );
|
|
|
|
$this->json( ['success' => TRUE, 'projectcostID' => $projectcostID] );
|
|
}
|
|
|
|
public function saveProjecthour()
|
|
{
|
|
$projecthourValidation = new ProjecthourValidation();
|
|
|
|
if ( ! $projecthourValidation->getValidationResult() )
|
|
return $this->json( [
|
|
'success' => FALSE, 'messages' => $projecthourValidation->getErrorMessages()] );
|
|
|
|
$projecthour = $this->input->post();
|
|
|
|
$projecthourID = $projecthour['id'];
|
|
unset( $projecthour['id'] );
|
|
|
|
$projecthour['hourdate'] = date2mysql( $projecthour['hourdate'] );
|
|
|
|
$paymentID = Projecthour::saveProjecthour( $projecthourID, $projecthour );
|
|
|
|
$this->json( ['success' => TRUE, 'projecthourID' => $paymentID] );
|
|
}
|
|
|
|
public function saveForecast()
|
|
{
|
|
$forecastValidation = new ForecastValidation();
|
|
|
|
if ( ! $forecastValidation->getValidationResult() )
|
|
return $this->json( [
|
|
'success' => FALSE, 'messages' => $forecastValidation->getErrorMessages()] );
|
|
|
|
$forecast = $this->input->post();
|
|
|
|
$forecastID = $forecast['id'];
|
|
unset( $forecast['id'] );
|
|
|
|
$forecastID = Forecast::saveForecast( $forecastID, $forecast );
|
|
|
|
$this->json( ['success' => TRUE, 'forecastID' => $forecastID] );
|
|
}
|
|
|
|
public function saveReservation()
|
|
{
|
|
$reservationValidation = new ReservationValidation();
|
|
|
|
if ( ! $reservationValidation->getValidationResult() )
|
|
return $this->json( [
|
|
'success' => FALSE, 'messages' => $reservationValidation->getErrorMessages()] );
|
|
|
|
$reservation = $this->input->post();
|
|
|
|
$reservationID = $reservation['id'];
|
|
unset( $reservation['id'] );
|
|
|
|
$reservationID = Reservation::saveReservation( $reservationID, $reservation );
|
|
|
|
$this->json( ['success' => TRUE, 'reservationID' => $reservationID] );
|
|
}
|
|
|
|
public function archiveProject( $projectID, $status )
|
|
{
|
|
Project::whereId( $projectID )->update( ['archive' => $status] );
|
|
}
|
|
|
|
public function removeProjectemployee( $projectemployeeID )
|
|
{
|
|
$removeProjectemployee = new RemoveProjectemployee( $projectemployeeID );
|
|
|
|
if ( $removeProjectemployee->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Projectemployee::removeProjectemployee( $projectemployeeID );
|
|
|
|
$this->json( ['result' => TRUE] );
|
|
}
|
|
|
|
public function removeInvoice( $invoiceID )
|
|
{
|
|
$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( $invoiceID )
|
|
{
|
|
// $removeInvoice = new RemoveInvoice( $invoiceID );
|
|
//
|
|
// if ( $removeInvoice->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Projectcost::whereId( $invoiceID )->delete();
|
|
|
|
return $this->json( ['result' => TRUE] );
|
|
}
|
|
|
|
public function removePayment( $paymentID )
|
|
{
|
|
$removePayment = new RemovePayment( $paymentID );
|
|
|
|
if ( $removePayment->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Payment::removePayment( $paymentID );
|
|
|
|
$this->json( ['result' => TRUE] );
|
|
}
|
|
|
|
public function removeProjecthour( $projecthourID )
|
|
{
|
|
$removeProjecthour = new RemoveProjecthour( $projecthourID );
|
|
|
|
if ( $removeProjecthour->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Projecthour::removeProjecthour( $projecthourID );
|
|
|
|
$this->json( ['result' => TRUE] );
|
|
}
|
|
|
|
public function removeForecast( $forecastID )
|
|
{
|
|
$removeForecast = new RemoveForecast( $forecastID );
|
|
|
|
if ( $removeForecast->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Forecast::removeForecast( $forecastID );
|
|
|
|
$this->json( ['result' => TRUE] );
|
|
}
|
|
|
|
public function removeReservation( $reservationID )
|
|
{
|
|
$removeReservation = new RemoveReservation( $reservationID );
|
|
|
|
if ( $removeReservation->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Reservation::removeReservation( $reservationID );
|
|
|
|
$this->json( ['result' => TRUE] );
|
|
}
|
|
|
|
public function removeProject( $projectID )
|
|
{
|
|
$removeProject = new RemoveProject( $projectID );
|
|
|
|
if ( $removeProject->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Project::removeProject( $projectID );
|
|
|
|
$this->json( ['result' => TRUE] );
|
|
}
|
|
|
|
}
|
|
|
|
|