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 @@