diff --git a/application/controllers/projects/EmployeeHoursController.php b/application/controllers/projects/EmployeeHoursController.php index 8115590..6424515 100644 --- a/application/controllers/projects/EmployeeHoursController.php +++ b/application/controllers/projects/EmployeeHoursController.php @@ -70,6 +70,7 @@ class EmployeeHoursController extends MY_Controller { } elseif ( $hourType == 'OFFERS' ) { + $data['projectemployee_id'] = $data['employee_id']; unset( $data['employee_id'] ); $data['hourtype_id'] = $data['hourtype_id'] - 8; diff --git a/application/controllers/projects/ProjectsController.php b/application/controllers/projects/ProjectsController.php index 701288e..13b4a70 100644 --- a/application/controllers/projects/ProjectsController.php +++ b/application/controllers/projects/ProjectsController.php @@ -27,14 +27,14 @@ class ProjectsController extends MY_Controller { } - public function getAllProjects( ) + 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 ); } @@ -46,6 +46,9 @@ class ProjectsController extends MY_Controller { $project->invoiceDetails = $this->Invoices_model->getOutstandingPerProject( $project->id ); + $project->hourTotals = + Projecthour::getTotalHoursPerProject( $project->id ); + $this->json( $project ); } diff --git a/application/controllers/reports/ReportsController.php b/application/controllers/reports/ReportsController.php index 925ca3a..1d9df08 100644 --- a/application/controllers/reports/ReportsController.php +++ b/application/controllers/reports/ReportsController.php @@ -27,9 +27,9 @@ class ReportsController extends MY_Controller { } - public function recapProjects() + public function recapProjects( $archive ) { - $recapprojects = new Recapprojects(); + $recapprojects = new Recapprojects( $archive ); $projects = $recapprojects->getProjects(); @@ -51,17 +51,17 @@ class ReportsController extends MY_Controller { $result = $query->result(); - foreach($result as $user) + foreach ( $result as $user ) { - $user->targethours = Employeetarget::getTargetHoursPerEmployee( $user->user_id, $year, $month); + $user->targethours = Employeetarget::getTargetHoursPerEmployee( $user->user_id, $year, $month ); } $this->json( $result ); } - public function getInvoiceOverview( $year = FALSE ) + public function getInvoiceOverview( $year = FALSE, $orderType, $orderDirection, $archive ) { - $invoices = new Invoices( $year ); + $invoices = new Invoices( $year, $orderType, $orderDirection, $archive ); $invoiceReport = $invoices->getInvoiceReport(); @@ -74,7 +74,7 @@ class ReportsController extends MY_Controller { $invoiceReport = $invoices->getInvoiceReport(); - new InvoiceSpreadsheet($invoiceReport); + new InvoiceSpreadsheet( $invoiceReport ); } public function saveCurrentFinnacialYear( $projectID ) diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index b3712b6..ff64b6d 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.00'; + $this->version = '1.00.01'; $this->load->library( 'beheer/session/RetrieveUserSession' ); diff --git a/application/libraries/reports/Recapprojects.php b/application/libraries/reports/Recapprojects.php index f02e711..92f6217 100644 --- a/application/libraries/reports/Recapprojects.php +++ b/application/libraries/reports/Recapprojects.php @@ -10,6 +10,7 @@ class Recapprojects { private $ci; private $index; + private $archive; private $project; private $projects; private $employeeHours; @@ -22,10 +23,12 @@ class Recapprojects { private $projectEmployeeDetail; private $projectEmployeeDetails; - public function __construct() + public function __construct( $archive ) { $this->ci =& get_instance(); + $this->archive = $archive; + $this->ci->load->Model( 'projects/Invoices_model' ); $this->handle(); @@ -51,7 +54,7 @@ class Recapprojects { private function setProjects() { - $this->projects = Project::getActiveProjects()->toArray(); + $this->projects = Project::getActiveProjects( $this->archive )->toArray(); } private function setUniqueEmployees() @@ -222,8 +225,8 @@ class Recapprojects { $this->projects[ $this->index ]['projectcosts'] - $this->projects[ $this->index ]['totalInvoiced']; - if( $this->projects[ $this->index ]['workInProgress'] < 0 ) - $this->projects[ $this->index ]['workInProgress'] = 0; + if ( $this->projects[ $this->index ]['workInProgress'] < 0 ) + $this->projects[ $this->index ]['workInProgress'] = 0; } private function setCurrentFinancialYear() diff --git a/application/libraries/reports/invoice/InvoiceOverview.php b/application/libraries/reports/invoice/InvoiceOverview.php index af23524..cc7969e 100644 --- a/application/libraries/reports/invoice/InvoiceOverview.php +++ b/application/libraries/reports/invoice/InvoiceOverview.php @@ -19,6 +19,7 @@ class InvoiceOverview { private $invoicesTotal; private $needInvoice; private $projectDetails; + private $projectnumber; public function __construct( $project, $year ) { @@ -41,6 +42,8 @@ class InvoiceOverview { private function handle() { + $this->setProjectnumber(); + $this->setProjectname(); $this->setCustomer(); @@ -60,9 +63,14 @@ class InvoiceOverview { $this->setProjectDetails(); } + private function setProjectnumber() + { + $this->projectnumber = $this->project->projectnumber; + } + private function setProjectname() { - $this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')'; + $this->projectname = $this->project->projectname; } private function setCustomer() @@ -111,6 +119,7 @@ class InvoiceOverview { private function setProjectDetails() { $this->projectDetails = [ + 'projectnumber' => $this->projectnumber, 'projectname' => $this->projectname, 'customer' => $this->customer, 'totalToInvoicingExcl' => number_format( $this->totalToInvoicingExcl, 0, ',', '.' ), diff --git a/application/libraries/reports/invoice/Invoices.php b/application/libraries/reports/invoice/Invoices.php index dcbc909..c2884f1 100644 --- a/application/libraries/reports/invoice/Invoices.php +++ b/application/libraries/reports/invoice/Invoices.php @@ -20,10 +20,16 @@ class Invoices { private $invoiceForecasts; private $invoiceOverviews = []; private $invoiceReport = []; + private $orderType; + private $orderDirection; + private $archive; - public function __construct( $year ) + public function __construct( $year, $orderType, $orderDirection, $archive ) { $this->year = $year; + $this->orderType = $orderType; + $this->orderDirection = $orderDirection; + $this->archive = $archive; $this->handle(); } @@ -44,7 +50,8 @@ class Invoices { private function setProjects() { - $this->projects = Project::getProjectsForReport(); + $this->projects = + Project::getProjectsForReport( $this->orderType, $this->orderDirection, $this->archive ); } private function loopProjects() diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index 020f1c2..2c075cd 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -48,7 +48,7 @@ class Project extends BaseModel { public function vat() { - return $this->belongsTo('Vat'); + return $this->belongsTo( 'Vat' ); } public function projectleader() @@ -65,11 +65,11 @@ class Project extends BaseModel { { $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' ); @@ -96,7 +96,7 @@ class Project extends BaseModel { Project::whereId( $projectID )->delete(); } - public static function getActiveProjects() + 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" ) @@ -104,15 +104,22 @@ class Project extends BaseModel { ->join( 'offers AS OFF', 'OFF.project_id', '=', 'projects.id' ) ->groupBy( 'projects.id' ) ->groupBy( 'OFF.own_revenue' ) - ->groupBy( 'OFF.other_revenue' ) - ->get(); + ->groupBy( 'OFF.other_revenue' ); + + if( $archive == 'F') $projects = $projects->where('projects.archive', '=', 'F'); + + $projects = $projects->get(); return $projects; } - public static function getProjectsForReport() + public static function getProjectsForReport( $orderType, $orderDirection, $archive = 'F' ) { - $projects = self::getBaseProject()->get(); + $projects = self::getBaseProject(); + + if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' ); + + $projects = $projects->orderBy( $orderType, $orderDirection )->get(); return $projects; } @@ -128,9 +135,9 @@ class Project extends BaseModel { 'projectemployees.user' => function ( $q ) { $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); }] ) - ->with('vat') - ->with(['forecasts']) - ->with(['reservations']) + ->with( 'vat' ) + ->with( ['forecasts'] ) + ->with( ['reservations'] ) ->with( 'projectemployees.projecthours' ) ->with( 'projectcosts.external' ) ->with( 'invoices.payments' ) diff --git a/application/models/eloquent/Projecthour.php b/application/models/eloquent/Projecthour.php index 00d0b9b..25f3dad 100644 --- a/application/models/eloquent/Projecthour.php +++ b/application/models/eloquent/Projecthour.php @@ -27,7 +27,7 @@ class Projecthour extends BaseModel { public static function getMonthlyEmployeeHoursPerProject( $employeeID, $year ) { - $projectHours = ProjecthoursPerEmployeePerMonth::fire($employeeID, $year); + $projectHours = ProjecthoursPerEmployeePerMonth::fire( $employeeID, $year ); return $projectHours; } @@ -61,5 +61,21 @@ class Projecthour extends BaseModel { Projecthour::whereId( $projecthourID )->delete(); } + public static function getTotalHoursPerProject( $projectID ) + { + $totalProjecthours = + self::selectRaw( "CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname, + SUM(IF(hourtype_id = 1, hours, 0)) AS declarable, + SUM(IF(hourtype_id = 1, hours * tarif, 0)) AS revenues, + SUM(IF(hourtype_id != 1, hours, 0)) AS nondeclarable" ) + ->join( 'projectemployees AS PRE', 'PRE.id', '=', 'projecthours.projectemployee_id' ) + ->join( 'users AS USR', 'USR.id', '=', 'PRE.user_id' ) + ->groupBy( 'USR.id' ) + ->where( 'PRE.project_id', '=', $projectID ) + ->get(); + + return $totalProjecthours; + } + } \ No newline at end of file diff --git a/application/models/eloquent/queries/QEmployeeHours.php b/application/models/eloquent/queries/QEmployeeHours.php index 8603af3..69ea245 100644 --- a/application/models/eloquent/queries/QEmployeeHours.php +++ b/application/models/eloquent/queries/QEmployeeHours.php @@ -49,7 +49,21 @@ class QEmployeeHours { if( $month != 0 ) $sql .= "AND MONTH(hourdate) = '$month' "; $sql .= " GROUP BY PEM.user_id, MONTH(hourdate) + UNION + SELECT PH.projectemployee_id AS user_id, + MONTH(hourdate) monthID, + SUM(hours) AS projecthours, + 0 AS profitablehours, + SUM(IF(hourtype_id = 3, hours, 0)) AS nonprofitablehours, + 0 AS revenues, + 0 AS nonprojecthours + FROM projecthours PH + WHERE YEAR(hourdate) = '{$year}' "; + if( $month != 0 ) $sql .= "AND MONTH(hourdate) = '$month' "; + $sql .= " + GROUP BY PH.projectemployee_id, MONTH(hourdate) ) AS Q1 + JOIN users AS USR ON USR.id = Q1.user_id GROUP BY user_id "; diff --git a/application/views/modals/partials/_hourTotals.php b/application/views/modals/partials/_hourTotals.php new file mode 100644 index 0000000..4e4182f --- /dev/null +++ b/application/views/modals/partials/_hourTotals.php @@ -0,0 +1,57 @@ +
+
+

