Merge pull request #342 from gerandonk/Development

fix postpaid more than 1 period
This commit is contained in:
iBNu Maksum 2024-11-05 19:14:10 +07:00 committed by GitHub
commit 7d24b719b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -149,24 +149,18 @@ class Package
$exp_date->modify('first day of next month'); $exp_date->modify('first day of next month');
$exp_date->setDate($exp_date->format('Y'), $exp_date->format('m'), $day_exp); $exp_date->setDate($exp_date->format('Y'), $exp_date->format('m'), $day_exp);
$min_days = 7; $min_days = 7 * $p['validity'];
$max_days = 35; $max_days = 35 * $p['validity'];
// If validity is more than 2 months, multiply the limit days
if ($p['validity'] >= 2) {
$min_days *= $p['validity'];
$max_days *= $p['validity'];
}
$days_until_exp = $exp_date->diff($current_date)->days; $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) { while ($days_until_exp < $min_days) {
$exp_date->modify('+1 month'); $exp_date->modify('+1 month');
$days_until_exp = $exp_date->diff($current_date)->days; $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) { while ($days_until_exp > $max_days) {
$exp_date->modify('-1 month'); $exp_date->modify('-1 month');
$days_until_exp = $exp_date->diff($current_date)->days; $days_until_exp = $exp_date->diff($current_date)->days;
@ -177,9 +171,15 @@ class Package
$exp_date->modify('+1 month'); $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'); $date_exp = $exp_date->format('Y-m-d');
$time = "23:59:59"; $time = "23:59:59";
} else if ($p['validity_unit'] == 'Days') { } else if ($p['validity_unit'] == 'Days') {
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' day'))); $datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' day')));
$date_exp = $datetime[0]; $date_exp = $datetime[0];
$time = $datetime[1]; $time = $datetime[1];