From d69de496bdea39a0093529fd5dc4291dce504d9c Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 10 Oct 2023 09:25:24 +0700 Subject: [PATCH 1/3] fix endline --- .../ReportActivityMaterialController.php | 304 +++++++++--------- 1 file changed, 152 insertions(+), 152 deletions(-) diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index 86cb638..94edcb4 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -1,152 +1,152 @@ -validate($request, [ - 'activity_id' => 'required', - 'qty' => 'required' - ]); - - $activity = Activity::where('id', $request->activity_id)->first(); - - $start_date = $activity->start_date; - $start_date = substr($start_date, 0, 19); // remove the timezone offset - $startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); - $reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date))); - - $data = $request->all(); - $data['created_by'] = $this->currentName; - /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ - $data['assign_material_id'] = $request->assign_material_id; - $data['qty'] = $this->sanitizeDecimal($data['qty']); - if($reportDate >= $startDate){ - $created = ReportActivityMaterial::create($data); - return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); - } else { - return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400); - } - } - - public function updateStatusStartFinish(Request $request){ - - $payloadUpdate = array( - 'start_activity' => $request->start_activity, - 'finish_activity' => $request->finish_activity, - 'status_activity' => $request->status_activity - ); - $updateData = AssignMaterial::where('activity_id',$request->activity_id) - ->update($payloadUpdate); - if($updateData){ - if($request->status_activity == 'done'){ - $dataUpdate = array( - "persentase_progress" => 100, - "updated_by" => $this->currentName - ); - Activity::where('id', $request->activity_id)->update($dataUpdate); - } else { - $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); - $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); - $dataUpdate = array( - "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, - "updated_by" => $this->currentName - ); - Activity::where('id', $request->activity_id)->update($dataUpdate); - } - - return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]); - } - else{ - return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]); - } - } - - public function delete($id) - { - if(!ReportActivityMaterial::findOrFail($id)->delete()) - return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200); - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'report_activity_material'); - $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 = ReportActivityMaterial::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, please try again later!','code'=>400], 400); - } - } - - public function datatables(Request $request){ - $id_activity = $request->query('idAct'); - $type = $request->query('type'); - $materialName = $request->query('materialName'); - if($type == 'plan'){ - $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") - ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") - ->where('assign_material_to_activity.activity_id', $id_activity) - ->where('m.description', $materialName) - ->orderBy('assign_material_to_activity.id', 'asc') - ->get(); - return Datatables::of($data) - ->addIndexColumn() - ->addColumn('action', function($row){ - $actionBtn = ''; - if ($row->status_activity != 'done') { - $actionBtn .= ''; - } - return $actionBtn; - }) - ->rawColumns(['action'])->make(true); - }else{ - $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity") - ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") - ->join("m_req_material as m", "m.id", "=", "amta.material_id") - ->join("m_users as u", "u.id", "=", "report_activity_material.user_id") - ->where('report_activity_material.activity_id', $id_activity) - ->where('m.description', $materialName) - ->orderBy('report_activity_material.report_date', 'asc') - ->get(); - return Datatables::of($data) - ->addIndexColumn() - ->addColumn('action', function($row){ - $actionBtn = ''; - if ($row->status_activity != 'done') { - $actionBtn .= ''; - } - return $actionBtn; - }) - ->rawColumns(['action'])->make(true); - } - } -} +validate($request, [ + 'activity_id' => 'required', + 'qty' => 'required' + ]); + + $activity = Activity::where('id', $request->activity_id)->first(); + + $start_date = $activity->start_date; + $start_date = substr($start_date, 0, 19); // remove the timezone offset + $startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); + $reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date))); + + $data = $request->all(); + $data['created_by'] = $this->currentName; + /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ + $data['assign_material_id'] = $request->assign_material_id; + $data['qty'] = $this->sanitizeDecimal($data['qty']); + if($reportDate >= $startDate){ + $created = ReportActivityMaterial::create($data); + return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); + } else { + return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400); + } + } + + public function updateStatusStartFinish(Request $request){ + + $payloadUpdate = array( + 'start_activity' => $request->start_activity, + 'finish_activity' => $request->finish_activity, + 'status_activity' => $request->status_activity + ); + $updateData = AssignMaterial::where('activity_id',$request->activity_id) + ->update($payloadUpdate); + if($updateData){ + if($request->status_activity == 'done'){ + $dataUpdate = array( + "persentase_progress" => 100, + "updated_by" => $this->currentName + ); + Activity::where('id', $request->activity_id)->update($dataUpdate); + } else { + $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); + $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); + $dataUpdate = array( + "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, + "updated_by" => $this->currentName + ); + Activity::where('id', $request->activity_id)->update($dataUpdate); + } + + return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]); + } + else{ + return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]); + } + } + + public function delete($id) + { + if(!ReportActivityMaterial::findOrFail($id)->delete()) + return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'report_activity_material'); + $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 = ReportActivityMaterial::all(); + $countData = $data->count(); + + if($data){ + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, please try again later!','code'=>400], 400); + } + } + + public function datatables(Request $request){ + $id_activity = $request->query('idAct'); + $type = $request->query('type'); + $materialName = $request->query('materialName'); + if($type == 'plan'){ + $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") + ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") + ->where('assign_material_to_activity.activity_id', $id_activity) + ->where('m.description', $materialName) + ->orderBy('assign_material_to_activity.id', 'asc') + ->get(); + return Datatables::of($data) + ->addIndexColumn() + ->addColumn('action', function($row){ + $actionBtn = ''; + if ($row->status_activity != 'done') { + $actionBtn .= ''; + } + return $actionBtn; + }) + ->rawColumns(['action'])->make(true); + }else{ + $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity") + ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") + ->join("m_req_material as m", "m.id", "=", "amta.material_id") + ->join("m_users as u", "u.id", "=", "report_activity_material.user_id") + ->where('report_activity_material.activity_id', $id_activity) + ->where('m.description', $materialName) + ->orderBy('report_activity_material.report_date', 'asc') + ->get(); + return Datatables::of($data) + ->addIndexColumn() + ->addColumn('action', function($row){ + $actionBtn = ''; + if ($row->status_activity != 'done') { + $actionBtn .= ''; + } + return $actionBtn; + }) + ->rawColumns(['action'])->make(true); + } + } +} From c49cbe48c8a0ead73044fa811b40af5ef206684f Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 10 Oct 2023 11:08:31 +0700 Subject: [PATCH 2/3] forcing report date --- app/Http/Controllers/ReportActivityMaterialController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index 94edcb4..eae0d86 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -35,11 +35,11 @@ class ReportActivityMaterialController extends Controller /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ $data['assign_material_id'] = $request->assign_material_id; $data['qty'] = $this->sanitizeDecimal($data['qty']); - if($reportDate >= $startDate){ + if($reportDate >= $startDate || isset($data['force']) && $data['force'] == "true"){ $created = ReportActivityMaterial::create($data); return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); } else { - return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400); + return response()->json(['status'=>'failed','message'=>'Report date is before early start, still wanna add data ?','code'=>400,'data'=>$data], 400); } } From e4b46f6d701a6ee141c0e8c2ed401afc63fa4193 Mon Sep 17 00:00:00 2001 From: wahyu Date: Tue, 10 Oct 2023 13:13:42 +0700 Subject: [PATCH 3/3] handle zero division --- app/Http/Controllers/ActivityController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index a516e9e..50ba368 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -431,10 +431,10 @@ class ActivityController extends Controller $duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd); if ($today >= $endDate) { $endDate = $today; - $rerataBobot = $activity->bobot_planning / $duration; + $rerataBobot = $duration > 0 ? $activity->bobot_planning / $duration : 0; $bobotActual = $activity->progress * $activity->bobot_planning; $sisaBobot = $activity->bobot_planning - $bobotActual; - $sisaHari = $sisaBobot / $rerataBobot; + $sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0; $endDate->modify("+".$sisaHari." Days"); $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); $activity->duration = $actualDuration;