@ -5,311 +5,151 @@ 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();
// $projectRisk = ProjectRisks::query()
// // Get Id Gantt & hierarchy_ftth_id
// ->select('proyek_id','description','level_risk','preventive_risk')
// $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();
// $projectIssue = ProjectIssues::query()
// // Manpower
// ->select('proyek_id','description','level_issue')
// $manCount = UserToProyek::where('proyek_id', $result['id'])->count();
// // Assigned
// $utAct = UserToActivity::query()
// ->whereIn('version_gantt_id', $gantt_id)
// ->get();
// ->get();
// // Actual
// $ganttData = VersionGantt::query()
// $presence = Presence::whereBetween('clock_in', [$dateStart, $dateEnd])
// ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type')
// ->select('m_users.name','m_users.ktp_number')
// ->join('m_users','t_clock_in_out.user_id','m_users.id')
// ->get();
// ->get();
// // Report distribution
// $arr = [];
// $reportsDistribution = DB::table('assign_material_to_activity as ama')
// foreach ($ganttData as $gantt) {
// ->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',
// $projectArr = [];
// 'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
// $riskProject = [];
// ->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
// $issueProject = [];
// ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
// foreach($projectData as $project) {
// ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
// if($project['id'] === $gantt['proyek_id']) {
// ->join('m_users as u', 'u.id', '=', 'ram.user_id')
// foreach ($projectRisk as $risk) {
// ->where('ama.proyek_id', '=', $result['id'])
// if ($risk['proyek_id'] === $project['id']) {
// ->whereNotNull('ram.lat')
// $riskProject[] = [
// ->whereBetween('ram.report_date', [$startDate, $startDate]);
// 'level_risk' => $risk['level_risk'],
// 'preventive_risk' => $risk['preventive_risk'],
// // Check Existing
// 'description' => $risk['description']
// $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);
// foreach ($projectIssue as $issue) {
// // Start
// if ($issue['proyek_id'] === $project['id']) {
// if ($actualStartExist) {
// $issueProject[] = [
// $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start'))
// 'level_issue' => $issue['level_issue'],
// ->groupBy('version_gantt_id')
// 'description' => $issue['description']
// ->get();
// ];
// } else {
// }
// $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start','version_gantt_id'))
// }
// ->groupBy('version_gantt_id')
// $projectArr[] = [
// ->orderBy('min_start', 'ASC')
// "project" => [
// ->get();
// "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')
// $arr[] = [
// ->groupBy('version_gantt_id')
// "gantt" => [
// ->orderBy('min_planned_start')
// "gantt_id" => $gantt['id'],
// ->get();
// 'proyek_id' => $gantt['proyek_id'],
// $plannedEnd = $query->selectRaw('MAX(planned_end) as max_planned_end, version_gantt_id')
// "name_version" => $gantt['name_version'],
// ->groupBy('version_gantt_id')
// "hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
// ->orderByDesc('max_planned_end')
// "cost_to_complete" => $gantt['cost_to_complete'],
// ->get();
// "calculation_type" => $gantt['calculation_type'],
// "project"=> $projectArr
// $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']
// ],
// ],
// '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) {
// 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('p arent_id')->toArray() ) {
// if ($ftth->parent_id) {
// $this->getParents($data, $ftth->pluck('p arent_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()
->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 = [];
$arr = [];
foreach($projectData as $project) {
$ganttForProject = [];
foreach ($ganttData as $gantt) {
foreach ($ganttData as $gantt) {
if ($gantt['proyek_id'] === $project['id']) {
$riskProject = [];
// Gantt
$issueProject = [];
$ganttForProject[] = [
foreach ($projectRisk as $risk) {
"gantt_id" => $gantt['id'],
if ($risk['proyek_id'] === $gantt['proyek_id']) {
'proyek_id' => $gantt['proyek_id'],
$riskProject[] = [
"name_version" => $gantt['name_version'],
'level_risk' => $risk['level_risk '],
"hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
'preventive_risk' => $risk['preventive_risk '],
"cost_to_complete" => $gantt['cost_to_complete'],
'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'])
foreach ($projectIssue as $issue) {
->orderBy('planned_start')
if ($issue['proyek_id'] === $gantt['proyek_id']) {
->value('planned_start');
$issueProject[] = [
$plannedEnd = Activity::where('version_gantt_id', $gantt['id'])
'level_issue' => $issue['level_issue'],
->orderByDesc('planned_end')
'description' => $issue['description']
->value('planned_end');
// SCurve
$req = (object)[
'project_id' => $project['id'],
'gantt_id' => $gantt['id'],
'period' => 'week',
];
];
$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')
$arr[$gantt['proyek_id']][] = [
->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',
"gantt" => [
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
"gantt_id" => $gantt['id'],
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
'proyek_id' => $gantt['proyek_id'],
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
"name_version" => $gantt['name_version'],
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
"hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
->join('m_users as u', 'u.id', '=', 'ram.user_id')
"cost_to_complete" => $gantt['cost_to_complete'],
->where('ama.proyek_id', '=', $project['id'])
"calculation_type" => $gantt['calculation_type'],
->whereNotNull('ram.lat')
],
->whereBetween('ram.report_date', [$startDate, $endDate]);
"project_risk" => $riskProject,
}
"project_issue"=>$issueProject
];
}
}
foreach($projectData as $project) {
$projectManager = User::where('id', $project['pm_id'])->value('name');
$projectManager = User::where('id', $project['pm_id'])->value('name');
$arr[$project['id']][] = [
$arr[]= [
"project" => [
"project" => [
"id" => $project['id'],
"id" => $project['id'],
"pm_id" => $project['pm_id'],
"pm_id" => $project['pm_id'],
@ -321,35 +161,12 @@ class ProjectCarausellController extends Controller
"akhir_proyek" => $project['akhir_proyek'],
"akhir_proyek" => $project['akhir_proyek'],
"rencana_biaya" => $project['rencana_biaya'],
"rencana_biaya" => $project['rencana_biaya'],
"company" => $project['company'],
"company" => $project['company'],
"scurve"=>$project['scurve'],
"gantt"=>$ganttForProject
],
"hierarchy"=>$finalData,
"manpower"=>$manCount,
"assigned"=>$assigned,
"actual"=>0,
"project_comment"=>$projectComment,
"project_manager" => $projectManager,
"project_manager" => $projectManager,
"activity" => [
"scurve" => $project['scurve']
"data" => $activity,
"start_date"=>$startDate,
"end_date"=>$endDate,
"planned_start"=>$plannedStart,
"planned_end"=>$plannedEnd
],
],
"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){
return response()->json(['status'=>'success','code'=> 200,'data'=>$arr, "total_project"=>count($arr)], 200);
$ftth = HierarchyFtth::find($id);
array_push($data, $ftth);
if ($ftth->parent_id) {
$this->getParents($data, $ftth->parent_id);
}
}
}
}
}