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, ',', '.' ), ]; } }