project = $project; $this->invoiceForecast = $invoiceForecast; $this->year = $year; $this->handle(); } public function getProjectDetails() { return $this->projectDetails; } private function handle() { $this->setProjectname(); $this->setCustomer(); $this->setInitialsForecastMonths(); $this->loopForecasts(); $this->setProjectDetails(); } private function setProjectname() { $this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')'; } private function setCustomer() { $this->customer = $this->project->customer->name; } private function setInitialsForecastMonths() { for ( $i = 0; $i < 12; $i ++ ) { $this->forecastMonths[ $i ] = ['forecastamount' => 0]; } } private function loopForecasts() { foreach ( $this->project->forecasts as $this->forecast ) { $this->setMonthForecast(); } } private function setMonthForecast() { if ( $this->forecast->year == $this->year ) $this->forecastMonths[ $this->forecast->month_id ]['forecastamount'] += $this->forecast->forecastamount; } private function setProjectDetails() { $this->projectDetails = [ 'projectname' => $this->projectname, 'customer' => $this->customer, 'needInvoice' => number_format( $this->invoiceForecast->getNeedInvoice(), 0, ',', '.' ), 'forecastOtherYears' => number_format( $this->invoiceForecast->getForecastOtherYear(), 0, ',', '.' ), 'forecastRemaining' => number_format( $this->invoiceForecast->getForecastRemaining(), 0, ',', '.' ), 'forecastMonths' => $this->forecastMonths ]; } }