From ddea7391994282aed2f5c97f3f2a4ab2697e495d Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Tue, 30 Apr 2019 19:07:18 +0200 Subject: [PATCH] invoice added new columns --- application/core/MY_Controller.php | 2 +- .../reports/invoice/InvoiceOverview.php | 20 ++++++++++++++++++- application/models/eloquent/Payment.php | 13 ++++++++++++ .../invoices/invoiceoverview_report.php | 14 +++++++++++++ .../js/lib/modules/reports/invoicereport.js | 8 ++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 5d8356f..58ffb96 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.04'; + $this->version = '1.00.05'; $this->load->library( 'beheer/session/RetrieveUserSession' ); diff --git a/application/libraries/reports/invoice/InvoiceOverview.php b/application/libraries/reports/invoice/InvoiceOverview.php index cc7969e..919ee45 100644 --- a/application/libraries/reports/invoice/InvoiceOverview.php +++ b/application/libraries/reports/invoice/InvoiceOverview.php @@ -20,6 +20,8 @@ class InvoiceOverview { private $needInvoice; private $projectDetails; private $projectnumber; + private $projectPayment; + private $invoicesToPay; public function __construct( $project, $year ) { @@ -35,7 +37,7 @@ class InvoiceOverview { return $this->projectDetails; } - public function getNeedinvoice( ) + public function getNeedinvoice() { return $this->needInvoice; } @@ -56,8 +58,12 @@ class InvoiceOverview { $this->setTotalInvoicedThisYear(); + $this->setPaymentPerProject(); + $this->setInvoicesTotal(); + $this->setInvoicesToPay(); + $this->setNeedInvoice(); $this->setProjectDetails(); @@ -104,12 +110,22 @@ class InvoiceOverview { Invoice::invoicePerYear( $this->project->id, $this->year, TRUE ); } + private function setPaymentPerProject() + { + $this->projectPayment = Payment::getPaymentPerProject( $this->project->id ); + } + private function setInvoicesTotal() { $this->invoicesTotal = $this->totalInvoicedOtherYears + $this->totalInvoicedThisYear; } + private function setInvoicesToPay() + { + $this->invoicesToPay = $this->invoicesTotal - $this->projectPayment; + } + private function setNeedInvoice() { $this->needInvoice = @@ -127,6 +143,8 @@ class InvoiceOverview { 'totalInvoicedOtherYears' => number_format( $this->totalInvoicedOtherYears, 0, ',', '.' ), 'totalInvoicedThisYear' => number_format( $this->totalInvoicedThisYear, 0, ',', '.' ), 'invoicesTotal' => number_format( $this->invoicesTotal, 0, ',', '.' ), + 'projectPayment' => number_format( $this->projectPayment, 0, ',', '.' ), + 'invoiceToPay' => number_format( $this->invoicesToPay, 0, ',', '.' ), 'needInvoice' => number_format( $this->needInvoice, 0, ',', '.' ) ]; } diff --git a/application/models/eloquent/Payment.php b/application/models/eloquent/Payment.php index 9099ef0..d3ff460 100644 --- a/application/models/eloquent/Payment.php +++ b/application/models/eloquent/Payment.php @@ -15,6 +15,19 @@ class Payment extends BaseModel { return $this->belongsTo( 'Invoice' ); } + public static function getPaymentPerProject( $projectID ) + { + $projectPayment = self::selectRAW( 'id, invoice_id, SUM(paymentamount) as payment' ) + ->whereHas( 'invoice', function ( $q ) use ( $projectID ) { + $q->whereProjectId( $projectID ); + } ) + ->first(); + + if( ! $projectPayment) return 0; + + return $projectPayment->payment; + } + public static function savePayment( $paymentID, $payment ) { $payment = (array) $payment; diff --git a/application/views/reports/invoices/invoiceoverview_report.php b/application/views/reports/invoices/invoiceoverview_report.php index e370cad..d409f03 100644 --- a/application/views/reports/invoices/invoiceoverview_report.php +++ b/application/views/reports/invoices/invoiceoverview_report.php @@ -29,6 +29,12 @@
Gefactureerd totaal
incl. btw
+ +
Betaald incl. btw
+ + +
gefactureerd niet betaald
incl. btw
+
Nog te factureren
incl. btw
@@ -45,6 +51,8 @@ + + @@ -69,6 +77,12 @@ + + + + + + diff --git a/public/js/lib/modules/reports/invoicereport.js b/public/js/lib/modules/reports/invoicereport.js index a650242..8146d98 100644 --- a/public/js/lib/modules/reports/invoicereport.js +++ b/public/js/lib/modules/reports/invoicereport.js @@ -29,6 +29,8 @@ dbo.invoicereportInit = function () { totalToInvoicingIncl : ko.observable(), totalInvoicedOtherYears: ko.observable(), totalInvoicedThisYear : ko.observable(), + totalPayment : ko.observable(), + totalToPay : ko.observable(), invoicesTotal : ko.observable(), needInvoice : ko.observable(), forecastThisYear : ko.observable(), @@ -111,6 +113,8 @@ dbo.invoicereportInit = function () { vm.totalInvoicedOtherYears( 0 ); vm.totalInvoicedThisYear( 0 ); vm.invoicesTotal( 0 ); + vm.totalPayment( 0 ); + vm.totalToPay( 0 ); vm.needInvoice( 0 ); vm.forecastThisYear( 0 ); vm.forecastOtherYears( 0 ); @@ -134,6 +138,8 @@ dbo.invoicereportInit = function () { vm.totalInvoicedOtherYears( vm.totalInvoicedOtherYears() + Number( p.totalInvoicedOtherYears.replace( '.', '' ) ) ); vm.totalInvoicedThisYear( vm.totalInvoicedThisYear() + Number( p.totalInvoicedThisYear.replace( '.', '' ) ) ); vm.invoicesTotal( vm.invoicesTotal() + Number( p.invoicesTotal.replace( '.', '' ) ) ); + vm.totalPayment( vm.totalPayment() + Number( p.projectPayment.replace( '.', '' ) ) ); + vm.totalToPay( vm.totalToPay() + Number( p.invoiceToPay.replace( '.', '' ) ) ); vm.needInvoice( vm.needInvoice() + Number( p.needInvoice.replace( '.', '' ) ) ); } ); @@ -142,6 +148,8 @@ dbo.invoicereportInit = function () { vm.totalInvoicedOtherYears( dbo.helpers.thousandSeparator( vm.totalInvoicedOtherYears() ) ); vm.totalInvoicedThisYear( dbo.helpers.thousandSeparator( vm.totalInvoicedThisYear() ) ); vm.invoicesTotal( dbo.helpers.thousandSeparator( vm.invoicesTotal() ) ); + vm.totalPayment( dbo.helpers.thousandSeparator( vm.totalPayment() ) ); + vm.totalToPay( dbo.helpers.thousandSeparator( vm.totalToPay() ) ); vm.needInvoice( dbo.helpers.thousandSeparator( vm.needInvoice() ) ); },