diff --git a/application/libraries/reports/invoice/Excel/InvoiceForecastSheet.php b/application/libraries/reports/invoice/Excel/InvoiceForecastSheet.php new file mode 100644 index 0000000..11407a9 --- /dev/null +++ b/application/libraries/reports/invoice/Excel/InvoiceForecastSheet.php @@ -0,0 +1,75 @@ + 'project', + 'B' => 'klant', + 'C' => 'Nog te factureren incl. btw', + 'D' => 'Nog te factureren incl. btw lopend boekjaar incl. btw', + 'E' => 'Nog te factureren na lopend boekjaar inc. btw', + 'F' => 'Nog te prognotiseren inc. btw' + ]; + + private $invoiceForecast; + private $sheet; + private $row; + + public function __construct( $invoiceForecast, $sheet ) + { + $this->invoiceForecast = $invoiceForecast; + $this->sheet = $sheet; + + $this->handle(); + } + + private function handle() + { + $this->setHeader(); + + $this->setBody(); + + $this->setTotals(); + } + + 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->invoiceForecast AS $project ) + { + $this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] ); + $this->sheet->setCellValue( 'B' . $this->row, $project['customer'] ); + $this->sheet->setCellValue( 'C' . $this->row, str_replace( '.', '', $project['needInvoice'] ) ); + $this->sheet->setCellValue( 'D' . $this->row, str_replace( '.', '', $project['forecastThisYear'] ) ); + $this->sheet->setCellValue( 'E' . $this->row, str_replace( '.', '', $project['forecastOtherYears'] ) ); + $this->sheet->setCellValue( 'F' . $this->row, str_replace( '.', '', $project['forecastRemaining'] ) ); + + $this->row ++; + } + } + + private function setTotals() + { + $lastRow = $this->row - 1; + $this->sheet->setCellValue( 'C' . $this->row, '=SUM(C2:C' . $lastRow . ')' ); + $this->sheet->setCellValue( 'D' . $this->row, '=SUM(D2:D' . $lastRow . ')' ); + $this->sheet->setCellValue( 'E' . $this->row, '=SUM(E2:E' . $lastRow . ')' ); + $this->sheet->setCellValue( 'F' . $this->row, '=SUM(F2:F' . $lastRow . ')' ); + } + +} \ No newline at end of file diff --git a/application/libraries/reports/invoice/Excel/InvoiceSheet.php b/application/libraries/reports/invoice/Excel/InvoiceOverviewSheet.php similarity index 98% rename from application/libraries/reports/invoice/Excel/InvoiceSheet.php rename to application/libraries/reports/invoice/Excel/InvoiceOverviewSheet.php index 6aed139..ae6c17d 100644 --- a/application/libraries/reports/invoice/Excel/InvoiceSheet.php +++ b/application/libraries/reports/invoice/Excel/InvoiceOverviewSheet.php @@ -6,7 +6,7 @@ * Time: 20:40 */ -class InvoiceSheet { +class InvoiceOverviewSheet { const HEADERS = [ 'A' => 'project', diff --git a/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php b/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php index bb73646..a06caba 100644 --- a/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php +++ b/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php @@ -34,7 +34,13 @@ class InvoiceSpreadsheet { { $this->setSpreadsheet(); - $this->setInvoiceSheet(); + $this->setInvoiceOverviewSheet(); + + $this->setInvoiceForecast(); + + $this->setMonthForecast(); + + $this->setMonthPayment(); $this->setFilename(); @@ -50,14 +56,44 @@ class InvoiceSpreadsheet { $this->spreadsheet = new Spreadsheet(); } - private function setInvoiceSheet() + private function setInvoiceOverviewSheet() { $invoiceSheet = new Worksheet( $this->spreadsheet, 'Facturen' ); $this->invoiceSheet = $this->spreadsheet->addSheet( $invoiceSheet ); - new InvoiceSheet( $this->invoiceReport['invoiceOverview'], $this->invoiceSheet ); + new InvoiceOverviewSheet( $this->invoiceReport['invoiceOverview'], $this->invoiceSheet ); + } + + private function setInvoiceForecast() + { + $invoiceSheet = new Worksheet( $this->spreadsheet, 'prognose' ); + + $this->invoiceSheet = + $this->spreadsheet->addSheet( $invoiceSheet ); + + new InvoiceForecastSheet( $this->invoiceReport['forecasts'], $this->invoiceSheet ); + } + + private function setMonthForecast() + { + $invoiceSheet = new Worksheet( $this->spreadsheet, 'maandprognose' ); + + $this->invoiceSheet = + $this->spreadsheet->addSheet( $invoiceSheet ); + + new MonthForecastSheet( $this->invoiceReport['monthForecasts'], $this->invoiceSheet ); + } + + private function setMonthPayment() + { + $invoiceSheet = new Worksheet( $this->spreadsheet, 'maand betalingen' ); + + $this->invoiceSheet = + $this->spreadsheet->addSheet( $invoiceSheet ); + + new MonthPaymentSheet( $this->invoiceReport['monthPayments'], $this->invoiceSheet ); } private function setFilename() diff --git a/application/libraries/reports/invoice/Excel/MonthForecastSheet.php b/application/libraries/reports/invoice/Excel/MonthForecastSheet.php new file mode 100644 index 0000000..85cb34d --- /dev/null +++ b/application/libraries/reports/invoice/Excel/MonthForecastSheet.php @@ -0,0 +1,101 @@ + 'project', + 'B' => 'klant', + 'C' => 'Nog te factureren incl. btw', + 'D' => 'januari', + 'E' => 'februari', + 'F' => 'maart', + 'G' => 'april', + 'H' => 'mei', + 'I' => 'juni', + 'J' => 'juli', + 'K' => 'augustus', + 'L' => 'september', + 'M' => 'oktober', + 'N' => 'november', + 'O' => 'december', + 'P' => 'Nog te factureren na lopend boekjaar inc. btw', + 'Q' => 'Nog te prognotiseren inc. btw' + ]; + + const MONTH_COLUMNS = ['D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O']; + + private $invoiceForecast; + private $sheet; + private $row; + + public function __construct( $invoiceForecast, $sheet ) + { + $this->invoiceForecast = $invoiceForecast; + $this->sheet = $sheet; + + $this->handle(); + } + + private function handle() + { + $this->setHeader(); + + $this->setBody(); + + $this->setTotals(); + } + + 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->invoiceForecast AS $project ) + { + $this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] ); + $this->sheet->setCellValue( 'B' . $this->row, $project['customer'] ); + $this->sheet->setCellValue( 'C' . $this->row, str_replace( '.', '', $project['needInvoice'] ) ); + + $columnCount = 0; + foreach ( $project['forecastMonths'] as $month ) + { + $column = self::MONTH_COLUMNS[ $columnCount ]; + $forecast = $month['forecastamount']; + $this->sheet->setCellValue( $column . $this->row, $forecast ); + $columnCount ++; + } + + $this->sheet->setCellValue( 'P' . $this->row, str_replace( '.', '', $project['forecastOtherYears'] ) ); + $this->sheet->setCellValue( 'Q' . $this->row, str_replace( '.', '', $project['forecastRemaining'] ) ); + + $this->row ++; + } + } + + private function setTotals() + { + $lastRow = $this->row - 1; + $this->sheet->setCellValue( 'C' . $this->row, '=SUM(C2:C' . $lastRow . ')' ); + $this->sheet->setCellValue( 'D' . $this->row, '=SUM(D2:D' . $lastRow . ')' ); + foreach ( self::MONTH_COLUMNS as $column ) + { + $this->sheet->setCellValue( $column . $this->row, '=SUM(' . $column . '2:' . $column . $lastRow . ')' ); + } + $this->sheet->setCellValue( 'P' . $this->row, '=SUM(P2:P' . $lastRow . ')' ); + $this->sheet->setCellValue( 'Q' . $this->row, '=SUM(Q2:Q' . $lastRow . ')' ); + } + +} \ No newline at end of file diff --git a/application/libraries/reports/invoice/Excel/MonthPaymentSheet.php b/application/libraries/reports/invoice/Excel/MonthPaymentSheet.php new file mode 100644 index 0000000..d51bd0d --- /dev/null +++ b/application/libraries/reports/invoice/Excel/MonthPaymentSheet.php @@ -0,0 +1,95 @@ + 'project', + 'B' => 'klant', + 'C' => 'januari', + 'D' => 'februari', + 'E' => 'maart', + 'F' => 'april', + 'G' => 'mei', + 'H' => 'juni', + 'I' => 'juli', + 'J' => 'augustus', + 'K' => 'september', + 'L' => 'oktober', + 'M' => 'november', + 'N' => 'december', + 'O' => 'Totaal betaald lopend boekjaar inc. btw' + ]; + + const MONTH_COLUMNS = ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N']; + + private $invoiceForecast; + private $sheet; + private $row; + + public function __construct( $invoiceForecast, $sheet ) + { + $this->invoiceForecast = $invoiceForecast; + $this->sheet = $sheet; + + $this->handle(); + } + + private function handle() + { + $this->setHeader(); + + $this->setBody(); + + $this->setTotals(); + } + + 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->invoiceForecast AS $project ) + { + $this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] ); + $this->sheet->setCellValue( 'B' . $this->row, $project['customer'] ); + + $columnCount = 0; + foreach ( $project['monthPayments'] as $month ) + { + $column = self::MONTH_COLUMNS[ $columnCount ]; + $forecast = $month['paymentamount']; + $this->sheet->setCellValue( $column . $this->row, $forecast ); + $columnCount ++; + } + + $formula = '=SUM(C'.$this->row.':N'.$this->row.')'; + $this->sheet->setCellValue( 'O' . $this->row, $formula); + + $this->row ++; + } + } + + private function setTotals() + { + $lastRow = $this->row - 1; + foreach ( self::MONTH_COLUMNS as $column ) + { + $this->sheet->setCellValue( $column . $this->row, '=SUM(' . $column . '2:' . $column . $lastRow . ')' ); + } + $this->sheet->setCellValue( 'O' . $this->row, '=SUM(O2:O' . $lastRow . ')' ); + } + +} \ No newline at end of file diff --git a/application/views/reports/invoices/monthpayment_report.php b/application/views/reports/invoices/monthpayment_report.php index e725a89..6c94a7e 100644 --- a/application/views/reports/invoices/monthpayment_report.php +++ b/application/views/reports/invoices/monthpayment_report.php @@ -13,7 +13,7 @@ -
Totaal gefactureerd
lopend boekjaar incl. btw
+
Totaal betaald
lopend boekjaar incl. btw
diff --git a/public/js/lib/modules/reports/invoicereport.js b/public/js/lib/modules/reports/invoicereport.js index 8d1ba49..d3f5a17 100644 --- a/public/js/lib/modules/reports/invoicereport.js +++ b/public/js/lib/modules/reports/invoicereport.js @@ -204,7 +204,8 @@ dbo.invoicereportInit = function () { createSpreadsheet:function(){ var vm = dbo.invoicereport; - dbo.invoiceDataService.createSpreadsheet(vm.selectedYear()); + var url = 'index.php/reports/reportsController/createInvoicesSpreadsheet/' + vm.selectedYear(); + window.open(url, '_blank'); } }