diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f16118f9..989e2625 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -502,6 +502,8 @@ $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) { $routes->get('view/(:any)','TicketController::view_ticket/$1'); $routes->get('mail_template','TicketController::mailTemplate'); $routes->post('crud_mail_template/(:any)','TicketController::crudTemplate/$1'); - $routes->post('note','TicketController::crudNote'); + $routes->post('note/(:any)','TicketController::crudNote/$1'); + $routes->post('reply','TicketController::saveReply'); +// $routes->post('ticket_messages','TicketController::getTicketMessage'); }); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 921a9f3d..da83ee07 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -1669,11 +1669,12 @@ class MasterController extends AdminController ["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"], ["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"] ]; - $email_id = 'hariharan@nhanceindia.in'; + $email_id = 'srinivas.saravanan@venbainfotech.com'; + $params = ['mail'=>$email_id]; $common = ['mail_type'=>'test_mail_cli']; - $bcc = "vijayalakshmi@nhanceindia.in,vitvelz@gmail.com,velmurugan.s@venbainfotech.com,hariharan@nhanceindia.in,hariharan@jubiliant.in,srinivas.saravanan@venbainfotech.com"; + // $bcc = "vijayalakshmi@nhanceindia.in,vitvelz@gmail.com,velmurugan.s@venbainfotech.com,hariharan@nhanceindia.in,hariharan@jubiliant.in,srinivas.saravanan@venbainfotech.com"; // Send email and get response - $result = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI','bcc'=>$bcc ,'message' => $message,'attachments' => $attachments,'common'=>$common]); + $result = MailHelper::send_email(['mail' => $email_id, 'params'=>$params,'subject' => 'Mail Via CLI','message' => $message,'attachments' => $attachments,'common'=>$common]); log_message('error',json_encode($result)); diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index be7b08e3..76d64155 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -11,6 +11,8 @@ use App\Models\TicketHistoryModel; use App\Models\TicketMailTemplateModel; use App\Models\TicketMessageModel; use App\Models\TicketNoteModel; +use App\Models\UserModel; +use DOMDocument; use Psr\Log\LoggerInterface; use Kint\Kint; @@ -33,9 +35,10 @@ class TicketController extends BaseController protected $ticketMasterModel; protected $ticketHistoryModel; protected $ticketMailTemplateModel; - protected $ticketMesageModel; + protected $ticketMessageModel; protected $ticketNoteModel; protected $triggerType; + protected $userModel; public function __construct() { @@ -92,15 +95,17 @@ class TicketController extends BaseController 7 => "Trigger 7" ]; - $this->placeHolders = ['member_name', 'nhance_logo', 'tpa_id', 'ecard_download_link', - 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', - 'client_name']; + $this->placeHolders = ['employee_name', 'employee_id', 'corporate_name', 'relationship', + 'insured_name', 'acm_name', 'acm_contact', 'claim_no', 'pt_name']; $this->ticketMasterModel = new TicketMasterModel(); $this->claimStatus = new TicketClaimStatusModel(); $this->clientModel = new ClientModel(); $this->ticketHistoryModel = new TicketHistoryModel(); $this->ticketMailTemplateModel = new TicketMailTemplateModel(); + $this->ticketNoteModel = new TicketNoteModel(); + $this->ticketMessageModel = new TicketMessageModel(); + $this->userModel = new UserModel(); } @@ -201,7 +206,16 @@ class TicketController extends BaseController // dd($ticket_data); $data = $this->ticket_form_data($ticket_data['ticket_type_id']); $data['ticket_data'] = $ticket_data; - $data['ticket_note'] = $this->ticketNoteModel->where('is_active', 1)->findAll(); + $data['reply_data'] = $this->ticketMasterModel + ->join('ticket_claim_status','ticket_master.claim_status_id = ticket_claim_status.id and ticket_claim_status.is_active = 1') + ->join('ticket_mail_template','ticket_claim_status.trigger_type = ticket_mail_template.trigger_type and ticket_claim_status.ticket_type = ticket_mail_template.ticket_type and ticket_mail_template.is_active = 1') + ->where('ticket_master.id',$ticket_id) + ->where('ticket_master.is_active',1) + ->first(); + $data['placeHolders'] = $this->placeHolders; + $data['message_data'] = $this->getTicketMessage($ticket_id); + // dd($data); + return $this->loadLayout('ticket_edit_onbording', $data); } @@ -351,8 +365,77 @@ class TicketController extends BaseController } } - public function crudNote(){ + public function crudNote($action){ + // action = 1 is read, action 2 is insert/update + if ($action == 1){ + $ticket_master_id = $this->request->getPost('id'); + if (isset($ticket_master_id) && $ticket_master_id != ''){ + $data = $this->ticketNoteModel->where('is_active',1)->where('ticket_id',$ticket_master_id)->first(); + if ($data){ + return $this->respond(['status' => true, 'data' => $data],200); + }else{ + return $this->respond(['status' => false],404); + } + } + + }elseif ($action == 2){ + $data = $this->request->getPost(); + // if (isset($data['id']) && $data['id'] != ''){ + $status = $this->ticketNoteModel->save($data); + // } + if ($status){ + return $this->respond(['status'=>true],200); + }else{ + return $this->respond(['status'=>false],404); + } + } + } + + public function saveReply(){ + + $received_data = $this->request->getPost(); + $received_data['sender'] = 'staff'; + $status = $this->ticketMessageModel->save($received_data); + if ($status){ + return $this->respond(['status' => true,'code'=>200],200); + }else{ + return $this->respond(['status' => false,'code' => 404],404); + } } + public function getTicketMessage($ticket_master_id){ + // log_message('error','Function called');die(); + // $ticket_master_id = $this->request->getPost('id'); + $user_id = get_session_userid(); + $logged_user = $this->userModel->select('first_name,last_name,profile')->where('id',$user_id)->first(); + $dataToSend = []; + $dataToSend['user_name'] = $logged_user['first_name'].' '.$logged_user['last_name']; + $dataToSend['messages'] = $this->ticketMessageModel->where('is_active',1) + ->where('ticket_id',$ticket_master_id)->orderBy('created_at', 'DESC') + ->findAll(); + foreach ($dataToSend['messages'] as $message){ + $mail_content_converted = $this->convertHtmlToText($message['mail_content']); + $message['mail_content'] = $mail_content_converted; + } + $dataToSend['emp_name'] = $this->ticketMasterModel->select('emp_name') + ->where('id',$ticket_master_id)->where('is_active',1) + ->first()['emp_name']; + // dd($dataToSend); + if($dataToSend){ + return $dataToSend; + }else{ + $data = []; + return $data; + } + + + } + + public function convertHtmlToText($html) { + $dom = new DOMDocument(); + @$dom->loadHTML($html); + return strip_tags($dom->saveHTML()); + } + } \ No newline at end of file diff --git a/app/Helpers/GmailResponseHandler.php b/app/Helpers/GmailResponseHandler.php index 4a45f65c..8ff0ed35 100644 --- a/app/Helpers/GmailResponseHandler.php +++ b/app/Helpers/GmailResponseHandler.php @@ -56,11 +56,12 @@ class GmailResponseHandler{ // 'employee_id' => isset($params['params']['common']['employee_id']) ? $params['params']['common']['employee_id'] : null, // 'mail_type' => isset($params['params']['common']['mail_type']) ? $params['params']['common']['mail_type'] : null, // 'gmail_api_status' => isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null, - // 'gmail_api_id' => isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null + // 'gmail_api_id' => isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null, + // 'received_message' => isset($params['gmail_api']['data']['labelIds'])?json_encode($params['gmail_api']['data']['labelIds']): null // ]; // Initialize data array $data = []; - // print_r($params['params']['common']);die(); + // // print_r($params['params']['common']);die(); if (isset($params['params']['common'])) { foreach ($params['params']['common'] as $key => $value) { $data[$key] = isset($value) ? $value : null; diff --git a/app/Models/TicketMessageModel.php b/app/Models/TicketMessageModel.php index 22044b2f..37de2edb 100644 --- a/app/Models/TicketMessageModel.php +++ b/app/Models/TicketMessageModel.php @@ -12,7 +12,7 @@ class TicketMessageModel extends Model protected $returnType = 'array'; protected $useSoftDeletes = false; protected $protectFields = true; - protected $allowedFields = []; + protected $allowedFields = ['id','sender','ticket_id','mail_subject','emp_mail','mail_content','created_at']; // Callbacks diff --git a/app/Views/ticket_conversation.php b/app/Views/ticket_conversation.php index 0b34ae71..e0e67c6a 100644 --- a/app/Views/ticket_conversation.php +++ b/app/Views/ticket_conversation.php @@ -1,28 +1,37 @@ +
+ +
-
- +
+
+ +
+
+ User +
-
RUPESH
- User
-
16 December 2024 04:15 pm
+
format('j F Y h:i a');?>
- Body
-
+

+
+
@@ -30,38 +39,41 @@
- +
-
- -
-
-
Venkatesh HelpDesk Admin
- Staff +
+
+ +
+
+ Staff +
-
24 January 2025 03:41 pm
+
format('j F Y h:i a');?>
-

hi how are you i am fine

+

-
+ +
-
\ No newline at end of file +
+ +
diff --git a/app/Views/ticket_edit_onbording.php b/app/Views/ticket_edit_onbording.php index 20873990..8f95b1e5 100644 --- a/app/Views/ticket_edit_onbording.php +++ b/app/Views/ticket_edit_onbording.php @@ -106,16 +106,17 @@ function submitClaimForm(event, form) { contentType: false, success: function(response) { // Hide loader - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); console.log('Form submitted response:', response); if (response.status === true) { + location.reload(); toastr.success(response.message, 'SUCCESS'); } else { toastr.error(response.message, 'ERROR'); } + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); }, error: function(xhr, status, error) { console.error(xhr.responseText); @@ -127,4 +128,6 @@ function submitClaimForm(event, form) { } }); } + + \ No newline at end of file diff --git a/app/Views/ticket_mail_template.php b/app/Views/ticket_mail_template.php index dec3c5cb..98b275eb 100644 --- a/app/Views/ticket_mail_template.php +++ b/app/Views/ticket_mail_template.php @@ -182,10 +182,10 @@ table.dataTable tbody td {
@@ -259,14 +259,52 @@ $(document).ready(function() { const editor = Jodit.make("#ticket_mail_editor", editorConfig); + let lastActiveField = null; + +// Track last active input field +$("#template_subject").on("focus", function() { + lastActiveField = this; + }); + + // Track Jodit editor focus separately + editor.events.on("focus", function() { + lastActiveField = editor; + }); + document.addEventListener('change', function(event) { - var target = event.target; - if (target.matches('#ticket_mail_customButton')) - { - editor.selection.insertHTML($(target).val()); - $(target).val(''); - } -}); + var target = event.target; + if (target.matches('#ticket_mail_customButton')) { + let placeholderValue = $(target).val(); + if (!placeholderValue) return; + + if (lastActiveField) { + if (lastActiveField.id === "template_subject") { + insertAtCursor(lastActiveField, placeholderValue); + } else { + editor.selection.insertHTML(placeholderValue); + } + } + + $(target).val(''); + } + }); + + function insertAtCursor(input, textToInsert) { + if (document.selection) { + input.focus(); + var sel = document.selection.createRange(); + sel.text = textToInsert; + } else if (input.selectionStart || input.selectionStart === 0) { + let startPos = input.selectionStart; + let endPos = input.selectionEnd; + input.value = input.value.substring(0, startPos) + textToInsert + input.value.substring(endPos, input.value.length); + input.selectionStart = input.selectionEnd = startPos + textToInsert.length; + } else { + input.value += textToInsert; + } + } + + $('.close').click(function () { $('#template_subject').val(''); $('#template_name').val(''); diff --git a/app/Views/ticket_note.php b/app/Views/ticket_note.php index 0e2968f0..7344e92b 100644 --- a/app/Views/ticket_note.php +++ b/app/Views/ticket_note.php @@ -7,11 +7,11 @@
- +
-
+
@@ -24,6 +24,28 @@ + \ No newline at end of file