Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
VENKATESHWARAN 2024-10-29 21:35:06 +05:30
commit 32e1abcf34

View File

@ -22,6 +22,7 @@ use App\Models\RFQModel;
use App\Models\InsurerModel;
use App\Helpers\MailHelper;
use Kint;
class LeadsController extends BaseController
@ -583,61 +584,72 @@ class LeadsController extends BaseController
$recipient_mail = $params['recipient_mail'];// - only primary key of contacts
$recipient_mail = json_decode($params['recipient_mail'], true);;// - only primary key of contacts
$cc = 'velz1990@gmail.com,vitvelz@gmail.com';
$reply_to = 'velmurugan.s@venbainfotech.com';
$result_data = [];
// dd($recipient_mail);
if(!is_array($recipient_mail) || count($recipient_mail) == 0)
if($recipient_type == 'insurer' && (!is_array($recipient_mail) || count($recipient_mail) == 0))
{
return $this->respond(['status' => 'failed','code' => 400,'data' => '','messgae' => 'Recipient mail not found ! ' ], 200);
}
// dd();
//gather lead info
$lead_data = $this->leadsModel
->select('leads.*,policy_type.long_name,policy_type.policy_type')
->select('leads.*,policy_type.long_name,policy_type.policy_type,user_profiles.email as created_person_email')
->join('policy_type','leads.policy_type_id = policy_type.id')
->join('user_profiles','leads.created_by = user_profiles.id')
->where('leads.id', $lead_id)
->first();
if( $recipient_type == 'client' && ($lead_data['contact_person_email'] == '' || $lead_data['contact_person_email'] == null))
{
return $this->respond(['status' => 'failed','code' => 400,'data' => '','messgae' => 'Recipient mail not found ! ' ], 200);
}
// dd($lead_data);
// dd(calculate_days_bw_dates($lead_data['policy_end_date'],$lead_data['policy_start_date']));
$reply_to = $lead_data['created_person_email'];
//get file path to attach
$file_path = WRITEPATH."uploads/excel/sample/correction.xls";
$file_name = $file_type.'.xlsx';
$file_info = $this->constructExcelToSaveTemp($lead_id, ( $file_type == 'rfq' ? 1 : 2) );
// $file_path = WRITEPATH."uploads/excel/sample/correction.xls";
// $file_name = $file_type.'.xlsx';
// !dd($file_info);
$file_path = $file_info['filePath'];
$file_name = $file_info['fileName'];
$attachments = [['fileName' => $file_name,'filePath' => $file_path]];
//get recipient address
$recipient_data = $this->levelContactModel
if($recipient_type == 'insurer')
{
$recipient_data = $this->levelContactModel
->where(['contact_type' => $recipient_type, 'is_active' => 1])
->whereIn('id', $recipient_mail)
->findAll();
}
else
{
$recipient_data = [['name' => $lead_data['contact_person_name'],'email' => $lead_data['contact_person_email']] ];
}
// !dd($recipient_data);
$subject = $file_type == 'rfq' ? 'Request for Quotation from '. $lead_data['client_name'] . ' for '.$lead_data['policy_type'] : 'Quotation Comparison Report for ' .$lead_data['policy_type'];
$message = '<style>body{font-family:Arial,sans-serif;color:#333;line-height:1.6;margin:0;padding:0}.email-container{width:100%;max-width:600px;margin:0 auto;padding:20px;border:1px solid #e0e0e0;background-color:#f9f9f9}.header{background-color:#4a90e2;color:#fff;padding:15px;text-align:center}.header h1{margin:0;font-size:24px}.content{padding:20px;background-color:#fff}.content h2{color:#4a90e2;font-size:20px;margin-top:0}.content p{margin:10px 0}.details-table{width:100%;border-collapse:collapse;margin-top:20px}.details-table td,.details-table th{border:1px solid #ddd;padding:10px;text-align:left}.details-table th{background-color:#f2f2f2}.footer{margin-top:20px;font-size:12px;color:#777;text-align:center}.attachment-note{margin-top:20px;padding:10px;background-color:#f7f7f7;border-left:4px solid #4a90e2;font-style:italic}</style><div class=email-container><div class=header><h1>Request for Quotation (RFQ)</h1></div><div class=content><h2>Dear {{RECIPIENT_NAME}},</h2><p>We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.<h2>RFQ Details</h2><table class=details-table><tr><th>Client name<td>{{CLIENT_NAME}}<tr><th>Coverage Type<td>{{POLICY_LONG_NAME}}<tr><th>Policy Start Date<td>{{POLICY_START_DATE}}<tr><th>Policy Duration<td>{{DURATION}}</table><div class=attachment-note>Please note: Additional terms and details are included in the attachment for your reference.</div><p>Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.<p>Best regards,<p><strong>Nhance India Pvt Ltd</strong><br></div><div class=footer><p>© Nhance India Pvt Ltd. All rights reserved.</div></div>';
$original_message = '<div style="width:100%;max-width:600px;margin:0 auto;padding:20px;border:1px solid #e0e0e0;background-color:#f9f9f9;font-family:Arial,sans-serif;color:#333;line-height:1.6"><div style=background-color:#4a90e2;color:#fff;padding:15px;text-align:center><h1 style=margin:0;font-size:24px>Request for Quotation (RFQ)</h1></div><div style=padding:20px;background-color:#fff><h2 style=color:#4a90e2;font-size:20px;margin-top:0>Dear {{RECIPIENT_NAME}},</h2><p>We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.<h2 style=color:#4a90e2;font-size:20px;margin-top:20px>RFQ Details</h2><table style=width:100%;border-collapse:collapse;margin-top:20px><tr><th style="border:1px solid #ddd;padding:10px;text-align:left;background-color:#f2f2f2">Client name<td style="border:1px solid #ddd;padding:10px;text-align:left">{{CLIENT_NAME}}<tr><th style="border:1px solid #ddd;padding:10px;text-align:left;background-color:#f2f2f2">Coverage Type<td style="border:1px solid #ddd;padding:10px;text-align:left">{{POLICY_LONG_NAME}}<tr><th style="border:1px solid #ddd;padding:10px;text-align:left;background-color:#f2f2f2">Policy Start Date<td style="border:1px solid #ddd;padding:10px;text-align:left">{{POLICY_START_DATE}}<tr><th style="border:1px solid #ddd;padding:10px;text-align:left;background-color:#f2f2f2">Policy Duration<td style="border:1px solid #ddd;padding:10px;text-align:left">{{DURATION}}</table><div style="margin-top:20px;padding:10px;background-color:#f7f7f7;border-left:4px solid #4a90e2;font-style:italic">Please note: Additional terms and details are included in the attachment for your reference.</div><p>Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.<p>Best regards,<p><strong>Nhance India Pvt Ltd</strong><br></div><div style=margin-top:20px;font-size:12px;color:#777;text-align:center><p>© Nhance India Pvt Ltd. All rights reserved.</div></div>';
foreach($recipient_data as $recipient)
{
$message = $original_message;
$message = str_replace("{{RECIPIENT_NAME}}", $recipient['name'], $message);
$message = str_replace("{{CLIENT_NAME}}", $lead_data['client_name'], $message);
$message = str_replace("{{POLICY_LONG_NAME}}", $lead_data['long_name'], $message);
$message = str_replace("{{POLICY_START_DATE}}", change_date_format($lead_data['policy_start_date'],'Y-m-d','d-m-Y'), $message);
$message = str_replace("{{DURATION}}", calculate_days_bw_dates($lead_data['policy_end_date'],$lead_data['policy_start_date'])->days, $message);
// !dd($message);
$res = MailHelper::send_email(['mail' => $recipient['email'], 'subject' => $subject, 'message' => $message,'attachments' => $attachments,'reply_to' => $reply_to]);
// print_rr($message);
$res = MailHelper::send_email(['mail' => $recipient['email'], 'subject' => $subject, 'message' => $message,'attachments' => $attachments,'reply_to' => $reply_to]);
// !dd($res);
// if($res['status'] == 'success' && $res['code'] == '200')
// {
$result_data[] = ['mail' => $recipient['email'],'status' => $res];
// }
// else
// {
// $result_data[] = ['mail' => $recipient['email'],'status' => 'falied'];
// }
$result_data[] = ['mail' => $recipient['email'],'status' => $res];
}
//delete attachment file
// unlink($file_path);
unlink($file_path);
return $this->respond(['status' => 'success','code' => 200,'data' => $result_data ], 200);
}