From fc5c14eda093d9bd0d733b821ddc69b8a878f3d8 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Sat, 15 Oct 2022 23:23:02 +0700 Subject: [PATCH 1/7] remove unused codes --- app/Http/Controllers/ProjectController.php | 160 +++++++-------------- 1 file changed, 55 insertions(+), 105 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 4c18e2c..039ea7d 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -256,125 +256,75 @@ class ProjectController extends Controller $d->progress = $progress; $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; $d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; - $d->projectManager = DB::table('m_proyek') - ->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') - ->where('m_proyek.id', $d->id) - ->pluck('m_users.name') - ->first(); - if($d->area_kerja != ''){ - $d->geolocation = $this->httpReq($d->area_kerja); + $d->projectManager = DB::table('m_proyek') + ->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') + ->where('m_proyek.id', $d->id) + ->pluck('m_users.name') + ->first(); + if($d->area_kerja != ''){ + $d->geolocation = $this->httpReq($d->area_kerja); $d->geolocation = []; - } else { - $d->geolocation = []; - } - } + } else { + $d->geolocation = []; + } + } - $totalPlannedCost = $data->sum('plannedCost'); - $totalActualCost = $data->sum('actualCost'); + $totalPlannedCost = $data->sum('plannedCost'); + $totalActualCost = $data->sum('actualCost'); $manpowers = User::count(); $projectsOnDanger = Project::where('budget_health', 'danger')->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')) - ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') - ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') - ->get(); - } catch (\Exception $e) { - return response()->json(['message' => $e->getMessage()]); - } - try { - $projectsByType = DB::table('m_proyek') - ->select('m_type_proyek.name', DB::raw('count(*) as total')) - ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') - ->groupBy('m_type_proyek.name') - ->get(); - } catch (\Exception $e) { - return response()->json(['message' => $e->getMessage()]); - } + $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')) + ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') + ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') + ->get(); + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage()]); + } + try { + $projectsByType = DB::table('m_proyek') + ->select('m_type_proyek.name', DB::raw('count(*) as total')) + ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') + ->groupBy('m_type_proyek.name') + ->get(); + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage()]); + } return response()->json( - [ - 'status'=>'success', - 'code'=>200, - 'data'=>$data, - 'totalRecord'=>$countData, - 'totalPlannedCost' => $totalPlannedCost, - 'totalActualCost' => $totalActualCost, - 'totalRevenue' => $totalPlannedCost - $totalActualCost, - 'manpowers' => $manpowers, - 'projectsOnDanger'=> $projectsOnDanger, - 'projectPhases' => $projectPhases, - 'projectsByPhase' => $projectsByPhase, - 'projectTypes' => $projectTypes, - 'projectsByType' => $projectsByType, - ], 200); - } - - public function getListProjectTask($id){ - $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*") - ->where("assign_hr_to_activity.user_id", $id) - ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') - ->groupBy("m_proyek.proyek_id") - ->get(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); - } - - public function dashboard($id) - { - $data = DB::table('m_proyek as mp') - ->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish', - 'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') - ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') - ->where('mp.id', $id) - ->first(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404); - - $manpowers = UserToProyek::where('proyek_id', $id)->count(); - $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); - - $actualCost = @$rootActivity->biaya_actual ?? 0; - $progress = @$rootActivity->persentase_progress ?? 0; - - $commentActivity = DB::table('m_comment_activity as mca') - ->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created', - 'ma.name as activity') - ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') - ->where('ma.proyek_id', $id) - ->orderBy('comment_by') - ->take(2) - ->get(); - - $data->actual_cost = $actualCost; - $data->progress = $progress; - $data->comment = $commentActivity; - $data->man_power = $manpowers; - - return response()->json(['status'=>'success','code'=>200,'data'=> $data], 200); + [ + 'status'=>'success', + 'code'=>200, + 'data'=>$data, + 'totalRecord'=>$countData, + 'totalPlannedCost' => $totalPlannedCost, + 'totalActualCost' => $totalActualCost, + 'totalRevenue' => $totalPlannedCost - $totalActualCost, + 'manpowers' => $manpowers, + 'projectsOnDanger'=> $projectsOnDanger, + 'projectPhases' => $projectPhases, + 'projectsByPhase' => $projectsByPhase, + 'projectTypes' => $projectTypes, + 'projectsByType' => $projectsByType, + ], 200); } private function httpReq($search){ - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w')); - $info = curl_getinfo($ch); - - $output = curl_exec($ch); - curl_close($ch); + $output = curl_exec($ch); + curl_close($ch); - return json_decode($output); + return json_decode($output); } } From f5a2d1e6f0eefeb30419f27b66af78c21a54fadf Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Sat, 15 Oct 2022 23:26:59 +0700 Subject: [PATCH 2/7] move s-curve endpoint --- app/Http/Controllers/ActivityController.php | 322 ------------------ app/Http/Controllers/ProjectController.php | 349 +++++++++++++++++++- routes/web.php | 16 +- 3 files changed, 345 insertions(+), 342 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 19c7182..c74f841 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -3,14 +3,11 @@ namespace App\Http\Controllers; use App\Models\Activity; use App\Models\CommentActivity; -use App\Models\Holiday; use App\Models\Link; use App\Models\Project; use App\Models\ReportActivity; use App\Models\TemplateGantt; use App\Models\UserToActivity; -use App\Models\VersionGantt; -use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; class ActivityController extends Controller @@ -280,325 +277,6 @@ class ActivityController extends Controller return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); } - public function getPercentagePerDay(Request $request) - { - $dataPayload = $request->all(); - $allGantt = []; - foreach ($dataPayload['project_id'] as $val) { - $allGantt[] = $this->getLatestGantt($val); - } - - $dataFinal=[]; - foreach ($allGantt as $val) { - $dataProject = Project::find($val['proyek_id']); - $holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get(); - $dateHoliday = []; //$holiday->all(); - foreach ($holidays as $holiday) { - $startH = new \DateTime($holiday->date); - $endH = clone $startH; - $endH->modify('+'.$holiday->duration.' day'); - $intervalH = \DateInterval::createFromDateString('1 day'); - $periodH = new \DatePeriod($startH, $intervalH, $endH); - foreach ($periodH as $dt) { - $dateHoliday[] = $dt->format("Y-m-d"); - } - } - $verGantt = VersionGantt::find($val['last_gantt_id']); - $configOff = $verGantt->config_dayoff; - if($configOff && $configOff!= ""){ - $dayOff = explode(",", $verGantt->config_dayoff); - $dayOff = array_map( - function($value) { return (int)$value; }, - $dayOff - ); - }else{ - $dayOff = []; - } - $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); - if($checkHeader > 0){ - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - $minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); - $maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); - }else{ - $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); - $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); - } - - $begin = new \DateTime($minDate); - $end = new \DateTime($maxDate); - $end = $end->modify( '+1 day' ); - $interval = \DateInterval::createFromDateString('1 day'); - $period = new \DatePeriod($begin, $interval, $end); - $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); - if($checkHeader > 0){ - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - }else{ - $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - } - - $totalRencanaBudget = $totalRencanaBudget->sum; - $currentPercentage = 0; - $dataDate = []; - $dataPercen = []; - foreach ($period as $dt) { - $weekDay = $dt->format("w"); - $currentDate = $dt->format("Y-m-d"); - if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) - { - $totalPercentage = 0; - $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); - if($checkHeader > 0){ - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); - $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); - }else{ - $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); - } - - foreach ($dataActivity as $activity) { - $duration = $activity->duration; - if($totalRencanaBudget > 0 && $duration > 0){ - $totalPercentage = $totalPercentage + ((($activity->rencana_biaya/$totalRencanaBudget)*100)/$duration); - } - } - $currentPercentage = $currentPercentage + $totalPercentage; - $dataDate[] = $currentDate; - $dataPercen[] = $currentPercentage; - }else{ - $dataDate[] = $currentDate; - $dataPercen[] = "dateOff"; - } - } - $dataPercentage = array( - "date"=>$dataDate, - "percentage"=>$dataPercen - ); - $dataFinal[] = array( - "proyek_name"=> $dataProject->nama, - "data"=>$dataPercentage - ); - } - - if($dataFinal){ - return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400); - } - } - - - public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) - { - DB::enableQueryLog(); - $dataPayload = $request->all(); - $allGantt = []; - if(isset($dataPayload['gannt_id'])){ - $allGantt = $dataPayload['gannt_id']; - }else{ - foreach ($dataPayload['project_id'] as $val) { - $allGantt[] = $this->getLatestGantt($val); - } - } - $dataFinal=[]; - foreach ($allGantt as $keyGantt) { - $dataProject = Project::find($keyGantt['proyek_id']); - $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first(); - - if($dataHeader){ - $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); - }else{ - $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); - } - - if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first()) - continue; - - $alreadyHasReport = DB::table('report_activity_material as a') - ->select('a.id') - ->join('m_activity as b', 'b.id', '=', 'a.activity_id') - ->where('b.version_gantt_id', '=', $keyGantt['last_gantt_id']) - ->exists(); - - 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"); - - $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"); - - $begin = new \DateTime($minDate); - $end = new \DateTime($maxDate); - $end2 = new \DateTime($maxDate); - $interval = \DateInterval::createFromDateString('1 day'); - $period = new \DatePeriod($begin->modify('-1 days'), $interval, $end); - $arr_ActualM = []; - $tempDate = []; - $tempPercentage = []; - $tempTtlPercentPlan=0; - $tempTtlPercentActual=0; - - $currentACWP = 0; - $currentBCWP = 0; - - foreach ($period as $dt) { - $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') - ->where('ama.proyek_id', '=', $keyGantt['proyek_id']) - ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) - ->whereDate('ama.plan_date', $dt->format("Y-m-d")) - ->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') - ->join('m_activity as a', 'a.id', '=', 'ram.activity_id') - ->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")) - ->get(); - $dataTempPlan = []; - $x = 0; - $sumPercentagePlan=0; - $totalACWP = isset($totalACWP) ? $totalACWP : 0; - $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; - - foreach ($dataPlanM as $keyPlanM) { - $sumVolPlan = DB::table('assign_material_to_activity') - ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) - ->where('activity_id', '=', $keyPlanM->activity_id) - ->groupBy('activity_id') - ->first(); - $dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; - $dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning; - $dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date; - $dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity; - $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; - $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan; - $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; - $dataTempPlan [$x]['duration'] = $keyPlanM->duration; - $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; - $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; - $sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; - $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; - $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; - $x++; - } - - $w = 0; - $dataTempReport = []; - $sumPercentageActual=0; - foreach ($dataActualM as $keyActualM) { - $sumVolActual = DB::table('assign_material_to_activity') - ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) - ->where('activity_id', '=', $keyActualM->activity_id) - ->groupBy('activity_id') - ->first(); - $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; - $dataTempReport [$w]['qty'] = $keyActualM->qty; - $dataTempReport [$w]['report_date'] = $keyActualM->report_date; - $dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; - $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; - $dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; - $dataTempReport [$w]['duration'] = $keyActualM->duration; - $dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; - $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; - try { - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; - } catch (\Exception $e) { - return response()->json(['message' => $e->getMessage()]); - } - $dataTempReport [$w]['totalacwp'] = $totalACWP; - $w++; - } - - $arr_ActualM[] = array( - 'date'=>$dt->format("Y-m-d"), - 'percentPlan'=>$sumPercentagePlan, - 'percentActual'=>$sumPercentageActual, - 'plan'=>$dataTempPlan, - 'actual'=>$dataTempReport, - ); - if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ - $tempTtlPercentPlan+= $sumPercentagePlan; - $tempTtlPercentActual+= $sumPercentageActual; - $currentACWP += $totalACWP; - $currentBCWP += $totalBCWP; - - $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); - }else{ - $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); - } - } - - - try { - if(round($totalACWP,0) > $totalRencanaBudget){ - $estimatedCost = round($totalACWP,0)+0; - }else{ - $estimatedCost = ($totalRencanaBudget+0); - } - } catch (\Exception $e) { - return response()->json([ - 'message' => $e->getMessage(), - "line" => 566, - 'gantt' => $keyGantt, - ]); - } - $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; - - $costDeviation = $totalRencanaBudget - $estimatedCost; - if($costDeviation > 0){ - $potential = "SAVING"; - } else { - $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; - } - - $dataResponse = array( - "date" =>$tempDate, - "percentage" =>$tempPercentage, - "data_details" =>$arr_ActualM, - "budget_control" =>array("current_budget"=> $totalRencanaBudget, - "acwp" => round($totalACWP,0), - "bcwp" => round($totalBCWP,0), - "rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), - "add_cost_to_complete" => 0, - "estimated_at_completion" => $estimatedCost, - "cost_deviation" => $costDeviation, - "potential" => $potential, - ) - ); - - $dataFinal[] = array( - "proyek_name"=> $dataProject->nama, - "data"=>$dataResponse, - "allGant"=>$allGantt - ); - } - - - return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); - - } - - private function getLatestGantt($id){ - $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); - $data = array( - "last_gantt_id" => $maxGanttId, - "proyek_id" => $id - ); - return $data; - } - public function setBaseline($gantt_id) { $activities = Activity::where("version_gantt_id", $gantt_id)->get(); diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 039ea7d..729942e 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -2,31 +2,31 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; -use App\Models\Project; -use App\Models\UserToProyek; use App\Models\Activity; -use App\Models\UserToActivity; -use App\Models\User; +use App\Models\ActivityDokumen; use App\Models\AssignMaterial; +use App\Models\CommentActivity; use App\Models\DokumenProject; use App\Models\FolderDocumentProyek; -use App\Models\ProjectCharter; +use App\Models\Holiday; +use App\Models\Image; +use App\Models\Link; +use App\Models\OfficeHours; +use App\Models\Project; use App\Models\ProjectApproval; -use App\Models\ProjectPhase; -use App\Models\ProjectType; +use App\Models\ProjectCharter; use App\Models\ProjectMileStone; use App\Models\ProjectParticipants; +use App\Models\ProjectPhase; +use App\Models\ProjectType; +use App\Models\ReportActivity; use App\Models\ShowHideColumn; +use App\Models\User; +use App\Models\UserToActivity; +use App\Models\UserToProyek; use App\Models\VersionGantt; -use App\Models\Image; -use App\Models\CommentActivity; -use App\Models\Link; -use App\Models\ActivityDokumen; -use App\Models\Holiday; -use App\Models\ReportActivity; -use App\Models\OfficeHours; -use DB; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; @@ -327,5 +327,322 @@ class ProjectController extends Controller return json_decode($output); } + private function getLatestGantt($id){ + $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); + $data = array( + "last_gantt_id" => $maxGanttId, + "proyek_id" => $id + ); + return $data; + } + + public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) + { + DB::enableQueryLog(); + $dataPayload = $request->all(); + $allGantt = []; + if(isset($dataPayload['gannt_id'])){ + $allGantt = $dataPayload['gannt_id']; + }else{ + foreach ($dataPayload['project_id'] as $val) { + $allGantt[] = $this->getLatestGantt($val); + } + } + $dataFinal=[]; + foreach ($allGantt as $keyGantt) { + $dataProject = Project::find($keyGantt['proyek_id']); + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first(); + + if($dataHeader){ + $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); + }else{ + $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya"); + } + + if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first()) + continue; + + $alreadyHasReport = DB::table('report_activity_material as a') + ->select('a.id') + ->join('m_activity as b', 'b.id', '=', 'a.activity_id') + ->where('b.version_gantt_id', '=', $keyGantt['last_gantt_id']) + ->exists(); + + 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"); + + $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"); + + $begin = new \DateTime($minDate); + $end = new \DateTime($maxDate); + $end2 = new \DateTime($maxDate); + $interval = \DateInterval::createFromDateString('1 day'); + $period = new \DatePeriod($begin->modify('-1 days'), $interval, $end); + $arr_ActualM = []; + $tempDate = []; + $tempPercentage = []; + $tempTtlPercentPlan=0; + $tempTtlPercentActual=0; + + $currentACWP = 0; + $currentBCWP = 0; + + foreach ($period as $dt) { + $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') + ->where('ama.proyek_id', '=', $keyGantt['proyek_id']) + ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) + ->whereDate('ama.plan_date', $dt->format("Y-m-d")) + ->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') + ->join('m_activity as a', 'a.id', '=', 'ram.activity_id') + ->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")) + ->get(); + $dataTempPlan = []; + $x = 0; + $sumPercentagePlan=0; + $totalACWP = isset($totalACWP) ? $totalACWP : 0; + $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; + + foreach ($dataPlanM as $keyPlanM) { + $sumVolPlan = DB::table('assign_material_to_activity') + ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) + ->where('activity_id', '=', $keyPlanM->activity_id) + ->groupBy('activity_id') + ->first(); + $dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; + $dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning; + $dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date; + $dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity; + $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan; + $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan [$x]['duration'] = $keyPlanM->duration; + $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; + $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; + $sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; + $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; + $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + $x++; + } + + $w = 0; + $dataTempReport = []; + $sumPercentageActual=0; + foreach ($dataActualM as $keyActualM) { + $sumVolActual = DB::table('assign_material_to_activity') + ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) + ->where('activity_id', '=', $keyActualM->activity_id) + ->groupBy('activity_id') + ->first(); + $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; + $dataTempReport [$w]['qty'] = $keyActualM->qty; + $dataTempReport [$w]['report_date'] = $keyActualM->report_date; + $dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; + $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; + $dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; + $dataTempReport [$w]['duration'] = $keyActualM->duration; + $dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; + $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + try { + $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage()]); + } + $dataTempReport [$w]['totalacwp'] = $totalACWP; + $w++; + } + + $arr_ActualM[] = array( + 'date'=>$dt->format("Y-m-d"), + 'percentPlan'=>$sumPercentagePlan, + 'percentActual'=>$sumPercentageActual, + 'plan'=>$dataTempPlan, + 'actual'=>$dataTempReport, + ); + if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ + $tempTtlPercentPlan+= $sumPercentagePlan; + $tempTtlPercentActual+= $sumPercentageActual; + $currentACWP += $totalACWP; + $currentBCWP += $totalBCWP; + + $tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2)); + $tempDate[] = array($dt->format("Y-m-d"), 0, 0); + }else{ + $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); + $tempDate[] = array($dt->format("Y-m-d"), 0, 0); + } + } + + + try { + if(round($totalACWP,0) > $totalRencanaBudget){ + $estimatedCost = round($totalACWP,0)+0; + }else{ + $estimatedCost = ($totalRencanaBudget+0); + } + } catch (\Exception $e) { + return response()->json([ + 'message' => $e->getMessage(), + "line" => 566, + 'gantt' => $keyGantt, + ]); + } + $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; + + $costDeviation = $totalRencanaBudget - $estimatedCost; + if($costDeviation > 0){ + $potential = "SAVING"; + } else { + $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; + } + + $dataResponse = array( + "date" =>$tempDate, + "percentage" =>$tempPercentage, + "data_details" =>$arr_ActualM, + "budget_control" =>array("current_budget"=> $totalRencanaBudget, + "acwp" => round($totalACWP,0), + "bcwp" => round($totalBCWP,0), + "rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), + "add_cost_to_complete" => 0, + "estimated_at_completion" => $estimatedCost, + "cost_deviation" => $costDeviation, + "potential" => $potential, + ) + ); + + $dataFinal[] = array( + "proyek_name"=> $dataProject->nama, + "data"=>$dataResponse, + "allGant"=>$allGantt + ); + } + + + return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); + } + + public function getPercentagePerDay(Request $request) + { + $dataPayload = $request->all(); + $allGantt = []; + foreach ($dataPayload['project_id'] as $val) { + $allGantt[] = $this->getLatestGantt($val); + } + + $dataFinal=[]; + foreach ($allGantt as $val) { + $dataProject = Project::find($val['proyek_id']); + $holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get(); + $dateHoliday = []; //$holiday->all(); + foreach ($holidays as $holiday) { + $startH = new \DateTime($holiday->date); + $endH = clone $startH; + $endH->modify('+'.$holiday->duration.' day'); + $intervalH = \DateInterval::createFromDateString('1 day'); + $periodH = new \DatePeriod($startH, $intervalH, $endH); + foreach ($periodH as $dt) { + $dateHoliday[] = $dt->format("Y-m-d"); + } + } + $verGantt = VersionGantt::find($val['last_gantt_id']); + $configOff = $verGantt->config_dayoff; + if($configOff && $configOff!= ""){ + $dayOff = explode(",", $verGantt->config_dayoff); + $dayOff = array_map( + function($value) { return (int)$value; }, + $dayOff + ); + }else{ + $dayOff = []; + } + $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); + if($checkHeader > 0){ + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + $minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); + $maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); + }else{ + $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); + $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); + } + + $begin = new \DateTime($minDate); + $end = new \DateTime($maxDate); + $end = $end->modify( '+1 day' ); + $interval = \DateInterval::createFromDateString('1 day'); + $period = new \DatePeriod($begin, $interval, $end); + $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); + if($checkHeader > 0){ + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + }else{ + $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + } + + $totalRencanaBudget = $totalRencanaBudget->sum; + $currentPercentage = 0; + $dataDate = []; + $dataPercen = []; + foreach ($period as $dt) { + $weekDay = $dt->format("w"); + $currentDate = $dt->format("Y-m-d"); + if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) + { + $totalPercentage = 0; + $checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count(); + if($checkHeader > 0){ + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); + $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); + }else{ + $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); + } + + foreach ($dataActivity as $activity) { + $duration = $activity->duration; + if($totalRencanaBudget > 0 && $duration > 0){ + $totalPercentage = $totalPercentage + ((($activity->rencana_biaya/$totalRencanaBudget)*100)/$duration); + } + } + $currentPercentage = $currentPercentage + $totalPercentage; + $dataDate[] = $currentDate; + $dataPercen[] = $currentPercentage; + }else{ + $dataDate[] = $currentDate; + $dataPercen[] = "dateOff"; + } + } + $dataPercentage = array( + "date"=>$dataDate, + "percentage"=>$dataPercen + ); + $dataFinal[] = array( + "proyek_name"=> $dataProject->nama, + "data"=>$dataPercentage + ); + } + + if($dataFinal){ + return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400); + } + } + } diff --git a/routes/web.php b/routes/web.php index 77e9196..06d4d10 100644 --- a/routes/web.php +++ b/routes/web.php @@ -58,8 +58,18 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/project/edit/{id}', 'ProjectController@edit'); $router->delete('/project/delete/{id}', 'ProjectController@delete'); $router->get('/project/list', 'ProjectController@list'); - $router->get('/project/dashboard/{id}', 'ProjectController@dashboard'); - $router->get('/project/list-user/{id}', 'ProjectController@getListProjectTask'); + + $router->post('/project/get-s-curve', 'ProjectController@getSCurve'); + /* $router->get('/project/get-progress/{id}/{date?}', 'ProjectController@getProgress'); */ + /* $router->get('/project/get-acwp/{id}/{date?}', 'ProjectController@getACWP'); */ + /* $router->get('/project/get-bcwp/{id}/{date?}', 'ProjectController@getBCWP'); */ + /* $router->get('/project/get-expenditure/{id}/{date?}', 'ProjectController@getExpenditure'); */ + /* $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-budget/{id}', 'ProjectController@getStatusBudget'); */ + + $router->post('/project-charter/search', 'ProjectCharterController@search'); $router->post('/project-charter/add', 'ProjectCharterController@add'); $router->put('/project-charter/update/{id}', 'ProjectCharterController@update'); @@ -189,9 +199,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->put('/task/update-regular/{id}', 'ActivityController@updateRegular'); $router->delete('/task/{id}', 'ActivityController@delete'); $router->get('/task/get-update/{id}', 'ActivityController@getUpdate'); - $router->post('/activity/get-percentage', 'ActivityController@getPercentagePerDay'); $router->get('/activity/set-baseline/{gantt_id}', 'ActivityController@setBaseline'); - $router->post('/activity/get-curva-s', 'ActivityController@getCalculateCurvaS'); $router->get('/activity/synchronize-report/{gantt_id}', 'ActivityController@synchronizeReport'); $router->post('/link', 'LinkController@add'); From 88fbfa395606ffdbfa8b4e74a2fc7fc0b8508dc7 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Sun, 16 Oct 2022 23:23:12 +0700 Subject: [PATCH 3/7] move synchro & baseline codes --- app/Http/Controllers/ActivityController.php | 52 --------------------- 1 file changed, 52 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index c74f841..3fdd675 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -277,57 +277,5 @@ class ActivityController extends Controller return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 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); - } - - 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); - } } From 51672832d7bbf944728ab1346a75ae4337d821f1 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Sun, 16 Oct 2022 23:25:51 +0700 Subject: [PATCH 4/7] adjust s-curve API --- app/Http/Controllers/ProjectController.php | 114 ++++++++++++++++++--- routes/web.php | 10 +- 2 files changed, 105 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 729942e..a547fe0 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -336,18 +336,20 @@ class ProjectController extends Controller return $data; } - public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) + public function getSCurve(Request $request) { DB::enableQueryLog(); $dataPayload = $request->all(); + /* print_r($dataPayload); exit(); */ + $allGantt = []; - if(isset($dataPayload['gannt_id'])){ - $allGantt = $dataPayload['gannt_id']; + + if(isset($dataPayload['gantt_id'])){ + $allGantt = $dataPayload['gantt_id']; }else{ - foreach ($dataPayload['project_id'] as $val) { - $allGantt[] = $this->getLatestGantt($val); - } + $allGantt[] = $this->getLatestGantt($dataPayload['project_id']); } + $dataFinal=[]; foreach ($allGantt as $keyGantt) { $dataProject = Project::find($keyGantt['proyek_id']); @@ -376,21 +378,29 @@ class ProjectController extends Controller ->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"); - - $begin = new \DateTime($minDate); - $end = new \DateTime($maxDate); - $end2 = new \DateTime($maxDate); - $interval = \DateInterval::createFromDateString('1 day'); - $period = new \DatePeriod($begin->modify('-1 days'), $interval, $end); + ->max("planned_end"); + /* ->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.' 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 = []; $tempDate = []; - $tempPercentage = []; + $tempPercentagePlan = []; + $tempPercentagePlanWhr = []; + $tempPercentageReal = []; $tempTtlPercentPlan=0; $tempTtlPercentActual=0; @@ -482,9 +492,14 @@ class ProjectController extends Controller $currentBCWP += $totalBCWP; $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); }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); } } @@ -515,6 +530,8 @@ class ProjectController extends Controller $dataResponse = array( "date" =>$tempDate, "percentage" =>$tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, "data_details" =>$arr_ActualM, "budget_control" =>array("current_budget"=> $totalRencanaBudget, "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); + } + } diff --git a/routes/web.php b/routes/web.php index 06d4d10..affecf1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -56,16 +56,18 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/project/add', 'ProjectController@add'); $router->put('/project/update/{id}', 'ProjectController@update'); $router->get('/project/edit/{id}', 'ProjectController@edit'); + $router->get('/project/detail/{id}', 'ProjectController@detail'); $router->delete('/project/delete/{id}', 'ProjectController@delete'); $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->get('/project/get-progress/{id}/{date?}', 'ProjectController@getProgress'); */ - /* $router->get('/project/get-acwp/{id}/{date?}', 'ProjectController@getACWP'); */ - /* $router->get('/project/get-bcwp/{id}/{date?}', 'ProjectController@getBCWP'); */ + /* $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'); */ - /* $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-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->delete('/task/{id}', 'ActivityController@delete'); $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->put('/link/{id}', 'LinkController@update'); From 8a6cb2b8948e6689b329c173b0a1244915ad3834 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Mon, 17 Oct 2022 01:02:20 +0700 Subject: [PATCH 5/7] fix real progress --- app/Http/Controllers/ProjectController.php | 21 ++++++++++++++------- app/Models/ReportActivity.php | 10 +++++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index a547fe0..cb29b1c 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -20,6 +20,7 @@ use App\Models\ProjectParticipants; use App\Models\ProjectPhase; use App\Models\ProjectType; use App\Models\ReportActivity; +use App\Models\ReportActivityMaterial; use App\Models\ShowHideColumn; use App\Models\User; use App\Models\UserToActivity; @@ -384,7 +385,7 @@ class ProjectController extends Controller ->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("planned_end"); + ->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 @@ -407,6 +408,9 @@ class ProjectController extends Controller $currentACWP = 0; $currentBCWP = 0; + /* foreach($period as $x){ */ + /* echo $x->format("Y-m-d")."\n"; */ + /* } exit(); */ foreach ($period as $dt) { $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') @@ -420,7 +424,8 @@ class ProjectController extends Controller ->join('m_activity as a', 'a.id', '=', 'ram.activity_id') ->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->format("Y-m-d")) + ->whereDate('ram.report_date', '>',$dt->modify('-7 day')->format("Y-m-d")) ->get(); $dataTempPlan = []; $x = 0; @@ -683,9 +688,9 @@ class ProjectController extends Controller foreach($activities as $activity) { $activity_id = $activity->id; - $countReports = ReportActivity::where('activity_id', $activity_id)->count(); + $countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count(); if ($countReports === 1) { - $dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get(); + $dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get(); foreach($dataReports as $dr) { $reports[] = array( 'activity_id'=>$activity_id, @@ -695,16 +700,18 @@ class ProjectController extends Controller } } 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(); + $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); + $lastReport = ReportActivityMaterial::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") ); - } + $activity->reports = $reports; } + /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ + /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ for ($i=0; $i < count($reports); $i++) { $activity = Activity::find($reports[$i]['activity_id']); diff --git a/app/Models/ReportActivity.php b/app/Models/ReportActivity.php index 8db5702..85b77e4 100644 --- a/app/Models/ReportActivity.php +++ b/app/Models/ReportActivity.php @@ -12,16 +12,16 @@ class ReportActivity extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'activity_id', - 'user_id', + 'activity_id', + 'user_id', 'report_date', 'job_count_report', 'description', 'lat', 'lon', - 'created_at', - 'created_by', - 'updated_at', + 'created_at', + 'created_by', + 'updated_at', 'updated_by' ]; } From d73c1055f66461dd120c99949df27053cd7d69ac Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Mon, 17 Oct 2022 02:00:10 +0700 Subject: [PATCH 6/7] fix interval, start and close on friday --- app/Http/Controllers/ProjectController.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index cb29b1c..3b930a1 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -391,9 +391,10 @@ class ProjectController extends Controller /* ->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.' Monday'); - $end = new \DateTime($maxDate. ' Friday'); - $interval = new \DateInterval('P7D'); + $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 $period = new \DatePeriod($begin, $interval, $end); /* $period = new \DatePeriod($begin->modify('-1 days'), $interval, $end); */ @@ -417,14 +418,16 @@ class ProjectController extends Controller ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->where('ama.proyek_id', '=', $keyGantt['proyek_id']) ->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->format("Y-m-d")) + ->whereDate('ama.plan_date', '>',$dt->modify('-7 day')->format("Y-m-d")) ->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') ->join('m_activity as a', 'a.id', '=', 'ram.activity_id') ->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->format("Y-m-d")) ->whereDate('ram.report_date', '>',$dt->modify('-7 day')->format("Y-m-d")) ->get(); $dataTempPlan = []; From 15040d01ed403f066713f2c5b24f30853409db23 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Mon, 17 Oct 2022 03:38:16 +0700 Subject: [PATCH 7/7] 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'); */