Update Package.php
Reversed failed logic
This commit is contained in:
parent
9569847612
commit
23bba0b189
@ -149,18 +149,24 @@ 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 * $p['validity'];
|
||||
$max_days = 35 * $p['validity'];
|
||||
$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'];
|
||||
}
|
||||
|
||||
$days_until_exp = $exp_date->diff($current_date)->days;
|
||||
|
||||
// If less than min_days away, move to the next period
|
||||
// If less than min_days away, move to the next month
|
||||
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 period
|
||||
// If more than max_days away, move to the previous month
|
||||
while ($days_until_exp > $max_days) {
|
||||
$exp_date->modify('-1 month');
|
||||
$days_until_exp = $exp_date->diff($current_date)->days;
|
||||
@ -171,15 +177,9 @@ 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') {
|
||||
|
||||
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' day')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
@ -195,6 +195,7 @@ class Package
|
||||
|
||||
if ($b) {
|
||||
$lastExpired = Lang::dateAndTimeFormat($b['expiration'], $b['time']);
|
||||
$isChangePlan = false;
|
||||
if ($b['namebp'] == $p['name_plan'] && $b['status'] == 'on' && $config['extend_expiry'] == 'yes') {
|
||||
// if it same internet plan, expired will extend
|
||||
switch ($p['validity_unit']) {
|
||||
@ -221,7 +222,11 @@ class Package
|
||||
$time = $datetime[1];
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$isChangePlan = true;
|
||||
}
|
||||
|
||||
//if ($b['status'] == 'on') {
|
||||
$dvc = Package::getDevice($p);
|
||||
if ($_app_stage != 'Demo') {
|
||||
try {
|
||||
@ -251,7 +256,7 @@ class Package
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
// if contains 'mikrotik', 'hotspot', 'pppoe', 'radius' then recharge it
|
||||
if (Validator::containsKeyword($p['device'])) {
|
||||
@ -284,14 +289,16 @@ class Package
|
||||
//its already paid
|
||||
$t->price = 0;
|
||||
} else {
|
||||
switch ($p['validity_unit']) {
|
||||
case 'Period':
|
||||
if ($p['validity_unit'] == 'Period') {
|
||||
// Postpaid price from field
|
||||
$add_inv = User::getAttribute("Invoice", $id_customer);
|
||||
$t->price = (empty($add_inv) or $add_inv == 0) ? $p['price'] + $add_cost : $add_inv + $add_cost;
|
||||
break;
|
||||
default:
|
||||
if (empty($add_inv) or $add_inv == 0) {
|
||||
$t->price = $p['price'] + $add_cost;
|
||||
} else {
|
||||
$t->price = $add_inv + $add_cost;
|
||||
}
|
||||
} else {
|
||||
$t->price = $p['price'] + $add_cost;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$t->recharged_on = $date_only;
|
||||
@ -397,15 +404,13 @@ class Package
|
||||
$t->price = 0;
|
||||
// its already paid
|
||||
} else {
|
||||
switch ($p['validity_unit']) {
|
||||
case 'Period':
|
||||
if ($p['validity_unit'] == 'Period') {
|
||||
// Postpaid price always zero for first time
|
||||
$note = '';
|
||||
$bills = [];
|
||||
$t->price = 0;
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
$t->price = $p['price'] + $add_cost;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$t->recharged_on = $date_only;
|
||||
@ -457,7 +462,6 @@ class Package
|
||||
"\nPrice: " . Lang::moneyFormat($p['price'] + $add_cost) .
|
||||
"\nNote:\n" . $note);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($bills) && count($bills) > 0) {
|
||||
User::billsPaid($bills, $id_customer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user