From 609cf4b69ddbedff7dec34c03af46a5455d9be85 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 15 Sep 2023 11:33:46 +0700 Subject: [PATCH] Sync Customer to mikrotik --- system/controllers/customers.php | 22 ++++++++++++++++++++++ system/controllers/prepaid.php | 3 +++ system/lan/english/common.lan.php | 4 +++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/system/controllers/customers.php b/system/controllers/customers.php index e130bff2..e58afaea 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -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': diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index 026eadf7..07820f5f 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -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; diff --git a/system/lan/english/common.lan.php b/system/lan/english/common.lan.php index 1988c935..e5e49c8f 100644 --- a/system/lan/english/common.lan.php +++ b/system/lan/english/common.lan.php @@ -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';