diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 4c7b9ba..669c670 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -157,6 +157,7 @@ class ActivityController extends Controller private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay) { $data = TemplateGantt::where('proyek_type_id', $type_proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); + dd($data); foreach($data as $objRow){ $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); $resultNew = Activity::create([ @@ -408,9 +409,20 @@ class ActivityController extends Controller $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); }else{ $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); - } + if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first()) + continue; + + $alreadyHasReport = DB::table('report_activity_material as a') + ->select('a.id') + ->join('m_activity as b', 'b.id', '=', 'a.activity_id') + ->where('b.version_gantt_id', '=', $keyGantt['last_gantt_id']) + ->exists(); + + if(!$alreadyHasReport) + continue; + $minDate = DB::table('assign_material_to_activity as ama') ->where("ama.proyek_id", $keyGantt['proyek_id']) ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') @@ -422,7 +434,7 @@ class ActivityController extends Controller ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) ->max("plan_date"); - + $begin = new \DateTime($minDate); $end = new \DateTime($maxDate); $end2 = new \DateTime($maxDate); @@ -502,7 +514,11 @@ class ActivityController extends Controller $dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + try { + $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage()]); + } $dataTempReport [$w]['totalacwp'] = $totalACWP; $w++; } @@ -547,11 +563,22 @@ class ActivityController extends Controller } } - if(round($totalACWP,0) > $totalRencanaBudget){ - $estimatedCost = round($totalACWP,0)+0; - }else{ - $estimatedCost = ($totalRencanaBudget+0); - } + + try { + if(round($totalACWP,0) > $totalRencanaBudget){ + $estimatedCost = round($totalACWP,0)+0; + }else{ + $estimatedCost = ($totalRencanaBudget+0); + } + } catch (\Exception $e) { + return response()->json([ + 'message' => $e->getMessage(), + "line" => 566, + 'gantt' => $keyGantt, + ]); + } + //$estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; + $costDeviation = $totalRencanaBudget - $estimatedCost; if($costDeviation > 0){ $potential = "SAVING"; @@ -573,7 +600,7 @@ class ActivityController extends Controller "potential" => $potential, ) ); - + $dataFinal[] = array( "proyek_name"=> $dataProject->nama, "data"=>$dataResponse, @@ -581,15 +608,18 @@ class ActivityController extends Controller ); } + return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); } private function getLatestGantt($id){ - return array( - "last_gantt_id" => VersionGantt::where("proyek_id", $id)->latest(), - "proyek_id" => $id - ); + $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); + $data = array( + "last_gantt_id" => $maxGanttId, + "proyek_id" => $id + ); + return $data; } public function setBaseline($gantt_id)