select('m_proyek.*', 'm_type_proyek.is_multiLocation') ->get(); foreach ($projects as $project) { if ($project->is_multiLocation == 1) { // untuk project multi location $versionGantt = VersionGantt::join('m_proyek', 'm_version_gantt.proyek_id', 'm_proyek.id') ->select('m_version_gantt.*') ->where('m_version_gantt.proyek_id', $project->id) ->get(); foreach ($versionGantt as $key => $gantt) { $progress[$key] = $gantt->progress; } $actualProgress = round(array_sum($progress) / count($versionGantt), 2); } else { // untuk project single location $gantt = MasterFunctionsHelper::getLatestGantt($project->id); isset($gantt['last_gantt_id']) ? $lastGantt = $gantt['last_gantt_id'] : $lastGantt = 0; $arr = [ 'project_id' => $project->id, 'gantt_id' => $lastGantt, 'periode' => 'week' ]; $project->scurve = MasterFunctionsHelper::getSCurve(collect($arr)); $actualArray = $project->scurve[0]['data']['percentageReal']; $actualProgress = !empty($actualArray) ? round(end($actualArray), 2) : 0; } Project::where('id', $project->id)->update(['persentase_progress' => $actualProgress]); } } }