diff --git a/system/autoload/Balance.php b/system/autoload/Balance.php
index f6557a3f..208551c1 100644
--- a/system/autoload/Balance.php
+++ b/system/autoload/Balance.php
@@ -19,12 +19,7 @@ class Balance
{
global $config;
if (Balance::min($id_customer, $amount)) {
- if (Balance::plusByPhone($phoneTarget, $amount)) {
- return true;
- } else {
- Balance::plus($id_customer, $amount);
- return false;
- }
+ return Balance::plusByPhone($phoneTarget, $amount);
} else {
return false;
}
diff --git a/system/controllers/home.php b/system/controllers/home.php
index 851a7a16..e2ecaaac 100644
--- a/system/controllers/home.php
+++ b/system/controllers/home.php
@@ -72,7 +72,17 @@ if (_post('send') == 'balance') {
r2(U . 'home', 's', Lang::T('Sending balance success'));
}
} else {
- r2(U . 'home', 'd', 'Failed, balance is not available');
+ r2(U . 'home', 'd', Lang::T('Failed, balance is not available'));
+ }
+}else if (_post('send') == 'plan') {
+ $active = ORM::for_table('tbl_user_recharges')
+ ->where('username', _post('username'))
+ ->find_one();
+ $router = ORM::for_table('tbl_routers') ->where('name', $active['routers'])->find_one();
+ if($router){
+ r2(U . "order/send/$router[id]/$active[plan_id]&u=".trim(_post('username')), 's', Lang::T('Review package before recharge'));
+ }else{
+ r2(U . 'package/order', 'w', Lang::T('Your friend do not have active package'));
}
}
diff --git a/system/controllers/order.php b/system/controllers/order.php
index d665889b..b87137fa 100644
--- a/system/controllers/order.php
+++ b/system/controllers/order.php
@@ -98,7 +98,7 @@ switch ($action) {
}
}
if (empty($trx)) {
- r2(U . "order", 'e', Lang::T("Transaction Not found"));
+ r2(U . "order/package", 'e', Lang::T("Transaction Not found"));
}
$router = ORM::for_table('tbl_routers')->find_one($trx['routers_id']);
$plan = ORM::for_table('tbl_plans')->find_one($trx['plan_id']);
@@ -111,8 +111,8 @@ switch ($action) {
$ui->display('user-orderView.tpl');
break;
case 'pay':
- if ($_c['enable_balance'] != 'yes'){
- r2(U . "order", 'e', Lang::T("Balance not enabled"));
+ if ($_c['enable_balance'] != 'yes' && $config['allow_balance_transfer'] != 'yes') {
+ r2(U . "order/package", 'e', Lang::T("Balance not enabled"));
}
$plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3']);
$router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2']);
@@ -130,10 +130,91 @@ switch ($action) {
"\nRouter: " . $router_name .
"\nPrice: " . $p['price']);
}
- }else{
+ } else {
echo "no renewall | plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n";
}
break;
+ case 'send':
+ if ($_c['enable_balance'] != 'yes') {
+ r2(U . "order/package", 'e', Lang::T("Balance not enabled"));
+ }
+ $ui->assign('_title', Lang::T('Buy for friend'));
+ $ui->assign('_system_menu', 'package');
+ $plan = ORM::for_table('tbl_plans')->find_one($routes['3']);
+ if (empty($plan)) {
+ r2(U . "order/package", 'e', Lang::T("Plan Not found"));
+ }
+ if (isset($_POST['send']) && $_POST['send'] == 'plan') {
+ $target = ORM::for_table('tbl_customers')->where('username', _post('username'))->find_one();
+ if (!$target) {
+ r2(U . 'home', 'd', Lang::T('Username not found'));
+ }
+ if ($user['balance'] < $plan['price']) {
+ r2(U . 'home', 'd', Lang::T('insufficient balance'));
+ }
+ if ($user['username'] == $target['username']) {
+ r2(U . "order/pay/$routes[2]/$routes[3]", 's', '^_^ v');
+ }
+ $active = ORM::for_table('tbl_user_recharges')
+ ->where('username', _post('username'))
+ ->where('status', 'on')
+ ->find_one();
+
+ if ($active['plan_id'] != $plan['id']) {
+ r2(U . "order/package", 'e', Lang::T("Target has active plan, different with current plant.")." [ $active[namebp] ]");
+ }
+ if (Package::rechargeUser($target['id'], $plan['routers'], $plan['id'], $user['fullname'], 'Balance')) {
+ // if success, then get the balance
+ Balance::min($user['id'], $plan['price']);
+ //sender
+ $d = ORM::for_table('tbl_payment_gateway')->create();
+ $d->username = $user['username'];
+ $d->gateway = $target['username'];
+ $d->plan_id = $plan['id'];
+ $d->plan_name = $plan['name_plan'];
+ $d->routers_id = $routes['2'];
+ $d->routers = $plan['routers'];
+ $d->price = $plan['price'];
+ $d->payment_method = "Balance";
+ $d->payment_channel = "Send Plan";
+ $d->created_date = date('Y-m-d H:i:s');
+ $d->paid_date = date('Y-m-d H:i:s');
+ $d->expired_date = date('Y-m-d H:i:s');
+ $d->pg_url_payment = 'balance';
+ $d->status = 2;
+ $d->save();
+ $trx_id = $d->id();
+ //receiver
+ $d = ORM::for_table('tbl_payment_gateway')->create();
+ $d->username = $target['username'];
+ $d->gateway = $user['username'];
+ $d->plan_id = $plan['id'];
+ $d->plan_name = $plan['name_plan'];
+ $d->routers_id = $routes['2'];
+ $d->routers = $plan['routers'];
+ $d->price = $plan['price'];
+ $d->payment_method = "Balance";
+ $d->payment_channel = "Received Plan";
+ $d->created_date = date('Y-m-d H:i:s');
+ $d->paid_date = date('Y-m-d H:i:s');
+ $d->expired_date = date('Y-m-d H:i:s');
+ $d->pg_url_payment = 'balance';
+ $d->status = 2;
+ $d->save();
+ r2(U . "order/view/$trx_id", 's', Lang::T("Success to send package"));
+ } else {
+ r2(U . "order/package", 'e', Lang::T("Failed to Send package"));
+ Message::sendTelegram("Send Package with Balance Failed\n\n#u$user[username] #send \n" . $plan['name_plan'] .
+ "\nRouter: " . $plan['routers'] .
+ "\nPrice: " . $plan['price']);
+ }
+ }
+
+ $ui->assign('username', $_GET['u']);
+ $ui->assign('router', $router);
+ $ui->assign('plan', $plan);
+ $ui->display('user-sendPlan.tpl');
+ break;
case 'buy':
if (strpos($user['email'], '@') === false) {
r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address"));
@@ -147,9 +228,9 @@ switch ($action) {
run_hook('customer_buy_plan'); #HOOK
include 'system/paymentgateway/' . $config['payment_gateway'] . '.php';
call_user_func($config['payment_gateway'] . '_validate_config');
- if ($routes['2']>0) {
+ if ($routes['2'] > 0) {
$router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2']);
- }else{
+ } else {
$router['id'] = 0;
$router['name'] = 'balance';
}
@@ -205,5 +286,5 @@ switch ($action) {
}
break;
default:
- r2(U . "order/package/", 's','');
+ r2(U . "order/package/", 's', '');
}
diff --git a/system/lan/english/common.lan.php b/system/lan/english/common.lan.php
index ffa3f126..1988c935 100644
--- a/system/lan/english/common.lan.php
+++ b/system/lan/english/common.lan.php
@@ -375,18 +375,28 @@ $_L['Active'] = 'Active';
$_L['Transfer_Balance'] = 'Transfer Balance';
$_L['Send_your_balance'] = 'Send your balance?';
$_L['Send'] = 'Send';
-$_L['Cannot_send_to_yourself'] = 'Cannot send to yourself';
-$_L['Sending_balance_success'] = 'Sending balance success';
-$_L['From'] = 'From';
-$_L['To'] = 'To';
-$_L['insufficient_balance'] = 'insufficient balance';
-$_L['Send_Balance'] = 'Send Balance';
-$_L['Received_Balance'] = 'Received Balance';
-$_L['Minimum_Balance_Transfer'] = 'Minimum Balance Transfer';
-$_L['Minimum_Transfer'] = 'Minimum Transfer';
-$_L['Company_Logo'] = 'Company Logo';
-$_L['Expired_IP_Pool'] = 'Expired IP Pool';
-$_L['Expired_IP_Pool'] = 'Expired IP Pool';
-$_L['Proxy'] = 'Proxy';
-$_L['Proxy_Server'] = 'Proxy Server';
-$_L['Proxy_Server_Login'] = 'Proxy Server Login';
+$_L['Cannot_send_to_yourself'] = 'Cannot send to yourself';
+$_L['Sending_balance_success'] = 'Sending balance success';
+$_L['From'] = 'From';
+$_L['To'] = 'To';
+$_L['insufficient_balance'] = 'insufficient balance';
+$_L['Send_Balance'] = 'Send Balance';
+$_L['Received_Balance'] = 'Received Balance';
+$_L['Minimum_Balance_Transfer'] = 'Minimum Balance Transfer';
+$_L['Minimum_Transfer'] = 'Minimum Transfer';
+$_L['Company_Logo'] = 'Company Logo';
+$_L['Expired_IP_Pool'] = 'Expired IP Pool';
+$_L['Expired_IP_Pool'] = 'Expired IP Pool';
+$_L['Proxy'] = 'Proxy';
+$_L['Proxy_Server'] = 'Proxy Server';
+$_L['Proxy_Server_Login'] = 'Proxy Server Login';
+$_L['Hotspot_Plan'] = 'Hotspot Plan';
+$_L['PPPOE_Plan'] = 'PPPOE Plan';
+$_L['UNKNOWN'] = 'UNKNOWN';
+$_L['Are_You_Sure'] = 'Are You Sure?';
+$_L['Success_to_send_package'] = 'Success to send package';
+$_L['Target_has_active_plan_different_with_current_plant'] = 'Target has active plan, different with current plant.';
+$_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';
diff --git a/ui/ui/sections/user-header.tpl b/ui/ui/sections/user-header.tpl
index e90f29bf..e5666a96 100644
--- a/ui/ui/sections/user-header.tpl
+++ b/ui/ui/sections/user-header.tpl
@@ -104,7 +104,7 @@
-