From 60fe1064a58232296400293d554b32c5c2b402d4 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 2 Nov 2023 13:02:51 +0700 Subject: [PATCH] update string agg --- app/Http/Controllers/ActivityController.php | 46 ++++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 16ccb60..70e84ff 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -544,22 +544,36 @@ class ActivityController extends Controller { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $builder = $dataBuilder['builder']; - $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', 'selfTable.start_date', 'selfTable.end_date', 'duration', - 'm_version_gantt.name_version', DB::raw('STRING_AGG(m_users.name, \',\') as user_name'), - DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning', - 'assign_material_to_activity.id as join_third_id') - ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') - ->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') - ->leftJoin('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') - ->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') - ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') - ->groupBy("selfTable.id") - ->groupBy("selfTable.name") - ->groupBy("selfTable.persentase_progress") - ->groupBy("m_version_gantt.name_version") - ->groupBy("assign_material_to_activity.qty_planning") - ->groupBy("assign_material_to_activity.id") - ->get(); + $dataGet = $builder->select( + 'selfTable.name', + 'persentase_progress', + 'selfTable.start_date', + 'selfTable.end_date', + 'duration', + 'm_version_gantt.name_version', + DB::raw('user_names.user_name as user_name'), + DB::raw('SUM(report_activity_material.qty) as qty'), + 'assign_material_to_activity.qty_planning', + 'assign_material_to_activity.id as join_third_id' + ) + ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') + ->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') + ->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') + ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') + ->leftJoin(DB::raw('(SELECT activity_id, STRING_AGG(m_users.name, \',\') as user_name + FROM assign_hr_to_activity + LEFT JOIN m_users ON assign_hr_to_activity.user_id = m_users.id + GROUP BY activity_id) as user_names'), function ($join) { + $join->on('user_names.activity_id', '=', 'selfTable.id'); + }) + ->groupBy('selfTable.id') + ->groupBy('selfTable.name') + ->groupBy('selfTable.persentase_progress') + ->groupBy('m_version_gantt.name_version') + ->groupBy('assign_material_to_activity.qty_planning') + ->groupBy('assign_material_to_activity.id') + ->groupBy('user_names.user_name') + ->get(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); } // before upload file