From f4a3195ec597c2d77f1cc22eac4215059688f575 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 23 Feb 2023 16:38:01 +0700 Subject: [PATCH] Report date validation --- .../ReportActivityMaterialController.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index a4a120b..fd61e5f 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -23,18 +23,24 @@ class ReportActivityMaterialController extends Controller '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']); - - $created = ReportActivityMaterial::create($data); - - if(!$created) - return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null]); - - return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); + 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){