From 15040d01ed403f066713f2c5b24f30853409db23 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Mon, 17 Oct 2022 03:38:16 +0700 Subject: [PATCH] recalc s-curve date & api overdue activities --- app/Http/Controllers/ProjectController.php | 81 ++++++++++++++-------- routes/web.php | 2 +- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 3b930a1..1351b7a 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -374,30 +374,29 @@ class ProjectController extends Controller if(!$alreadyHasReport) continue; - $minDate = DB::table('assign_material_to_activity as ama') - ->where("ama.proyek_id", $keyGantt['proyek_id']) - ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') - ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) - ->min("plan_date"); - /* ->min("planned_Start"); */ - - $maxDate = DB::table('assign_material_to_activity as ama') - ->where("ama.proyek_id", $keyGantt['proyek_id']) - ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') - ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) - ->max("plan_date"); - /* ->whereNull('deleted_at') */ - /* ->get(); */ - /* ->max("plan_date"); */ // plan date overlapped with assign_material_to_activity's, it should be m_activity's - /* print_r($maxDate); exit(); */ - - $begin = new \DateTime($minDate.' Friday'); - /* print_r($begin); exit(); */ - $end = new \DateTime($maxDate); - $interval = new \DateInterval('P1W'); - // timezone problems in KIT case also occurs in here + /* $minDate = DB::table('assign_material_to_activity as ama') */ + /* ->where("ama.proyek_id", $keyGantt['proyek_id']) */ + /* ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') */ + /* ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) */ + /* ->min("plan_date"); */ + $minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->min("planned_start"); + + $begin = new \DateTime($minDate.' Monday'); + if(isset($dataPayload['end_date'])){ + $maxDate = $dataPayload['end_date']; + $end = new \DateTime($maxDate); + $interval = \DateInterval::createFromDateString('1 day'); + } else { + $maxDate = DB::table('assign_material_to_activity as ama') + ->where("ama.proyek_id", $keyGantt['proyek_id']) + ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) + ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's + $end = new \DateTime($maxDate. ' Friday'); + $interval = new \DateInterval('P7D'); + } $period = new \DatePeriod($begin, $interval, $end); - /* $period = new \DatePeriod($begin->modify('-1 days'), $interval, $end); */ + $arr_ActualM = []; $tempDate = []; $tempPercentagePlan = []; @@ -409,10 +408,12 @@ class ProjectController extends Controller $currentACWP = 0; $currentBCWP = 0; - /* foreach($period as $x){ */ - /* echo $x->format("Y-m-d")."\n"; */ - /* } exit(); */ + foreach($period as $x){ + echo $x->format("Y-m-d")."\n"; + } exit(); foreach ($period as $dt) { + $minSevenDays = new \Datetime($dt->format("Y-m-d")); + $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); $dataPlanM = DB::table('assign_material_to_activity as ama') ->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') @@ -420,7 +421,7 @@ class ProjectController extends Controller ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) /* ->whereDate('ama.plan_date', $dt->format("Y-m-d")) */ ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) - ->whereDate('ama.plan_date', '>',$dt->modify('-7 day')->format("Y-m-d")) + ->whereDate('ama.plan_date', '>', $minSevenDays) ->get(); $dataActualM = DB::table('report_activity_material as ram') ->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') @@ -428,7 +429,7 @@ class ProjectController extends Controller ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) ->where('a.proyek_id', '=', $keyGantt['proyek_id']) ->whereDate('ram.report_date', '<=',$dt->format("Y-m-d")) - ->whereDate('ram.report_date', '>',$dt->modify('-7 day')->format("Y-m-d")) + ->whereDate('ram.report_date', '>',$minSevenDays) ->get(); $dataTempPlan = []; $x = 0; @@ -503,14 +504,14 @@ class ProjectController extends Controller $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; $tempPercentageReal[] = round($tempTtlPercentActual, 2); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); }else{ $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); $tempPercentagePlan[] = round($sumPercentagePlan, 2); $tempPercentageReal[] = round($sumPercentageActual, 2); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); } + $tempDate[] = array($dt->format("Y-m-d")); } + /* print_r($tempDate); exit(); */ try { @@ -740,5 +741,25 @@ class ProjectController extends Controller return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200); } + public function getOverdueActivities(Request $request){ + $payload = $request->all(); + if(empty($payload['id']) || !is_int((int)$payload['id'])) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $result = Project::find($payload['id']); + + if(!$result) + return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); + + if(isset($payload['till_date'])) + $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); + else + $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); + + $result->overdueActivities = $overdueActivities; + + return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + } + } diff --git a/routes/web.php b/routes/web.php index affecf1..21f880e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -63,8 +63,8 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/project/synchronize-report/{gantt_id}', 'ProjectController@synchronizeReport'); $router->post('/project/get-s-curve', 'ProjectController@getSCurve'); + $router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities'); /* $router->get('/project/get-progress/{id}/{date?}', 'ProjectController@getProgress'); */ - /* $router->get('/project/get-overdue-activities/{id}/{date?}', 'ProjectController@getOverdueActivities'); */ /* $router->get('/project/get-expenditure/{id}/{date?}', 'ProjectController@getExpenditure'); */ /* $router->get('/project/get-total-expenditure/{id}', 'ProjectController@getTotalExpenditure'); */