From e78650b1dbfffe3f42a8be259bb6be2582955c6d Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Tue, 19 Aug 2025 09:42:47 +0530 Subject: [PATCH] CHANGES_Ticket Master and rest api --- app/Controllers/ThzController.php | 67 ++-- app/Models/ThzMasterNotesModel.php | 30 +- app/Views/layout/header.php | 3 + app/Views/thz_list.php | 473 +++++++++++++++++++++++++++++ 4 files changed, 546 insertions(+), 27 deletions(-) create mode 100644 app/Views/thz_list.php diff --git a/app/Controllers/ThzController.php b/app/Controllers/ThzController.php index 2b9dafcc..8c065eb2 100644 --- a/app/Controllers/ThzController.php +++ b/app/Controllers/ThzController.php @@ -8,7 +8,7 @@ use CodeIgniter\HTTP\ResponseInterface; use App\Models\ThzMasterModel; use App\Models\ThzMasterNotesModel; use App\ControllerCleaners\ThzControllerCleaner; -use app\Models\UserModel; +use App\Models\UserModel; class ThzController extends BaseController { @@ -36,7 +36,7 @@ class ThzController extends BaseController public function ticketSave(){ $data = $this->request->getJSON(true); - + // $return_type = isset($data['return_type']) ? $data['return_type'] : 'api'; if (!empty($data['thz_id'])) { $text = "update"; $result = $this->updateTicket($data); @@ -48,7 +48,7 @@ class ThzController extends BaseController return $this->response->setJSON([ 'status' => $result ? 'success' : 'error', 'message' => $result ? "Ticket {$text}d successfully" : "Unable to {$text} ticket. Please try again." - ]); + ])->setStatusCode($result ? 200 : 400); } public function ticketList() @@ -60,26 +60,22 @@ class ThzController extends BaseController $tickets = $this->fetchTicketsBasedOnrole($data); - - if ($returnType === 'api') { if (empty($tickets)) { - return $this->response->setJSON([ 'status' => 'error','message' => 'No tickets found',])->setStatusCode(404); + return $this->response->setJSON([ 'status' => 'error','message' => 'No tickets found'])->setStatusCode(404); } }else{ $data['page_name'] = "Ticket List"; $data['ticket_data'] = $tickets; - $data['assigner'] = $this->userModel->where('is_active', 1)->findAll(); - return $this->loadLayout('ticket_list_web', $data); - } - - + $data['assignee'] = $this->userModel->where('is_active', 1)->whereIn('role', ['1', '5'])->findAll(); // enga 5-"head" and 1-"admin" role person thaan assignee.. + return $this->loadLayout('thz_list', $data); + } return $this->response->setJSON([ 'status' => 'success', 'data' => $tickets, - ]); + ])->setStatusCode(200); } public function ticketConversationSave(){ @@ -89,11 +85,14 @@ class ThzController extends BaseController $result = $this->thzMasterNotesModel->insert($data); if(empty($result)){ - return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found'])); + return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(404); } - return $this->response->setJSON((['status' => 'success', 'data' => $result])); - + + return $this->response->setJSON([ + 'status' => $result ? 'success' : 'error', + 'message' => $result ? "Ticket Notes created successfully" : "Unable to create ticket notes. Please try again." + ])->setStatusCode($result ? 200 : 400); } @@ -103,13 +102,21 @@ class ThzController extends BaseController $thz_id = $data['thz_id'] ?? null; - $result = $this->thzMasterNotesModel->ticketConversationList($thz_id); + if($thz_id){ + $result['master'] = $this->thzMasterModel + ->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name') + ->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left') + ->where('thz_master.thz_id', $thz_id) + ->findAll(); - if(empty($result)){ - return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found'])); + $notes = $this->thzMasterNotesModel->ticketConversationList($thz_id); + $result['notes'] = !empty($notes) ? $notes : []; + + }else{ + return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(404); } - - return $this->response->setJSON((['status' => 'success', 'data' => $result])); + + return $this->response->setJSON((['status' => 'success', 'data' => $result]))->setStatusCode(400); } @@ -159,27 +166,35 @@ class ThzController extends BaseController private function fetchTicketsBasedOnrole(array $data): array { - $id = $data['thz_id'] ?? null; + // $id = $data['thz_id'] ?? null; $assign_to = $data['assign_to'] ?? null; $mobile = $data['mobile'] ?? null; if (!empty($assign_to)) { // Tickets assigned to a staff return $this->thzMasterModel - ->where('assign_to', $assign_to) + ->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name') + ->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left') + ->where('thz_master.assign_to', $assign_to) ->findAll(); } - if (!empty($id) && !empty($mobile)) { + // if (!empty($id) && !empty($mobile)) { + if (!empty($mobile)) { // Specific ticket by ID and mobile return $this->thzMasterModel - ->where('thz_id', $id) - ->where('mobile', $mobile) + ->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name') + ->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left') + // ->where('thz_id', $id) + ->where('thz_master.mobile', $mobile) ->findAll(); } // All tickets (e.g., for managers) - return $this->thzMasterModel->findAll(); + return $this->thzMasterModel + ->select('thz_master.*, CONCAT(user_profiles.first_name, " ", user_profiles.last_name) as assignee_name') + ->join('user_profiles', 'user_profiles.id = thz_master.assign_to', 'left') + ->findAll(); } private function notificationBasedOnRole($data){ diff --git a/app/Models/ThzMasterNotesModel.php b/app/Models/ThzMasterNotesModel.php index 769b505d..6b738219 100644 --- a/app/Models/ThzMasterNotesModel.php +++ b/app/Models/ThzMasterNotesModel.php @@ -40,7 +40,7 @@ class ThzMasterNotesModel extends Model protected $beforeDelete = []; protected $afterDelete = []; - public function ticketConversationList($thz_id){ + public function ticketConversationLists($thz_id){ if(empty($thz_id)){ @@ -76,5 +76,33 @@ class ThzMasterNotesModel extends Model } + public function ticketConversationList($thz_id) + { + + $notes_sql = "SELECT + thz_master_notes.*, + CASE + WHEN LOWER(thz_master_notes.notes_by) = 'staff' + THEN CONCAT(user_profiles.first_name, ' ', user_profiles.last_name) + WHEN LOWER(thz_master_notes.notes_by) = 'user' + THEN thz_master.name + ELSE thz_master_notes.notes_by + END AS name + FROM thz_master_notes + LEFT JOIN user_profiles + ON user_profiles.id = thz_master_notes.created_by + AND LOWER(thz_master_notes.notes_by) = 'staff' + LEFT JOIN thz_master + ON thz_master.thz_id = thz_master_notes.thz_id + AND LOWER(thz_master_notes.notes_by) = 'user' + WHERE thz_master_notes.thz_id = " . (int)$thz_id . " + ORDER BY thz_master_notes.created_at ASC"; + + $result = $this->db->query($notes_sql)->getResultArray(); + + return $result; + } + + } diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index f148d77b..a18f2ed4 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -677,6 +677,9 @@
  • Claim Feedback List
  • +
  • + Ticket List +
  • diff --git a/app/Views/thz_list.php b/app/Views/thz_list.php new file mode 100644 index 00000000..cc6f4c11 --- /dev/null +++ b/app/Views/thz_list.php @@ -0,0 +1,473 @@ + + + + +
    +
    +
    +
    +
    +

    Ticket List

    +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + $row){ ?> + + + + + + + + + + + + + + + + + + + + +
    Ticket NumberNameMobile NumberEmailEmp CodePolicy NumberTicket TypeSubjectMessageStatusAssignee ACTION
    + + +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + \ No newline at end of file