From 10d991f4c738b6a4a89ff70b209b42e92b986e79 Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Fri, 31 Jan 2020 15:56:51 +0100 Subject: [PATCH] Diversen dashboard --- .../dashboard/DashboardController.php | 53 +++++++++++++++---- application/models/eloquent/Invoice.php | 2 +- application/views/pages/dashboard_view.php | 27 +++++++--- .../reports/invoices/invoices_report.php | 14 +++++ .../lib/modules/dashboard/dashboardModule.js | 6 +++ .../js/lib/modules/reports/invoicereport.js | 28 +++++++--- 6 files changed, 104 insertions(+), 26 deletions(-) diff --git a/application/controllers/dashboard/DashboardController.php b/application/controllers/dashboard/DashboardController.php index e3b768f..df734f2 100644 --- a/application/controllers/dashboard/DashboardController.php +++ b/application/controllers/dashboard/DashboardController.php @@ -42,23 +42,25 @@ class DashboardController extends MY_Controller { $available += $project['budgetAvailable']; } - $outstandings = $this->Invoices_model->getTotalsOutstandingPerProject(FALSE); + $outstandings = $this->Invoices_model->getTotalsOutstandingPerProject( FALSE ); $this->json( [ 'totalOwp' => round( $totalOwp, 0 ), - 'revenuesThisYear' => $this->getRevenuesThisYear(), + 'revenuesThisYear' => $this->getRevenuesThisYear(), 'currentFinancialYear' => round( $currentFinancialYear ), 'owpNextyear' => round( $totalOwp - $currentFinancialYear ), 'revenuesNextyear' => round( $currentFinancialYear / 0.4 ), 'totalRevenues' => round( $totalRevenues ), - 'outstandings' => $this->getInvoiceOverview(), - 'costsToPay' => $this->reservations() + 'outstandings' => $this->getInvoiceOverview(), + 'costsToPay' => $this->reservations(), + 'invoiced' => $this->getInvoiced(), + 'totalChance' => $this->getChanceRevenues() ] ); } private function getRevenuesThisYear() { - $year = date('Y'); + $year = date( 'Y' ); $sql = QEmployeeHours::fire( FALSE, $year ); $query = $this->db->query( $sql ); @@ -66,7 +68,7 @@ class DashboardController extends MY_Controller { $result = $query->result(); $totalRevenue = 0; - foreach($result as $revenue) + foreach ( $result as $revenue ) { $totalRevenue += $revenue->revenues; } @@ -74,13 +76,13 @@ class DashboardController extends MY_Controller { return $totalRevenue; } - private function getInvoiceOverview( ) + private function getInvoiceOverview() { - $projects = Project::whereArchive('F')->get(); + $projects = Project::whereArchive( 'F' )->get(); - foreach($projects as $project) + foreach ( $projects as $project ) { - $invoiceOverview = new InvoiceOverview( $project, date('Y') ); + $invoiceOverview = new InvoiceOverview( $project, date( 'Y' ) ); $invoiceOverviews[] = $invoiceOverview->getProjectDetails(); } @@ -97,7 +99,7 @@ class DashboardController extends MY_Controller { $results = $query->result(); $costsToPay = 0; - foreach($results as $result) + foreach ( $results as $result ) { $toPay = $result->other_revenue - $result->costs + $result->saldoToPay; $costsToPay += $toPay; @@ -106,4 +108,33 @@ class DashboardController extends MY_Controller { return $costsToPay; } + private function getInvoiced() + { + $invoiced = Invoice::getInvoiced( date( 'Y' ) ); + + $totalInvoiced = 0; + foreach ( $invoiced as $invoice ) + { + $totalInvoiced += ROUND( ( $invoice->invoiceamount * 1.21 ), 0 ); + } + + return $totalInvoiced; + } + + private function getChanceRevenues() + { + $offers = Offer::getAllOffers( FALSE, 'F', '', 'id', 'desc' ); + + $totalChance = 0; + foreach ( $offers as $offer ) + { + $totalChance += + ROUND( + ( $offer->own_revenue + $offer->other_revenue ) * + ( $offer->acceptance_chance / 100 ), 0 ); + } + + return $totalChance; + } + } diff --git a/application/models/eloquent/Invoice.php b/application/models/eloquent/Invoice.php index 6a44250..9fdb7b0 100644 --- a/application/models/eloquent/Invoice.php +++ b/application/models/eloquent/Invoice.php @@ -65,7 +65,7 @@ class Invoice extends BaseModel { public static function getInvoiced( $year ) { - $invoiced = Invoice::selectRaw('invoicenumber, PRJ.projectname, projectnumber, CUS.name, invoicedate, CUS.name, invoiceamount') + $invoiced = Invoice::selectRaw('invoicenumber, PRJ.projectname, projectnumber, CUS.name, invoicedate, CUS.name, ROUND(invoiceamount, 0) AS 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}") diff --git a/application/views/pages/dashboard_view.php b/application/views/pages/dashboard_view.php index 287e546..3d14ea3 100644 --- a/application/views/pages/dashboard_view.php +++ b/application/views/pages/dashboard_view.php @@ -34,15 +34,19 @@

- Omzet komende jaar: + Omzet totaal gerealiseerd lopend jaar: + +

+

+ Minimum omzet lopend jaar: + +

+

+ Verwachte omzet komende 12 maanden:

-

- Omzet totaal gerealiseerd lopend jaar: - -

@@ -92,6 +96,13 @@

+

+ Verstuurde facturen lopende jaar (incl btw): + + + + +

Openstaande facturen (incl btw): @@ -116,13 +127,17 @@

- Kosten derden (excl btw): + Kosten derden (incl btw):

Saldo inkomsten (excl btw):

+

+ (eigen) omzet * kans (excl btw): + +

diff --git a/application/views/reports/invoices/invoices_report.php b/application/views/reports/invoices/invoices_report.php index c40df1c..7b1529d 100644 --- a/application/views/reports/invoices/invoices_report.php +++ b/application/views/reports/invoices/invoices_report.php @@ -51,6 +51,20 @@ + + + Totaal + + + + + + + + + + +

diff --git a/public/js/lib/modules/dashboard/dashboardModule.js b/public/js/lib/modules/dashboard/dashboardModule.js index b655dbd..cec1757 100644 --- a/public/js/lib/modules/dashboard/dashboardModule.js +++ b/public/js/lib/modules/dashboard/dashboardModule.js @@ -29,6 +29,9 @@ dbo.dashboardInit = function () { billingOverview : ko.observableArray([]), showInvoiceOverview: ko.observable(false), openInvoices : ko.observable(null), + invoiced : ko.observable(null), + minimumRevenues : ko.observable(null), + totalChance : ko.observable(null), init: function () { var self = dbo.dashboardModel @@ -41,8 +44,11 @@ dbo.dashboardInit = function () { self.owpTotal(dbo.helpers.thousandSeparator(data.totalOwp)) self.revenuesNextyear(dbo.helpers.thousandSeparator(data.revenuesNextyear)) self.totalRevenues(dbo.helpers.thousandSeparator(data.totalRevenues)) + self.minimumRevenues(dbo.helpers.thousandSeparator(data.currentFinancialYear + data.revenuesThisYear)) + self.invoiced(dbo.helpers.thousandSeparator(data.invoiced)) self.openInvoices(dbo.helpers.thousandSeparator(outstandings.openInvoices)) self.toInvoice(dbo.helpers.thousandSeparator(outstandings.toInvoice)) + self.totalChance(dbo.helpers.thousandSeparator(data.totalChance)) self.revenueCurrentYear(dbo.helpers.thousandSeparator(revCurYear)) self.revenuesThisYear(dbo.helpers.thousandSeparator(data.revenuesThisYear)) diff --git a/public/js/lib/modules/reports/invoicereport.js b/public/js/lib/modules/reports/invoicereport.js index 7cc66cb..6891c7e 100644 --- a/public/js/lib/modules/reports/invoicereport.js +++ b/public/js/lib/modules/reports/invoicereport.js @@ -42,6 +42,9 @@ dbo.invoicereportInit = function () { archive : ko.observable(false), recievedInvoices : ko.observableArray([]), invoiced : ko.observableArray([]), + totalInvoiced : ko.observable(), + totalVat : ko.observable(), + totalInclVat : ko.observable(), init: function () { var vm = dbo.invoicereport @@ -87,13 +90,18 @@ dbo.invoicereportInit = function () { p.paymentamount(dbo.helpers.thousandSeparator(p.paymentamount())) }) - vm.years(data.invoicedYears); + vm.years(data.invoicedYears) vm.invoiced.removeAll() - _.each(data.invoiced, function(p){ - vm.invoiced.push( new vm.Invoice(p)); - }); - + vm.totalInvoiced(0) + vm.totalVat(0) + vm.totalInclVat(0) + _.each(data.invoiced, function (p) { + vm.invoiced.push(new vm.Invoice(p)) + }) + vm.totalInvoiced(dbo.helpers.thousandSeparator(vm.totalInvoiced())) + vm.totalVat(dbo.helpers.thousandSeparator(vm.totalVat())) + vm.totalInclVat(dbo.helpers.thousandSeparator(vm.totalInclVat())) }) }, @@ -244,9 +252,10 @@ dbo.invoicereportInit = function () { this.paymentamount = dbo.helpers.thousandSeparator(Math.round(data.paymentamount)) }, - Invoice : function(data){ - var vat = Math.round((data.invoiceamount * 21) / 100); - var inclVat = vat + Number(data.invoiceamount); + Invoice: function (data) { + var vm = dbo.invoicereport + var vat = Math.round((data.invoiceamount * 21) / 100) + var inclVat = vat + Number(data.invoiceamount) this.invoiceamount = dbo.helpers.thousandSeparator(data.invoiceamount) this.vat = dbo.helpers.thousandSeparator(vat) this.inclVat = dbo.helpers.thousandSeparator(inclVat) @@ -254,6 +263,9 @@ dbo.invoicereportInit = function () { this.invoicedate = data.invoicedate this.name = data.name this.invoicenumber = ko.observable(data.invoicenumber) + vm.totalInvoiced(Number(vm.totalInvoiced()) + Number(data.invoiceamount)) + vm.totalVat(Number(vm.totalVat()) + Number(vat)) + vm.totalInclVat(Number(vm.totalInclVat()) + Number(inclVat)) }, createSpreadsheet: function () {