sparqapi/api/application/helpers/pdalerts_helper.php

926 lines
43 KiB
PHP

<?php
class PDALERTS
{
/*
This function plays role of sending sms/email while PD status changing.
@param pdid
get current status, lender, created by, allocated_to, etc by using pdid.
then get pd notification config's using current pd status.
based on that pd config's send sms/email to endpoints
*/
public static function pdnotification($pdid)
{
log_message('ERROR','####PD notification for:-'.$pdid);
if($pdid != "" || $pdid != null)
{
//echo $pdid;
$CI =&get_instance();
//$CI->load->library('AWS_SNS');
$CI->load->helper('push_notification');
$CI->load->helper('custom_pdalerts');
$pd_notification_configs = array();
//die();
$additional_data_for_logs = array('pd_id' =>$pdid);
/*********************************************/
/*******Get PD Master Details*****************/
/*********************************************/
$CI->db->SELECT("PDTRIGGER.pd_id,PDTRIGGER.fk_lender_id,ENTITY.short_name,PDTRIGGER.lender_applicant_id,PDTRIGGER.fk_pd_type,PDTRIGGER.pd_status,PDTRIGGER.pd_date_of_initiation,PDTRIGGER.scheduled_on,PDTRIGGER.updatedon,PDTRIGGER.fk_pd_allocated_to,ALLOCATED.email as allocated_email,ALLOCATED.mobile_no as allocated_mobile_no,concat(ALLOCATED.first_name,' ',ALLOCATED.last_name) as pdofficer_name,PDTRIGGER.executive_id,EXECUTIVE.email as executive_email,EXECUTIVE.mobile_no as executive_mobile_no,PDTRIGGER.central_pd_officer_id,CENTRALPDOFFICER.mobile_no as centralpdofficer_mobile_no,CENTRALPDOFFICER.email as centralpdofficer_mail,PDTRIGGER.pd_agency_id,PDTRIGGER.pd_contact_person,PDTRIGGER.pd_contact_mobileno,CREATED.fk_entity_type_id,CREATED.email as created_email,PDTRIGGER.pd_contact_person_mail,PDAPPLICANTSDETAILS.applicant_name,PDAPPLICANTSDETAILS.mobile_no as customer_mobile_no,PDTRIGGER.encrypted_url,PDOFFICER.web_token as pdofficer_webtoken,PDOFFICER.mob_token as pdofficer_mobtoken,PDEXECUTIVE.web_token as pdexecutive_webtoken,PDEXECUTIVE.mob_token as pdexecutive_mobtoken,CENTRALPDOFFICERTOKEN.web_token as centralpdofficer_webtoken,CENTRALPDOFFICERTOKEN.mob_token as centralpdofficer_mobtoken,concat(LENDERSALESPERSON.first_name,' ',LENDERSALESPERSON.last_name) as lender_sales_person_name,LENDERSALESPERSON.mobile_no as lender_sales_contact_mobileno,LENDERSALESPERSON.email as lender_sales_person_email,concat(LENDERCREDITPERSON.first_name,' ',LENDERCREDITPERSON.last_name) as lender_credit_person_name,LENDERCREDITPERSON.mobile_no as lender_credit_person_contact_mobileno,LENDERCREDITPERSON.email as lender_credit_person_email,LENDERSALESPERSONTOKEN.web_token as lender_sales_web_token,LENDERSALESPERSONTOKEN.mob_token as lender_sales_mob_token,LENDERCREDITPERSONTOKEN.web_token as lender_credit_web_token,LENDERCREDITPERSONTOKEN.mob_token as lender_credit_mob_token,ENTITYFININSTITUTION.institute_email,ENTITY.is_sms_enabled,ENTITY.is_mail_enabled,ENTITY.is_app_notify_enabled,PDTRIGGER.is_notify_enabled,PDTRIGGER.pd_agency_id,VENDORBILLING.email as vendor_email");
$CI->db->FROM(PDTRIGGER." as PDTRIGGER");
$CI->db->JOIN(USERPROFILE." as CREATED","PDTRIGGER.fk_createdby = CREATED.userid",'LEFT');
$CI->db->JOIN(ENTITY." as ENTITY","PDTRIGGER.fk_lender_id = ENTITY.entity_id",'LEFT');
$CI->db->JOIN(ENTITYBILLING." as VENDORBILLING","PDTRIGGER.pd_agency_id = VENDORBILLING.fk_entity_id",'LEFT');
$CI->db->JOIN(ENTITYFININSTITUTION." as ENTITYFININSTITUTION","PDTRIGGER.imgc_fin_institute = ENTITYFININSTITUTION.entity_fin_institution_id",'LEFT');
$CI->db->JOIN(USERPROFILE." as ALLOCATED","PDTRIGGER.fk_pd_allocated_to = ALLOCATED.userid",'LEFT');
$CI->db->JOIN(USERPROFILE." as EXECUTIVE","PDTRIGGER.executive_id = EXECUTIVE.userid",'LEFT');
$CI->db->JOIN(USERPROFILE." as CENTRALPDOFFICER","PDTRIGGER.central_pd_officer_id = CENTRALPDOFFICER.userid",'LEFT');
$CI->db->JOIN(USERPROFILE.' as LENDERSALESPERSON','PDTRIGGER.lender_sales_person = LENDERSALESPERSON.userid','LEFT');
$CI->db->JOIN(USERPROFILE.' as LENDERCREDITPERSON','PDTRIGGER.lender_credit_person = LENDERCREDITPERSON.userid','LEFT');
$CI->db->JOIN(PDAPPLICANTSDETAILS." as PDAPPLICANTSDETAILS","PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1",'LEFT');
$CI->db->JOIN(USERNOTIFICATIONTOKENS." as PDOFFICER","PDTRIGGER.fk_pd_allocated_to = PDOFFICER.fk_user_id",'LEFT');
$CI->db->JOIN(USERNOTIFICATIONTOKENS." as PDEXECUTIVE","PDTRIGGER.executive_id = PDEXECUTIVE.fk_user_id",'LEFT');
$CI->db->JOIN(USERNOTIFICATIONTOKENS." as CENTRALPDOFFICERTOKEN","PDTRIGGER.central_pd_officer_id = CENTRALPDOFFICERTOKEN.fk_user_id",'LEFT');
$CI->db->JOIN(USERNOTIFICATIONTOKENS." as LENDERSALESPERSONTOKEN","PDTRIGGER.lender_sales_person = LENDERSALESPERSONTOKEN.fk_user_id",'LEFT');
$CI->db->JOIN(USERNOTIFICATIONTOKENS." as LENDERCREDITPERSONTOKEN","PDTRIGGER.lender_credit_person = LENDERCREDITPERSONTOKEN.fk_user_id",'LEFT');
$CI->db->WHERE("PDTRIGGER.pd_id",$pdid);
$core_details = $CI->db->GET()->result_array();
//print_r($core_details);
// die();
if(count($core_details))
{
//SMC MWISE Custome PdNotification Don't Call.
$smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //SMC lender id MWISE in live and demo
if($smc_lender_id != $core_details[0]['fk_lender_id']){
//Trigger Custom Notification apart from entity and PD level notification config
CUSTOM_PDALERTS::custom_pdnotification($CI,$core_details);//die();
//END Trigger Custom Notification apart from entity and PD level notification config
}
$is_pd_notify_enabled = $core_details[0]['is_notify_enabled'];
$is_sms_enabled = $core_details[0]['is_sms_enabled'];
$is_mail_enabled = $core_details[0]['is_mail_enabled'];
$is_app_notify_enabled = $core_details[0]['is_app_notify_enabled'];
if(!$is_pd_notify_enabled)
{
$is_sms_enabled = 0;
$is_mail_enabled = 0;
$is_app_notify_enabled = 0;
}
$additional_data_for_logs['pd_status'] = $core_details[0]['pd_status'];
/*********************************************/
/*******Get Notification Config Details*****/
/*********************************************/
$CI->db->SELECT("*");
$CI->db->FROM(PDNOTIFICATION." as PDNOTIFICATION");
$CI->db->WHERE("PDNOTIFICATION.pd_status",$core_details[0]['pd_status']);
$CI->db->WHERE("PDNOTIFICATION.isactive",1);
$pd_notification_configs = $CI->db->GET()->result_array();
//print_r($CI->db->last_query());
//print_r($pd_notification_configs);
/*********************************************/
/*******Get Previous PD status from History Table*****/
/*********************************************/
$CI->db->SELECT("*");
$CI->db->FROM(COMMONMASTER." as COMMONMASTER");
$CI->db->WHERE("COMMONMASTER.primary_key",$pdid);
$CI->db->WHERE("COMMONMASTER.field_name",'pd_status');
$CI->db->WHERE("COMMONMASTER.table_name",PDTRIGGER);
$pd_previous_status = $CI->db->GET()->result_array();
$is_flag = 0;
//print_r($pd_previous_status);
if($core_details[0]['pd_status'] != 'ALLOCATED' || $core_details[0]['pd_status'] != 'SCHEDULED')
{
if(count($pd_previous_status))
{
foreach($pd_previous_status as $previous_status)
{
if($previous_status['old_value'] == $core_details[0]['pd_status'])
{
$is_flag = 1;
}
}
}
}
//echo $is_flag;
if($is_flag == 0)
{
/*********************************************/
/*******Get SMS Notifications From Master*****/
/*********************************************/
$CI->db->SELECT("*");
$CI->db->FROM(PDNOTIFICATIONMSG." as PDNOTIFICATIONMSG");
$CI->db->WHERE("PDNOTIFICATIONMSG.pd_status",$core_details[0]['pd_status']);
$CI->db->WHERE("PDNOTIFICATIONMSG.isactive",1);
$pd_notification_msg = $CI->db->GET()->result_array();
if(count($pd_notification_configs))
{
/*********************************************/
/*******Send SMS Notification to Lender*****/
/*********************************************/
if($pd_notification_configs[0]['sms_lender'] == 1 && $is_sms_enabled)
{
$lender_sms = (string)$core_details[0]['pd_contact_mobileno'];
$lender_sales_contact_mobileno = (string)$core_details[0]['lender_sales_contact_mobileno'];
$lender_credit_person_contact_mobileno = (string)$core_details[0]['lender_credit_person_contact_mobileno'];
if($pd_notification_msg[0]['lender'] != null)
{
$msg = $pd_notification_msg[0]['lender'];
$msg = self::stringReplace($msg,$core_details);
//echo $msg;
$msg = str_replace('<br>','',$msg);
$additional_data_for_logs['to_whom'] = 'LEDNER';
SMS_GUPSHUP::sendSMS($msg,$lender_sms,$additional_data_for_logs);
$additional_data_for_logs['to_whom'] = 'LEDNERSALES';
SMS_GUPSHUP::sendSMS($msg,$lender_sales_contact_mobileno,$additional_data_for_logs);
$additional_data_for_logs['to_whom'] = 'LEDNERCREDIT';
SMS_GUPSHUP::sendSMS($msg,$lender_credit_person_contact_mobileno,$additional_data_for_logs);
}
}
/*********************************************/
/*******Send Mail Notification to Lender*****/ //
/*********************************************/
if($pd_notification_configs[0]['mail_lender'] == 1 && $is_mail_enabled)
{
$lender_email = null;
$lender_sales_person_email = $core_details[0]['lender_sales_person_email'];
$lender_credit_person_email = $core_details[0]['lender_credit_person_email'];
$financial_institude_email = $core_details[0]['institute_email'];
if($core_details[0]['fk_entity_type_id'] == 2 )
{
$lender_email = $core_details[0]['created_email'];
}
else if($core_details[0]['pd_contact_person_mail'] != null)
{
$lender_email = $core_details[0]['pd_contact_person_mail'];
}
$msg = $pd_notification_msg[0]['lender'];
$msg = self::stringReplace($msg,$core_details,'MAIL');
if($lender_email != null)
{
// self::sendMail($CI,$lender_email,$msg,$core_details); // currently Mail disabled
}
if($lender_sales_person_email != null){ self::sendMail($CI,$lender_sales_person_email,$msg,$core_details); }
if($lender_credit_person_email != null){ self::sendMail($CI,$lender_credit_person_email,$msg,$core_details); }
if($financial_institude_email != null)
{
self::sendMail($CI,$financial_institude_email,$msg,$core_details);
//self::sendMail($CI,'velmurugan.s@venbainfotech.com',$msg,$core_details);
if(ENVIRONMENT == 'testing')
{
//self::sendMail($CI,'vitvelz@gmail.com',$msg,$core_details);
}
}
self::sendMail($CI,'komalmittal@sinemanagement.com',$msg,$core_details);
if($core_details[0]['pd_status'] != 'TRIGGERED' && ENVIRONMENT == 'production')
{
self::sendMail($CI,'sinepd@sinemanagement.com',$msg,$core_details);
}
}
/*********************************************/
/*******Send Push Notification to Lender(WEB/MOB)*****
/*********************************************/
if($pd_notification_configs[0]['app_lender'] == 1 && $is_app_notify_enabled)
{
//$lender_web_token = (string)$core_details[0]['pd_contact_mobileno'];
//$lender_mob_token = (string)$core_details[0]['pd_contact_mobileno'];
$msg = $pd_notification_msg[0]['lender'];
$msg = self::stringReplace($msg,$core_details);
$lender_sales_web_token = (string)$core_details[0]['lender_sales_web_token'];
$lender_sales_mob_token = (string)$core_details[0]['lender_sales_mob_token'];
$additional_data_for_logs['to_whom'] = 'LEDNERSALES';
PUSH_NOTIFICATION::sendNotification($lender_sales_web_token,$lender_sales_mob_token,$msg,$additional_data_for_logs);
$lender_credit_web_token = (string)$core_details[0]['lender_credit_web_token'];
$lender_credit_mob_token = (string)$core_details[0]['lender_credit_mob_token'];
$additional_data_for_logs['to_whom'] = 'LEDNERCREDIT';
PUSH_NOTIFICATION::sendNotification($lender_credit_web_token,$lender_credit_mob_token,$msg,$additional_data_for_logs);
}
/*********************************************/
/*******Send Push Notification to Admin(WEB)*****
/*********************************************/
if($pd_notification_configs[0]['admin'] == 1)// && $is_app_notify_enabled)
{
//$lender_web_token = (string)$core_details[0]['pd_contact_mobileno'];
//$lender_mob_token = (string)$core_details[0]['pd_contact_mobileno'];
$msg = $pd_notification_msg[0]['admin'];
$msg = self::stringReplace($msg,$core_details);
//get all admins tokens
$CI->db->SELECT("notification_token_id, fk_user_id, web_token, mob_token, createdon, updatedon");
$CI->db->FROM(USERNOTIFICATIONTOKENS." as USERNOTIFICATIONTOKENS");
$CI->db->JOIN(USERPROFILEROLES." as USERPROFILEROLES","USERNOTIFICATIONTOKENS.fk_user_id = USERPROFILEROLES.fk_userid and USERPROFILEROLES.user_role = 10 and USERPROFILEROLES.isactive = 1");
$admins = $CI->db->GET()->result_array();
foreach ($admins as $key => $value)
{
$additional_data_for_logs['to_whom'] = 'ADMIN';
PUSH_NOTIFICATION::sendNotification($value['web_token'],$value['mob_token'],$msg,$additional_data_for_logs);
}
}
/*********************************************/
/*******Send SMS Notification to PD Officer*****/
/*********************************************/
if($pd_notification_configs[0]['sms_pdofficer'] == 1 && $is_sms_enabled)
{
$mobile_nos_to_send_notification = array();
array_push($mobile_nos_to_send_notification,$core_details[0]['allocated_mobile_no']);
if($core_details[0]['executive_mobile_no'] != "" || $core_details[0]['executive_mobile_no'] != null)
{
array_push($mobile_nos_to_send_notification,$core_details[0]['executive_mobile_no']);
}
if($pd_notification_msg[0]['pdofficer'] != null)
{
$msg = $pd_notification_msg[0]['pdofficer'];
$msg = self::stringReplace($msg,$core_details);
$additional_data_for_logs['to_whom'] = 'PD_OFFICER';
foreach($mobile_nos_to_send_notification as $mobile){ SMS_GUPSHUP::sendSMS($msg,(string)$mobile,$additional_data_for_logs); };
}
}
/*********************************************/
/*******Send Push Notification to PD Officer*****/
/*********************************************/
if($pd_notification_configs[0]['app_pdofficer'] == 1 && $is_app_notify_enabled)
{
$pd_offcier_web_token = $core_details[0]['pdofficer_webtoken'];
$pd_offcier_mob_token = $core_details[0]['pdofficer_mobtoken'];
$pd_executive_mob_token = $core_details[0]['pdexecutive_mobtoken'];
$pd_executive_web_token = $core_details[0]['pdexecutive_webtoken'];
$msg = $pd_notification_msg[0]['pdofficer'];
$msg = self::stringReplace($msg,$core_details);
PUSH_NOTIFICATION::sendNotification($pd_offcier_web_token,$pd_offcier_mob_token,$msg,$additional_data_for_logs);
PUSH_NOTIFICATION::sendNotification($pd_executive_web_token,$pd_executive_mob_token,$msg,$additional_data_for_logs);
}
/*********************************************/
/*******Send SMS Notification to Customer*****/
/*********************************************/
if($pd_notification_configs[0]['sms_customer'] == 1 && $is_sms_enabled)
{
if($core_details[0]['customer_mobile_no'] != "" || $core_details[0]['customer_mobile_no'] != null)
{
if($pd_notification_msg[0]['customer'] != null)
{
$msg = $pd_notification_msg[0]['customer'];
$msg = self::stringReplace($msg,$core_details);
$additional_data_for_logs['to_whom'] = 'CUSTOMER';
SMS_GUPSHUP::sendSMS($msg,(string)$core_details[0]['customer_mobile_no'],$additional_data_for_logs);
}
}
}
/*********************************************/
/**Send SMS Notification to Central PD Officer**/
/*********************************************/
if($pd_notification_configs[0]['sms_pdincharge'] == 1 && $is_sms_enabled)
{
if($core_details[0]['centralpdofficer_mobile_no'] != "" || $core_details[0]['centralpdofficer_mobile_no'] != null)
{
if($pd_notification_msg[0]['pdincharge'] != null)
{
$msg = $pd_notification_msg[0]['pdincharge'];
$msg = self::stringReplace($msg,$core_details);
$additional_data_for_logs['to_whom'] = 'PDMANAGER/PDINCHARGE';
SMS_GUPSHUP::sendSMS($msg,(string)$core_details[0]['centralpdofficer_mobile_no'],$additional_data_for_logs);
}
}
}
/*********************************************/
/**Send Push Notification to Central PD Officer**/
/*********************************************/
if($pd_notification_configs[0]['app_pdincharge'] == 1 && $is_app_notify_enabled)
{
$central_offcier_web_token = $core_details[0]['centralpdofficer_webtoken'];
$central_offcier_mob_token = $core_details[0]['centralpdofficer_mobtoken'];
$msg = $pd_notification_msg[0]['pdincharge'];
$msg = self::stringReplace($msg,$core_details);
PUSH_NOTIFICATION::sendNotification($central_offcier_web_token,$central_offcier_mob_token,$msg,$additional_data_for_logs);
}
/*********************************************/
/**Send SMS Notification to QC Team*****/
/*********************************************/
if($pd_notification_configs[0]['sms_qcteam'] == 1 && $is_sms_enabled)
{
$CI->db->DISTINCT();
$CI->db->SELECT("mobile_no");
$CI->db->FROM(USERPROFILE." as USERPROFILE");
$CI->db->JOIN(USERPROFILEROLES." as USERPROFILEROLES","USERPROFILE.userid = USERPROFILEROLES.fk_userid AND USERPROFILEROLES.isactive = 1 AND USERPROFILE.isactive = 1");
$CI->db->WHERE("USERPROFILEROLES.user_role",6);//QC Manager
$CI->db->OR_WHERE("USERPROFILEROLES.user_role",7);//QC Officer
$qcteam_mobile_nos = $CI->db->GET()->result_array();
if(count($qcteam_mobile_nos))
{
$mobile_nos_to_send_notification = array();
foreach($qcteam_mobile_nos as $mobile)
{
array_push($mobile_nos_to_send_notification,$mobile);
}
if($pd_notification_msg[0]['qc_team'] != null)
{
$msg = $pd_notification_msg[0]['qc_team'];
$msg = self::stringReplace($msg,$core_details);
$additional_data_for_logs['to_whom'] = 'QC_TEAM';
foreach($mobile_nos_to_send_notification as $mobile){
SMS_GUPSHUP::sendSMS($msg,(string)$mobile['mobile_no'],$additional_data_for_logs);
};
}
}
}
/*********************************************/
/**Send PUSH Notification to QC Team*****/
/*********************************************/
if($pd_notification_configs[0]['app_qcteam'] == 1 && $is_app_notify_enabled)
{
$CI->db->DISTINCT();
$CI->db->SELECT("web_token,mob_token");
$CI->db->FROM(USERNOTIFICATIONTOKENS." as USERNOTIFICATIONTOKENS");
//$CI->db->FROM(USERPROFILE." as USERPROFILE");
$CI->db->JOIN(USERPROFILEROLES." as USERPROFILEROLES","USERPROFILEROLES.fk_userid = USERNOTIFICATIONTOKENS.fk_user_id AND USERPROFILEROLES.isactive = 1",'LEFT');
$CI->db->WHERE("USERPROFILEROLES.user_role",6);//QC Manager
$CI->db->OR_WHERE("USERPROFILEROLES.user_role",7);//QC Officer
$qcteam_push_tokens = $CI->db->GET()->result_array();
if(count($qcteam_push_tokens))
{
$qc_team_web_token = array();
$qc_team_mob_token = array();
foreach($qcteam_push_tokens as $token)
{
if(isset($token['web_token']) && ($token['web_token'] != "" || $token['web_token'] != null))
{
array_push($qc_team_web_token,$token['web_token']);
}
if(isset($token['mob_token']) && ($token['mob_token'] != "" || $token['mob_token'] != null))
{
array_push($qc_team_mob_token,$token['mob_token']);
}
}
$msg = $pd_notification_msg[0]['qc_team'];
$msg = self::stringReplace($msg,$core_details);
$additional_data_for_logs['to_whom'] = 'QC_TEAM';
foreach ($qc_team_web_token as $key => $value) {
PUSH_NOTIFICATION::sendNotification($value,null,$msg,$additional_data_for_logs);
}
foreach ($qc_team_mob_token as $key => $value) {
PUSH_NOTIFICATION::sendNotification(null,$value,$msg,$additional_data_for_logs);
}
}
}
}
}
}
}
}
/*********************************************/
/**REPLACE PLACEHOLDERS****/
/*********************************************/
public static function stringReplace($msg,$core_details,$for = 'SMS')
{
$msg = str_replace('{{applicant_name}}',$core_details[0]['applicant_name'],$msg);
$msg = str_replace('{{applicant_id}}',$core_details[0]['lender_applicant_id'],$msg);
$msg = str_replace('{{schedule_time}}',$core_details[0]['scheduled_on'],$msg);
$msg = str_replace('{{initiate_time}}',$core_details[0]['pd_date_of_initiation'],$msg);
$msg = str_replace('{{pdofficer_name}}',$core_details[0]['pdofficer_name'],$msg);
$msg = str_replace('{{start_time}}',$core_details[0]['updatedon'],$msg);
$msg = str_replace('{{pdofficer_name}}',$core_details[0]['pdofficer_name'],$msg);
$msg = str_replace('{{lender_name}}',$core_details[0]['short_name'],$msg);
$msg = str_replace('{{link}}',$core_details[0]['encrypted_url'],$msg);
//$msg = str_replace('{{\n\n}}','\n\n',$msg);
// $msg = nl2br($msg);
if($for == 'SMS')
{
$msg = str_replace('\n','',$msg);
$msg = str_replace('\\','',$msg);
}
else if($for == 'MAIL')
{
$msg = str_replace('\n','<br>',$msg);
$msg = str_replace('\\','',$msg);
}
return $msg;
}
public static function sendMail($CI,$lender_email,$msg,$core_details)
{
//echo "Mail called";
$mail = $CI->phpmailer_library->load();
//echo "$msg";
$mail->IsSMTP(); // Telling the class to use SMTP
$mail->SMTPAuth = true;
$mail->SMTPDebug = 0;
$mail->SMTPSecure = "ssl";
$mail->Host = 'bh-in-16.webhostbox.net'; // SMTP server
$mail->Username = "noreply@ssa.sineedge.com"; // "The account"
$mail->Password = "noreply@ssa"; // "The password"
$mail->Port = 465; // "The port"
$mail->addAddress($lender_email); // Name is optional
$mail->From = 'noreply@pdgenie.com';
$fromName = 'PD Genie'; if(ENVIRONMENT == 'testing' || ENVIRONMENT == 'development') { $fromName .= ' ( TEST ENV ) '; }
$mail->FromName = $fromName;
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = SELF::subGenerator($core_details);
$mail->Body = $msg;
$mail->AltBody = $msg;
$logger = MYLOG::logFunction(null,$core_details[0]['pd_id']);
if(!$mail->send()) {
$logger->error("Mailer Error:" ,array($mail->ErrorInfo));
} else {
$logger->info("Mailer Send:" ,array('mail_ID' => $lender_email,'Status' => 'SEND'));
}
}
public static function sendSalesPDMail($CI,$salespd_id,$city)
{
log_message('ERROR','####SALESPD MAIL CALLED'.$salespd_id);
$mail = $CI->phpmailer_library->load();
$mail_contents = SELF::salesPDMailContentGrabber($CI,$salespd_id);
$city_arg = array('869','1239','5785','1248','4307','4085','6081');
// $city_arg = array('new delhi','Noida','Ghaziabad','Gurgaon','Ludhiana','Jaipur','Faridabad');
if(count($mail_contents))
{
$mail->IsSMTP(); // Telling the class to use SMTP
$mail->SMTPAuth = true;
$mail->SMTPDebug = 0;
$mail->SMTPSecure = "ssl";
$mail->Host = 'bh-in-16.webhostbox.net'; // SMTP server
$mail->Username = "noreply@ssa.sineedge.com"; // "The account"
$mail->Password = "noreply@ssa"; // "The password"
$mail->Port = 465; // "The port"
$mail_id = 'ssa@venbainfotech.com';
if(ENVIRONMENT == 'testing' && in_array((string)$city,$city_arg)){ $mail->addBCC("venkiraj0@gmail.com");}
if(ENVIRONMENT == 'production')
{
$mail_id = 'cpa@smcfinance.com';
$mail->addBCC("cpumumbai@smcfinance.com");
$mail->addBCC("cpa@smcfinance.com");
$mail->addBCC("neville@sinemanagement.com");
$mail->addBCC("ssa@venbainfotech.com");
$mail->addBCC("aakashjadhav@smcfinance.com");
$mail->addBCC("nainajindal@smcfinance.com");
$mail->addBCC("utkarsh@smcfinance.com");
$mail->addBCC("vikashmishra@smcfinance.com");
$mail->addBCC("parmarrushang@smcfinance.com");
$mail->addAddress('cpumumbai@smcfinance.com');
if(in_array((string)$city,$city_arg)){ $mail->addBCC("satendersingh@smcfinance.com");}
// $mail->addBCC("vitvelz@gmail.com");
} // Name is optional }
$mail->addAddress($mail_id);
$mail->From = 'noreply@pdgenie.com';
$fromName = 'PD Genie'; if(ENVIRONMENT == 'testing' || ENVIRONMENT == 'development') { $fromName .= ' ( TEST ENV ) '; }
$mail->FromName = $fromName;
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $mail_contents[0];
$mail->Body = $mail_contents[2];
$mail->AltBody = $mail_contents[2];
$mail->addStringAttachment(file_get_contents($mail_contents[3]), $mail_contents[1]);
//print_r($mail);
//$logger = MYLOG::logFunction(null,$core_details[0]['pd_id']);
$try = 1;
$mail_send_status = null;
sendMailAgain:
if(!$mail->send()) {
//$logger->error("Mailer Error:" ,array($mail->ErrorInfo));
//echo 'not send';
log_message('ERROR','###SALESPD MAIL NOT SEND'.$mail_contents[1].'- mail Error - '.$mail->ErrorInfo);
if($try == 4)
{
goto stopSendAttempt;
}
$try++;
log_message('ERROR','###SALESPD MAIL attempt'.$try.' '.$mail_contents[1].'- mail Error - '.$mail->ErrorInfo);
goto sendMailAgain;
} else {
//$logger->info("Mailer Send:" ,array('mail_ID' => $lender_email,'Status' => 'SEND'));
//echo 'DONE';
//echo 'send';
$mail_send_status = 'Sent';
log_message('ERROR','####SALESPD MAIL SEND'.$mail_contents[1]);
}
stopSendAttempt:
//update mail sent status to sales pd master
SELF::updateSalesPDmailStatus($CI,$salespd_id,$mail_send_status);
}
}
public static function salesPDMailContentGrabber($CI,$sales_pd_id)
{
log_message('ERROR','####SALESPD MAIL CONTENT GRABBER CALLED'.$sales_pd_id);
$columns = array('SALES_PD_DATA.*','ENTITY.short_name','PRODUCT.abbr');
$table = SALES_PD_DATA.' as SALES_PD_DATA';
$joins = array(
array('table' => ENTITY. ' as ENTITY',
'condition' =>'SALES_PD_DATA.lender_id = ENTITY.entity_id',
'jointype' => 'INNER'),
array('table' => PRODUCTS. ' as PRODUCT',
'condition' =>'SALES_PD_DATA.product_id = PRODUCT.product_id',
'jointype' => 'INNER')
);
$where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $sales_pd_id);
$sales_pd_data = $CI->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array);
if(count($sales_pd_data))
{
$pd_type = "";
if($sales_pd_data[0]['sales_pd_type'] == 1){$pd_type = "Physical PD-"; }else if($sales_pd_data[0]['sales_pd_type'] == 2){$pd_type = "Tele PD-";}
$mail_subject = "Sales PD Report for ";
$pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name']));
$pdf_name .= '-'.$pd_type.$sales_pd_data[0]['abbr'];
$pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date'])));
$mail_subject .=$pdf_name;
$file_name = $pdf_name.'.pdf';
$content = "Dear Team<br><br>Please find enclosed the sales PD report." ;
$key = 'sales_pd/'.$sales_pd_id.'/'.$pdf_name.'.pdf';
## NEW KEY BECAUSE TITLE-RENAME
$_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI((LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id']),$key,'+5 minutes');
$headers = @get_headers($_uri);
if($headers && strpos( $headers[0], '200')) {
$singed_uri = $_uri;
}else {
$old_pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name']));
$old_pdf_name .= '-'.$sales_pd_data[0]['abbr'];
$old_pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date'])));
$old_key = 'sales_pd/'.$sales_pd_id.'/'.$old_pdf_name.'.pdf';
$file_name = $old_pdf_name.'.pdf';
$singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI((LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id']),$old_key,'+5 minutes');;
}
//echo $singed_uri;
return array($mail_subject,$file_name,$content,$singed_uri);
}
}
public static function subGenerator($core_details)
{
$status = $core_details[0]['pd_status'];
$dynamic = '';
switch($status)
{
case 'TRIGGERED':
$dynamic = 'Triggered';
break;
case 'ACCEPTED':$dynamic = 'Accepted';
break;
case 'BOUNCED':$dynamic = 'Bounced';
break;
case 'ALLOCATED':$dynamic = 'Allocated';
break;
case 'SCHEDULED':$dynamic = 'Scheduled';
break;
case 'STARTED':$dynamic = 'Started';
break;
case 'COMPLETED':$dynamic = 'Completed';
break;
case 'QC_COMPLETED':$dynamic = 'QC Completed';
break;
case 'CANCELLED':$dynamic = 'Cancelled';
break;
default: $dynamic = 'Status Update';
}
$subject = 'PD '.$dynamic .' For Application ID -'.$core_details[0]['lender_applicant_id'];
return ENVIRONMENT == 'testing' || ENVIRONMENT == 'development' ? $subject .= ' ( TEST ENV ) ' : $subject;
}
public static function updateSalesPDmailStatus($CI,$salespd_id,$mail_send_status)
{
//echo 'UPDAT called';
$d = $CI->Sales_PD_Model->updateRecords(array('mail_status' => $mail_send_status),SALES_PD_DATA,array('sales_pd_id' => $salespd_id) );
//print_r($CI->db->last_query);
//echo $d;
}
public static function sendMWcreditPDMail($CI,$arr,$flag)
{
$pd_id = $arr['pd_id'];
$RCM_or_CM = $arr['fk_updatedby'];
log_message('ERROR','#### MW AGENCY-MAIL CALLED'.$pd_id);
if($pd_id != "" || $pd_id != null)
{
// $CI->db->SELECT("PDTRIGGER.pd_id,PDTRIGGER.pd_sno,ENTITY.short_name,PRODUCT.abbr,'concat(USERPROFILE.first_name,' ',USERPROFILE.last_name)' as officer_name,AGENCYLIST.agency_name,USERPROFILE.vendor_status,AGENCYLIST.mail_id,USERPROFILE.email");
// $CI->db->SELECT("PDTRIGGER.pd_id,PDTRIGGER.pd_sno,concat(USERPROFILE.first_name,'',USERPROFILE.last_name) as officer_name,AGENCYLIST.agency_name,PDTRIGGER.vendor_status,AGENCYLIST.mail_id,USERPROFILE.email");
// $CI->db->FROM(PDTRIGGER.' as PDTRIGGER');
// $CI->db->JOIN(AGENCYLIST. ' as AGENCYLIST','PDTRIGGER.pd_agency_id = AGENCYLIST.agency_id');
// $CI->db->JOIN(USERPROFILE. ' as USERPROFILE','PDTRIGGER.fk_pd_allocated_to = USERPROFILE.userid');
// $CI->db->WHERE('PDTRIGGER.pd_id',$pd_id);
// $pd_data = $CI->db->GET()->result_array();
$CI->db->SELECT("PDTRIGGER.pd_id,PDTRIGGER.pd_sno,PDTRIGGER.fk_lender_id,ENTITY.short_name,
PDTRIGGER.scheduled_on,PDTRIGGER.pd_date_of_initiation,PDTRIGGER.updatedon,PDTRIGGER.encrypted_url,
PDTRIGGER.lender_applicant_id,PDTRIGGER.fk_pd_type,PDTRIGGER.pd_status,PDTRIGGER.vendor_status,
PDTRIGGER.pd_contact_mobileno,PDTRIGGER.loan_amount,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDAPPLICANTSDETAILS.company_name,
PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PINCODE.pincode,PDTRIGGER.pincode as pincode_id,
PDTRIGGER.fk_pd_allocated_to,ALLOCATED.email as allocated_email,PDAPPLICANTSDETAILS.applicant_name,PDAPPLICANTSDETAILS.mobile_no,
concat(ALLOCATED.first_name,' ',ALLOCATED.last_name) as pdofficer_name,PDTRIGGER.excel_file_id,
PDTRIGGER.pd_agency_id,AGENCYLIST.agency_name,AGENCYLIST.mail_id as agency_mail");
$CI->db->FROM(PDTRIGGER." as PDTRIGGER");
$CI->db->JOIN(ENTITY." as ENTITY","PDTRIGGER.fk_lender_id = ENTITY.entity_id",'LEFT');
$CI->db->JOIN(AGENCYLIST. ' as AGENCYLIST','PDTRIGGER.pd_agency_id = AGENCYLIST.agency_id','LEFT');
$CI->db->JOIN(USERPROFILE." as ALLOCATED","PDTRIGGER.fk_pd_allocated_to = ALLOCATED.userid",'LEFT');
$CI->db->JOIN(PDAPPLICANTSDETAILS." as PDAPPLICANTSDETAILS","PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1",'LEFT');
$CI->db->JOIN(STATE.' as STATE','PDTRIGGER.fk_state = STATE.state_id ','LEFT');
$CI->db->JOIN(CITY.' as CITY','PDTRIGGER.fk_city = CITY.city_id','LEFT');
$CI->db->JOIN(PINCODE.' as PINCODE','PDTRIGGER.pincode = PINCODE.pincode_id','LEFT');
$CI->db->WHERE("PDTRIGGER.pd_id",$pd_id);
$core_details = $CI->db->GET()->result_array();
// print_r($core_details);die();
$CI->db->SELECT("USERPROFILE.email");
$CI->db->FROM(USERPROFILE." as USERPROFILE");
$CI->db->JOIN(USERPROFILEROLES." as USERPROFILEROLES", "USERPROFILEROLES.isactive = 1 and USERPROFILEROLES.fk_userid = USERPROFILE.userid");
$CI->db->WHERE("USERPROFILE.userid",$RCM_or_CM);
$CI->db->WHERE_IN("USERPROFILEROLES.user_role",[26,27]);
$get_details = $CI->db->GET()->result_array();
$rcm_mail_id = (count($get_details)>0) ? $get_details[0]['email'] : "";
$CI->db->SELECT('COMMONMASTER.log_id, COMMONMASTER.primary_key as pd_id, COMMONMASTER.old_value, COMMONMASTER.new_value, COMMONMASTER.fk_createdby, DATE_FORMAT(COMMONMASTER.createdon,"%D %b %Y at %h:%i:%s %p") as createdon,COMMONMASTER.createdon raw_date_createdon,concat(USERPROFILE.first_name," ",IFNULL(USERPROFILE.last_name,"")) as createdby');
$CI->db->FROM(COMMONMASTER.' as COMMONMASTER');
$CI->db->JOIN(USERPROFILE.' as USERPROFILE','COMMONMASTER.fk_createdby = USERPROFILE.userid','LEFT');
$CI->db->WHERE('COMMONMASTER.table_name="'.PDTRIGGER.'" AND COMMONMASTER.primary_key=',$pd_id);
$CI->db->WHERE('COMMONMASTER.new_value ="'.ALLOCATED_TO_FIA.'"');
$CI->db->ORDER_BY('COMMONMASTER.log_id','desc');
$logs = $CI->db->GET()->result_array();
$case_initiated_by = count($logs) > 0 ? $logs[0]['createdby'] : "-";
if(count($core_details)){
$msg = "" ; $subject = "" ;
if($flag == 2){ // Mail Content For - RCM and CM ONLY.
if(ENVIRONMENT == 'production' && (((int)$RCM_or_CM) == 205)){
//Note : SMC SSA_supportcreditpd users means this mail hardcoded for temp-purpose only
$mail_id = "vishant@sinemanagement.com";
}
else{
$mail_id = $rcm_mail_id;
}
log_message('ERROR','#### MW AGENCY-MAIL CALLED TYPE 2(RCM and CM) PD ID :'.$pd_id." and MAIL : ".$mail_id);
$msg = "PD for Loan Application ID-".$core_details[0]['lender_applicant_id']." ".$core_details[0]['applicant_name']." have been triggered to the vendor. ";
$subject = "PD allocated to vendor for application ID - ".$core_details[0]['lender_applicant_id']." ".$core_details[0]['applicant_name'];
$ref_str = "vendor email id";
}
if($flag == 1){ // Mail Content For - Agency ONLY
$mail_id = $core_details[0]['agency_mail'];
log_message('ERROR','#### MW AGENCY-MAIL CALLED TYPE 1(AGENCY) PD ID :'.$pd_id." and MAIL : ".$mail_id);
$msg = "PD for Loan Application ID - ".$core_details[0]['lender_applicant_id']." ".$core_details[0]['applicant_name']." have been allocated to you. ";
$subject = "PD allocated for application ID - ".$core_details[0]['lender_applicant_id']." ".$core_details[0]['applicant_name'];
$ref_str = "client email id";
}
if($flag == 3){ // Mail Conent For - Allocated Person ONLY
// $mail_id = $core_details[0]['allocated_email'];
log_message('ERROR','#### MW-AGENCY MAIL CALLED TYPE 3(Normal Allocated Person) PD ID : '.$pd_id." and MAIL : ".$mail_id);
$CI->db->SELECT("*");
$CI->db->FROM(PDNOTIFICATIONMSG." as PDNOTIFICATIONMSG");
$CI->db->WHERE("PDNOTIFICATIONMSG.pd_status",ALLOCATED);
$CI->db->WHERE("PDNOTIFICATIONMSG.isactive",1);
$pd_notification_msg = $CI->db->GET()->result_array();
$msg = $pd_notification_msg[0]['lender'];
$msg = self::stringReplace($msg,$core_details,'MAIL');
$subject = "PD allocated for application ID - ".$core_details[0]['lender_applicant_id']." ".$core_details[0]['applicant_name'];
$ref_str = "";
// $mail_id = "sanjeev.p@venbaingotech.com";
// $mail->addBCC("sanjeev.p@venbainfotech.com");
}
// if(!empty($core_details[0]['excel_file_id']) && $core_details[0]['excel_file_id'] != null){
$CI->db->SELECT("PDAPPLICANTSDETAILS.applicant_name,PDAPPLICANTSDETAILS.mobile_no");
$CI->db->FROM(PDAPPLICANTSDETAILS." as PDAPPLICANTSDETAILS");
$CI->db->WHERE("PDAPPLICANTSDETAILS.fk_pd_id",$pd_id);
$applicatant_details = $CI->db->GET()->result_array();
// $company_name = $applicatant_details[0]['applicant_name'] ? $applicatant_details[0]['applicant_name'] : "-";
// $applicant_name = $applicatant_details[1]['applicant_name'] ? $applicatant_details[1]['applicant_name'] : "-";
if(count($applicatant_details) > 0 ){
$company_name = $applicatant_details[0]['applicant_name'] ? $applicatant_details[0]['applicant_name'] : "-";
unset($applicatant_details[0]);
Sort($applicatant_details);
$name = array_column($applicatant_details, 'applicant_name');
$applicant_name = (count($name)>0) ? implode(', ', $name) : "-";
}else{
$company_name = "-";
$applicant_name = "-";
}
// }else{
// $company_name = $core_details[0]['company_name'] ? $core_details[0]['company_name'] : "-";
// $applicant_name = $core_details[0]['applicant_name'] ? $core_details[0]['applicant_name'] : "-";
// }
// $company_name = $core_details[0]['company_name'] ? $core_details[0]['company_name'] : "-";
$msg .= "<br><br> 1. Name of the firm : ".$company_name
."<br> 2. Address : ".$core_details[0]['addressline1'].",".$core_details[0]['city_name'].",".$core_details[0]['state_name']."-".$core_details[0]['pincode']."."
."<br> 3. Loan Amount : ".$core_details[0]['loan_amount']
."<br> 4. Name of the loan applicant : ".$applicant_name
."<br> 5. Contact Number : ".$core_details[0]['mobile_no']
."<br> 6. Case initiated by : ".$case_initiated_by
."<br> 7. Case allocated to : ".($core_details[0]['agency_name'] ? $core_details[0]['agency_name'] : ($core_details[0]['pdofficer_name'] ? $core_details[0]['pdofficer_name'] : "-"));
if(!empty($ref_str)){
$msg .= "<br><br><br> This is an automatically generated notification mail. Please contact on ".$ref_str." for any
queries/update. ";
if(!empty($mail_id)){
$arg = array('mail'=>$mail_id,'pd_id'=>$pd_id,'msg'=>$msg,'subject'=>$subject);
SELF::send_smcagencymail($CI,$arg);
}else{
log_message('ERROR','#### MW AGENCY-MAIL NOT CALLED - NO Email');
}
}
}else{
// log_message('INFO','### MWISE-CREDITPD(AGENCY) MAIL NOT SEND BCOZ '.count($core_details).' core_details');
}
}else{
// log_message('INFO','### MWISE-CREDITPD(AGENCY) MAIL NOT SEND BCOZ THERE IS NO PDID');
}
}//function closed here.
public static function send_smcagencymail($CI,$arg){
log_message('ERROR','#### MW AGENCY-MAIL CONTENT CALLED');
$mail = $CI->phpmailer_library->load();
$mail->IsSMTP(); // Telling the class to use SMTP
$mail->SMTPAuth = true;
$mail->SMTPDebug = 0;
$mail->SMTPSecure = "ssl";
$mail->Host = 'bh-in-16.webhostbox.net'; // SMTP server
$mail->Username = "noreply@ssa.sineedge.com"; // "The account"
$mail->Password = "noreply@ssa"; // "The password"
$mail->Port = 465; // "The port"
$mail->From = 'noreply@pdgenie.com';
$fromName = 'PD Genie';
$mail->addAddress($arg["mail"]);
$subject = $arg["subject"];
if(ENVIRONMENT == 'testing' || ENVIRONMENT == 'development') {
$fromName .= ' ( TEST ENV- check ) ';
$subject .= ' ( TEST ENV- check ) ';
}
$mail->FromName = $fromName;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = 'Dear Team ,<br><br> '.$arg["msg"];
$mail->AltBody = $arg["msg"];
$mail->addBCC($arg["mail"]);
if(!$mail->send()) {
// $logger->error("Mailer Error:" ,array($mail->ErrorInfo));
log_message('ERROR','#### MW AGENCY-MAIL NOT SEND '.$arg["pd_id"].' - ERR - '.$mail->ErrorInfo);
}
else{
log_message('ERROR','#### MW AGENCY-MAIL SENDED SUCESSFULLY'.$arg["subject"]);
}
$mail->SmtpClose();
}
public static function sendNotificationToOfficers($records)
{
log_message('ERROR','send Notification To Officers in pd alert');
$users = $records['user_id']; // alluser,multiuser,particularuser
$msg = $records['msg']; // msg
$CI =&get_instance();
$CI->load->helper('push_notification');
// notification_token_id, fk_user_id, web_token, mob_token, createdon, updatedon
$CI->db->SELECT("USERNOTIFICATIONTOKENS.notification_token_id,USERNOTIFICATIONTOKENS.fk_user_id,USERNOTIFICATIONTOKENS.mob_token,concat(USERPROFILE.first_name,' ',USERPROFILE.last_name) as pdofficer_name");
$CI->db->FROM(USERNOTIFICATIONTOKENS." as USERNOTIFICATIONTOKENS");
$CI->db->JOIN(USERPROFILEROLES.' as USERPROFILEROLES','USERPROFILEROLES.fk_userid = USERNOTIFICATIONTOKENS.fk_user_id and USERPROFILEROLES.isactive = 1');
$CI->db->JOIN(USERPROFILE." as USERPROFILE","USERNOTIFICATIONTOKENS.fk_user_id = USERPROFILE.userid",'LEFT');
// $CI->db->WHERE('ROLES.role_id',2);
if(is_array($users) && count($users)){
if($users[0] != 0){
$CI->db->WHERE_IN('USERNOTIFICATIONTOKENS.fk_user_id ',$users);
}else{
$CI->db->WHERE_IN("USERPROFILEROLES.user_role",[5]);//pd officer roles only
// $CI->db->WHERE_IN("USERPROFILEROLES.user_role",[2,5,22]);
}
}
$CI->db->WHERE('USERNOTIFICATIONTOKENS.mob_token != ""');
$notification_details = $CI->db->GET()->result_array();
log_message('ERROR',"send Notification To Officers Records : ".json_encode($notification_details));
// print_r($CI->db->last_query());die();
// print_r($notification_details);die();
$additional_data_for_logs['to_whom'] = 'PDOFFICERS';
$web_token = "";
// $officers_name = array();
$officers_name['total_count'] = count($notification_details);
$officers_name['officers'] = array();
for($i=0;$i<count($notification_details);$i++){
$mob_token = $notification_details[$i]['mob_token'] ;
PUSH_NOTIFICATION::sendNotification($web_token,$mob_token,$msg,$additional_data_for_logs);
array_push($officers_name['officers'],$notification_details[$i]['pdofficer_name']);
}
log_message('ERROR',"Notification sended Officers List : ".json_encode($officers_name));
return $officers_name;
}
}
?>