From 8608510f6e3758e87df9eb8a33e32804aa89398e Mon Sep 17 00:00:00 2001 From: satori Date: Wed, 27 Jul 2022 02:47:14 +0700 Subject: [PATCH] bug fix --- app/Http/Controllers/ActivityController.php | 36 ++++++++++---------- app/Models/.Activity.php.swp | Bin 0 -> 20480 bytes app/Models/Activity.php | 23 +++++++------ 3 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 app/Models/.Activity.php.swp diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 9c384c8..4c7b9ba 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -1,5 +1,4 @@ -count() == 0) { + if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) { $this->cloneTemplate($id, $proyek_id); } @@ -29,18 +28,20 @@ class ActivityController extends Controller private function getDataActivity($id) { - $dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first(); - $startDate = date_create($dataHeader->start_date); - $endDate = date_create($dataHeader->end_date); - $dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s"); - $dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s"); - $dataHeader->type = "project"; - $dataHeader->text = $dataHeader->name; - $finalData[] = $dataHeader; - $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); - - if(Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count() == 0) - $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); + $checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count(); $finalData = []; + if($checkHeader > 0){ + $dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first(); + $startDate = date_create($dataHeader->start_date); + $endDate = date_create($dataHeader->end_date); + $dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s"); + $dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s"); + $dataHeader->type = "project"; + $dataHeader->text = $dataHeader->name; + $finalData[] = $dataHeader; + $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); + }else{ + $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); + } foreach($data as $objRow){ $type = "project"; @@ -117,7 +118,7 @@ class ActivityController extends Controller private function cloneTemplate($id, $proyek_id) { - $project = Project::findOrFail($proyek_id); + $project = Project::find($proyek_id); $rootActivity = Activity::create([ 'version_gantt_id'=>$id, @@ -126,7 +127,7 @@ class ActivityController extends Controller 'kode_sortname'=>$project->kode_sortname, 'start_date'=> $project->mulai_proyek, 'end_date'=> $project->akhir_proyek, - 'rencana_biaya'=> str_replace(".","", $project->rencana_biaya), + 'rencana_biaya'=> $project->rencana_biaya, 'type_activity'=> 'header', 'created_by'=>$this->currentName, ]); @@ -186,7 +187,6 @@ class ActivityController extends Controller $parent = $data['parent_id'] ?? null; if($parent){ - $this->updateTypeProject($parent); Activity::find($parent)->update(["type_activity"=>"project"]); CommentActivity::where('activity_id', $parent)->delete(); UserToActivity::where('activity_id', $parent)->delete(); diff --git a/app/Models/.Activity.php.swp b/app/Models/.Activity.php.swp new file mode 100644 index 0000000000000000000000000000000000000000..1f10603e10d65dac1b058a297422c9a500943daa GIT binary patch literal 20480 zcmeI2ZEPGz8ON8Dlw6>tFMMbvB&LUxyGvr9Q=pVf?dTG_G%0D_I7yM>aLnDUeQWRS zZgyvrI3biGM1znD;zepHl_*pKDN3aP6^IuJgoN5kln)@%B9&IH_)w4#&@U9e@PB4^ z_RZ(mPIxOCOTS!p=lwskGxIz%?a@Pf_OV+>wj21n#xOoL@lyN8x34ptlZGK&-=fzm z{Y^|x-+AEfsp0oEKR7*kx6El^l8;k{_2aI;5O};}2K6@YESOHW-ki91cvt*??s@fn zZr8Mfdb1;}W0qJP@p|6C4E0N`fL3623WQ>I_|~h9_uRaFloGtVd=tC=x`V4rt7B;e zv;tZIt$>3mHq$sw;RUm z;1%#P_!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/Activity.php index 01957ed..e3358b2 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -25,10 +25,10 @@ class Activity extends Model 'planned_start', 'planned_end', 'satuan_id', 'created_at', 'created_by', 'updated_at', 'updated_by' ]; - - protected $attributes = [ - 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' - ]; + // this piece of shit prepend column on create(), causing bugs + //protected $attributes = [ + // 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' + //]; protected $appends = [ 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' @@ -57,7 +57,7 @@ class Activity extends Model private function updateBobot() { - if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0) + 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))') ) @@ -65,17 +65,18 @@ class Activity extends Model ->where("version_gantt_id", $this->version_gantt_id) ->whereNull("parent_id") ->first(); - - $rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id) - ->where("proyek_id", $this->proyek_id) - ->where('type_activity', 'header') - ->first(); - + } else { $totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) ->where("proyek_id", $this->proyek_id) ->where("version_gantt_id", $this->version_gantt_id) ->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){ $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();