@ -224,54 +224,6 @@ class ProjectController extends Controller
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$scheduleWarningThreshold = 10;
$scheduleDangerThreshold = 5;
foreach($data as $d){
$progress = $costVariance = $actualCost = 0;
$lastActivity = null;
$scheduleHealth = "on-track";
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first();
if($rootActivity){
$costVariance = (int)$d->rencana_biaya - (int)$rootActivity->biaya_actual;
$actualCost = $rootActivity->biaya_actual ?? 0;
$progress = $rootActivity->persentase_progress ?? 0;
$timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date);
$date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek)));
$date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date)));
$daysRemaining = $date2->diff($date1);
$daysRemaining = $daysRemaining->d;
if($daysRemaining < = $scheduleDangerThreshold) {
$scheduleHealth = "danger";
} elseif ($daysRemaining < = $scheduleWarningThreshold) {
$scheduleHealth = "warning";
}
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date));
}
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek));
$d->plannedCost = $d->rencana_biaya;
$d->actualCost = $actualCost;
$d->lastActivity = $lastActivity ?? "-";
$d->costVariance = $costVariance;
$d->costHealth = $d->budget_health;
$d->scheduleHealth = $scheduleHealth;
$d->progress = $progress;
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null;
$d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0;
$d->projectManager = DB::table('m_proyek')
->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id')
->where('m_proyek.id', $d->id)
->pluck('m_users.name')
->first();
if($d->area_kerja != ''){
$d->geolocation = $this->httpReq($d->area_kerja);
$d->geolocation = [];
} else {
$d->geolocation = [];
}
}
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost');
$manpowers = User::count();