From 3b3129d5b71270fdb7d8b355576f58c96556a902 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Wed, 24 Aug 2022 02:36:41 +0700 Subject: [PATCH] bug fix --- app/Models/Activity.php | 14 +++++++------- app/Models/AssignMaterial.php | 18 ------------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 1f01083..0753d20 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -57,6 +57,10 @@ class Activity extends Model private function updateBobot() { + $rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id) + ->where("proyek_id", $this->proyek_id) + ->where('type_activity', 'header') + ->first(); if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0) { $totalCost = Activity::select( DB::raw('sum(cast(rencana_biaya as double precision))') @@ -72,10 +76,6 @@ class Activity extends Model ->where("parent_id", $rootActivity->id) ->first(); } - $rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id) - ->where("proyek_id", $this->proyek_id) - ->where('type_activity', 'header') - ->first(); if($totalCost->sum > 0){ @@ -130,9 +130,9 @@ class Activity extends Model public function getJobsDoneAttribute() { $tmpPercentage = []; - if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) - return 0; - if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) + if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) + return 0; + if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) return 0; foreach ($dataPlan as $value) { $tmpPercentage[] = 100; diff --git a/app/Models/AssignMaterial.php b/app/Models/AssignMaterial.php index e3957a8..597f430 100644 --- a/app/Models/AssignMaterial.php +++ b/app/Models/AssignMaterial.php @@ -29,32 +29,14 @@ class AssignMaterial extends Model static::created(function($data) { $activity = Activity::find($data->activity_id); $material = RequestMaterial::where("id", $data->material_id)->first(); - $old = $activity->rencana_biaya; $activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); $activity->save(); - - $msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL; - $msg .= "Added: ".$material->desc." (".floatval($material->price)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | +".$activity->rencana_biaya.PHP_EOL; - $msg .= "Data type (".gettype(floatval($material->price))." * ".gettype(floatval($material->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL; - $msg .= "Data type origin (".gettype($material->price)." * ".gettype($material->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL; - $msg .= "------".PHP_EOL; - file_put_contents('activity_log.txt', $msg, FILE_APPEND | LOCK_EX); - }); static::deleted(function($data) { $activity = Activity::where('id', $data->activity_id)->first(); - $old = $activity->rencana_biaya; $activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); $activity->save(); - $material = RequestMaterial::where("id", $data->material_id)->first(); - - $msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL; - $msg .= "Deleted: ".$material->desc." (".floatval($data->budget)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | -".$activity->rencana_biaya.PHP_EOL; - $msg .= "Data type (".gettype(floatval($data->budget))." * ".gettype(floatval($data->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL; - $msg .= "Data type origin (".gettype($data->budget)." * ".gettype($data->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL; - $msg .= "------".PHP_EOL; - file_put_contents('activity_log.txt', $msg, FILE_APPEND | LOCK_EX); }); }