287 lines
11 KiB
PHP
287 lines
11 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)
|
|
{
|
|
if($pdid != "" || $pdid != null)
|
|
{
|
|
|
|
$CI =&get_instance();
|
|
$CI->load->library('AWS_SNS');
|
|
//$CI->load->library('Phpmailer_library');
|
|
$pd_notification_configs = array();
|
|
//die();
|
|
|
|
/*********************************************/
|
|
/*******Get PD Master Details*****************/
|
|
/*********************************************/
|
|
$CI->db->SELECT("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,");
|
|
$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(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(PDAPPLICANTSDETAILS." as PDAPPLICANTSDETAILS","PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1",'LEFT');
|
|
$CI->db->WHERE("PDTRIGGER.pd_id",$pdid);
|
|
$core_details = $CI->db->GET()->result_array();
|
|
//print_r($core_details);
|
|
|
|
|
|
|
|
if(count($core_details))
|
|
{
|
|
|
|
/*********************************************/
|
|
/*******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 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)
|
|
{
|
|
$lender_sms = (string)$core_details[0]['pd_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);
|
|
$CI->aws_sns->sendSMS($msg,$lender_sms);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*********************************************/
|
|
/*******Send Mail Notification to Lender*****/
|
|
/*********************************************/
|
|
if($pd_notification_configs[0]['mail_lender'] == 1)
|
|
{
|
|
$lender_email = null;
|
|
|
|
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'];
|
|
}
|
|
|
|
|
|
if($lender_email != null)
|
|
{
|
|
$msg = $pd_notification_msg[0]['lender'];
|
|
$msg = self::stringReplace($msg,$core_details);
|
|
self::sendMail($CI,$lender_email,$msg,$core_details);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*********************************************/
|
|
/*******Send SMS Notification to PD Officer*****/
|
|
/*********************************************/
|
|
if($pd_notification_configs[0]['sms_pdofficer'] == 1)
|
|
{
|
|
$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);
|
|
foreach($mobile_nos_to_send_notification as $mobile){ $CI->aws_sns->sendSMS($msg,(string)$mobile); };
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/*********************************************/
|
|
/*******Send SMS Notification to Customer*****/
|
|
/*********************************************/
|
|
if($pd_notification_configs[0]['sms_customer'] == 1)
|
|
{
|
|
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);
|
|
$CI->aws_sns->sendSMS($msg,(string)$core_details[0]['customer_mobile_no']);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*********************************************/
|
|
/**Send SMS Notification to Central PD Officer**/
|
|
/*********************************************/
|
|
if($pd_notification_configs[0]['sms_pdincharge'] == 1)
|
|
{
|
|
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);
|
|
$CI->aws_sns->sendSMS($msg,(string)$core_details[0]['centralpdofficer_mobile_no']);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*********************************************/
|
|
/**Send SMS Notification to QC Team*****/
|
|
/*********************************************/
|
|
if($pd_notification_configs[0]['sms_qcteam'] == 1)
|
|
{
|
|
$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);
|
|
|
|
foreach($mobile_nos_to_send_notification as $mobile){
|
|
$CI->aws_sns->sendSMS($msg,(string)$mobile['mobile_no']);
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*********************************************/
|
|
/**REPLACE PLACEHOLDERS****/
|
|
/*********************************************/
|
|
public static function stringReplace($msg,$core_details)
|
|
{
|
|
|
|
$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 = str_replace('\n','<br>',$msg);
|
|
$msg = str_replace('\\',' ',$msg);
|
|
$msg = nl2br($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 = 3;
|
|
$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('velmurugan.s@venbainfotech.com'); // Name is optional
|
|
$mail->From = 'noreply@ssa.sineedge.com';
|
|
$mail->FromName = 'SineEdge QC Team';
|
|
$mail->isHTML(true); // Set email format to HTML
|
|
$mail->Subject = 'PD Report For Application ID -'.$core_details[0]['lender_applicant_id'];
|
|
$mail->Body = $msg;
|
|
$mail->AltBody = $msg;
|
|
|
|
if(!$mail->send()) {
|
|
//echo 'Message could not be sent.';
|
|
//echo 'Mailer Error: ' . $mail->ErrorInfo;
|
|
} else {
|
|
//echo 'Message has been sent';
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|