95 lines
2.4 KiB
PHP
95 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 30/07/2018
|
|
* Time: 10:48
|
|
*/
|
|
|
|
class MonthPaymentSheet {
|
|
|
|
const HEADERS = [
|
|
'A' => 'project',
|
|
'B' => 'klant',
|
|
'C' => 'januari',
|
|
'D' => 'februari',
|
|
'E' => 'maart',
|
|
'F' => 'april',
|
|
'G' => 'mei',
|
|
'H' => 'juni',
|
|
'I' => 'juli',
|
|
'J' => 'augustus',
|
|
'K' => 'september',
|
|
'L' => 'oktober',
|
|
'M' => 'november',
|
|
'N' => 'december',
|
|
'O' => 'Totaal betaald lopend boekjaar inc. btw'
|
|
];
|
|
|
|
const MONTH_COLUMNS = ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'];
|
|
|
|
private $invoiceForecast;
|
|
private $sheet;
|
|
private $row;
|
|
|
|
public function __construct( $invoiceForecast, $sheet )
|
|
{
|
|
$this->invoiceForecast = $invoiceForecast;
|
|
$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->invoiceForecast AS $project )
|
|
{
|
|
$this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] );
|
|
$this->sheet->setCellValue( 'B' . $this->row, $project['customer'] );
|
|
|
|
$columnCount = 0;
|
|
foreach ( $project['monthPayments'] as $month )
|
|
{
|
|
$column = self::MONTH_COLUMNS[ $columnCount ];
|
|
$forecast = $month['paymentamount'];
|
|
$this->sheet->setCellValue( $column . $this->row, $forecast );
|
|
$columnCount ++;
|
|
}
|
|
|
|
$formula = '=SUM(C'.$this->row.':N'.$this->row.')';
|
|
$this->sheet->setCellValue( 'O' . $this->row, $formula);
|
|
|
|
$this->row ++;
|
|
}
|
|
}
|
|
|
|
private function setTotals()
|
|
{
|
|
$lastRow = $this->row - 1;
|
|
foreach ( self::MONTH_COLUMNS as $column )
|
|
{
|
|
$this->sheet->setCellValue( $column . $this->row, '=SUM(' . $column . '2:' . $column . $lastRow . ')' );
|
|
}
|
|
$this->sheet->setCellValue( 'O' . $this->row, '=SUM(O2:O' . $lastRow . ')' );
|
|
}
|
|
|
|
} |