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/controllers/reports/ReservationsController.php b/application/controllers/reports/ReservationsController.php index e2eaa6a..f2e8598 100644 --- a/application/controllers/reports/ReservationsController.php +++ b/application/controllers/reports/ReservationsController.php @@ -27,6 +27,7 @@ class ReservationsController extends MY_Controller { { $projects[ $result->projectID ] = [ 'projectnumber' => $result->projectnumber, + 'projectname' => $result->projectname, 'costs' => 0, 'reservation' => 0, 'payed' => 0, 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/Excel/InvoiceSpreadsheet.php b/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php index a06caba..2482df7 100644 --- a/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php +++ b/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php @@ -40,7 +40,9 @@ class InvoiceSpreadsheet { $this->setMonthForecast(); - $this->setMonthPayment(); + $this->setMonthPayment(); + + $this->setInvoiced(); $this->setFilename(); @@ -86,15 +88,25 @@ class InvoiceSpreadsheet { new MonthForecastSheet( $this->invoiceReport['monthForecasts'], $this->invoiceSheet ); } - private function setMonthPayment() - { - $invoiceSheet = new Worksheet( $this->spreadsheet, 'maand betalingen' ); + private function setMonthPayment() + { + $invoiceSheet = new Worksheet( $this->spreadsheet, 'maand betalingen' ); - $this->invoiceSheet = - $this->spreadsheet->addSheet( $invoiceSheet ); + $this->invoiceSheet = + $this->spreadsheet->addSheet( $invoiceSheet ); - new MonthPaymentSheet( $this->invoiceReport['monthPayments'], $this->invoiceSheet ); - } + new MonthPaymentSheet( $this->invoiceReport['monthPayments'], $this->invoiceSheet ); + } + + private function setInvoiced() + { + $invoiceSheet = new Worksheet( $this->spreadsheet, 'ontvangen facturen' ); + + $this->invoiceSheet = + $this->spreadsheet->addSheet( $invoiceSheet ); + + new InvoicedSheet( $this->invoiceReport['invoiced'], $this->invoiceSheet ); + } private function setFilename() { @@ -121,4 +133,4 @@ class InvoiceSpreadsheet { } -} \ No newline at end of file +} diff --git a/application/libraries/reports/invoice/Excel/InvoicedSheet.php b/application/libraries/reports/invoice/Excel/InvoicedSheet.php new file mode 100644 index 0000000..d0de687 --- /dev/null +++ b/application/libraries/reports/invoice/Excel/InvoicedSheet.php @@ -0,0 +1,67 @@ + 'factuurnummer', + 'B' => 'project', + 'C' => 'klant', + 'D' => 'factuurdatum', + 'E' => 'exc btw', + 'F' => 'btw', + 'G' => 'incl btw' + ]; + + private $invoiced; + private $sheet; + private $row; + + public function __construct( $invoiced, $sheet ) + { + $this->invoiced = $invoiced; + $this->sheet = $sheet; + + $this->handle(); + } + + private function handle() + { + $this->setHeader(); + + $this->setBody(); + } + + private function setHeader() + { + foreach ( self::HEADERS as $cell => $header ) + { + $this->sheet->setCellValue( $cell . '1', $header ); + $this->sheet->getColumnDimension( $cell )->setAutoSize( TRUE ); + } + } + + private function setBody() + { + $this->row = 2; + foreach ( $this->invoiced AS $invoice ) + { + $vat = ROUND($invoice->invoiceamount * 0.21, 2); + $this->sheet->setCellValue( 'A' . $this->row, $invoice->invoicenumber ); + $this->sheet->setCellValue( 'B' . $this->row, ($invoice->projectnumber . ' ' . $invoice['projectname'])); + $this->sheet->setCellValue( 'C' . $this->row, $invoice->name ); + $this->sheet->setCellValue( 'D' . $this->row, $invoice->invoicenumber ); + $this->sheet->setCellValue( 'E' . $this->row, $invoice->invoiceamount ); + $this->sheet->setCellValue( 'F' . $this->row, $vat ); + $this->sheet->setCellValue( 'G' . $this->row, $invoice->invoiceamount + $vat ); + + $this->row ++; + } + } + +} diff --git a/application/libraries/reports/invoice/Invoices.php b/application/libraries/reports/invoice/Invoices.php index c2884f1..bc5b56b 100644 --- a/application/libraries/reports/invoice/Invoices.php +++ b/application/libraries/reports/invoice/Invoices.php @@ -8,104 +8,126 @@ 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; + private $invoicedYears; + private $invoiced; - 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->setInvoicedyears(); - private function loopProjects() - { - foreach ( $this->projects as $this->project ) - { - $this->setInvoiceOverview(); + $this->setInvoiced(); - $this->setInvoiceForecasts(); + $this->setInvoiceReport(); + } - $this->setMonthForecasts(); + private function setProjects() + { + $this->projects = + Project::getProjectsForReport( $this->orderType, $this->orderDirection, $this->archive ); + } - $this->setMonthPayments(); - } - } + private function loopProjects() + { + foreach ( $this->projects as $this->project ) + { + $this->setInvoiceOverview(); - private function setInvoiceOverview() - { - $this->invoiceOverview = new InvoiceOverview( $this->project, $this->year ); + $this->setInvoiceForecasts(); - $this->invoiceOverviews[] = $this->invoiceOverview->getProjectDetails(); - } + $this->setMonthForecasts(); + } + } - private function setInvoiceForecasts() - { - $this->invoiceForecast = - new InvoiceForecast( $this->project, $this->invoiceOverview->getNeedinvoice(), $this->year ); + private function setInvoiceOverview() + { + $this->invoiceOverview = new InvoiceOverview( $this->project, $this->year ); - $this->invoiceForecasts[] = $this->invoiceForecast->getProjectDetails(); - } + $this->invoiceOverviews[] = $this->invoiceOverview->getProjectDetails(); + } - public function setMonthForecasts() - { - $this->monthForecast = - new MonthForecast( $this->invoiceForecast, $this->project, $this->year ); + private function setInvoiceForecasts() + { + $this->invoiceForecast = + new InvoiceForecast( $this->project, $this->invoiceOverview->getNeedinvoice(), $this->year ); - $this->monthForecasts[] = $this->monthForecast->getProjectDetails(); - } + $this->invoiceForecasts[] = $this->invoiceForecast->getProjectDetails(); + } - public function setMonthPayments() - { - $this->monthPayment = - new MonthPayments( $this->project, $this->year ); + public function setMonthForecasts() + { + $this->monthForecast = + new MonthForecast( $this->invoiceForecast, $this->project, $this->year ); - $this->monthPayments[] = $this->monthPayment->getProjectDetails(); - } + $this->monthForecasts[] = $this->monthForecast->getProjectDetails(); + } - private function setInvoiceReport() - { - $this->invoiceReport = [ - 'invoiceOverview' => $this->invoiceOverviews, - 'forecasts' => $this->invoiceForecasts, - 'monthForecasts' => $this->monthForecasts, - 'monthPayments' => $this->monthPayments - ]; - } -} \ No newline at end of file + public function setMonthPayments() + { + $monthPayment = new MonthPayments( + $this->year, $this->orderType, $this->orderDirection ); + + $this->monthPayments = $monthPayment->getProjectDetails(); + } + + private function setInvoiced() + { + $this->invoiced = Invoice::getInvoiced( $this->year ); + } + + private function setInvoicedYears() + { + $this->invoicedYears = Invoice::selectRaw( 'DATE_FORMAT(invoicedate, "%Y") AS years' ) + ->distinct() + ->orderBy( 'invoicedate' ) + ->lists( 'years' ); + } + + private function setInvoiceReport() + { + $this->invoiceReport = [ + 'invoiceOverview' => $this->invoiceOverviews, + 'forecasts' => $this->invoiceForecasts, + 'monthForecasts' => $this->monthForecasts, + 'monthPayments' => $this->monthPayments, + 'invoicedYears' => $this->invoicedYears, + 'invoiced' => $this->invoiced + ]; + } +} 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/Invoice.php b/application/models/eloquent/Invoice.php index 6430b1e..6a44250 100644 --- a/application/models/eloquent/Invoice.php +++ b/application/models/eloquent/Invoice.php @@ -62,4 +62,16 @@ class Invoice extends BaseModel { return $invoiceID; } -} \ No newline at end of file + + public static function getInvoiced( $year ) + { + $invoiced = Invoice::selectRaw('invoicenumber, PRJ.projectname, projectnumber, CUS.name, invoicedate, CUS.name, invoiceamount') + ->join('projects AS PRJ', 'PRJ.id', '=', 'invoices.project_id') + ->join('customers AS CUS', 'CUS.id', '=', 'PRJ.customer_id') + ->whereRaw("DATE_FORMAT(invoicedate, '%Y') = {$year}") + ->orderBy('invoicedate') + ->get(); + + return $invoiced; + } +} 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 6e24fca..4191a51 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/queries/QEmployeeHours.php b/application/models/eloquent/queries/QEmployeeHours.php index 3b45922..afd9d2a 100644 --- a/application/models/eloquent/queries/QEmployeeHours.php +++ b/application/models/eloquent/queries/QEmployeeHours.php @@ -77,4 +77,4 @@ class QEmployeeHours { } -} \ No newline at end of file +} diff --git a/application/models/eloquent/queries/QinvoiceMonthOverview.php b/application/models/eloquent/queries/QinvoiceMonthOverview.php index 1816b7d..fbeaa5e 100644 --- a/application/models/eloquent/queries/QinvoiceMonthOverview.php +++ b/application/models/eloquent/queries/QinvoiceMonthOverview.php @@ -10,7 +10,7 @@ class QinvoiceMonthOverview { public static function fire( $projectID, $year ) { - $sql = "SELECT MNT.id, + $sql = "SELECT MNT.id, month, COALESCE(forecastamount, 0) AS forecastamount, COALESCE(paymentamount, 0) AS paymentamount @@ -34,10 +34,10 @@ class QinvoiceMonthOverview { ) AS PAY ON MNT.id = PAY.month_id LEFT JOIN projects PRJ - GROUP BY MNT.id + GROUP BY MNT.id ORDER BY MNT.id "; return $sql; } -} \ No newline at end of file +} diff --git a/application/models/eloquent/queries/ReservationTotals.php b/application/models/eloquent/queries/ReservationTotals.php index 44f7002..d5b9edb 100644 --- a/application/models/eloquent/queries/ReservationTotals.php +++ b/application/models/eloquent/queries/ReservationTotals.php @@ -11,7 +11,8 @@ class ReservationTotals { public static function fire() { // UNION ALL wordt gebruikt voor een full outer join - $sql = " SELECT PRJ.id AS projectID, external_id AS externalID, + $sql = "SELECT PRJ.id AS projectID, external_id AS externalID, + PRJ.projectname, COALESCE(fromreservation, 0) AS fromreservation, COALESCE(Q5.costs, 0) AS costs, COALESCE(reservation, 0) AS reservation, COALESCE(payed, 0) AS payed, (COALESCE(reservation, 0) - COALESCE(fromreservation, 0)) AS saldo, 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 0026de9..4929d5e 100644 --- a/application/views/main_view.php +++ b/application/views/main_view.php @@ -9,7 +9,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
- - - + + + + + + + + + + + + +