From a6422ba6b6f005aed8ce591ba86bf507dbaf3613 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 29 Oct 2024 15:24:07 +0530 Subject: [PATCH] FEAT_SEND_MAIL_ATTACHMENT_RFQ --- app/Config/Routes.php | 1 + app/Controllers/LeadsController.php | 77 ++++++++++++++++++++++++++++ app/Controllers/MasterController.php | 13 ++++- 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 8c1521be..6885275a 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -343,6 +343,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) { $routes->get("list", "LeadsController::viewLeadsList"); $routes->post("create", "LeadsController::createLead"); $routes->get("list/(:any)", "LeadsController::getLeadDataForEdit/$1"); + $routes->get("sendMail", "LeadsController::sendMailWithAttachement"); }); $routes->get("driveListFiles", "GoogleDriveController::listFiles"); diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 9c9d153f..f3a85d33 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -16,6 +16,9 @@ use App\Models\PolicyTransactionStatusModel; use App\Models\InsurerBranchModel; use App\Models\TPABranchModel; +use App\Helpers\MailHelper; + + class LeadsController extends BaseController { use ResponseTrait; @@ -296,4 +299,78 @@ class LeadsController extends BaseController } + //this funciton for send mail to insurer and client with either RFQ/QCR + public function sendMailWithAttachement() + { + helper('excel_util_helper'); + helper('MailHelper'); + + $params = $this->request->getGet(); + // dd($params); + $lead_id = $params['lead_id']; + $file_type = $params['file_type']; //rfq or qcr + $recipient_type = $params['recipient_type'];//insurer or client + $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) + { + return $this->respond(['status' => 'failed','code' => 400,'data' => '','messgae' => 'Recipient mail not found ! ' ], 200); + } + //gather lead info + $lead_data = $this->leadsModel + ->select('leads.*,policy_type.long_name,policy_type.policy_type') + ->join('policy_type','leads.policy_type_id = policy_type.id') + ->where('leads.id', $lead_id) + ->first(); + // dd($lead_data); + // dd(calculate_days_bw_dates($lead_data['policy_end_date'],$lead_data['policy_start_date'])); + //get file path to attach + $file_path = WRITEPATH."uploads/excel/sample/correction.xls"; + $file_name = $file_type.'.xlsx'; + + $attachments = [['fileName' => $file_name,'filePath' => $file_path]]; + + //get recipient address + $recipient_data = $this->levelContactModel + ->where(['contact_type' => $recipient_type, 'is_active' => 1]) + ->whereIn('id', $recipient_mail) + ->findAll(); + // !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

'; + + + foreach($recipient_data as $recipient) + { + + $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]); + // !dd($res); + // if($res['status'] == 'success' && $res['code'] == '200') + // { + $result_data[] = ['mail' => $recipient['email'],'status' => $res]; + // } + // else + // { + // $result_data[] = ['mail' => $recipient['email'],'status' => 'falied']; + // } + } + //delete attachment file + // unlink($file_path); + return $this->respond(['status' => 'success','code' => 200,'data' => $result_data ], 200); + + } + + } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 42f3d660..a4927e3d 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -1605,10 +1605,21 @@ class MasterController extends AdminController //testing a sample mail from cli public function testGmailAPIViaCLI(string $email_id = 'velmurugan.s@venbainfotech.com') { + + $email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id; // print_r($email_id);die(); // $gmailapi = \Config\Services::gmailapi(); + $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

'; + + $attachments = [ + ["filePath" => WRITEPATH."uploads/excel/sample/correction.xls","fileName" => "correction.xls"], + ["filePath" => WRITEPATH."uploads/excel/sample/deletion.xls","fileName" => "deletion.xls"], + ["filePath" => "C:\\Users\\Venba\\Desktop\\IQ.pdf","fileName" => "Questions.pdf"], + ["filePath" => "C:\\Users\\Venba\\Desktop\\config_age.png","fileName" => "config_age.png"] + ]; + $email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id; - $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => 'This is sample mail sent via CLI mode']); + $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments]); print_r($res); }