Browse Source

remove unrelated things

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago committed by Gitea
parent
commit
6d1fcfe38b
  1. 218
      app/Http/Controllers/DashboardController.php
  2. 38
      app/Http/Controllers/ProjectController.php
  3. 6
      routes/web.php

218
app/Http/Controllers/DashboardController.php

@ -2,224 +2,6 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Project;
use App\Models\Activity;
use App\Models\ReportActivity;
use App\Models\Role;
class DashboardController extends Controller class DashboardController extends Controller
{ {
public function costPlanningActual(Request $request)
{
$dataPayload = $request->all();
$dataMaxVersionGantt = [];
foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
}
$dataFinal=[];
foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.rencana_biaya', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'Data not found','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}
public function getMaxVersionGantt($id){
$data = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $id)->first();
return array("last_version_gantt"=>$data->last_version_gantt, "proyek_id" => $id, "proyek_name" => $data->proyek_name);
}
public function percentagePlanningActual(Request $request)
{
$dataPayload = $request->all();
$dataMaxVersionGantt = [];
foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
}
$dataFinal=[];
foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}
public function list()
{
$data = Role::all();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
public function getActivityByProjectId($projectId) {
$output = [];
$data = Activity::select('id')->where('proyek_id', $projectId)->get();
foreach ($data as $actData) {
$output[] = $actData->id;
}
return $output;
}
/*
const statusProyek = [
{
"id": "1",
"proyek_name": "Pembuatan Aplikasi Survey Covid Varian Baru", // ambil dari m_proyek
"total_task": 80, // ambil dari m_activity -> SUM(jumlah_pekerjaan) where proyek_id berdasarkan proyek_id terpilih
"task_on_progress": 60, // ambil dari report_activity -> SUM(job_count_report) where activity_id berdasarkan activity_id terpilih
"day_left": 7, // ambil dari m_proyek, cari sisa hari (end_date - hari ini)
"percentage": 75 // (task_on_progress / total_task * 100)
},
{
"id": "2",
"proyek_name": "Pembangunan Jembatan Layang",
"total_task": 70, // SELECT SUM(jumlah_pekerjaan) FROM public.m_activity WHERE proyek_id IN (11);
"task_on_progress": 70, // SELECT SUM(job_count_report) FROM public.report_activity WHERE activity_id IN (349, 355);
"day_left": 0,
"percentage": 100
},
...
]
*/
public function statusProyek(Request $request) {
$dataPayload = $request->all();
$reqProject = $dataFinal = [];
if (!isset($dataPayload['project_id']))
return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400);
foreach ($dataPayload['project_id'] as $val) {
$prj["project_id"] = $val;
$prj["activity_id"] = $this->getActivityByProjectId($val);
$reqProject[] = $prj;
}
if (count($reqProject) > 0) {
$row = [];
for ($i=0; $i < count($reqProject); $i++) {
$dataMaxVersionGantt = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $reqProject[$i]['project_id'])->first();
$last_version_gantt = $dataMaxVersionGantt->last_version_gantt;
$queryProject = Project::select('id', 'nama', 'mulai_proyek', 'akhir_proyek')->where('id',$reqProject[$i]['project_id'])->first();
$sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan");
$count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id");
$count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id");
$count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress");
$progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get();
$current_progress = 0;
foreach($progress_actual as $objRow) {
$current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100;
}
if (count($reqProject[$i]['activity_id']) > 0) {
for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) {
$sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report");
}
}
if (!isset($queryProject->id))
return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400);
$now = time();
$akhir_proyek = strtotime($queryProject->akhir_proyek);
$datediff = $akhir_proyek - $now;
$mulai_proyek = strtotime($queryProject->mulai_proyek);
$total_kontrak = $akhir_proyek - $mulai_proyek;
$row["id"] = $queryProject->id;
$row["proyek_name"] = $queryProject->nama;
$row["mulai_proyek"] = $queryProject->mulai_proyek;
$row["akhir_proyek"] = $queryProject->akhir_proyek;
$row["total_kontrak"] = round($total_kontrak / (60 * 60 * 24));
$row["total_task"] = $sum_jumlah_pekerjaan;
$row["task_on_progress"] = $sum_job_count_report;
$row["count_activity"] = $count_activity;
$row["count_activity_done"] = $count_activity_done;
$row["day_left"] = round($datediff / (60 * 60 * 24));
$row["percentage"] = round($current_progress,3);
$row["count_progress_percentage"] = $count_progress_percentage;
$dataFinal[] = $row;
}
}
if(empty($dataFinal))
return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}
public function curvaS(Request $request)
{
$dataPayload = $request->all();
$dataMaxVersionGantt = [];
$dataFinal=[];
foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
}
foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya');
for ($i=0; $i < count($data); $i++) {
$tmpp = $tmpa = $tmpbc = $tmpac = 0;
for ($x=$i; $x >= 0 ; $x--) {
$tmpp += $data[$x]['bobot_planning'];
$tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100;
$tmpbc += ((($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100)*$totalCostPlanning)/100;
$tmpac += $data[$x]['biaya_actual'];
}
$data[$i]['cal_bobot_p'] = round($tmpp,2);
if($i > 0 ){
if($data[$i-1]['cal_bobot_a'] != null){
if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){
$data[$i]['cal_bobot_a'] = null;
}else{
$data[$i]['cal_bobot_a'] = round($tmpa,2);
}
}else{
$data[$i]['cal_bobot_a'] = null;
}
if($data[$i-1]['cal_actual_cost'] != null){
if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){
$data[$i]['cal_actual_cost'] = null;
}else{
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
}else{
$data[$i]['cal_actual_cost'] = null;
}
}else{
$data[$i]['cal_bobot_a'] = round($tmpa,2);
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
$data[$i]['cal_budget_cost'] = round($tmpbc,2);
}
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
}
} }

