Browse Source

Merge pull request 'staging' (#11) from staging into master

Reviewed-on: ibnu/generic-ospro-backend#11
pull/1/head
farhantock 12 months ago
parent
commit
ebc44f6c7a
  1. 455
      app/Http/Controllers/ProjectCarausellController.php
  2. 4
      app/Http/Controllers/UserToProyekController.php

455
app/Http/Controllers/ProjectCarausellController.php

@ -5,351 +5,168 @@ namespace App\Http\Controllers;
use App\Models\{ use App\Models\{
User, User,
Project, Project,
Activity,
HierarchyFtth,
ProjectComment,
VersionGantt, VersionGantt,
UserToProyek, ProjectIssues,
UserToActivity, ProjectRisks
Presence
}; };
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
class ProjectCarausellController extends Controller class ProjectCarausellController extends Controller
{ {
// public function invoke($id) // public function invoke() {
// { // // Master Data
// $dateStart = Carbon::now()->startOfDay(); // $projectData = Project::query()
// $dateEnd = Carbon::now()->endOfDay(); // ->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve")
// // 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')
// ->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)
// ->get(); // ->get();
// $projectRisk = ProjectRisks::query()
// // Manpower // ->select('proyek_id','description','level_risk','preventive_risk')
// $manCount = UserToProyek::where('proyek_id', $result['id'])->count();
// // Assigned
// $utAct = UserToActivity::query()
// ->whereIn('version_gantt_id', $gantt_id)
// ->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')
// ->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();
// }
// // 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(); // ->get();
// $plannedEnd = $query->selectRaw('MAX(planned_end) as max_planned_end, version_gantt_id') // $projectIssue = ProjectIssues::query()
// ->groupBy('version_gantt_id') // ->select('proyek_id','description','level_issue')
// ->orderByDesc('max_planned_end') // ->get();
// $ganttData = VersionGantt::query()
// ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type')
// ->get(); // ->get();
// $projectManager = User::whereId($result['pm_id'])->value('name'); // $arr = [];
// $key =1; // foreach ($ganttData as $gantt) {
// foreach($ganttData as $gantt) // $projectArr = [];
// { // $riskProject = [];
// $pStart =$plannedStart->where('version_gantt_id',$gantt['id'])->first(); // $issueProject = [];
// $actStart =$startDate->where('version_gantt_id',$gantt['id'])->first(); // foreach($projectData as $project) {
// $actEnd =$endDate->where('version_gantt_id',$gantt['id'])->first(); // if($project['id'] === $gantt['proyek_id']) {
// $pEnd =$plannedEnd->where('version_gantt_id',$gantt['id'])->first(); // foreach ($projectRisk as $risk) {
// $matchingActivities = $overdueActivities->where('version_gantt_id', $gantt['id']); // if ($risk['proyek_id'] === $project['id']) {
// $matchingProjectComment = $projectComment->where('version_gantt_id', $gantt['id']); // $riskProject[] = [
// $usAtc = $utAct->where('version_gantt_id', $gantt['id']); // 'level_risk' => $risk['level_risk'],
// $arr[] = // 'preventive_risk' => $risk['preventive_risk'],
// [ // 'description' => $risk['description']
// 'gantt_id'=>$gantt['id'], // ];
// 'projectManager'=>$projectManager, // }
// 'name_version'=>$gantt['name_version'], // }
// 'cost_to_complete'=>$gantt['cost_to_complete'], // foreach ($projectIssue as $issue) {
// 'schedule' => [ // if ($issue['proyek_id'] === $project['id']) {
// 'plannedStart'=> $pStart['min_planned_start'], // $issueProject[] = [
// 'actual_start'=>$actStart['min_start'], // 'level_issue' => $issue['level_issue'],
// 'plannedFinish'=>$pEnd['max_planned_end'], // 'description' => $issue['description']
// 'estimatedFinish'=>$actEnd['end_date'] // ];
// ], // }
// 'manpower'=>$manCount, // }
// 'assigned'=>$usAtc->toArray(), // $projectArr[] = [
// 'actual'=>count($presence->toArray()), // "project" => [
// 'overdue_activities'=>$matchingActivities->toArray(), // "id" => $project['id'],
// 'project_comment'=>$matchingProjectComment->toArray(), // "pm_id" => $project['pm_id'],
// 'hierarchy'=>$finalData, // "nama" => $project['nama'],
// 'proyek'=>$result, // "kode_sortname" => $project['kode_sortname'],
// 'key'=>$key++ // "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
// ],
// ];
// }
// }
// $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
// ],
// ];
// } // }
// 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){ // public function getParents(&$data, $id) {
// $ftth = HierarchyFtth::whereIn('id',$id)->get(); // $ftth = HierarchyFtth::find($id);
// array_push($data, $ftth); // array_push($data, $ftth);
// if ($ftth->pluck('parent_id')->toArray()) { // if ($ftth->parent_id) {
// $this->getParents($data, $ftth->pluck('parent_id')->toArray()); // $this->getParents($data, $ftth->parent_id);
// } // }
// } // }
public function invoke() public function invoke() {
{ // Master Data
// 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();
$projectData = Project::query() $projectData = Project::query()
->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve") ->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve")
->get(); ->get();
// nested looping $projectRisk = ProjectRisks::query()
$arr = []; ->select('proyek_id','description','level_risk','preventive_risk')
foreach($projectData as $project) { ->get();
$ganttForProject = []; $projectIssue = ProjectIssues::query()
foreach ($ganttData as $gantt) { ->select('proyek_id','description','level_issue')
if ($gantt['proyek_id'] === $project['id']) { ->get();
// Gantt $ganttData = VersionGantt::query()
$ganttForProject[] = [ ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type')
"gantt_id" => $gantt['id'], ->get();
'proyek_id' => $gantt['proyek_id'],
"name_version" => $gantt['name_version'],
"hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
"cost_to_complete" => $gantt['cost_to_complete'],
];
// 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']) // Nested looping
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $gantt['id'])
->orderByDesc('planned_end')
->value('planned_end');
// SCurve $arr = [];
$req = (object)[ foreach ($ganttData as $gantt) {
'project_id' => $project['id'], $riskProject = [];
'gantt_id' => $gantt['id'], $issueProject = [];
'period' => 'week', 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']
]; ];
$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]);
} }
} }
$projectManager = User::where('id', $project['pm_id'])->value('name'); foreach ($projectIssue as $issue) {
if ($issue['proyek_id'] === $gantt['proyek_id']) {
$issueProject[] = [
'level_issue' => $issue['level_issue'],
'description' => $issue['description']
];
}
}
$arr[]= [ $arr[$gantt['proyek_id']][] = [
"project"=> [ "gantt" => [
"id"=>$project['id'], "gantt_id" => $gantt['id'],
"pm_id"=>$project['pm_id'], 'proyek_id' => $gantt['proyek_id'],
"nama"=>$project['nama'], "name_version" => $gantt['name_version'],
"kode_sortname"=>$project['kode_sortname'], "hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
"budget_health"=>$project['budget_health'], "cost_to_complete" => $gantt['cost_to_complete'],
"calculation_status"=>$project['calculation_status'], "calculation_type" => $gantt['calculation_type'],
"mulai_proyek"=>$project['mulai_proyek'],
"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
], ],
"report_distribution"=>$reports, "project_risk" => $riskProject,
"overdueActivities"=>$overdueActivities, "project_issue"=>$issueProject
"SCurve"=>$SCurve
]; ];
} }
return response()->json(['status'=>'success','code'=> 200,'data'=>$arr, "count"=>count($arr)], 200);
}
public function getParents(&$data, $id){ foreach($projectData as $project) {
$ftth = HierarchyFtth::find($id); $projectManager = User::where('id', $project['pm_id'])->value('name');
array_push($data, $ftth); $arr[$project['id']][] = [
if ($ftth->parent_id) { "project" => [
$this->getParents($data, $ftth->parent_id); "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'],
"project_manager" => $projectManager,
"scurve" => $project['scurve']
],
];
} }
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){ if($countRes > 0){
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]); return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
}else{ }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{ }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