CODE_MERGE : RV

This commit is contained in:
VENKATESHWARAN 2024-10-29 15:45:09 +05:30
commit e910797ea0
3 changed files with 90 additions and 7 deletions

View File

@ -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']);

View File

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

View File

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