diff --git a/app/Config/Routes.php b/app/Config/Routes.php index bafc5373..ea9c7fc0 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -551,6 +551,13 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("claimView", "EmployeeRestController::claimView"); $routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData"); + + //thz_master's + $routes->post("ticketSave", "ThzController::ticketSave"); + $routes->get("ticketList", "ThzController::ticketList"); + $routes->post("ticketConversationSave", "ThzController::ticketConversationSave"); + $routes->get("ticketConversationList", "ThzController::ticketConversationList"); + }); $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); diff --git a/app/Controllers/ThzController.php b/app/Controllers/ThzController.php index 2b9dafcc..fd2f424f 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 { @@ -35,8 +35,9 @@ class ThzController extends BaseController public function ticketSave(){ - $data = $this->request->getJSON(true); - + $data = $this->request->getPost(); + // $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 +49,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 +61,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 +86,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 +103,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 +167,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/ThzMasterModel.php b/app/Models/ThzMasterModel.php index 410a84ba..580c6181 100644 --- a/app/Models/ThzMasterModel.php +++ b/app/Models/ThzMasterModel.php @@ -12,7 +12,7 @@ class ThzMasterModel extends Model protected $returnType = 'array'; protected $useSoftDeletes = false; protected $protectFields = true; - protected $allowedFields = ['name','mobile','email','empcode','policy_no','ticket_type','subject','message','status','assign_to','created_at','updated_at']; + protected $allowedFields = ['name','mobile','email','empcode','policy_no','ticket_type','subject','message','status','assign_to','created_at','updated_at','created_by','updated_by' ,'client_id' ,'policy_id' ,'branch_id']; protected bool $allowEmptyInserts = false; 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 0fedd6a5..8085112c 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -676,6 +676,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 diff --git a/app/Views/thz_notes.php b/app/Views/thz_notes.php new file mode 100644 index 00000000..21a1d8d2 --- /dev/null +++ b/app/Views/thz_notes.php @@ -0,0 +1,436 @@ + +
    +
    +
    +
    + +
    +
    +

    Ticket

    +
    +
    + + + +
    +
    + + + + + +
    +
    +
    +
    +
    +
    +
    + +
    Ticket Master Details
    +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + + +
    + +

    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + +
    + +
    + + + + + \ No newline at end of file