static function makeWeightedValue($sale, $year) { $currentYear = $year; $startMonth = Carbon::parse($sale->started_at)->month; $startYear = Carbon::parse($sale->started_at)->year; $endMonth = Carbon::parse($sale->started_at)->addMonth($sale->duration - 1)->month; $endYear = Carbon::parse($sale->started_at)->addMonth($sale->duration - 1)->year; $values = []; $months = Sale::getMonthInYear($sale->started_at, $sale->duration, $currentYear); $val = $sale->values; if (count($val) > 0) { for ($i = 1; $i <= 12; $i++) { if (in_array($i, $months['val'])) { $keySearch = array_search($i, $months['val']); $position = $months['pos'][$keySearch]; array_push($values, array('hc' => $val[$position]->head_count * ($sale->probability / 100), 'value' => $val[$position]->value * ($sale->probability / 100))); } else { array_push($values, array('hc' => 0, 'value' => 0)); } } } else { for ($i = 1; $i <= 12; $i++) { array_push($values, array('hc' => 0, 'value' => 0)); } } return $values; }