diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ebfe2a84..379713d4 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -158,7 +158,7 @@ $routes->match(['get','post'],'/itemwise_report_with_payment_method','Invoice::i # Notifications Routes // $routes->get('controller/SubExpdetail/(:num)', 'YourController::SubExpdetail/$1'); -$routes->get("getExpCustomerDetail/(:num)",'Notifications::getExpCustomerDetail/$1'); +$routes->get("getExpCustomerDetail/(:any)",'Notifications::getExpCustomerDetail/$1'); $routes->get('send_whatsapp_message/', 'Notifications::send_whatsapp_message'); // $routes->post('whatsapp_custom_notifications/', 'Notifications::whatsapp_custom_notifications'); // $routes->match(['post', 'get'], 'mail_custom_notifications', 'Notifications::mail_custom_notifications'); diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index f1a24640..dbc5dbe0 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -572,11 +572,14 @@ class Notifications extends BaseController public function getExpCustomerDetail($window_time = null) { $this->update_expired_members(); - $response = "
 Hi, ";
+        $response ="
";// $response = "
 Hi, Started. 
"; # Step 1: add the days to retrive the data// $providedDate = date('Y-m-d'); - $newDate = date('Y-m-d', strtotime($providedDate . ' + ' . $window_time . ' days')); - $this->logger->error('EXPIRYDATE T-Date = '.$providedDate.', Given ' .$window_time.' Day, Calacuated Date based on Given day count = '.$newDate); + if($window_time >= 0){ + $newDate = date('Y-m-d', strtotime("$providedDate + $window_time days")); + }else{ + $newDate = date('Y-m-d', strtotime("$providedDate $window_time days")); + } # Step 2 :Get the customer detail// $NotificationModel = new NotificationModel(); @@ -596,125 +599,90 @@ class Notifications extends BaseController } $db = \Config\Database::connect(); $queryResult = $db->query($modifiedQuery)->getResultArray(); - $notification = new NotificationHelper(); if (empty($queryResult)) { $this->logger->error("There is no customer expiring on date:{$newDate}"); - $response .= " There is no customer expiring. till dated :{$newDate}"; - return; + $response .= "There is no customer expiring. Date = ".date('d/m/Y', strtotime($newDate))."
"; + return $this->response->setBody($response); } $emailTemplateName = $NotificationModel->getTempName('EXPIRY NOTIFY TEMPLATE EMAIL'); - $response .= "Started.
Customer expiring. till dated = ".date('d/m/Y', strtotime($newDate))."
There are ".count($queryResult)." persons
"; + $this->logger->error("Customer expiring. till {$newDate} There are ".count($queryResult)." persons"); + $response .= "Customer expiring list. ( Date = ".date('d/m/Y', strtotime($newDate))." )
There are ".count($queryResult)." persons
"; if(!empty($queryResult)){ usort($queryResult, function ($a, $b) { return $a['to_subscription'] <=> $b['to_subscription']; //Asc order }); } + foreach ($queryResult as $inx => $row) { $subscription_id = $row['sub_id']; $status = $row['status']; - $userFirstName = $row['first_name']; - $userLastName = $row['last_name']; - $fullName = $userFirstName . ' ' . $userLastName; + $fullName = trim($row['first_name'] . ' ' . $row['last_name']); $userMobileNumber = $row['mobile_no']; + $email = $row['email']; $schemename = $row['title']; $expirydate = $row['to_subscription']; $customerId = $row['customer_id']; - $countdays = $row['countdays']; $membership_id = $row['membership_id']; + $countdays = $row['countdays']; + if (empty($fullName)) { - $this->logger->error('There is no subcription Name'); + $this->logger->error('No subscription name found for record #' . $inx); continue; - } - $response .= ($inx+1).") #".$customerId." - Person Name : ".$fullName." ----- ( Expiry on ". date('d/m/Y', strtotime($expirydate)).")
"; - if ($status === 'Approved') { - # EXPIRY NOTIFY TEMPLATE EMAIL - $emailTemplateName = $NotificationModel->getTempName('EXPIRY NOTIFY TEMPLATE EMAIL'); - if(empty($row['email'])){ - $response .= ($inx+1).") Email Not Available
"; - continue; - } + } - $existingcheck = $NotificationModel->checkEmailAlreadyExisting($row['email'],$customerId); - $check_existing = 0; - $check_date = ""; - $check_diff_days = ""; + $response .= ($inx + 1) . ") #{$customerId} - Person Name = {$fullName} / {$membership_id} --- (Expiry on " . date('d/m/Y', strtotime($expirydate)) . ")
"; + + // Skip records with non-approved status + if ($status !== 'Approved') { + $response .= ($inx + 1) . ") Status = {$status}
"; + $this->logger->error("Record #{$inx}: status is not Approved"); + continue; + } + + // Email Notification + $emailTemplateName = $NotificationModel->getTempName('EXPIRY NOTIFY TEMPLATE EMAIL'); - if(!empty($existingcheck)){ - - foreach ($existingcheck as $i => $r) { - if($r['receiving_status'] == 1){ - $check_existing = 1; - $check_date = $r['sent_time']; - $sentTimestamp = strtotime($r['sent_time']); - $provedTimestamp = strtotime($providedDate); - - - $diffInSeconds = abs($provedTimestamp - $sentTimestamp); - $diffInDays = $diffInSeconds / (60 * 60 * 24); - - $check_diff_days = $diffInDays; - } - } - } - - if($check_existing){ - $response .= ($inx+1).") Email already send on - ".date('d/m/Y h:i A', strtotime($check_date))."
"; - continue; - } - - if (count($emailTemplateName) && !empty($emailTemplateName)) { + if (!empty($emailTemplateName)) { + $existingEmailCheck = $NotificationModel->checkAlreadyExistingInHistory($email, $customerId, $subscription_id); + if (empty($existingEmailCheck)) { $campaign_id = 1; # Insertion on History Email Means Campaign ID 1 Hardcoded $history_parents_data = ['campaign_id' => $campaign_id,'status' => 0]; $history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data); - # Step 4: Prepare email content based on the template $emailContent = $emailTemplateName[0]['message']; - if (isset($fullName)) { - $emailContent = str_replace("{USER_NAME}", $fullName, $emailContent); - } - if (isset($schemename)) { - $emailContent = str_replace("{SCHEME_NAME}", $schemename, $emailContent); - } - if (isset($expirydate)) { - $expiryon = $expirydate ? date('d-m-Y', strtotime($expirydate)) : ''; - $emailContent = str_replace("{EXPIRY_DATE}", $expiryon, $emailContent); - $replaceContent = (int)$countdays == 0 ? 'expires today, ' : 'expiring on '; - $emailContent = str_replace("expiring on", $replaceContent, $emailContent); - } - if (isset($membership_id)) { - $link = base_url() . 'subscription_renewal/' . $membership_id; - $emailContent = str_replace("{RENEWAL_LINK}", ''.$link.'', $emailContent); - } - - - + $emailContent = str_replace( + ['{USER_NAME}', '{SCHEME_NAME}', '{EXPIRY_DATE}', '{RENEWAL_LINK}'], + [ + $fullName, + $schemename, + date('d-m-Y', strtotime($expirydate)), + '' . base_url() . 'subscription_renewal/' . $membership_id . '', + ], + $emailContent + ); + $emailData = [ 'template_name' => 'EXPIRY NOTIFY TEMPLATE EMAIL', - 'recipient_email' => $row['email'], + 'recipient_email' => $email, 'subject' => 'Your Subscription Expiry Notification', 'description' => $emailContent, ]; - - $history_child_data = [ 'fkid' => $history_parent_id, 'customer_id' => $customerId, - 'receiving_entity' => $row['email'], + 'receiving_entity' => $email, 'receiving_status' => 0, 'subscription_id' => $subscription_id, 'message' => $emailContent]; - # Step 5: Insertion on History Child + $history_child_id = $NotificationModel->save_notification_history_child($history_child_data); - - # Step 6:Send email using NotificationHelper + $emailResult = $notification->sendEmail($emailData); - - $this->logger->error("EXPIRAY NOTIFY TEMPLATE EMAIL Email CID = ".$customerId." ".json_encode($emailResult)); - - if (isset($emailResult['success'])) { + + if (isset($emailResult['success']) && !empty($emailResult['success'])) { $history_msg = 'Email sent successfully'; $history_child_updatedata = ['receiving_status'=>1,'result'=>$history_msg]; $history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id]; @@ -736,142 +704,107 @@ class Notifications extends BaseController $response .= ($inx+1).") Failed to send email
"; } } else { - $history_msg = 'There is no email template found by the name of EXPIRY NOTIFY TEMPLATE EMAIL'; - // $receiving_status = 0 ; - $this->logger->error($history_msg); - $response .= $history_msg."
"; - continue; - } - } - else{ - $response .= ($inx+1).") Staus = ".$status."
"; - $this->logger->error("status is Draft"); - } - # EXPIRY NOTIFY TEMPLATE EMAIL Closed - if ($status === 'Approved') { - $existingcheck2 = $NotificationModel->checkEmailAlreadyExisting($userMobileNumber,$customerId); - $check_existing2 = 0; - $check_date2 = ""; - $check_diff_days2 = ""; - if(!empty($existingcheck2)){ - - foreach ($existingcheck2 as $i2 => $r2) { - if($r2['receiving_status'] == 1){ - $check_existing2 = 1; - $check_date2 = $r2['sent_time']; - $sentTimestamp2 = strtotime($r2['sent_time']); - $provedTimestamp2 = strtotime($providedDate); - - - $diffInSeconds2 = abs($provedTimestamp2 - $sentTimestamp2); - $diffInDays2 = $diffInSeconds2 / (60 * 60 * 24); - - $check_diff_days2 = $diffInDays2; - } + $check_existing = 0; + $check_email_date = ""; + + + if(!empty($existingEmailCheck)){ + + foreach ($existingEmailCheck as $i => $r) { + $check_email_date = ($r['receiving_status'] == 1) ? $r['sent_time'] : ""; } } - if($check_existing2){ - $response .= ($inx+1).") whatsapp already send ".$check_date2."
"; - continue; + if($check_email_date){ + $response .= ($inx+1).") Email already send on - ".date('d/m/Y h:i A', strtotime($check_email_date))."
"; + $this->logger->error(($inx + 1) . ") Email already sent to {$email}"); + $this->logger->error(($inx + 1) . ") Email already sent on {$check_email_date}"); + } + } - # EXPIRY NOTIFY TEMPLATE WHATSAPP - $whatsappTemplateName = $NotificationModel->getTempName('EXPIRY NOTIFY TEMPLATE WHATSAPP'); - // print_r($whatsappTemplateName);die; - if ((count($whatsappTemplateName) > 0) && !empty($whatsappTemplateName)) { - $campaign_id = 2; // hardcoded because static Template. - $history_parents_data = ['campaign_id' => 2,'status' => 0]; - $history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data); - if (empty($userMobileNumber)) { - $history_msg = 'There is no subscriber mobile number'; - $history_child_updatedata = ['receiving_status'=>0,'result'=>$history_msg]; - $history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id]; - $history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where); - $this->logger->error($history_child_statement); + } else { + $response .= ($inx + 1) . ") No email template found
"; + $this->logger->error(($inx + 1) . ") No email template found
"); + } + + // WhatsApp Notification + $whatsappTemplateName = $NotificationModel->getTempName('EXPIRY NOTIFY TEMPLATE WHATSAPP'); + if (!empty($whatsappTemplateName)) { + $existingWhatsAppCheck = $NotificationModel->checkAlreadyExistingInHistory($userMobileNumber, $customerId, $subscription_id); + + if (empty($existingWhatsAppCheck)) { + + $campaign_id = 2; + $history_parents_data = ['campaign_id' => $campaign_id,'status' => 0]; + $history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data); - $history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id); - $this->logger->error($history_parent_statement); - $this->logger->error($history_msg); - $response .= ($inx+1).") ".$history_msg."
"; - continue; - } - # Insertion on History Whatsapp Means Campaign ID 2 Hardcoded - $history_parents_data = ['campaign_id' => 2,'status' => 0]; - $history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data); + $whatsappContent = $whatsappTemplateName[0]['message']; + $whatsappContent = str_replace( + ['{USER_NAME}', '{SCHEME_NAME}', '{EXPIRY_DATE}', '{RENEWAL_LINK}'], + [ + $fullName, + $schemename, + date('d-m-Y', strtotime($expirydate)), + base_url() . 'subscription_renewal/' . $customerId, + ], + $whatsappContent + ); + + $params = (object)[ + 'number' => '91' . $userMobileNumber, + 'type' => 'text', + 'message' => $whatsappContent, + 'instance_id' => $_ENV['WAAI_INSTANCE'], + 'access_token' => $_ENV['WAAI_TOKEN'], + ]; + + $whatsappResult = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params); + $history_child_data = [ 'fkid' => $history_parent_id, + 'customer_id' => $customerId, + 'receiving_entity' => $userMobileNumber, + 'receiving_status' => 0, + 'subscription_id' => $subscription_id, + 'message' => strip_tags(ltrim($whatsappContent))]; + $history_child_id = $NotificationModel->save_notification_history_child($history_child_data); + $receiving_status = $whatsappResult['receiving_status']; + $history_msg = strtolower(gettype($whatsappResult)) == "string" ? $whatsappResult : json_encode($whatsappResult['reponse']); + $history_child_updatedata = ['receiving_status'=>$receiving_status,'result'=>$history_msg]; + $history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id]; + $history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where); + $this->logger->error($history_child_statement); - # Step 7: Prepare whatsapp content based on the template - $whatsappContent = $whatsappTemplateName[0]['message']; - if (isset($fullName)) { - $whatsappContent = str_replace("{USER_NAME}", $fullName, $whatsappContent); + $history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id); + $this->logger->error($history_parent_statement); + if(strtolower(gettype($whatsappResult)) == "string"){ + $response .= ($inx+1).") ".$whatsappResult."
"; + } + else{ + $result = json_encode($whatsappResult['reponse']); + $decodedResult = json_decode($result, true); + if ($decodedResult && isset($decodedResult['message']['key']['remoteJid'])) { + $remoteJid = $decodedResult['message']['key']['remoteJid']; + $this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Remote Jid = " . $remoteJid); + $response .= ($inx+1).") Whatsapp sent successfully
"; + } else { + // echo "Failed to extract remoteJid"; + $this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Failed to extract remoteJid "); + $response .= ($inx+1).") Failed to send Whatsapp
"; } - if (isset($schemename)) { - $whatsappContent = str_replace("{SCHEME_NAME}", $schemename, $whatsappContent); + } + } else { + $check_whatsapp_date = ""; + if(!empty($existingWhatsAppCheck)){ + foreach ($existingWhatsAppCheck as $i => $r) { + $check_whatsapp_date = ($r['receiving_status'] == 1) ? $r['sent_time'] : ""; } - if (isset($expirydate)) { - $expiryon = $expirydate ? date('d-m-Y', strtotime($expirydate)) : ''; - $whatsappContent = str_replace("{EXPIRY_DATE}", $expiryon, $whatsappContent); - } - if (isset($customerId)) { - $whatsappContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' . $customerId, $whatsappContent); - } - # Step 8: Insertion on History Child for whatsapp - $history_child_data = [ 'fkid' => $history_parent_id, - 'customer_id' => $customerId, - 'receiving_entity' => $userMobileNumber, - 'receiving_status' => 0, - 'subscription_id' => $subscription_id, - 'message' => strip_tags(ltrim($whatsappContent))]; - $history_child_id = $NotificationModel->save_notification_history_child($history_child_data); - - - # Step 8: Send Whatsapp using NotificationHelper - $params = (object) Null; - $url = SEND_WAAI_URL; - $params->number = (int)'91' . $userMobileNumber; - $params->type = "text"; - $params->message = strip_tags(ltrim($whatsappContent)); - $params->instance_id = $_ENV['WAAI_INSTANCE']; - $params->access_token = $_ENV['WAAI_TOKEN']; - $this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request = " . json_encode($params)); - $this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request type b4 = " . gettype($params)); - $whatsapp_result = $notification->sendWhatsAppMessage($url, "POST", $params); - $receiving_status = $whatsapp_result['receiving_status']; - $history_msg = strtolower(gettype($whatsapp_result)) == "string" ? $whatsapp_result : json_encode($whatsapp_result['reponse']); - $history_child_updatedata = ['receiving_status'=>$receiving_status,'result'=>$history_msg]; - $history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id]; - $history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where); - $this->logger->error($history_child_statement); - - $history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id); - $this->logger->error($history_parent_statement); - $this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Reponse = " . $history_msg); - - if(strtolower(gettype($whatsapp_result)) == "string"){ - $response .= ($inx+1).") ".$whatsapp_result."
"; - } - else{ - $result = json_encode($whatsapp_result['reponse']); - $decodedResult = json_decode($result, true); - if ($decodedResult && isset($decodedResult['message']['key']['remoteJid'])) { - $remoteJid = $decodedResult['message']['key']['remoteJid']; - $this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Remote Jid = " . $remoteJid); - $response .= ($inx+1).") Whatsapp sent successfully
"; - } else { - // echo "Failed to extract remoteJid"; - $this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Failed to extract remoteJid "); - $response .= ($inx+1).") Failed to send Whatsapp
"; - } - } - } else { - // $receiving_status = 0; - $history_msg = 'There is no Whatsapp template found by the name of EXPIRAY NOTIFY TEMPLATE WHATSAPP '; - $this->logger->error($history_msg); - $response .= "There is no Whatsapp template
"; - continue; - } - # EXPIRY NOTIFY TEMPLATE WHATSAPP Closed - } - else{ - $this->logger->error("status is draft"); + } + if($check_whatsapp_date){ + $response .= ($inx+1).") WhatsApp already send on - ".date('d/m/Y h:i A', strtotime($check_whatsapp_date))."
"; + $this->logger->error(($inx + 1) . ") WhatsApp already sent to {$userMobileNumber}"); + $this->logger->error(($inx + 1) . ") WhatsApp already sent on {$check_whatsapp_date}"); + } + } + } else { + $response .= ($inx + 1) . ") No WhatsApp template found
"; } # Loop Closed } diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php index 01930699..d09bee6a 100755 --- a/app/Models/HomeModel.php +++ b/app/Models/HomeModel.php @@ -104,6 +104,7 @@ class HomeModel extends Model $query = $this->db->table('subscription AS S') ->select('S.business_id, BK.title as name, BK.short_code, BK.book_id as id, S.scheme_id, LEFT(BK.title, 1) AS first_letter, COUNT(S.customer_id) AS count, BI.wp_img_url') ->select('COUNT(S.customer_id) AS overall, COUNT(IF(S.isactive = 1, S.customer_id, NULL)) AS activeoverall, COUNT(IF(S.is_renew = 0 AND S.isactive = 1, S.customer_id, NULL)) AS nonrenewal, COUNT(IF(S.is_renew = 1 AND S.isactive = 1, S.customer_id, NULL)) AS renewal, SUM(CASE WHEN S.created_on >= NOW() - INTERVAL 30 DAY THEN 1 ELSE 0 END) AS new_subscribers') + ->select('COUNT(IF(S.status = 1, S.customer_id, NULL)) AS active,COUNT(IF(S.status = 0, S.customer_id, NULL)) AS expired,COUNT(IF(S.is_renew > 0 AND S.status = 1, S.customer_id, NULL)) AS renew') ->join('customers AS C', 'C.customer_id = S.customer_id AND C.isactive = 1', 'left') ->join('books AS BK', 'BK.book_id = S.scheme_id', 'left') ->join('book_categories AS BC', 'BC.book_id = S.scheme_id AND BC.isactive = 1', 'left') @@ -185,29 +186,15 @@ class HomeModel extends Model ->join('books as BK', 'BK.book_id = S.scheme_id', 'left') ->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left') ->join('category as CM', 'CM.id = BC.category_id', 'left') + ->join('notification_history_children as NHC', 'NHC.subscription_id = S.sub_id AND NHC.receiving_status = 1 AND NHC.receiving_entity LIKE "%@%"', 'left') + ->join('notification_history_parents as NHP', 'NHP.id = NHC.fkid', 'left') ->select('CM.name, CONCAT_WS(" ", C.first_name, C.last_name) as customer_name, C.email as customer_email, C.mobile_no as customer_mobile, S.sub_id, S.scheme_id, S.customer_id, S.business_id, - S.to_subscription, S.from_subscription, BK.title, BK.short_code, BK.book_id, + S.to_subscription, S.from_subscription, BK.title, BK.short_code, BK.book_id, S.membership_id, DATEDIFF(S.to_subscription, CURDATE()) as countdays, DATE_FORMAT(S.to_subscription, "%d/%m/%Y") as to_subscription_date_format, - ( - SELECT MAX(NHP.start_date_time) - FROM notification_campaign as NC - LEFT JOIN notification_history_parents as NHP ON NHP.campaign_id = NC.campaign_id - LEFT JOIN notification_history_children as NHC ON NHC.fkid = NHP.id - WHERE NHC.customer_id = C.customer_id AND NHC.receiving_entity LIKE "%@%" AND NHC.receiving_status = 1 - AND NHP.start_date_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) - ) as email_last_notify_on, - ( - SELECT MAX(NHP.start_date_time) - FROM notification_campaign as NC - LEFT JOIN notification_history_parents as NHP ON NHP.campaign_id = NC.campaign_id - LEFT JOIN notification_history_children as NHC ON NHC.fkid = NHP.id - WHERE NHC.customer_id = S.customer_id AND NHC.receiving_entity NOT LIKE "%@%" AND NHC.receiving_status = 1 - AND NHC.receiving_status REGEXP "^[0-9]+$" - AND NHP.start_date_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) - ) as whatsapp_last_notify_on') + ( NHC.sent_time ) as email_last_notify_on') ->where('S.to_subscription >=', $now) ->where('S.to_subscription <=', $last30days) ->where('S.isactive', 1) diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php index 18fd6de0..bbddc83d 100755 --- a/app/Models/NotificationModel.php +++ b/app/Models/NotificationModel.php @@ -318,12 +318,14 @@ public function customerGroupQueryExecution($queries){ return count($arr)>0 ? $arr : []; } - public function checkEmailAlreadyExisting($email,$customerId){ + public function checkAlreadyExistingInHistory($email,$customerId,$subscriptionId){ return $this->db->table('notification_history_children as nhc' ) ->join('customers as C', 'C.customer_id = nhc.customer_id', 'left') + ->join('subscription as S', 'S.sub_id = nhc.subscription_id', 'left') ->where('nhc.receiving_entity =',$email) ->where('C.customer_id =',$customerId) - ->where('nhc.sent_time >=', date('Y-m-d H:i:s', strtotime('-30 days'))) + ->where('S.sub_id =',$subscriptionId) + ->where('nhc.sent_time >=', date('Y-m-d', strtotime('-30 days'))) ->get()->getResultArray(); } diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index 139e4fda..909b36ee 100755 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -250,8 +250,7 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va $result = $query->getResultArray(); $lastQuery = $this->db->getLastQuery(); $finalQueryString = $lastQuery->getQuery(); - echo $finalQueryString; - die; + return $result; } public function getSubscriptionDetailsBySchemeName($selectedScheme, $downloadType){ diff --git a/app/Views/dashboard.php b/app/Views/dashboard.php index 67e55684..5eb28e12 100755 --- a/app/Views/dashboard.php +++ b/app/Views/dashboard.php @@ -108,14 +108,21 @@

