Spreadsheet
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?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->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 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user