Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
bcaf62c12a
@ -453,7 +453,6 @@ $routes->get('cli/sendZeptoMail', 'MasterController::testZeptoSMTP');
|
||||
|
||||
$routes->cli('cli/processjob', 'JobWorker::processJob');
|
||||
$routes->cli('cli/processjobs', 'JobWorker::processJobs');
|
||||
$routes->cli('cli/sendMailWithAutoQuery','TicketController::sendMailWithAutoQuery');
|
||||
|
||||
$routes->get("processjob", "JobWorker::processJob");
|
||||
$routes->cli('cli/new_gmail_token', 'MasterController::generateNewGmailAPIToken');
|
||||
@ -467,6 +466,10 @@ $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDr
|
||||
$routes->cli('cli/enrollOpendAndClose', 'DashboardController::updatePolicyEnrollmentStatus');
|
||||
$routes->cli("cli/sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail");
|
||||
$routes->cli('cli/update-emp-policy-status', 'ClientController::updateEmpAndPolicyStatus');
|
||||
$routes->cli('cli/update-emp-policy-status', 'ClientController::updateEmpAndPolicyStatus');
|
||||
$routes->cli('cli/insurerRFQRemainder', 'LeadsController::remainderForQcr');
|
||||
$routes->cli('cli/sendMailWithAutoQuery','TicketController::sendMailWithAutoQuery');
|
||||
|
||||
|
||||
//Employee login api's
|
||||
$routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber");
|
||||
@ -670,4 +673,5 @@ $routes->get("ticketHistoryList", "ThzController::ticketHistoryList");
|
||||
//for testing
|
||||
$routes->group('test', function($routes) {
|
||||
$routes->post('api/saveForm', 'TestingController::saveForm');
|
||||
$routes->get('insurerRFQRemainder', 'LeadsController::remainderForQcr');
|
||||
});
|
||||
|
||||
@ -876,21 +876,40 @@ class LeadsController extends BaseController
|
||||
$qcr_created = true;
|
||||
}
|
||||
|
||||
if (($data['submit_type'] ?? "") == 'QCR') {
|
||||
$quote_received_insurer = [];
|
||||
if (($data['submit_type'] ?? "") === 'QCR') {
|
||||
|
||||
$inputJson = json_decode($data['json'], true);
|
||||
$proposal_data = array_pop($inputJson);
|
||||
if (isset($proposal_data['proposal_data']['over_all_column_data'])) {
|
||||
$proposel_count = $proposal_data['proposal_data']['over_all_column_data'];
|
||||
$proposal_data = $inputJson['proposal_data'] ?? array_pop($inputJson);
|
||||
|
||||
if (isset($proposal_data['over_all_column_data'])) {
|
||||
$proposel_count = $proposal_data['over_all_column_data'];
|
||||
|
||||
$this->myLogger->logme("error", "insurer id : " . json_encode($proposel_count));
|
||||
|
||||
foreach ($proposel_count as $key => $value) {
|
||||
if (!empty($value['insurers'])) {
|
||||
$qcr_created = true;
|
||||
|
||||
foreach ($value['insurers'] as $insurer => $id) {
|
||||
if (!empty($id['id'])) {
|
||||
$quote_received_insurer[] = $id['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->myLogger->logme("error", "quote_received_insurer : " . json_encode($quote_received_insurer));
|
||||
$data['type'] = 1;
|
||||
|
||||
//update the quote received insurer data to the lead
|
||||
if(count($quote_received_insurer) != 0){
|
||||
$this->leadsModel->update($lead_id, ['quote_received_insurer' => json_encode($quote_received_insurer ?? [])]);
|
||||
$this->myLogger->logme("error", "quote_received_insurer data updated in the lead: " . json_encode($quote_received_insurer));
|
||||
}
|
||||
|
||||
// Deactivate existing RFQs for this lead and type
|
||||
if (!isset($data['rfq_primaryKey']) && empty($data['rfq_primaryKey'])) {
|
||||
$this->RFQModel
|
||||
@ -2573,16 +2592,20 @@ class LeadsController extends BaseController
|
||||
}
|
||||
|
||||
$type = "";
|
||||
$insurer_ids = null;
|
||||
if (in_array($recipient_type, ['placement'])) {
|
||||
$type = "placement";
|
||||
} else if (in_array($recipient_type, ['insurer'])) {
|
||||
$type = "insurer";
|
||||
$insurer_ids = json_decode($params['insurer_ids'] ?? "", true) ?? [];
|
||||
}else if (in_array($recipient_type, ['internal'])) {
|
||||
$type = "internal";
|
||||
}else if (in_array($recipient_type, ['client'])) {
|
||||
$type = "client";
|
||||
}
|
||||
|
||||
// print_r($insurer_ids); die;
|
||||
|
||||
if ($recipient_type === 'placement') {
|
||||
|
||||
$lead_data = $this->leadsModel->find($lead_id);
|
||||
@ -2777,10 +2800,14 @@ class LeadsController extends BaseController
|
||||
}
|
||||
|
||||
// print_r($subject); die;
|
||||
$common = ['module' => "leads", 'pk' => $lead_id, 'mail_type' => $type];
|
||||
$common = ['module' => "leads", 'pk' => $lead_id, 'mail_type' => $type, 'common' => null];
|
||||
if ($recipient_data) {
|
||||
foreach ($recipient_data as $recipient) {
|
||||
foreach ($recipient_data as $position => $recipient) {
|
||||
|
||||
if ($recipient_type == 'insurer'){
|
||||
$common['common'] = $insurer_ids[$position] ?? null;
|
||||
}
|
||||
|
||||
$message = $original_message;
|
||||
$message = str_replace("{{RECIPIENT_NAME}}", $recipient['name'] != "" ? $recipient['name'] : " ", $message);
|
||||
$message = str_replace("{{CLIENT_NAME}}", $lead_data['client_name'] != "" ? $lead_data['client_name'] : "", $message);
|
||||
@ -3570,10 +3597,11 @@ class LeadsController extends BaseController
|
||||
$message = str_replace("{{POLICY_YEAR}}", $policy_year, $message);
|
||||
$message = str_replace("{{POLICY_END_DATE}}", " (Due On " . $formatted_policy . ")", $message);
|
||||
|
||||
$message = str_replace("{{LOGGED_USER_NAME}}", ucfirst($logged_user_data['first_name']) . " " . ucfirst($logged_user_data['last_name']), $message);
|
||||
$message = str_replace("{{LOGGED_USER_EMAIL}}", $logged_user_data['email'], $message);
|
||||
$message = str_replace("{{LOGGED_USER_MOBILE}}", $logged_user_data['mobile'], $message);
|
||||
$message = str_replace("{{LOGO_PATH}}", $log_path, $message);
|
||||
|
||||
$message = str_replace("{{LOGGED_USER_NAME}}", ucfirst($logged_user_data['first_name'] ?? "") . " " . ucfirst($logged_user_data['last_name'] ?? ""), $message);
|
||||
$message = str_replace("{{LOGGED_USER_EMAIL}}", $logged_user_data['email'] ?? "", $message);
|
||||
$message = str_replace("{{LOGGED_USER_MOBILE}}", $logged_user_data['mobile'] ?? "", $message);
|
||||
$message = str_replace("{{LOGO_PATH}}", $log_path ?? "", $message);
|
||||
|
||||
return $message;
|
||||
} else {
|
||||
@ -4946,4 +4974,197 @@ class LeadsController extends BaseController
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
// function for insurer remainder mail cron job
|
||||
public function remainderForQcr()
|
||||
{
|
||||
$lead_data = $this->leadsModel
|
||||
->select(
|
||||
'leads.*,
|
||||
user_profiles.email as created_person_email,
|
||||
policy_type.policy_type,
|
||||
policy_type.long_name
|
||||
')
|
||||
->join('policy_type', 'leads.policy_type_id = policy_type.id')
|
||||
->join('user_profiles', 'leads.created_by = user_profiles.id', 'left')
|
||||
->where('leads.is_active', 1)
|
||||
->where('user_profiles.is_active', 1)
|
||||
->whereIn('leads.status', ['rfq_sent', 'qcr_created'])
|
||||
->where('leads.next_reminder_date', date('Y-m-d'))
|
||||
->findAll();
|
||||
|
||||
// dd($lead_data);
|
||||
|
||||
if (count($lead_data) == 0) {
|
||||
$this->myLogger->logme("info", "No leads found for reminder mail at " . date('Y-m-d H:i:s'));
|
||||
print_r(["status" => true, "message" => "There is no data to send reminder mail"]);
|
||||
return ["status" => true, "message" => "There is no data to send reminder mail"];
|
||||
|
||||
}
|
||||
|
||||
$from_mail = "im@nhanceindia.in";
|
||||
$subject = "Reminder for RFQ";
|
||||
$content_string = '
|
||||
<p>Dear Sir,</p>
|
||||
<p>Greetings from Nhance India!</p>
|
||||
<p>This is a gentle reminder regarding our earlier mail about the RFQ for the <strong>{{POLICY_TYPE}}</strong> policy pertaining to <strong>{{CLIENT_NAME}}</strong>.</p>
|
||||
<p>We kindly request you to share the competitive quotes at the earliest possible convenience.</p>
|
||||
<p>In case of any clarification, please feel free to contact us.</p>
|
||||
<p>Thank you for your prompt attention to this matter.</p><br>
|
||||
<p>Best regards,</p>
|
||||
<p><strong>Nhance India</strong></p>
|
||||
';
|
||||
|
||||
$reminder_sended_lead = [];
|
||||
|
||||
foreach ($lead_data as $lead) {
|
||||
|
||||
$leadId = $lead['id'];
|
||||
$reply_to = $lead['created_person_email'] ?? "";
|
||||
|
||||
if (isset($lead['policy_end_date']) && $lead['policy_end_date'] != null) {
|
||||
$subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}} {{POLICY_END_DATE}}";
|
||||
} else {
|
||||
$subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}}";
|
||||
}
|
||||
|
||||
$mail_content = $this->transformMailContent($lead, $content_string, "RFQ");
|
||||
$mail_subject = $this->transformMailContent($lead, $subject, "RFQ");
|
||||
|
||||
|
||||
$this->myLogger->logme("info", "Processing lead_id={$leadId} for reminder mails");
|
||||
|
||||
// get sales person + created_by emails
|
||||
$sales_person_emails = $this->userModel
|
||||
->select('email')
|
||||
->where('is_active', 1)
|
||||
->whereIn('id', json_decode($lead['salse_person_id'] ?? "[]", true))
|
||||
->findAll();
|
||||
|
||||
$email_list = array_column($sales_person_emails, 'email');
|
||||
if (!empty($reply_to)) {
|
||||
$email_list[] = $reply_to;
|
||||
}
|
||||
$email_list = array_filter(array_unique($email_list));
|
||||
$email_string = implode(',', $email_list);
|
||||
|
||||
// Get latest sent mail timestamp
|
||||
$createdAtRow = $this->gmailSentHistoryModel
|
||||
->select("DATE_FORMAT(created_at, '%Y-%m-%d %H:%i') as created_at", false)
|
||||
->where('isactive', 1)
|
||||
->where('mail_type', 'insurer')
|
||||
->where('pk', $leadId)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
// dd(db_connect()->getLastQuery(), $createdAtRow);
|
||||
|
||||
if (!$createdAtRow) {
|
||||
$this->myLogger->logme("warning", "No sent history found for lead_id={$leadId}, skipping...");
|
||||
continue;
|
||||
}
|
||||
|
||||
$createdAt = $createdAtRow['created_at'];
|
||||
|
||||
// Fetch mail data for that timestamp
|
||||
$mail_datas = $this->gmailSentHistoryModel
|
||||
->where('isactive', 1)
|
||||
->where('mail_type', "insurer")
|
||||
->where('pk', $leadId)
|
||||
->where("DATE_FORMAT(created_at, '%Y-%m-%d %H:%i')", $createdAt)
|
||||
->findAll();
|
||||
|
||||
if (empty($mail_datas)) {
|
||||
$this->myLogger->logme("warning", "No mail data found for lead_id={$leadId} at created_at={$createdAt}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Filter only pending insurers
|
||||
$quote_received_insurer = json_decode($lead['quote_received_insurer'] ?? "[]", true);
|
||||
$reminder_mail_data = [];
|
||||
|
||||
if (empty($quote_received_insurer)) {
|
||||
$reminder_mail_data = $mail_datas;
|
||||
} else {
|
||||
foreach ($mail_datas as $mail_value) {
|
||||
$insurer_id = $mail_value['common'] ?? "";
|
||||
if (!in_array($insurer_id, $quote_received_insurer)) {
|
||||
$reminder_mail_data[] = $mail_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dd($reminder_mail_data);
|
||||
if (empty($reminder_mail_data)) {
|
||||
$this->myLogger->logme("info", "All insurers already responded for lead_id={$leadId}, no reminder needed");
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->myLogger->logme("info", "Sending " . count($reminder_mail_data) . " reminder mail(s) for lead_id={$leadId}");
|
||||
|
||||
$common = ['module' => "leads", 'pk' => $leadId, 'mail_type' => "remainder", 'common' => null];
|
||||
|
||||
foreach ($reminder_mail_data as $content) {
|
||||
$insurerId = $content['common'] ?? null;
|
||||
$common['common'] = $insurerId;
|
||||
|
||||
try {
|
||||
|
||||
if ($lead['is_insurer_auto_mail'] == 1) {
|
||||
// send reminder to insurer
|
||||
$res = MailHelper::send_email([
|
||||
'from_mail' => $from_mail,
|
||||
'mail' => $content['mail'] ?? "",
|
||||
'cc' => json_decode($content['cc'] ?? "", true) ?? "",
|
||||
'subject' => $mail_subject ?? "",
|
||||
'message' => $mail_content ?? "",
|
||||
'reply_to' => $reply_to,
|
||||
'bcc' => json_decode($content["bcc"] ?? "", true) ?? "",
|
||||
'common' => $common
|
||||
]);
|
||||
$this->myLogger->logme("info", "Reminder mail sent to the insurer | lead_id={$leadId}, insurer_id={$insurerId}, response=" . json_encode($res));
|
||||
|
||||
$reminder_sended_lead[] = [
|
||||
'lead_id' => $leadId,
|
||||
'insurer_id' => $insurerId,
|
||||
'response' => $res
|
||||
];
|
||||
} else{
|
||||
$this->myLogger->logme("info", "Reminder mail disable for this lead_id={$leadId}");
|
||||
}
|
||||
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
$errorDetails = [
|
||||
'error_message' => $e->getMessage(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'stack_trace' => $e->getTraceAsString(),
|
||||
];
|
||||
$this->myLogger->logme("error", "Exception while sending reminder | lead_id={$leadId}, insurer_id={$insurerId}, error=" . json_encode($errorDetails));
|
||||
$reminder_sended_lead[] = [
|
||||
'lead_id' => $leadId,
|
||||
'insurer_id' => $insurerId,
|
||||
'response' => ['status' => false, 'error' => $errorDetails]
|
||||
];
|
||||
}
|
||||
|
||||
// send reminder to sales person / creator only
|
||||
$internal_mail_response = MailHelper::send_email([
|
||||
'mail' => $from_mail,
|
||||
'cc' => $email_string,
|
||||
'subject' => $mail_subject ?? "",
|
||||
'message' => $mail_content ?? "",
|
||||
'common' => $common
|
||||
]);
|
||||
|
||||
$this->myLogger->logme("info", "Reminder mail sent to sales persons | lead_id={$leadId}, recipients={$email_string}, response=" . json_encode($internal_mail_response));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return ['status' => true, "data" => $reminder_sended_lead];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user