From fd0fe14ef02cf2fd0bfd4d3d53b65bf5cbfc5630 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 22 Aug 2023 10:26:58 +0700 Subject: [PATCH] Excluding customer for user assignment --- .../Controllers/HumanResourceController.php | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 9e47627..f71cf28 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -138,11 +138,26 @@ class HumanResourceController extends Controller } } - if($search && !empty($search)){ - $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') - ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereNotIn("m_users.id", $forbidden)->get(); - }else{ - $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereNotIn("m_users.id", $forbidden)->get(); + if ($search && !empty($search)) { + $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") + ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') + ->where("assign_hr_to_proyek.proyek_id", $idProyek) + ->where(function ($query) { + $query->where("assign_hr_to_proyek.is_customer", "!=", true) + ->orWhereNull("assign_hr_to_proyek.is_customer"); + }) + ->where("m_users.name", 'like', '%' . $search . '%') + ->whereNotIn("m_users.id", $forbidden)->get(); + } else { + $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") + ->where("assign_hr_to_proyek.proyek_id", $idProyek) + ->where(function ($query) { + $query->where("assign_hr_to_proyek.is_customer", "!=", true) + ->orWhereNull("assign_hr_to_proyek.is_customer"); + }) + ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') + ->whereNotIn("m_users.id", $forbidden) + ->get(); } return response()->json($data);