From 56194e5e942d45b66cd3ef2f281f05b427afd0d1 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 4 Aug 2022 16:57:08 +0700 Subject: [PATCH] bug fix --- app/Http/Controllers/ProjectController.php | 5 +- .../Controllers/ProjectPhaseController.php | 84 +++++++++++++++++++ app/Models/ProjectPhase.php | 17 ++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/ProjectPhaseController.php create mode 100644 app/Models/ProjectPhase.php diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index c9ea6a4..0bd3c42 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -212,6 +212,7 @@ class ProjectController extends Controller { $data = Project::orderBy('id', 'desc')->get(); $countData = $data->count(); + if(!$data) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); @@ -223,6 +224,7 @@ class ProjectController extends Controller $lastActivity = null; $scheduleHealth = "on-track"; $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); + if($rootActivity){ $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; $actualCost = $rootActivity->biaya_actual ?? 0; @@ -244,7 +246,7 @@ class ProjectController extends Controller $d->lastActivity = $lastActivity ?? "-"; $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); $d->scheduleHealth = $scheduleHealth; - + $d->plannedCost = $d->rencana_biaya; $d->actualCost = $actualCost; $d->costVariance = $costVariance; @@ -260,6 +262,7 @@ class ProjectController extends Controller $manpowers = User::count(); $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); $projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); + try { $projectsByPhase = DB::table('m_proyek') ->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) diff --git a/app/Http/Controllers/ProjectPhaseController.php b/app/Http/Controllers/ProjectPhaseController.php new file mode 100644 index 0000000..1dd1259 --- /dev/null +++ b/app/Http/Controllers/ProjectPhaseController.php @@ -0,0 +1,84 @@ +validate($request, [ + 'name' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + if(!ProjectPhase::create($data)) + return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id=="") + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + if(!$result = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id=="") + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + if(!$data = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); + + if(!$data->update($request->all())) + return response()->json(['status'=>'failed','message'=>'data project type failed updated!','code'=>400], 400); + + return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200); + } + + public function delete($id) + { + + if(!$data = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'data project phase not found!','code'=>400], 400); + + if(!$data->delete()) + return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_proyek_phase'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = ProjectPhase::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'failed get list project type, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + + } +} diff --git a/app/Models/ProjectPhase.php b/app/Models/ProjectPhase.php new file mode 100644 index 0000000..1a82a81 --- /dev/null +++ b/app/Models/ProjectPhase.php @@ -0,0 +1,17 @@ +