From 00246f49f78447e00c9ba921ce4cebe7c499e57e Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Tue, 16 Jan 2018 13:36:59 +0100 Subject: [PATCH] project --- .../libraries/projects/RemoveProject.php | 43 ++++++++++++++ application/models/eloquent/Offer.php | 9 ++- application/models/eloquent/Payment.php | 18 ++++++ application/models/eloquent/Project.php | 15 ++++- application/views/modals/project_modal.php | 53 +++++++++++++----- application/views/pages/projects_view.php | 22 +++----- public/css/correction.css | 16 ++++++ public/css/main.css | 39 ++++++++++++- public/js/lib/modules/modals/projectModal.js | 18 +++++- .../js/lib/modules/projects/projectsModule.js | 56 ++++++++++++++++--- 10 files changed, 248 insertions(+), 41 deletions(-) create mode 100644 application/libraries/projects/RemoveProject.php create mode 100644 application/models/eloquent/Payment.php diff --git a/application/libraries/projects/RemoveProject.php b/application/libraries/projects/RemoveProject.php new file mode 100644 index 0000000..d0cc42a --- /dev/null +++ b/application/libraries/projects/RemoveProject.php @@ -0,0 +1,43 @@ +setProjectID( $projectID ); + + $this->handle(); + } + + public function getAllowDelete() + { + return $this->allowDelete; + } + + private function setProjectID( $customerID ) + { + $this->offerID = $customerID; + } + + private function handle() + { + $this->checkForOffers(); + } + + private function checkForOffers() + { + $offers = Offer::whereProjectId($this->setProjectID); + + if( $offers->count > 0 ) $this->allowDelete = FALSE; + } + +} \ No newline at end of file diff --git a/application/models/eloquent/Offer.php b/application/models/eloquent/Offer.php index c59fe4f..6253e90 100644 --- a/application/models/eloquent/Offer.php +++ b/application/models/eloquent/Offer.php @@ -11,6 +11,11 @@ class Offer extends BaseModel { protected $table = "offers"; + public function payments() + { + return $this->hasMany( 'Payment' ); + } + public function project() { return $this->belongsTo( 'Project' ); @@ -23,7 +28,7 @@ class Offer extends BaseModel { public static function getAllOffers( $archive = 'F' ) { - $offers = Offer::orderBy('startdate') + $offers = Offer::orderBy( 'startdate' ) ->with( 'customer' ) ->with( 'project' ); @@ -56,6 +61,6 @@ class Offer extends BaseModel { public static function removeOffer( $offerID ) { - Offer::whereId($offerID)->delete(); + Offer::whereId( $offerID )->delete(); } } \ No newline at end of file diff --git a/application/models/eloquent/Payment.php b/application/models/eloquent/Payment.php new file mode 100644 index 0000000..6673ab3 --- /dev/null +++ b/application/models/eloquent/Payment.php @@ -0,0 +1,18 @@ +belongsTo( 'Offer' ); + } + +} \ No newline at end of file diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index e8cd56c..f10c159 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -32,12 +32,25 @@ class Project extends BaseModel { 'projectleader' => function ( $q ) { $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); }] ) + ->with( [ + 'offers' => function ( $q ) { + $q->whereArchive( 'F' ) + ->with( [ + 'payment' => function ( $q ) { + $q->selectRaw( '*' ); + }] ); + }] ) ->with( 'customer' ); - if($archive == 'F') $projects = $projects->whereArchive('F'); + if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' ); $projects = $projects->get(); return $projects; } + + public static function removeProject( $projectID ) + { + Project::whereId($projectID)->delete(); + } } \ No newline at end of file diff --git a/application/views/modals/project_modal.php b/application/views/modals/project_modal.php index 2b3eeeb..e410f17 100644 --- a/application/views/modals/project_modal.php +++ b/application/views/modals/project_modal.php @@ -1,20 +1,45 @@ -