134 lines
2.9 KiB
PHP
134 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 29/07/2018
|
|
* Time: 10:19
|
|
*/
|
|
|
|
class Invoices {
|
|
|
|
private $year;
|
|
private $project;
|
|
private $projects;
|
|
private $monthPayment;
|
|
private $monthPayments;
|
|
private $monthForecast;
|
|
private $monthForecasts;
|
|
private $invoiceOverview;
|
|
private $invoiceForecast;
|
|
private $invoiceForecasts;
|
|
private $invoiceOverviews = [];
|
|
private $invoiceReport = [];
|
|
private $orderType;
|
|
private $orderDirection;
|
|
private $archive;
|
|
private $invoicedYears;
|
|
private $invoiced;
|
|
|
|
public function __construct( $year, $orderType, $orderDirection, $archive )
|
|
{
|
|
$this->year = $year;
|
|
$this->orderType = $orderType;
|
|
$this->orderDirection = $orderDirection;
|
|
$this->archive = $archive;
|
|
|
|
$this->handle();
|
|
}
|
|
|
|
public function getInvoiceReport()
|
|
{
|
|
return $this->invoiceReport;
|
|
}
|
|
|
|
private function handle()
|
|
{
|
|
$this->setProjects();
|
|
|
|
$this->loopProjects();
|
|
|
|
//only projects with payments also archived projects
|
|
$this->setMonthPayments();
|
|
|
|
$this->setInvoicedyears();
|
|
|
|
$this->setInvoiced();
|
|
|
|
$this->setInvoiceReport();
|
|
}
|
|
|
|
private function setProjects()
|
|
{
|
|
$this->projects =
|
|
Project::getProjectsForReport( $this->orderType, $this->orderDirection, $this->archive );
|
|
}
|
|
|
|
private function loopProjects()
|
|
{
|
|
foreach ( $this->projects as $this->project )
|
|
{
|
|
$this->setInvoiceOverview();
|
|
|
|
$this->setInvoiceForecasts();
|
|
|
|
$this->setMonthForecasts();
|
|
}
|
|
}
|
|
|
|
private function setInvoiceOverview()
|
|
{
|
|
$this->invoiceOverview = new InvoiceOverview( $this->project, $this->year );
|
|
|
|
$this->invoiceOverviews[] = $this->invoiceOverview->getProjectDetails();
|
|
}
|
|
|
|
private function setInvoiceForecasts()
|
|
{
|
|
$this->invoiceForecast =
|
|
new InvoiceForecast( $this->project, $this->invoiceOverview->getNeedinvoice(), $this->year );
|
|
|
|
$this->invoiceForecasts[] = $this->invoiceForecast->getProjectDetails();
|
|
}
|
|
|
|
public function setMonthForecasts()
|
|
{
|
|
$this->monthForecast =
|
|
new MonthForecast( $this->invoiceForecast, $this->project, $this->year );
|
|
|
|
$this->monthForecasts[] = $this->monthForecast->getProjectDetails();
|
|
}
|
|
|
|
public function setMonthPayments()
|
|
{
|
|
$monthPayment = new MonthPayments(
|
|
$this->year, $this->orderType, $this->orderDirection );
|
|
|
|
$this->monthPayments = $monthPayment->getProjectDetails();
|
|
}
|
|
|
|
private function setInvoiced()
|
|
{
|
|
$this->invoiced = Invoice::getInvoiced( $this->year, $this->orderType, $this->orderDirection );
|
|
}
|
|
|
|
private function setInvoicedYears()
|
|
{
|
|
$this->invoicedYears = Invoice::selectRaw( 'DATE_FORMAT(invoicedate, "%Y") AS years' )
|
|
->distinct()
|
|
->orderBy( 'invoicedate' )
|
|
->lists( 'years' );
|
|
}
|
|
|
|
private function setInvoiceReport()
|
|
{
|
|
$this->invoiceReport = [
|
|
'invoiceOverview' => $this->invoiceOverviews,
|
|
'forecasts' => $this->invoiceForecasts,
|
|
'monthForecasts' => $this->monthForecasts,
|
|
'monthPayments' => $this->monthPayments,
|
|
'invoicedYears' => $this->invoicedYears,
|
|
'invoiced' => $this->invoiced
|
|
];
|
|
}
|
|
}
|