diff --git a/app/Controllers/ThzController.php b/app/Controllers/ThzController.php index 68511d1c..e2ca1a06 100644 --- a/app/Controllers/ThzController.php +++ b/app/Controllers/ThzController.php @@ -108,6 +108,8 @@ class ThzController extends BaseController $data = $this->request->getPost(); + $data['notes_type'] = $data['notes_ticket_type'] ?? 'External' ; + $result = $this->thzMasterNotesModel->insert($data); if(empty($result)){ @@ -155,21 +157,23 @@ class ThzController extends BaseController } - public function ticketConversationList(){ + public function ticketConversationList(){ - $data = $this->request->getGet(); + $data = $this->request->getGet(); - $thz_id = $data['thz_id'] ?? null; + $thz_id = $data['thz_id'] ?? null; + + $ticketType = $data['notes_ticket_type'] ?? 'External' ; 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) + ->where('thz_master.thz_id', $thz_id) ->findAll(); if(!empty($result['master'])){ - $notes = $this->thzMasterNotesModel->ticketConversationList($thz_id); + $notes = $this->thzMasterNotesModel->ticketConversationList($thz_id, $ticketType ); $result['notes'] = !empty($notes) ? $notes : []; }else{ return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']))->setStatusCode(400); @@ -296,7 +300,7 @@ class ThzController extends BaseController return $subject ? $subject : " " ; } - private function ticketSaveEmailNotificationBasedOnRole($emailToNotified , $insertOrUpdate , $ticketId , $data){ + private function ticketSaveEmailNotificationBasedOnRole($emailToNotified , $insertOrUpdate , $ticketId , $data){ $user_email = $emailToNotified['user_email'] ?? null; $assignee_email = $emailToNotified['assignee_email'] ?? null; diff --git a/app/Models/ThzMasterNotesModel.php b/app/Models/ThzMasterNotesModel.php index 6b738219..73e355bd 100644 --- a/app/Models/ThzMasterNotesModel.php +++ b/app/Models/ThzMasterNotesModel.php @@ -12,7 +12,7 @@ class ThzMasterNotesModel extends Model protected $returnType = 'array'; protected $useSoftDeletes = false; protected $protectFields = true; - protected $allowedFields = ['thz_id','notes','notes_by','created_by','created_at']; + protected $allowedFields = ['thz_id','notes','notes_by','notes_type','created_by','created_at']; protected bool $allowEmptyInserts = false; @@ -76,9 +76,19 @@ class ThzMasterNotesModel extends Model } - public function ticketConversationList($thz_id) + public function ticketConversationList($thz_id , $ticketType) { - + $ticketTypeFilter = ""; + + if ($ticketType == 'External') { + //user only see his message + $ticketTypeFilter = "AND thz_master_notes.notes_type = 'External' "; + } elseif ($ticketType == 'Internal') { + // internal team needs to see both the tickets + $ticketTypeFilter = "AND ( thz_master_notes.notes_type = 'External' OR thz_master_notes.notes_type = 'Internal' ) "; + } + + $notes_sql = "SELECT thz_master_notes.*, CASE @@ -95,7 +105,8 @@ class ThzMasterNotesModel extends Model 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 . " + WHERE thz_master_notes.thz_id = '. (int)$thz_id .' + $ticketTypeFilter ORDER BY thz_master_notes.created_at ASC"; $result = $this->db->query($notes_sql)->getResultArray();