Sync Customer to mikrotik

This commit is contained in:
Ibnu Maksum 2023-09-15 11:33:46 +07:00
parent 84cd66ea9a
commit 609cf4b69d
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
3 changed files with 28 additions and 1 deletions

View File

@ -45,7 +45,29 @@ switch ($action) {
run_hook('view_add_customer'); #HOOK
$ui->display('customers-add.tpl');
break;
case 'sync':
case 'sync':
$id_customer = $routes['2'];
$b = ORM::for_table('tbl_user_recharges')->where('customer_id', $id_customer)->where('status', 'on')->find_one();
if($b){
$mikrotik = Mikrotik::info($b['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$c = ORM::for_table('tbl_customers')->find_one($id_customer);
$p = ORM::for_table('tbl_plans')->where('id', $b['plan_id'])->where('enabled', '1')->find_one();
if($p){
if($b['type']=='Hotspot'){
Mikrotik::addHotspotUser($client, $p, $c);
}else if($b['type']=='PPPOE'){
Mikrotik::addPpoeUser($client, $p, $c);
}
r2(U . 'customers/view/'.$id_customer , 's', 'success sync customer to Mikrotik');
}else{
r2(U . 'customers/view/'.$id_customer , 'e', 'Customer plan is inactive');
}
}
r2(U . 'customers/view/'.$id_customer , 'e', 'Cannot find active plan');
break;
case 'viewu':
$customer = ORM::for_table('tbl_customers')->where('username', $routes['2'])->find_one();
case 'view':

View File

@ -65,6 +65,9 @@ switch ($action) {
$ui->assign('p', $p);
$r = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
$ui->assign('r', $r);
if(isset($routes['2']) && !empty($routes['2'])){
$ui->assign('cust', ORM::for_table('tbl_customers')->find_one($routes['2']));
}
run_hook('view_recharge'); #HOOK
$ui->display('recharge.tpl');
break;

View File

@ -399,4 +399,6 @@ $_L['Target_has_active_plan_different_with_current_plant'] = 'Target has active
$_L['Recharge_a_friend'] = 'Recharge a friend';
$_L['Buy_for_friend'] = 'Buy for friend';
$_L['Buy_this_for_friend_account'] = 'Buy this for friend account?';
$_L['Review_package_before_recharge'] = 'Review package before recharge';
$_L['Review_package_before_recharge'] = 'Review package before recharge';
$_L['Deactivate'] = 'Deactivate';
$_L['Sync'] = 'Sync';