fix change plan when customer plan not active

This commit is contained in:
Ibnu Maksum 2024-06-25 14:40:01 +07:00
parent 1fbd393fa3
commit f08d8e127e
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -248,15 +248,15 @@ switch ($action) {
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']); $p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
if (in_array($admin['user_type'], array('SuperAdmin', 'Admin'))) { if (in_array($admin['user_type'], array('SuperAdmin', 'Admin'))) {
$ps = ORM::for_table('tbl_plans') $ps = ORM::for_table('tbl_plans')
->where('type', $p['type']) ->where('type', $p['type'])
->where('is_radius', $p['is_radius']) ->where('is_radius', $p['is_radius'])
->find_many(); ->find_many();
} else { } else {
$ps = ORM::for_table('tbl_plans') $ps = ORM::for_table('tbl_plans')
->where("enabled", 1) ->where("enabled", 1)
->where('is_radius', $p['is_radius']) ->where('is_radius', $p['is_radius'])
->where('type', $p['type']) ->where('type', $p['type'])
->find_many(); ->find_many();
} }
$ui->assign('p', $ps); $ui->assign('p', $ps);
run_hook('view_edit_customer_plan'); #HOOK run_hook('view_edit_customer_plan'); #HOOK
@ -322,29 +322,31 @@ switch ($action) {
$d->status = 'on'; $d->status = 'on';
} }
} }
if ($d['status'] == 'on' && $oldPlanID != $id_plan) { if ($oldPlanID != $id_plan) {
$d->plan_id = $newPlan['id']; $d->plan_id = $newPlan['id'];
$d->namebp = $newPlan['name_plan']; $d->namebp = $newPlan['name_plan'];
$customer = User::_info($d['customer_id']); $customer = User::_info($d['customer_id']);
//remove from old plan //remove from old plan
$p = ORM::for_table('tbl_plans')->find_one($oldPlanID); if ($d['status'] == 'on') {
$dvc = Package::getDevice($p); $p = ORM::for_table('tbl_plans')->find_one($oldPlanID);
if ($_app_stage != 'demo') { $dvc = Package::getDevice($p);
if (file_exists($dvc)) { if ($_app_stage != 'demo') {
require_once $dvc; if (file_exists($dvc)) {
(new $p['device'])->remove_customer($customer, $p); require_once $dvc;
} else { (new $p['device'])->remove_customer($customer, $p);
new Exception(Lang::T("Devices Not Found")); } else {
new Exception(Lang::T("Devices Not Found"));
}
} }
} //add new plan
//add new plan $dvc = Package::getDevice($newPlan);
$dvc = Package::getDevice($newPlan); if ($_app_stage != 'demo') {
if ($_app_stage != 'demo') { if (file_exists($dvc)) {
if (file_exists($dvc)) { require_once $dvc;
require_once $dvc; (new $newPlan['device'])->add_customer($customer, $newPlan);
(new $newPlan['device'])->add_customer($customer, $newPlan); } else {
} else { new Exception(Lang::T("Devices Not Found"));
new Exception(Lang::T("Devices Not Found")); }
} }
} }
} }
@ -393,9 +395,9 @@ switch ($action) {
$ui->assign('customers', ORM::for_table('tbl_voucher')->distinct()->select("user")->whereNotEqual("user", '0')->findArray()); $ui->assign('customers', ORM::for_table('tbl_voucher')->distinct()->select("user")->whereNotEqual("user", '0')->findArray());
// option plans // option plans
$plns = ORM::for_table('tbl_voucher')->distinct()->select("id_plan")->findArray(); $plns = ORM::for_table('tbl_voucher')->distinct()->select("id_plan")->findArray();
if(count($plns)>0){ if (count($plns) > 0) {
$ui->assign('plans', ORM::for_table('tbl_plans')->selects(["id", 'name_plan'])->where_in('id', array_column($plns, 'id_plan'))->findArray()); $ui->assign('plans', ORM::for_table('tbl_plans')->selects(["id", 'name_plan'])->where_in('id', array_column($plns, 'id_plan'))->findArray());
}else{ } else {
$ui->assign('plans', []); $ui->assign('plans', []);
} }
$ui->assign('routers', array_column(ORM::for_table('tbl_voucher')->distinct()->select("routers")->findArray(), 'routers')); $ui->assign('routers', array_column(ORM::for_table('tbl_voucher')->distinct()->select("routers")->findArray(), 'routers'));
@ -873,15 +875,15 @@ switch ($action) {
$plns = ORM::for_table('tbl_user_recharges')->distinct()->select("plan_id")->findArray(); $plns = ORM::for_table('tbl_user_recharges')->distinct()->select("plan_id")->findArray();
$ids = array_column($plns, 'plan_id'); $ids = array_column($plns, 'plan_id');
if(count($ids)){ if (count($ids)) {
$ui->assign('plans', ORM::for_table('tbl_plans')->select("id")->select('name_plan')->where_id_in($ids)->findArray()); $ui->assign('plans', ORM::for_table('tbl_plans')->select("id")->select('name_plan')->where_id_in($ids)->findArray());
}else{ } else {
$ui->assign('plans', []); $ui->assign('plans', []);
} }
$query = ORM::for_table('tbl_user_recharges')->order_by_desc('id'); $query = ORM::for_table('tbl_user_recharges')->order_by_desc('id');
if ($search != '') { if ($search != '') {
$query->where_like("username","%$search%"); $query->where_like("username", "%$search%");
} }
if (!empty($router)) { if (!empty($router)) {
$query->where('routers', $router); $query->where('routers', $router);