Browse Source

adjust s-curve API

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
51672832d7
  1. 114
      app/Http/Controllers/ProjectController.php
  2. 10
      routes/web.php

114
app/Http/Controllers/ProjectController.php

@ -336,18 +336,20 @@ class ProjectController extends Controller
return $data; return $data;
} }
public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) public function getSCurve(Request $request)
{ {
DB::enableQueryLog(); DB::enableQueryLog();
$dataPayload = $request->all(); $dataPayload = $request->all();
/* print_r($dataPayload); exit(); */
$allGantt = []; $allGantt = [];
if(isset($dataPayload['gannt_id'])){
$allGantt = $dataPayload['gannt_id']; if(isset($dataPayload['gantt_id'])){
$allGantt = $dataPayload['gantt_id'];
}else{ }else{
foreach ($dataPayload['project_id'] as $val) { $allGantt[] = $this->getLatestGantt($dataPayload['project_id']);
$allGantt[] = $this->getLatestGantt($val);
}
} }
$dataFinal=[]; $dataFinal=[];
foreach ($allGantt as $keyGantt) { foreach ($allGantt as $keyGantt) {
$dataProject = Project::find($keyGantt['proyek_id']); $dataProject = Project::find($keyGantt['proyek_id']);
@ -376,21 +378,29 @@ class ProjectController extends Controller
->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->min("plan_date"); ->min("plan_date");
/* ->min("planned_Start"); */
$maxDate = DB::table('assign_material_to_activity as ama') $maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id']) ->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->max("plan_date"); ->max("planned_end");
/* ->whereNull('deleted_at') */
$begin = new \DateTime($minDate); /* ->get(); */
$end = new \DateTime($maxDate); /* ->max("plan_date"); */ // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$end2 = new \DateTime($maxDate); /* print_r($maxDate); exit(); */
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin->modify('-1 days'), $interval, $end); $begin = new \DateTime($minDate.' Monday');
$end = new \DateTime($maxDate. ' Friday');
$interval = new \DateInterval('P7D');
// timezone problems in KIT case also occurs in here
$period = new \DatePeriod($begin, $interval, $end);
/* $period = new \DatePeriod($begin->modify('-1 days'), $interval, $end); */
$arr_ActualM = []; $arr_ActualM = [];
$tempDate = []; $tempDate = [];
$tempPercentage = []; $tempPercentagePlan = [];
$tempPercentagePlanWhr = [];
$tempPercentageReal = [];
$tempTtlPercentPlan=0; $tempTtlPercentPlan=0;
$tempTtlPercentActual=0; $tempTtlPercentActual=0;
@ -482,9 +492,14 @@ class ProjectController extends Controller
$currentBCWP += $totalBCWP; $currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
$tempPercentageReal[] = round($tempTtlPercentActual, 2);
$tempDate[] = array($dt->format("Y-m-d"), 0, 0); $tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}else{ }else{
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); $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"), 0, 0);
} }
} }
@ -515,6 +530,8 @@ class ProjectController extends Controller
$dataResponse = array( $dataResponse = array(
"date" =>$tempDate, "date" =>$tempDate,
"percentage" =>$tempPercentage, "percentage" =>$tempPercentage,
"percentagePlan" => $tempPercentagePlan,
"percentageReal" => $tempPercentageReal,
"data_details" =>$arr_ActualM, "data_details" =>$arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget, "budget_control" =>array("current_budget"=> $totalRencanaBudget,
"acwp" => round($totalACWP,0), "acwp" => round($totalACWP,0),
@ -644,5 +661,74 @@ class ProjectController extends Controller
} }
} }
public function detail($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = Project::find($id);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$gantt = $this->getLatestGantt($id);
$result->projectManager = User::where('id', $result->pm_id)->value('name');
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first();
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
public function synchronizeReport($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$reports = [];
foreach($activities as $activity) {
$activity_id = $activity->id;
$countReports = ReportActivity::where('activity_id', $activity_id)->count();
if ($countReports === 1) {
$dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach($dataReports as $dr) {
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$dr->report_date,
'max_date'=>date_modify(date_create($dr->report_date), "1 days")
);
}
}
if ($countReports > 1) {
$firstReport = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->first();
$lastReport = ReportActivity::where('activity_id', $activity_id)->orderByDesc('report_date')->first();
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$firstReport->report_date,
'max_date'=>date_modify(date_create($lastReport->report_date), "1 days")
);
}
}
for ($i=0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']);
$activity->start_date = $reports[$i]['min_date'];
$activity->end_date = $reports[$i]['max_date'];
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
}
public function setBaseline($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
foreach ($activities as $activity) {
$activity->update([
"planned_start"=>$activity->start_date,
"planned_end"=>$activity->end_date,
]);
}
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200);
}
} }

