FIX_expiring_membership_with_notification_list
This commit is contained in:
parent
ef96346c5b
commit
d466bbd1f0
@ -179,65 +179,44 @@ class HomeModel extends Model
|
|||||||
public function expiring_membership_with_notification_list() {
|
public function expiring_membership_with_notification_list() {
|
||||||
$now = date('Y-m-d');
|
$now = date('Y-m-d');
|
||||||
$last30days = date('Y-m-d', strtotime('+30 days'));
|
$last30days = date('Y-m-d', strtotime('+30 days'));
|
||||||
$sql = "SELECT
|
|
||||||
`CM`.`name`,
|
$membershipList = $this->db->table('subscription as S')
|
||||||
CONCAT_WS(' ', `C`.`first_name`, `C`.`last_name`) AS customer_name,
|
->join('customers as C', 'C.customer_id = S.customer_id', 'left')
|
||||||
`C`.`email` AS customer_email,
|
->join('books as BK', 'BK.book_id = S.scheme_id', 'left')
|
||||||
`C`.`mobile_no` AS customer_mobile,
|
->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left')
|
||||||
`S`.`sub_id`,
|
->join('category as CM', 'CM.id = BC.category_id', 'left')
|
||||||
`S`.`scheme_id`,
|
->select('CM.name, CONCAT_WS(" ", C.first_name, C.last_name) as customer_name,
|
||||||
`S`.`customer_id`,
|
C.email as customer_email, C.mobile_no as customer_mobile,
|
||||||
`S`.`business_id`,
|
S.sub_id, S.scheme_id, S.customer_id, S.business_id,
|
||||||
`S`.`to_subscription`,
|
S.to_subscription, S.from_subscription, BK.title, BK.short_code, BK.book_id,
|
||||||
`S`.`from_subscription`,
|
DATEDIFF(S.to_subscription, CURDATE()) as countdays,
|
||||||
`BK`.`title`,
|
DATE_FORMAT(S.to_subscription, "%d/%m/%Y") as to_subscription_date_format,
|
||||||
`BK`.`short_code`,
|
|
||||||
`BK`.`book_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`)
|
SELECT MAX(NHP.start_date_time)
|
||||||
FROM `notification_campaign` AS `NC`
|
FROM notification_campaign as NC
|
||||||
LEFT JOIN `notification_history_parents` AS `NHP` ON `NHP`.`campaign_id` = `NC`.`campaign_id`
|
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`
|
LEFT JOIN notification_history_children as NHC ON NHC.fkid = NHP.id
|
||||||
WHERE `NHC`.`customer_id` = `S`.`customer_id`
|
WHERE NHC.customer_id = C.customer_id AND NHC.receiving_entity LIKE "%@%" AND NHC.receiving_status = 1
|
||||||
AND `NHC`.`receiving_entity` LIKE '%@%'
|
AND NHP.start_date_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
||||||
AND `NHC`.`receiving_status` = 1
|
) as email_last_notify_on,
|
||||||
AND `NHP`.`start_date_time` >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
|
||||||
) AS email_last_notify_on,
|
|
||||||
(
|
(
|
||||||
SELECT MAX(`NHP`.`start_date_time`)
|
SELECT MAX(NHP.start_date_time)
|
||||||
FROM `notification_campaign` AS `NC`
|
FROM notification_campaign as NC
|
||||||
LEFT JOIN `notification_history_parents` AS `NHP` ON `NHP`.`campaign_id` = `NC`.`campaign_id`
|
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`
|
LEFT JOIN notification_history_children as NHC ON NHC.fkid = NHP.id
|
||||||
WHERE `NHC`.`customer_id` = `S`.`customer_id`
|
WHERE NHC.customer_id = S.customer_id AND NHC.receiving_entity NOT LIKE "%@%" AND NHC.receiving_status = 1
|
||||||
AND `NHC`.`receiving_entity` NOT LIKE '%@%'
|
AND NHC.receiving_status REGEXP "^[0-9]+$"
|
||||||
AND `NHC`.`receiving_status` = 1
|
AND NHP.start_date_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
||||||
AND `NHC`.`receiving_status` REGEXP '^[0-9]+$'
|
) as whatsapp_last_notify_on')
|
||||||
AND `NHP`.`start_date_time` >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
->where('S.to_subscription >=', $now)
|
||||||
) AS whatsapp_last_notify_on
|
->where('S.to_subscription <=', $last30days)
|
||||||
FROM
|
->where('S.isactive', 1)
|
||||||
`subscription` AS `S`
|
->where('LOWER(CM.name)', strtolower("Membership"))
|
||||||
LEFT JOIN `customers` AS `C` ON `C`.`customer_id` = `S`.`customer_id`
|
->orderBy('S.to_subscription', 'ASC')
|
||||||
LEFT JOIN `books` AS `BK` ON `BK`.`book_id` = `S`.`scheme_id`
|
->groupBy('S.sub_id')
|
||||||
LEFT JOIN `book_categories` AS `BC` ON `BC`.`book_id` = `S`.`scheme_id`
|
->get()
|
||||||
LEFT JOIN `category` AS `CM` ON `CM`.`id` = `BC`.`category_id`
|
->getResultArray();
|
||||||
WHERE
|
return $membershipList;
|
||||||
`S`.`to_subscription` >= $now
|
|
||||||
AND `S`.`to_subscription` <= $last30days
|
|
||||||
AND `S`.`isactive` = 1
|
|
||||||
AND LOWER(`CM`.`name`) = 'membership'
|
|
||||||
|
|
||||||
GROUP BY
|
|
||||||
`S`.`sub_id`
|
|
||||||
|
|
||||||
ORDER BY
|
|
||||||
`S`.`to_subscription` ASC;
|
|
||||||
";
|
|
||||||
|
|
||||||
$query = $this->db->query($sql);
|
|
||||||
$membershipList = $query->getResultArray();
|
|
||||||
return $membershipList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user