Files
2026-01-12 17:30:36 +01:00

134 lines
3.0 KiB
PHP

<?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;
public function __construct( $invoiceReport )
{
$this->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 );
}
}