diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 818fe4b5..0771e41a 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -344,15 +344,10 @@ $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("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1");
});
-$routes->group("rfq", ["filter" => "authMVC"], function ($routes) {
- $routes->post("create", "LeadsController::createRFQ");
- $routes->post("createQCR", "LeadsController::createQCR");
- $routes->get("list/(:any)", "LeadsController::viewRFQ/$1");
-});
-
$routes->get("driveListFiles", "GoogleDriveController::listFiles");
$routes->post('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
$routes->get('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php
index 737a686f..8b68ef55 100644
--- a/app/Controllers/LeadsController.php
+++ b/app/Controllers/LeadsController.php
@@ -21,6 +21,9 @@ use App\Models\TPABranchModel;
use App\Models\RFQModel;
use App\Models\InsurerModel;
+use App\Helpers\MailHelper;
+
+
class LeadsController extends BaseController
{
use ResponseTrait;
@@ -566,4 +569,78 @@ class LeadsController extends BaseController
]; // Return file path and file name
}
+ //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 = '
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 = '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);
}