From f0afba52dc07994347a6197b8bbdc6106081d76a Mon Sep 17 00:00:00 2001 From: bnu Date: Wed, 3 Aug 2022 02:35:02 +0700 Subject: [PATCH 01/17] add comment activity in project@dashboard --- app/Http/Controllers/ProjectController.php | 92 +++++++++++++++++----- 1 file changed, 72 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index c5e23db..beb438e 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -7,11 +7,13 @@ use App\Models\Project; use App\Models\UserToProyek; use App\Models\Activity; use App\Models\UserToActivity; +use App\Models\User; use App\Models\AssignMaterial; use App\Models\DokumenProject; use App\Models\FolderDocumentProyek; use App\Models\ProjectCharter; use App\Models\ProjectApproval; +use App\Models\ProjectPhase; use App\Models\ProjectMileStone; use App\Models\ProjectParticipants; use App\Models\ShowHideColumn; @@ -213,21 +215,18 @@ class ProjectController extends Controller if(!$data) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - $costWarningThreshold = 50000000; - $costDangerThreshold = 25000000; $scheduleWarningThreshold = 10; $scheduleDangerThreshold = 5; foreach($data as $d){ $progress = $costVariance = $actualCost = 0; $lastActivity = null; $scheduleHealth = "on-track"; - $costHealth = "on-budget"; $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); if($rootActivity){ $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; $actualCost = $rootActivity->biaya_actual ?? 0; $progress = $rootActivity->persentase_progress ?? 0; - /* + $timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); $date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); $date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); @@ -239,27 +238,47 @@ class ProjectController extends Controller } elseif ($daysRemaining <= $scheduleWarningThreshold) { $scheduleHealth = "warning"; } - $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); - */ - if($costVariance <= $costDangerThreshold) { - $costHealth = "danger"; - } elseif ($costVariance <= $costWarningThreshold) { - $costHealth = "warning"; - } } $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); $d->plannedCost = $d->rencana_biaya; $d->actualCost = $actualCost; - //$d->lastActivity = $lastActivity ?? "-"; + $d->lastActivity = $lastActivity ?? "-"; //$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; $d->costVariance = $costVariance; - $d->costHealth = $costHealth; - //$d->scheduleHealth = $scheduleHealth; - $d->progress = $progress . "%"; + $d->costHealth = $d->budget_health; + $d->scheduleHealth = $scheduleHealth; + $d->progress = $progress; + $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; } - - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + + $totalPlannedCost = $data->sum('plannedCost'); + $totalActualCost = $data->sum('actualCost'); + $manpowers = User::where('employee_type', 'employee')->count(); + $projectPhases = ProjectPhase::orderBy('order', '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()]); + } + + return response()->json( + [ + 'status'=>'success', + 'code'=>200, + 'data'=>$data, + 'totalRecord'=>$countData, + 'totalPlannedCost' => $totalPlannedCost, + 'totalActualCost' => $totalActualCost, + 'totalRevenue' => $totalPlannedCost - $totalActualCost, + 'manpowers' => $manpowers, + 'projectPhases' => $projectPhases, + 'projectsByPhase' => $projectsByPhase, + ], 200); } public function getListProjectTask($id){ @@ -278,15 +297,48 @@ class ProjectController extends Controller 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') + ->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) ->get(); $countData = $data->count(); + $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); + if($rootActivity){ + $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(); + + foreach ($data as $val) { + $dataRes['kode_sortname'] = $val->kode_sortname; + $dataRes['name_project'] = $val->name_project; + $dataRes['start'] = $val->start; + $dataRes['finish'] = $val->finish; + $dataRes['rencana_biaya'] = $val->rencana_biaya; + $dataRes['company'] = $val->company; + $dataRes['currency_symbol'] = $val->currency_symbol; + // get firstname + $arr = explode(" ", $val->pm); + $dataRes['pm'] = $arr[0]; + $dataRes['budget_health'] = $val->budget_health; + $dataRes['actualCost'] = $actualCost; + $dataRes['progress'] = $progress; + $dataRes['comment'] = $commentActivity; + } + if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, 'totalRecord'=>$countData], 200); } } From ef08830b01f3b9c4609dd9fec1afe8630e78b9ea Mon Sep 17 00:00:00 2001 From: bnu Date: Wed, 3 Aug 2022 03:07:30 +0700 Subject: [PATCH 02/17] add manpower in project@dashboard --- app/Http/Controllers/ProjectController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index beb438e..b6adcf5 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -304,7 +304,9 @@ class ProjectController extends Controller ->get(); $countData = $data->count(); + $manpowers = UserToProyek::where('proyek_id', $id)->count(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); + if($rootActivity){ $actualCost = $rootActivity->biaya_actual ?? 0; $progress = $rootActivity->persentase_progress ?? 0; @@ -331,9 +333,10 @@ class ProjectController extends Controller $arr = explode(" ", $val->pm); $dataRes['pm'] = $arr[0]; $dataRes['budget_health'] = $val->budget_health; - $dataRes['actualCost'] = $actualCost; + $dataRes['actual_cost'] = $actualCost; $dataRes['progress'] = $progress; $dataRes['comment'] = $commentActivity; + $dataRes['man_power'] = $manpowers; } if(!$data) From c8e70b38c6003e2bb2f784c47e4daf94d72f29fc Mon Sep 17 00:00:00 2001 From: bnu Date: Wed, 3 Aug 2022 11:30:18 +0700 Subject: [PATCH 03/17] update calculate manpower --- app/Http/Controllers/ProjectController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index b6adcf5..23c66e0 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -14,6 +14,7 @@ use App\Models\FolderDocumentProyek; use App\Models\ProjectCharter; use App\Models\ProjectApproval; use App\Models\ProjectPhase; +use App\Models\ProjectType; use App\Models\ProjectMileStone; use App\Models\ProjectParticipants; use App\Models\ShowHideColumn; @@ -254,8 +255,10 @@ class ProjectController extends Controller $totalPlannedCost = $data->sum('plannedCost'); $totalActualCost = $data->sum('actualCost'); - $manpowers = User::where('employee_type', 'employee')->count(); + // $manpowers = User::where('employee_type', 'employee')->count(); + $manpowers = User::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')) @@ -265,6 +268,15 @@ class ProjectController extends Controller } 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( [ @@ -278,6 +290,8 @@ class ProjectController extends Controller 'manpowers' => $manpowers, 'projectPhases' => $projectPhases, 'projectsByPhase' => $projectsByPhase, + 'projectTypes' => $projectTypes, + 'projectsByType' => $projectsByType, ], 200); } From 75e31ab09fd3e9698ddb8c059718c73fba7855a5 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Jul 2022 23:01:02 +0700 Subject: [PATCH 04/17] inject config --- bootstrap/app.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index ca0155b..5f8ccca 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -62,9 +62,7 @@ $app->singleton( $app->configure('auth'); $app->configure('api'); $app->configure('assets'); - - - +$app->configure('app'); /* |-------------------------------------------------------------------------- From bef1efe6dadf746d8abafbba3cd97c4016fc8ac6 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Jul 2022 23:01:22 +0700 Subject: [PATCH 05/17] remove decimal file --- config/app.php | 9 +++++++++ config/decimal.php | 5 ----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 config/app.php delete mode 100644 config/decimal.php diff --git a/config/app.php b/config/app.php new file mode 100644 index 0000000..2ab666c --- /dev/null +++ b/config/app.php @@ -0,0 +1,9 @@ + 5, + 'cost_health_warning_threshold' => 20000000, + 'cost_health_danger_threshold' => 0, + 'schedule_health_warning_threshold' => 30, + 'schedule_health_danger_threshold' => 0, + ]; +?> diff --git a/config/decimal.php b/config/decimal.php deleted file mode 100644 index 9a4cb27..0000000 --- a/config/decimal.php +++ /dev/null @@ -1,5 +0,0 @@ - 5, - ]; -?> From 0985b0bfa84a3cc7f8715fa6c375c3a04d0e3524 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 4 Aug 2022 16:20:21 +0700 Subject: [PATCH 06/17] converging --- app/Http/Controllers/ActivityController.php | 377 +++++----- app/Http/Controllers/ProjectController.php | 723 ++++++++++---------- app/Http/Middleware/CorsMiddleware.php | 78 +-- app/Models/Activity.php | 7 +- routes/web.php | 421 +----------- 5 files changed, 608 insertions(+), 998 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 4c7b9ba..26a1a0f 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -401,193 +401,206 @@ class ActivityController extends Controller } $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"); - - } - - $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, $interval, $end); - $arr_ActualM = []; - $tempDate = []; - $tempPercentage = []; - $tempTtlPercentPlan=0; - $tempTtlPercentActual=0; - - $currentACWP = 0; - $budgetControlACWP = 0; - $currentProgressActivity = 0; - $currentBCWP = 0; - $budgetControlBCWP = 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; - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; - $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'){ - if($dt->format("w")==1){ - if($totalACWP > 0 ){ - $budgetControlACWP = $currentACWP + $totalACWP; - } - if($totalBCWP > 0 ){ - $budgetControlBCWP = $currentBCWP + $totalBCWP; - } - - $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 if($dt->format("Y-m-d") == $end2->format("Y-m-d")) { - $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); - $tempTtlPercentPlan = 0; - $tempTtlPercentActual = 0; - } - }else{ - $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); - } - } - - if(round($totalACWP,0) > $totalRencanaBudget){ - $estimatedCost = round($totalACWP,0)+0; - }else{ - $estimatedCost = ($totalRencanaBudget+0); - } - $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 - ); + $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"); + + } + + $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, $interval, $end); + $arr_ActualM = []; + $tempDate = []; + $tempPercentage = []; + $tempTtlPercentPlan=0; + $tempTtlPercentActual=0; + + $currentACWP = 0; + $budgetControlACWP = 0; + $currentProgressActivity = 0; + $currentBCWP = 0; + $budgetControlBCWP = 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; + try { + $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; + $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; + $x++; + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage(), + 'data' => $keyPlanM->persentase_progress, + 'data2' => $keyPlanM->bobot_planning, + 'data3' => $keyPlanM->duration, + 'data4' => $totalRencanaBudget, + 'data5' => $keyPlanM, + ]); + } + } + + $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; + $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + $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'){ + if($dt->format("w")==1){ + if($totalACWP > 0 ){ + $budgetControlACWP = $currentACWP + $totalACWP; + } + if($totalBCWP > 0 ){ + $budgetControlBCWP = $currentBCWP + $totalBCWP; + } + + $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 if($dt->format("Y-m-d") == $end2->format("Y-m-d")) { + // error here + $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); + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; + } + }else{ + $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); + $tempDate[] = array($dt->format("Y-m-d"), 0, 0); + } + } + + if(round($totalACWP,0) > $totalRencanaBudget){ + $estimatedCost = round($totalACWP,0)+0; + }else{ + $estimatedCost = ($totalRencanaBudget+0); + } + $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); } - - return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); - } private function getLatestGantt($id){ return array( - "last_gantt_id" => VersionGantt::where("proyek_id", $id)->latest(), + "last_gantt_id" => VersionGantt::where("proyek_id", $id)->max("id"), "proyek_id" => $id ); } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 23c66e0..c9ea6a4 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -1,361 +1,362 @@ -validate($request, [ - 'nama' => 'required', - 'mulai_proyek' => 'required', - 'akhir_proyek' => 'required', - 'rencana_biaya' => 'required', - 'type_proyek_id' => 'required' - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = Project::create($data); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); - - $this->createOfficeHours($result->id); - $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); - - return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); - } - - public function edit($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); - - return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); - } - - public function update(Request $request, $id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Project::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $result = $data->update($request->all()); - - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); - } - - private function createOfficeHours($proyek_id) - { - $dataCreate = array( - "proyek_id"=>$proyek_id, - "monday_start"=> "08:00:00", - "monday_end"=> "16:00:00", - "tuesday_start"=> "08:00:00", - "tuesday_end"=> "16:00:00", - "wednesday_start"=> "08:00:00", - "wednesday_end"=> "16:00:00", - "thursday_start"=> "08:00:00", - "thursday_end"=> "16:00:00", - "friday_start"=> "08:00:00", - "friday_end"=> "16:00:00", - "saturday_start"=> "08:00:00", - "saturday_end"=> "16:00:00", - "sunday_start"=> "08:00:00", - "sunday_end"=> "16:00:00", - "created_by"=> $this->currentName - ); - - OfficeHours::create($dataCreate); - - return true; - } - - public function delete($id) - { - $data = Project::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - $this->deleteRelative($id); - - if(!$data->delete()) - return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); - } - - private function deleteRelative($project_id) - { - UserToProyek::where('proyek_id', $project_id)->delete(); - UserToActivity::where('proyek_id', $project_id)->delete(); - AssignMaterial::where('proyek_id', $project_id)->delete(); - ProjectCharter::where('proyek_id', $project_id)->delete(); - ProjectApproval::where('proyek_id', $project_id)->delete(); - ProjectMileStone::where('proyek_id', $project_id)->delete(); - ProjectParticipants::where('proyek_id', $project_id)->delete(); - $this->deleteVersionGantt($project_id); - $this->deleteDokumenProject($project_id); - } - - private function deleteVersionGantt($project_id) - { - $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); - $vhIds = $dataVg->all(); - $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); - $activityIds = $activity->all(); - $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); - foreach ($dataRa as $ra) { - $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); - foreach ($images as $image) { - if(file_exists($this->pathImage.$image->image)){ - unlink($this->pathImage.$image->image); - } - } - Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); - } - $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); - foreach ($dataAd as $ad) { - if(file_exists($this->pathActivityDocument.$ad->file)){ - unlink($this->pathActivityDocument.$ad->file); - } - } - ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); - CommentActivity::whereIn("activity_id", $activityIds)->delete(); - Holiday::where("proyek_id", $project_id)->delete(); - VersionGantt::where("proyek_id", $project_id)->delete(); - Link::whereIn("version_gantt_id", $vhIds)->delete(); - ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); - Activity::whereIn("version_gantt_id", $vhIds)->delete(); - ReportActivity::whereIn("activity_id", $activityIds)->delete(); - } - - private function deleteDokumenProject($project_id) - { - $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); - - foreach ($dataDokumen as $dokumen) { - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); - } - } - DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); - - $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); - $ref_ids = $dataFolder->all(); - $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); - foreach ($dataDokumen as $dokumen) { - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); - } - } - - DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); - } - - public function search(Request $request) - { - $payload = $request->all(); - - $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); - $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 = Project::orderBy('id', 'desc')->get(); - $countData = $data->count(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - $scheduleWarningThreshold = 10; - $scheduleDangerThreshold = 5; - foreach($data as $d){ - $progress = $costVariance = $actualCost = 0; - $lastActivity = null; - $scheduleHealth = "on-track"; - $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); - if($rootActivity){ - $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; - $actualCost = $rootActivity->biaya_actual ?? 0; - $progress = $rootActivity->persentase_progress ?? 0; - - $timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); - $date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); - $date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); - $daysRemaining = $date2->diff($date1); - $daysRemaining = $daysRemaining->d; - - if($daysRemaining <= $scheduleDangerThreshold) { - $scheduleHealth = "danger"; - } elseif ($daysRemaining <= $scheduleWarningThreshold) { - $scheduleHealth = "warning"; - } - $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); - } - $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); - $d->plannedCost = $d->rencana_biaya; - $d->actualCost = $actualCost; - $d->lastActivity = $lastActivity ?? "-"; - //$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; - $d->costVariance = $costVariance; - $d->costHealth = $d->budget_health; - $d->scheduleHealth = $scheduleHealth; - $d->progress = $progress; - $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; - } - - $totalPlannedCost = $data->sum('plannedCost'); - $totalActualCost = $data->sum('actualCost'); - // $manpowers = User::where('employee_type', 'employee')->count(); - $manpowers = User::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()]); - } - - return response()->json( - [ - 'status'=>'success', - 'code'=>200, - 'data'=>$data, - 'totalRecord'=>$countData, - 'totalPlannedCost' => $totalPlannedCost, - 'totalActualCost' => $totalActualCost, - 'totalRevenue' => $totalPlannedCost - $totalActualCost, - 'manpowers' => $manpowers, - '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) - ->get(); - $countData = $data->count(); - - $manpowers = UserToProyek::where('proyek_id', $id)->count(); - $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); - - if($rootActivity){ - $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(); - - foreach ($data as $val) { - $dataRes['kode_sortname'] = $val->kode_sortname; - $dataRes['name_project'] = $val->name_project; - $dataRes['start'] = $val->start; - $dataRes['finish'] = $val->finish; - $dataRes['rencana_biaya'] = $val->rencana_biaya; - $dataRes['company'] = $val->company; - $dataRes['currency_symbol'] = $val->currency_symbol; - // get firstname - $arr = explode(" ", $val->pm); - $dataRes['pm'] = $arr[0]; - $dataRes['budget_health'] = $val->budget_health; - $dataRes['actual_cost'] = $actualCost; - $dataRes['progress'] = $progress; - $dataRes['comment'] = $commentActivity; - $dataRes['man_power'] = $manpowers; - } - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, 'totalRecord'=>$countData], 200); - } -} +validate($request, [ + 'nama' => 'required', + 'mulai_proyek' => 'required', + 'akhir_proyek' => 'required', + 'rencana_biaya' => 'required', + 'type_proyek_id' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = Project::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); + + $this->createOfficeHours($result->id); + $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); + + return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); + } + + public function edit($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); + + return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + } + + public function update(Request $request, $id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Project::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); + } + + private function createOfficeHours($proyek_id) + { + $dataCreate = array( + "proyek_id"=>$proyek_id, + "monday_start"=> "08:00:00", + "monday_end"=> "16:00:00", + "tuesday_start"=> "08:00:00", + "tuesday_end"=> "16:00:00", + "wednesday_start"=> "08:00:00", + "wednesday_end"=> "16:00:00", + "thursday_start"=> "08:00:00", + "thursday_end"=> "16:00:00", + "friday_start"=> "08:00:00", + "friday_end"=> "16:00:00", + "saturday_start"=> "08:00:00", + "saturday_end"=> "16:00:00", + "sunday_start"=> "08:00:00", + "sunday_end"=> "16:00:00", + "created_by"=> $this->currentName + ); + + OfficeHours::create($dataCreate); + + return true; + } + + public function delete($id) + { + $data = Project::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + $this->deleteRelative($id); + + if(!$data->delete()) + return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); + } + + private function deleteRelative($project_id) + { + UserToProyek::where('proyek_id', $project_id)->delete(); + UserToActivity::where('proyek_id', $project_id)->delete(); + AssignMaterial::where('proyek_id', $project_id)->delete(); + ProjectCharter::where('proyek_id', $project_id)->delete(); + ProjectApproval::where('proyek_id', $project_id)->delete(); + ProjectMileStone::where('proyek_id', $project_id)->delete(); + ProjectParticipants::where('proyek_id', $project_id)->delete(); + $this->deleteVersionGantt($project_id); + $this->deleteDokumenProject($project_id); + } + + private function deleteVersionGantt($project_id) + { + $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); + $vhIds = $dataVg->all(); + $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); + $activityIds = $activity->all(); + $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); + foreach ($dataRa as $ra) { + $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); + foreach ($images as $image) { + if(file_exists($this->pathImage.$image->image)){ + unlink($this->pathImage.$image->image); + } + } + Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); + } + $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); + foreach ($dataAd as $ad) { + if(file_exists($this->pathActivityDocument.$ad->file)){ + unlink($this->pathActivityDocument.$ad->file); + } + } + ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); + CommentActivity::whereIn("activity_id", $activityIds)->delete(); + Holiday::where("proyek_id", $project_id)->delete(); + VersionGantt::where("proyek_id", $project_id)->delete(); + Link::whereIn("version_gantt_id", $vhIds)->delete(); + ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); + Activity::whereIn("version_gantt_id", $vhIds)->delete(); + ReportActivity::whereIn("activity_id", $activityIds)->delete(); + } + + private function deleteDokumenProject($project_id) + { + $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); + + foreach ($dataDokumen as $dokumen) { + if(file_exists($this->pathDocument.$dokumen->file)){ + unlink($this->pathDocument.$dokumen->file); + } + } + DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); + + $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); + $ref_ids = $dataFolder->all(); + $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); + foreach ($dataDokumen as $dokumen) { + if(file_exists($this->pathDocument.$dokumen->file)){ + unlink($this->pathDocument.$dokumen->file); + } + } + + DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); + } + + public function search(Request $request) + { + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); + $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 = Project::orderBy('id', 'desc')->get(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + $scheduleWarningThreshold = 10; + $scheduleDangerThreshold = 5; + foreach($data as $d){ + $progress = $costVariance = $actualCost = 0; + $lastActivity = null; + $scheduleHealth = "on-track"; + $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); + if($rootActivity){ + $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; + $actualCost = $rootActivity->biaya_actual ?? 0; + $progress = $rootActivity->persentase_progress ?? 0; + + $timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); + $date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); + $date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); + $daysRemaining = $date2->diff($date1); + $daysRemaining = $daysRemaining->d; + + if($daysRemaining <= $scheduleDangerThreshold) { + $scheduleHealth = "danger"; + } elseif ($daysRemaining <= $scheduleWarningThreshold) { + $scheduleHealth = "warning"; + } + + $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); + $d->lastActivity = $lastActivity ?? "-"; + $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); + $d->scheduleHealth = $scheduleHealth; + + $d->plannedCost = $d->rencana_biaya; + $d->actualCost = $actualCost; + $d->costVariance = $costVariance; + $d->costHealth = $d->budget_health; + + $d->progress = $progress; + $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; + } + } + + $totalPlannedCost = $data->sum('plannedCost'); + $totalActualCost = $data->sum('actualCost'); + $manpowers = User::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()]); + } + + return response()->json( + [ + 'status'=>'success', + 'code'=>200, + 'data'=>$data, + 'totalRecord'=>$countData, + 'totalPlannedCost' => $totalPlannedCost, + 'totalActualCost' => $totalActualCost, + 'totalRevenue' => $totalPlannedCost - $totalActualCost, + 'manpowers' => $manpowers, + '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) + ->get(); + $countData = $data->count(); + + $manpowers = UserToProyek::where('proyek_id', $id)->count(); + $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); + + if($rootActivity){ + $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(); + + foreach ($data as $val) { + $dataRes['kode_sortname'] = $val->kode_sortname; + $dataRes['name_project'] = $val->name_project; + $dataRes['start'] = $val->start; + $dataRes['finish'] = $val->finish; + $dataRes['rencana_biaya'] = $val->rencana_biaya; + $dataRes['company'] = $val->company; + $dataRes['currency_symbol'] = $val->currency_symbol; + // get firstname + $arr = explode(" ", $val->pm); + $dataRes['pm'] = $arr[0]; + $dataRes['budget_health'] = $val->budget_health; + $dataRes['actual_cost'] = $actualCost; + $dataRes['progress'] = $progress; + $dataRes['comment'] = $commentActivity; + $dataRes['man_power'] = $manpowers; + } + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, 'totalRecord'=>$countData], 200); + } +} diff --git a/app/Http/Middleware/CorsMiddleware.php b/app/Http/Middleware/CorsMiddleware.php index 99d148a..ba1bd81 100644 --- a/app/Http/Middleware/CorsMiddleware.php +++ b/app/Http/Middleware/CorsMiddleware.php @@ -1,39 +1,39 @@ - '*', - 'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE', - 'Access-Control-Allow-Credentials' => 'true', - 'Access-Control-Max-Age' => '86400', - 'Access-Control-Allow-Headers' => 'Content-Type, Accept, Authorization, X-Requested-With, Application' - ]; - - if ($request->isMethod('OPTIONS')) - { - return response()->json('{"method":"OPTIONS"}', 200, $headers); - } - - $response = $next($request); - foreach($headers as $key => $value) - { - $response->headers->set($key, $value); - } - - return $response; - } -} + '*', + 'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE', + 'Access-Control-Allow-Credentials' => 'true', + 'Access-Control-Max-Age' => '86400', + 'Access-Control-Allow-Headers' => 'Content-Type, Accept, Authorization, X-Requested-With, Application' + ]; + + if ($request->isMethod('OPTIONS')) + { + return response()->json('{"method":"OPTIONS"}', 200, $headers); + } + + $response = $next($request); + foreach($headers as $key => $value) + { + $response->headers->set($key, $value); + } + + return $response; + } +} diff --git a/app/Models/Activity.php b/app/Models/Activity.php index e3358b2..1f01083 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -130,9 +130,10 @@ class Activity extends Model public function getJobsDoneAttribute() { $tmpPercentage = []; - $dataPlan = AssignMaterial::where('activity_id', $this->id)->get(); - if($dataPlan->isEmpty()) - return 0; + if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) + return 0; + if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) + return 0; foreach ($dataPlan as $value) { $tmpPercentage[] = 100; $getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty"); diff --git a/routes/web.php b/routes/web.php index 807c355..153d050 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,415 +1,3 @@ -<<<<<<< HEAD -get('/', function () use ($router) { - return $router->app->version(); -}); - -$router->group(['prefix'=>'api'], function () use ($router) { - $router->post('/login', 'AuthController@login'); - - $router->post('/menu/add', 'MenuController@add'); - $router->get('/menu/edit/{id}', 'MenuController@edit'); - $router->put('/menu/update/{id}', 'MenuController@update'); - $router->delete('/menu/delete/{id}', 'MenuController@delete'); - $router->post('/menu/search', 'MenuController@search'); - $router->get('/menu/management/{id}', 'MenuController@listMenu'); - $router->get('/menu/list', 'MenuController@list'); - $router->post('/role-menu/add', 'RoleMenuController@add'); - $router->put('/role-menu/update/{id}', 'RoleMenuController@update'); - $router->delete('/role-menu/delete/{id}', 'RoleMenuController@delete'); - $router->delete('/role-menu/delete-byrole/{id}', 'RoleMenuController@deleteByRole'); - $router->post('/role-menu/search', 'RoleMenuController@search'); - $router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu'); - - $router->group(['middleware' => 'auth'], function () use ($router) { - - $router->post('/role/search', 'RoleController@search'); - $router->post('/role/add', 'RoleController@add'); - $router->get('/role/edit/{id}', 'RoleController@edit'); - $router->put('/role/update/{id}', 'RoleController@update'); - $router->delete('/role/delete/{id}', 'RoleController@delete'); - $router->get('/role/list', 'RoleController@list'); - - $router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen'); - $router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId'); - $router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete'); - $router->post('/document-project/search', 'ProjectDokumenController@searchDocProject'); - $router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen'); - - $router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen'); - $router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId'); - $router->delete('/document-activity/delete/{id}', 'ActivityDokumenController@delete'); - $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); - $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); - - $router->post('/project/search', 'ProjectController@search'); - $router->post('/project/add', 'ProjectController@add'); - $router->put('/project/update/{id}', 'ProjectController@update'); - $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-charter/search', 'ProjectCharterController@search'); - $router->post('/project-charter/add', 'ProjectCharterController@add'); - $router->put('/project-charter/update/{id}', 'ProjectCharterController@update'); - - $router->post('/divisi/add', 'DivisiController@add'); - $router->get('/divisi/edit/{id}', 'DivisiController@edit'); - $router->put('/divisi/update/{id}', 'DivisiController@update'); - $router->post('/divisi/search', 'DivisiController@search'); - $router->delete('/divisi/delete/{id}', 'DivisiController@delete'); - $router->get('/divisi/list', 'DivisiController@list'); - - $router->post('/config-alert/search', 'ConfigAlertController@search'); - $router->post('/config-alert/add', 'ConfigAlertController@add'); - $router->get('/config-alert/edit/{id}', 'ConfigAlertController@edit'); - $router->put('/config-alert/update/{id}', 'ConfigAlertController@update'); - $router->delete('/config-alert/delete/{id}', 'ConfigAlertController@delete'); - $router->get('/config-alert/list', 'ConfigAlertController@list'); - - $router->post('/config-alert-to-user/search', 'ConfigAlertUserController@search'); - $router->post('/config-alert-to-user/add', 'ConfigAlertUserController@add'); - $router->put('/config-alert-to-user/update/{id}', 'ConfigAlertUserController@update'); - $router->delete('/config-alert-to-user/delete/{id}', 'ConfigAlertUserController@delete'); - $router->get('/config-alert/get-user/{id}', 'ConfigAlertUserController@getConfigUser'); - - $router->post('/human-resource/search', 'HumanResourceController@search'); - $router->post('/human-resource/add', 'HumanResourceController@add'); - $router->get('/human-resource/edit/{id}', 'HumanResourceController@edit'); - $router->put('/human-resource/update/{id}', 'HumanResourceController@update'); - $router->delete('/human-resource/delete/{id}', 'HumanResourceController@delete'); - $router->get('/human-resource/list', 'HumanResourceController@list'); - $router->get('/human-resource/select', 'HumanResourceController@select'); - $router->post('/human-resource/check-old-password/{id}', 'HumanResourceController@checkOldPassword'); - - $router->post('/project-role/search', 'ProjectRoleController@search'); - $router->post('/project-role/add', 'ProjectRoleController@add'); - $router->get('/project-role/edit/{id}', 'ProjectRoleController@edit'); - $router->put('/project-role/update/{id}', 'ProjectRoleController@update'); - $router->delete('/project-role/delete/{id}', 'ProjectRoleController@delete'); - $router->get('/project-role/list', 'ProjectRoleController@list'); - $router->get('/project-role/select', 'ProjectRoleController@select'); - - $router->post('/project-type/search', 'ProjectTypeController@search'); - $router->post('/project-type/add', 'ProjectTypeController@add'); - $router->get('/project-type/edit/{id}', 'ProjectTypeController@edit'); - $router->put('/project-type/update/{id}', 'ProjectTypeController@update'); - $router->delete('/project-type/delete/{id}', 'ProjectTypeController@delete'); - $router->get('/project-type/list', 'ProjectTypeController@list'); - - $router->post('/user-to-project/assign', 'UserProyekController@assignUserProyek'); - - $router->post('/request-material/add', 'RequestMaterialController@add'); - $router->post('/request-material/search', 'RequestMaterialController@search'); - $router->get('/request-material/edit/{id}', 'RequestMaterialController@edit'); - $router->put('/request-material/update/{id}', 'RequestMaterialController@update'); - $router->delete('/request-material/delete/{id}', 'RequestMaterialController@delete'); - $router->get('/request-material/list', 'RequestMaterialController@list'); - - $router->put('/request-material/update-warehouse-site/{id}', 'RequestMaterialController@updateWarehouseSite'); - - $router->post('/material-to-project/assign', 'MaterialProjectController@assignMaterial'); - - $router->post('/material-resource/add', 'MaterialResourceController@add'); - $router->post('/material-resource/search', 'MaterialResourceController@search'); - $router->get('/material-resource/update/{id}', 'MaterialResourceController@edit'); - $router->put('/material-resource/update/{id}', 'MaterialResourceController@update'); - $router->delete('/material-resource/delete/{id}', 'MaterialResourceController@delete'); - $router->get('/material-resource/list', 'MaterialResourceController@list'); - $router->get('/material-resource/select', 'MaterialResourceController@select'); - - $router->post('/tools-to-project/assign', 'ToolsProjectController@assignTools'); - $router->get('/tools-to-project/search', 'ToolsProjectController@searchTools'); - - $router->post('/tools-resource/add', 'ToolsResourceController@add'); - $router->post('/tools-resource/search', 'ToolsResourceController@search'); - $router->get('/tools-resource/edit/{id}', 'ToolsResourceController@edit'); - $router->put('/tools-resource/update/{id}', 'ToolsResourceController@update'); - $router->delete('/tools-resource/delete/{id}', 'ToolsResourceController@delete'); - $router->get('/tools-resource/list', 'ToolsResourceController@list'); - $router->get('/tools-resource/select', 'ToolsResourceController@select'); - - $router->post('/req-tools/add', 'ToolsRequestController@add'); - $router->get('/req-tools/edit/{id}', 'ToolsRequestController@edit'); - $router->put('/req-tools/update/{id}', 'ToolsRequestController@update'); - $router->post('/req-tools/search', 'ToolsRequestController@search'); - $router->delete('/req-tools/delete/{id}', 'ToolsRequestController@delete'); - $router->get('/req-tools/list', 'ToolsRequestController@list'); - - $router->post('/version-gantt/add', 'VersionGanttController@add'); - $router->get('/version-gantt/edit/{id}', 'VersionGanttController@edit'); - $router->put('/version-gantt/update/{id}', 'VersionGanttController@update'); - $router->post('/version-gantt/search', 'VersionGanttController@search'); - $router->delete('/version-gantt/delete/{id}', 'VersionGanttController@delete'); - $router->get('/version-gantt/list', 'VersionGanttController@list'); - - $router->post('/user-to-version-gantt/add', 'UserToVersionGanttController@add'); - $router->post('/user-to-version-gantt/add-multiple', 'UserToVersionGanttController@addMultiple'); - $router->get('/user-to-version-gantt/edit/{id}', 'UserToVersionGanttController@edit'); - $router->put('/user-to-version-gantt/update/{id}', 'UserToVersionGanttController@update'); - $router->post('/user-to-version-gantt/search', 'UserToVersionGanttController@search'); - $router->delete('/user-to-version-gantt/delete/{id}', 'UserToVersionGanttController@delete'); - $router->get('/user-to-version-gantt/list', 'UserToVersionGanttController@list'); - $router->get('/user-to-version-gantt/get-by-gantt/{gantt_id}', 'UserToVersionGanttController@getByUserGantt'); - - $router->post('/user-to-activity/add', 'UserToActivityController@add'); - $router->post('/user-to-activity/add-multiple', 'UserToActivityController@addMultiple'); - $router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit'); - $router->put('/user-to-activity/update/{id}', 'UserToActivityController@update'); - $router->post('/user-to-activity/search', 'UserToActivityController@search'); - $router->delete('/user-to-activity/delete/{id}', 'UserToActivityController@delete'); - $router->get('/user-to-activity/list', 'UserToActivityController@list'); - $router->get('/user-to-activity/datatables', 'UserToActivityController@datatables'); - - $router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial'); - $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); - $router->get('/activity/search', 'ActivityController@search'); - $router->post('/task', 'ActivityController@add'); - $router->get('/task/edit/{id}', 'ActivityController@edit'); - $router->put('/task/{id}', 'ActivityController@update'); - $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'); - $router->put('/link/{id}', 'LinkController@update'); - $router->delete('/link/{id}', 'LinkController@delete'); - - $router->post('/template-gantt/add', 'TemplateGanttController@add'); - $router->get('/template-gantt/edit/{id}', 'TemplateGanttController@edit'); - $router->put('/template-gantt/update/{id}', 'TemplateGanttController@update'); - $router->post('/template-gantt/search', 'TemplateGanttController@search'); - $router->delete('/template-gantt/delete/{id}', 'TemplateGanttController@delete'); - $router->get('/template-gantt/list', 'TemplateGanttController@list'); - $router->get('/template-gantt/get-tree/{id}', 'TemplateGanttController@getTreeByTypeProject'); - - $router->post('/comment-activity/add', 'CommentActivityController@add'); - $router->get('/comment-activity/edit/{id}', 'CommentActivityController@edit'); - $router->put('/comment-activity/update/{id}', 'CommentActivityController@update'); - $router->post('/comment-activity/search', 'CommentActivityController@search'); - $router->delete('/comment-activity/delete/{id}', 'CommentActivityController@delete'); - $router->get('/comment-activity/list', 'CommentActivityController@list'); - - $router->post('/presence/add', 'PresenceController@add'); - $router->get('/presence/edit/{id}', 'PresenceController@edit'); - $router->put('/presence/update/{id}', 'PresenceController@update'); - $router->post('/presence/search', 'PresenceController@search'); - $router->delete('/presence/delete/{id}', 'PresenceController@delete'); - $router->get('/presence/list', 'PresenceController@list'); - $router->get('/presence/clockinout/{id}', 'PresenceController@clockinout'); - $router->get('/presence/bulk-update-location', 'PresenceController@bulkUpdateLocation'); - - $router->post('/permit/add', 'AbsentController@add'); - $router->get('/permit/edit/{id}', 'AbsentController@edit'); - $router->put('/permit/update/{id}', 'AbsentController@update'); - $router->post('/permit/search', 'AbsentController@search'); - $router->delete('/permit/delete/{id}', 'AbsentController@delete'); - $router->get('/permit/list', 'AbsentController@list'); - - $router->post('/assign-tools/add', 'AssignToolsController@add'); - $router->get('/assign-tools/edit/{id}', 'AssignToolsController@edit'); - $router->put('/assign-tools/update/{id}', 'AssignToolsController@update'); - $router->post('/assign-tools/search', 'AssignToolsController@search'); - $router->delete('/assign-tools/delete/{id}', 'AssignToolsController@delete'); - $router->get('/assign-tools/list', 'AssignToolsController@list'); - $router->get('/assign-tools/datatables', 'AssignToolsController@datatables'); - - $router->post('/assign-material/add', 'AssignMaterialController@add'); - $router->get('/assign-material/edit/{id}', 'AssignMaterialController@edit'); - $router->put('/assign-material/update/{id}', 'AssignMaterialController@update'); - $router->post('/assign-material/search', 'AssignMaterialController@search'); - $router->delete('/assign-material/delete/{id}', 'AssignMaterialController@delete'); - $router->get('/assign-material/list', 'AssignMaterialController@list'); - $router->get('/assign-material/datatables', 'AssignMaterialController@datatables'); - $router->get('/assign-material/datatablesForReportActivity', 'AssignMaterialController@datatablesForReportActivity'); - $router->post('/assign-material/ForReportActivityByMaterial', 'AssignMaterialController@ForReportActivityByMaterial'); - - $router->post('/image/search', 'ImageController@search'); - $router->delete('/image/delete/{id}', 'ImageController@delete'); - $router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef'); - $router->post('/image/upload', 'ImageController@uploadImage'); - $router->get('/image/{id}/{category}', 'ImageController@getByRefId'); - - $router->post('/panic-button/add', 'PanicButtonController@add'); - $router->get('/panic-button/edit/{id}', 'PanicButtonController@edit'); - $router->put('/panic-button/update/{id}', 'PanicButtonController@update'); - $router->post('/panic-button/search', 'PanicButtonController@search'); - $router->delete('/panic-button/delete/{id}', 'PanicButtonController@delete'); - $router->get('/panic-button/list', 'PanicButtonController@list'); - - $router->post('/rate-sallary/add', 'RateSallaryController@add'); - $router->get('/rate-sallary/edit/{id}', 'RateSallaryController@edit'); - $router->put('/rate-sallary/update/{id}', 'RateSallaryController@update'); - $router->post('/rate-sallary/search', 'RateSallaryController@search'); - $router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete'); - $router->get('/rate-sallary/list', 'RateSallaryController@list'); - - $router->post('/project-participants/add', 'ProjectParticipantsController@add'); - $router->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit'); - $router->put('/project-participants/update/{id}', 'ProjectParticipantsController@update'); - $router->post('/project-participants/search', 'ProjectParticipantsController@search'); - $router->delete('/project-participants/delete/{id}', 'ProjectParticipantsController@delete'); - $router->delete('/project-participants/delete-by-proyek/{id}', 'ProjectParticipantsController@deleteByProyek'); - $router->get('/project-participants/list', 'ProjectParticipantsController@list'); - $router->get('/project-participants/{where}/{val}', 'ProjectParticipantsController@customWhere'); - - $router->post('/project-approval/add', 'ProjectApprovalController@add'); - $router->get('/project-approval/edit/{id}', 'ProjectApprovalController@edit'); - $router->put('/project-approval/update/{id}', 'ProjectApprovalController@update'); - $router->post('/project-approval/search', 'ProjectApprovalController@search'); - $router->delete('/project-approval/delete/{id}', 'ProjectApprovalController@delete'); - $router->delete('/project-approval/delete-by-proyek/{id}', 'ProjectApprovalController@deleteByProyek'); - $router->get('/project-approval/list', 'ProjectApprovalController@list'); - $router->get('/project-approval/{where}/{val}', 'ProjectApprovalController@customWhere'); - - $router->post('/project-milestone/add', 'ProjectMileStoneController@add'); - $router->get('/project-milestone/edit/{id}', 'ProjectMileStoneController@edit'); - $router->put('/project-milestone/update/{id}', 'ProjectMileStoneController@update'); - $router->post('/project-milestone/search', 'ProjectMileStoneController@search'); - $router->delete('/project-milestone/delete/{id}', 'ProjectMileStoneController@delete'); - $router->delete('/project-milestone/delete-by-proyek/{id}', 'ProjectMileStoneController@deleteByProyek'); - $router->get('/project-milestone/list', 'ProjectMileStoneController@list'); - $router->get('/project-milestone/select', 'ProjectMileStoneController@select'); - $router->get('/project-milestone/{where}/{val}', 'ProjectMileStoneController@customWhere'); - - $router->post('/dashboard/cost-planning-actual', 'DashboardController@costPlanningActual'); - $router->post('/dashboard/percentage-planning-actual', 'DashboardController@percentagePlanningActual'); - $router->post('/dashboard/search-user-presence', 'DashboardController@searchUserPresencePoints'); - $router->post('/dashboard/status-proyek', 'DashboardController@statusProyek'); - $router->post('/dashboard/curva-s', 'DashboardController@curvaS'); - - $router->post('/report-activity/add', 'ReportActivityController@add'); - $router->get('/report-activity/edit/{id}', 'ReportActivityController@edit'); - $router->put('/report-activity/update/{id}', 'ReportActivityController@update'); - $router->post('/report-activity/search', 'ReportActivityController@search'); - $router->delete('/report-activity/delete/{id}', 'ReportActivityController@delete'); - $router->get('/report-activity/list', 'ReportActivityController@list'); - $router->post('/report-activity/search-point', 'ReportActivityController@searchPoint'); - $router->get('/report-activity/datatables', 'ReportActivityController@datatables'); - - $router->post('/report-activity-material/add', 'ReportActivityMaterialController@add'); - $router->post('/report-activity-material/search', 'ReportActivityMaterialController@search'); - $router->delete('/report-activity-material/delete/{id}', 'ReportActivityMaterialController@delete'); - $router->get('/report-activity-material/list', 'ReportActivityMaterialController@list'); - $router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables'); - $router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish'); - $router->get('/report-activity-material/test', 'ReportActivityMaterialController@countForProgressTest'); - - - $router->post('/waypoint/add', 'WaypointController@add'); - $router->get('/waypoint/edit/{id}', 'WaypointController@edit'); - $router->put('/waypoint/update/{id}', 'WaypointController@update'); - $router->post('/waypoint/search', 'WaypointController@search'); - $router->delete('/waypoint/delete/{id}', 'WaypointController@delete'); - $router->get('/waypoint/list', 'WaypointController@list'); - - $router->post('/holiday/add', 'HolidayController@add'); - $router->get('/holiday/edit/{id}', 'HolidayController@edit'); - $router->put('/holiday/update/{id}', 'HolidayController@update'); - $router->post('/holiday/search', 'HolidayController@search'); - $router->delete('/holiday/delete/{id}', 'HolidayController@delete'); - $router->get('/holiday/list', 'HolidayController@list'); - $router->get('/holiday/datatables', 'HolidayController@datatables'); - - $router->post('/satuan/add', 'SatuanController@add'); - $router->get('/satuan/edit/{id}', 'SatuanController@edit'); - $router->put('/satuan/update/{id}', 'SatuanController@update'); - $router->post('/satuan/search', 'SatuanController@search'); - $router->delete('/satuan/delete/{id}', 'SatuanController@delete'); - $router->get('/satuan/list', 'SatuanController@list'); - - $router->post('/checklist-k3/add', 'ChecklistK3Controller@add'); - $router->get('/checklist-k3/edit/{id}', 'ChecklistK3Controller@edit'); - $router->put('/checklist-k3/update/{id}', 'ChecklistK3Controller@update'); - $router->post('/checklist-k3/search', 'ChecklistK3Controller@search'); - $router->delete('/checklist-k3/delete/{id}', 'ChecklistK3Controller@delete'); - $router->get('/checklist-k3/list', 'ChecklistK3Controller@list'); - - $router->post('/report-k3/add', 'ReportK3Controller@add'); - $router->get('/report-k3/edit/{id}', 'ReportK3Controller@edit'); - $router->put('/report-k3/update/{id}', 'ReportK3Controller@update'); - $router->post('/report-k3/search', 'ReportK3Controller@search'); - $router->delete('/report-k3/delete/{id}', 'ReportK3Controller@delete'); - $router->get('/report-k3/list', 'ReportK3Controller@list'); - - $router->post('/report-k3-detail/add', 'ReportK3DetailController@add'); - $router->get('/report-k3-detail/edit/{id}', 'ReportK3DetailController@edit'); - $router->put('/report-k3-detail/update/{id}', 'ReportK3DetailController@update'); - $router->post('/report-k3-detail/search', 'ReportK3DetailController@search'); - $router->delete('/report-k3-detail/delete/{id}', 'ReportK3DetailController@delete'); - $router->get('/report-k3-detail/list', 'ReportK3DetailController@list'); - - $router->post('/user-to-proyek/add', 'UserToProyekController@add'); - $router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit'); - $router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update'); - $router->post('/user-to-proyek/search', 'UserToProyekController@search'); - $router->delete('/user-to-proyek/delete/{id}', 'UserToProyekController@delete'); - $router->get('/user-to-proyek/list', 'UserToProyekController@list'); - $router->get('/user-to-proyek/select', 'UserToProyekController@select'); - - $router->post('/folder-document-proyek/add', 'FolderDocumentProyekController@add'); - $router->get('/folder-document-proyek/edit/{id}', 'FolderDocumentProyekController@edit'); - $router->put('/folder-document-proyek/update/{id}', 'FolderDocumentProyekController@update'); - $router->post('/folder-document-proyek/search', 'FolderDocumentProyekController@search'); - $router->delete('/folder-document-proyek/delete/{id}', 'FolderDocumentProyekController@delete'); - $router->get('/folder-document-proyek/list', 'FolderDocumentProyekController@list'); - $router->get('/folder-document-proyek/get-tree/{id}', 'FolderDocumentProyekController@getTree'); - - $router->post('/office-hours/add', 'OfficeHoursController@add'); - $router->get('/office-hours/edit/{id}', 'OfficeHoursController@edit'); - $router->put('/office-hours/update/{id}', 'OfficeHoursController@update'); - $router->post('/office-hours/search', 'OfficeHoursController@search'); - $router->delete('/office-hours/delete/{id}', 'OfficeHoursController@delete'); - $router->get('/office-hours/list', 'OfficeHoursController@list'); - - $router->get('/gantt-show-hide/get-by-gantt/{gantt_id}', 'ShowHideColumnController@getByUserGantt'); - $router->post('/gantt-show-hide/add', 'ShowHideColumnController@add'); - $router->post('/gantt-show-hide/update/{gantt_id}', 'ShowHideColumnController@update'); - - - $router->post('/shift/add', 'ShiftController@add'); - $router->get('/shift/edit/{id}', 'ShiftController@edit'); - $router->put('/shift/update/{id}', 'ShiftController@update'); - $router->post('/shift/search', 'ShiftController@search'); - $router->delete('/shift/delete/{id}', 'ShiftController@delete'); - $router->get('/shift/list', 'ShiftController@list'); - - $router->post('/user-monthly-shift/add', 'UserMonthlyShiftController@add'); - $router->put('/user-monthly-shift/update/{id}', 'UserMonthlyShiftController@update'); - $router->post('/user-monthly-shift/search', 'UserMonthlyShiftController@search'); - $router->delete('/user-monthly-shift/delete/{id}', 'UserMonthlyShiftController@delete'); - $router->delete('/user-monthly-shift/delete-at/{yyyymm}', 'UserMonthlyShiftController@deleteYYYYMM'); - $router->get('/user-monthly-shift/list', 'UserMonthlyShiftController@list'); - $router->post('/user-monthly-shift/import', 'UserMonthlyShiftController@import'); - $router->get('/user-monthly-shift/list/{yyyymm}', 'UserMonthlyShiftController@listYYYYMM'); - - $router->post('/user-to-shift/add', 'UserToShiftController@add'); - $router->get('/user-to-shift/edit/{id}', 'UserToShiftController@edit'); - $router->put('/user-to-shift/update/{id}', 'UserToShiftController@update'); - $router->post('/user-to-shift/search', 'UserToShiftController@search'); - $router->delete('/user-to-shift/delete/{id}', 'UserToShiftController@delete'); - $router->get('/user-to-shift/list', 'UserToShiftController@list'); - - $router->post('/control-monitoring/search', 'ControlMonitoringController@search'); - $router->get('/currency/list', 'CurrencyController@list'); - - $router->post('/project-to-checklist-k3/add', 'ProjectToChecklistK3Controller@add'); - $router->post('/project-to-checklist-k3/add-multiple', 'ProjectToChecklistK3Controller@addMultiple'); - $router->get('/project-to-checklist-k3/edit/{id}', 'ProjectToChecklistK3Controller@edit'); - $router->put('/project-to-checklist-k3/update/{id}', 'ProjectToChecklistK3Controller@update'); - $router->post('/project-to-checklist-k3/search', 'ProjectToChecklistK3Controller@search'); - $router->delete('/project-to-checklist-k3/delete/{id}', 'ProjectToChecklistK3Controller@delete'); - $router->get('/project-to-checklist-k3/list', 'ProjectToChecklistK3Controller@list'); - }); - -}); -======= get('/', function () use ($router) { @@ -460,6 +48,7 @@ $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-charter/search', 'ProjectCharterController@search'); $router->post('/project-charter/add', 'ProjectCharterController@add'); @@ -508,6 +97,13 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->put('/project-type/update/{id}', 'ProjectTypeController@update'); $router->delete('/project-type/delete/{id}', 'ProjectTypeController@delete'); $router->get('/project-type/list', 'ProjectTypeController@list'); + + $router->post('/project-phase/search', 'ProjectPhaseController@search'); + $router->post('/project-phase/add', 'ProjectPhaseController@add'); + $router->get('/project-phase/edit/{id}', 'ProjectPhaseController@edit'); + $router->put('/project-phase/update/{id}', 'ProjectPhaseController@update'); + $router->delete('/project-phase/delete/{id}', 'ProjectPhaseController@delete'); + $router->get('/project-phase/list', 'ProjectPhaseController@list'); $router->post('/user-to-project/assign', 'UserProyekController@assignUserProyek'); @@ -819,4 +415,3 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout }); }); ->>>>>>> d6dcff417710f6f13b2c20098213dfbeac52ff2d From 56194e5e942d45b66cd3ef2f281f05b427afd0d1 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 4 Aug 2022 16:57:08 +0700 Subject: [PATCH 07/17] bug fix --- app/Http/Controllers/ProjectController.php | 5 +- .../Controllers/ProjectPhaseController.php | 84 +++++++++++++++++++ app/Models/ProjectPhase.php | 17 ++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/ProjectPhaseController.php create mode 100644 app/Models/ProjectPhase.php diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index c9ea6a4..0bd3c42 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -212,6 +212,7 @@ class ProjectController extends Controller { $data = Project::orderBy('id', 'desc')->get(); $countData = $data->count(); + if(!$data) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); @@ -223,6 +224,7 @@ class ProjectController extends Controller $lastActivity = null; $scheduleHealth = "on-track"; $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); + if($rootActivity){ $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; $actualCost = $rootActivity->biaya_actual ?? 0; @@ -244,7 +246,7 @@ class ProjectController extends Controller $d->lastActivity = $lastActivity ?? "-"; $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); $d->scheduleHealth = $scheduleHealth; - + $d->plannedCost = $d->rencana_biaya; $d->actualCost = $actualCost; $d->costVariance = $costVariance; @@ -260,6 +262,7 @@ class ProjectController extends Controller $manpowers = User::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')) diff --git a/app/Http/Controllers/ProjectPhaseController.php b/app/Http/Controllers/ProjectPhaseController.php new file mode 100644 index 0000000..1dd1259 --- /dev/null +++ b/app/Http/Controllers/ProjectPhaseController.php @@ -0,0 +1,84 @@ +validate($request, [ + 'name' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + if(!ProjectPhase::create($data)) + return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id=="") + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + if(!$result = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id=="") + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + if(!$data = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); + + if(!$data->update($request->all())) + return response()->json(['status'=>'failed','message'=>'data project type failed updated!','code'=>400], 400); + + return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200); + } + + public function delete($id) + { + + if(!$data = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'data project phase not found!','code'=>400], 400); + + if(!$data->delete()) + return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_proyek_phase'); + $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 = ProjectPhase::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'failed get list project type, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + + } +} diff --git a/app/Models/ProjectPhase.php b/app/Models/ProjectPhase.php new file mode 100644 index 0000000..1a82a81 --- /dev/null +++ b/app/Models/ProjectPhase.php @@ -0,0 +1,17 @@ + Date: Tue, 2 Aug 2022 11:57:14 +0700 Subject: [PATCH 08/17] Dashboard PMO & Project Phase --- .../.ReportActivityMaterialController.php.swp | Bin 20480 -> 0 bytes app/Http/Controllers/ProjectController.php | 44 ++++----- .../Controllers/ProjectPhaseController.php | 89 ++++++++++++++++++ app/Models/Project.php | 2 + 4 files changed, 111 insertions(+), 24 deletions(-) delete mode 100644 app/Http/Controllers/.ReportActivityMaterialController.php.swp diff --git a/app/Http/Controllers/.ReportActivityMaterialController.php.swp b/app/Http/Controllers/.ReportActivityMaterialController.php.swp deleted file mode 100644 index 6c4666e885359659e4ceafb411f69fd965acc9c4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI4Ym6jS6@Uv6q(P9CL=yyZw`u7f(mgZFL)L+AoY@C#VA*AtUBumGsOhemsomhk8|%m_ndq0?9BM?EnCI<(RCKD(=6-H*Zy(l*-gh<{>_#Z2cau3zus%( zrkz(_yKQ^vqRGp5ZrY|&8u-XZWP)RhL3ki)*i|PQo3X109KSX;x$(Nvl=*Hq8e><) zabs*l;KyO$c}^IO?Qj}F7*AGXcfpO9w%V~1y0+Jr7;Vfq24`^AE^dX4Wt@KHIQl`)j+C&R0F97QVpaU zNHvgZAl1PCKm&HovUa`0vYr9C|DVMFuf5Z#8o`i?s2%HHr|Gz;KVwi$ooNQT-!B63na0HsL5!S#T zPO_}u!Vw5z8ZLk{;FXMJ{Tv>JkHRf*2u^_v90OlC(Xu`Zcf(z<01-^UV{a#4sKb76 zVG=4(hIhl0Cs@|Qa4*~gharFu!fEjI@s{;_2w^>345!26ET-H8H^5F<11G}?@DK|r zUx&}Zr{Qk63+{wZ!Od_LoC|B=B^GX8gulb1@ME|g>fpgPD8kur798Cx!|NPT4QkHl z=qP&2%m$%jSLa0`SF>Y#yJ!2tjzn(3_L|O!IE08hTUgt=S*p0vrg|e@DvXRAl8Vp8 z^~QE5tU7*d&pGQvS?t+&iM-xQt}G^_$er_(Lmm?oi}OzC6!Nw?{W0y<@f@7M=tOwbkmPF2jTWGm8M#R^yqp- zjA^Cx-H>VO9L;-gGws<&);X%yYPU*RtQ#K}mx&LIi;1pVDzT0t_OO%JFObFSSYQ!Smtx!|Cq_Bu4ul6I!P2ctBjC><>t4<=RKil#hCD!6cWl*TYG8Uz; zrK#E~4N6X_FEJ?EASI@ORFkh06SJ;gD@bXn;6oUm&|RQWhFcyb+--O;NR7acoB}Pj zKMMT9p1f{}e7Ta3npF=I`8|ROY?<)%4O?w;5 zwrmEow(B_<(T?=~M4TG|%MR8{p$63K_n zftutj+srhV$}`jMTxPCQQ(P`|ZfY`Xl`3|7>Z8NxiKuUyN+v2MAuaJbQ`It)6-Ghj1QtPOO#4h?(B3+$TCLbXP&Ei8xK3VeZf zNjmjJ`Bi!uGqPHfMqbU{!%8o!ou~7<(fqI{dhRMs$xOm{*c071)zsfraVnb3{(XLo zR>w|dr+E+K&8l#P9lCRfr1ol3>hNur9Ww)a@D{((j72h+icp=o6^Two70(ab(`|Zm zlNnd2$K&egB1t05TBhT#)=s@nA@wNlEvxCsd-BX(dF9LK5=XZ0#_r9|MyKl5Z7h}S z?nX-2Okc43=U$o0N;+q&eR@Z6!)sO#6!MI8hV-l(O7B$8kERSp+jyIu1@7=RTe1`+ z=>z29c`_N&(Y7t4s@y#_t6y?Tkz>FOX;RhcJK8AU@j#cL>bhEYI1nz{!Cf{(sVMgJ zd*ODiHn^vD`{91GKI4R{O8P66isEpZKIm~$ypS#OZ!}xX>APA{gC&v5b_w>)&wZ_K z5+!^gLachU_7G>Rec)U;2V+jIN1}a+*fes4G;*;$<2lhK>i1-$v3Dy|wHNK}?k@ee zjgjxWF?fpAVp}|~S$BQfVXr(izt>m=dVo(vqK?@MSp;>nT~-QbU3!^3G%w@-$Jp#I z5lhPWKiR*3oS6Pz@SzUJ!B2?akH7&KfqxRWe;d9AE>vL#Y}gBH;6!+VSpF~Y99#)k zz~yijoB{tLmVW^502?;I8E_wQ{8!-1@Nu{UY?y*cxDXy8j(-@&p$H>TfLDp(e+Hk2 zMYs{3CuYABwwm}o!{@Wa=}*8{;biy+@%i)cL-;Q2f($%DY<>qEhJCOZ&V*ah+Z@~o z?}zhY45U7bkiOnR8en>rGpu&nN|n%F+z>GS{0RSDn$N(`@57qc?E_9B4p|YA77clP zUinH^9kl3FY=Xf|u5|&km%r2&^Pw|a&hEDt?5G;Ljd)@qaBGF}k*spaOKz>4&5!27 zU{MBrqxq~*Mys6FUbL8reMzZi`*TjHzD9NR5!&^V7RpvGb(6 zl`274bHb^m0+W;clb@DH)e3w^%?&yCNS_)N<&%_*_dN8`&MA(#*{!vbPg2+)xPBp9 zpT?AjkzCqpW{V=*9Cd5*vn=0+rY@hs!O5z$R1Im)9RvSzX<{NGlB>pr;i;XcGnQst zmSetIw|(ZrC}^?@qw;7k1EIIHFTR0&vDg2LgI33(XAJ3u%RRL6j)-&B>iV)D)MdA* zclO8S^66N6>F$=@zDT<}E|(ZRlALRfwn=i0RhEZgDE}63T6R=jwq{UQBPXb)q+@nn&E)WZms}#&}X)o^e~W8Y|J> z1!HNFwC6V1V{KXf)rKx6HercLS_Ns{TB}MeH5Ns~b67kUakwPxIotJxCpFx$2qV`m zih_5gqqY%PNwL~-Uwiqen3pwYDM^_uEUH>l-r-a+#qz3JNZ*J^Yn@34_3|kdbY|Kj zQseSE>*6vP?1*TVF@+{($sFnrA3V2z(SC)2?XU`7?!^6d?5J`_E%oZU)`YB?s?$`{ z^_ZgiYe>RUXePPeUP|nIF42%lW)EvZC@QZvLCmv#GUmFGk_tADOGy*TI`OW?cDT_xE>T{}f`4YX%NBWcF= zrivEo-V$lGXX3aG*fV(}cU5F8p16$ZzKWa-SPkpj#A&Y=vI5e%(R6g%Dyx5z(JF0R zd+TPn>z3?C_RUPv5qPt0$jJErW5lV)664DFKRMt3AL9Kd;ClEFoD1J1=6?_#fEXgU z9t!X>asH3sVTfQiY=HN`zlrgG2j77E!GRlL8eSyM|0_HLx56Pf2#fGxxDL*S2Z{9` zfNS7t*b481EUbmsi21(G`O(q?g^1X14EfQ}C@;xh0*Ragn~$0Dmn#@ zN&2`@dd7uwFXDaDG&$uu{uVkDh$I?2_;;rh8 WOS#fI(6-#UJbkXjY`~3J)_(!rbhiKi diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 0bd3c42..578ce35 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -212,7 +212,6 @@ class ProjectController extends Controller { $data = Project::orderBy('id', 'desc')->get(); $countData = $data->count(); - if(!$data) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); @@ -224,7 +223,6 @@ class ProjectController extends Controller $lastActivity = null; $scheduleHealth = "on-track"; $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); - if($rootActivity){ $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; $actualCost = $rootActivity->biaya_actual ?? 0; @@ -241,28 +239,26 @@ class ProjectController extends Controller } elseif ($daysRemaining <= $scheduleWarningThreshold) { $scheduleHealth = "warning"; } - $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); - $d->lastActivity = $lastActivity ?? "-"; - $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); - $d->scheduleHealth = $scheduleHealth; - - $d->plannedCost = $d->rencana_biaya; - $d->actualCost = $actualCost; - $d->costVariance = $costVariance; - $d->costHealth = $d->budget_health; - - $d->progress = $progress; - $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; } + $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); + $d->plannedCost = $d->rencana_biaya; + $d->actualCost = $actualCost; + $d->lastActivity = $lastActivity ?? "-"; + //$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; + $d->costVariance = $costVariance; + $d->costHealth = $d->budget_health; + $d->scheduleHealth = $scheduleHealth; + $d->progress = $progress; + $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; } - + $totalPlannedCost = $data->sum('plannedCost'); $totalActualCost = $data->sum('actualCost'); + // $manpowers = User::where('employee_type', 'employee')->count(); $manpowers = User::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')) @@ -313,18 +309,18 @@ class ProjectController extends Controller } 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', + ->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) - ->get(); - $countData = $data->count(); + ->get(); + $countData = $data->count(); $manpowers = UserToProyek::where('proyek_id', $id)->count(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); - + if($rootActivity){ $actualCost = $rootActivity->biaya_actual ?? 0; $progress = $rootActivity->persentase_progress ?? 0; @@ -355,10 +351,10 @@ class ProjectController extends Controller $dataRes['progress'] = $progress; $dataRes['comment'] = $commentActivity; $dataRes['man_power'] = $manpowers; - } - + } + if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, 'totalRecord'=>$countData], 200); } diff --git a/app/Http/Controllers/ProjectPhaseController.php b/app/Http/Controllers/ProjectPhaseController.php index 1dd1259..e61821b 100644 --- a/app/Http/Controllers/ProjectPhaseController.php +++ b/app/Http/Controllers/ProjectPhaseController.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD validate($request, [ + 'name' => 'required', + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + if(!ProjectPhase::create($data)) + return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id=="") + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + if(!$result = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id=="") + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + if(!$data = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); + + if(!$data->update($request->all())) + return response()->json(['status'=>'failed','message'=>'data project type failed updated!','code'=>400], 400); + + return response()->json(['status'=>'success','message'=>'data project type successfully updated!','code'=>200], 200); + } + + public function delete($id) + { + + if(!$data = ProjectPhase::find($id)) + return response()->json(['status'=>'failed','message'=>'data project type not found!','code'=>400], 400); + + if(!$data->delete()) + return response()->json(['status'=>'failed','message'=>'data project type failed deleted!','code'=>400], 400); + + return response()->json(['status'=>'success','message'=>'data project type successfully deleted!','code'=>200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + dd($payload); + + $dataBuilder = $this->setUpPayload($payload, 'm_proyek_phase'); + $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 = ProjectPhase::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'failed get list project type, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + + } +} +>>>>>>> 3ef5875 (Dashboard PMO & Project Phase) diff --git a/app/Models/Project.php b/app/Models/Project.php index eea1e2e..5cbc7b4 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -39,6 +39,8 @@ class Project extends Model 'currency_code', 'currency_symbol', 'currency_name', + 'budget_health', + 'phase_id', 'created_at', 'created_by', 'updated_at', From c7a00e24019d9d4d2919e70c6a63d54d015fd191 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 4 Aug 2022 12:41:42 +0700 Subject: [PATCH 09/17] bug fix modified: app/Http/Controllers/ActivityController.php modified: app/Http/Controllers/ProjectPhaseController.php --- app/Http/Controllers/ActivityController.php | 411 +++++++++--------- .../Controllers/ProjectPhaseController.php | 91 +--- 2 files changed, 214 insertions(+), 288 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 26a1a0f..f6952aa 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -132,12 +132,11 @@ class ActivityController extends Controller 'created_by'=>$this->currentName, ]); - $resultTypeProject = TemplateGantt::where('proyek_type_id',$project - ->type_proyek_id) + $resultTypeProject = TemplateGantt::where('proyek_type_id', $project->type_proyek_id) ->whereNull('parent_id') ->orderByRaw('id ASC') ->get(); - + foreach($resultTypeProject as $objRow){ $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); $resultNew = Activity::create([ @@ -150,13 +149,13 @@ class ActivityController extends Controller 'end_date'=>date("Y-m-d H:i:s"), 'created_by'=>$this->currentName ]); - $this->getChildrenTemplate($id, $objRow->id, $project->type_project_id ,$proyek_id, $resultNew->id, $project->mulai_proyek); + $this->getChildrenTemplate($id, $objRow->id, $project->type_project_id, $proyek_id, $resultNew->id, $project->mulai_proyek); } } private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay) { - $data = TemplateGantt::where('proyek_type_id', $type_proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); + $data = TemplateGantt::where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); foreach($data as $objRow){ $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); $resultNew = Activity::create([ @@ -401,208 +400,224 @@ class ActivityController extends Controller } $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"); - - } - - $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, $interval, $end); - $arr_ActualM = []; - $tempDate = []; - $tempPercentage = []; - $tempTtlPercentPlan=0; - $tempTtlPercentActual=0; - - $currentACWP = 0; - $budgetControlACWP = 0; - $currentProgressActivity = 0; - $currentBCWP = 0; - $budgetControlBCWP = 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; - try { - $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; - $dataTempPlan [$x]['totalBCWP'] = $totalBCWP; - $x++; - } catch (\Exception $e) { - return response()->json(['message' => $e->getMessage(), - 'data' => $keyPlanM->persentase_progress, - 'data2' => $keyPlanM->bobot_planning, - 'data3' => $keyPlanM->duration, - 'data4' => $totalRencanaBudget, - 'data5' => $keyPlanM, - ]); - } - } - - $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; - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; - $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'){ - if($dt->format("w")==1){ - if($totalACWP > 0 ){ - $budgetControlACWP = $currentACWP + $totalACWP; - } - if($totalBCWP > 0 ){ - $budgetControlBCWP = $currentBCWP + $totalBCWP; - } - - $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 if($dt->format("Y-m-d") == $end2->format("Y-m-d")) { - // error here - $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); - $tempTtlPercentPlan = 0; - $tempTtlPercentActual = 0; - } - }else{ - $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); - $tempDate[] = array($dt->format("Y-m-d"), 0, 0); - } - } - + $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, $interval, $end); + $arr_ActualM = []; + $tempDate = []; + $tempPercentage = []; + $tempTtlPercentPlan=0; + $tempTtlPercentActual=0; + + $currentACWP = 0; + $budgetControlACWP = 0; + $currentProgressActivity = 0; + $currentBCWP = 0; + $budgetControlBCWP = 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'){ + if($dt->format("w")==1){ + if($totalACWP > 0 ){ + $budgetControlACWP = $currentACWP + $totalACWP; + } + if($totalBCWP > 0 ){ + $budgetControlBCWP = $currentBCWP + $totalBCWP; + } + + $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 if($dt->format("Y-m-d") == $end2->format("Y-m-d")) { + $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); + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 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); } - $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); + } 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){ - return array( - "last_gantt_id" => VersionGantt::where("proyek_id", $id)->max("id"), - "proyek_id" => $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) diff --git a/app/Http/Controllers/ProjectPhaseController.php b/app/Http/Controllers/ProjectPhaseController.php index e61821b..6e78855 100644 --- a/app/Http/Controllers/ProjectPhaseController.php +++ b/app/Http/Controllers/ProjectPhaseController.php @@ -1,4 +1,3 @@ -<<<<<<< HEAD json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); } -} -======= -validate($request, [ - 'name' => 'required', - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - if(!ProjectPhase::create($data)) - return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id=="") - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - if(!$result = ProjectPhase::find($id)) - return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); - - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id=="") - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - if(!$data = ProjectPhase::find($id)) - return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); - - if(!$data->update($request->all())) - return response()->json(['status'=>'failed','message'=>'data project type failed updated!','code'=>400], 400); - - return response()->json(['status'=>'success','message'=>'data project type successfully updated!','code'=>200], 200); - } - - public function delete($id) - { - - if(!$data = ProjectPhase::find($id)) - return response()->json(['status'=>'failed','message'=>'data project type not found!','code'=>400], 400); - - if(!$data->delete()) - return response()->json(['status'=>'failed','message'=>'data project type failed deleted!','code'=>400], 400); - - return response()->json(['status'=>'success','message'=>'data project type successfully deleted!','code'=>200], 200); - } - - public function search(Request $request) - { - $payload = $request->all(); - dd($payload); - - $dataBuilder = $this->setUpPayload($payload, 'm_proyek_phase'); - $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 = ProjectPhase::all(); - $countData = $data->count(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'failed get list project type, please try again later!','code'=>400], 400); - - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - - } -} ->>>>>>> 3ef5875 (Dashboard PMO & Project Phase) +} \ No newline at end of file From a488cc98ea2928a28dc9ee5e0a20b41388f01670 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 5 Aug 2022 00:42:58 +0700 Subject: [PATCH 10/17] fix docker composer problem --- Dockerfile | 8 ++------ docker-compose.yml | 16 +--------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8e36fff..15e997f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,14 +28,10 @@ WORKDIR /var/www/html COPY . . RUN chmod +x artisan -RUN composer install -RUN composer dump-autoload --optimize +#RUN composer install --ignore-platform-reqs --prefer-dist --no-scripts --no-progress --no-interaction --no-dev --no-autoloader +#RUN composer dump-autoload --optimize RUN chown -R www-data:www-data . WORKDIR /home/www-data USER www-data - -EXPOSE 9000 - -CMD php-fpm diff --git a/docker-compose.yml b/docker-compose.yml index 93749de..ce2c29f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - '80:80' - '443:443' volumes: - - ./:/var/www/html + - .:/var/www/html:ro,cached - ./docker/nginx/conf.d/:/etc/nginx/conf.d/ links: - app @@ -16,27 +16,13 @@ services: - ospro depends_on: - app - command: [nginx-debug, '-g', 'daemon off;'] app: build: context: . dockerfile: Dockerfile - extra_hosts: - - 'host.docker.internal:host-gateway' - working_dir: /var/www/html - volumes: - - .:/var/www/html restart: unless-stopped - ports: - - "9000:9000" networks: - ospro - healthcheck: - test: curl --fail http://localhost || exit 1 - interval: 60s - retries: 5 - start_period: 20s - timeout: 10s db: image: postgres:14.4-alpine restart: always From 35fc1b51f8ce1b900b87d9ba95e74944fa70d15d Mon Sep 17 00:00:00 2001 From: bnu Date: Fri, 5 Aug 2022 10:38:09 +0700 Subject: [PATCH 11/17] update conflict --- app/Http/Controllers/ActivityController.php | 56 ++++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 4c7b9ba..669c670 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -157,6 +157,7 @@ class ActivityController extends Controller private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay) { $data = TemplateGantt::where('proyek_type_id', $type_proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); + dd($data); foreach($data as $objRow){ $childActivities = TemplateGantt::where("parent_id", $objRow->id)->count(); $resultNew = Activity::create([ @@ -408,9 +409,20 @@ class ActivityController extends Controller $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') @@ -422,7 +434,7 @@ class ActivityController extends Controller ->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); @@ -502,7 +514,11 @@ class ActivityController extends Controller $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; - $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + try { + $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage()]); + } $dataTempReport [$w]['totalacwp'] = $totalACWP; $w++; } @@ -547,11 +563,22 @@ class ActivityController extends Controller } } - if(round($totalACWP,0) > $totalRencanaBudget){ - $estimatedCost = round($totalACWP,0)+0; - }else{ - $estimatedCost = ($totalRencanaBudget+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"; @@ -573,7 +600,7 @@ class ActivityController extends Controller "potential" => $potential, ) ); - + $dataFinal[] = array( "proyek_name"=> $dataProject->nama, "data"=>$dataResponse, @@ -581,15 +608,18 @@ class ActivityController extends Controller ); } + return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); } private function getLatestGantt($id){ - return array( - "last_gantt_id" => VersionGantt::where("proyek_id", $id)->latest(), - "proyek_id" => $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) From ea1c64bf1abe09cc4965b69f1987deed88f83e9b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 5 Aug 2022 16:17:20 +0700 Subject: [PATCH 12/17] projects on danger --- app/Http/Controllers/ProjectController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 578ce35..bb9d679 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -257,6 +257,7 @@ class ProjectController extends Controller $totalActualCost = $data->sum('actualCost'); // $manpowers = User::where('employee_type', 'employee')->count(); $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 { @@ -288,6 +289,7 @@ class ProjectController extends Controller 'totalActualCost' => $totalActualCost, 'totalRevenue' => $totalPlannedCost - $totalActualCost, 'manpowers' => $manpowers, + 'projectsOnDanger'=> $projectsOnDanger, 'projectPhases' => $projectPhases, 'projectsByPhase' => $projectsByPhase, 'projectTypes' => $projectTypes, From 0cb1fe0b437b7f842a81b3a18271de100e179a0f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 5 Aug 2022 23:35:20 +0700 Subject: [PATCH 13/17] revise --- app/Http/Controllers/ProjectController.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index bb9d679..507cb74 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -251,11 +251,16 @@ class ProjectController extends Controller $d->scheduleHealth = $scheduleHealth; $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(); + } $totalPlannedCost = $data->sum('plannedCost'); $totalActualCost = $data->sum('actualCost'); - // $manpowers = User::where('employee_type', 'employee')->count(); $manpowers = User::count(); $projectsOnDanger = Project::where('budget_health', 'danger')->count(); $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); From b9479dcb37ffdcc953545650e1792f8c73e4c411 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 6 Aug 2022 03:44:53 +0700 Subject: [PATCH 14/17] fix db conn --- Dockerfile | 42 +++++++++++++++++++++++++++--------------- docker-compose.yml | 6 +++--- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 15e997f..4edd5c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,37 @@ FROM php:7.4-fpm-alpine RUN apk add --update libzip-dev curl-dev &&\ - apk del gcc g++ + apk del gcc g++ RUN apk add --no-cache \ - zlib-dev \ - icu-dev \ - libpng-dev \ - oniguruma-dev \ - libpq-dev + zlib-dev \ + icu-dev \ + libpng-dev \ + oniguruma-dev \ + libpq-dev \ + libpng-dev \ + libzip-dev \ + zip \ + vim \ + unzip \ + git \ + curl + RUN rm -rf /var/cache/apk/* RUN docker-php-ext-install \ - curl \ - mbstring \ - intl \ - pdo \ - pdo_pgsql \ - pgsql \ - tokenizer + curl \ + mbstring \ + intl \ + pdo \ + pdo_pgsql \ + pgsql \ + tokenizer + +#Install Extensions +RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql + RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer @@ -28,8 +40,8 @@ WORKDIR /var/www/html COPY . . RUN chmod +x artisan -#RUN composer install --ignore-platform-reqs --prefer-dist --no-scripts --no-progress --no-interaction --no-dev --no-autoloader -#RUN composer dump-autoload --optimize +RUN composer install --ignore-platform-reqs --prefer-dist --no-scripts --no-progress --no-interaction --no-dev --no-autoloader +RUN composer dump-autoload --optimize RUN chown -R www-data:www-data . diff --git a/docker-compose.yml b/docker-compose.yml index ce2c29f..8cb9402 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - '80:80' - '443:443' volumes: - - .:/var/www/html:ro,cached + - .:/var/www/html - ./docker/nginx/conf.d/:/etc/nginx/conf.d/ links: - app @@ -27,8 +27,8 @@ services: image: postgres:14.4-alpine restart: always environment: - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres + - POSTGRES_USER=posgres + - POSTGRES_PASSWORD=posgres ports: - '5432:5432' networks: From 83ab9ac99dd78f7cb3da958bef9fddb3edfc9bf7 Mon Sep 17 00:00:00 2001 From: Ibnu Hamdani Date: Sun, 7 Aug 2022 03:41:37 +0700 Subject: [PATCH 15/17] update conflict --- Dockerfile | 4 ++-- docker-compose.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 15e997f..d2c749c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,8 +28,8 @@ WORKDIR /var/www/html COPY . . RUN chmod +x artisan -#RUN composer install --ignore-platform-reqs --prefer-dist --no-scripts --no-progress --no-interaction --no-dev --no-autoloader -#RUN composer dump-autoload --optimize +RUN composer install --ignore-platform-reqs --prefer-dist --no-scripts --no-progress --no-interaction --no-dev --no-autoloader +RUN composer dump-autoload --optimize RUN chown -R www-data:www-data . diff --git a/docker-compose.yml b/docker-compose.yml index ce2c29f..2f775a1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,10 +5,10 @@ services: restart: unless-stopped tty: true ports: - - '80:80' - - '443:443' + - '8444:80' + - '8555:443' volumes: - - .:/var/www/html:ro,cached + - .:/var/www/html - ./docker/nginx/conf.d/:/etc/nginx/conf.d/ links: - app @@ -30,7 +30,7 @@ services: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres ports: - - '5432:5432' + - '5435:5432' networks: - ospro volumes: From c632278e1477479cae62469055a8dfca96c23239 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 8 Aug 2022 14:21:57 +0700 Subject: [PATCH 16/17] project geolocation --- app/Http/Controllers/ProjectController.php | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 507cb74..1855eca 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -28,6 +28,8 @@ use App\Models\ReportActivity; use App\Models\OfficeHours; use DB; +const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; + class ProjectController extends Controller { @@ -245,7 +247,6 @@ class ProjectController extends Controller $d->plannedCost = $d->rencana_biaya; $d->actualCost = $actualCost; $d->lastActivity = $lastActivity ?? "-"; - //$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; $d->costVariance = $costVariance; $d->costHealth = $d->budget_health; $d->scheduleHealth = $scheduleHealth; @@ -257,6 +258,11 @@ class ProjectController extends Controller ->where('m_proyek.id', $d->id) ->pluck('m_users.name') ->first(); + if($d->area_kerja != ''){ + $d->geolocation = $this->httpReq($d->area_kerja); + } else { + $d->geolocation = ''; + } } $totalPlannedCost = $data->sum('plannedCost'); @@ -365,4 +371,20 @@ class ProjectController extends Controller return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, 'totalRecord'=>$countData], 200); } + + private function httpReq($search){ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); + + // SSL important + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + $output = curl_exec($ch); + curl_close($ch); + + return json_decode($output); + } + } From 5d5f7e0168dcf222e779594c1340c71c3c20cfa5 Mon Sep 17 00:00:00 2001 From: Ibnu Hamdani Date: Mon, 8 Aug 2022 15:06:31 +0700 Subject: [PATCH 17/17] update environments set from .env file --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1931846..8c280b9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,8 +27,8 @@ services: image: postgres:14.4-alpine restart: always environment: - - POSTGRES_USER=posgres - - POSTGRES_PASSWORD=posgres + - POSTGRES_USER=${DB_USERNAME} + - POSTGRES_PASSWORD=${DB_PASSWORD} ports: - '5435:5432' networks: