Plan For Expired Customer

This commit is contained in:
Ibnu Maksum 2024-06-11 13:28:05 +07:00
parent 55b32ce0da
commit e685c5d702
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
13 changed files with 72 additions and 169 deletions

View File

@ -330,4 +330,6 @@ ALTER TABLE `tbl_customers` ADD `status` ENUM('Active','Banned','Disabled') NOT
ALTER TABLE `tbl_customers` CHANGE `status` `status` ENUM('Active','Banned','Disabled','Inactive','Limited','Suspended') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'Active';
ALTER TABLE `tbl_plans` ADD `price_old` VARCHAR(40) NOT NULL DEFAULT '' AFTER `price`;
ALTER TABLE `tbl_plans` ADD `device` VARCHAR(32) NOT NULL DEFAULT '' AFTER `plan_type`;
ALTER TABLE `tbl_pool` ADD `local_ip` VARCHAR(40) NOT NULL DEFAULT '' AFTER `pool_name`;
ALTER TABLE `tbl_pool` ADD `local_ip` VARCHAR(40) NOT NULL DEFAULT '' AFTER `pool_name`;
ALTER TABLE `tbl_plans` ADD `plan_expired` INT NOT NULL DEFAULT '0' AFTER `pool`;
ALTER TABLE `tbl_plans` DROP `pool_expired`, DROP `list_expired`;

View File

@ -15,10 +15,6 @@ if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php';
switch ($action) {
case 'sync':
set_time_limit(-1);
@ -31,10 +27,6 @@ switch ($action) {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_plan($plan);
if (!empty($plan['pool_expired'])) {
$plan->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
(new $p['device'])->add_plan($plan);
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
@ -49,10 +41,6 @@ switch ($action) {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_plan($plan);
if (!empty($plan['pool_expired'])) {
$plan->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
(new $p['device'])->add_plan($plan);
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
@ -84,9 +72,9 @@ switch ($action) {
$ui->assign('r', $r);
$devices = [];
$files = scandir($DEVICE_PATH);
foreach($files as $file){
foreach ($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext == 'php'){
if ($ext == 'php') {
$devices[] = pathinfo($file, PATHINFO_FILENAME);
}
}
@ -99,28 +87,33 @@ switch ($action) {
$id = $routes['2'];
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
if(empty($d['device'])){
if($d['is_radius']){
if (empty($d['device'])) {
if ($d['is_radius']) {
$d->device = 'Radius';
}else{
} else {
$d->device = 'MikrotikHotspot';
}
$d->save();
}
$ui->assign('d', $d);
$p = ORM::for_table('tbl_pool')->where('routers', $d['routers'])->find_many();
$ui->assign('p', $p);
$b = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('b', $b);
$devices = [];
$files = scandir($DEVICE_PATH);
foreach($files as $file){
foreach ($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext == 'php'){
if ($ext == 'php') {
$devices[] = pathinfo($file, PATHINFO_FILENAME);
}
}
$ui->assign('devices', $devices);
//select expired plan
if($d['is_radius']){
$exps = ORM::for_table('tbl_plans')->selects('id','name_plan')->where("is_radius", 1)->findArray();
}else{
$exps = ORM::for_table('tbl_plans')->selects('id','name_plan')->where("routers", $d['routers'])->findArray();
}
$ui->assign('exps', $exps);
run_hook('view_edit_plan'); #HOOK
$ui->display('hotspot-edit.tpl');
} else {
@ -164,8 +157,6 @@ switch ($action) {
$validity_unit = _post('validity_unit');
$routers = _post('routers');
$device = _post('device');
$pool_expired = _post('pool_expired');
$list_expired = _post('list_expired');
$enabled = _post('enabled');
$prepaid = _post('prepaid');
@ -215,8 +206,6 @@ switch ($action) {
$d->is_radius = 0;
$d->routers = $routers;
}
$d->pool_expired = $pool_expired;
$d->list_expired = $list_expired;
$d->enabled = $enabled;
$d->prepaid = $prepaid;
$d->device = $device;
@ -226,14 +215,6 @@ switch ($action) {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_plan($d);
if (!empty($pool_expired)) {
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
$d->rate_down_unit = "Kbps";
$d->rate_up_unit == 'Kbps';
$d->rate_up = '512';
$d->rate_down = '512';
(new $p['device'])->add_plan($d);
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
@ -260,8 +241,7 @@ switch ($action) {
$sharedusers = _post('sharedusers');
$validity = _post('validity');
$validity_unit = _post('validity_unit');
$pool_expired = _post('pool_expired');
$list_expired = _post('list_expired');
$plan_expired = _post('plan_expired', '0');
$device = _post('device');
$enabled = _post('enabled');
$prepaid = _post('prepaid');
@ -317,8 +297,7 @@ switch ($action) {
$d->validity = $validity;
$d->validity_unit = $validity_unit;
$d->shared_users = $sharedusers;
$d->pool_expired = $pool_expired;
$d->list_expired = $list_expired;
$d->plan_expired = $plan_expired;
$d->enabled = $enabled;
$d->prepaid = $prepaid;
$d->device = $device;
@ -328,15 +307,6 @@ switch ($action) {
if (file_exists($dvc)) {
require_once $dvc;
(new $d['device'])->update_plan($old, $d);
if (!empty($pool_expired)) {
$old->name_plan = 'EXPIRED NUXBILL ' . $old['pool_expired'];
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
$d->rate_down_unit = "Kbps";
$d->rate_up_unit == 'Kbps';
$d->rate_up = '512';
$d->rate_down = '512';
(new $d['device'])->update_plan($old, $d);
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
@ -373,9 +343,9 @@ switch ($action) {
$ui->assign('r', $r);
$devices = [];
$files = scandir($DEVICE_PATH);
foreach($files as $file){
foreach ($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext == 'php'){
if ($ext == 'php') {
$devices[] = pathinfo($file, PATHINFO_FILENAME);
}
}
@ -389,10 +359,10 @@ switch ($action) {
$id = $routes['2'];
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
if(empty($d['device'])){
if($d['is_radius']){
if (empty($d['device'])) {
if ($d['is_radius']) {
$d->device = 'Radius';
}else{
} else {
$d->device = 'MikrotikPppoe';
}
$d->save();
@ -409,13 +379,20 @@ switch ($action) {
$ui->assign('r', $r);
$devices = [];
$files = scandir($DEVICE_PATH);
foreach($files as $file){
foreach ($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext == 'php'){
if ($ext == 'php') {
$devices[] = pathinfo($file, PATHINFO_FILENAME);
}
}
$ui->assign('devices', $devices);
//select expired plan
if($d['is_radius']){
$exps = ORM::for_table('tbl_plans')->selects('id','name_plan')->where("is_radius", 1)->findArray();
}else{
$exps = ORM::for_table('tbl_plans')->selects('id','name_plan')->where("routers", $d['routers'])->findArray();
}
$ui->assign('exps', $exps);
run_hook('view_edit_ppoe'); #HOOK
$ui->display('pppoe-edit.tpl');
} else {
@ -454,8 +431,6 @@ switch ($action) {
$routers = _post('routers');
$device = _post('device');
$pool = _post('pool_name');
$pool_expired = _post('pool_expired');
$list_expired = _post('list_expired');
$enabled = _post('enabled');
$prepaid = _post('prepaid');
@ -516,8 +491,6 @@ switch ($action) {
$d->is_radius = 0;
$d->routers = $routers;
}
$d->pool_expired = $pool_expired;
$d->list_expired = $list_expired;
$d->enabled = $enabled;
$d->prepaid = $prepaid;
$d->device = $device;
@ -527,10 +500,6 @@ switch ($action) {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_plan($d);
if (!empty($pool_expired)) {
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
(new $p['device'])->add_plan($d);
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
@ -552,8 +521,7 @@ switch ($action) {
$routers = _post('routers');
$device = _post('device');
$pool = _post('pool_name');
$pool_expired = _post('pool_expired');
$list_expired = _post('list_expired');
$plan_expired = _post('plan_expired');
$enabled = _post('enabled');
$prepaid = _post('prepaid');
@ -603,8 +571,7 @@ switch ($action) {
$d->validity_unit = $validity_unit;
$d->routers = $routers;
$d->pool = $pool;
$d->pool_expired = $pool_expired;
$d->list_expired = $list_expired;
$d->plan_expired = $plan_expired;
$d->enabled = $enabled;
$d->prepaid = $prepaid;
$d->device = $device;
@ -614,15 +581,6 @@ switch ($action) {
if (file_exists($dvc)) {
require_once $dvc;
(new $d['device'])->update_plan($old, $d);
if (!empty($pool_expired)) {
$old->name_plan = 'EXPIRED NUXBILL ' . $old['pool_expired'];
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
$d->rate_down_unit = "Kbps";
$d->rate_up_unit == 'Kbps';
$d->rate_up = '512';
$d->rate_down = '512';
(new $d['device'])->update_plan($old, $d);
}
} else {
new Exception(Lang::T("Devices Not Found"));
}

View File

@ -34,8 +34,9 @@ class MikrotikHotspot
}
$mikrotik = $this->info($plan['routers']);
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
if (!empty($plan['pool_expired'])) {
$this->setHotspotUserPackage($client, $customer['username'], 'EXPIRED NUXBILL ' . $plan['pool_expired']);
if (!empty($plan['plan_expired'])) {
$p = ORM::for_table("tbl_plans")->select("name_plan")->find_one($plan['plan_expired']);
$this->setHotspotUserPackage($client, $customer['username'], $p['name_plan']);
} else {
$this->removeHotspotUser($client, $customer['username']);
}
@ -322,7 +323,7 @@ class MikrotikHotspot
$client->sendSync($setRequest);
}
function setHotspotUserPackage($client, $user, $plan)
function setHotspotUserPackage($client, $user, $plan_name)
{
global $_app_stage;
if ($_app_stage == 'demo') {
@ -335,7 +336,7 @@ class MikrotikHotspot
$setRequest = new RouterOS\Request('/ip/hotspot/user/set');
$setRequest->setArgument('numbers', $id);
$setRequest->setArgument('profile', $plan);
$setRequest->setArgument('profile', $plan_name);
$client->sendSync($setRequest);
}

View File

@ -34,8 +34,9 @@ class MikrotikPppoe
}
$mikrotik = $this->info($plan['routers']);
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
if (!empty($plan['pool_expired'])) {
$this->setPpoeUserPlan($client, $customer['username'], 'EXPIRED NUXBILL ' . $plan['pool_expired']);
if (!empty($plan['plan_expired'])) {
$p = ORM::for_table("tbl_plans")->select("name_plan")->find_one($plan['plan_expired']);
$this->setPpoeUserPlan($client, $customer['username'], $p['plan_expired']);
} else {
$this->removePpoeUser($client, $customer['username']);
}

View File

@ -23,8 +23,10 @@ class Radius {
if ($_app_stage == 'demo') {
return;
}
if (empty($plan['pool_expired'])) {
if (empty($plan['plan_expired'])) {
$p = ORM::for_table("tbl_plans")->find_one($plan['plan_expired']);
$this->customerDeactivate($customer['username']);
$this->customerAddPlan($customer, $p);
} else {
$this->upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool_expired'], ':=');
$this->disconnectCustomer($customer['username']);

View File

@ -633,5 +633,7 @@
"Zip_Code": "Zip Code",
"Local_IP": "Local IP",
"": "",
"Device": "Device"
"Device": "Device",
"Expired_Internet_Plan": "Expired Internet Plan",
"When_Expired__customer_will_be_move_to_selected_internet_plan": "When Expired, customer will be move to selected internet plan"
}

View File

@ -109,5 +109,9 @@
],
"2024.6.10" : [
"ALTER TABLE `tbl_pool` ADD `local_ip` VARCHAR(40) NOT NULL DEFAULT '' AFTER `pool_name`;"
],
"2024.6.11" : [
"ALTER TABLE `tbl_plans` ADD `plan_expired` INT NOT NULL DEFAULT '0' AFTER `pool`;",
"ALTER TABLE `tbl_plans` DROP `pool_expired`, DROP `list_expired`;"
]
}

View File

@ -169,22 +169,6 @@
</div>
</div>
</span>
<legend>{Lang::T('Expired Action')} <sub>{Lang::T('Optional')}</sub></legend>
<div class="form-group" id="ipPool">
<label class="col-md-2 control-label"><a
href="{$_url}pool/add">{Lang::T('Expired IP Pool')}</a></label>
<div class="col-md-6">
<select id="pool_expired" name="pool_expired" class="form-control select2">
<option value=''>{Lang::T('Select Pool')}</option>
</select>
</div>
</div>
{* <div class="form-group" id="AddressList">
<label class="col-md-2 control-label">{Lang::T('Address List')}</label>
<div class="col-md-6">
<input type="text" class="form-control" name="list_expired" id="list_expired">
</div>
</div> *}
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button class="btn btn-success" type="submit">{Lang::T('Save Changes')}</button>

View File

@ -179,8 +179,7 @@
{/if}
</select>
</div>
<p class="help-block col-md-4">{Lang::T('1 Period = 1 Month, Expires the 20th of each month')}
</p>
<p class="help-block col-md-4">{Lang::T('1 Period = 1 Month, Expires the 20th of each month')}</p>
</div>
<span id="routerChoose" class="{if $d['is_radius']}hidden{/if}">
<div class="form-group">
@ -194,24 +193,18 @@
</span>
<legend>{Lang::T('Expired Action')} <sub>{Lang::T('Optional')}</sub></legend>
<div class="form-group">
<label class="col-md-2 control-label"><a
href="{$_url}pool/add">{Lang::T('Expired IP Pool')}</a></label>
<label class="col-md-2 control-label">{Lang::T('Expired Internet Plan')}</label>
<div class="col-md-6">
<select id="pool_expired" name="pool_expired" class="form-control select2">
<option value=''>{Lang::T('Select Pool')}</option>
{foreach $p as $ps}
<option value="{$ps['pool_name']}" {if $d['pool_expired'] eq $ps['pool_name']} selected
{/if}>{$ps['pool_name']}</option>
<select id="plan_expired" name="plan_expired" class="form-control select2">
<option value='0'>Default - Remove Customer</option>
{foreach $exps as $exp}
<option value="{$exp['id']}" {if $d['plan_expired'] eq $exp['id']} selected
{/if}>{$exp['name_plan']}</option>
{/foreach}
</select>
</div>
<p class="help-block col-md-4">{Lang::T('When Expired, customer will be move to selected internet plan')}</p>
</div>
{* <div class="form-group" id="AddressList">
<label class="col-md-2 control-label">{Lang::T('Address List')}</label>
<div class="col-md-6">
<input type="text" class="form-control" name="list_expired" id="list_expired" value="{$d['list_expired']}">
</div>
</div> *}
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button class="btn btn-success" type="submit">{Lang::T('Save Changes')}</button>

View File

@ -45,7 +45,7 @@
<th>{Lang::T('Plan Validity')}</th>
<th>{Lang::T('Routers')}</th>
<th>{Lang::T('Device')}</th>
<th>{Lang::T('Expired IP Pool')}</th>
<th>{Lang::T('Expired Internet Plan')}</th>
<th>{Lang::T('ID')}</th>
<th>{Lang::T('Manage')}</th>
</tr>
@ -72,8 +72,7 @@
{/if}
</td>
<td>{$ds['device']}</td>
<td>{$ds['pool_expired']}{if $ds['list_expired']}{if $ds['pool_expired']} |
{/if}{$ds['list_expired']}{/if}</td>
<td>{if $ds['plan_expired']}<a href="{$_url}services/edit/{$ds['plan_expired']}">Yes</a>{else}No{/if}</td>
<td>{$ds['id']}</td>
<td>
<a href="{$_url}services/edit/{$ds['id']}"

View File

@ -117,22 +117,6 @@
</select>
</div>
</div>
<legend>{Lang::T('Expired Action')} <sub>{Lang::T('Optional')}</sub></legend>
<div class="form-group" id="ipPool">
<label class="col-md-2 control-label"><a
href="{$_url}pool/add">{Lang::T('Expired IP Pool')}</a></label>
<div class="col-md-6">
<select id="pool_expired" name="pool_expired" class="form-control select2">
<option value=''>{Lang::T('Select Pool')}</option>
</select>
</div>
</div>
{* <div class="form-group" id="AddressList">
<label class="col-md-2 control-label">{Lang::T('Address List')}</label>
<div class="col-md-6">
<input type="text" class="form-control" name="list_expired" id="list_expired">
</div>
</div> *}
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button class="btn btn-primary" type="submit">{Lang::T('Save Changes')}</button>

View File

@ -136,24 +136,18 @@
</div>
<legend>{Lang::T('Expired Action')} <sub>{Lang::T('Optional')}</sub></legend>
<div class="form-group">
<label class="col-md-2 control-label"><a
href="{$_url}pool/add">{Lang::T('Expired IP Pool')}</a></label>
<label class="col-md-2 control-label">{Lang::T('Expired Internet Plan')}</label>
<div class="col-md-6">
<select id="pool_expired" name="pool_expired" class="form-control select2">
<option value=''>{Lang::T('Select Pool')}</option>
{foreach $p as $ps}
<option value="{$ps['pool_name']}" {if $d['pool_expired'] eq $ps['pool_name']} selected
{/if}>{$ps['pool_name']}</option>
<select id="plan_expired" name="plan_expired" class="form-control select2">
<option value='0'>Default - Remove Customer</option>
{foreach $exps as $exp}
<option value="{$exp['id']}" {if $d['plan_expired'] eq $exp['id']} selected
{/if}>{$exp['name_plan']}</option>
{/foreach}
</select>
</div>
<p class="help-block col-md-4">{Lang::T('When Expired, customer will be move to selected internet plan')}</p>
</div>
{* <div class="form-group" id="AddressList">
<label class="col-md-2 control-label">{Lang::T('Address List')}</label>
<div class="col-md-6">
<input type="text" class="form-control" name="list_expired" id="list_expired" value="{$d['list_expired']}">
</div>
</div> *}
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success" type="submit">{Lang::T('Save Changes')}</button>
@ -181,22 +175,4 @@
$("#validity_unit").html(postOpt);
}
</script>
{if $_c['radius_enable'] && $d['is_radius']}
{literal}
<script>
document.getElementById("routers").required = false;
document.getElementById("routers").disabled = true;
setTimeout(() => {
$.ajax({
url: "index.php?_route=autoload/pool",
data: "routers=radius",
cache: false,
success: function(msg) {
$("#pool_expired").html(msg);
}
});
}, 2000);
</script>
{/literal}
{/if}
{include file="sections/footer.tpl"}

View File

@ -41,7 +41,7 @@
<th>{Lang::T('Plan Price')}</th>
<th>{Lang::T('Plan Validity')}</th>
<th>{Lang::T('IP Pool')}</th>
<th>{Lang::T('Expired IP Pool')}</th>
<th>{Lang::T('Expired Internet Plan')}</th>
<th>{Lang::T('Routers')}</th>
<th>{Lang::T('Device')}</th>
<th>{Lang::T('Manage')}</th>
@ -57,10 +57,7 @@
<td>{Lang::moneyFormat($ds['price'])}</td>
<td>{$ds['validity']} {$ds['validity_unit']}</td>
<td>{$ds['pool']}</td>
<td>{$ds['pool_expired']}{if $ds['list_expired']}
{if $ds['pool_expired']} |
{/if}{$ds['list_expired']}
{/if}</td>
<td>{if $ds['plan_expired']}<a href="{$_url}services/edit/{$ds['plan_expired']}">Yes</a>{else}No{/if}</td>
<td>
{if $ds['is_radius']}
<span class="label label-primary">RADIUS</span>