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 @@ +
+
+ = $message['mail_content'] ?>
+
-
+ hi how are you i am fine
+= $message['mail_content'] ?>