Fix edit customer plan

This commit is contained in:
Ibnu Maksum 2024-06-20 14:02:36 +07:00
parent b9ff4399a4
commit 29ad9dec73
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
8 changed files with 77 additions and 67 deletions

View File

@ -127,11 +127,19 @@ class Lang
if(time()>strtotime($datetime)){
$when = Lang::T('ago');
}else{
$when = Lang::T('later');
$when = '';
}
if (!$full)
$string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) .' '. $when : Lang::T('just now');
if($string){
if(empty($when)){
return '<b>'. implode(', ', $string) .'</b>';
}else{
return implode(', ', $string) .' '. $when;
}
}else{
return Lang::T('just now');
}
}
public static function nl2br($text)

View File

@ -37,20 +37,28 @@ switch ($action) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
set_time_limit(-1);
$plans = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many();
$turs = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many();
$log = '';
$router = '';
foreach ($plans as $plan) {
$p = ORM::for_table('tbl_plans')->findOne($plan['plan_id']);
$c = ORM::for_table('tbl_customers')->findOne($plan['customer_id']);
$dvc = Package::getDevice($plan);
if (file_exists($dvc) && $_app_stage != 'demo') {
require_once $dvc;
(new $p['device'])->add_customer($c, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
foreach ($turs as $tur) {
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
if($p){
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
if($c){
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
require_once $dvc;
(new $p['device'])->add_customer($c, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
$log .= "DONE : $tur[username], $ptur[namebp], $tur[type], $tur[routers]<br>";
}else{
$log .= "Customer NOT FOUND : $tur[username], $tur[namebp], $tur[type], $tur[routers]<br>";
}
}else{
$log .= "PLAN NOT FOUND : $tur[username], $tur[namebp], $tur[type], $tur[routers]<br>";
}
$log .= "DONE : $plan[username], $plan[namebp], $plan[type], $plan[routers]<br>";
}
r2(U . 'plan/list', 's', $log);
case 'recharge':
@ -235,12 +243,13 @@ switch ($action) {
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
if ($d) {
$ui->assign('d', $d);
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
if (in_array($admin['user_type'], array('SuperAdmin', 'Admin'))) {
$p = ORM::for_table('tbl_plans')->where_not_equal('type', 'Balance')->find_many();
$ps = ORM::for_table('tbl_plans')->where('type', $p['type'])->where('is_radius', $p['is_radius'])->find_many();
} else {
$p = ORM::for_table('tbl_plans')->where('enabled', '1')->where_not_equal('type', 'Balance')->find_many();
$ps = ORM::for_table('tbl_plans')->where("enabled", 1)->where('is_radius', $p['is_radius'])->where('type', $p['type'])->find_many();
}
$ui->assign('p', $p);
$ui->assign('p', $ps);
run_hook('view_edit_customer_plan'); #HOOK
$ui->assign('_title', 'Edit Plan');
$ui->display('plan-edit.tpl');
@ -274,7 +283,6 @@ switch ($action) {
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
$username = _post('username');
$id_plan = _post('id_plan');
$recharged_on = _post('recharged_on');
$expiration = _post('expiration');
@ -286,17 +294,14 @@ switch ($action) {
} else {
$msg .= Lang::T('Data Not Found') . '<br>';
}
$p = ORM::for_table('tbl_plans')->where('id', $id_plan)->where('enabled', '1')->find_one();
if ($d) {
$oldPlanID = $d['plan_id'];
$newPlan = ORM::for_table('tbl_plans')->where('id', $id_plan)->find_one();
if ($newPlan) {
} else {
$msg .= ' Plan Not Found<br>';
}
if ($msg == '') {
run_hook('edit_customer_plan'); #HOOK
$d->username = $username;
$d->plan_id = $id_plan;
$d->namebp = $p['name_plan'];
//$d->recharged_on = $recharged_on;
$d->expiration = $expiration;
$d->time = $time;
if ($d['status'] == 'off') {
@ -304,15 +309,29 @@ switch ($action) {
$d->status = 'on';
}
}
if ($p['is_radius']) {
$d->routers = 'radius';
} else {
$d->routers = $p['routers'];
if ($d['status'] == 'on' && $oldPlanID != $id_plan) {
$d->plan_id = $newPlan['id'];
$d->namebp = $newPlan['name_plan'];
$customer = User::_info($d['customer_id']);
//remove from old plan
$p = ORM::for_table('tbl_plans')->find_one($oldPlanID);
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
require_once $dvc;
(new $p['device'])->remove_customer($customer, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
//add new plan
$dvc = Package::getDevice($newPlan);
if (file_exists($dvc) && $_app_stage != 'demo') {
require_once $dvc;
(new $newPlan['device'])->add_customer($customer, $newPlan);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
$d->save();
if ($d['status'] == 'on') {
Package::changeTo($username, $id_plan, $id);
}
_log('[' . $admin['username'] . ']: ' . 'Edit Plan for Customer ' . $d['username'] . ' to [' . $d['namebp'] . '][' . Lang::moneyFormat($p['price']) . ']', $admin['user_type'], $admin['id']);
r2(U . 'plan/list', 's', Lang::T('Data Updated Successfully'));
} else {

View File

@ -35,15 +35,6 @@ class MikrotikHotspot
$this->removeHotspotActiveUser($client, $customer['username']);
}
function change_customer($customer, $plan)
{
$mikrotik = $this->info($plan['routers']);
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$this->removeHotspotUser($client, $customer['username']);
$this->removeHotspotActiveUser($client, $customer['username']);
$this->addHotspotUser($client, $plan, $customer);
}
function add_plan($plan)
{
$mikrotik = $this->info($plan['routers']);

View File

@ -35,16 +35,6 @@ class MikrotikPppoe
$this->removePpoeActive($client, $customer['username']);
}
function change_customer($customer, $plan)
{
$mikrotik = $this->info($plan['routers']);
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$this->removePpoeUser($client, $customer['username']);
$this->removePpoeActive($client, $customer['username']);
$this->addPpoeUser($client, $plan, $customer);
}
function add_plan($plan)
{
$mikrotik = $this->info($plan['routers']);

View File

@ -20,19 +20,13 @@ class Radius {
{
if (empty($plan['plan_expired'])) {
$p = ORM::for_table("tbl_plans")->find_one($plan['plan_expired']);
$this->customerDeactivate($customer['username']);
$this->customerAddPlan($customer, $p);
$this->customerAddPlan($customer, $plan);
} else {
$this->upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool_expired'], ':=');
$this->disconnectCustomer($customer['username']);
}
}
function change_customer($customer, $plan)
{
$this->customerUpsert($customer, $plan);
}
function add_plan($plan)
{
$bw = ORM::for_table("tbl_bandwidth")->find_one($plan['id_bw']);
@ -92,6 +86,7 @@ class Radius {
function disconnect_customer($customer, $router_name)
{
$this->disconnectCustomer($customer['username']);
}
public function getTableNas()

View File

@ -7,38 +7,42 @@ just follow the template
class FileName {
// Add Customer to Mikrotik/Device
function add_customer($customer, $plan)
{
}
// Remove Customer to Mikrotik/Device
function remove_customer($customer, $plan)
{
}
function change_customer($customer, $plan)
{
}
// Add Plan to Mikrotik/Device
function add_plan($plan)
{
}
// Update Plan to Mikrotik/Device
function update_plan($old_name, $plan)
{
}
// Remove Plan from Mikrotik/Device
function remove_plan($plan)
{
}
// check if customer is online
function online_customer($customer, $router_name)
{
}
// make customer online
function connect_customer($customer, $ip, $mac_address, $router_name)
{
}
// make customer disconnect
function disconnect_customer($customer, $router_name)
{
}

View File

@ -20,11 +20,15 @@
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Service Plan')}</label>
<div class="col-md-6">
<select id="id_plan" name="id_plan" class="form-control select2">
{foreach $p as $ps}
<option value="{$ps['id']}" {if $d['plan_id'] eq $ps['id']} selected {/if}>
{if $ps['enabled'] neq 1}DISABLED PLAN &bull; {/if}
{if $ps['is_radius']=='1'}Radius{else}{$ps['routers']}{/if} &bull; {$ps['name_plan']}</option>
{if $ps['enabled'] neq 1}DISABLED PLAN &bull; {/if}
{$ps['name_plan']} &bull;
{Lang::moneyFormat($ps['price'])}
{if $ps['prepaid'] neq 'yes'} &bull; POSTPAID {/if}
</option>
{/foreach}
</select>
</div>
@ -32,7 +36,7 @@
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Created On')}</label>
<div class="col-md-4">
<input type="date" class="form-control" name="expiration" readonly
<input type="date" class="form-control" readonly
value="{$d['recharged_on']}">
</div>
<div class="col-md-2">
@ -54,8 +58,7 @@
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success"
type="submit">{Lang::T('Edit')}</button>
<button class="btn btn-success" type="submit">{Lang::T('Edit')}</button>
Or <a href="{$_url}plan/list">{Lang::T('Cancel')}</a>
</div>
</div>

View File

@ -1,13 +1,13 @@
{include file="sections/user-header.tpl"}
<div class="row">
<div class="col-sm-12">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-info panel-hovered">
<div class="panel-heading">{Lang::T('Available Payment Gateway')}</div>
<div class="panel-footer">
<form method="post" action="{$_url}order/buy/{$route2}/{$route3}">
<div class="form-group row">
<label class="col-md-2 control-label">Payment Gateway</label>
<label class="col-md-4 ">Payment Gateway</label>
<div class="col-md-8">
<select name="gateway" id="gateway" class="form-control">
{foreach $pgs as $pg}