38
app/Http/Controllers/ProjectController.php

@ -332,16 +332,16 @@ class ProjectController extends Controller
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') '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') ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id) ->where('mp.id', $id)
->get(); ->first();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404);
$manpowers = UserToProyek::where('proyek_id', $id)->count(); $manpowers = UserToProyek::where('proyek_id', $id)->count();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first();
if($rootActivity){ $actualCost = @$rootActivity->biaya_actual ?? 0;
$actualCost = $rootActivity->biaya_actual ?? 0; $progress = @$rootActivity->persentase_progress ?? 0;
$progress = $rootActivity->persentase_progress ?? 0;
}
$commentActivity = DB::table('m_comment_activity as mca') $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', ->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created',
@ -352,28 +352,12 @@ class ProjectController extends Controller
->take(2) ->take(2)
->get(); ->get();
foreach ($data as $val) { $data->actual_cost = $actualCost;
$dataRes['kode_sortname'] = $val->kode_sortname; $data->progress = $progress;
$dataRes['name_project'] = $val->name_project; $data->comment = $commentActivity;
$dataRes['start'] = $val->start; $data->man_power = $manpowers;
$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'=>'success','code'=>200,'data'=> $data], 200);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, 'totalRecord'=>$countData], 200);
} }
private function httpReq($search){ private function httpReq($search){

6
routes/web.php

@ -285,12 +285,6 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/project-milestone/select', 'ProjectMileStoneController@select'); $router->get('/project-milestone/select', 'ProjectMileStoneController@select');
$router->get('/project-milestone/{where}/{val}', 'ProjectMileStoneController@customWhere'); $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->post('/report-activity/add', 'ReportActivityController@add');
$router->get('/report-activity/edit/{id}', 'ReportActivityController@edit'); $router->get('/report-activity/edit/{id}', 'ReportActivityController@edit');
$router->put('/report-activity/update/{id}', 'ReportActivityController@update'); $router->put('/report-activity/update/{id}', 'ReportActivityController@update');

Loading…
Cancel
Save