-->
-

+

Total Subscriber


-
- New :
- Renewed:
+
+
+

New :

+
+
+

Expired :

+
+
+

Renewed :

+
@@ -143,6 +150,7 @@ Scheme Name Expiring In Notification On + member id @@ -169,6 +177,7 @@ : ''; ?> + diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index 8a744bb9..18c138a9 100755 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -1555,18 +1555,21 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d }, success: function(response) { cm = response['data']['customer_membership']; + console.log(cm); cm.sort(function(a, b) { return b.is_renew - a.is_renew; }); if (cm.length > 0) { - text1 = cm[0].is_renew == 1 ? " - Renewal" : ""; - text2 = cm[0].isactive == 0 ? " - Expried" : ""; - $(".subscribedetails").show(); // Change this line to use the class selector - let message = "Earlier Membership : " + cm[0].title + " ( From: " + cm[0].formatted_from_subscription + " To: " + cm[0].formatted_to_subscription + " )" + text1 + text2; - console.log(text1); - // $("#schemeName").text(message); - showAlert(message) - } else { + $(".subscribedetails").show(); + let messages = "Earlier Membership :
"; + for (let i = 0; i < cm.length; i++) { + let text1 = cm[i].is_renew == 1 ? " - Renewal" : ""; + let text2 = cm[i].isactive == 1 ? " - Active" : " - Draft "; + messages += cm[i].title + "
( From: " + cm[i].formatted_from_subscription + " To: " + cm[i].formatted_to_subscription + " )" + text1 + text2 + "
"; + } + showAlert(messages.trim()); + } + else { $(".subscribedetails").show(); // Change this line to use the class selector let message = "No Earlier Membership found"; //$("#schemeName").text(message); @@ -1582,7 +1585,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d // New function to create a cutom alert box, // since the default alert box is small to display the message function showAlert(message) { - $('#customAlertMessage').text(message); + $('#customAlertMessage').html(message); $('#customAlertModal').modal('show'); } diff --git a/app/Views/notify_the_expiry_subscribers.php b/app/Views/notify_the_expiry_subscribers.php index 257da56b..039e52d3 100755 --- a/app/Views/notify_the_expiry_subscribers.php +++ b/app/Views/notify_the_expiry_subscribers.php @@ -25,7 +25,7 @@ function sendsms(){ var params = $("#params").val(); - if(params && params > 0){ + if(params){ $.ajax({ type: "GET", url: ""+params,