Add Edit Delete Balance Package

This commit is contained in:
Ibnu Maksum 2023-08-14 15:01:47 +07:00
parent a5a959eade
commit e27c0da2aa
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
15 changed files with 297 additions and 24 deletions

View File

@ -70,10 +70,10 @@ switch ($action) {
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
run_hook('delete_plan'); #HOOK
if(!$config['radius_mode']){
if (!$config['radius_mode']) {
$mikrotik = Mikrotik::info($d['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotPlan($client,$d['name_plan']);
Mikrotik::removeHotspotPlan($client, $d['name_plan']);
}
$d->delete();
@ -96,7 +96,7 @@ switch ($action) {
$validity = _post('validity');
$validity_unit = _post('validity_unit');
$routers = _post('routers');
$enabled = _post('enabled')*1;
$enabled = _post('enabled');
$msg = '';
if (Validator::UnsignedNumber($validity) == false) {
@ -130,7 +130,7 @@ switch ($action) {
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
if(!$config['radius_mode']){
if (!$config['radius_mode']) {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate);
@ -176,7 +176,7 @@ switch ($action) {
$validity = _post('validity');
$validity_unit = _post('validity_unit');
$routers = _post('routers');
$enabled = _post('enabled')*1;
$enabled = _post('enabled');
$msg = '';
if (Validator::UnsignedNumber($validity) == false) {
@ -209,7 +209,7 @@ switch ($action) {
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
if(!$config['radius_mode']){
if (!$config['radius_mode']) {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate);
@ -293,7 +293,7 @@ switch ($action) {
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
run_hook('delete_ppoe'); #HOOK
if(!$config['radius_mode']){
if (!$config['radius_mode']) {
$mikrotik = Mikrotik::info($d['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removePpoePlan($client, $d['name_plan']);
@ -312,7 +312,7 @@ switch ($action) {
$validity_unit = _post('validity_unit');
$routers = _post('routers');
$pool = _post('pool_name');
$enabled = _post('enabled')*1;
$enabled = _post('enabled');
$msg = '';
if (Validator::UnsignedNumber($validity) == false) {
@ -344,7 +344,7 @@ switch ($action) {
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
if(!$config['radius_mode']){
if (!$config['radius_mode']) {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addPpoePlan($client, $name, $pool, $rate);
@ -377,7 +377,7 @@ switch ($action) {
$validity_unit = _post('validity_unit');
$routers = _post('routers');
$pool = _post('pool_name');
$enabled = _post('enabled')*1;
$enabled = _post('enabled');
$msg = '';
if (Validator::UnsignedNumber($validity) == false) {
@ -410,7 +410,7 @@ switch ($action) {
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
if(!$config['radius_mode']){
if (!$config['radius_mode']) {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setPpoePlan($client, $name, $pool, $rate);
@ -431,7 +431,112 @@ switch ($action) {
r2(U . 'services/pppoe-edit/' . $id, 'e', $msg);
}
break;
case 'balance':
$ui->assign('_title', Lang::T('Balance Plans'));
$name = _post('name');
if ($name != '') {
$paginator = Paginator::bootstrap('tbl_plans', 'name_plan', '%' . $name . '%', 'type', 'Balance');
$d = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->where_like('tbl_plans.name_plan', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many();
} else {
$paginator = Paginator::bootstrap('tbl_plans', 'type', 'Hotspot');
$d = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many();
}
$ui->assign('d', $d);
$ui->assign('paginator', $paginator);
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'));
$id = $routes['2'];
$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':
$id = $routes['2'];
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
run_hook('delete_balance'); #HOOK
$d->delete();
r2(U . 'services/balance', 's', $_L['Delete_Successfully']);
}
break;
case 'balance-edit-post':
$id = _post('id');
$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 == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
if ($d) {
} else {
$msg .= $_L['Data_Not_Found'] . '<br>';
}
run_hook('edit_ppoe'); #HOOK
if ($msg == '') {
$d->name_plan = $name;
$d->price = $price;
$d->enabled = $enabled;
$d->save();
r2(U . 'services/balance', 's', $_L['Updated_Successfully']);
} 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 == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one();
if ($d) {
$msg .= $_L['Plan_already_exist'] . '<br>';
}
run_hook('add_ppoe'); #HOOK
if ($msg == '') {
$d = ORM::for_table('tbl_plans')->create();
$d->type = 'Balance';
$d->name_plan = $name;
$d->id_bw = 0;
$d->price = $price;
$d->validity = 0;
$d->validity_unit = 'Months';
$d->routers = '';
$d->pool = '';
$d->enabled = $enabled;
$d->save();
r2(U . 'services/balance', 's', $_L['Created_Successfully']);
} else {
r2(U . 'services/balance-add', 'e', $msg);
}
break;
default:
echo 'action not defined';
}

View File

@ -355,3 +355,4 @@ $_L['User_Cannot_change_this_only_admin_if_it_Empty_it_will_use_user_password']
$_L['Invoice_Balance_Message'] = 'Invoice Balance Message';
$_L['Invoice_Notification_Payment'] = 'Invoice Notification Payment';
$_L['Balance_Notification_Payment'] = 'Balance Notification Payment';
$_L['Balance_Plans'] = 'Balance Plans';

View File

@ -6,6 +6,8 @@
"ALTER TABLE `tbl_customers_meta` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;"
],
"2023.8.14": [
"ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '1' COMMENT 'For PPPOE Login' AFTER `password`;"
"ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '1' COMMENT 'For PPPOE Login' AFTER `password`;",
"ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
"ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;"
]
}

48
ui/ui/balance-add.tpl Normal file
View File

@ -0,0 +1,48 @@
{include file="sections/header.tpl"}
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="panel panel-primary panel-hovered panel-stacked mb30">
<div class="panel-heading">{$_L['Add_Plan']}</div>
<div class="panel-body">
<form class="form-horizontal" method="post" role="form" action="{$_url}services/balance-add-post" >
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Status')}</label>
<div class="col-md-10">
<label class="radio-inline warning">
<input type="radio" checked name="enabled" value="1"> Enable
</label>
<label class="radio-inline">
<input type="radio" name="enabled" value="0"> Disable
</label>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Name']}</label>
<div class="col-md-6">
<input type="text" required class="form-control" id="name" name="name" maxlength="40" placeholder="Topup 100">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Price']}</label>
<div class="col-md-6">
<div class="input-group">
<span class="input-group-addon">{$_c['currency_code']}</span>
<input type="number" class="form-control" name="price" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success waves-effect waves-light" type="submit">{$_L['Save']}</button>
Or <a href="{$_url}services/balance">{$_L['Cancel']}</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{include file="sections/footer.tpl"}

49
ui/ui/balance-edit.tpl Normal file
View File

@ -0,0 +1,49 @@
{include file="sections/header.tpl"}
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="panel panel-primary panel-hovered panel-stacked mb30">
<div class="panel-heading">{$_L['Edit_Plan']}</div>
<div class="panel-body">
<form class="form-horizontal" method="post" role="form" action="{$_url}services/balance-edit-post">
<input type="hidden" name="id" value="{$d['id']}">
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Status')}</label>
<div class="col-md-10">
<label class="radio-inline warning">
<input type="radio" checked name="enabled" value="1"> Enable
</label>
<label class="radio-inline">
<input type="radio" name="enabled" value="0"> Disable
</label>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Name']}</label>
<div class="col-md-6">
<input type="text" required class="form-control" id="name" value="{$d['name_plan']}" name="name" maxlength="40" placeholder="Topup 100">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Price']}</label>
<div class="col-md-6">
<div class="input-group">
<span class="input-group-addon">{$_c['currency_code']}</span>
<input type="number" class="form-control" name="price" value="{$d['price']}" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success waves-effect waves-light" type="submit">{$_L['Save']}</button>
Or <a href="{$_url}services/balance">{$_L['Cancel']}</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{include file="sections/footer.tpl"}

56
ui/ui/balance.tpl Normal file
View File

@ -0,0 +1,56 @@
{include file="sections/header.tpl"}
<div class="row">
<div class="col-sm-12">
<div class="panel panel-hovered mb20 panel-primary">
<div class="panel-heading">{Lang::T('Balance Plans')}</div>
<div class="panel-body">
<div class="md-whiteframe-z1 mb20 text-center" style="padding: 15px">
<div class="col-md-8">
<form id="site-search" method="post" action="{$_url}services/balance/">
<div class="input-group">
<div class="input-group-addon">
<span class="fa fa-search"></span>
</div>
<input type="text" name="name" class="form-control" placeholder="{$_L['Search_by_Name']}...">
<div class="input-group-btn">
<button class="btn btn-success" type="submit">{$_L['Search']}</button>
</div>
</div>
</form>
</div>
<div class="col-md-4">
<a href="{$_url}services/balance-add" class="btn btn-primary btn-block waves-effect"><i class="ion ion-android-add"> </i> {$_L['New_Plan']}</a>
</div>&nbsp;
</div>
<div class="table-responsive">
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>{$_L['Plan_Name']}</th>
<th>{$_L['Plan_Price']}</th>
<th>{$_L['Manage']}</th>
</tr>
</thead>
<tbody>
{foreach $d as $ds}
<tr {if $ds['enabled'] != 1}class="danger" title="disabled"{/if}>
<td>{$ds['name_plan']}</td>
<td>{Lang::moneyFormat($ds['price'])}</td>
<td>
<a href="{$_url}services/balance-edit/{$ds['id']}" class="btn btn-info btn-xs">{$_L['Edit']}</a>
<a href="{$_url}services/balance-delete/{$ds['id']}" onclick="return confirm('{$_L['Delete']}?')" id="{$ds['id']}" class="btn btn-danger btn-xs">{$_L['Delete']}</a>
</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
{$paginator['contents']}
</div>
</div>
</div>
</div>
{include file="sections/footer.tpl"}

View File

@ -21,7 +21,6 @@
<label class="col-md-2 control-label">{$_L['Plan_Name']}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="name" name="name" maxlength="40">
<p class="help-block">{Lang::T('Cannot be change after saved')}</p>
</div>
</div>
<div class="form-group">
@ -83,7 +82,10 @@
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Price']}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="pricebp" name="pricebp">
<div class="input-group">
<span class="input-group-addon">{$_c['currency_code']}</span>
<input type="number" class="form-control" name="pricebp" required>
</div>
</div>
</div>
<div class="form-group">

View File

@ -21,7 +21,7 @@
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Name']}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="name" name="name" maxlength="40" value="{$d['name_plan']}" readonly>
<input type="text" class="form-control" id="name" name="name" maxlength="40" value="{$d['name_plan']}">
</div>
</div>
<div class="form-group">
@ -82,7 +82,10 @@
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Price']}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="price" name="price" value="{$d['price']}">
<div class="input-group">
<span class="input-group-addon">{$_c['currency_code']}</span>
<input type="number" class="form-control" name="pricebp" value="{$d['price']}" required>
</div>
</div>
</div>
<div class="form-group">

View File

@ -51,7 +51,7 @@
<td>{$ds['routers']}</td>
<td>
<a href="{$_url}services/edit/{$ds['id']}" class="btn btn-info btn-xs">{$_L['Edit']}</a>
<a href="{$_url}services/delete/{$ds['id']}" id="{$ds['id']}" class="btn btn-danger btn-xs">{$_L['Delete']}</a>
<a href="{$_url}services/delete/{$ds['id']}" id="{$ds['id']}" onclick="return confirm('{$_L['Delete']}?')" class="btn btn-danger btn-xs">{$_L['Delete']}</a>
</td>
</tr>
{/foreach}

View File

@ -47,7 +47,7 @@
<td align="center">
<a href="{$_url}pool/edit/{$ds['id']}"
class="btn btn-info btn-xs">{$_L['Edit']}</a>
<a href="{$_url}pool/delete/{$ds['id']}" id="{$ds['id']}"
<a href="{$_url}pool/delete/{$ds['id']}" id="{$ds['id']}" onclick="return confirm('{$_L['Delete']}?')"
class="btn btn-danger btn-xs">{$_L['Delete']}</a>
</td>
</tr>

View File

@ -21,7 +21,6 @@
<label class="col-md-2 control-label">{$_L['Plan_Name']}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="name_plan" maxlength="40" name="name_plan">
<p class="help-block">{Lang::T('Cannot be change after saved')}</p>
</div>
</div>
<div class="form-group">
@ -38,7 +37,10 @@
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Price']}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="price" name="price">
<div class="input-group">
<span class="input-group-addon">{$_c['currency_code']}</span>
<input type="number" class="form-control" name="price" required>
</div>
</div>
</div>
<div class="form-group">

View File

@ -21,7 +21,7 @@
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Name']}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="name_plan" maxlength="40" name="name_plan" value="{$d['name_plan']}" readonly>
<input type="text" class="form-control" id="name_plan" maxlength="40" name="name_plan" value="{$d['name_plan']}">
</div>
</div>
<div class="form-group">
@ -37,7 +37,10 @@
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Price']}</label>
<div class="col-md-6">
<input type="text" class="form-control" id="price" name="price" value="{$d['price']}">
<div class="input-group">
<span class="input-group-addon">{$_c['currency_code']}</span>
<input type="number" class="form-control" name="price" required value="{$d['price']}">
</div>
</div>
</div>
<div class="form-group">

View File

@ -47,7 +47,7 @@
<td>{$ds['routers']}</td>
<td>
<a href="{$_url}services/pppoe-edit/{$ds['id']}" class="btn btn-info btn-xs">{$_L['Edit']}</a>
<a href="{$_url}services/pppoe-delete/{$ds['id']}" id="{$ds['id']}" class="btn btn-danger btn-xs">{$_L['Delete']}</a>
<a href="{$_url}services/pppoe-delete/{$ds['id']}" onclick="return confirm('{$_L['Delete']}?')" id="{$ds['id']}" class="btn btn-danger btn-xs">{$_L['Delete']}</a>
</td>
</tr>
{/foreach}

View File

@ -50,7 +50,7 @@
<td>
<a href="{$_url}routers/edit/{$ds['id']}"
class="btn btn-info btn-xs">{$_L['Edit']}</a>
<a href="{$_url}routers/delete/{$ds['id']}" id="{$ds['id']}" class="btn btn-danger btn-xs">{$_L['Delete']}</a>
<a href="{$_url}routers/delete/{$ds['id']}" id="{$ds['id']}" onclick="return confirm('{$_L['Delete']}?')" class="btn btn-danger btn-xs">{$_L['Delete']}</a>
</td>
</tr>
{/foreach}

View File

@ -157,6 +157,8 @@
href="{$_url}services/pppoe">{$_L['PPPOE_Plans']}</a></li>
<li {if $_routes[1] eq 'list'}class="active" {/if}><a
href="{$_url}bandwidth/list">{$_L['Bandwidth_Plans']}</a></li>
<li {if $_routes[1] eq 'balance'}class="active" {/if}><a
href="{$_url}services/balance">{Lang::T('Balance Plans')}</a></li>
{$_MENU_SERVICES}
</ul>
</li>