diff --git a/application/controllers/beheer/UsersController.php b/application/controllers/beheer/UsersController.php index eee3f02..0b90fdc 100644 --- a/application/controllers/beheer/UsersController.php +++ b/application/controllers/beheer/UsersController.php @@ -53,6 +53,13 @@ class usersController extends MY_Controller { $this->json( $usersWithProjects ); } + public function getUserActiveProjects($userID) + { + $userActiveProjects = User::getUserActiveProjects($userID); + + $this->json( $userActiveProjects ); + } + public function getUniqueprojectEmployees() { $projectEmployees = User::getUniqueProjectUsers(); @@ -136,4 +143,4 @@ class usersController extends MY_Controller { $this->email->send(); } -} \ No newline at end of file +} diff --git a/application/controllers/projects/ProjectsController.php b/application/controllers/projects/ProjectsController.php index 13b4a70..19d4290 100644 --- a/application/controllers/projects/ProjectsController.php +++ b/application/controllers/projects/ProjectsController.php @@ -9,363 +9,365 @@ defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' ); */ class ProjectsController extends MY_Controller { - public function __construct() - { - parent::__construct(); + public function __construct() + { + parent::__construct(); - if ( AUTHENTICATED == FALSE ) die( 'NO ACCESS' ); + if ( AUTHENTICATED == FALSE ) die( 'NO ACCESS' ); - $models = ['projects/Invoices_model']; - $libraries = []; + $models = ['projects/Invoices_model']; + $libraries = []; - $this->load->model( $models ); - $this->load->library( $libraries ); - } + $this->load->model( $models ); + $this->load->library( $libraries ); + } - public function index() - { + 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' ); + 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 ); + $projects = Project::getAllProjects( $archive, $search, $order, $direction ); - $this->json( $projects ); - } + $this->json( $projects ); + } - public function getProject( $projectID ) - { - $project = Project::getProject( $projectID ); + public function getProject( $projectID ) + { + $project = Project::getProject( $projectID ); - $project->invoiceDetails = - $this->Invoices_model->getOutstandingPerProject( $project->id ); + $project->invoiceDetails = + $this->Invoices_model->getOutstandingPerProject( $project->id ); - $project->hourTotals = - Projecthour::getTotalHoursPerProject( $project->id ); + $project->hourTotals = + Projecthour::getTotalHoursPerProject( $project->id ); - $this->json( $project ); - } + $this->json( $project ); + } - public function getAvailableEmployees( $projectID ) - { - $availableEmployees = - Projectemployee::getAvailableEmployees( $projectID ); + public function getAvailableEmployees( $projectID ) + { + $availableEmployees = + Projectemployee::getAvailableEmployees( $projectID ); - $this->json( $availableEmployees ); - } + $this->json( $availableEmployees ); + } - public function addProject() - { - $projectID = Project::createProject(); + public function addProject() + { + $projectID = Project::createProject(); - $this->json( $projectID ); - } + $this->json( $projectID ); + } - public function creatProjectFromOffer( $offerID ) - { - $offer = Offer::find( $offerID ); + public function creatProjectFromOffer( $offerID ) + { + $offer = Offer::find( $offerID ); - $offernumber = $offer->offernumber; + $offernumber = $offer->offernumber; - $projectnumber = 'P' . substr( $offernumber, 1 ); + $projectnumber = 'P' . substr( $offernumber, 1 ); - $data = [ - 'projectnumber' => $projectnumber, - 'projectname' => $offer->offername, - 'projectleader_id' => $offer->offerleader_id, - 'startdate' => $offer->accepteddate, - 'customer_id' => $offer->customer_id - ]; + $data = [ + 'projectnumber' => $projectnumber, + 'projectname' => $offer->offername, + 'projectleader_id' => $offer->offerleader_id, + 'startdate' => $offer->accepteddate, + 'customer_id' => $offer->customer_id + ]; - $project = Project::create( $data ); + $project = Project::create( $data ); - Offer::whereId( $offerID )->update( ['project_id' => $project->id] ); + Offer::whereId( $offerID )->update( ['project_id' => $project->id] ); - Projectemployee::firstOrCreateProjectemployee( $offer->offerleader_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 ); + $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 - ]; + $data = [ + 'projectemployee_id' => $projectemployee->id, + 'hourtype_id' => 10, + 'hourdate' => $offerteHour->hourdate, + 'hours' => $offerteHour->hours + ]; - Projecthour::create( $data ); + Projecthour::create( $data ); - Employeehour::whereId( $offerteHour->id )->delete(); - } + Employeehour::whereId( $offerteHour->id )->delete(); + } - $this->json( ['success' => TRUE, 'projectnumber' => $projectnumber] ); - } + $this->json( ['success' => TRUE, 'projectnumber' => $projectnumber] ); + } - public function addProjectEmployee( $projectID ) - { - Projectemployee::createProjectEmployee( $projectID ); - } + public function addProjectEmployee( $projectID ) + { + Projectemployee::createProjectEmployee( $projectID ); + } - public function saveProject() - { - $projectValidation = new ProjectValidation(); + public function saveProject() + { + $projectValidation = new ProjectValidation(); - if ( ! $projectValidation->getValidationResult() ) - return $this->json( [ - 'success' => FALSE, 'messages' => $projectValidation->getErrorMessages()] ); + if ( ! $projectValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $projectValidation->getErrorMessages()] ); - $project = $this->input->post(); + $project = $this->input->post(); - $projectID = $project['id']; - unset( $project['id'] ); + $projectID = $project['id']; + unset( $project['id'] ); - $project['startdate'] = date2mysql( $project['startdate'] ); - $project['enddate'] = date2mysql( $project['enddate'] ); + $project['startdate'] = date2mysql( $project['startdate'] ); + $project['enddate'] = date2mysql( $project['enddate'] ); - $projectID = Project::saveProject( $projectID, $project ); + $projectID = Project::saveProject( $projectID, $project ); - $this->json( ['success' => TRUE, 'projectID' => $projectID] ); - } + Offer::syncProjectname( $projectID ); - public function saveProjectemployee() - { - $projectemployeeValidation = new ProjectemployeeValidation(); + $this->json( ['success' => TRUE, 'projectID' => $projectID] ); + } - if ( ! $projectemployeeValidation->getValidationResult() ) - return $this->json( [ - 'success' => FALSE, 'messages' => $projectemployeeValidation->getErrorMessages()] ); + public function saveProjectemployee() + { + $projectemployeeValidation = new ProjectemployeeValidation(); - $projectemployee = $this->input->post(); + if ( ! $projectemployeeValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $projectemployeeValidation->getErrorMessages()] ); - $projectemployeeID = $projectemployee['id']; - unset( $projectemployee['id'] ); + $projectemployee = $this->input->post(); - Projectemployee::saveProjectemployee( $projectemployeeID, $projectemployee ); + $projectemployeeID = $projectemployee['id']; + unset( $projectemployee['id'] ); - $this->json( ['success' => TRUE] ); - } + Projectemployee::saveProjectemployee( $projectemployeeID, $projectemployee ); - public function saveInvoice() - { - $invoiceValidation = new InvoiceValidation(); + $this->json( ['success' => TRUE] ); + } - if ( ! $invoiceValidation->getValidationResult() ) - return $this->json( [ - 'success' => FALSE, 'messages' => $invoiceValidation->getErrorMessages()] ); + public function saveInvoice() + { + $invoiceValidation = new InvoiceValidation(); - $invoice = $this->input->post(); + if ( ! $invoiceValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $invoiceValidation->getErrorMessages()] ); - $invoiceID = $invoice['id']; - unset( $invoice['id'] ); + $invoice = $this->input->post(); - $invoice['invoicedate'] = date2mysql( $invoice['invoicedate'] ); - $invoice['forecastdate'] = date2mysql( $invoice['forecastdate'] ); - $invoice['invoiceamount'] = str_replace( ',', '.', $invoice['invoiceamount'] ); - $invoice['forecastamount'] = str_replace( ',', '.', $invoice['forecastamount'] ); + $invoiceID = $invoice['id']; + unset( $invoice['id'] ); - $invoiceID = Invoice::saveInvoice( $invoiceID, $invoice ); + $invoice['invoicedate'] = date2mysql( $invoice['invoicedate'] ); + $invoice['forecastdate'] = date2mysql( $invoice['forecastdate'] ); + $invoice['invoiceamount'] = str_replace( ',', '.', $invoice['invoiceamount'] ); + $invoice['forecastamount'] = str_replace( ',', '.', $invoice['forecastamount'] ); - $this->json( ['success' => TRUE, 'invoiceID' => $invoiceID] ); - } + $invoiceID = Invoice::saveInvoice( $invoiceID, $invoice ); - public function savePayment() - { - $paymentValidation = new PaymentValidation(); + $this->json( ['success' => TRUE, 'invoiceID' => $invoiceID] ); + } - if ( ! $paymentValidation->getValidationResult() ) - return $this->json( [ - 'success' => FALSE, 'messages' => $paymentValidation->getErrorMessages()] ); + public function savePayment() + { + $paymentValidation = new PaymentValidation(); - $payment = $this->input->post(); + if ( ! $paymentValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $paymentValidation->getErrorMessages()] ); - $paymentID = $payment['id']; - unset( $payment['id'] ); + $payment = $this->input->post(); - $payment['paymentdate'] = date2mysql( $payment['paymentdate'] ); - $payment['paymentamount'] = str_replace( ',', '.', $payment['paymentamount'] ); + $paymentID = $payment['id']; + unset( $payment['id'] ); - $paymentID = Payment::savePayment( $paymentID, $payment ); + $payment['paymentdate'] = date2mysql( $payment['paymentdate'] ); + $payment['paymentamount'] = str_replace( ',', '.', $payment['paymentamount'] ); - $this->json( ['success' => TRUE, 'paymentID' => $paymentID] ); - } + $paymentID = Payment::savePayment( $paymentID, $payment ); - public function saveProjectcost() - { - $projectcostValidation = new ProjectcostValidation(); + $this->json( ['success' => TRUE, 'paymentID' => $paymentID] ); + } - if ( ! $projectcostValidation->getValidationResult() ) - return $this->json( [ - 'success' => FALSE, 'messages' => $projectcostValidation->getErrorMessages()] ); + public function saveProjectcost() + { + $projectcostValidation = new ProjectcostValidation(); - $projectcost = $this->input->post(); + if ( ! $projectcostValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $projectcostValidation->getErrorMessages()] ); - $projectcostID = $projectcost['id']; - unset( $projectcost['id'] ); + $projectcost = $this->input->post(); - $projectcost['date'] = date2mysql( $projectcost['date'] ); + $projectcostID = $projectcost['id']; + unset( $projectcost['id'] ); - $projectcostID = Projectcost::saveProjectcost( $projectcostID, $projectcost ); + $projectcost['date'] = date2mysql( $projectcost['date'] ); - $this->json( ['success' => TRUE, 'projectcostID' => $projectcostID] ); - } + $projectcostID = Projectcost::saveProjectcost( $projectcostID, $projectcost ); - public function saveProjecthour() - { - $projecthourValidation = new ProjecthourValidation(); + $this->json( ['success' => TRUE, 'projectcostID' => $projectcostID] ); + } - if ( ! $projecthourValidation->getValidationResult() ) - return $this->json( [ - 'success' => FALSE, 'messages' => $projecthourValidation->getErrorMessages()] ); + public function saveProjecthour() + { + $projecthourValidation = new ProjecthourValidation(); - $projecthour = $this->input->post(); + if ( ! $projecthourValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $projecthourValidation->getErrorMessages()] ); - $projecthourID = $projecthour['id']; - unset( $projecthour['id'] ); + $projecthour = $this->input->post(); - $projecthour['hourdate'] = date2mysql( $projecthour['hourdate'] ); + $projecthourID = $projecthour['id']; + unset( $projecthour['id'] ); - $paymentID = Projecthour::saveProjecthour( $projecthourID, $projecthour ); + $projecthour['hourdate'] = date2mysql( $projecthour['hourdate'] ); - $this->json( ['success' => TRUE, 'projecthourID' => $paymentID] ); - } + $paymentID = Projecthour::saveProjecthour( $projecthourID, $projecthour ); - public function saveForecast() - { - $forecastValidation = new ForecastValidation(); + $this->json( ['success' => TRUE, 'projecthourID' => $paymentID] ); + } - if ( ! $forecastValidation->getValidationResult() ) - return $this->json( [ - 'success' => FALSE, 'messages' => $forecastValidation->getErrorMessages()] ); + public function saveForecast() + { + $forecastValidation = new ForecastValidation(); - $forecast = $this->input->post(); + if ( ! $forecastValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $forecastValidation->getErrorMessages()] ); - $forecastID = $forecast['id']; - unset( $forecast['id'] ); + $forecast = $this->input->post(); - $forecastID = Forecast::saveForecast( $forecastID, $forecast ); + $forecastID = $forecast['id']; + unset( $forecast['id'] ); - $this->json( ['success' => TRUE, 'forecastID' => $forecastID] ); - } + $forecastID = Forecast::saveForecast( $forecastID, $forecast ); - public function saveReservation() - { - $reservationValidation = new ReservationValidation(); + $this->json( ['success' => TRUE, 'forecastID' => $forecastID] ); + } - if ( ! $reservationValidation->getValidationResult() ) - return $this->json( [ - 'success' => FALSE, 'messages' => $reservationValidation->getErrorMessages()] ); + public function saveReservation() + { + $reservationValidation = new ReservationValidation(); - $reservation = $this->input->post(); + if ( ! $reservationValidation->getValidationResult() ) + return $this->json( [ + 'success' => FALSE, 'messages' => $reservationValidation->getErrorMessages()] ); - $reservationID = $reservation['id']; - unset( $reservation['id'] ); + $reservation = $this->input->post(); - $reservationID = Reservation::saveReservation( $reservationID, $reservation ); + $reservationID = $reservation['id']; + unset( $reservation['id'] ); - $this->json( ['success' => TRUE, 'reservationID' => $reservationID] ); - } + $reservationID = Reservation::saveReservation( $reservationID, $reservation ); - public function archiveProject( $projectID, $status ) - { - Project::whereId( $projectID )->update( ['archive' => $status] ); - } + $this->json( ['success' => TRUE, 'reservationID' => $reservationID] ); + } - public function removeProjectemployee( $projectemployeeID ) - { - $removeProjectemployee = new RemoveProjectemployee( $projectemployeeID ); + public function archiveProject( $projectID, $status ) + { + Project::whereId( $projectID )->update( ['archive' => $status] ); + } - if ( $removeProjectemployee->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); + public function removeProjectemployee( $projectemployeeID ) + { + $removeProjectemployee = new RemoveProjectemployee( $projectemployeeID ); - Projectemployee::removeProjectemployee( $projectemployeeID ); + if ( $removeProjectemployee->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); - $this->json( ['result' => TRUE] ); - } + Projectemployee::removeProjectemployee( $projectemployeeID ); - public function removeInvoice( $invoiceID ) - { - $removeInvoice = new RemoveInvoice( $invoiceID ); + $this->json( ['result' => TRUE] ); + } - if ( $removeInvoice->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); + public function removeInvoice( $invoiceID ) + { + $removeInvoice = new RemoveInvoice( $invoiceID ); - Invoice::whereId( $invoiceID )->delete(); + if ( $removeInvoice->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); - return $this->json( ['result' => TRUE] ); - } + Invoice::whereId( $invoiceID )->delete(); - public function removeIncomingInvoice( $invoiceID ) - { + 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(); + Projectcost::whereId( $invoiceID )->delete(); - return $this->json( ['result' => TRUE] ); - } + return $this->json( ['result' => TRUE] ); + } - public function removePayment( $paymentID ) - { - $removePayment = new RemovePayment( $paymentID ); + public function removePayment( $paymentID ) + { + $removePayment = new RemovePayment( $paymentID ); - if ( $removePayment->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + if ( $removePayment->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); - Payment::removePayment( $paymentID ); + Payment::removePayment( $paymentID ); - $this->json( ['result' => TRUE] ); - } + $this->json( ['result' => TRUE] ); + } - public function removeProjecthour( $projecthourID ) - { - $removeProjecthour = new RemoveProjecthour( $projecthourID ); + public function removeProjecthour( $projecthourID ) + { + $removeProjecthour = new RemoveProjecthour( $projecthourID ); - if ( $removeProjecthour->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + if ( $removeProjecthour->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); - Projecthour::removeProjecthour( $projecthourID ); + Projecthour::removeProjecthour( $projecthourID ); - $this->json( ['result' => TRUE] ); - } + $this->json( ['result' => TRUE] ); + } - public function removeForecast( $forecastID ) - { - $removeForecast = new RemoveForecast( $forecastID ); + public function removeForecast( $forecastID ) + { + $removeForecast = new RemoveForecast( $forecastID ); - if ( $removeForecast->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + if ( $removeForecast->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); - Forecast::removeForecast( $forecastID ); + Forecast::removeForecast( $forecastID ); - $this->json( ['result' => TRUE] ); - } + $this->json( ['result' => TRUE] ); + } - public function removeReservation( $reservationID ) - { - $removeReservation = new RemoveReservation( $reservationID ); + public function removeReservation( $reservationID ) + { + $removeReservation = new RemoveReservation( $reservationID ); - if ( $removeReservation->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + if ( $removeReservation->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); - Reservation::removeReservation( $reservationID ); + Reservation::removeReservation( $reservationID ); - $this->json( ['result' => TRUE] ); - } + $this->json( ['result' => TRUE] ); + } - public function removeProject( $projectID ) - { - $removeProject = new RemoveProject( $projectID ); + public function removeProject( $projectID ) + { + $removeProject = new RemoveProject( $projectID ); - if ( $removeProject->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); + if ( $removeProject->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); - Project::removeProject( $projectID ); + Project::removeProject( $projectID ); - $this->json( ['result' => TRUE] ); - } + $this->json( ['result' => TRUE] ); + } } diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index e87d4c8..1f29f1e 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -16,7 +16,7 @@ class MY_Controller extends CI_Controller { { parent::__construct(); - $this->version = '1.00.06'; + $this->version = '1.00.10'; $this->load->library( 'beheer/session/RetrieveUserSession' ); @@ -65,4 +65,4 @@ class MY_Controller extends CI_Controller { } -} \ No newline at end of file +} diff --git a/application/models/eloquent/Offer.php b/application/models/eloquent/Offer.php index 690b96d..87545f3 100644 --- a/application/models/eloquent/Offer.php +++ b/application/models/eloquent/Offer.php @@ -9,76 +9,90 @@ class Offer extends BaseModel { - protected $table = "offers"; + protected $table = "offers"; - public function payments() - { - return $this->hasMany( 'Payment' ); - } + public function payments() + { + return $this->hasMany( 'Payment' ); + } - public function project() - { - return $this->belongsTo( 'Project' ); - } + public function project() + { + return $this->belongsTo( 'Project' ); + } - public function customer() - { - return $this->belongsTo( 'Customer' ); - } + public function customer() + { + return $this->belongsTo( 'Customer' ); + } - public static function getAllOffers( $projectID, $archive = 'F', $search, $order, $direction ) - { - $offers = Offer::selectRAW('offers.*') - ->join('customers AS CUS', 'CUS.id', '=', 'offers.customer_id') - ->with( 'customer' ) - ->with( 'project' ) - ->where('offernumber', 'LIKE', "%{$search}%") - ->orderBy($order, $direction); + public static function getAllOffers( $projectID, $archive = 'F', $search, $order, $direction ) + { + $offers = Offer::selectRAW( 'offers.*' ) + ->join( 'customers AS CUS', 'CUS.id', '=', 'offers.customer_id' ) + ->with( 'customer' ) + ->with( 'project' ) + ->where( 'offernumber', 'LIKE', "%{$search}%" ) + ->orderBy( $order, $direction ); - if ( $projectID ) $offers = $offers->whereProjectId( $projectID ); + if ( $projectID ) $offers = $offers->whereProjectId( $projectID ); - if ( $archive == 'F' ) $offers = $offers->where( 'offers.archive', '=', 'F' ); + if ( $archive == 'F' ) $offers = $offers->where( 'offers.archive', '=', 'F' ); - $offers = $offers->get(); + $offers = $offers->get(); - return $offers; - } + return $offers; + } - public static function getOffersWithoutProject( ) - { - $offersWithoutProject = Offer::orderBy('startdate') + public static function getOffersWithoutProject() + { + $offersWithoutProject = Offer::orderBy( 'startdate' ) // ->whereNull('rejectdate') // ->whereNull('project_id') - ->whereArchive('F') - ->get(); + ->whereArchive( 'F' ) + ->get(); - return $offersWithoutProject; - } + return $offersWithoutProject; + } - public static function saveOffer( $offerID, $offer ) - { - $offer = (array) $offer; + public static function saveOffer( $offerID, $offer ) + { + $offer = (array) $offer; - $offer['startdate'] = date2mysql( $offer['startdate'] ); - $offer['accepteddate'] = date2mysql( $offer['accepteddate'] ); - $offer['rejectdate'] = date2mysql( $offer['rejectdate'] ); + $offer['startdate'] = date2mysql( $offer['startdate'] ); + $offer['accepteddate'] = date2mysql( $offer['accepteddate'] ); + $offer['rejectdate'] = date2mysql( $offer['rejectdate'] ); - if ( $offerID == 0 ) - { - $offer = Offer::create( $offer ); + if ( $offerID == 0 ) + { + $offer = Offer::create( $offer ); - $offerID = $offer['id']; - } - else - { - Offer::whereId( $offerID )->update( $offer ); - } + $offerID = $offer['id']; + } + else + { + Offer::whereId( $offerID )->update( $offer ); - return $offerID; - } + $offer = self::find( $offerID ); - public static function removeOffer( $offerID ) - { - Offer::whereId( $offerID )->delete(); - } -} \ No newline at end of file + if ( ! is_null( $offer->project_id ) ) Project::syncOffername( $offer ); + } + + return $offerID; + } + + public static function syncProjectname( $projectID ) + { + $project = Project::find( $projectID ); + + $offer = self::find( $projectID ); + + $offer->offername = $project->projectname; + $offer->save(); + } + + public static function removeOffer( $offerID ) + { + Offer::whereId( $offerID )->delete(); + } +} diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index 2c075cd..7736d28 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -9,169 +9,174 @@ class Project extends BaseModel { - protected $table = "projects"; + protected $table = "projects"; - public function offers() - { - return $this->hasMany( 'Offer' ); - } + public function offers() + { + return $this->hasMany( 'Offer' ); + } - public function offer() - { - return $this->hasOne( 'Offer' ); - } + public function offer() + { + return $this->hasOne( 'Offer' ); + } - public function projectemployees() - { - return $this->hasMany( 'Projectemployee' ); - } + public function projectemployees() + { + return $this->hasMany( 'Projectemployee' ); + } - public function projectcosts() - { - return $this->hasMany( 'Projectcost' ); - } + public function projectcosts() + { + return $this->hasMany( 'Projectcost' ); + } - public function invoices() - { - return $this->hasMany( 'Invoice' ); - } + public function invoices() + { + return $this->hasMany( 'Invoice' ); + } - public function forecasts() - { - return $this->hasMany( 'Forecast' ); - } + public function forecasts() + { + return $this->hasMany( 'Forecast' ); + } - public function reservations() - { - return $this->hasMany( 'Reservation' ); - } + public function reservations() + { + return $this->hasMany( 'Reservation' ); + } - public function vat() - { - return $this->belongsTo( 'Vat' ); - } + public function vat() + { + return $this->belongsTo( 'Vat' ); + } - public function projectleader() - { - return $this->belongsTo( 'User', 'projectleader_id' ); - } + public function projectleader() + { + return $this->belongsTo( 'User', 'projectleader_id' ); + } - public function customer() - { - return $this->belongsTo( 'Customer' ); - } + public function customer() + { + return $this->belongsTo( 'Customer' ); + } - public static function getAllProjects( $archive, $search, $order, $direction ) - { - $projects = Project::getBaseProject(); + public static function getAllProjects( $archive, $search, $order, $direction ) + { + $projects = Project::getBaseProject(); - $projects = $projects->selectRaw( 'projects.*' ) - ->join( 'customers AS CUS', 'CUS.id', '=', 'projects.customer_id' ) - ->join( 'users AS USR', 'USR.id', '=', 'projects.projectleader_id' ) - ->where( 'projects.projectnumber', 'LIKE', "%{$search}%" ) - ->orderBy( $order, $direction ); + $projects = $projects->selectRaw( 'projects.*' ) + ->join( 'customers AS CUS', 'CUS.id', '=', 'projects.customer_id' ) + ->join( 'users AS USR', 'USR.id', '=', 'projects.projectleader_id' ) + ->where( 'projects.projectnumber', 'LIKE', "%{$search}%" ) + ->orderBy( $order, $direction ); - if ( $archive == 'F' ) $projects = $projects->where( 'projects.archive', '=', 'F' ); + if ( $archive == 'F' ) $projects = $projects->where( 'projects.archive', '=', 'F' ); - $projects = $projects->get(); + $projects = $projects->get(); - return $projects; - } + return $projects; + } - public static function getProject( $projectID ) - { - $project = Project::getBaseProject(); + public static function getProject( $projectID ) + { + $project = Project::getBaseProject(); - $project = $project->whereArchive( 'F' ) - ->whereId( $projectID ) - ->first(); + $project = $project->whereArchive( 'F' ) + ->whereId( $projectID ) + ->first(); - return $project; - } + return $project; + } - public static function removeProject( $projectID ) - { - Offer::whereProjectId( $projectID )->update( ['project_id' => NULL] ); + public static function removeProject( $projectID ) + { + Offer::whereProjectId( $projectID )->update( ['project_id' => NULL] ); - Project::whereId( $projectID )->delete(); - } + Project::whereId( $projectID )->delete(); + } - public static function getActiveProjects($archive = 'T') - { - $projects = Project::selectRaw( "projects.id, YEAR(projects.startdate) AS instroom, YEAR(projects.enddate) AS uitstroom, projectnumber, current_financial_year, + public static function getActiveProjects( $archive = 'T' ) + { + $projects = Project::selectRaw( "projects.id, YEAR(projects.startdate) AS instroom, YEAR(projects.enddate) AS uitstroom, projectnumber, current_financial_year, projectname, CUS.name, OFF.own_revenue, OFF.other_revenue" ) - ->join( 'customers AS CUS', 'CUS.id', '=', 'projects.customer_id' ) - ->join( 'offers AS OFF', 'OFF.project_id', '=', 'projects.id' ) - ->groupBy( 'projects.id' ) - ->groupBy( 'OFF.own_revenue' ) - ->groupBy( 'OFF.other_revenue' ); + ->join( 'customers AS CUS', 'CUS.id', '=', 'projects.customer_id' ) + ->join( 'offers AS OFF', 'OFF.project_id', '=', 'projects.id' ) + ->groupBy( 'projects.id' ) + ->groupBy( 'OFF.own_revenue' ) + ->groupBy( 'OFF.other_revenue' ); - if( $archive == 'F') $projects = $projects->where('projects.archive', '=', 'F'); + if ( $archive == 'F' ) $projects = $projects->where( 'projects.archive', '=', 'F' ); - $projects = $projects->get(); + $projects = $projects->get(); - return $projects; - } + return $projects; + } - public static function getProjectsForReport( $orderType, $orderDirection, $archive = 'F' ) - { - $projects = self::getBaseProject(); + public static function getProjectsForReport( $orderType, $orderDirection, $archive = 'F' ) + { + $projects = self::getBaseProject(); - if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' ); + if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' ); - $projects = $projects->orderBy( $orderType, $orderDirection )->get(); + $projects = $projects->orderBy( $orderType, $orderDirection )->get(); - return $projects; - } + return $projects; + } - public static function getBaseProject() - { - $project = Project::with( [ - 'projectleader' => function ( $q ) { - $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); - }] ) - ->with( 'offer' ) - ->with( [ - 'projectemployees.user' => function ( $q ) { - $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); - }] ) - ->with( 'vat' ) - ->with( ['forecasts'] ) - ->with( ['reservations'] ) - ->with( 'projectemployees.projecthours' ) - ->with( 'projectcosts.external' ) - ->with( 'invoices.payments' ) - ->with( 'invoices.vat' ) - ->with( 'vat' ) - ->with( 'customer' ); + public static function getBaseProject() + { + $project = Project::with( [ + 'projectleader' => function ( $q ) { + $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); + }] ) + ->with( 'offer' ) + ->with( [ + 'projectemployees.user' => function ( $q ) { + $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); + }] ) + ->with( 'vat' ) + ->with( ['forecasts'] ) + ->with( ['reservations'] ) + ->with( 'projectemployees.projecthours' ) + ->with( 'projectcosts.external' ) + ->with( 'invoices.payments' ) + ->with( 'invoices.vat' ) + ->with( 'vat' ) + ->with( 'customer' ); - return $project; - } + return $project; + } - public static function createProject() - { - $data = ['startdate' => date( 'Y-m-d' )]; + public static function createProject() + { + $data = ['startdate' => date( 'Y-m-d' )]; - $project = Project::create( $data ); + $project = Project::create( $data ); - return $project->id; - } + return $project->id; + } - public static function saveProject( $projectID, $project ) - { - $project = (array) $project; + public static function saveProject( $projectID, $project ) + { + $project = (array) $project; - if ( $projectID == 0 ) - { - $project = Project::create( $project ); - $projectID = $project['id'];; - } - else - { - Project::whereId( $projectID )->update( $project ); - } + if ( $projectID == 0 ) + { + $project = Project::create( $project ); + $projectID = $project['id'];; + } + else + { + Project::whereId( $projectID )->update( $project ); + } - return $projectID; + return $projectID; + } - } -} \ No newline at end of file + public static function syncOffername( $offer ) + { + self::whereId( $offer->project_id ) + ->update( ['projectname' => $offer->offername] ); + } +} diff --git a/application/models/eloquent/User.php b/application/models/eloquent/User.php index 51a4714..b2edf96 100644 --- a/application/models/eloquent/User.php +++ b/application/models/eloquent/User.php @@ -9,117 +9,130 @@ class User extends BaseModel { - protected $table = "users"; + protected $table = "users"; - public function projectemployees() - { - return $this->hasMany( 'Projectemployee' ); - } + public function projectemployees() + { + return $this->hasMany( 'Projectemployee' ); + } - public function employeetargets() - { - return $this->hasMany( 'Employeetarget' ); - } + public function employeetargets() + { + return $this->hasMany( 'Employeetarget' ); + } - public function projectemployee() - { - return $this->hasOne( 'Projectemployee' ); - } + public function projectemployee() + { + return $this->hasOne( 'Projectemployee' ); + } - public function role() - { - return $this->belongsTo( 'Role', 'level', 'rolelevel' ); - } + public function role() + { + return $this->belongsTo( 'Role', 'level', 'rolelevel' ); + } - public static function getAllUsers( $archive ) - { - $users = User::selectRaw( "*, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) - ->orderBy( 'lastname' ); + public static function getAllUsers( $archive ) + { + $users = User::selectRaw( "*, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) + ->orderBy( 'lastname' ); - if ( $archive == 'F' ) $users = $users->whereArchive( 'F' ); + if ( $archive == 'F' ) $users = $users->whereArchive( 'F' ); - $users = $users->get(); + $users = $users->get(); - return $users; - } + return $users; + } - public static function getUserRoleHierarchy() - { - $userrole = User::find( USERID )->role; + public static function getUserRoleHierarchy() + { + $userrole = User::find( USERID )->role; - return $userrole; - } + return $userrole; + } - public static function getUserWithprojects() - { - $usersWithProjects = - User::selectRaw( "users.id, CONCAT(users.firstname, ' ', users.middlename, ' ', users.lastname) AS fullname" ) - ->with( [ - 'projectemployees.project' => function ( $q ) { - $q->whereArchive( 'F' ); - }] ) - ->get(); + public static function getUserWithprojects() + { + $usersWithProjects = + User::selectRaw( "users.id, CONCAT(users.firstname, ' ', users.middlename, ' ', users.lastname) AS fullname" ) + ->with( [ + 'projectemployees.project' => function ( $q ) { + $q->whereArchive( 'F' ); + }] ) + ->get(); - return $usersWithProjects; - } + return $usersWithProjects; + } - public static function checkUsername( $username ) - { - $username = strtoupper( $username ); + public static function getUserActiveProjects( $userID ) + { + $usersActiveProjects = + User::selectRaw( "PRJ.id AS projectID, projectname, projectnumber, CONCAT(projectnumber, '-', projectname) AS projectFull" ) + ->join( 'projectemployees AS PRE', 'PRE.user_id', '=', 'users.id' ) + ->join( 'projects AS PRJ', 'PRJ.id', '=', 'PRE.project_id' ) + ->where( 'PRJ.archive', '=', 'F' ) + ->where( 'users.id', '=', $userID ) + ->get(); - $user = User::whereRaw( "UCASE(username) = {$username}" ); + return $usersActiveProjects; + } - if ( $user->count() == 0 ) return FALSE; + public static function checkUsername( $username ) + { + $username = strtoupper( $username ); - return TRUE; - } + $user = User::whereRaw( "UCASE(username) = {$username}" ); - public static function saveUser( $userID, $user ) - { - $user = (array) $user; + if ( $user->count() == 0 ) return FALSE; - if ( $userID == 0 ) - { - $user = User::create( $user ); - $userID = $user['id']; - } - else - { - User::whereId( $userID )->update( $user ); - } + return TRUE; + } - return $userID; - } + public static function saveUser( $userID, $user ) + { + $user = (array) $user; - public static function removeUser( $userID ) - { - User::whereId( $userID )->delete(); - } + if ( $userID == 0 ) + { + $user = User::create( $user ); + $userID = $user['id']; + } + else + { + User::whereId( $userID )->update( $user ); + } - public static function getUniqueProjectUsers() - { - //TODO: date range - $projectusers = User::selectRaw( " + return $userID; + } + + public static function removeUser( $userID ) + { + User::whereId( $userID )->delete(); + } + + public static function getUniqueProjectUsers() + { + //TODO: date range + $projectusers = User::selectRaw( " users.id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname, SUBSTR(MD5(users.id), 1, 6) AS slug" ) - ->join( 'projectemployees AS PEM', 'PEM.user_id', '=', 'users.id' ) - ->with( [ - 'projectemployee.project' => function ( $q ) { - $q->selectRaw( "id, YEAR(startdate) AS instroom, COALESCE(YEAR(enddate), '') AS uitstroom" ); - }] ) - ->distinct() - ->get(); + ->join( 'projectemployees AS PEM', 'PEM.user_id', '=', 'users.id' ) + ->with( [ + 'projectemployee.project' => function ( $q ) { + $q->selectRaw( "id, YEAR(startdate) AS instroom, COALESCE(YEAR(enddate), '') AS uitstroom" ); + }] ) + ->distinct() + ->get(); - return $projectusers; - } + return $projectusers; + } - public static function getSaltedPassword( $password, $salt ) - { - $saltedpassword = sha1( sha1( $password ) . $salt ); + public static function getSaltedPassword( $password, $salt ) + { + $saltedpassword = sha1( sha1( $password ) . $salt ); - return $saltedpassword; - } + return $saltedpassword; + } -} \ No newline at end of file +} diff --git a/application/models/eloquent/queries/ReservationTotals.php b/application/models/eloquent/queries/ReservationTotals.php index db6c03d..3331003 100644 --- a/application/models/eloquent/queries/ReservationTotals.php +++ b/application/models/eloquent/queries/ReservationTotals.php @@ -16,10 +16,10 @@ class ReservationTotals { Q5.costs, reservation, payed, (reservation - fromreservation) AS saldo, (Q5.costs - payed) AS saldoToPay, PRJ.projectnumber, EXT.contactperson, ROUND(( (OFF.costs * (100 + (SELECT vatrate - FROM vats VTS - JOIN projects P - ON VTS.id = P.vat_id - WHERE P.id = PRJ.id LIMIT 1))) / 100 ), 0) other_revenue + FROM vats VTS + JOIN projects P + ON VTS.id = P.vat_id + WHERE P.id = PRJ.id LIMIT 1))) / 100 ), 0) other_revenue FROM ( SELECT COALESCE(reservation, 0) AS reservation, costs, payed, Q2.external_id, Q2.project_id, IF(from_reservation = 'T', payed, 0) fromreservation diff --git a/application/views/modals/partials/_reservations.php b/application/views/modals/partials/_reservations.php index 67b3c16..a1a923c 100644 --- a/application/views/modals/partials/_reservations.php +++ b/application/views/modals/partials/_reservations.php @@ -1,7 +1,7 @@

- Reserveringen (incl. btw) + budget onderaannemers (incl. btw)

@@ -59,4 +59,4 @@
-
\ No newline at end of file + diff --git a/application/views/pages/employeehours_view.php b/application/views/pages/employeehours_view.php index ae97e9a..e0ddee6 100644 --- a/application/views/pages/employeehours_view.php +++ b/application/views/pages/employeehours_view.php @@ -28,87 +28,61 @@ - - - - - - + + + + + - - - - - @@ -125,4 +99,4 @@ -
medewerkerdatumsoort urenprojecturen datumsoort urenprojecturen 
- - - - + - - + + - - - - - uur - - + + data-bind="textInput:hours, + enable:canFillInHours, + event:{keyup:$root.saveDelayedEmployeehours, + change: $root.saveDelayedEmployeehours}"/> - + +
\ No newline at end of file + diff --git a/application/views/pages/offers_view.php b/application/views/pages/offers_view.php index c5c1c58..1809be4 100644 --- a/application/views/pages/offers_view.php +++ b/application/views/pages/offers_view.php @@ -54,7 +54,7 @@ % - € + € @@ -78,6 +78,19 @@ + + + Totaal + + + € + +   + + € + +   +