nhance/app/Helpers/ChatbotHelper.php
2025-10-09 15:00:03 +05:30

572 lines
26 KiB
PHP

<?php
// File: App\Helpers\DepositHelper.php
namespace App\Helpers;
use App\Models\EmployeeModel;
use App\Models\CDMasterModel;
use App\Models\EmployeePolicyModel;
use App\Models\TPAModel;
use App\Helpers\MailHelper;
use App\Models\InsurerModel;
use App\Models\TicketMasterModel;
use App\Controllers\TicketController;
class ChatbotHelper
{
//get list of policies againest an employee_id
public static function getListOfPolicies($chat_session_info)
{
// $emp_id = 12288;
// $emp_code = 'HTL-007';
// $client_id = 159;
// $policy_id = 0;
// $client_branch_id = 126;
$emp_id = $chat_session_info['emp_id'];
$emp_code = $chat_session_info['emp_code'];
$client_id = $chat_session_info['client_id'];
$client_branch_id = $chat_session_info['client_branch_id'];
$relationship ='Self';
$EmployeeModel = new EmployeeModel();
return $EmployeeModel->getEmpFamilybyEmpCode(emp_code: $emp_code,client_id: $client_id,emp_status: ['active'],policy_status:['active'],client_branch_id:[ $client_branch_id ],relationship:[$relationship],policy_type_id:[2,3,4,5]);//,relationship:[$relationship];
}
public static function getHospitalLink($emp_policy_id){
// $client_policy_id = 336;
// $emp_id = 12288;
$EmployeePolicyModel = new EmployeePolicyModel();
$res = $EmployeePolicyModel->getHospitalLinkByPolicyandEmp($emp_policy_id);
return is_array($res) && count($res) ? $res[0]['network_hospitals'] : null;
}
public static function getPhoneNumber($chat_session_info){
$emp_id = $chat_session_info['emp_id'];
$EmployeeModel = new EmployeeModel();
return $EmployeeModel->select('mobile')->where('id',$emp_id)->first()['mobile'];
}
public static function sendReimbursementProcessOverMail($chat_session_info)
{
$emp_id = $chat_session_info['emp_id'];
$emp_code = $chat_session_info['emp_code'];
$client_id = $chat_session_info['client_id'];
$client_branch_id = $chat_session_info['client_branch_id'];
// $policy_id = 0;
// $relationship ='Father';
$EmployeeModel = new EmployeeModel();
$data = $EmployeeModel->find($emp_id);
if(isset($data) && isset($data['email_corporate']))
{
$message = SELF::ReimbursementProcessMailTemplate();
// $attachments = [
// ["filePath" => ROOTPATH."public/sample_excel/sample_addition.xls","fileName" => "sample_addition.xls"],
// ["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"],
// ["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"]
// ];
$common = ['mail_type'=>'reimbursement_mail_process_bot'];
$email_id = $data['email_corporate'];
// $email_id = 'vitvelz@gmail.com';
// $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Claim Reimbursement Process', 'message' => $message,'attachments' => $attachments,'common'=>$common]);
$res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Claim Reimbursement Process', 'message' => $message,'common'=>$common]);
$res = json_decode($res);
if($res->status == 'success')
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
public static function ReimbursementProcessMailTemplate()
{
$template = '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to Claim Your Insurance Reimbursement</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 20px auto;
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #2c3e50;
text-align: center;
}
p {
font-size: 16px;
color: #555;
line-height: 1.5;
}
.steps {
padding: 10px;
background-color: #ecf0f1;
border-radius: 5px;
margin-bottom: 20px;
}
.steps ol {
padding-left: 20px;
}
.btn {
display: block;
width: 200px;
margin: 20px auto;
padding: 12px;
text-align: center;
background-color: #3498db;
color: #ffffff;
text-decoration: none;
border-radius: 5px;
font-size: 16px;
}
.btn:hover {
background-color: #2980b9;
}
.footer {
text-align: center;
font-size: 14px;
color: #777;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h2>How to Claim Your Insurance Reimbursement</h2>
<p>Dear [Customer Name],</p>
<p>We are here to assist you in claiming your insurance reimbursement smoothly. Please follow the steps below:</p>
<div class="steps">
<ol>
<li><strong>Gather Documents:</strong> Collect all required documents such as bills, invoices, and medical reports.</li>
<li><strong>Complete the Claim Form:</strong> Fill out the insurance claim form in the portal.</li>
<li><strong>Attach Supporting Documents:</strong> Attach all necessary documents to support your claim.</li>
<li><strong>Submit Your Claim:</strong> Send the completed form and documents via email or through our online portal.</li>
<li><strong>Track Your Claim:</strong> Use our tracking system to monitor the status of your claim.</li>
<li><strong>Receive Reimbursement:</strong> Once approved, the reimbursement will be processed to your registered account.</li>
</ol>
</div>
<p>If you have any questions, feel free to contact our support team.</p>
<div class="footer">
<p>Best Regards,<br><strong>NhanceIndia Support Team</strong><br><a href="mailto:support@example.com">info@nhanceindia.in</a></p>
</div>
</div>
</body>
</html>
';
return $template;
}
public static function getInsurersList(){
$insurer = new InsurerModel();
$data = $insurer->select('short_name,name')->where('category','general')->where('is_active',1)->findAll();
return $data;
}
public static function sendQuotationRequestMail($data){
$message = SELF::quotationRequestMailTemplate($data);
$common = ['mail_type'=>'request_quotation_bot'];
$email_id = getenv('email.enquiryMail');
// $res = MailHelper::send_email(['mail' => $email_id, 'bcc' => 'vitvelz@gmail.com','subject' => '(TESTING)Quotation Request Received from bot.', 'message' => $message,'common'=>$common]);
$res = MailHelper::send_email(['mail' => $email_id,'subject' => 'Quotation Request Received from bot.', 'message' => $message,'common'=>$common]);
$res = json_decode($res);
log_message('error','res: '.json_encode($res));
if($res->status == 'success')
{
return true;
}
else
{
return false;
}
}
public static function quotationRequestMailTemplate($data){
$message = 'A customer has requested for a quotation using bot,Here are all the details for it:<br>
'.$data;
return $message;
}
public static function getReimbursementClaimStatus($chat_session_info){
$client_claim_status = [
'Received' => [1,2,3,4],
'Under Process' => [5,6,7,10],
'Finished' => [9,11,12],
'Rejected' => [8],
'Cancelled' => [13,14]
];
$emp_id = $chat_session_info['emp_id'];
log_message('error','emp_id'.$emp_id);
$emp_code = $chat_session_info['emp_code'];
$client_id = $chat_session_info['client_id'];
$client_branch_id = $chat_session_info['client_branch_id'];
$ticketMaster = new TicketMasterModel();
$data = $ticketMaster->select('tcs.id as tcs_id,tcs.claim_status,ticket_master.claim_number,ticket_master.id,ticket_master.emp_name,ticket_master.emp_mail')
// ->join('client_policy cp',"cp.client_id = {$client_id} and cp.client_branch_id = {$client_branch_id} and cp.policy_id = {$policy_id} and cp.is_active = 1")
->join('ticket_claim_status tcs',"ticket_master.claim_status_id = tcs.id and tcs.is_active = 1")
->where('ticket_master.emp_id',$emp_id)
->where('ticket_master.emp_code',$emp_code)
->where('ticket_master.is_active',1)
->orderBy('ticket_master.created_at', 'DESC')
->first();
$server_claim_status = $data['tcs_id'];
$matched_key = null;
foreach ($client_claim_status as $key => $statuses) {
if (in_array($server_claim_status, $statuses)) {
$matched_key = $key;
break; // Stop loop once found
}
}
log_message('error','Data from ticket master'.json_encode($data));
// print_r($data);
// die();
$ticket_controller = new TicketController();
if (!empty($data) && !empty($matched_key)){
$ticket_id = $data['id'];
$mail_content = Self::ReimbursementStatusMailTemplate($data['emp_name'],$data['claim_number'],$matched_key);
$common = ['mail_type'=>'Claim Status'];
$email_id = $data['emp_mail'];
// $email_id = 'vitvelz@gmail.com';
$res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Claim status as you requested in bot.', 'message' => $mail_content,'common'=>$common]);
$res = json_decode($res);
log_message('error','res: '.json_encode($res));
if($res->status == 'success')
{
$data['client_status'] = $matched_key;
return $data;
}
else
{
return false;
}
}else{
return false;
}
}
public static function ReimbursementStatusMailTemplate($emp_name, $claim_number, $client_status) {
$template = '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="x-apple-disable-message-reformatting">
<!--[if !mso]><!-->
<meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]-->
<title></title>
<style type="text/css">
@media only screen and (min-width: 640px) {
.u-row {
width: 620px !important;
}
.u-row .u-col {
vertical-align: top;
}
.u-row .u-col-100 {
width: 620px !important;
}
}
@media only screen and (max-width: 640px) {
.u-row-container {
max-width: 100% !important;
padding-left: 0px !important;
padding-right: 0px !important;
}
.u-row {
width: 100% !important;
}
.u-row .u-col {
display: block !important;
width: 100% !important;
min-width: 320px !important;
max-width: 100% !important;
}
.u-row .u-col>div {
margin: 0 auto;
}
.u-row .u-col img {
max-width: 100% !important;
}
}
body {
margin: 0;
padding: 0
}
table,
td,
tr {
border-collapse: collapse;
vertical-align: top
}
.ie-container table,
.mso-container table {
table-layout: fixed
}
* {
line-height: inherit
}
a[x-apple-data-detectors=true] {
color: inherit !important;
text-decoration: none !important
}
table,
td {
color: #000000;
}
</style>
</head>
<body class="clean-body u_body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #F9F9F9;color: #000000">
<!--[if IE]><div class="ie-container"><![endif]-->
<!--[if mso]><div class="mso-container"><![endif]-->
<table data-custom-table-css="table" style="border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;min-width: 320px;Margin: 0 auto;background-color: #F9F9F9;width:100%" cellpadding="0" cellspacing="0">
<tbody>
<tr style="vertical-align: top">
<td style="word-break: break-word;border-collapse: collapse !important;vertical-align: top">
<!--[if (mso)|(IE)]><table data-custom-table-css="table" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #F9F9F9;"><![endif]-->
<div class="u-row-container" style="padding: 0px;background-color: transparent">
<div class="u-row" style="margin: 0 auto;min-width: 320px;max-width: 620px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
<div style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
<!--[if (mso)|(IE)]><table data-custom-table-css="table" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding: 0px;background-color: transparent;" align="center"><table data-custom-table-css="table" cellpadding="0" cellspacing="0" border="0" style="width:620px;"><tr style="background-color: transparent;"><![endif]-->
<!--[if (mso)|(IE)]><td align="center" width="620" style="width: 620px;padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;" valign="top"><![endif]-->
<div class="u-col u-col-100" style="max-width: 320px;min-width: 620px;display: table-cell;vertical-align: top;">
<div style="height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
<!--[if (!mso)&(!IE)]><!-->
<div style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;"><!--<![endif]-->
<table data-custom-table-css="table" style="font-family:times new roman,times;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
<tbody>
<tr>
<td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:times new roman,times;" align="left">
<table data-custom-table-css="table" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="padding-right: 0px;padding-left: 0px;" align="center">
<img align="center" border="0" src="https://assets.unlayer.com/projects/263979/1739609649412-nhance_logo.png?w=372px" alt="" title="" style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 31%;max-width: 186px;" width="186" />
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
<!--[if (!mso)&(!IE)]><!-->
</div><!--<![endif]-->
</div>
</div>
<!--[if (mso)|(IE)]></td><![endif]-->
<!--[if (mso)|(IE)]></tr></table></td></tr></table><![endif]-->
</div>
</div>
</div>
<div class="u-row-container" style="padding: 0px;background-color: transparent">
<div class="u-row" style="margin: 0 auto;min-width: 320px;max-width: 620px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
<div style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
<!--[if (mso)|(IE)]><table data-custom-table-css="table" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding: 0px;background-color: transparent;" align="center"><table data-custom-table-css="table" cellpadding="0" cellspacing="0" border="0" style="width:620px;"><tr style="background-color: transparent;"><![endif]-->
<!--[if (mso)|(IE)]><td align="center" width="620" style="width: 620px;padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;" valign="top"><![endif]-->
<div class="u-col u-col-100" style="max-width: 320px;min-width: 620px;display: table-cell;vertical-align: top;">
<div style="height: 100%;width: 100% !important;">
<!--[if (!mso)&(!IE)]><!-->
<div style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;"><!--<![endif]-->
<table data-custom-table-css="table" style="font-family:times new roman,times;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
<tbody>
<tr>
<td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:times new roman,times;" align="left">
<div style="font-size: 14px; line-height: 140%; text-align: left; word-wrap: break-word;">
<p style="line-height: 140%; margin: 0px;">&nbsp;</p>
<p style="line-height: 140%; margin: 0px;">Dear [[member_name]],</p>
<p style="line-height: 140%; margin: 0px;">Your Claim Number [[claim_number]] is currently in the <strong>[[status]]</strong> status with us.</p>
<p style="line-height: 140%; margin: 0px;">&nbsp;</p>
<p style="line-height: 140%; margin: 0px;">&nbsp;</p>
</div>
</td>
</tr>
</tbody>
</table>
<!--[if (!mso)&(!IE)]><!-->
</div><!--<![endif]-->
</div>
</div>
<!--[if (mso)|(IE)]></td><![endif]-->
<!--[if (mso)|(IE)]></tr></table></td></tr></table><![endif]-->
</div>
</div>
</div>
<div class="u-row-container" style="padding: 0px;background-color: transparent">
<div class="u-row" style="margin: 0 auto;min-width: 320px;max-width: 620px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
<div style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
<!--[if (mso)|(IE)]><table data-custom-table-css="table" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding: 0px;background-color: transparent;" align="center"><table data-custom-table-css="table" cellpadding="0" cellspacing="0" border="0" style="width:620px;"><tr style="background-color: transparent;"><![endif]-->
<!--[if (mso)|(IE)]><td align="center" width="620" style="width: 620px;padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;" valign="top"><![endif]-->
<div class="u-col u-col-100" style="max-width: 320px;min-width: 620px;display: table-cell;vertical-align: top;">
<div style="height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
<!--[if (!mso)&(!IE)]><!-->
<div style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;"><!--<![endif]-->
<table data-custom-table-css="table" style="font-family:times new roman,times;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
<tbody>
<tr>
<td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:times new roman,times;" align="left">
<div>
<img alt="Alternate image text" src="https://ci3.googleusercontent.com/meips/ADKq_NZ1tC_lDp1mJDJ6iwpQvycq0vGPIeb0bF_z4SVXl6h2csrbTBpjuVtXZuXhPHAIRyGfRvc30Y83qZtaXRsM4_p2B9-yGkYAS56f6UraLELku6bQTXbhUaAyXGeq8TndT-y0vuvSLRhMi8iS9xL62fcwJ8r-MqMCdiwLcvuYRFZHcWeuPmkC_ByeA0H0v3lVozfDHgTThXzpuzsfkMMhg4wcUoxWxVNg4GNkS9dv=s0-d-e1-ft#https://res.cloudinary.com/mailmodo/image/upload/v1731739899/editor/p/86755bd3-1482-4348-86df-ac4c01829407/93af6a8f9f9d7c81c28b1b51d9127cea_fv4fpe.gif" width="22" height="auto" class="CToWUd __web-inspector-hide-shortcut__" data-bit="iit" style="border: 0px solid transparent; height: auto; line-height: 13px; outline: 0px; text-decoration: none; object-fit: cover; border-radius: 0px; display: block; width: 21.9907px; font-size: 13px; margin-left: auto; margin-right: auto;">
</div>
</td>
</tr>
</tbody>
</table>
<table data-custom-table-css="table" style="font-family:times new roman,times;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
<tbody>
<tr>
<td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:times new roman,times;" align="left">
<div style="font-size: 14px; line-height: 140%; text-align: center; word-wrap: break-word;">
<p style="line-height: 140%; margin: 0px;">ⓒ2024 Nhance India Insurance Broking Pvt Ltd</p>
</div>
</td>
</tr>
</tbody>
</table>
<!--[if (!mso)&(!IE)]><!-->
</div><!--<![endif]-->
</div>
</div>
<!--[if (mso)|(IE)]></td><![endif]-->
<!--[if (mso)|(IE)]></tr></table></td></tr></table><![endif]-->
</div>
</div>
</div>
<!--[if (mso)|(IE)]></td></tr></table><![endif]-->
</td>
</tr>
</tbody>
</table>
<!--[if mso]></div><![endif]-->
<!--[if IE]></div><![endif]-->
</body>
</html>
';
// Replace placeholders with actual values
$replacedTemplate = str_replace(
['[[member_name]]', '[[claim_number]]', '[[status]]'],
[$emp_name, $claim_number, $client_status],
$template
);
return $replacedTemplate;
}
}
?>