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 @@ -