From be1b6734191c2ab554177857ef589a2385294437 Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Mon, 3 Feb 2025 18:01:33 +0530 Subject: [PATCH 1/5] FEAT_SEND_AUTO_QUERY_MAIL_SRI --- app/Config/Routes.php | 1 + app/Controllers/TicketController.php | 203 +++++++++++++++++---------- app/Models/TicketMasterModel.php | 6 +- app/Models/TicketMessageModel.php | 2 +- app/Models/TicketNoteModel.php | 2 +- app/Views/ticket_auto_query.php | 98 +++++++++++++ app/Views/ticket_edit_onbording.php | 10 ++ app/Views/ticket_list.php | 26 +++- app/Views/ticket_note.php | 6 +- app/Views/ticket_reply.php | 2 +- 10 files changed, 271 insertions(+), 85 deletions(-) create mode 100644 app/Views/ticket_auto_query.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3d8b8f42..2f294b04 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -412,6 +412,7 @@ $routes->get('cli/sendZeptoMail', 'MasterController::testZeptoSMTP'); $routes->cli('cli/processjob', 'JobWorker::processJob'); $routes->cli('cli/processjobs', 'JobWorker::processJobs'); +$routes->cli('cli/sendMailWithAutoQuery','TicketController::sendMailWithAutoQuery'); $routes->get("processjob", "JobWorker::processJob"); $routes->cli('cli/new_gmail_token', 'MasterController::generateNewGmailAPIToken'); diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index e3817ef5..43b0bf0d 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -109,6 +109,7 @@ class TicketController extends BaseController '((CLAIM_NO))' => 'claim_number', '((RELATIONSHIP))' => 'relationship', '((POLICY_TYPE))' => 'policy_type', + '((AUTO_QUERY_CONTENT))' => 'auto_query_content', ]; $this->ticketMasterModel = new TicketMasterModel(); @@ -145,9 +146,9 @@ class TicketController extends BaseController if ($action == 1) { $data = $this->ticketMasterModel ->select('ticket_master.id, ticket_claim_status.claim_status as status, - ticket_master.claim_number as claim_no,ticket_master.tpa_id,ticket_master.emp_name, - insurers.name as insurer_name, clients.client_name, - DATE_FORMAT(ticket_master.created_at, "%d-%m-%Y") as tat') + ticket_master.claim_number as claim_no,ticket_master.tpa_id,ticket_master.emp_name, + insurers.name as insurer_name, clients.client_name,ticket_master.insured_name,clients.short_name, + DATE_FORMAT(ticket_master.created_at, "%d-%m-%Y") as tat') ->join('insurers', 'insurers.id = ticket_master.insurer_id and insurers.is_active = 1', 'left') ->join('clients', 'clients.id = ticket_master.client_id and clients.is_active = 1', 'left') ->join('ticket_claim_status', 'ticket_claim_status.id = ticket_master.claim_status_id and ticket_claim_status.is_active = 1', 'left') @@ -169,9 +170,9 @@ class TicketController extends BaseController // print_rr($where); $data = $this->ticketMasterModel ->select('ticket_master.id, ticket_claim_status.claim_status as status, - ticket_master.claim_number as claim_no,ticket_master.tpa_id,ticket_master.emp_name, - insurers.name as insurer_name, clients.client_name, - DATE_FORMAT(ticket_master.created_at, "%d-%m-%Y") as tat') + ticket_master.claim_number as claim_no,ticket_master.tpa_id,ticket_master.emp_name, + insurers.name as insurer_name, clients.client_name,ticket_master.insured_name,clients.short_name, + DATE_FORMAT(ticket_master.created_at, "%d-%m-%Y") as tat') ->join('insurers', 'insurers.id = ticket_master.insurer_id and insurers.is_active = 1', 'left') ->join('clients', 'clients.id = ticket_master.client_id and clients.is_active = 1', 'left') ->join('ticket_claim_status', 'ticket_claim_status.id = ticket_master.claim_status_id and ticket_claim_status.is_active = 1', 'left') @@ -250,7 +251,7 @@ class TicketController extends BaseController $ticket_data = $this->formatDateForClaim($ticket_data, 'd/m/Y'); // dd($ticket_data); $template_data = $this->ticketMasterModel->getTemplateDataByTicketID($ticket_id); - if(!empty($template_data)){ + if (!empty($template_data)) { $template_data['mail_content'] = $this->replacePlaceholders($template_data['mail_content'], $ticket_data); $template_data['subject'] = $this->replacePlaceholders($template_data['subject'], $ticket_data); } @@ -423,8 +424,10 @@ class TicketController extends BaseController // action = 1 is read, action 2 is insert/update if ($action == 1) { $ticket_master_id = $this->request->getPost('id'); + $is_auto_query = $this->request->getPost('is_auto_query'); + // print_rr($is_auto_query); if (isset($ticket_master_id) && $ticket_master_id != '') { - $data = $this->ticketNoteModel->where('is_active', 1)->where('ticket_id', $ticket_master_id)->first(); + $data = $this->ticketNoteModel->where('is_active', 1)->where('ticket_id', $ticket_master_id)->where('is_auto_query', $is_auto_query)->first(); if ($data) { return $this->respond(['status' => true, 'data' => $data], 200); } else { @@ -434,10 +437,13 @@ class TicketController extends BaseController } elseif ($action == 2) { $data = $this->request->getPost(); // if (isset($data['id']) && $data['id'] != ''){ + // print_rr($data);die(); $status = $this->ticketNoteModel->save($data); + $id = isset($data['id']) ? $data['id'] : $this->ticketNoteModel->insertID(); + // } if ($status) { - return $this->respond(['status' => true], 200); + return $this->respond(['status' => true, 'id' => $id], 200); } else { return $this->respond(['status' => false], 200); } @@ -532,12 +538,12 @@ class TicketController extends BaseController // Validate Essential Fields if (empty($ticket_data['emp_mail'])) { - $this->myLogger->logme('error', "Employee email is missing for Ticket ID : '".$ticket_id ."'"); + $this->myLogger->logme('error', "Employee email is missing for Ticket ID : '" . $ticket_id . "'"); return null; } if (empty($subject) || empty($message)) { - $this->myLogger->logme('error', "Generated email content is empty for Ticket ID: '".$ticket_id ."'"); + $this->myLogger->logme('error', "Generated email content is empty for Ticket ID: '" . $ticket_id . "'"); return null; } @@ -570,9 +576,9 @@ class TicketController extends BaseController if ($value == "emp_code") { $replaceData = $ticket_data[$value] ?? ''; - }else if($value == "policy_type"){ + } else if ($value == "policy_type") { $replaceData = str_replace("Claim-", "", $this->ticketType[$ticket_data['ticket_type_id']] ?? ""); - }else{ + } else { $replaceData = strtoupper($ticket_data[$value]) ?? ''; } @@ -589,9 +595,9 @@ class TicketController extends BaseController public function sendTrigger($mail_content) { $this->myLogger->logme('error', "Sending email with content"); - if(!empty($mail_content)){ + if (!empty($mail_content)) { $response = MailHelper::send_email($mail_content); - }else{ + } else { $response = ['status' => false, 'code' => 404, 'message' => "Mail not sent, mail data empty"]; $this->myLogger->logme('error', "Mail not sent, mail data empty"); } @@ -615,14 +621,14 @@ class TicketController extends BaseController } $ticket_data = $this->ticketMasterModel->getTicketDataByTicketID($mail_data['ticket_id']); - + // print_rr($ticket_data);die(); if (!$ticket_data) { - $this->myLogger->logme('error', "No ticket data found for Ticket ID : " .$mail_data['ticket_id']); + $this->myLogger->logme('error', "No ticket data found for Ticket ID : " . $mail_data['ticket_id']); $this->myLogger->logme('error', "Reply mail not send"); return null; } - if(!empty($mail_data)){ + if (!empty($mail_data)) { $mail_data['mail_content'] = $this->replacePlaceholders($mail_data['mail_content'], $ticket_data); $mail_data['mail_subject'] = $this->replacePlaceholders($mail_data['mail_subject'], $ticket_data); } @@ -653,10 +659,10 @@ class TicketController extends BaseController $mail_content = $this->constructMailContent($ticket_id); // print_r($mail_content); die; $mail_responce = $this->sendTrigger($mail_content); - }elseif (!empty($auto_mail_enable) && $auto_mail_enable['is_auto_mail'] == 0 ){ - $this->myLogger->logme('error','Auto Mail Not Sent, Reason: Automail Not Enabled'); - }else{ - $this->myLogger->logme('error','Auto Mail Not Sent, Reason: Mail Template Not Created'); + } elseif (!empty($auto_mail_enable) && $auto_mail_enable['is_auto_mail'] == 0) { + $this->myLogger->logme('error', 'Auto Mail Not Sent, Reason: Automail Not Enabled'); + } else { + $this->myLogger->logme('error', 'Auto Mail Not Sent, Reason: Mail Template Not Created'); } return $mail_responce; @@ -733,61 +739,106 @@ class TicketController extends BaseController AND th.is_active = 1 ORDER BY th.created_at DESC"; - $data = $this->ticketHistoryModel->query($sql)->getResultArray(); - $priorityType = $this->priorityType; - $relationshipType = $this->relationshipType; - $modeOFIntimate = $this->modeOFIntimate; - $claim_type = $this->claimType; - foreach ($data as &$row) { - if ($row['field_name'] == 'claim_status_id') { - $new_old_value = isset($row['old_status_value']) ? $row['old_status_value'] : '-'; - $new_new_value = $row['new_status_value']; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; - } elseif ($row['field_name'] == 'acm_id') { - $new_old_value = isset($row['old_account_manager']) ? $row['old_account_manager'] : '-'; - $new_new_value = $row['new_account_manager']; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; - } elseif ($row['field_name'] == 'insured_emp_id') { - $new_old_value = isset($row['old_insured_id_name']) ? $row['old_insured_id_name'] : '-'; - $new_new_value = $row['new_insured_id_name']; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; - } elseif ($row['field_name'] == 'priority') { - $new_old_value = isset($priorityType[$row['old_value']]) ? $priorityType[$row['old_value']] : '-'; - $new_new_value = isset($priorityType[$row['new_value']]) ? $priorityType[$row['new_value']] : '-'; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; - } elseif ($row['field_name'] == 'relationship') { - $new_old_value = isset($relationshipType[$row['old_value']]) ? $relationshipType[$row['old_value']] : '-'; - $new_new_value = isset($relationshipType[$row['new_value']]) ? $relationshipType[$row['new_value']] : '-'; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; - } elseif ($row['field_name'] == 'mode_of_intimation') { - $new_old_value = isset($modeOFIntimate[$row['old_value']]) ? $modeOFIntimate[$row['old_value']] : "-"; - $new_new_value = isset($modeOFIntimate[$row['old_value']]) ? $modeOFIntimate[$row['old_value']] : "-"; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; - } elseif ($row['field_name'] == 'claim_type') { - $new_old_value = isset($claim_type[$row['ticket_type_id']][$row['old_value']]) ? $claim_type[$row['ticket_type_id']][$row['old_value']] : '-'; - $new_new_value = isset($claim_type[$row['ticket_type_id']][$row['new_value']])?$claim_type[$row['ticket_type_id']][$row['new_value']]:'-'; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; - } elseif ($row['field_name'] == 'claim_type') { - $new_old_value = isset($claim_type[$row['old_value']]) ? $claim_type[$row['old_value']] : '-'; - $new_new_value = isset($claim_type[$row['new_value']]) ? $claim_type[$row['new_value']] : '-'; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; - } else { - $new_old_value = isset($row['old_value']) ? $row['old_value'] : '-'; - $new_new_value = isset($row['new_value']) ? $row['new_value'] : '-'; - $row['old_value'] = $new_old_value; - $row['new_value'] = $new_new_value; + $data = $this->ticketHistoryModel->query($sql)->getResultArray(); + $priorityType = $this->priorityType; + $relationshipType = $this->relationshipType; + $modeOFIntimate = $this->modeOFIntimate; + $claim_type = $this->claimType; + foreach ($data as &$row) { + if ($row['field_name'] == 'claim_status_id') { + $new_old_value = isset($row['old_status_value']) ? $row['old_status_value'] : '-'; + $new_new_value = $row['new_status_value']; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } elseif ($row['field_name'] == 'acm_id') { + $new_old_value = isset($row['old_account_manager']) ? $row['old_account_manager'] : '-'; + $new_new_value = $row['new_account_manager']; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } elseif ($row['field_name'] == 'insured_emp_id') { + $new_old_value = isset($row['old_insured_id_name']) ? $row['old_insured_id_name'] : '-'; + $new_new_value = $row['new_insured_id_name']; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } elseif ($row['field_name'] == 'priority') { + $new_old_value = isset($priorityType[$row['old_value']]) ? $priorityType[$row['old_value']] : '-'; + $new_new_value = isset($priorityType[$row['new_value']]) ? $priorityType[$row['new_value']] : '-'; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } elseif ($row['field_name'] == 'relationship') { + $new_old_value = isset($relationshipType[$row['old_value']]) ? $relationshipType[$row['old_value']] : '-'; + $new_new_value = isset($relationshipType[$row['new_value']]) ? $relationshipType[$row['new_value']] : '-'; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } elseif ($row['field_name'] == 'mode_of_intimation') { + $new_old_value = isset($modeOFIntimate[$row['old_value']]) ? $modeOFIntimate[$row['old_value']] : "-"; + $new_new_value = isset($modeOFIntimate[$row['old_value']]) ? $modeOFIntimate[$row['old_value']] : "-"; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } elseif ($row['field_name'] == 'claim_type') { + $new_old_value = isset($claim_type[$row['ticket_type_id']][$row['old_value']]) ? $claim_type[$row['ticket_type_id']][$row['old_value']] : '-'; + $new_new_value = isset($claim_type[$row['ticket_type_id']][$row['new_value']]) ? $claim_type[$row['ticket_type_id']][$row['new_value']] : '-'; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } elseif ($row['field_name'] == 'claim_type') { + $new_old_value = isset($claim_type[$row['old_value']]) ? $claim_type[$row['old_value']] : '-'; + $new_new_value = isset($claim_type[$row['new_value']]) ? $claim_type[$row['new_value']] : '-'; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } else { + $new_old_value = isset($row['old_value']) ? $row['old_value'] : '-'; + $new_new_value = isset($row['new_value']) ? $row['new_value'] : '-'; + $row['old_value'] = $new_old_value; + $row['new_value'] = $new_new_value; + } + } - } - } + return ($data); + } - return ($data); + public function sendMailWithAutoQuery() + { + + $ticket_ids = $this->ticketMessageModel + ->select('ticket_master.id') + ->join('ticket_master', 'ticket_master.id = ticket_messages.ticket_id AND ticket_master.is_active = 1 and ticket_master.claim_status_id in (4,17,27,37)') + ->join('ticket_claim_status AS tcs', 'tcs.id = ticket_messages.claim_status AND (tcs.is_active = 1)') + ->join('ticket_notes', 'ticket_notes.ticket_id = ticket_messages.ticket_id AND ticket_notes.is_auto_query = 1 AND ticket_notes.is_active = 1') + ->where('ticket_messages.is_active', 1) + ->where('ticket_messages.claim_status in (4,17,27,37)') + ->groupBy('ticket_master.id') + ->having('DATEDIFF(CURDATE(), MAX(ticket_messages.created_at)) =', 7) + ->having('count(ticket_messages.id) < ', 6) + ->findAll(); + + + // var_dump($ticket_ids);die(); + foreach ($ticket_ids as $ticket) { + + $ticket_id = $ticket['id']; + $acm_mails = $this->ticketMasterModel->getTicketDataByTicketID($ticket_id); + $ticket_data = $this->ticketMasterModel->getTicketDataByTicketID($ticket_id); + + $template_data = $this->ticketMasterModel->getTemplateDataByTicketID($ticket_id); + + if (!empty($template_data)) { + $template_data['mail_content'] = $this->replacePlaceholders($template_data['mail_content'], $ticket_data); + $template_data['subject'] = $this->replacePlaceholders($template_data['subject'], $ticket_data); + } + $emailData = [ + 'mail' => $template_data['emp_mail'], + 'subject' => $template_data['subject'], + 'message' => $template_data['mail_content'], + 'common' => [], + 'cc' => $acm_mails['common_mails'], + 'attachments' => [] + ]; + + $this->myLogger->logme('error', "Final Reply Email Data"); + // var_dump($emailData); + $this->sendTrigger($emailData); + } + + return 'Ticket id\'s : '.json_encode($ticket_ids); } } diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index 28b3215f..2d562005 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -105,7 +105,7 @@ class TicketMasterModel extends Model public function getTemplateDataByTicketID($ticket_id) { $template_data = $this - ->select("ticket_mail_template.*, ticket_master.emp_mail") + ->select("ticket_mail_template.*, ticket_master.emp_mail,ticket_master.claim_status_id") ->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 @@ -131,11 +131,13 @@ class TicketMasterModel extends Model clients.client_name, insurers.name as insurer_name, - tpa.name as tpa_name + tpa.name as tpa_name, + ticket_notes.note as auto_query_content ") ->join('clients', 'ticket_master.client_id = clients.id', 'left') ->join('insurers', 'ticket_master.insurer_id = insurers.id', 'left') ->join('tpa', 'ticket_master.tpa_id = tpa.id', 'left') + ->join('ticket_notes', 'ticket_master.id = ticket_notes.ticket_id and ticket_notes.is_active = 1 and ticket_notes.is_auto_query = 1','left') ->join('user_profiles', 'ticket_master.acm_id = user_profiles.id', 'left') ->where('ticket_master.id', $ticket_id) ->where('ticket_master.is_active', 1) diff --git a/app/Models/TicketMessageModel.php b/app/Models/TicketMessageModel.php index 37de2edb..88926fff 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 = ['id','sender','ticket_id','mail_subject','emp_mail','mail_content','created_at']; + protected $allowedFields = ['id','sender','ticket_id','claim_status','mail_subject','emp_mail','mail_content','created_at']; // Callbacks diff --git a/app/Models/TicketNoteModel.php b/app/Models/TicketNoteModel.php index 7efe2281..24f54be3 100644 --- a/app/Models/TicketNoteModel.php +++ b/app/Models/TicketNoteModel.php @@ -12,7 +12,7 @@ class TicketNoteModel extends Model protected $returnType = 'array'; protected $useSoftDeletes = false; protected $protectFields = true; - protected $allowedFields = ['id','ticket_id','note','created_by','updated_by','is_active']; + protected $allowedFields = ['id','ticket_id','note','is_auto_query','created_by','updated_by','is_active']; // Callbacks protected $allowCallbacks = true; diff --git a/app/Views/ticket_auto_query.php b/app/Views/ticket_auto_query.php new file mode 100644 index 00000000..68865fd2 --- /dev/null +++ b/app/Views/ticket_auto_query.php @@ -0,0 +1,98 @@ +
+
+
+
+
+
+
+ + +
+
+
+ +
+ +
+
+ + + + \ No newline at end of file diff --git a/app/Views/ticket_edit_onbording.php b/app/Views/ticket_edit_onbording.php index 2928a664..778a16e1 100644 --- a/app/Views/ticket_edit_onbording.php +++ b/app/Views/ticket_edit_onbording.php @@ -49,6 +49,13 @@ History + @@ -72,6 +79,9 @@
+
+ +
diff --git a/app/Views/ticket_list.php b/app/Views/ticket_list.php index 90b42568..d340881a 100644 --- a/app/Views/ticket_list.php +++ b/app/Views/ticket_list.php @@ -25,6 +25,20 @@ table.dataTable tbody td { margin-left: 20px !important; } + + +
@@ -52,12 +66,14 @@ table.dataTable tbody td { $row){ ?> - + + + - - + + @@ -77,6 +93,10 @@ table.dataTable tbody td { diff --git a/app/Views/claims_report_acc_manager_gpa.php b/app/Views/claims_report_acc_manager_gpa.php new file mode 100644 index 00000000..b1523e04 --- /dev/null +++ b/app/Views/claims_report_acc_manager_gpa.php @@ -0,0 +1,203 @@ + + +
+
+
+
+
+

Insurer List

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OPENCLEARED
Account MangerClaim IntimationIntimation to InsurerClient PendingInsurer PendingInvestigationApprovedOn HoldTotalNot CoveredClosedSettledTotal
Grand Total
+
+
+
+
+ + diff --git a/app/Views/claims_report_tpa_wise.php b/app/Views/claims_report_tpa_wise.php new file mode 100644 index 00000000..3682ca00 --- /dev/null +++ b/app/Views/claims_report_tpa_wise.php @@ -0,0 +1,210 @@ + + +
+
+
+
+
+

Insurer List

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OPENCLEARED
TPAID Not GeneratedNon-IDCDAInformation RequiredUnder ProcessApprovedPayment InitiatedTotalClosedSettledReturnedDeniedTotal
Grand Total
+
+
+
+
+ + diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index fa265d9c..f26439e5 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -658,6 +658,9 @@
  • Mail Template
  • +
  • + Claim Reports +
  • diff --git a/app/Views/ticket_reply.php b/app/Views/ticket_reply.php index 28a782f4..fffb138d 100644 --- a/app/Views/ticket_reply.php +++ b/app/Views/ticket_reply.php @@ -34,7 +34,7 @@
    - + diff --git a/app/Views/ticket_reports.php b/app/Views/ticket_reports.php new file mode 100644 index 00000000..4fe9732d --- /dev/null +++ b/app/Views/ticket_reports.php @@ -0,0 +1,140 @@ +
    +
    +
    +
    +
    + + + +
    +
    +
    + +
    +
    + +
    +   + +
    + > + > +
    + + +
    +
    + +
    + + +
    +
    + +
    + + +
    +
    + +
    + Submit +
    +
    + +
    +
    +
    +
    +
    +
    +
    + +
    +
    + + + \ No newline at end of file From eba590d90767ff12e518d17d482091e0e055e9f3 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 4 Feb 2025 15:39:18 +0530 Subject: [PATCH 4/5] FEAT_TAT_BAND_WISE : RV --- app/Controllers/ClientController.php | 16 +++- app/Models/TicketMasterModel.php | 120 ++++++++++++++++++++++++ app/Views/tat_report_band_wise_list.php | 101 ++++++++++++++++++++ 3 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 app/Views/tat_report_band_wise_list.php diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 4dd09ce2..7f340fa5 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -45,6 +45,7 @@ use App\Controllers\GoogleDriveController; use App\Helpers\sendMailNotification; use App\Models\RFQModel; +use App\Models\TicketMasterModel; class ClientController extends AdminController { @@ -4047,11 +4048,11 @@ class ClientController extends AdminController // -----------BDS REPORT CONTROLLER--------------------------------------------------------------------------------- - $BDSReportController = new BDSReportController(); + // $BDSReportController = new BDSReportController(); - $data['data'] = $BDSReportController->getBAPInsurerData(); + // $data['data'] = $BDSReportController->getBAPInsurerData(); - return $this->loadLayout('irda_bap_insurer_report_list', $data); + // return $this->loadLayout('irda_bap_insurer_report_list', $data); // $data['data'] = $BDSReportController->getBAPClientData(); // return $this->loadLayout('irda_bap_client_report_list', $data); @@ -4080,6 +4081,15 @@ class ClientController extends AdminController // $result = MailHelper::send_email($data[0]); // echo json_encode($result); // log_message('error',json_encode($result)); + + //-------------------------------------------------------------------------------------------------------- + + $ticketModel = new TicketMasterModel(); + $reportData['data'] = $ticketModel->getTATReport(1); + // print_rr($reportData); + $this->loadLayout('tat_report_band_wise_list', $reportData); + // $data = $ticketModel->getTATReport(1); + } // ------------------------------------------------------------------------------------------------------- diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index 2d562005..87998389 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -146,5 +146,125 @@ class TicketMasterModel extends Model return $ticket_data; } + //get TAT report BAND wise Data + public function getTATReport($ticket_type = null, $start_date = null, $end_date = null) + { + //set default last 3 months data date + $fromDate = date('Y-m-d', strtotime('-90 days')); + $toDate = date('Y-m-d 23:59:59'); + if (!empty($start_date) && !empty($end_date)) { + $fromDate = change_date_format($start_date); + $toDate = change_date_format($end_date); + } + $ticket_type_data_1 = ""; + $ticket_type_data_2 = ""; + if(!empty($ticket_type)){ + $ticket_type_data_1 = "WHERE ticket_type = $ticket_type"; + $ticket_type_data_2 = "AND tm.ticket_type_id = $ticket_type"; + } + + // Fetch claim statuses from the `ticket_claim_status` table + $statusQuery = " SELECT + id, claim_status + FROM ticket_claim_status + $ticket_type_data_1 + "; + $statusResult = $this->db->query($statusQuery)->getResultArray(); + // dd($statusResult); + + // Initialize dynamic query parts + $dynamicSelect = ''; + + // Loop through each claim status and generate the COALESCE and CASE statements for the SELECT + foreach ($statusResult as $status) { + // Dynamically add the COALESCE and CASE for each status in the SELECT part + $dynamicSelect .= " + COALESCE( + SUM( + CASE + WHEN subquery.status_id = {$status['id']} THEN 1 + ELSE 0 + END + ), + 0 + ) AS `{$status['claim_status']}`, "; + } + + // Remove the trailing comma from the SELECT part + $dynamicSelect = rtrim($dynamicSelect, ', '); + // dd($dynamicSelect); + + + // Construct the full SQL query + $sql = " + SELECT + tc.TAT_Category, + $dynamicSelect + FROM + ( + SELECT 'Above 20 Days' AS TAT_Category + UNION ALL + SELECT '13-20 Days' + UNION ALL + SELECT '7-12 Days' + UNION ALL + SELECT '0-6 Days' + ) AS tc + LEFT JOIN ( + SELECT + th.ticket_id, + tcs.claim_status, + tcs.id AS status_id, + CASE + WHEN DATEDIFF( + th.created_at, + COALESCE(tm.updated_at, th.created_at) + ) BETWEEN 0 AND 6 THEN '0-6 Days' + WHEN DATEDIFF( + th.created_at, + COALESCE(tm.updated_at, th.created_at) + ) BETWEEN 7 AND 12 THEN '7-12 Days' + WHEN DATEDIFF( + th.created_at, + COALESCE(tm.updated_at, th.created_at) + ) BETWEEN 13 AND 20 THEN '13-20 Days' + ELSE 'Above 20 Days' + END AS TAT_Category + FROM + ticket_master tm + JOIN ticket_history th ON tm.id = th.ticket_id + JOIN ticket_claim_status tcs ON th.field_name = 'claim_status_id' + AND th.new_value = tcs.id + $ticket_type_data_2 + AND tm.created_at >= '$fromDate' + AND tm.created_at <= '$toDate' + ) AS subquery ON tc.TAT_Category = subquery.TAT_Category + GROUP BY + tc.TAT_Category + ORDER BY + FIELD( + tc.TAT_Category, + 'Above 20 Days', + '13-20 Days', + '7-12 Days', + '0-6 Days' + ); + "; + + // Execute the query and return the result + $data = $this->db->query($sql)->getResultArray(); + // dd($this->db->getLastQuery(), $data); + + $tableData = []; + if (!empty($data)) { + // Extract table headers from the first row keys + $headers = array_keys($data[0]); + $tableData['headers'] = $headers; + $tableData['body'] = $data; + } + + return $data; + } + } diff --git a/app/Views/tat_report_band_wise_list.php b/app/Views/tat_report_band_wise_list.php new file mode 100644 index 00000000..204b4542 --- /dev/null +++ b/app/Views/tat_report_band_wise_list.php @@ -0,0 +1,101 @@ + + +
    +
    +
    +
    +
    +

    TAT Band Wise Report

    +
    + +
    +
    + + + + + + + + + + + + + + + + + +
    + +
    +
    +
    +
    +
    +
    + + + + \ No newline at end of file From 66dedc24e7d7d4722293fe66a42e8b7748661df4 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 4 Feb 2025 15:51:27 +0530 Subject: [PATCH 5/5] CHANGE_ADD_TAT_WISE_REPORT_VIEW_FILE : RV --- app/Controllers/ClientController.php | 6 +++--- app/Controllers/TicketController.php | 8 +++++++- app/Models/TicketMasterModel.php | 20 ++++++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 7f340fa5..6714a44d 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -4084,10 +4084,10 @@ class ClientController extends AdminController //-------------------------------------------------------------------------------------------------------- - $ticketModel = new TicketMasterModel(); - $reportData['data'] = $ticketModel->getTATReport(1); + // $ticketModel = new TicketMasterModel(); + // $reportData['data'] = $ticketModel->getTATReport(1); // print_rr($reportData); - $this->loadLayout('tat_report_band_wise_list', $reportData); + // $this->loadLayout('tat_report_band_wise_list', $reportData); // $data = $ticketModel->getTATReport(1); } diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 3da804a2..d8af5e1c 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -865,7 +865,7 @@ class TicketController extends BaseController $fromDate = \DateTime::createFromFormat('d-m-Y', $from_Date)->format('Y-m-d'); $toDate = \DateTime::createFromFormat('d-m-Y', $to_Date)->format('Y-m-d'); $policy_type = $received_data['policy_type']; -// print_rr($received_data); + // print_rr($received_data); if ($received_data['report_type'] == "acc_manager_wise_status"){ $viewData['account_manager_wise_data'] = $this->accountManagerWiseReport($policy_type,$fromDate,$toDate); @@ -884,6 +884,12 @@ class TicketController extends BaseController $html = view('claims_report_tpa_wise',$viewData); return $this->respond(['status' => true, 'html' => $html], 200); + }else if ($received_data['report_type'] == 'tat_band_wise'){ + + $viewData['data'] = $this->ticketMasterModel->getTATReport($policy_type, $fromDate, $toDate); + $html = view('tat_report_band_wise_list',$viewData); + return $this->respond(['status' => true, 'html' => $html], 200); + } } diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index 87998389..def64345 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -160,7 +160,7 @@ class TicketMasterModel extends Model $ticket_type_data_1 = ""; $ticket_type_data_2 = ""; if(!empty($ticket_type)){ - $ticket_type_data_1 = "WHERE ticket_type = $ticket_type"; + $ticket_type_data_1 = "AND ticket_type = $ticket_type"; $ticket_type_data_2 = "AND tm.ticket_type_id = $ticket_type"; } @@ -168,6 +168,7 @@ class TicketMasterModel extends Model $statusQuery = " SELECT id, claim_status FROM ticket_claim_status + Where is_active = 1 $ticket_type_data_1 "; $statusResult = $this->db->query($statusQuery)->getResultArray(); @@ -239,6 +240,9 @@ class TicketMasterModel extends Model $ticket_type_data_2 AND tm.created_at >= '$fromDate' AND tm.created_at <= '$toDate' + AND tm.is_active = 1 + AND th.is_active = 1 + AND tcs.is_active = 1 ) AS subquery ON tc.TAT_Category = subquery.TAT_Category GROUP BY tc.TAT_Category @@ -256,13 +260,13 @@ class TicketMasterModel extends Model $data = $this->db->query($sql)->getResultArray(); // dd($this->db->getLastQuery(), $data); - $tableData = []; - if (!empty($data)) { - // Extract table headers from the first row keys - $headers = array_keys($data[0]); - $tableData['headers'] = $headers; - $tableData['body'] = $data; - } + // $tableData = []; + // if (!empty($data)) { + // // Extract table headers from the first row keys + // $headers = array_keys($data[0]); + // $tableData['headers'] = $headers; + // $tableData['body'] = $data; + // } return $data; }