From 9503d9e6c6c146a54eff450ddf364d48acfc184b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 20 Feb 2023 12:41:20 +0700 Subject: [PATCH] Handling if cost planning < 0 --- app/Models/Activity.php | 7 +++++++ app/Models/UserToActivity.php | 3 +++ 2 files changed, 10 insertions(+) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 9be182c..7ee841a 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -127,6 +127,13 @@ class Activity extends Model if($parent = Activity::find($this->parent_id)){ $parentActWeight = $parent->bobot_planning; + if ($parentActWeight == 0) { + $parent->update([ + "persentase_progress" => 0 + ]); + return; + } + $totalChildProportionalProgress = 0; $childs = Activity::where("parent_id", $parent->id)->get(); foreach($childs as $child){ diff --git a/app/Models/UserToActivity.php b/app/Models/UserToActivity.php index 3dac828..a33667c 100644 --- a/app/Models/UserToActivity.php +++ b/app/Models/UserToActivity.php @@ -50,6 +50,9 @@ class UserToActivity extends Model } $activity->rencana_biaya -= $salary; + if ($activity->rencana_biaya < 0) { + $activity->rencana_biaya = 0; + } $activity->save(); });