186 lines
5.1 KiB
PHP
186 lines
5.1 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 = [];
|
|
$libraries = [];
|
|
|
|
$this->load->model( $models );
|
|
$this->load->library( $libraries );
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
}
|
|
|
|
public function getAllProjects( $archive = 'F' )
|
|
{
|
|
$projects = Project::getAllProjects( $archive );
|
|
|
|
$this->json( $projects );
|
|
}
|
|
|
|
public function getProject( $projectID )
|
|
{
|
|
$project = Project::getProject( $projectID );
|
|
|
|
$this->json( $project );
|
|
}
|
|
|
|
public function addProject()
|
|
{
|
|
$projectID = Project::createProject();
|
|
|
|
$this->json( $projectID );
|
|
}
|
|
|
|
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 );
|
|
|
|
$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['startdate'] = date2mysql( $projectemployee['startdate'] );
|
|
|
|
Projectemployee::saveProjectemployee( $projectemployeeID, $projectemployee );
|
|
|
|
$this->json( ['success' => TRUE] );
|
|
}
|
|
|
|
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'] );
|
|
|
|
$paymentID = Payment::savePayment( $paymentID, $payment );
|
|
|
|
$this->json( ['success' => TRUE, 'paymentID'=> $paymentID ] );
|
|
}
|
|
|
|
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 archiveProject( $projectID, $status )
|
|
{
|
|
Project::whereId( $projectID )->update( ['archive' => $status] );
|
|
}
|
|
|
|
public function removeProject( $projectID )
|
|
{
|
|
$removeProject = new RemoveProject( $projectID );
|
|
|
|
if ( $removeProject->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Project::removeProject( $projectID );
|
|
|
|
$this->json( ['result' => TRUE] );
|
|
}
|
|
|
|
public function removeProjectemployee( $projectemployeeID )
|
|
{
|
|
$removeProjectemployee = new RemoveProjectemployee( $projectemployeeID );
|
|
|
|
if ( $removeProjectemployee->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
|
|
|
|
Projectemployee::removeProjectemployee( $projectemployeeID );
|
|
|
|
$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] );
|
|
}
|
|
|
|
} |