Files
2026-01-09 11:41:28 +01:00

126 lines
3.0 KiB
PHP

<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/07/2018
* Time: 13:14
*/
class InvoiceForecast {
private $year;
private $project;
private $customer;
private $forecast;
private $currentYear;
private $projectname;
private $needInvoice;
private $projectDetails;
private $forecastThisYear = 0;
private $forecastRemaining;
private $forecastOtherYears = 0;
public function __construct( $project, $needInvoice, $year )
{
$this->project = $project;
$this->needInvoice = $needInvoice;
$this->year = $year;
$this->handle();
}
public function getProjectDetails()
{
return $this->projectDetails;
}
public function getNeedInvoice()
{
return $this->needInvoice;
}
public function getForecastOtherYear()
{
return $this->forecastOtherYears;
}
public function getForecastRemaining()
{
return $this->forecastRemaining;
}
private function handle()
{
$this->setCurrentyear();
$this->setProjectname();
$this->setCustomer();
$this->loopForecasts();
$this->setForecastRemaining();
$this->setProjectDetails();
}
private function setCurrentyear()
{
$this->currentYear = date( 'Y' );
}
private function setProjectname()
{
$this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')';
}
private function setCustomer()
{
$this->customer = $this->project->customer->name;
}
private function loopForecasts()
{
if ( is_null( $this->project->forecasts ) ) return $this->forecastThisYear = 0;
foreach ( $this->project->forecasts as $this->forecast )
{
$this->setForecastThisYear();
$this->setForecastOtherYears();
}
}
private function setForecastThisYear()
{
if ( $this->forecast->year == $this->year )
$this->forecastThisYear += $this->forecast->forecastamount;
}
private function setForecastOtherYears()
{
if ( $this->forecast->year != $this->year )
$this->forecastOtherYears += $this->forecast->forecastamount;
}
private function setForecastRemaining()
{
$this->forecastRemaining =
$this->needInvoice - $this->forecastThisYear - $this->forecastOtherYears;
}
private function setProjectDetails()
{
$this->projectDetails = [
'projectnumber' => $this->project->projectnumber,
'projectname' => $this->projectname,
'customer' => $this->customer,
'needInvoice' => number_format( $this->needInvoice, 0, ',', '.' ),
'forecastThisYear' => number_format( $this->forecastThisYear, 0, ',', '.' ),
'forecastOtherYears' => number_format( $this->forecastOtherYears, 0, ',', '.' ),
'forecastRemaining' => number_format( $this->forecastRemaining, 0, ',', '.' ),
];
}
}