From d0069061ba710d4850bd484e88b0892bc153060e Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Fri, 25 Oct 2019 16:47:46 +0200 Subject: [PATCH] Diverse wijzigingen nav word document --- .../controllers/beheer/UsersController.php | 17 +- .../controllers/reports/ReportsController.php | 7 +- .../libraries/reports/Recapprojects.php | 14 +- .../libraries/reports/invoice/Invoices.php | 163 +- .../reports/invoice/MonthPayments.php | 173 +- application/models/eloquent/Payment.php | 13 +- application/models/eloquent/Project.php | 8 +- .../models/eloquent/Projectemployee.php | 171 +- .../views/emails/requestpassword_email.php | 2 +- application/views/emails/welcome_email.php | 2 +- application/views/main_view.php | 2 +- .../views/modals/partials/_invoices.php | 18 +- .../views/modals/partials/_projectcosts.php | 16 +- .../views/modals/partials/_reservations.php | 8 +- application/views/pages/login/login_view.php | 2 +- application/views/pages/reservations_view.php | 2 +- .../monthlyemployeehours/euro_view.php | 70 +- .../monthlyemployeehours/hours_view.php | 52 +- public/css/main.css | 4 + .../js/lib/dataservices/reportsDataService.js | 54 +- public/js/lib/dataservices/userDataservice.js | 19 +- public/js/lib/modals/projectModal.js | 2205 +++++++++-------- .../js/lib/modules/reports/invoicereport.js | 401 +-- .../reports/monthlyEmployeeHoursModule.js | 808 +++--- 24 files changed, 2203 insertions(+), 2028 deletions(-) diff --git a/application/controllers/beheer/UsersController.php b/application/controllers/beheer/UsersController.php index 0b90fdc..b499a50 100644 --- a/application/controllers/beheer/UsersController.php +++ b/application/controllers/beheer/UsersController.php @@ -60,12 +60,19 @@ class usersController extends MY_Controller { $this->json( $userActiveProjects ); } - public function getUniqueprojectEmployees() - { - $projectEmployees = User::getUniqueProjectUsers(); + public function getUniqueprojectEmployees() + { + $projectEmployees = User::getUniqueProjectUsers(); - $this->json( $projectEmployees ); - } + $this->json( $projectEmployees ); + } + + public function getUniqueEmployeesWithActivity($archive) + { + $projectEmployees = Projectemployee::getUniqueEmployeesWithActivity($archive); + + $this->json( $projectEmployees ); + } public function saveUser() { diff --git a/application/controllers/reports/ReportsController.php b/application/controllers/reports/ReportsController.php index 96f245f..1dd5c0d 100644 --- a/application/controllers/reports/ReportsController.php +++ b/application/controllers/reports/ReportsController.php @@ -29,7 +29,10 @@ class ReportsController extends MY_Controller { public function recapProjects( $archive ) { - $recapprojects = new Recapprojects( $archive ); + $field = $this->input->post('field'); + $direction = $this->input->post('direction'); + + $recapprojects = new Recapprojects( $archive, $field, $direction ); $projects = $recapprojects->getProjects(); @@ -84,4 +87,4 @@ class ReportsController extends MY_Controller { Project::whereId( $projectID )->update( ['current_financial_year' => $amount] ); } -} \ No newline at end of file +} diff --git a/application/libraries/reports/Recapprojects.php b/application/libraries/reports/Recapprojects.php index 92f6217..f74f7cd 100644 --- a/application/libraries/reports/Recapprojects.php +++ b/application/libraries/reports/Recapprojects.php @@ -10,9 +10,11 @@ class Recapprojects { private $ci; private $index; + private $field; private $archive; private $project; private $projects; + private $direction; private $employeeHours; private $invoicedYears = []; private $projectTotals; @@ -23,11 +25,13 @@ class Recapprojects { private $projectEmployeeDetail; private $projectEmployeeDetails; - public function __construct( $archive ) + public function __construct( $archive, $field, $direction ) { $this->ci =& get_instance(); $this->archive = $archive; + $this->field = $field; + $this->direction = $direction; $this->ci->load->Model( 'projects/Invoices_model' ); @@ -54,12 +58,14 @@ class Recapprojects { private function setProjects() { - $this->projects = Project::getActiveProjects( $this->archive )->toArray(); + $this->projects = Project::getActiveProjects( + $this->archive, $this->field, $this->direction )->toArray(); } private function setUniqueEmployees() { - $this->uniqueEmployees = Projectemployee::getUniqueProjectEmployees(); + $this->uniqueEmployees = + Projectemployee::getUniqueEmployeesWithActivity(); } private function loopProjects() @@ -272,4 +278,4 @@ class Recapprojects { $this->index ++; } } -} \ No newline at end of file +} diff --git a/application/libraries/reports/invoice/Invoices.php b/application/libraries/reports/invoice/Invoices.php index c2884f1..c011455 100644 --- a/application/libraries/reports/invoice/Invoices.php +++ b/application/libraries/reports/invoice/Invoices.php @@ -8,104 +8,105 @@ class Invoices { - private $year; - private $project; - private $projects; - private $monthPayment; - private $monthPayments; - private $monthForecast; - private $monthForecasts; - private $invoiceOverview; - private $invoiceForecast; - private $invoiceForecasts; - private $invoiceOverviews = []; - private $invoiceReport = []; - private $orderType; - private $orderDirection; - private $archive; + private $year; + private $project; + private $projects; + private $monthPayment; + private $monthPayments; + private $monthForecast; + private $monthForecasts; + private $invoiceOverview; + private $invoiceForecast; + private $invoiceForecasts; + private $invoiceOverviews = []; + private $invoiceReport = []; + private $orderType; + private $orderDirection; + private $archive; - public function __construct( $year, $orderType, $orderDirection, $archive ) - { - $this->year = $year; - $this->orderType = $orderType; - $this->orderDirection = $orderDirection; - $this->archive = $archive; + public function __construct( $year, $orderType, $orderDirection, $archive ) + { + $this->year = $year; + $this->orderType = $orderType; + $this->orderDirection = $orderDirection; + $this->archive = $archive; - $this->handle(); - } + $this->handle(); + } - public function getInvoiceReport() - { - return $this->invoiceReport; - } + public function getInvoiceReport() + { + return $this->invoiceReport; + } - private function handle() - { - $this->setProjects(); + private function handle() + { + $this->setProjects(); - $this->loopProjects(); + $this->loopProjects(); - $this->setInvoiceReport(); - } + //only projects with payments also archived projects + $this->setMonthPayments(); - private function setProjects() - { - $this->projects = - Project::getProjectsForReport( $this->orderType, $this->orderDirection, $this->archive ); - } + $this->setInvoiceReport(); + } - private function loopProjects() - { - foreach ( $this->projects as $this->project ) - { - $this->setInvoiceOverview(); + private function setProjects() + { + $this->projects = + Project::getProjectsForReport( $this->orderType, $this->orderDirection, $this->archive ); + } - $this->setInvoiceForecasts(); + private function loopProjects() + { + foreach ( $this->projects as $this->project ) + { + $this->setInvoiceOverview(); - $this->setMonthForecasts(); + $this->setInvoiceForecasts(); - $this->setMonthPayments(); - } - } + $this->setMonthForecasts(); + } + } - private function setInvoiceOverview() - { - $this->invoiceOverview = new InvoiceOverview( $this->project, $this->year ); + private function setInvoiceOverview() + { + $this->invoiceOverview = new InvoiceOverview( $this->project, $this->year ); - $this->invoiceOverviews[] = $this->invoiceOverview->getProjectDetails(); - } + $this->invoiceOverviews[] = $this->invoiceOverview->getProjectDetails(); + } - private function setInvoiceForecasts() - { - $this->invoiceForecast = - new InvoiceForecast( $this->project, $this->invoiceOverview->getNeedinvoice(), $this->year ); + private function setInvoiceForecasts() + { + $this->invoiceForecast = + new InvoiceForecast( $this->project, $this->invoiceOverview->getNeedinvoice(), $this->year ); - $this->invoiceForecasts[] = $this->invoiceForecast->getProjectDetails(); - } + $this->invoiceForecasts[] = $this->invoiceForecast->getProjectDetails(); + } - public function setMonthForecasts() - { - $this->monthForecast = - new MonthForecast( $this->invoiceForecast, $this->project, $this->year ); + public function setMonthForecasts() + { + $this->monthForecast = + new MonthForecast( $this->invoiceForecast, $this->project, $this->year ); - $this->monthForecasts[] = $this->monthForecast->getProjectDetails(); - } + $this->monthForecasts[] = $this->monthForecast->getProjectDetails(); + } - public function setMonthPayments() - { - $this->monthPayment = - new MonthPayments( $this->project, $this->year ); + public function setMonthPayments() + { + $monthPayment = new MonthPayments( + $this->year, $this->orderType, $this->orderDirection ); - $this->monthPayments[] = $this->monthPayment->getProjectDetails(); - } + $this->monthPayments = $monthPayment->getProjectDetails(); + } - private function setInvoiceReport() - { - $this->invoiceReport = [ - 'invoiceOverview' => $this->invoiceOverviews, - 'forecasts' => $this->invoiceForecasts, - 'monthForecasts' => $this->monthForecasts, - 'monthPayments' => $this->monthPayments - ]; - } -} \ No newline at end of file + private function setInvoiceReport() + { + $this->invoiceReport = [ + 'invoiceOverview' => $this->invoiceOverviews, + 'forecasts' => $this->invoiceForecasts, + 'monthForecasts' => $this->monthForecasts, + 'monthPayments' => $this->monthPayments + ]; + } +} diff --git a/application/libraries/reports/invoice/MonthPayments.php b/application/libraries/reports/invoice/MonthPayments.php index 12eed37..cf301ee 100644 --- a/application/libraries/reports/invoice/MonthPayments.php +++ b/application/libraries/reports/invoice/MonthPayments.php @@ -8,96 +8,119 @@ class MonthPayments { - private $year; - private $project; - private $payment; - private $customer; - private $projectname; - private $monthPayments; - private $projectDetails; - private $totalProjectPayments; + private $year; + private $project; + private $payment; + private $customer; + private $projectname; + private $monthPayments; + private $projectDetails; + private $projectsWithPayments; + private $totalProjectPayments; + private $orderType; + private $orderDirection; - public function __construct( $project, $year ) - { - $this->project = $project; - $this->year = $year; + public function __construct( $year, $orderType, $orderDirection ) + { + $this->year = $year; + $this->orderType = $orderType; + $this->orderDirection = $orderDirection; - $this->handle(); - } + $this->handle(); + } - public function getProjectDetails() - { - return $this->projectDetails; - } + public function getProjectDetails() + { + return $this->projectDetails; + } - private function handle() - { - $this->setProjectname(); + private function handle() + { + $this->setProjectsWithPayments(); - $this->setCustomer(); + $this->loopProjectsWithPayments(); + } - $this->setInitialsMonthPayments(); + private function setProjectsWithPayments() + { + $projectsArray = Payment::getProjectsWithPayments( $this->year ); - $this->loopPayments(); + $this->projectsWithPayments = + Project::getProjectsForReport( + $this->orderType, $this->orderDirection, FALSE, $projectsArray ); + } - $this->setProjectDetails(); - } + private function loopProjectsWithPayments() + { + foreach ( $this->projectsWithPayments as $this->project ) + { + $this->setProjectname(); - private function setProjectname() - { - $this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')'; - } + $this->setCustomer(); - private function setCustomer() - { - $this->customer = $this->project->customer->name; - } + $this->setInitialsMonthPayments(); - private function setInitialsMonthPayments() - { - for ( $i = 1; $i <= 12; $i ++ ) - { - $this->monthPayments[ $i ] = ['paymentamount' => 0]; - } - } + $this->loopPayments(); - private function loopPayments() - { - foreach ( $this->project->invoices as $invoice ) - { - foreach($invoice->payments as $this->payment) - { - $this->setMonthPayments(); + $this->setProjectDetails(); + } + } - $this->setTotalProjectPayments(); - } - } - } + private function setProjectname() + { + $this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')'; + } - private function setMonthPayments() - { - $paymentYear = date( 'Y', strtotime( $this->payment->paymentdate ) ); - $paymentMonth = date( 'n', strtotime( $this->payment->paymentdate ) ); + private function setCustomer() + { + $this->customer = $this->project->customer->name; + } - if ( $paymentYear == $this->year ) - $this->monthPayments[ $paymentMonth ]['paymentamount'] += $this->payment->paymentamount; - } + private function setInitialsMonthPayments() + { + for ( $i = 1; $i <= 12; $i ++ ) + { + $this->monthPayments[ $i ] = ['paymentamount' => 0]; + } + } - private function setTotalProjectPayments() - { - $paymentYear = date( 'Y', strtotime( $this->payment->paymentdate ) ); + private function loopPayments() + { + foreach ( $this->project->invoices as $invoice ) + { + foreach ( $invoice->payments as $this->payment ) + { + $this->setMonthPayments(); - if ( $paymentYear == $this->year ) - $this->totalProjectPayments += $this->payment->paymentamount; - } + $this->setTotalProjectPayments(); + } + } + } - private function setProjectDetails() - { - $this->projectDetails = [ - 'projectname' => $this->projectname, - 'customer' => $this->customer, - 'monthPayments' => $this->monthPayments, - 'totalProjectPayments' => number_format( $this->totalProjectPayments, 0, ',', '.' ) - ]; - } -} \ No newline at end of file + private function setMonthPayments() + { + $paymentYear = date( 'Y', strtotime( $this->payment->paymentdate ) ); + $paymentMonth = date( 'n', strtotime( $this->payment->paymentdate ) ); + + if ( $paymentYear == $this->year ) + $this->monthPayments[ $paymentMonth ]['paymentamount'] += $this->payment->paymentamount; + } + + private function setTotalProjectPayments() + { + $paymentYear = date( 'Y', strtotime( $this->payment->paymentdate ) ); + + if ( $paymentYear == $this->year ) + $this->totalProjectPayments += $this->payment->paymentamount; + } + + private function setProjectDetails() + { + $this->projectDetails[] = [ + 'projectname' => $this->projectname, + 'customer' => $this->customer, + 'monthPayments' => $this->monthPayments, + 'totalProjectPayments' => number_format( $this->totalProjectPayments, 0, ',', '.' ) + ]; + } +} diff --git a/application/models/eloquent/Payment.php b/application/models/eloquent/Payment.php index d3ff460..fa6ac0b 100644 --- a/application/models/eloquent/Payment.php +++ b/application/models/eloquent/Payment.php @@ -28,6 +28,17 @@ class Payment extends BaseModel { return $projectPayment->payment; } + public static function getProjectsWithPayments($year) + { + $projects = self::selectRaw('INV.project_id') + ->distinct() + ->join('invoices AS INV', 'INV.id', '=', 'payments.invoice_id') + ->whereRaw('DATE_FORMAT(INV.invoicedate, "%Y") = "'. $year.'"') + ->lists('project_id'); + + return $projects->toArray(); + } + public static function savePayment( $paymentID, $payment ) { $payment = (array) $payment; @@ -50,4 +61,4 @@ class Payment extends BaseModel { Payment::whereId( $paymentID )->delete(); } -} \ No newline at end of file +} diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index 7736d28..54422af 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -96,7 +96,7 @@ class Project extends BaseModel { Project::whereId( $projectID )->delete(); } - public static function getActiveProjects( $archive = 'T' ) + public static function getActiveProjects( $archive = 'T', $sortField = FALSE, $direction = FALSE ) { $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" ) @@ -106,6 +106,8 @@ class Project extends BaseModel { ->groupBy( 'OFF.own_revenue' ) ->groupBy( 'OFF.other_revenue' ); + if ( $sortField ) $projects = $projects->orderBy( $sortField, $direction ); + if ( $archive == 'F' ) $projects = $projects->where( 'projects.archive', '=', 'F' ); $projects = $projects->get(); @@ -113,12 +115,14 @@ class Project extends BaseModel { return $projects; } - public static function getProjectsForReport( $orderType, $orderDirection, $archive = 'F' ) + public static function getProjectsForReport( $orderType, $orderDirection, $archive = 'F', $projectsArray = FALSE ) { $projects = self::getBaseProject(); if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' ); + if ( is_array( $projectsArray ) ) $projects = $projects->whereIn( 'id', $projectsArray ); + $projects = $projects->orderBy( $orderType, $orderDirection )->get(); return $projects; diff --git a/application/models/eloquent/Projectemployee.php b/application/models/eloquent/Projectemployee.php index d2d1579..4053cfc 100644 --- a/application/models/eloquent/Projectemployee.php +++ b/application/models/eloquent/Projectemployee.php @@ -8,94 +8,111 @@ class Projectemployee extends BaseModel { - public function project() - { - return $this->belongsTo( 'Project' ); + public function project() + { + return $this->belongsTo( 'Project' ); + } + + public function user() + { + return $this->belongsTo( 'User' ); + } + + public function projecthours() + { + return $this->hasMany( 'Projecthour' ); + } + + public static function getAvailableEmployees( $projectID ) + { + $currentEmployees = Self::whereProjectId( $projectID ) + ->lists( 'user_id' ); + + $availableEmployees = User::selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) + ->whereNotIn( 'id', $currentEmployees ) + ->whereArchive( 'F' ) + ->get(); + + return $availableEmployees; + } + + public static function getUniqueProjectEmployees() + { + $projectemployees = Projectemployee::selectRaw( "USR.id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) + ->distinct() + ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) + ->get(); + + return $projectemployees; + } + + public static function getUniqueEmployeesWithActivity( $archive = 'F' ) + { + $projectemployees = Projectemployee::selectRaw( "USR.id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) + ->distinct() + ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) + ->join( 'projectemployees AS PRE', 'PRE.user_id', '=', 'USR.id' ) + ->join( 'projects AS PRJ', 'PRJ.id', '=', 'PRE.project_id' ); + + if ( $archive == 'F' ) $projectemployees = $projectemployees->where( 'PRJ.archive', '=', 'F' ); + + $projectemployees = $projectemployees->get(); + + return $projectemployees; } - public function user() - { - return $this->belongsTo( 'User' ); - } + public static function getProjectemployeeDetailsPerProject( $projectID ) + { + $details = Projectemployee::selectRaw( 'USR.id, budget, project_id, ROUND(SUM(hours), 0) AS hours, ROUND(SUM(hours * tarif), 0) AS revenues, projectemployees.id AS projectemployeeID' ) + ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) + ->join( 'projecthours AS PRH', 'PRH.projectemployee_id', '=', 'projectemployees.id' ) + ->where( 'projectemployees.project_id', '=', $projectID ) + ->where( 'PRH.hourtype_id', '=', 1 ) + ->where( 'budget', '!=', 0 ) + ->groupBy( 'projectemployees.id' ) + ->havingRaw( 'ROUND(SUM(hours), 0) > 0' ) + ->get(); - public function projecthours() - { - return $this->hasMany( 'Projecthour' ); - } + return $details; + } - public static function getAvailableEmployees( $projectID ) - { - $currentEmployees = Self::whereProjectId( $projectID ) - ->lists( 'user_id' ); + public static function firstOrCreateProjectemployee( $userID, $projectID ) + { + $projectemployee = self::whereUserId( $userID )->whereProjectId( $projectID ); - $availableEmployees = User::selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) - ->whereNotIn( 'id', $currentEmployees ) - ->whereArchive( 'F' ) - ->get(); + if ( $projectemployee->count() > 0 ) return $projectemployee->first(); - return $availableEmployees; - } + $user = User::find( $userID ); - public static function getUniqueProjectEmployees() - { - $projectemployees = Projectemployee::selectRaw( "USR.id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) - ->distinct() - ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) - ->get(); + $tarif = $user ? $user->hourlyrate : 0; - return $projectemployees; - } + $projectemployee = Projectemployee::create( [ + 'project_id' => $projectID, + 'user_id' => $userID, + 'tarif' => $tarif + ] ); - public static function getProjectemployeeDetailsPerProject( $projectID ) - { - $details = Projectemployee::selectRaw( 'USR.id, budget, project_id, ROUND(SUM(hours), 0) AS hours, ROUND(SUM(hours * tarif), 0) AS revenues, projectemployees.id AS projectemployeeID' ) - ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) - ->join( 'projecthours AS PRH', 'PRH.projectemployee_id', '=', 'projectemployees.id' ) - ->where( 'projectemployees.project_id', '=', $projectID ) - ->where( 'PRH.hourtype_id', '=', 1 ) - ->groupBy( 'projectemployees.id' ) - ->get(); + return $projectemployee; + } - return $details; - } + public static function createProjectEmployee( $projectID ) + { + $projectemployee = Projectemployee::create( [ + 'project_id' => $projectID + ] ); - public static function firstOrCreateProjectemployee( $userID, $projectID ) - { - $projectemployee = self::whereUserId($userID)->whereProjectId($projectID); + return $projectemployee->id; + } - if( $projectemployee->count() > 0 ) return $projectemployee->first(); + public static function saveProjectemployee( $projectemployeeID, $projectemployee ) + { + Projectemployee::whereId( $projectemployeeID ) + ->update( $projectemployee ); + } - $user = User::find( $userID ); + public static function removeProjectemployee( $projectemployeeID ) + { + Projectemployee::whereId( $projectemployeeID )->delete(); + } - $tarif = $user ? $user->hourlyrate : 0; - - $projectemployee = Projectemployee::create( [ - 'project_id' => $projectID, - 'user_id' => $userID, - 'tarif' => $tarif - ] ); - - return $projectemployee; - } - - public static function createProjectEmployee( $projectID ) - { - $projectemployee = Projectemployee::create( [ - 'project_id' => $projectID - ] ); - - return $projectemployee->id; - } - - public static function saveProjectemployee( $projectemployeeID, $projectemployee ) - { - Projectemployee::whereId( $projectemployeeID ) - ->update( $projectemployee ); - } - - public static function removeProjectemployee( $projectemployeeID ) - { - Projectemployee::whereId( $projectemployeeID )->delete(); - } - -} \ No newline at end of file +} diff --git a/application/views/emails/requestpassword_email.php b/application/views/emails/requestpassword_email.php index f1d9ddb..a141a26 100644 --- a/application/views/emails/requestpassword_email.php +++ b/application/views/emails/requestpassword_email.php @@ -311,7 +311,7 @@ diff --git a/application/views/emails/welcome_email.php b/application/views/emails/welcome_email.php index 06471aa..4dd69e4 100644 --- a/application/views/emails/welcome_email.php +++ b/application/views/emails/welcome_email.php @@ -311,7 +311,7 @@
- Nieuw wachtwoord DBOIS De Beleidsonderzoeker + Nieuw wachtwoord DBOIS De Beleidsonderzoekers
diff --git a/application/views/main_view.php b/application/views/main_view.php index 7effca0..ae9d928 100644 --- a/application/views/main_view.php +++ b/application/views/main_view.php @@ -7,7 +7,7 @@ - ** De Beleidsonderzoeker ** + ** De Beleidsonderzoekers **load->view( 'partials/_css' ); ?> diff --git a/application/views/modals/partials/_invoices.php b/application/views/modals/partials/_invoices.php index 5ca8891..54b4516 100644 --- a/application/views/modals/partials/_invoices.php +++ b/application/views/modals/partials/_invoices.php @@ -169,11 +169,21 @@
- Wachtwoord De Beleidsonderzoeker + Wachtwoord De Beleidsonderzoekers
- - - + + + + + + + + + + + + +