+ projecturen +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ medewerker + + niet declarabel + + declarabel + + omzet +
+ + + uur + + uur + + +
+ totaal + + uur + + uur + + +
+
+
\ No newline at end of file diff --git a/application/views/modals/project_modal.php b/application/views/modals/project_modal.php index ea56eac..fe0ccf9 100644 --- a/application/views/modals/project_modal.php +++ b/application/views/modals/project_modal.php @@ -65,7 +65,7 @@ load->view( 'modals/partials/_projectemployees' ); ?>
- load->view( 'modals/partials/_hours' ); ?> + load->view( 'modals/partials/_hourTotals' ); ?>
diff --git a/application/views/pages/invoicereport_view.php b/application/views/pages/invoicereport_view.php index a8e8c53..4633042 100644 --- a/application/views/pages/invoicereport_view.php +++ b/application/views/pages/invoicereport_view.php @@ -12,6 +12,24 @@ maak spreadsheet +
+
+ +
+
+ + +
+
+
+
diff --git a/application/views/pages/monthlyemployeehours_view.php b/application/views/pages/monthlyemployeehours_view.php index 9b75745..6d6be2b 100644 --- a/application/views/pages/monthlyemployeehours_view.php +++ b/application/views/pages/monthlyemployeehours_view.php @@ -8,6 +8,26 @@ +
+
+
+ +
+
+ + +
+
+
+
+