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 ); $project->outstanding = $this->Invoices_model->getOutstandingPerProject( $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, '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::create( [ 'project_id' => $project->id, 'user_id' => $offer->offerleader_id, 'tarif' => User::find( $offer->offerleader_id )->hourlyrate ] ); $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 ); $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 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] ); } 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] ); Forecast::removeReservation( $reservationID ); $this->json( ['result' => TRUE] ); } }