diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 09afb5d..2dbe9c2 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -381,7 +381,9 @@ class ProjectController extends Controller /* ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') */ /* ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) */ /* ->min("plan_date"); */ - $minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->min("planned_start"); + /* $minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->min("planned_start"); */ + $minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->whereNull('parent_id')->pluck('start_date')->first(); + /* print_r($minDate); exit(); */ $begin = new \DateTime($minDate.' Monday'); if(isset($dataPayload['end_date'])){ @@ -402,7 +404,6 @@ class ProjectController extends Controller $arr_ActualM = []; $tempDate = []; - $tempPercentage = []; $tempPercentagePlan = []; $tempPercentagePlanWhr = []; $tempPercentageReal = []; @@ -415,6 +416,7 @@ class ProjectController extends Controller /* foreach($period as $x){ */ /* echo $x->format("Y-m-d")."\n"; */ /* } exit(); */ + foreach ($period as $dt) { $minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); @@ -532,27 +534,27 @@ class ProjectController extends Controller } /* print_r($tempDate); exit(); */ - /* try { */ - /* if(round($totalACWP,0) > $totalRencanaBudget){ */ - /* $estimatedCost = round($totalACWP,0)+0; */ - /* }else{ */ - /* $estimatedCost = ($totalRencanaBudget+0); */ - /* } */ - /* } catch (\DivisionByZeroError $e) { */ - /* return response()->json([ */ - /* 'message' => $e->getMessage(), */ - /* "line" => 566, */ - /* 'gantt' => $keyGantt, */ - /* ]); */ - /* } */ - /* $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; */ - - /* $costDeviation = $totalRencanaBudget - $estimatedCost; */ - /* if($costDeviation > 0){ */ - /* $potential = "SAVING"; */ - /* } else { */ - /* $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; */ - /* } */ + try { + if(round($totalACWP,0) > $totalRencanaBudget){ + $estimatedCost = round($totalACWP,0)+0; + }else{ + $estimatedCost = ($totalRencanaBudget+0); + } + } catch (\DivisionByZeroError $e) { + return response()->json([ + 'message' => $e->getMessage(), + "line" => 566, + 'gantt' => $keyGantt, + ]); + } + $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; + + $costDeviation = $totalRencanaBudget - $estimatedCost; + if($costDeviation > 0){ + $potential = "SAVING"; + } else { + $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; + } $dataResponse = array( "date" =>$tempDate, @@ -565,9 +567,9 @@ class ProjectController extends Controller "bcwp" => round($totalBCWP,0), "rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), "add_cost_to_complete" => 0, - /* "estimated_at_completion" => $estimatedCost, */ - /* "cost_deviation" => $costDeviation, */ - /* "potential" => $potential, */ + "estimated_at_completion" => $estimatedCost, + "cost_deviation" => $costDeviation, + "potential" => $potential, ) );