Browse Source

Merge pull request 'dashboard carousel' (#10) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#10
pull/1/head
farhantock 1 year ago
parent
commit
fcd2e1aa61
  1. 401
      app/Http/Controllers/ProjectCarausellController.php
  2. 4
      app/Http/Controllers/UserToProyekController.php

401
app/Http/Controllers/ProjectCarausellController.php

@ -5,311 +5,151 @@ namespace App\Http\Controllers;
use App\Models\{
User,
Project,
Activity,
HierarchyFtth,
ProjectComment,
VersionGantt,
UserToProyek,
UserToActivity,
Presence
ProjectIssues,
ProjectRisks
};
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
class ProjectCarausellController extends Controller
{
// public function invoke($id)
// {
// $dateStart = Carbon::now()->startOfDay();
// $dateEnd = Carbon::now()->endOfDay();
// // Mengatur waktu awal bulan dan mengurangkan 1 tahun
// $startDate = Carbon::now()->startOfMonth()->subYear()->format('Y-m-d');
// // Mengatur waktu saat ini dan mengurangkan 1 tahun
// $endDate = Carbon::now()->subYear()->format('Y-m-d');
// if(empty($id) || !is_int((int)$id)){
// return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
// }
// $result = Project::select('id','nama','budget_health','kode_sortname','pm_id','rencana_biaya','company','scurve','calculation_status')->find($id);
// if(!$result){
// return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404);
// }
// $ganttData = VersionGantt::where('proyek_id', $id)
// ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete')
// public function invoke() {
// // Master Data
// $projectData = Project::query()
// ->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve")
// ->get();
// // Get Id Gantt & hierarchy_ftth_id
// $gantt_id = $ganttData->pluck('id')->toArray();
// $hierarchy_ftth_id = $ganttData->pluck('hierarchy_ftth_id')->toArray();
// // Heararchy
// $finalData = [];
// if($hierarchy_ftth_id){
// $ftth = HierarchyFtth::whereIn('id',$hierarchy_ftth_id)->get();
// if($ftth->first() != null)
// {
// array_push($finalData, $ftth->first());
// }
// if($ftth->where('parent_id','!=', null)->first()){
// $this->getParents($finalData, $ftth->pluck('parent_id')->toArray());
// }
// } else {
// return $finalData;
// }
// // SCurve
// $SCurve = MasterFunctionsHelper::getSCurveCarausell($result['id'],$gantt_id,'week');
// // Overdue Activities
// $endDate = Activity::where('proyek_id', $result['id'])
// ->orderByDesc('end_date')
// ->value('end_date');
// $overdueActivities = Activity::whereIn('version_gantt_id', $gantt_id)->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get();
// // Project Comment
// $projectComment = ProjectComment::query()
// ->select('project_id','gantt_id','comment','created_at')
// ->where('project_id',$result['id'])
// ->whereIn('gantt_id',$gantt_id)
// $projectRisk = ProjectRisks::query()
// ->select('proyek_id','description','level_risk','preventive_risk')
// ->get();
// // Manpower
// $manCount = UserToProyek::where('proyek_id', $result['id'])->count();
// // Assigned
// $utAct = UserToActivity::query()
// ->whereIn('version_gantt_id', $gantt_id)
// $projectIssue = ProjectIssues::query()
// ->select('proyek_id','description','level_issue')
// ->get();
// // Actual
// $presence = Presence::whereBetween('clock_in', [$dateStart, $dateEnd])
// ->select('m_users.name','m_users.ktp_number')
// ->join('m_users','t_clock_in_out.user_id','m_users.id')
// $ganttData = VersionGantt::query()
// ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type')
// ->get();
// // Report distribution
// $reportsDistribution = DB::table('assign_material_to_activity as ama')
// ->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit',
// 'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
// ->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
// ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
// ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
// ->join('m_users as u', 'u.id', '=', 'ram.user_id')
// ->where('ama.proyek_id', '=', $result['id'])
// ->whereNotNull('ram.lat')
// ->whereBetween('ram.report_date', [$startDate, $startDate]);
// // Check Existing
// $actualStartExist = Activity::whereIn('version_gantt_id',$gantt_id)->whereNotNull('actual_start')->exists();
// $actualEndExist = Activity::whereIn('version_gantt_id',$gantt_id)->exists();
// $query = Activity::query()->whereIn('version_gantt_id', $gantt_id);
// // Start
// if ($actualStartExist) {
// $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start'))
// ->groupBy('version_gantt_id')
// ->get();
// } else {
// $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start','version_gantt_id'))
// ->groupBy('version_gantt_id')
// ->orderBy('min_start', 'ASC')
// ->get();
// $arr = [];
// foreach ($ganttData as $gantt) {
// $projectArr = [];
// $riskProject = [];
// $issueProject = [];
// foreach($projectData as $project) {
// if($project['id'] === $gantt['proyek_id']) {
// foreach ($projectRisk as $risk) {
// if ($risk['proyek_id'] === $project['id']) {
// $riskProject[] = [
// 'level_risk' => $risk['level_risk'],
// 'preventive_risk' => $risk['preventive_risk'],
// 'description' => $risk['description']
// ];
// }
// }
// foreach ($projectIssue as $issue) {
// if ($issue['proyek_id'] === $project['id']) {
// $issueProject[] = [
// 'level_issue' => $issue['level_issue'],
// 'description' => $issue['description']
// ];
// }
// }
// $projectArr[] = [
// "project" => [
// "id" => $project['id'],
// "pm_id" => $project['pm_id'],
// "nama" => $project['nama'],
// "kode_sortname" => $project['kode_sortname'],
// "budget_health" => $project['budget_health'],
// "calculation_status" => $project['calculation_status'],
// "mulai_proyek" => $project['mulai_proyek'],
// "akhir_proyek" => $project['akhir_proyek'],
// "rencana_biaya" => $project['rencana_biaya'],
// "company" => $project['company'],
// "scurve" => $project['scurve'],
// "project_risk" => $riskProject,
// "project_issues" => $issueProject
// ],
// ];
// }
// // End
// if($actualEndExist)
// {
// $maxIds = $query->selectRaw('MAX(id) as max_id')
// ->groupBy('version_gantt_id')
// ->pluck('max_id', 'version_gantt_id');
// $endDate = Activity::whereIn('id', $maxIds)->select('end_date','version_gantt_id')->get();
// }
// $plannedStart = $query->selectRaw('MIN(planned_start) as min_planned_start, version_gantt_id')
// ->groupBy('version_gantt_id')
// ->orderBy('min_planned_start')
// ->get();
// $plannedEnd = $query->selectRaw('MAX(planned_end) as max_planned_end, version_gantt_id')
// ->groupBy('version_gantt_id')
// ->orderByDesc('max_planned_end')
// ->get();
// $projectManager = User::whereId($result['pm_id'])->value('name');
// $key =1;
// foreach($ganttData as $gantt)
// {
// $pStart =$plannedStart->where('version_gantt_id',$gantt['id'])->first();
// $actStart =$startDate->where('version_gantt_id',$gantt['id'])->first();
// $actEnd =$endDate->where('version_gantt_id',$gantt['id'])->first();
// $pEnd =$plannedEnd->where('version_gantt_id',$gantt['id'])->first();
// $matchingActivities = $overdueActivities->where('version_gantt_id', $gantt['id']);
// $matchingProjectComment = $projectComment->where('version_gantt_id', $gantt['id']);
// $usAtc = $utAct->where('version_gantt_id', $gantt['id']);
// $arr[] =
// [
// 'gantt_id'=>$gantt['id'],
// 'projectManager'=>$projectManager,
// 'name_version'=>$gantt['name_version'],
// 'cost_to_complete'=>$gantt['cost_to_complete'],
// 'schedule' => [
// 'plannedStart'=> $pStart['min_planned_start'],
// 'actual_start'=>$actStart['min_start'],
// 'plannedFinish'=>$pEnd['max_planned_end'],
// 'estimatedFinish'=>$actEnd['end_date']
// $arr[] = [
// "gantt" => [
// "gantt_id" => $gantt['id'],
// 'proyek_id' => $gantt['proyek_id'],
// "name_version" => $gantt['name_version'],
// "hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
// "cost_to_complete" => $gantt['cost_to_complete'],
// "calculation_type" => $gantt['calculation_type'],
// "project"=> $projectArr
// ],
// 'manpower'=>$manCount,
// 'assigned'=>$usAtc->toArray(),
// 'actual'=>count($presence->toArray()),
// 'overdue_activities'=>$matchingActivities->toArray(),
// 'project_comment'=>$matchingProjectComment->toArray(),
// 'hierarchy'=>$finalData,
// 'proyek'=>$result,
// 'key'=>$key++
// ];
// }
// return response()->json(['status'=>'success','code'=> 200,'data'=>$arr,'report_distribution'=>$reportsDistribution,'sCurve'=>$SCurve, 'count'=>count($arr)], 200);
// return response()->json(['status'=>'success','code'=> 200,'data'=>$projectArr, "total_project"=>count($arr)], 200);
// }
// public function getParents(&$data, $id) {
// $ftth = HierarchyFtth::whereIn('id',$id)->get();
// $ftth = HierarchyFtth::find($id);
// array_push($data, $ftth);
// if ($ftth->pluck('parent_id')->toArray()) {
// $this->getParents($data, $ftth->pluck('parent_id')->toArray());
// if ($ftth->parent_id) {
// $this->getParents($data, $ftth->parent_id);
// }
// }
public function invoke()
{
// Data Master
// Mengatur waktu awal bulan dan mengurangkan 1 tahun
$startDate = Carbon::now()->startOfMonth()->subYear()->format('Y-m-d');
// Mengatur waktu saat ini dan mengurangkan 1 tahun
$endDate = Carbon::now()->subYear()->format('Y-m-d');
$ganttData = VersionGantt::query()
->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id')
->get();
public function invoke() {
// Master Data
$projectData = Project::query()
->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve")
->get();
// nested looping
$projectRisk = ProjectRisks::query()
->select('proyek_id','description','level_risk','preventive_risk')
->get();
$projectIssue = ProjectIssues::query()
->select('proyek_id','description','level_issue')
->get();
$ganttData = VersionGantt::query()
->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type')
->get();
// Nested looping
$arr = [];
foreach($projectData as $project) {
$ganttForProject = [];
foreach ($ganttData as $gantt) {
if ($gantt['proyek_id'] === $project['id']) {
// Gantt
$ganttForProject[] = [
"gantt_id" => $gantt['id'],
'proyek_id' => $gantt['proyek_id'],
"name_version" => $gantt['name_version'],
"hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
"cost_to_complete" => $gantt['cost_to_complete'],
$riskProject = [];
$issueProject = [];
foreach ($projectRisk as $risk) {
if ($risk['proyek_id'] === $gantt['proyek_id']) {
$riskProject[] = [
'level_risk' => $risk['level_risk'],
'preventive_risk' => $risk['preventive_risk'],
'description' => $risk['description']
];
// Activity
$activity = Activity::query()
->select('id','name','proyek_id','version_gantt_id','type_activity','parent_id','kode_sortname','rencana_biaya','start_date','end_date','biaya_actual','persentase_bobot','persentase_progress','planned_start','planned_end','actual_start','actual_end')
->whereNull('parent_id')
->where([
["proyek_id", $project['id']],
["version_gantt_id", $gantt['id']]
])
->first();
$actualStartExist = Activity::query()
->where('version_gantt_id', $gantt['id'])
->whereNotNull('actual_start')
->exists();
$actualEndExist = Activity::query()
->where('version_gantt_id', $gantt['id'])
->exists();
$query = Activity::where('version_gantt_id', $gantt['id']);
if ($actualStartExist) {
$startDate = $query->orderBy('actual_start')->value('start_date');
} else {
$startDate = $query->orderBy('start_date')->value('start_date');
}
if($actualEndExist)
{
$maxEndDate = $query->max('id');
$endDate = $query->where('id',$maxEndDate)->first()->end_date;
}
$plannedStart = Activity::where('version_gantt_id', $gantt['id'])
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $gantt['id'])
->orderByDesc('planned_end')
->value('planned_end');
// SCurve
$req = (object)[
'project_id' => $project['id'],
'gantt_id' => $gantt['id'],
'period' => 'week',
foreach ($projectIssue as $issue) {
if ($issue['proyek_id'] === $gantt['proyek_id']) {
$issueProject[] = [
'level_issue' => $issue['level_issue'],
'description' => $issue['description']
];
$SCurve = MasterFunctionsHelper::getSCurveCarausell($req);
// Overdue
$endDate = Activity::where('proyek_id', $project['id'])
->orderByDesc('end_date')
->value('end_date');
$overdueActivities = Activity::query()
->where([
['version_gantt_id', $gantt['id']],
['persentase_progress', '!=', 100]
])
->whereNotNull('parent_id')
->whereDate('end_date','<=',$endDate)
->orderBy('end_date', 'asc')
->get();
// Manpower
$manCount = UserToProyek::where('proyek_id', $project['id'])->count();
// Assigned
$assigned = UserToActivity::query()
->select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt['id'])
->get();
// Project Comment
$projectComment = ProjectComment::query()
->select('m_users.name','m_users.username','m_project_comment.project_id','m_project_comment.gantt_id','m_project_comment.comment','m_project_comment.created_at')
->join('m_users','m_project_comment.sender_id','m_users.id')
->where([
['project_id',$project['id']],
['gantt_id',$gantt['id']]
])
->get();
// Hierarchy
$finalData = [];
$ganttHierarchy = VersionGantt::find($gantt['id']);
if ($ganttHierarchy->hierarchy_ftth_id) {
$ftth = HierarchyFtth::find($ganttHierarchy->hierarchy_ftth_id);
array_push($finalData, $ftth);
if($ftth->parent_id){
$this->getParents($finalData, $ftth->parent_id);
}
}else{
$finalData = $finalData;
}
$reports = DB::table('assign_material_to_activity as ama')
->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit',
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->join('m_users as u', 'u.id', '=', 'ram.user_id')
->where('ama.proyek_id', '=', $project['id'])
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$startDate, $endDate]);
}
$arr[$gantt['proyek_id']][] = [
"gantt" => [
"gantt_id" => $gantt['id'],
'proyek_id' => $gantt['proyek_id'],
"name_version" => $gantt['name_version'],
"hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
"cost_to_complete" => $gantt['cost_to_complete'],
"calculation_type" => $gantt['calculation_type'],
],
"project_risk" => $riskProject,
"project_issue"=>$issueProject
];
}
foreach($projectData as $project) {
$projectManager = User::where('id', $project['pm_id'])->value('name');
$arr[]= [
$arr[$project['id']][] = [
"project" => [
"id" => $project['id'],
"pm_id" => $project['pm_id'],
@ -321,35 +161,12 @@ class ProjectCarausellController extends Controller
"akhir_proyek" => $project['akhir_proyek'],
"rencana_biaya" => $project['rencana_biaya'],
"company" => $project['company'],
"scurve"=>$project['scurve'],
"gantt"=>$ganttForProject
],
"hierarchy"=>$finalData,
"manpower"=>$manCount,
"assigned"=>$assigned,
"actual"=>0,
"project_comment"=>$projectComment,
"project_manager" => $projectManager,
"activity" => [
"data" => $activity,
"start_date"=>$startDate,
"end_date"=>$endDate,
"planned_start"=>$plannedStart,
"planned_end"=>$plannedEnd
"scurve" => $project['scurve']
],
"report_distribution"=>$reports,
"overdueActivities"=>$overdueActivities,
"SCurve"=>$SCurve
];
}
return response()->json(['status'=>'success','code'=> 200,'data'=>$arr, "count"=>count($arr)], 200);
}
public function getParents(&$data, $id){
$ftth = HierarchyFtth::find($id);
array_push($data, $ftth);
if ($ftth->parent_id) {
$this->getParents($data, $ftth->parent_id);
}
return response()->json(['status'=>'success','code'=> 200,'data'=>$arr, "total_project"=>count($arr)], 200);
}
}

4
app/Http/Controllers/UserToProyekController.php

@ -64,10 +64,10 @@ class UserToProyekController extends Controller
if($countRes > 0){
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
}else{
return response()->json(['status'=>'success' ,'message'=>'Project customer failed created','code'=>400]);
return response()->json(['status'=>'failed' ,'message'=>'Project customer failed created','code'=>400]);
}
}else{
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
return response()->json(['status'=>'failed' ,'message'=>'Project customer failed created','code'=>200]);
}
}

Loading…
Cancel
Save