10
routes/web.php

@ -56,16 +56,18 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/project/add', 'ProjectController@add'); $router->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update'); $router->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit'); $router->get('/project/edit/{id}', 'ProjectController@edit');
$router->get('/project/detail/{id}', 'ProjectController@detail');
$router->delete('/project/delete/{id}', 'ProjectController@delete'); $router->delete('/project/delete/{id}', 'ProjectController@delete');
$router->get('/project/list', 'ProjectController@list'); $router->get('/project/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');
$router->get('/project/synchronize-report/{gantt_id}', 'ProjectController@synchronizeReport');
$router->post('/project/get-s-curve', 'ProjectController@getSCurve'); $router->post('/project/get-s-curve', 'ProjectController@getSCurve');
/* $router->get('/project/get-progress/{id}/{date?}', 'ProjectController@getProgress'); */ /* $router->get('/project/get-progress/{id}/{date?}', 'ProjectController@getProgress'); */
/* $router->get('/project/get-acwp/{id}/{date?}', 'ProjectController@getACWP'); */ /* $router->get('/project/get-overdue-activities/{id}/{date?}', 'ProjectController@getOverdueActivities'); */
/* $router->get('/project/get-bcwp/{id}/{date?}', 'ProjectController@getBCWP'); */
/* $router->get('/project/get-expenditure/{id}/{date?}', 'ProjectController@getExpenditure'); */ /* $router->get('/project/get-expenditure/{id}/{date?}', 'ProjectController@getExpenditure'); */
/* $router->get('/project/get-total-expenditure/{id}', 'ProjectController@getTotalExpenditure'); */ /* $router->get('/project/get-total-expenditure/{id}', 'ProjectController@getTotalExpenditure'); */
/* $router->get('/project/get-overdue-activities/{id}/{date?}', 'ProjectController@getOverdueActivities'); */
/* $router->get('/project/get-status-health-schedule/{id}', 'ProjectController@getStatusSchedule'); */ /* $router->get('/project/get-status-health-schedule/{id}', 'ProjectController@getStatusSchedule'); */
/* $router->get('/project/get-status-health-budget/{id}', 'ProjectController@getStatusBudget'); */ /* $router->get('/project/get-status-health-budget/{id}', 'ProjectController@getStatusBudget'); */
@ -199,8 +201,6 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->put('/task/update-regular/{id}', 'ActivityController@updateRegular'); $router->put('/task/update-regular/{id}', 'ActivityController@updateRegular');
$router->delete('/task/{id}', 'ActivityController@delete'); $router->delete('/task/{id}', 'ActivityController@delete');
$router->get('/task/get-update/{id}', 'ActivityController@getUpdate'); $router->get('/task/get-update/{id}', 'ActivityController@getUpdate');
$router->get('/activity/set-baseline/{gantt_id}', 'ActivityController@setBaseline');
$router->get('/activity/synchronize-report/{gantt_id}', 'ActivityController@synchronizeReport');
$router->post('/link', 'LinkController@add'); $router->post('/link', 'LinkController@add');
$router->put('/link/{id}', 'LinkController@update'); $router->put('/link/{id}', 'LinkController@update');

Loading…
Cancel
Save