Files
.github
admin
install
pages_template
qrcode
system
autoload
cache
controllers
accounts.php
admin.php
autoload.php
autoload_user.php
bandwidth.php
callback.php
codecanyon.php
community.php
customers.php
dashboard.php
default.php
export.php
home.php
index.html
login.php
logout.php
logs.php
map.php
message.php
order.php
page.php
pages.php
paymentgateway.php
plan.php
plugin.php
pluginmanager.php
pool.php
radius.php
register.php
reports.php
routers.php
services.php
settings.php
voucher.php
lan
paymentgateway
plugin
uploads
vendor
.htaccess
api.php
boot.php
composer.json
composer.lock
cron.php
cron_reminder.php
index.html
orm.php
updates.json
ui
.gitignore
.htaccess_firewall
CHANGELOG.md
LICENSE
README.md
composer.json
config.sample.php
favicon.ico
index.php
init.php
update.php
version.json
mitrobill/system/controllers/services.php

937 lines
37 KiB
PHP
Raw Normal View History

2017-03-11 02:51:06 +07:00
<?php
2023-10-16 13:54:34 +07:00
2017-03-11 02:51:06 +07:00
/**
2023-10-12 15:55:42 +07:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
2022-08-23 16:33:21 +07:00
**/
2017-03-11 02:51:06 +07:00
_admin();
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('Hotspot Plans'));
2017-03-11 02:51:06 +07:00
$ui->assign('_system_menu', 'services');
$action = $routes['1'];
$ui->assign('_admin', $admin);
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
2024-03-18 22:55:08 +03:00
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2017-03-11 02:51:06 +07:00
}
use PEAR2\Net\RouterOS;
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
require_once 'system/autoload/PEAR2/Autoload.php';
switch ($action) {
2023-09-15 14:03:23 +07:00
case 'sync':
set_time_limit(-1);
if ($routes['2'] == 'hotspot') {
$plans = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->where('tbl_plans.enabled', '1')->find_many();
$log = '';
$router = '';
foreach ($plans as $plan) {
2023-10-04 11:37:32 +07:00
if ($plan['is_radius']) {
2023-10-16 13:54:34 +07:00
if ($b['rate_down_unit'] == 'Kbps') {
$raddown = '000';
} else {
$raddown = '000000';
}
if ($b['rate_up_unit'] == 'Kbps') {
$radup = '000';
} else {
$radup = '000000';
}
$radiusRate = $plan['rate_up'] . $radup . '/' . $plan['rate_down'] . $raddown . '/' . $plan['burst'];
2023-10-16 13:54:34 +07:00
Radius::planUpSert($plan['id'], $radiusRate);
$log .= "DONE : Radius $plan[name_plan], $plan[shared_users], $radiusRate<br>";
2023-10-04 11:37:32 +07:00
} else {
2023-10-03 15:46:55 +07:00
if ($router != $plan['routers']) {
$mikrotik = Mikrotik::info($plan['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$router = $plan['routers'];
}
if ($plan['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
} else {
$unitdown = 'M';
}
if ($plan['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
} else {
$unitup = 'M';
}
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
Mikrotik::addHotspotPlan($client, $plan['name_plan'], $plan['shared_users'], $rate);
$log .= "DONE : $plan[name_plan], $plan[shared_users], $rate<br>";
if (!empty($plan['pool_expired'])) {
2023-10-03 15:46:55 +07:00
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired']);
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
}
2023-09-15 14:03:23 +07:00
}
}
r2(U . 'services/hotspot', 's', $log);
2023-10-04 11:37:32 +07:00
} else if ($routes['2'] == 'pppoe') {
2023-09-15 14:03:23 +07:00
$plans = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->where('tbl_plans.enabled', '1')->find_many();
$log = '';
$router = '';
foreach ($plans as $plan) {
2023-10-16 13:54:34 +07:00
if ($plan['is_radius']) {
if ($b['rate_down_unit'] == 'Kbps') {
$raddown = '000';
} else {
$raddown = '000000';
}
if ($b['rate_up_unit'] == 'Kbps') {
$radup = '000';
} else {
$radup = '000000';
}
$radiusRate = $plan['rate_up'] . $radup . '/' . $plan['rate_down'] . $raddown . '/' . $plan['burst'];
2023-10-16 13:54:34 +07:00
Radius::planUpSert($plan['id'], $radiusRate, $plan['pool']);
$log .= "DONE : RADIUS $plan[name_plan], $plan[pool], $rate<br>";
2023-09-15 14:03:23 +07:00
} else {
2023-10-16 13:54:34 +07:00
if ($router != $plan['routers']) {
$mikrotik = Mikrotik::info($plan['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$router = $plan['routers'];
}
if ($plan['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
} else {
$unitdown = 'M';
}
if ($plan['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
} else {
$unitup = 'M';
}
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
Mikrotik::addPpoePlan($client, $plan['name_plan'], $plan['pool'], $rate);
$log .= "DONE : $plan[name_plan], $plan[pool], $rate<br>";
if (!empty($plan['pool_expired'])) {
2023-10-16 13:54:34 +07:00
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired'], '512K/512K');
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
}
2023-09-15 14:03:23 +07:00
}
}
r2(U . 'services/pppoe', 's', $log);
}
r2(U . 'services/hotspot', 'w', 'Unknown command');
2017-03-11 02:51:06 +07:00
case 'hotspot':
2022-08-23 16:33:21 +07:00
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/hotspot.js"></script>');
$name = _post('name');
if ($name != '') {
$query = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->where_like('tbl_plans.name_plan', '%' . $name . '%');
$d = Paginator::findMany($query, ['name' => $name]);
2022-08-23 16:33:21 +07:00
} else {
$query = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query);
2022-08-23 16:33:21 +07:00
}
$ui->assign('d', $d);
2022-09-18 00:00:40 +07:00
run_hook('view_list_plans'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('hotspot.tpl');
break;
case 'add':
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('d', $d);
$r = ORM::for_table('tbl_routers')->find_many();
$ui->assign('r', $r);
2022-09-18 00:00:40 +07:00
run_hook('view_add_plan'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('hotspot-add.tpl');
break;
case 'edit':
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
2022-08-23 16:33:21 +07:00
if ($d) {
$ui->assign('d', $d);
2023-09-05 16:40:23 +07:00
$p = ORM::for_table('tbl_pool')->where('routers', $d['routers'])->find_many();
$ui->assign('p', $p);
2022-08-23 16:33:21 +07:00
$b = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('b', $b);
2022-09-18 00:00:40 +07:00
run_hook('view_edit_plan'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('hotspot-edit.tpl');
2022-08-23 16:33:21 +07:00
} else {
2024-03-30 12:02:57 +07:00
r2(U . 'services/hotspot', 'e', Lang::T('Account Not Found'));
2017-03-11 02:51:06 +07:00
}
break;
case 'delete':
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
2022-08-23 16:33:21 +07:00
if ($d) {
2022-09-18 00:00:40 +07:00
run_hook('delete_plan'); #HOOK
2023-10-04 16:11:55 +07:00
if ($d['is_radius']) {
Radius::planDelete($d['id']);
2023-10-16 13:54:34 +07:00
} else {
2023-10-24 12:27:30 +07:00
try {
$mikrotik = Mikrotik::info($d['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotPlan($client, $d['name_plan']);
2023-10-24 12:27:30 +07:00
} catch (Exception $e) {
//ignore exception, it means router has already deleted
2024-02-19 18:03:40 +07:00
} catch (Throwable $e) {
//ignore exception, it means router has already deleted
}
2022-08-23 16:33:21 +07:00
}
2017-03-11 02:51:06 +07:00
$d->delete();
2022-08-23 16:33:21 +07:00
2024-02-13 13:54:01 +07:00
r2(U . 'services/hotspot', 's', Lang::T('Data Deleted Successfully'));
2017-03-11 02:51:06 +07:00
}
break;
case 'add-post':
$name = _post('name');
2024-03-18 22:55:08 +03:00
$plan_type = _post('plan_type'); //Personal / Business
2023-10-03 15:46:55 +07:00
$radius = _post('radius');
2017-03-11 02:51:06 +07:00
$typebp = _post('typebp');
2022-08-23 16:33:21 +07:00
$limit_type = _post('limit_type');
$time_limit = _post('time_limit');
$time_unit = _post('time_unit');
$data_limit = _post('data_limit');
$data_unit = _post('data_unit');
$id_bw = _post('id_bw');
2023-08-15 13:24:44 +07:00
$price = _post('price');
2022-08-23 16:33:21 +07:00
$sharedusers = _post('sharedusers');
2017-03-11 02:51:06 +07:00
$validity = _post('validity');
2022-08-23 16:33:21 +07:00
$validity_unit = _post('validity_unit');
$routers = _post('routers');
2023-09-05 16:40:23 +07:00
$pool_expired = _post('pool_expired');
2024-02-19 18:03:40 +07:00
$list_expired = _post('list_expired');
2023-08-14 15:01:47 +07:00
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$msg = '';
2022-08-23 16:33:21 +07:00
if (Validator::UnsignedNumber($validity) == false) {
$msg .= 'The validity must be a number' . '<br>';
}
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
2017-03-11 02:51:06 +07:00
}
2023-10-03 15:46:55 +07:00
if ($name == '' or $id_bw == '' or $price == '' or $validity == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2017-03-11 02:51:06 +07:00
}
if (empty($radius)) {
2023-10-03 15:46:55 +07:00
if ($routers == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2023-10-03 15:46:55 +07:00
}
}
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->where('type', 'Hotspot')->find_one();
if ($d) {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Name Plan Already Exist') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-09-18 00:00:40 +07:00
run_hook('add_plan'); #HOOK
2022-08-23 16:33:21 +07:00
if ($msg == '') {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
2023-10-03 15:46:55 +07:00
$raddown = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitdown = 'M';
2023-10-03 15:46:55 +07:00
$raddown = '000000';
2022-08-23 16:33:21 +07:00
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
2023-10-03 15:46:55 +07:00
$radup = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitup = 'M';
2023-10-03 15:46:55 +07:00
$radup = '000000';
2022-08-23 16:33:21 +07:00
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
2024-05-07 08:11:16 +07:00
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
2024-02-19 18:03:40 +07:00
$rate = trim($rate . " " . $b['burst']);
2023-09-05 17:06:43 +07:00
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
// Create new plan
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->create();
$d->name_plan = $name;
$d->id_bw = $id_bw;
$d->price = $price_with_tax; // Set price with or without tax based on configuration
2022-08-23 16:33:21 +07:00
$d->type = 'Hotspot';
2017-03-11 02:51:06 +07:00
$d->typebp = $typebp;
2024-03-18 22:55:08 +03:00
$d->plan_type = $plan_type;
2022-08-23 16:33:21 +07:00
$d->limit_type = $limit_type;
$d->time_limit = $time_limit;
$d->time_unit = $time_unit;
$d->data_limit = $data_limit;
$d->data_unit = $data_unit;
$d->validity = $validity;
2017-03-11 02:51:06 +07:00
$d->validity_unit = $validity_unit;
2022-08-23 16:33:21 +07:00
$d->shared_users = $sharedusers;
if (!empty($radius)) {
2023-10-03 15:46:55 +07:00
$d->is_radius = 1;
$d->routers = '';
2023-10-04 11:37:32 +07:00
} else {
2023-10-03 15:46:55 +07:00
$d->is_radius = 0;
$d->routers = $routers;
}
2024-02-19 18:03:40 +07:00
$d->pool_expired = $pool_expired;
$d->list_expired = $list_expired;
2022-09-08 10:43:46 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = $prepaid;
2017-03-11 02:51:06 +07:00
$d->save();
2023-10-03 15:46:55 +07:00
$plan_id = $d->id();
2023-10-04 16:11:55 +07:00
if ($d['is_radius']) {
2023-10-12 13:27:34 +07:00
Radius::planUpSert($plan_id, $radiusRate);
2023-10-04 11:37:32 +07:00
} else {
2023-10-03 15:46:55 +07:00
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate);
if (!empty($pool_expired)) {
2023-10-03 15:46:55 +07:00
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
}
}
2022-08-23 16:33:21 +07:00
2024-02-13 13:54:01 +07:00
r2(U . 'services/hotspot', 's', Lang::T('Data Created Successfully'));
2022-08-23 16:33:21 +07:00
} else {
2017-03-11 02:51:06 +07:00
r2(U . 'services/add', 'e', $msg);
}
break;
case 'edit-post':
2022-08-23 16:33:21 +07:00
$id = _post('id');
2017-03-11 02:51:06 +07:00
$name = _post('name');
2024-03-18 22:55:08 +03:00
$plan_type = _post('plan_type');
2017-03-11 02:51:06 +07:00
$id_bw = _post('id_bw');
2022-08-23 16:33:21 +07:00
$typebp = _post('typebp');
2017-03-11 02:51:06 +07:00
$price = _post('price');
2022-08-23 16:33:21 +07:00
$limit_type = _post('limit_type');
$time_limit = _post('time_limit');
$time_unit = _post('time_unit');
$data_limit = _post('data_limit');
$data_unit = _post('data_unit');
$sharedusers = _post('sharedusers');
2017-03-11 02:51:06 +07:00
$validity = _post('validity');
2022-08-23 16:33:21 +07:00
$validity_unit = _post('validity_unit');
2023-09-05 16:40:23 +07:00
$pool_expired = _post('pool_expired');
2024-02-19 18:03:40 +07:00
$list_expired = _post('list_expired');
2023-08-14 15:01:47 +07:00
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
$routers = _post('routers');
2017-03-11 02:51:06 +07:00
$msg = '';
2022-08-23 16:33:21 +07:00
if (Validator::UnsignedNumber($validity) == false) {
$msg .= 'The validity must be a number' . '<br>';
}
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
2017-03-11 02:51:06 +07:00
}
2023-10-03 15:46:55 +07:00
if ($name == '' or $id_bw == '' or $price == '' or $validity == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
if ($d) {
} else {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Data Not Found') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-09-18 00:00:40 +07:00
run_hook('edit_plan'); #HOOK
2022-08-23 16:33:21 +07:00
if ($msg == '') {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
2023-10-03 15:46:55 +07:00
$raddown = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitdown = 'M';
2023-10-03 15:46:55 +07:00
$raddown = '000000';
2022-08-23 16:33:21 +07:00
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
2023-10-03 15:46:55 +07:00
$radup = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitup = 'M';
2023-10-03 15:46:55 +07:00
$radup = '000000';
2022-08-23 16:33:21 +07:00
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
2024-05-07 08:11:16 +07:00
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
2022-08-23 16:33:21 +07:00
2024-02-19 18:03:40 +07:00
$rate = trim($rate . " " . $b['burst']);
2023-10-04 16:11:55 +07:00
if ($d['is_radius']) {
2023-10-12 13:27:34 +07:00
Radius::planUpSert($id, $radiusRate);
2023-10-04 11:37:32 +07:00
} else {
2022-09-18 00:52:39 +07:00
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate);
if (!empty($pool_expired)) {
2023-09-15 14:03:23 +07:00
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
2023-09-05 17:06:43 +07:00
}
2022-08-23 16:33:21 +07:00
}
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
2017-03-11 02:51:06 +07:00
$d->name_plan = $name;
$d->id_bw = $id_bw;
$d->price = $price_with_tax; // Set price with or without tax based on configuration
2017-03-11 02:51:06 +07:00
$d->typebp = $typebp;
2022-08-23 16:33:21 +07:00
$d->limit_type = $limit_type;
$d->time_limit = $time_limit;
$d->time_unit = $time_unit;
$d->data_limit = $data_limit;
2024-03-18 22:55:08 +03:00
$d->plan_type = $plan_type;
2022-08-23 16:33:21 +07:00
$d->data_unit = $data_unit;
$d->validity = $validity;
2017-03-11 02:51:06 +07:00
$d->validity_unit = $validity_unit;
2022-08-23 16:33:21 +07:00
$d->shared_users = $sharedusers;
2023-09-05 16:40:23 +07:00
$d->pool_expired = $pool_expired;
2024-02-19 18:03:40 +07:00
$d->list_expired = $list_expired;
2022-09-08 10:43:46 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = $prepaid;
2017-03-11 02:51:06 +07:00
$d->save();
2022-08-23 16:33:21 +07:00
2024-02-13 13:54:01 +07:00
r2(U . 'services/hotspot', 's', Lang::T('Data Updated Successfully'));
2022-08-23 16:33:21 +07:00
} else {
r2(U . 'services/edit/' . $id, 'e', $msg);
2017-03-11 02:51:06 +07:00
}
break;
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
case 'pppoe':
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('PPPOE Plans'));
2022-08-23 16:33:21 +07:00
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/pppoe.js"></script>');
$name = _post('name');
if ($name != '') {
$query = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->where_like('tbl_plans.name_plan', '%' . $name . '%');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query, ['name' => $name]);
2022-08-23 16:33:21 +07:00
} else {
$query = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query);
2022-08-23 16:33:21 +07:00
}
$ui->assign('d', $d);
2022-09-18 00:00:40 +07:00
run_hook('view_list_ppoe'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('pppoe.tpl');
break;
case 'pppoe-add':
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('PPPOE Plans'));
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('d', $d);
$r = ORM::for_table('tbl_routers')->find_many();
$ui->assign('r', $r);
2022-09-18 00:00:40 +07:00
run_hook('view_add_ppoe'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('pppoe-add.tpl');
break;
case 'pppoe-edit':
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('PPPOE Plans'));
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
2022-08-23 16:33:21 +07:00
if ($d) {
$ui->assign('d', $d);
2023-10-04 11:37:32 +07:00
$p = ORM::for_table('tbl_pool')->where('routers', ($d['is_radius']) ? 'radius' : $d['routers'])->find_many();
2023-09-05 16:40:23 +07:00
$ui->assign('p', $p);
2022-08-23 16:33:21 +07:00
$b = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('b', $b);
2023-10-04 11:37:32 +07:00
$r = [];
2023-10-04 16:11:55 +07:00
if ($d['is_radius']) {
2023-10-04 11:37:32 +07:00
$r = ORM::for_table('tbl_routers')->find_many();
}
2022-08-23 16:33:21 +07:00
$ui->assign('r', $r);
2022-09-18 00:00:40 +07:00
run_hook('view_edit_ppoe'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('pppoe-edit.tpl');
2022-08-23 16:33:21 +07:00
} else {
2024-03-30 12:02:57 +07:00
r2(U . 'services/pppoe', 'e', Lang::T('Account Not Found'));
2017-03-11 02:51:06 +07:00
}
break;
case 'pppoe-delete':
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
2022-08-23 16:33:21 +07:00
if ($d) {
2022-09-18 00:00:40 +07:00
run_hook('delete_ppoe'); #HOOK
2023-10-04 16:11:55 +07:00
if ($d['is_radius']) {
Radius::planDelete($d['id']);
2023-10-16 13:54:34 +07:00
} else {
2023-10-24 12:27:30 +07:00
try {
$mikrotik = Mikrotik::info($d['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removePpoePlan($client, $d['name_plan']);
2023-10-24 12:27:30 +07:00
} catch (Exception $e) {
//ignore exception, it means router has already deleted
2024-02-19 18:03:40 +07:00
} catch (Throwable $e) {
//ignore exception, it means router has already deleted
}
2022-08-23 16:33:21 +07:00
}
2017-03-11 02:51:06 +07:00
$d->delete();
2024-02-13 13:54:01 +07:00
r2(U . 'services/pppoe', 's', Lang::T('Data Deleted Successfully'));
2017-03-11 02:51:06 +07:00
}
break;
case 'pppoe-add-post':
$name = _post('name_plan');
2024-03-18 22:55:08 +03:00
$plan_type = _post('plan_type');
2023-10-04 11:37:32 +07:00
$radius = _post('radius');
2022-08-23 16:33:21 +07:00
$id_bw = _post('id_bw');
$price = _post('price');
2017-03-11 02:51:06 +07:00
$validity = _post('validity');
2022-08-23 16:33:21 +07:00
$validity_unit = _post('validity_unit');
$routers = _post('routers');
$pool = _post('pool_name');
2023-09-05 16:40:23 +07:00
$pool_expired = _post('pool_expired');
2024-02-20 10:07:07 +07:00
$list_expired = _post('list_expired');
2023-08-14 15:01:47 +07:00
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$msg = '';
2022-08-23 16:33:21 +07:00
if (Validator::UnsignedNumber($validity) == false) {
$msg .= 'The validity must be a number' . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-08-23 16:33:21 +07:00
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
2017-03-11 02:51:06 +07:00
}
2023-10-04 11:37:32 +07:00
if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $pool == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2017-03-11 02:51:06 +07:00
}
if (empty($radius)) {
2023-10-04 11:37:32 +07:00
if ($routers == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2023-10-04 11:37:32 +07:00
}
}
2017-03-11 02:51:06 +07:00
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one();
if ($d) {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Name Plan Already Exist') . '<br>';
2022-08-23 16:33:21 +07:00
}
2022-09-18 00:00:40 +07:00
run_hook('add_ppoe'); #HOOK
2022-08-23 16:33:21 +07:00
if ($msg == '') {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
2023-10-04 11:37:32 +07:00
$raddown = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitdown = 'M';
2023-10-04 11:37:32 +07:00
$raddown = '000000';
2022-08-23 16:33:21 +07:00
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
2023-10-04 11:37:32 +07:00
$radup = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitup = 'M';
2023-10-04 11:37:32 +07:00
$radup = '000000';
2022-08-23 16:33:21 +07:00
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
2024-05-07 08:11:16 +07:00
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
2024-02-19 18:03:40 +07:00
$rate = trim($rate . " " . $b['burst']);
2022-08-23 16:33:21 +07:00
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->create();
$d->type = 'PPPOE';
2022-08-23 16:33:21 +07:00
$d->name_plan = $name;
2017-03-11 02:51:06 +07:00
$d->id_bw = $id_bw;
$d->price = $price_with_tax;
2024-03-18 22:55:08 +03:00
$d->plan_type = $plan_type;
2022-08-23 16:33:21 +07:00
$d->validity = $validity;
2017-03-11 02:51:06 +07:00
$d->validity_unit = $validity_unit;
2022-08-23 16:33:21 +07:00
$d->pool = $pool;
if (!empty($radius)) {
2023-10-04 11:37:32 +07:00
$d->is_radius = 1;
$d->routers = '';
} else {
$d->is_radius = 0;
$d->routers = $routers;
}
2024-02-20 10:07:07 +07:00
$d->pool_expired = $pool_expired;
$d->list_expired = $list_expired;
2022-09-08 10:43:46 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = $prepaid;
2017-03-11 02:51:06 +07:00
$d->save();
2023-10-04 11:37:32 +07:00
$plan_id = $d->id();
2023-10-04 16:11:55 +07:00
if ($d['is_radius']) {
2023-10-12 13:27:34 +07:00
Radius::planUpSert($plan_id, $radiusRate, $pool);
2023-10-04 11:37:32 +07:00
} else {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addPpoePlan($client, $name, $pool, $rate);
if (!empty($pool_expired)) {
2023-10-04 11:37:32 +07:00
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
}
}
2017-03-11 02:51:06 +07:00
2024-02-13 13:54:01 +07:00
r2(U . 'services/pppoe', 's', Lang::T('Data Created Successfully'));
2022-08-23 16:33:21 +07:00
} else {
2017-03-11 02:51:06 +07:00
r2(U . 'services/pppoe-add', 'e', $msg);
}
break;
case 'edit-pppoe-post':
2022-08-23 16:33:21 +07:00
$id = _post('id');
2024-03-18 22:55:08 +03:00
$plan_type = _post('plan_type');
2017-03-11 02:51:06 +07:00
$name = _post('name_plan');
2022-08-23 16:33:21 +07:00
$id_bw = _post('id_bw');
$price = _post('price');
2017-03-11 02:51:06 +07:00
$validity = _post('validity');
2022-08-23 16:33:21 +07:00
$validity_unit = _post('validity_unit');
$routers = _post('routers');
$pool = _post('pool_name');
2023-09-05 16:40:23 +07:00
$pool_expired = _post('pool_expired');
2024-02-20 10:07:07 +07:00
$list_expired = _post('list_expired');
2023-08-14 15:01:47 +07:00
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$msg = '';
2022-08-23 16:33:21 +07:00
if (Validator::UnsignedNumber($validity) == false) {
$msg .= 'The validity must be a number' . '<br>';
}
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
2017-03-11 02:51:06 +07:00
}
2023-10-04 11:37:32 +07:00
if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $pool == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
if ($d) {
} else {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Data Not Found') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-09-18 00:00:40 +07:00
run_hook('edit_ppoe'); #HOOK
2022-08-23 16:33:21 +07:00
if ($msg == '') {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
2023-10-04 11:37:32 +07:00
$raddown = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitdown = 'M';
2023-10-04 11:37:32 +07:00
$raddown = '000000';
2022-08-23 16:33:21 +07:00
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
2023-10-04 11:37:32 +07:00
$radup = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitup = 'M';
2023-10-04 11:37:32 +07:00
$radup = '000000';
2022-08-23 16:33:21 +07:00
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
2024-05-07 08:11:16 +07:00
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
2024-02-19 18:03:40 +07:00
$rate = trim($rate . " " . $b['burst']);
2022-08-23 16:33:21 +07:00
2023-10-04 16:11:55 +07:00
if ($d['is_radius']) {
2023-10-12 13:27:34 +07:00
Radius::planUpSert($id, $radiusRate, $pool);
2023-10-04 11:37:32 +07:00
} else {
2022-09-18 00:52:39 +07:00
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setPpoePlan($client, $name, $pool, $rate);
if (!empty($pool_expired)) {
2023-09-15 14:03:23 +07:00
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
2023-09-05 17:06:43 +07:00
}
2022-08-23 16:33:21 +07:00
}
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
2017-03-11 02:51:06 +07:00
$d->name_plan = $name;
$d->id_bw = $id_bw;
$d->price = $price_with_tax;
2024-03-18 22:55:08 +03:00
$d->plan_type = $plan_type;
2022-08-23 16:33:21 +07:00
$d->validity = $validity;
2017-03-11 02:51:06 +07:00
$d->validity_unit = $validity_unit;
2022-08-23 16:33:21 +07:00
$d->routers = $routers;
$d->pool = $pool;
2023-09-05 16:40:23 +07:00
$d->pool_expired = $pool_expired;
2024-02-20 10:07:07 +07:00
$d->list_expired = $list_expired;
2022-09-08 10:43:46 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = $prepaid;
2017-03-11 02:51:06 +07:00
$d->save();
2022-08-23 16:33:21 +07:00
2024-02-13 13:54:01 +07:00
r2(U . 'services/pppoe', 's', Lang::T('Data Updated Successfully'));
2022-08-23 16:33:21 +07:00
} else {
r2(U . 'services/pppoe-edit/' . $id, 'e', $msg);
2017-03-11 02:51:06 +07:00
}
break;
2023-08-14 15:01:47 +07:00
case 'balance':
$ui->assign('_title', Lang::T('Balance Plans'));
$name = _post('name');
if ($name != '') {
$query = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->where_like('tbl_plans.name_plan', '%' . $name . '%');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query, ['name' => $name]);
2023-08-14 15:01:47 +07:00
} else {
$query = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query);
2023-08-14 15:01:47 +07:00
}
$ui->assign('d', $d);
run_hook('view_list_balance'); #HOOK
$ui->display('balance.tpl');
break;
case 'balance-add':
$ui->assign('_title', Lang::T('Balance Plans'));
run_hook('view_add_balance'); #HOOK
$ui->display('balance-add.tpl');
break;
case 'balance-edit':
$ui->assign('_title', Lang::T('Balance Plans'));
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2023-08-14 15:01:47 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
$ui->assign('d', $d);
run_hook('view_edit_balance'); #HOOK
$ui->display('balance-edit.tpl');
break;
case 'balance-delete':
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2023-08-14 15:01:47 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
run_hook('delete_balance'); #HOOK
$d->delete();
2024-02-13 13:54:01 +07:00
r2(U . 'services/balance', 's', Lang::T('Data Deleted Successfully'));
2023-08-14 15:01:47 +07:00
}
break;
case 'balance-edit-post':
$id = _post('id');
$name = _post('name');
$price = _post('price');
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
2023-08-14 15:01:47 +07:00
$msg = '';
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
}
if ($name == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2023-08-14 15:01:47 +07:00
}
2022-08-23 16:33:21 +07:00
2023-08-14 15:01:47 +07:00
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
if ($d) {
} else {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Data Not Found') . '<br>';
2023-08-14 15:01:47 +07:00
}
run_hook('edit_ppoe'); #HOOK
if ($msg == '') {
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
2023-08-14 15:01:47 +07:00
$d->name_plan = $name;
$d->price = $price_with_tax;
2023-08-14 15:01:47 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = 'yes';
2023-08-14 15:01:47 +07:00
$d->save();
2024-02-13 13:54:01 +07:00
r2(U . 'services/balance', 's', Lang::T('Data Updated Successfully'));
2023-08-14 15:01:47 +07:00
} else {
r2(U . 'services/balance-edit/' . $id, 'e', $msg);
}
break;
case 'balance-add-post':
$name = _post('name');
$price = _post('price');
$enabled = _post('enabled');
$msg = '';
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
}
if ($name == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2023-08-14 15:01:47 +07:00
}
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one();
if ($d) {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Name Plan Already Exist') . '<br>';
2023-08-14 15:01:47 +07:00
}
run_hook('add_ppoe'); #HOOK
if ($msg == '') {
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
2023-08-14 15:01:47 +07:00
$d = ORM::for_table('tbl_plans')->create();
$d->type = 'Balance';
$d->name_plan = $name;
$d->id_bw = 0;
$d->price = $price_with_tax;
2023-08-14 15:01:47 +07:00
$d->validity = 0;
$d->validity_unit = 'Months';
$d->routers = '';
$d->pool = '';
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = 'yes';
2023-08-14 15:01:47 +07:00
$d->save();
2024-02-13 13:54:01 +07:00
r2(U . 'services/balance', 's', Lang::T('Data Created Successfully'));
2023-08-14 15:01:47 +07:00
} else {
r2(U . 'services/balance-add', 'e', $msg);
}
break;
2017-03-11 02:51:06 +07:00
default:
2023-09-27 15:01:48 +07:00
$ui->display('a404.tpl');
2022-08-23 16:33:21 +07:00
}