diff --git a/application/controllers/reports/ReportsController.php b/application/controllers/reports/ReportsController.php index efece4a..925ca3a 100644 --- a/application/controllers/reports/ReportsController.php +++ b/application/controllers/reports/ReportsController.php @@ -59,26 +59,22 @@ class ReportsController extends MY_Controller { $this->json( $result ); } - public function getInvoiceOverview( $year ) + public function getInvoiceOverview( $year = FALSE ) { - $sql = Qinvoiceoverview::fire( $year ); + $invoices = new Invoices( $year ); - $query = $this->db->query( $sql ); + $invoiceReport = $invoices->getInvoiceReport(); - $result = $query->result(); + $this->json( $invoiceReport ); + } - foreach ( $result as $project ) - { - $sql = QinvoiceMonthOverview::fire( $project->id, $year ); + public function createInvoicesSpreadsheet( $year = FALSE ) + { + $invoices = new Invoices( $year ); - $query = $this->db->query( $sql ); + $invoiceReport = $invoices->getInvoiceReport(); - $months = $query->result(); - - $project->months = $months; - } - - $this->json( $result ); + new InvoiceSpreadsheet($invoiceReport); } public function saveCurrentFinnacialYear( $projectID ) diff --git a/application/libraries/reports/invoice/Excel/InvoiceSheet.php b/application/libraries/reports/invoice/Excel/InvoiceSheet.php new file mode 100644 index 0000000..6aed139 --- /dev/null +++ b/application/libraries/reports/invoice/Excel/InvoiceSheet.php @@ -0,0 +1,80 @@ + 'project', + 'B' => 'klant', + 'C' => 'Totaal te factureren excl. btw', + 'D' => 'Totaal te factureren incl. btw', + 'E' => 'Gefactureerd overige jaren incl. btw', + 'F' => 'Gefactureerd lopende boekjaar incl. btw', + 'G' => 'Gefactureerd totaal incl. btw', + 'H' => 'Nog te factureren incl. btw' + ]; + + private $invoiceOverview; + private $sheet; + private $row; + + public function __construct( $invoiceOverview, $sheet ) + { + $this->invoiceOverview = $invoiceOverview; + $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->invoiceOverview 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['totalToInvoicingExcl'] ) ); + $this->sheet->setCellValue( 'D' . $this->row, str_replace( '.', '', $project['totalToInvoicingIncl'] ) ); + $this->sheet->setCellValue( 'E' . $this->row, str_replace( '.', '', $project['totalInvoicedOtherYears'] ) ); + $this->sheet->setCellValue( 'F' . $this->row, str_replace( '.', '', $project['totalInvoicedThisYear'] ) ); + $this->sheet->setCellValue( 'G' . $this->row, str_replace( '.', '', $project['invoicesTotal'] ) ); + $this->sheet->setCellValue( 'H' . $this->row, str_replace( '.', '', $project['needInvoice'] ) ); + + $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 . ')' ); + $this->sheet->setCellValue( 'G' . $this->row, '=SUM(G2:G' . $lastRow . ')' ); + $this->sheet->setCellValue( 'H' . $this->row, '=SUM(H2:H' . $lastRow . ')' ); + } +} \ No newline at end of file diff --git a/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php b/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php new file mode 100644 index 0000000..bb73646 --- /dev/null +++ b/application/libraries/reports/invoice/Excel/InvoiceSpreadsheet.php @@ -0,0 +1,88 @@ +ci =& get_instance(); + + $this->invoiceReport = $invoiceReport; + + $this->ci->load->helper( 'download' ); + + $this->handle(); + } + + private function handle() + { + $this->setSpreadsheet(); + + $this->setInvoiceSheet(); + + $this->setFilename(); + + $this->setFullPathname(); + + $this->createFile(); + + $this->downloadSpreadsheet(); + } + + private function setSpreadsheet() + { + $this->spreadsheet = new Spreadsheet(); + } + + private function setInvoiceSheet() + { + $invoiceSheet = new Worksheet( $this->spreadsheet, 'Facturen' ); + + $this->invoiceSheet = + $this->spreadsheet->addSheet( $invoiceSheet ); + + new InvoiceSheet( $this->invoiceReport['invoiceOverview'], $this->invoiceSheet ); + } + + private function setFilename() + { + $this->filename = 'facturen' . date( 'YmdHis' ) . '.xlsx'; + } + + private function setFullPathname() + { + $this->fullpathname = MYROOTPATH . 'documents/spreadsheets/' . $this->filename; + } + + private function createFile() + { + $writer = new Xlsx( $this->spreadsheet ); + + $writer->save( $this->fullpathname ); + } + + private function downloadSpreadsheet() + { + $data = file_get_contents( $this->fullpathname ); + + force_download( $this->filename, $data ); + } + + +} \ No newline at end of file diff --git a/application/libraries/reports/invoice/InvoiceForecast.php b/application/libraries/reports/invoice/InvoiceForecast.php new file mode 100644 index 0000000..89ad696 --- /dev/null +++ b/application/libraries/reports/invoice/InvoiceForecast.php @@ -0,0 +1,124 @@ +project = $project; + $this->needInvoice = $needInvoice; + $this->year = $year; + + $this->handle(); + } + + public function getProjectDetails() + { + return $this->projectDetails; + } + + public function getNeedInvoice() + { + return $this->needInvoice; + } + + public function getForecastOtherYear() + { + return $this->forecastOtherYears; + } + + public function getForecastRemaining() + { + return $this->forecastRemaining; + } + + private function handle() + { + $this->setCurrentyear(); + + $this->setProjectname(); + + $this->setCustomer(); + + $this->loopForecasts(); + + $this->setForecastRemaining(); + + $this->setProjectDetails(); + } + + private function setCurrentyear() + { + $this->currentYear = date( 'Y' ); + } + + private function setProjectname() + { + $this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')'; + } + + private function setCustomer() + { + $this->customer = $this->project->customer->name; + } + + private function loopForecasts() + { + if ( is_null( $this->project->forecasts ) ) return $this->forecastThisYear = 0; + + foreach ( $this->project->forecasts as $this->forecast ) + { + $this->setForecastThisYear(); + + $this->setForecastOtherYears(); + } + } + + private function setForecastThisYear() + { + if ( $this->forecast->year == $this->year ) + $this->forecastThisYear += $this->forecast->forecastamount; + } + + private function setForecastOtherYears() + { + if ( $this->forecast->year != $this->year ) + $this->forecastOtherYears += $this->forecast->forecastamount; + } + + private function setForecastRemaining() + { + $this->forecastRemaining = + $this->needInvoice - $this->forecastThisYear - $this->forecastOtherYears; + } + + private function setProjectDetails() + { + $this->projectDetails = [ + 'projectname' => $this->projectname, + 'customer' => $this->customer, + 'needInvoice' => number_format( $this->needInvoice, 0, ',', '.' ), + 'forecastThisYear' => number_format( $this->forecastThisYear, 0, ',', '.' ), + 'forecastOtherYears' => number_format( $this->forecastOtherYears, 0, ',', '.' ), + 'forecastRemaining' => number_format( $this->forecastRemaining, 0, ',', '.' ), + ]; + } + +} \ No newline at end of file diff --git a/application/libraries/reports/invoice/InvoiceOverview.php b/application/libraries/reports/invoice/InvoiceOverview.php new file mode 100644 index 0000000..b0f1397 --- /dev/null +++ b/application/libraries/reports/invoice/InvoiceOverview.php @@ -0,0 +1,129 @@ +project = $project; + + $this->handle(); + } + + public function getProjectDetails() + { + return $this->projectDetails; + } + + public function getNeedinvoice( ) + { + return $this->needInvoice; + } + + private function handle() + { + $this->setCurrentyear(); + + $this->setProjectname(); + + $this->setCustomer(); + + $this->setTotalToInvoicingExcl(); + + $this->setTotalToInvoicingIncl(); + + $this->setTotalInvoicedOtherYears(); + + $this->setTotalInvoicedThisYear(); + + $this->setInvoicesTotal(); + + $this->setNeedInvoice(); + + $this->setProjectDetails(); + } + + private function setCurrentyear() + { + $this->currentYear = date( 'Y' ); + } + + private function setProjectname() + { + $this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')'; + } + + private function setCustomer() + { + $this->customer = $this->project->customer->name; + } + + private function setTotalToInvoicingExcl() + { + $offer = $this->project->offer; + + $this->totalToInvoicingExcl = + $offer->own_revenue + $offer->other_revenue + $offer->costs; + } + + private function setTotalToInvoicingIncl() + { + $this->totalToInvoicingIncl = + $this->totalToInvoicingExcl * ( 1 + ( $this->project->vat->vatrate / 100 ) ); + } + + private function setTotalInvoicedOtherYears() + { + $this->totalInvoicedOtherYears = + Invoice::invoicePerYear( $this->project->id, $this->currentYear, FALSE ); + } + + private function setTotalInvoicedThisYear() + { + $this->totalInvoicedThisYear = + Invoice::invoicePerYear( $this->project->id, $this->currentYear, TRUE ); + } + + private function setInvoicesTotal() + { + $this->invoicesTotal = + $this->totalInvoicedOtherYears + $this->totalInvoicedThisYear; + } + + private function setNeedInvoice() + { + $this->needInvoice = + $this->totalToInvoicingIncl - $this->invoicesTotal; + } + + private function setProjectDetails() + { + $this->projectDetails = [ + 'projectname' => $this->projectname, + 'customer' => $this->customer, + 'totalToInvoicingExcl' => number_format( $this->totalToInvoicingExcl, 0, ',', '.' ), + 'totalToInvoicingIncl' => number_format( $this->totalToInvoicingIncl, 0, ',', '.' ), + 'totalInvoicedOtherYears' => number_format( $this->totalInvoicedOtherYears, 0, ',', '.' ), + 'totalInvoicedThisYear' => number_format( $this->totalInvoicedThisYear, 0, ',', '.' ), + 'invoicesTotal' => number_format( $this->invoicesTotal, 0, ',', '.' ), + 'needInvoice' => number_format( $this->needInvoice, 0, ',', '.' ) + ]; + } +} \ No newline at end of file diff --git a/application/libraries/reports/invoice/Invoices.php b/application/libraries/reports/invoice/Invoices.php new file mode 100644 index 0000000..dcbc909 --- /dev/null +++ b/application/libraries/reports/invoice/Invoices.php @@ -0,0 +1,104 @@ +year = $year; + + $this->handle(); + } + + public function getInvoiceReport() + { + return $this->invoiceReport; + } + + private function handle() + { + $this->setProjects(); + + $this->loopProjects(); + + $this->setInvoiceReport(); + } + + private function setProjects() + { + $this->projects = Project::getProjectsForReport(); + } + + private function loopProjects() + { + foreach ( $this->projects as $this->project ) + { + $this->setInvoiceOverview(); + + $this->setInvoiceForecasts(); + + $this->setMonthForecasts(); + + $this->setMonthPayments(); + } + } + + private function setInvoiceOverview() + { + $this->invoiceOverview = new InvoiceOverview( $this->project, $this->year ); + + $this->invoiceOverviews[] = $this->invoiceOverview->getProjectDetails(); + } + + private function setInvoiceForecasts() + { + $this->invoiceForecast = + new InvoiceForecast( $this->project, $this->invoiceOverview->getNeedinvoice(), $this->year ); + + $this->invoiceForecasts[] = $this->invoiceForecast->getProjectDetails(); + } + + public function setMonthForecasts() + { + $this->monthForecast = + new MonthForecast( $this->invoiceForecast, $this->project, $this->year ); + + $this->monthForecasts[] = $this->monthForecast->getProjectDetails(); + } + + public function setMonthPayments() + { + $this->monthPayment = + new MonthPayments( $this->project, $this->year ); + + $this->monthPayments[] = $this->monthPayment->getProjectDetails(); + } + + private function setInvoiceReport() + { + $this->invoiceReport = [ + 'invoiceOverview' => $this->invoiceOverviews, + 'forecasts' => $this->invoiceForecasts, + 'monthForecasts' => $this->monthForecasts, + 'monthPayments' => $this->monthPayments + ]; + } +} \ No newline at end of file diff --git a/application/libraries/reports/invoice/MonthForecast.php b/application/libraries/reports/invoice/MonthForecast.php new file mode 100644 index 0000000..8fa6f8c --- /dev/null +++ b/application/libraries/reports/invoice/MonthForecast.php @@ -0,0 +1,91 @@ +project = $project; + $this->invoiceForecast = $invoiceForecast; + $this->year = $year; + + $this->handle(); + } + + public function getProjectDetails() + { + return $this->projectDetails; + } + + private function handle() + { + $this->setProjectname(); + + $this->setCustomer(); + + $this->setInitialsForecastMonths(); + + $this->loopForecasts(); + + $this->setProjectDetails(); + } + + private function setProjectname() + { + $this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')'; + } + + private function setCustomer() + { + $this->customer = $this->project->customer->name; + } + + private function setInitialsForecastMonths() + { + for ( $i = 1; $i <= 12; $i ++ ) + { + $this->forecastMonths[ $i ] = ['forecastamount' => 0]; + } + } + + private function loopForecasts() + { + foreach ( $this->project->forecasts as $this->forecast ) + { + $this->setMonthForecast(); + } + } + + private function setMonthForecast() + { + if ( $this->forecast->year == $this->year ) + $this->forecastMonths[ $this->forecast->month_id ]['forecastamount'] += $this->forecast->forecastamount; + } + + private function setProjectDetails() + { + $this->projectDetails = [ + 'projectname' => $this->projectname, + 'customer' => $this->customer, + 'needInvoice' => number_format( $this->invoiceForecast->getNeedInvoice(), 0, ',', '.' ), + 'forecastOtherYears' => number_format( $this->invoiceForecast->getForecastOtherYear(), 0, ',', '.' ), + 'forecastRemaining' => number_format( $this->invoiceForecast->getForecastRemaining(), 0, ',', '.' ), + 'forecastMonths' => $this->forecastMonths + ]; + } + +} \ No newline at end of file diff --git a/application/libraries/reports/invoice/MonthPayments.php b/application/libraries/reports/invoice/MonthPayments.php new file mode 100644 index 0000000..023e25f --- /dev/null +++ b/application/libraries/reports/invoice/MonthPayments.php @@ -0,0 +1,100 @@ +project = $project; + $this->year = $year; + + $this->handle(); + } + + public function getProjectDetails() + { + return $this->projectDetails; + } + + private function handle() + { + $this->setProjectname(); + + $this->setCustomer(); + + $this->setInitialsMonthPayments(); + + $this->loopPayments(); + + $this->setProjectDetails(); + } + + private function setProjectname() + { + $this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')'; + } + + private function setCustomer() + { + $this->customer = $this->project->customer->name; + } + + private function setInitialsMonthPayments() + { + for ( $i = 1; $i <= 12; $i ++ ) + { + $this->monthPayments[ $i ] = ['paymentamount' => 0]; + } + } + + private function loopPayments() + { + foreach ( $this->project->invoices as $invoice ) + { + foreach($invoice->payments as $this->payment) + { + $this->setMonthPayments(); + + $this->setTotalProjectPayments(); + } + } + } + + 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() + { + $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, ',', '.' ) + ]; + } +} \ No newline at end of file diff --git a/application/models/eloquent/Invoice.php b/application/models/eloquent/Invoice.php index dbcf462..6430b1e 100644 --- a/application/models/eloquent/Invoice.php +++ b/application/models/eloquent/Invoice.php @@ -24,6 +24,28 @@ class Invoice extends BaseModel { return $this->belongsTo( 'Vat' ); } + public static function invoicePerYear( $projectID, $year, $thatYear = TRUE ) + { + $invoices = Invoice::selectRAW( 'SUM(invoiceamount * ( 1 +(vatrate / 100))) AS invoicetotal' ) + ->join( 'vats', 'vats.id', '=', 'invoices.vat_id' ) + ->whereProjectId( $projectID ); + + if ( $thatYear ) + { + $invoices = $invoices->whereRaw( "YEAR(invoicedate) = {$year}" ); + } + else + { + $invoices = $invoices->whereRaw( "YEAR(invoicedate) != {$year}" ); + } + + if ( $invoices->count() == 0 ) return 0; + + $invoices = $invoices->first(); + + return $invoices->invoicetotal; + } + public static function saveInvoice( $invoiceID, $invoice ) { $invoice = (array) $invoice; diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index 2fddfc4..86bd800 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -104,6 +104,13 @@ class Project extends BaseModel { return $projects; } + public static function getProjectsForReport() + { + $projects = self::getBaseProject()->get(); + + return $projects; + } + public static function getBaseProject() { $project = Project::with( [ @@ -115,6 +122,7 @@ class Project extends BaseModel { 'projectemployees.user' => function ( $q ) { $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); }] ) + ->with('vat') ->with(['forecasts']) ->with(['reservations']) ->with( 'projectemployees.projecthours' ) diff --git a/application/views/pages/invoicereport_view.php b/application/views/pages/invoicereport_view.php new file mode 100644 index 0000000..6dc15c0 --- /dev/null +++ b/application/views/pages/invoicereport_view.php @@ -0,0 +1,61 @@ +
+
+
+ +
+
+ +
geen geldig jaar
+
+
+ +
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/application/views/pages/outgoinginvoices_view.php b/application/views/pages/outgoinginvoices_view.php deleted file mode 100644 index 8527a94..0000000 --- a/application/views/pages/outgoinginvoices_view.php +++ /dev/null @@ -1,37 +0,0 @@ -
-
-
- -
-
- -
geen geldig jaar
-
-
-
-
- -
-
-
\ No newline at end of file diff --git a/application/views/partials/_js.php b/application/views/partials/_js.php index f4e897c..324475f 100644 --- a/application/views/partials/_js.php +++ b/application/views/partials/_js.php @@ -44,7 +44,7 @@ - + diff --git a/application/views/reports/invoices/_invoicetable.php b/application/views/reports/invoices/_invoicetable.php deleted file mode 100644 index a5f9ccf..0000000 --- a/application/views/reports/invoices/_invoicetable.php +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
project
-
-
klant
-
-
status afgehandeld
-
-
te factureren(excl btw)
-
-
te factureren(incl btw)
-
-
gefactureerd
voorgaande jaren(incl btw)
-
-
gefactureerd
lopend jaar(incl btw)
-
-
totaal gefactureerd
-
-
betaald voorgaande jaren
-
-
betaald lopend jaar
-
-
totaal betaald
-
-
nog niet betaald
-
-
nog te factureren (incl.btw)
-
-
nog te factureren lopend jaar
-
-
nog te factureren na lopend jaar
-
-
nog te prognotiseren
-
-
te factureren(incl btw)
-
-
te factureren volgende jaren
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- totaal - - - - - - - - - - - - - - - - - - - - - - - - -
\ No newline at end of file diff --git a/application/views/reports/invoices/contractors_report.php b/application/views/reports/invoices/contractors_report.php new file mode 100644 index 0000000..593b05d --- /dev/null +++ b/application/views/reports/invoices/contractors_report.php @@ -0,0 +1,7 @@ + + + + +
project
+ + +
klant
+ + +
Nog te factureren
incl. btw
+ + +
Nog te factureren
lopend boekjaar incl. btw
+ + +
Nog te factureren
na lopend boekjaar incl. btw
+ + +
Nog te prognotiseren
incl. btw
+ + + + + + + + + + + + + + + + + + + totaal + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/application/views/reports/invoices/invoiceoverview_report.php b/application/views/reports/invoices/invoiceoverview_report.php new file mode 100644 index 0000000..5607f81 --- /dev/null +++ b/application/views/reports/invoices/invoiceoverview_report.php @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
project
+
+
klant
+
+
Totaal te factureren
excl. btw
+
+
Totaal te factureren
incl. btw
+
+
Gefactureerd overige jaren
incl. btw
+
+
Gefactureerd lopende boekjaar
incl. btw
+
+
Gefactureerd totaal
incl. btw
+
+
Nog te factureren
incl. btw
+
+ totaal + + + + + + + + + + + + +
\ No newline at end of file diff --git a/application/views/reports/invoices/monthforecast_report.php b/application/views/reports/invoices/monthforecast_report.php new file mode 100644 index 0000000..1bafc8f --- /dev/null +++ b/application/views/reports/invoices/monthforecast_report.php @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
project
+
+
klant
+
+
Nog te factureren
incl. btw
+
+
+
+
Nog te factureren
na lopend boekjaar incl. btw
+
+
Nog te prognotiseren
incl. btw
+
+ + + + + + + + + +
\ No newline at end of file diff --git a/application/views/reports/invoices/monthpayment_report.php b/application/views/reports/invoices/monthpayment_report.php new file mode 100644 index 0000000..e725a89 --- /dev/null +++ b/application/views/reports/invoices/monthpayment_report.php @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
project
+
+
klant
+
+
+
+
Totaal gefactureerd
lopend boekjaar incl. btw
+
+ totaal + + + + +
\ No newline at end of file diff --git a/composer.json b/composer.json index 49a89aa..70ea60a 100755 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "php": ">=5.3.7", "vlucas/phpdotenv": "^2.4", "illuminate/database": "5.1.16", - "symfony/var-dumper": "^3.4" + "symfony/var-dumper": "^3.4", + "phpoffice/phpspreadsheet": "^1.3" }, "autoload": { "classmap": [ diff --git a/public/css/main.css b/public/css/main.css index 8a82341..4cc81f7 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -108,7 +108,7 @@ th.rotate > div > span { height:20px; border:1px solid #777; } -th.focus-green{ +.focus-green{ background-color:#dcf7b0; border:0; font-weight: bold; diff --git a/public/hello world.xlsx b/public/hello world.xlsx new file mode 100644 index 0000000..b74e7d5 Binary files /dev/null and b/public/hello world.xlsx differ diff --git a/public/js/lib/dataservices/invoiceDataService.js b/public/js/lib/dataservices/invoiceDataService.js index 528cde0..315f279 100644 --- a/public/js/lib/dataservices/invoiceDataService.js +++ b/public/js/lib/dataservices/invoiceDataService.js @@ -13,5 +13,9 @@ dbo.invoiceDataService = { .done( function ( data ) { callback( data ); } ); + }, + + createSpreadsheet : function(year){ + $.get( 'index.php/reports/reportsController/createInvoicesSpreadsheet/' + year ) } }; \ No newline at end of file diff --git a/public/js/lib/modules/menuModule.js b/public/js/lib/modules/menuModule.js index f573075..dc8895f 100644 --- a/public/js/lib/modules/menuModule.js +++ b/public/js/lib/modules/menuModule.js @@ -48,6 +48,8 @@ $( function () { vm[page]( true ); var func = page.toLowerCase() + 'Init'; +console.log( func ); + window.dbo[func](); }, diff --git a/public/js/lib/modules/reports/invoicereport.js b/public/js/lib/modules/reports/invoicereport.js new file mode 100644 index 0000000..8d1ba49 --- /dev/null +++ b/public/js/lib/modules/reports/invoicereport.js @@ -0,0 +1,220 @@ +/** + * Created by Pensare Software. + * User: Theo Weijmer + * Date: 02/03/2018 + * Time: 11:43 + */ + + +dbo.invoicereportInit = function () { + + if ( dbo.invoicereport !== undefined ) { + + dbo.invoicereport.initModule(); + + } else { + dbo.invoicereport = { + + selectedYear : ko.observable(), + invoiceOverview : ko.observableArray( [] ), + forecasts : ko.observableArray( [] ), + monthForecasts : ko.observableArray( [] ), + monthPayments : ko.observableArray( [] ), + months : ko.observableArray( [] ), + monthTotals : ko.observableArray( [] ), + monthPaymentTotals : ko.observableArray( [] ), + validYear : ko.observable(), + invoiceTab : ko.observable(), + totalToInvoicingExcl : ko.observable(), + totalToInvoicingIncl : ko.observable(), + totalInvoicedOtherYears: ko.observable(), + totalInvoicedThisYear : ko.observable(), + invoicesTotal : ko.observable(), + needInvoice : ko.observable(), + forecastThisYear : ko.observable(), + forecastOtherYears : ko.observable(), + forecastRemaining : ko.observable(), + totalProjectPayments : ko.observable(), + + init: function () { + var vm = dbo.invoicereport; + + vm.selectedYear( (new Date()).getFullYear() ); + vm.invoiceTab( 'invoice' ); + vm.validYear( true ); + vm.months( dbo.monthArray ); + + vm.initModule(); + }, + + initModule: function () { + var vm = dbo.invoicereport; + + vm.resetTotals(); + + dbo.invoiceDataService.getInvoiceOverview( vm.selectedYear(), function ( data ) { + vm.invoiceOverview( data.invoiceOverview ); + vm.setInvoiceOverviewTotals( data.invoiceOverview ); + + vm.forecasts( data.forecasts ); + vm.setForecastsTotals( data.forecasts ); + + vm.monthForecasts.removeAll(); + _.each( data.monthForecasts, function ( p ) { + vm.monthForecasts.push( new vm.Monthforecast( p ) ); + } ); + _.each( vm.monthTotals(), function ( p ) { + p.forecastamount( dbo.helpers.thousandSeparator( p.forecastamount() ) ); + } ); + + vm.monthPayments.removeAll(); + _.each( data.monthPayments, function ( p ) { + vm.monthPayments.push( new vm.Monthpayment( p ) ); + vm.totalProjectPayments( Number( vm.totalProjectPayments() ) + Number(p.totalProjectPayments.replace('.', '')) ); + console.log( vm.totalProjectPayments() ); + } ); + vm.totalProjectPayments( dbo.helpers.thousandSeparator( vm.totalProjectPayments() ) ); + _.each( vm.monthPaymentTotals(), function ( p ) { + p.paymentamount( dbo.helpers.thousandSeparator( p.paymentamount() ) ); + } ); + + } ); + }, + + resetTotals: function () { + var vm = dbo.invoicereport; + + vm.totalToInvoicingExcl( 0 ); + vm.totalToInvoicingIncl( 0 ); + vm.totalInvoicedOtherYears( 0 ); + vm.totalInvoicedThisYear( 0 ); + vm.invoicesTotal( 0 ); + vm.needInvoice( 0 ); + vm.forecastThisYear( 0 ); + vm.forecastOtherYears( 0 ); + vm.forecastRemaining( 0 ); + vm.totalProjectPayments( 0 ); + + for ( var i = 1; i <= 12; i++ ) { + vm.monthTotals.push( {monthID: i, forecastamount: ko.observable( 0 )} ); + vm.monthPaymentTotals.push( {monthID: i, paymentamount: ko.observable( 0 )} ); + } + }, + + setInvoiceOverviewTotals: function ( data ) { + var vm = dbo.invoicereport; + + _.each( data, function ( p ) { + vm.totalToInvoicingExcl( vm.totalToInvoicingExcl() + Number( p.totalToInvoicingExcl.replace( '.', '' ) ) ); + vm.totalToInvoicingIncl( vm.totalToInvoicingIncl() + Number( p.totalToInvoicingIncl.replace( '.', '' ) ) ); + 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.needInvoice( vm.needInvoice() + Number( p.needInvoice.replace( '.', '' ) ) ); + } ); + + vm.totalToInvoicingExcl( dbo.helpers.thousandSeparator( vm.totalToInvoicingExcl() ) ); + vm.totalToInvoicingIncl( dbo.helpers.thousandSeparator( vm.totalToInvoicingIncl() ) ); + vm.totalInvoicedOtherYears( dbo.helpers.thousandSeparator( vm.totalInvoicedOtherYears() ) ); + vm.totalInvoicedThisYear( dbo.helpers.thousandSeparator( vm.totalInvoicedThisYear() ) ); + vm.invoicesTotal( dbo.helpers.thousandSeparator( vm.invoicesTotal() ) ); + vm.needInvoice( dbo.helpers.thousandSeparator( vm.needInvoice() ) ); + }, + + setForecastsTotals: function ( data ) { + var vm = dbo.invoicereport; + + _.each( data, function ( p ) { + vm.forecastThisYear( vm.forecastThisYear() + Number( p.forecastThisYear.replace( '.', '' ) ) ); + vm.forecastOtherYears( vm.forecastOtherYears() + Number( p.forecastOtherYears.replace( '.', '' ) ) ); + vm.forecastRemaining( vm.forecastRemaining() + Number( p.forecastRemaining.replace( '.', '' ) ) ); + } ); + vm.forecastThisYear( dbo.helpers.thousandSeparator( vm.forecastThisYear() ) ); + vm.forecastOtherYears( dbo.helpers.thousandSeparator( vm.forecastOtherYears() ) ); + vm.forecastRemaining( dbo.helpers.thousandSeparator( vm.forecastRemaining() ) ); + }, + + setForecastMonthsTotals: function ( data ) { + var vm = dbo.invoicereport; + + _.each( data, function ( p ) { + _.each( p.forecastMonths(), function ( q ) { + vm.forecastMonths( vm.forecastMonths() + q ); + } ); + } ); + }, + + checkYear: function () { + var vm = dbo.invoicereport; + if ( !Number.isInteger( Number( vm.selectedYear() ) ) ) return vm.validYear( false ); + if ( Number( vm.selectedYear() ) > 2100 ) return vm.validYear( false ); + if ( Number( vm.selectedYear() ) < 2000 ) return vm.validYear( false ); + vm.validYear( true ); + + vm.initModule(); + }, + + setActivetab: function ( page ) { + var vm = dbo.invoicereport; + + vm.invoiceTab( page ); + }, + + Monthforecast: function ( data ) { + var vm = dbo.invoicereport; + var self = this; + self.projectname = data.projectname; + self.customer = data.customer; + self.needInvoice = data.needInvoice; + self.forecastOtherYears = data.forecastOtherYears; + self.forecastRemaining = data.forecastRemaining; + + self.forecastMonths = ko.observableArray( [] ); + _.each( data.forecastMonths, function ( p, i ) { + self.forecastMonths.push( new vm.ForecastMonth( p ) ); + _.each( vm.monthTotals(), function ( q ) { + if ( q.monthID == i ) q.forecastamount( Number( q.forecastamount() ) + p.forecastamount ); + } ); + } ); + }, + + ForecastMonth: function ( data ) { + this.forecastamount = dbo.helpers.thousandSeparator( data.forecastamount ); + }, + + Monthpayment: function ( data ) { + var vm = dbo.invoicereport; + var self = this; + self.projectname = data.projectname; + self.customer = data.customer; + self.totalProjectPayments = data.totalProjectPayments; + + self.paymentMonths = ko.observableArray( [] ); + _.each( data.monthPayments, function ( p, i ) { + self.paymentMonths.push( new vm.PaymentMonth( p ) ); + _.each( vm.monthPaymentTotals(), function ( q ) { + if ( q.monthID == i ) q.paymentamount( Number( q.paymentamount() ) + p.paymentamount ); + } ); + } ); + }, + + PaymentMonth: function ( data ) { + this.paymentamount = dbo.helpers.thousandSeparator( data.paymentamount ); + }, + + createSpreadsheet:function(){ + var vm = dbo.invoicereport; + dbo.invoiceDataService.createSpreadsheet(vm.selectedYear()); + } + } + + dbo.invoicereport.init(); + + ko.applyBindings( + dbo.invoicereport, document.getElementById( "INVOICEREPORT" ) ); + + + } + + +} \ No newline at end of file diff --git a/public/js/lib/modules/reports/outgoingInvoices.js b/public/js/lib/modules/reports/outgoingInvoices.js deleted file mode 100644 index 90e00f4..0000000 --- a/public/js/lib/modules/reports/outgoingInvoices.js +++ /dev/null @@ -1,160 +0,0 @@ -/** - * Created by Pensare Software. - * User: Theo Weijmer - * Date: 02/03/2018 - * Time: 11:43 - */ - - -dbo.outgoinginvoicesInit = function () { - - if ( dbo.outgoinginvoicesModel !== undefined ) { - - - } else { - dbo.outgoinginvoicesModel = { - - initialize : null, - years : ko.observableArray( [] ), - selectedYear : ko.observable(), - selectedMonthID : ko.observable(), - projects : ko.observableArray( [] ), - invoiceTab : ko.observable( 'invoice' ), - months : ko.observableArray( dbo.monthArray ), - totalToInvoice : ko.observable(), - totalToInvoiceFuture: ko.observable(), - initialize : null, - validYear : ko.observable(), - totalToInvoice : ko.observable(), - totalCurrentforecast: ko.observable(), - totalOtherforecast : ko.observable(), - totalMissingForecast: ko.observable(), - - init: function () { - var vm = dbo.outgoinginvoicesModel; - - vm.selectedYear( (new Date()).getFullYear() ); - vm.selectedMonthID( 0 ); - vm.validYear( true ); - - vm.initModule(); - }, - - setActivetab: function ( tab ) { - var vm = dbo.outgoinginvoicesModel; - - vm.invoiceTab( tab ); - }, - - initModule: function () { - var vm = dbo.outgoinginvoicesModel; - - vm.refreshInvoiceDetails(); - }, - - checkYear: function () { - var vm = dbo.outgoinginvoicesModel; - if ( !Number.isInteger( Number( vm.selectedYear() ) ) ) return vm.validYear( false ); - if ( Number( vm.selectedYear() ) > 2100 ) return vm.validYear( false ); - if ( Number( vm.selectedYear() ) < 2000 ) return vm.validYear( false ); - vm.validYear( true ); - - vm.initModule(); - }, - - refreshInvoiceDetails: function () { - var vm = dbo.outgoinginvoicesModel; - - vm.resetModel(); - - if ( vm.initialize ) return; - - dbo.invoiceDataService.getInvoiceOverview( vm.selectedYear(), function ( data ) { - vm.projects.removeAll(); - _.each( data, function ( p ) { - vm.projects.push( new vm.Project( p ) ); - } ); - vm.totalToInvoice( dbo.helpers.numberWithPoints( Math.round( vm.totalToInvoice() ) ) ); - vm.totalToInvoiceFuture( dbo.helpers.numberWithPoints( Math.round( vm.totalToInvoiceFuture() ) ) ); - vm.totalCurrentforecast( dbo.helpers.numberWithPoints( Math.round( vm.totalCurrentforecast() ) ) ); - vm.totalOtherforecast( dbo.helpers.numberWithPoints( Math.round( vm.totalOtherforecast() ) ) ); - vm.totalMissingForecast( dbo.helpers.numberWithPoints( Math.round( vm.totalMissingForecast() ) ) ); - } ); - }, - - resetModel: function () { - var vm = dbo.outgoinginvoicesModel; - vm.totalToInvoice( 0 ); - vm.totalToInvoiceFuture( 0 ); - vm.totalCurrentforecast( 0 ); - vm.totalOtherforecast( 0 ); - vm.totalMissingForecast( 0 ); - }, - - Project: function ( data ) { - var vm = dbo.outgoinginvoicesModel; - var self = this; - var openstaand = data.revenues - (Number( data.currentyear ) + Number( data.otheryear )); - var totalInvoice = data.revenues * (1 + (data.vatrate / 100)); - var totalInvoiced = Math.round( data.currentyear ) + Math.round( data.otheryear ); - var totalInvoicedPayed = Math.round( data.currentyearpayed ) + Math.round( data.otheryearpayed ); - var notPayed = totalInvoiced - totalInvoicedPayed; - - self.projectnumber = data.projectnumber; - self.customername = data.customername; - self.statusProject = Math.abs( openstaand ) > 2 ? 'OPEN' : 'CLOSED'; - self.fullname = data.fullname; - self.revenues = dbo.helpers.numberWithPoints( Number(data.revenues).toFixed(0) ); - self.totalInvoice = dbo.helpers.numberWithPoints( Number(totalInvoice).toFixed(0) ); - self.openstaand = dbo.helpers.numberWithPoints( Math.round( openstaand ) ); - self.openstaandIncl = dbo.helpers.numberWithPoints( Math.round( openstaand * 1.21 ) ); - self.invoicedOtherYears = dbo.helpers.numberWithPoints( Math.round( data.otheryear ) ); - self.invoicedCurentYear = dbo.helpers.numberWithPoints( Math.round( data.currentyear ) ); - self.totalInvoiced = dbo.helpers.numberWithPoints( totalInvoiced ); - self.invoicedOtherYearsPayed = dbo.helpers.numberWithPoints( Math.round( data.otheryearpayed ) ); - self.invoicedCurentYearPayed = dbo.helpers.numberWithPoints( Math.round( data.currentyearpayed ) ); - self.totalInvoicedPayed = dbo.helpers.numberWithPoints( Math.round( totalInvoicedPayed ) ); - self.notPayed = dbo.helpers.numberWithPoints( Math.round( notPayed ) ); - self.toInvoice = dbo.helpers.numberWithPoints( Math.round( totalInvoice - totalInvoiced ) ); - self.toInvoiceFuture = dbo.helpers.numberWithPoints( Math.round( totalInvoice - totalInvoiced - Number( data.currentforecast ) ) ); - self.currentforecast = dbo.helpers.numberWithPoints( Math.round( data.currentforecast ) ); - self.otherforecast = dbo.helpers.numberWithPoints( Math.round( data.otherforecast ) ); - var missingForcast = Math.round( totalInvoice - totalInvoiced - data.otherforecast - data.currentforecast ); - console.log( missingForcast ); - self.missingForecast = dbo.helpers.numberWithPoints( missingForcast ); - - self.months = ko.observableArray( [] ); - _.each( data.months, function ( p ) { - self.months.push( new vm.Month( p ) ); - - if ( !vm['forecast' + p.month] ) vm['forecast' + p.month] = ko.observable( 0 ); - vm['forecast' + p.month]( Number( vm['forecast' + p.month]() ) + Number( p.forecastamount ) ); - - if ( !vm['payment' + p.month] ) vm['payment' + p.month] = ko.observable( 0 ); - vm['payment' + p.month]( Number( vm['payment' + p.month]() ) + Number( p.paymentamount ) ); - } ); - - - vm.totalToInvoice( vm.totalToInvoice() + (totalInvoice - totalInvoiced) ); - vm.totalToInvoiceFuture( vm.totalToInvoiceFuture() + (totalInvoice - totalInvoiced - Number( data.currentforecast )) ); - vm.totalCurrentforecast( Number( vm.totalCurrentforecast() ) + Number( data.currentforecast ) ); - vm.totalOtherforecast( Number( vm.totalOtherforecast() ) + Number( data.otherforecast ) ); - vm.totalMissingForecast( Number( vm.totalMissingForecast() ) + Number( missingForcast ) ); - }, - - Month: function ( data ) { - this.forecastamount = dbo.helpers.numberWithPoints( Number( data.forecastamount ).toFixed( 0 ) ); - this.paymentamount = dbo.helpers.numberWithPoints( Number( data.paymentamount ).toFixed( 0 ) ); - } - } - - dbo.outgoinginvoicesModel.init(); - - ko.applyBindings( - dbo.outgoinginvoicesModel, document.getElementById( "OUTGOINGINVOICES" ) ); - - - } - - -} \ No newline at end of file