From 5ccddf11beb743855b46c76084de61797a4d9685 Mon Sep 17 00:00:00 2001 From: gerandonk Date: Wed, 6 Nov 2024 11:34:28 +0700 Subject: [PATCH] update postpaid logic for more than 1 period fix mikrotiksms not working --- system/autoload/Message.php | 2 +- system/autoload/Package.php | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/system/autoload/Message.php b/system/autoload/Message.php index aef2f3c9..1911d6b7 100644 --- a/system/autoload/Message.php +++ b/system/autoload/Message.php @@ -48,7 +48,7 @@ class Message } } else { try { - self::sendSMS($config['sms_url'], $phone, $txt); + self::MikrotikSendSMS($config['sms_url'], $phone, $txt); } catch (Exception $e) { // ignore, add to logs _log("Failed to send SMS using Mikrotik.\n" . $e->getMessage(), 'SMS', 0); diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 9b751b0f..dda20884 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -149,24 +149,18 @@ class Package $exp_date->modify('first day of next month'); $exp_date->setDate($exp_date->format('Y'), $exp_date->format('m'), $day_exp); - $min_days = 7; - $max_days = 35; - - // If validity is more than 2 months, multiply the limit days - if ($p['validity'] >= 2) { - $min_days *= $p['validity']; - $max_days *= $p['validity']; - } + $min_days = 7 * $p['validity']; + $max_days = 35 * $p['validity']; $days_until_exp = $exp_date->diff($current_date)->days; - // If less than min_days away, move to the next month + // If less than min_days away, move to the next period while ($days_until_exp < $min_days) { $exp_date->modify('+1 month'); $days_until_exp = $exp_date->diff($current_date)->days; } - // If more than max_days away, move to the previous month + // If more than max_days away, move to the previous period while ($days_until_exp > $max_days) { $exp_date->modify('-1 month'); $days_until_exp = $exp_date->diff($current_date)->days; @@ -177,6 +171,11 @@ class Package $exp_date->modify('+1 month'); } + // Adjust for multiple periods + if ($p['validity'] > 1) { + $exp_date->modify('+' . ($p['validity'] - 1) . ' months'); + } + $date_exp = $exp_date->format('Y-m-d'); $time = "23:59:59"; } else if ($p['validity_unit'] == 'Days') {