From d7cda428444dd59f8b4e479e7dd8f7162516fef9 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Mon, 17 Oct 2022 21:12:11 +0700 Subject: [PATCH] division by zero catch --- app/Http/Controllers/ProjectController.php | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 24ba04b..023d3fd 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -282,7 +282,7 @@ class ProjectController extends Controller ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') ->get(); - } catch (\Exception $e) { + } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } try { @@ -291,7 +291,7 @@ class ProjectController extends Controller ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') ->groupBy('m_type_proyek.name') ->get(); - } catch (\Exception $e) { + } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } @@ -452,10 +452,14 @@ class ProjectController extends Controller $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; $dataTempPlan [$x]['duration'] = $keyPlanM->duration; $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; - $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; - $sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; - $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; - $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + try { + $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; + $sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; + $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; + $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } $x++; } @@ -476,11 +480,11 @@ class ProjectController extends Controller $dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; $dataTempReport [$w]['duration'] = $keyActualM->duration; $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; try { + $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; - } catch (\Exception $e) { + } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } $dataTempReport [$w]['totalacwp'] = $totalACWP; @@ -520,7 +524,7 @@ class ProjectController extends Controller }else{ $estimatedCost = ($totalRencanaBudget+0); } - } catch (\Exception $e) { + } catch (\DivisionByZeroError $e) { return response()->json([ 'message' => $e->getMessage(), "line" => 566, @@ -791,5 +795,6 @@ class ProjectController extends Controller return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); } + }