From 19d60da919ec6df75d18a766557e19470234ceff Mon Sep 17 00:00:00 2001 From: Novath Thomas Date: Mon, 18 Mar 2024 23:12:23 +0300 Subject: [PATCH] added plan type to order user account --- system/controllers/order.php | 83 ++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/system/controllers/order.php b/system/controllers/order.php index 9df265f2..e11e7879 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -47,26 +47,27 @@ switch ($action) { } $ui->assign('_title', 'Order Plan'); $ui->assign('_system_menu', 'package'); - if (!empty($_SESSION['nux-router'])) { + if (!empty ($_SESSION['nux-router'])) { + $account_type = $user['account_type']; if ($_SESSION['nux-router'] == 'radius') { - $radius_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); - $radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); + $radius_pppoe = ORM::for_table('tbl_plans')->where('plan_type', $account_type)->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); + $radius_hotspot = ORM::for_table('tbl_plans')->where('plan_type', $account_type)->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); } else { $routers = ORM::for_table('tbl_routers')->where('id', $_SESSION['nux-router'])->find_many(); $rs = []; foreach ($routers as $r) { $rs[] = $r['name']; } - $plans_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); - $plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); + $plans_pppoe = ORM::for_table('tbl_plans')->where('plan_type', $account_type)->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); + $plans_hotspot = ORM::for_table('tbl_plans')->where('plan_type', $account_type)->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); } } else { - $radius_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); - $radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); + $radius_pppoe = ORM::for_table('tbl_plans')->where('plan_type', $account_type)->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); + $radius_hotspot = ORM::for_table('tbl_plans')->where('plan_type', $account_type)->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); $routers = ORM::for_table('tbl_routers')->find_many(); - $plans_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 0)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); - $plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 0)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); + $plans_pppoe = ORM::for_table('tbl_plans')->where('plan_type', $account_type)->where('enabled', '1')->where('is_radius', 0)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); + $plans_hotspot = ORM::for_table('tbl_plans')->where('plan_type', $account_type)->where('enabled', '1')->where('is_radius', 0)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); } $ui->assign('routers', $routers); $ui->assign('radius_pppoe', $radius_pppoe); @@ -84,7 +85,7 @@ switch ($action) { run_hook('custome r_find_unpaid'); #HOOK if ($d) { - if (empty($d['pg_url_payment'])) { + if (empty ($d['pg_url_payment'])) { r2(U . "order/buy/" . $trx['routers_id'] . '/' . $trx['plan_id'], 'w', Lang::T("Checking payment")); } else { r2(U . "order/view/" . $d['id'] . '/check/', 's', Lang::T("You have unpaid transaction")); @@ -100,11 +101,11 @@ switch ($action) { ->find_one($trxid); run_hook('customer_view_payment'); #HOOK // jika tidak ditemukan, berarti punya orang lain - if (empty($trx)) { + if (empty ($trx)) { r2(U . "order/package", 'w', Lang::T("Payment not found")); } // jika url kosong, balikin ke buy - if (empty($trx['pg_url_payment'])) { + if (empty ($trx['pg_url_payment'])) { r2(U . "order/buy/" . (($trx['routers_id'] == 0) ? $trx['routers'] : $trx['routers_id']) . '/' . $trx['plan_id'], 'w', Lang::T("Checking payment")); } if ($routes['3'] == 'check') { @@ -125,7 +126,7 @@ switch ($action) { ->where('username', $user['username']) ->find_one($trxid); } - if (empty($trx)) { + if (empty ($trx)) { r2(U . "order/package", 'e', Lang::T("Transaction Not found")); } $router = Mikrotik::info($trx['routers']); @@ -146,7 +147,7 @@ switch ($action) { r2(U . "order/package", 'e', Lang::T("Balance not enabled")); } $plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3']); - if (empty($plan)) { + if (empty ($plan)) { r2(U . "order/package", 'e', Lang::T("Plan Not found")); } if (!$plan['enabled']) { @@ -180,7 +181,7 @@ switch ($action) { $ui->assign('_title', Lang::T('Buy for friend')); $ui->assign('_system_menu', 'package'); $plan = ORM::for_table('tbl_plans')->find_one($routes['3']); - if (empty($plan)) { + if (empty ($plan)) { r2(U . "order/package", 'e', Lang::T("Plan Not found")); } if (!$plan['enabled']) { @@ -191,10 +192,10 @@ switch ($action) { } else { $router_name = $plan['routers']; } - if (isset($_POST['send']) && $_POST['send'] == 'plan') { + if (isset ($_POST['send']) && $_POST['send'] == 'plan') { $target = ORM::for_table('tbl_customers')->where('username', _post('username'))->find_one(); list($bills, $add_cost) = User::getBills($target['id']); - if (!empty($add_cost)) { + if (!empty ($add_cost)) { $ui->assign('bills', $bills); $ui->assign('add_cost', $add_cost); $plan['price'] += $add_cost; @@ -289,7 +290,7 @@ switch ($action) { $ui->display('user-selectGateway.tpl'); break; } else { - if (empty($pgs[0])) { + if (empty ($pgs[0])) { sendTelegram("Payment Gateway not set, please set it in Settings"); _log(Lang::T("Payment Gateway not set, please set it in Settings")); r2(U . "home", 'e', Lang::T("Failed to create Transaction..")); @@ -299,12 +300,12 @@ switch ($action) { } case 'buy': $gateway = _post('gateway'); - if (empty($gateway) && !empty($_SESSION['gateway'])) { + if (empty ($gateway) && !empty ($_SESSION['gateway'])) { $gateway = $_SESSION['gateway']; - } else if (!empty($gateway)) { + } else if (!empty ($gateway)) { $_SESSION['gateway'] = $gateway; } - if (empty($gateway)) { + if (empty ($gateway)) { r2(U . 'order/gateway/' . $routes[2] . '/' . $routes[3], 'w', Lang::T("Please select Payment Gateway")); } run_hook('customer_buy_plan'); #HOOK @@ -321,7 +322,7 @@ switch ($action) { $router['name'] = 'balance'; } $plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3']); - if (empty($router) || empty($plan)) { + if (empty ($router) || empty ($plan)) { r2(U . "order/package", 'e', Lang::T("Plan Not found")); } $d = ORM::for_table('tbl_payment_gateway') @@ -344,7 +345,7 @@ switch ($action) { if ($router['name'] != 'balance') { list($bills, $add_cost) = User::getBills($id_customer); } - if (empty($id)) { + if (empty ($id)) { $d = ORM::for_table('tbl_payment_gateway')->create(); $d->username = $user['username']; $d->gateway = $gateway; @@ -352,16 +353,16 @@ switch ($action) { $d->plan_name = $plan['name_plan']; $d->routers_id = $router['id']; $d->routers = $router['name']; - if ($plan['validity_unit'] == 'Period') { - // Postpaid price from field - $add_inv = User::getAttribute("Invoice", $id_customer); - if (empty ($add_inv) or $add_inv == 0) { - $d->price = ($plan['price'] + $add_cost); - } else { - $d->price = ($add_inv + $add_cost); - } - } else { + if ($plan['validity_unit'] == 'Period') { + // Postpaid price from field + $add_inv = User::getAttribute("Invoice", $id_customer); + if (empty ($add_inv) or $add_inv == 0) { $d->price = ($plan['price'] + $add_cost); + } else { + $d->price = ($add_inv + $add_cost); + } + } else { + $d->price = ($plan['price'] + $add_cost); } //$d->price = ($plan['price'] + $add_cost); $d->created_date = date('Y-m-d H:i:s'); @@ -375,16 +376,16 @@ switch ($action) { $d->plan_name = $plan['name_plan']; $d->routers_id = $router['id']; $d->routers = $router['name']; - if ($plan['validity_unit'] == 'Period') { - // Postpaid price from field - $add_inv = User::getAttribute("Invoice", $id_customer); - if (empty ($add_inv) or $add_inv == 0) { - $d->price = ($plan['price'] + $add_cost); - } else { - $d->price = ($add_inv + $add_cost); - } - } else { + if ($plan['validity_unit'] == 'Period') { + // Postpaid price from field + $add_inv = User::getAttribute("Invoice", $id_customer); + if (empty ($add_inv) or $add_inv == 0) { $d->price = ($plan['price'] + $add_cost); + } else { + $d->price = ($add_inv + $add_cost); + } + } else { + $d->price = ($plan['price'] + $add_cost); } //$d->price = ($plan['price'] + $add_cost); $d->created_date = date('Y-m-d H:i:s');