From 4272bd817cef16039f3574496e9e9f9ac4855031 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 29 Oct 2024 17:53:08 +0530 Subject: [PATCH] CHNAGE_RFQ_MAIL_TEMPLATE --- app/Controllers/LeadsController.php | 54 ++++++++++++++++++----------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 8b68ef55..b9f4029f 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -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 = '

Request for Quotation (RFQ)

Dear {{RECIPIENT_NAME}},

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.

RFQ Details

Client name{{CLIENT_NAME}}
Coverage Type{{POLICY_LONG_NAME}}
Policy Start Date{{POLICY_START_DATE}}
Policy Duration{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.

Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.

Best regards,

Nhance India Pvt Ltd

'; + $original_message = '

Request for Quotation (RFQ)

Dear {{RECIPIENT_NAME}},

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.

RFQ Details

Client name{{CLIENT_NAME}}
Coverage Type{{POLICY_LONG_NAME}}
Policy Start Date{{POLICY_START_DATE}}
Policy Duration{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.

Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.

Best regards,

Nhance India Pvt Ltd

© Nhance India Pvt Ltd. All rights reserved.

'; 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); }