Conversie codeigniter 4
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 29/07/2018
|
||||
* Time: 20:04
|
||||
*/
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class InvoiceSpreadsheet {
|
||||
|
||||
private $invoiceReport;
|
||||
private $spreadsheet;
|
||||
private $invoiceSheet;
|
||||
private $fullpathname;
|
||||
private $filename;
|
||||
private $ci;
|
||||
|
||||
public function __construct( $invoiceReport )
|
||||
{
|
||||
$this->ci =& get_instance();
|
||||
|
||||
$this->invoiceReport = $invoiceReport;
|
||||
|
||||
$this->ci->load->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 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user