FIX_CustomerGroup_bug_fix
This commit is contained in:
parent
afb7349ec7
commit
f2898721b3
5
.env
5
.env
@ -183,3 +183,8 @@ SMTP_HOST = 'smtp.sendgrid.net'
|
||||
SMTP_USER = 'apikey'
|
||||
SMTP_PASS = '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'
|
||||
SMTP_PORT = '587'
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# New Whatsapp Access Token
|
||||
#----------------------------------------------------------------------
|
||||
# whatsAppToken = 'EAARGyzEtu2kBO1mK3ILZAvZCd8D3QNpHo2uU5SWZBXbZC3eNL9hFpZA5WebolazilZA0RfU0zdu6gNZAW1yGCYiXFgZBC1YQfZBErv0QKAYQAT9wMOTy2f0C3m4ZAK8ZCwt3mGlURfa6m2uUCyNK4qEUy2Evx7scd8aanXLFr8MJUbVNJP8BPPSpUJW4A0dZAaci56lrPGnw0hV7jV9ISGmDLNYZD';
|
||||
@ -171,6 +171,7 @@ $routes->post("campaign_creation_insert", "Notifications::campaign_creation_inse
|
||||
|
||||
# Auto run process routes
|
||||
$routes->get('process_scheduled_notifications/', 'Notifications::processScheduledNotifications');
|
||||
$routes->get('process_customergroup_notifications/(:any)/(:any)', 'Notifications::customer_group_notification/$1/$2');
|
||||
$routes->get('acknowlegdement', 'Notifications::noifications_acknowlegdement');
|
||||
$routes->get('subscription_inactive', 'Invoice::subscription_inactive');
|
||||
|
||||
|
||||
@ -300,16 +300,20 @@ class Customer extends BaseController
|
||||
}
|
||||
public function view_customer_group($id){
|
||||
helper('session');
|
||||
$model = new CustomerModel();
|
||||
$session_bid = get_business_id();
|
||||
|
||||
$data['type_values'] = $model->getType();
|
||||
$data['mode_values'] = $model->getMode();
|
||||
$data['category_values'] = $model->getCategory();
|
||||
|
||||
$data['field'] = [
|
||||
['value'=>'','fieldflag'=>1,'text'=> 'Choose the Field','disable' => false],
|
||||
['value'=>'C.type','fieldflag'=>1,'text'=> 'Type','disable' => false],
|
||||
['value'=>'C.type','fieldflag'=>3,'text'=> 'Type','disable' => false],
|
||||
['value'=>'CA.city','fieldflag'=>1,'text'=> 'City','disable' => false],
|
||||
// ['value'=>'CA.state','fieldflag'=>1,'text'=> 'State','disable' => false],
|
||||
['value'=>'CA.postal_code','fieldflag'=>1,'text'=> 'Postal Code','disable' => false],
|
||||
['value'=>'C.mode','fieldflag'=>3,'text'=> 'Mode','disable' => false],
|
||||
['value'=>'CM.name','fieldflag'=>1,'text'=> 'Category','disable' => false],
|
||||
['value'=>'CM.name','fieldflag'=>3,'text'=> 'Category','disable' => false],
|
||||
['value'=>'I.invoice_date','fieldflag'=>2,'text'=> 'Invoice Date','disable' => false],
|
||||
['value'=>'S.to_subscription','fieldflag'=>2,'text'=> 'Expiry Date','disable' => false]];
|
||||
|
||||
|
||||
@ -782,7 +782,7 @@ class Notifications extends BaseController
|
||||
$this->logger->error("Auto Scheduled Notification Started");
|
||||
$model = new NotificationModel();
|
||||
#step 1 get scheduled notification details
|
||||
$notification_campaign_result = $this->getScheduledNotificationDetails();
|
||||
$notification_campaign_result = $this->getScheduledNotificationDetails(0,0);
|
||||
$this->logger->error("Auto Scheduled Campaign Details Count = ".count($notification_campaign_result));
|
||||
if(!count($notification_campaign_result))
|
||||
{
|
||||
@ -902,12 +902,18 @@ class Notifications extends BaseController
|
||||
}
|
||||
|
||||
#step 1 get scheduled notification details
|
||||
function getScheduledNotificationDetails()
|
||||
function getScheduledNotificationDetails($tid,$cid)
|
||||
{
|
||||
$model = new NotificationModel();
|
||||
$templateIds = [1, 2];
|
||||
$model->setTable('notification_campaign');
|
||||
$notification_campaign_result = $model->whereIn('template_id', $templateIds)->where('isactive', 1)->findAll();
|
||||
if($tid == 0&&$cid == 0){
|
||||
$templateIds = [1, 2];
|
||||
$model->setTable('notification_campaign');
|
||||
$notification_campaign_result = $model->whereIn('template_id', $templateIds)->where('isactive', 1)->findAll();
|
||||
}else{
|
||||
$templateIds = [$tid];
|
||||
$model->setTable('notification_campaign');
|
||||
$notification_campaign_result = $model->whereIn('template_id', $templateIds)->where(['isactive'=>1,'campaign_id'=>$cid])->findAll();
|
||||
}
|
||||
|
||||
// $today = date('Y-m-d');
|
||||
// $currentTime = date('H:i:s');
|
||||
@ -923,7 +929,6 @@ class Notifications extends BaseController
|
||||
return $notification_campaign_result;
|
||||
}
|
||||
|
||||
|
||||
#step 2 get template details
|
||||
function getTemplateDetails($template_id)
|
||||
{
|
||||
@ -972,6 +977,7 @@ class Notifications extends BaseController
|
||||
$notificationContent = str_replace("{USER_NAME}", $dataPointsArray["customer_name"], $notificationContent);
|
||||
$notificationContent = str_replace("{SCHEME_NAME}", $dataPointsArray["scheme_name"], $notificationContent);
|
||||
$notificationContent = str_replace("{EXPIRY_DATE}", $dataPointsArray["formatted_due_date"], $notificationContent);
|
||||
$notificationContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' . $dataPointsArray["customer_id"], $notificationContent);
|
||||
return $notificationContent;
|
||||
}
|
||||
############## Auto Scheduled Notification Ends ################
|
||||
@ -987,6 +993,119 @@ class Notifications extends BaseController
|
||||
$this->render_page('noifications_acknowlegdement', $data);
|
||||
}
|
||||
############## Notification Acknowlegdement Ends ################
|
||||
public function customer_group_notification($tid,$cid){
|
||||
$this->logger->error("Customer Group Notification Started");
|
||||
|
||||
$this->logger->error("Customer Group Notification Ended");
|
||||
$model = new NotificationModel();
|
||||
#step 1 get scheduled notification details
|
||||
$notification_campaign_result = $this->getScheduledNotificationDetails($tid,$cid);
|
||||
// print_r($notification_campaign_result);
|
||||
//looping multiple notification campaign
|
||||
if(count($notification_campaign_result))
|
||||
{
|
||||
foreach($notification_campaign_result as $index => $single_campaign)
|
||||
{
|
||||
echo "Notification Campaign Name = ".$single_campaign['campaign_name']."<br>";
|
||||
#step 2 get template details
|
||||
$template = $this->getTemplateDetails($single_campaign['template_id']);
|
||||
$customer_details = $this->getCustomerDetails($single_campaign['group_id']);
|
||||
if(count($template) && count($customer_details))
|
||||
{
|
||||
#step 3 execute the customer group query and return customer details
|
||||
$sent_customer_details = [];
|
||||
if(count($customer_details))
|
||||
{
|
||||
#step 2.1
|
||||
$history_parents_data = ['campaign_id' => $single_campaign['campaign_id'],'status' => 0];
|
||||
$history_parent_id = $model->save_notification_history_parents($history_parents_data);
|
||||
$single_campaign['history_parent_id'] = $history_parent_id;
|
||||
|
||||
foreach($customer_details as $customer)
|
||||
{
|
||||
$customer['customer_name'] = isset($customer['customer_name'])
|
||||
? $customer['customer_name']
|
||||
: (isset($customer['first_name']) && isset($customer['last_name'])
|
||||
? $customer['first_name'] . ' ' . $customer['last_name']
|
||||
: '');
|
||||
$customer['scheme_name'] = isset($customer['scheme_name']) ? $customer['scheme_name'] : (isset($customer['title']) ? $customer['title'] : "");
|
||||
$formatted_due_date = "";
|
||||
|
||||
if(isset($customer['to_subscription'])){
|
||||
$dateObj = date_create($customer['to_subscription']);
|
||||
$formatted_due_date = date_format($dateObj, 'd-m-Y');
|
||||
}else{
|
||||
$formatted_due_date = $customer['formatted_due_date'];
|
||||
}
|
||||
$customer['formatted_due_date'] = $formatted_due_date;
|
||||
|
||||
|
||||
#step 4 replace templates palceholders with data points
|
||||
$notificationContent = $this->replaceTemplateWithDataPoints($template['message'],$customer);
|
||||
$history_child_data = [
|
||||
'fkid' => $single_campaign['history_parent_id'],
|
||||
'customer_id' => $customer['customer_id'],
|
||||
'receiving_entity' => $single_campaign['mode'] == 'Email' ? $customer['email'] : $customer['mobile_no'],
|
||||
'receiving_status' => 0,
|
||||
'message' => $notificationContent];
|
||||
$history_child_id = $model->save_notification_history_child($history_child_data);
|
||||
if(!in_array($customer['customer_id'],$sent_customer_details))
|
||||
{
|
||||
$this->logger->error("Auto Scheduled Customer CID = ".$customer['customer_id'].", CN = ".$customer['customer_name']);
|
||||
#step 5 send notification
|
||||
$notification = new NotificationHelper();
|
||||
if($single_campaign['mode'] == 'Email')
|
||||
{
|
||||
$email_response = $notification->sendEmail(array('recipient_email' => $customer['email'],'subject' => $template['subject'],'template_name' => $template['template_name'],'description' => $notificationContent));
|
||||
$mail_log = isset($email_response['success']) ? 'Email sent successfully' : 'Failed to send email';
|
||||
$receiving_status = isset($email_response['success']) ? 1 : 0;
|
||||
$this->logger->error("Auto Scheduled Email CID = ".$customer['customer_id']." ".$mail_log);
|
||||
|
||||
$history_child_where = ['fkid' => $single_campaign['history_parent_id'],'id' => (int)$history_child_id];
|
||||
$history_child_updatedata = ['receiving_status'=>$receiving_status, 'result'=>isset($email_response['success']) ? $mail_log : (strtolower(gettype($email_response)) == "string" ? $email_response : json_encode($email_response)) ];
|
||||
$history_child_statement = $model->update_notification_history_child($history_child_updatedata,$history_child_where);
|
||||
$this->logger->error($history_child_statement);
|
||||
|
||||
}
|
||||
if($single_campaign['mode'] == 'Whatsapp')
|
||||
{
|
||||
$params = (object) Null;
|
||||
$url = SEND_WAAI_URL;
|
||||
$params->type = "text";
|
||||
$params->instance_id = $_ENV['WAAI_INSTANCE'];
|
||||
$params->access_token = $_ENV['WAAI_TOKEN'];
|
||||
$params->message = strip_tags(ltrim($notificationContent));
|
||||
$params->number = (int)'91' . $customer['mobile_no'];
|
||||
$whatsapp_reponse = $notification->sendWhatsAppMessage($url, "POST", $params);
|
||||
$whatsapp_reponse_msg = strtolower(gettype($whatsapp_reponse)) == "string" ? $whatsapp_reponse : json_encode($whatsapp_reponse['reponse']);
|
||||
// echo "Whatsapp Response = ".$whatsapp_reponse_msg."<br>";
|
||||
$this->logger->error("Auto Scheduled Whatsapp CID = ".$customer['customer_id']." ".$whatsapp_reponse_msg);
|
||||
$history_child_where = ['fkid' => $single_campaign['history_parent_id'],'id' => (int)$history_child_id];
|
||||
|
||||
$history_child_updatedata = ['receiving_status'=>$whatsapp_reponse['receiving_status'],'result'=>$whatsapp_reponse_msg];
|
||||
$history_child_statement = $model->update_notification_history_child($history_child_updatedata,$history_child_where);
|
||||
$this->logger->error($history_child_statement);
|
||||
|
||||
}
|
||||
|
||||
array_push($sent_customer_details,$customer['customer_id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#step 6 update campaign status to 1
|
||||
$statement = $model->update_notification_campaign_status(['status' => 0],$single_campaign['campaign_id']);
|
||||
echo "Final Campaign Status = ".$statement."<br>";
|
||||
$this->logger->error($statement);
|
||||
|
||||
#step 7 update history parent status to 1
|
||||
$history_parent_statement = $model->update_notification_history_parent_status(['status' => 1],$history_parent_id,$single_campaign['campaign_id']);
|
||||
echo "Final Acknowlegdement = ".$history_parent_statement."<br>";
|
||||
$this->logger->error($history_parent_statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -258,6 +258,30 @@ public function storeCustomerAddresses($billingAddress, $shippingAddress)
|
||||
}
|
||||
return ["billing_addr_id"=>$billing_addr_id,"shipping_addr_id"=>$shipping_addr_id]; // Return true indicating successful insertion
|
||||
}
|
||||
public function getType(){
|
||||
return $this->db->table('customers as C' )
|
||||
->select('C.type as value')
|
||||
->groupBy('C.type')
|
||||
->get()
|
||||
->getResultArray();
|
||||
}
|
||||
public function getMode(){
|
||||
return $this->db->table('customers as C' )
|
||||
->select('C.mode as value')
|
||||
->where(['C.mode != ' => ''])
|
||||
->groupBy('C.mode')
|
||||
->get()
|
||||
->getResultArray();
|
||||
}
|
||||
public function getCategory(){
|
||||
return $this->db->table('category as C' )
|
||||
->select('C.name as value')
|
||||
->where(['C.name != ' => '','C.isactive' => 1])
|
||||
->groupBy('C.name')
|
||||
->get()
|
||||
->getResultArray();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@ -64,7 +64,10 @@
|
||||
<td data-order="<?= $message; ?>"><span class="<?php echo $class; ?>"><?php echo $message; ?></span></td>
|
||||
<td>
|
||||
<a href="<?= base_url()."campaign_creation_form/".$c['campaign_id']; ?>" class="edit-button" title="Click to Edit Campaign" ><i class="ri-pencil-line"></i></a>
|
||||
<?php if ($c['isactive']) { ?> <a href="<?= base_url() . "campaign_creation_delete/".$c['campaign_id']; ?>" class="delete-button" title="Click to Delete Campaign" ><i class="ri-delete-bin-line"></i></a> <?php } ?>
|
||||
<?php if ($c['isactive']) { ?>
|
||||
<a href="<?= base_url() . "campaign_creation_delete/".$c['campaign_id']; ?>" class="delete-button" title="Click to Delete Campaign" ><i class="ri-delete-bin-line"></i></a>
|
||||
<a href="<?= base_url()."process_customergroup_notifications/".$c['template_id']."/".$c['campaign_id']; ?>" class="send-button" title="Send Now" ><i class="ri-mail-send-fill"></i></a>
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
<?php if(!empty($customer_group) && !empty($customer_group['column'])){ for ($i = 0; $i < count($customer_group['column']); $i++) { ?>
|
||||
<tr>
|
||||
<td style="width:30%;">
|
||||
<select class="form-control" data-toggle="select2" id=<?= "column".$i; ?> name="column[]" >
|
||||
<select class="form-control" data-toggle="select2" id=<?= "column".$i; ?> name="column[]" onchange="resetWhenChange(this,<?= $i; ?>)">
|
||||
<?php foreach ($field as $f) : ?>
|
||||
<option value="<?= $f['value']; ?>"
|
||||
fieldflag="<?= $f['fieldflag']; ?>"
|
||||
@ -82,7 +82,7 @@
|
||||
<?php } }else{ ?>
|
||||
<tr>
|
||||
<td style="width:30%;">
|
||||
<select class="form-control" data-toggle="select2" id="column0" name="column[]" >
|
||||
<select class="form-control" data-toggle="select2" id="column0" name="column[]" onchange="resetWhenChange(this,0)">
|
||||
<?php foreach ($field as $f) : ?>
|
||||
<option value="<?= $f['value']; ?>"
|
||||
fieldflag="<?= $f['fieldflag']; ?>"
|
||||
@ -222,7 +222,7 @@ document.getElementById("addItem").addEventListener("click", function() {
|
||||
select2.setAttribute("data-toggle", "select2");
|
||||
select2.id = 'operator' + rowCounter; // Set a dynamic ID for the select input
|
||||
select2.onchange = function() {
|
||||
FieldChange(this, rowCounter);
|
||||
FieldChange(this,rowCounter);
|
||||
};
|
||||
|
||||
exstingColumnId = 'column'+(rowCounter-1);
|
||||
@ -474,12 +474,30 @@ document.getElementById("addItem").addEventListener("click", function() {
|
||||
$("#string_flag").val("save");
|
||||
});
|
||||
|
||||
|
||||
function resetWhenChange(element, index) {
|
||||
// Reset the operator dropdown to the first option
|
||||
$('#operator' + index).val($('#operator' + index + ' option:first').val()).trigger('change');
|
||||
|
||||
// Find the values input and reset its parent element's HTML
|
||||
var valuesInput = document.getElementById("values" + index);
|
||||
if (valuesInput) {
|
||||
// Corrected selector and input ID usage
|
||||
$(valuesInput).parent().html('<input type="text" class="form-control" id="values' + index + '" name="values[]" placeholder="Enter the Values" onkeypress="return restriction(event,1)" />');
|
||||
}
|
||||
}
|
||||
function FieldChange(selectElement, rowCounter) {
|
||||
|
||||
var type_values = <?php echo json_encode($type_values); ?>;
|
||||
var mode_values = <?php echo json_encode($mode_values); ?>;
|
||||
var category_values = <?php echo json_encode($category_values); ?>;
|
||||
|
||||
var id = selectElement.id;
|
||||
var selectedOperator = selectElement.value;
|
||||
var inputId = 'values' + rowCounter;
|
||||
var column = $("#column"+rowCounter).find(':selected').attr('fieldflag');
|
||||
if (column == 2 && (selectedOperator == 'greater than' || selectedOperator == 'greater than or equal to' || selectedOperator == 'less than' || selectedOperator == 'less than or equal to')) {
|
||||
var columnValue = $("#column"+rowCounter).find(':selected').attr('value');
|
||||
if (column == 2 && (selectedOperator === 'equal' || selectedOperator == 'not equal' || selectedOperator == 'like' || selectedOperator == 'greater than' || selectedOperator == 'greater than or equal to' || selectedOperator == 'less than' || selectedOperator == 'less than or equal to'|| selectedOperator === 'contain' || selectedOperator == 'not contain')) {
|
||||
$('#' + inputId).parent().html('<input type="date" class="form-control" id="' + inputId + '" name="values[]" placeholder="Enter the Date" />');
|
||||
}else if (column == 2 && selectedOperator === 'between') {
|
||||
var newInput = '<div style="display: inline-flex;"><input type="date" class="form-control" id="' + inputId + '1" placeholder="Enter the Start Date" onchange="concatBetween(' + rowCounter + ')" />' +
|
||||
@ -492,11 +510,22 @@ function FieldChange(selectElement, rowCounter) {
|
||||
$('#' + inputId).parent().html('<input type="text" class="form-control" id="' + inputId + '" name="values[]" placeholder="Enter the Multiple Values with comma Seprator" onkeypress="return restriction(event,2)" />');
|
||||
}else if(selectedOperator === 'is null' || selectedOperator == 'is not null') {
|
||||
$('#' + inputId).parent().html('<input type="hidden" class="form-control" id="' + inputId + '" name="values[]" placeholder="Enter the Values" value="0" />');
|
||||
}else if(column == 3 && (selectedOperator === 'equal' || selectedOperator == 'not equal' || selectedOperator == 'like' )){
|
||||
$('#' + inputId).parent().html('<select class="form-control" id="' + inputId + '" name="values[]" ><option value="">Choose the mode</option><option value="Online">Online</option><option value="Offline">Offline</option></select>');
|
||||
}else if (column == 3 && ['equal', 'not equal', 'like', 'greater than', 'greater than or equal to', 'less than', 'less than or equal to', 'contain', 'not contain'].includes(selectedOperator)) {
|
||||
$('#' + inputId).parent().html('<select class="form-control" id="' + inputId + '" name="values[]"><option value="">Choose the Values</option></select>');
|
||||
let values = [];
|
||||
if (columnValue === 'C.mode') {
|
||||
values = mode_values;
|
||||
} else if (columnValue === 'CM.name') {
|
||||
values = category_values;
|
||||
} else if (columnValue === 'C.type') {
|
||||
values = type_values;
|
||||
}
|
||||
$.each(values, function (index, item) {
|
||||
$('#' + inputId).append('<option value="' + item.value + '">' + item.value + '</option>');
|
||||
});
|
||||
}else{
|
||||
$('#' + inputId).parent().html('<input type="text" class="form-control" id="' + inputId + '" name="values[]" placeholder="Enter the Values" onkeypress="return restriction(event,1)" />');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
function concatBetween(Counter) {
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
  Please, write text here!.";
|
||||
} ?>
|
||||
</textarea>
|
||||
<span class="help-block"><small>Keywords are {USER_NAME},{SCHEME_NAME},{EXPIRY_DATE}</small></span>
|
||||
<span class="help-block"><small>Keywords are {USER_NAME},{SCHEME_NAME},{EXPIRY_DATE},{RENEWAL_LINK}</small></span>
|
||||
</div>
|
||||
|
||||
<div class="invalid-feedback"> Please provide. </div>
|
||||
@ -58,7 +58,7 @@
|
||||
else{ echo "Sample Template : \n Hello {USER_NAME}, \n\t\t Please, write text here!.";
|
||||
} ?>
|
||||
</textarea>
|
||||
<span class="help-block"><small>Keywords are {USER_NAME},{SCHEME_NAME},{EXPIRY_DATE}</small></span>
|
||||
<span class="help-block"><small>Keywords are {USER_NAME},{SCHEME_NAME},{EXPIRY_DATE},{RENEWAL_LINK}</small></span>
|
||||
</div>
|
||||
<div class="invalid-feedback"> Please provide. </div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user