diff --git a/application/controllers/projects/OffersController.php b/application/controllers/projects/OffersController.php
index c357c5e..22883ef 100644
--- a/application/controllers/projects/OffersController.php
+++ b/application/controllers/projects/OffersController.php
@@ -27,9 +27,9 @@ class OffersController extends MY_Controller {
}
- public function getAllOffers( $archive = 'F' )
+ public function getAllOffers( $projectID, $archive = 'F' )
{
- $offers = Offer::getAllOffers( $archive );
+ $offers = Offer::getAllOffers( $projectID, $archive );
$this->json( $offers );
}
diff --git a/application/controllers/projects/ProjectsController.php b/application/controllers/projects/ProjectsController.php
index d51e92b..1bef08f 100644
--- a/application/controllers/projects/ProjectsController.php
+++ b/application/controllers/projects/ProjectsController.php
@@ -29,11 +29,30 @@ class ProjectsController extends MY_Controller {
public function getAllProjects( $archive = 'F' )
{
- $projects = Project::getAllProjects( $archive );
+ $projects = Project::getAllProjects( FALSE, $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();
diff --git a/application/libraries/projects/RemoveProject.php b/application/libraries/projects/RemoveProject.php
index d0cc42a..409c125 100644
--- a/application/libraries/projects/RemoveProject.php
+++ b/application/libraries/projects/RemoveProject.php
@@ -8,7 +8,7 @@
class RemoveProject {
- private $offerID;
+ private $projectID;
private $allowDelete = TRUE;
public function __construct( $projectID )
@@ -23,9 +23,9 @@ class RemoveProject {
return $this->allowDelete;
}
- private function setProjectID( $customerID )
+ private function setProjectID( $projectID )
{
- $this->offerID = $customerID;
+ $this->projectID = $projectID;
}
private function handle()
@@ -35,9 +35,9 @@ class RemoveProject {
private function checkForOffers()
{
- $offers = Offer::whereProjectId($this->setProjectID);
+ $offers = Offer::whereProjectId($this->projectID);
- if( $offers->count > 0 ) $this->allowDelete = FALSE;
+ 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 6253e90..9946a34 100644
--- a/application/models/eloquent/Offer.php
+++ b/application/models/eloquent/Offer.php
@@ -26,12 +26,14 @@ class Offer extends BaseModel {
return $this->belongsTo( 'Customer' );
}
- public static function getAllOffers( $archive = 'F' )
+ public static function getAllOffers( $projectID, $archive = 'F' )
{
$offers = Offer::orderBy( 'startdate' )
->with( 'customer' )
->with( 'project' );
+ if ( $projectID ) $offers = $offers->whereProjectId( $projectID );
+
if ( $archive == 'F' ) $offers = $offers->whereArchive( 'F' );
$offers = $offers->get();
diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php
index f10c159..8ff774e 100644
--- a/application/models/eloquent/Project.php
+++ b/application/models/eloquent/Project.php
@@ -16,6 +16,11 @@ class Project extends BaseModel {
return $this->hasMany( 'Offer' );
}
+ public function projectemployees()
+ {
+ return $this->hasMany( 'Projectemployee' );
+ }
+
public function projectleader()
{
return $this->belongsTo( 'User', 'projectleader_id' );
@@ -28,7 +33,34 @@ class Project extends BaseModel {
public static function getAllProjects( $archive = 'F' )
{
- $projects = Project::with( [
+ $projects = Project::getBaseProject();
+
+ if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' );
+
+ $projects = $projects->get();
+
+ return $projects;
+ }
+
+ public static function getProject( $projectID )
+ {
+ $project = Project::getBaseProject();
+
+ $project = $project->whereArchive( 'F' )
+ ->whereId( $projectID )
+ ->first();
+
+ return $project;
+ }
+
+ public static function removeProject( $projectID )
+ {
+ Project::whereId( $projectID )->delete();
+ }
+
+ public static function getBaseProject()
+ {
+ $project = Project::with( [
'projectleader' => function ( $q ) {
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
}] )
@@ -40,17 +72,21 @@ class Project extends BaseModel {
$q->selectRaw( '*' );
}] );
}] )
+ ->with( [
+ 'projectemployees.user' => function ( $q ) {
+ $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
+ }] )
->with( 'customer' );
- if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' );
-
- $projects = $projects->get();
-
- return $projects;
+ return $project;
}
- public static function removeProject( $projectID )
+ public static function createProject()
{
- Project::whereId($projectID)->delete();
+ $data = ['startdate'=> date('Y-m-d')];
+
+ $project = Project::create($data);
+
+ return $project->id;
}
}
\ No newline at end of file
diff --git a/application/models/eloquent/Projectemployee.php b/application/models/eloquent/Projectemployee.php
new file mode 100644
index 0000000..e868b81
--- /dev/null
+++ b/application/models/eloquent/Projectemployee.php
@@ -0,0 +1,30 @@
+belongsTo( 'Project' );
+ }
+
+ public function user()
+ {
+ return $this->belongsTo( 'User' );
+ }
+
+ public static function createProjectEmployee( $projectID )
+ {
+ $projectemployee = Projectemployee::create( [
+ 'project_id' => $projectID
+ ] );
+
+ return $projectemployee->id;
+ }
+
+}
\ No newline at end of file
diff --git a/application/views/modals/partials/_projectemployees.php b/application/views/modals/partials/_projectemployees.php
new file mode 100644
index 0000000..f1897e7
--- /dev/null
+++ b/application/views/modals/partials/_projectemployees.php
@@ -0,0 +1,63 @@
+
+
+
+
+ project medewerkers
+
+
+
+
+
+
+ naam
+
+
+ tarief
+
+
+ budget
+
+
+ start
+
+
+ eind
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uur
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/modals/partials/_projectoffers.php b/application/views/modals/partials/_projectoffers.php
new file mode 100644
index 0000000..9092cf0
--- /dev/null
+++ b/application/views/modals/partials/_projectoffers.php
@@ -0,0 +1,49 @@
+
+
+
+ offertes
+
+
+
+
+
+
+ nummer
+
+
+ start
+
+
+ eigen omzet
+
+
+ overig omzet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/modals/project_modal.php b/application/views/modals/project_modal.php
index e410f17..95e6893 100644
--- a/application/views/modals/project_modal.php
+++ b/application/views/modals/project_modal.php
@@ -1,44 +1,77 @@
-