From 5c1567db0a76abb48ddc4e05fa8163e1e6165a38 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Wed, 19 Oct 2022 16:43:02 +0700 Subject: [PATCH] fix mindate --- app/Http/Controllers/DashboardBoDController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 315c0ca..6c952ef 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -130,15 +130,19 @@ class DashboardBoDController extends Controller $projects = Project::where('mulai_proyek', 'like', $year)->get(); foreach($projects as $project) { $project->scurve = $this->getSCurve($project->id); + try { if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) $return['warning'] += 1; elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) $return['behind-schedule'] += 1; elseif(@$project->scurve['difference'] == 0) $return['on-schedule'] += 1; + } catch (\Error $e) { + return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); + } } - return response()->json(['data' => $return], 200); + return response()->json(['data' => $return, 'q' => $projects], 200); } public function getTotalProjectScheduleHealthPerDivision($year = '%'){ @@ -326,7 +330,8 @@ class DashboardBoDController extends Controller if(!$alreadyHasReport) continue; - $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(); $begin = new \DateTime($minDate.' Monday'); $maxDate = DB::table('assign_material_to_activity as ama') @@ -379,15 +384,15 @@ class DashboardBoDController extends Controller $sumPercentageActual=0; foreach ($dataActualM as $keyActualM) { + try { $sumVolActual = DB::table('assign_material_to_activity') ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) ->where('activity_id', '=', $keyActualM->activity_id) ->groupBy('activity_id') ->first(); - try { $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - } catch (\DivisionByZeroError $e) { - return response()->json(['message' => $e->getMessage()]); + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage(), 'q' => $sumVolActual]); } }