invoiceReport = $invoiceReport; helper('download'); $this->handle(); } private function handle() { $this->setSpreadsheet(); $this->setInvoiceOverviewSheet(); $this->setInvoiceForecast(); $this->setMonthForecast(); $this->setMonthPayment(); $this->setInvoiced(); $this->setFilename(); $this->setFullPathname(); $this->createFile(); $this->downloadSpreadsheet(); } private function setSpreadsheet() { $this->spreadsheet = new Spreadsheet(); } private function setInvoiceOverviewSheet() { $invoiceSheet = new Worksheet( $this->spreadsheet, 'Facturen' ); $this->invoiceSheet = $this->spreadsheet->addSheet( $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 setInvoiced() { $invoiceSheet = new Worksheet( $this->spreadsheet, 'verstuurde facturen' ); $this->invoiceSheet = $this->spreadsheet->addSheet( $invoiceSheet ); new InvoicedSheet( $this->invoiceReport['invoiced'], $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 ); } }