diff --git a/system/autoload/Package.php b/system/autoload/Package.php
index a33df78b..c6c9b902 100644
--- a/system/autoload/Package.php
+++ b/system/autoload/Package.php
@@ -19,7 +19,7 @@ class Package
*/
public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel)
{
- global $config, $admin, $c, $p, $b, $t, $d;
+ global $config, $admin, $c, $p, $b, $t, $d, $zero;
$date_now = date("Y-m-d H:i:s");
$date_only = date("Y-m-d");
$time_only = date("H:i:s");
@@ -31,6 +31,20 @@ class Package
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one();
+
+ if(isset($zero) && $zero==1){
+ $p['price'] = 0;
+ }
+
+ if(!$p['enabled']){
+ if(!isset($admin) || !isset($admin['id']) || empty($admin['id'])){
+ r2(U . 'home', 'e', Lang::T('Plan Not found'));
+ }
+ if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
+ r2(U . 'dashboard', 'e', Lang::T('Plan Not found'));
+ }
+ }
+
if ($p['validity_unit'] == 'Period') {
$f = ORM::for_table('tbl_customers_fields')->where('field_name', 'Expired Date')->where('customer_id', $c['id'])->find_one();
if (!$f) {
diff --git a/system/autoload/User.php b/system/autoload/User.php
index afda269d..645190c7 100644
--- a/system/autoload/User.php
+++ b/system/autoload/User.php
@@ -39,9 +39,11 @@ class User
}
}
- public static function _info()
+ public static function _info($id = 0)
{
- $id = User::getID();
+ if(!$id){
+ $id = User::getID();
+ }
$d = ORM::for_table('tbl_customers')->find_one($id);
if(empty($d['username'])){
diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php
index 18f99ca1..f31aadd5 100644
--- a/system/controllers/prepaid.php
+++ b/system/controllers/prepaid.php
@@ -120,22 +120,45 @@ switch ($action) {
$id_customer = _post('id_customer');
$type = _post('type');
$server = _post('server');
- $plan = _post('plan');
+ $planId = _post('plan');
+ $using = _post('using');
$date_only = date("Y-m-d");
$time = date("H:i:s");
$msg = '';
- if ($id_customer == '' or $type == '' or $server == '' or $plan == '') {
- $msg .= 'All field is required' . '
';
+ if ($id_customer == '' or $type == '' or $server == '' or $planId == '') {
+ $msg .= Lang::T('All field is required') . '
';
}
if ($msg == '') {
- if (Package::rechargeUser($id_customer, $server, $plan, "Recharge", $admin['fullname'])) {
- $c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
- $in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one();
+ $gateway = 'Recharge';
+ $channel = $admin['fullname'];
+ $cust = User::_info($id_customer);
+ if ($using == 'balance' && $config['enable_balance'] == 'yes') {
+ $plan = ORM::for_table('tbl_plans')->find_one($planId);
+ if (!$cust) {
+ r2(U . 'prepaid/recharge', 'e', Lang::T('Customer not found'));
+ }
+ if (!$plan) {
+ r2(U . 'prepaid/recharge', 'e', Lang::T('Plan not found'));
+ }
+ if ($cust['balance'] < $plan['price']) {
+ r2(U . 'prepaid/recharge', 'e', Lang::T('insufficient balance'));
+ }
+ $gateway = 'Recharge Balance';
+ }
+ if ($using == 'zero') {
+ $zero = 1;
+ $gateway = 'Recharge Zero';
+ }
+ if (Package::rechargeUser($id_customer, $server, $planId, $gateway, $channel)) {
+ if ($using == 'balance') {
+ Balance::min($cust['id'], $plan['price']);
+ }
+ $in = ORM::for_table('tbl_transactions')->where('username', $cust['username'])->order_by_desc('id')->find_one();
Package::createInvoice($in);
$ui->display('invoice.tpl');
- _log('[' . $admin['username'] . ']: ' . 'Recharge ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']);
+ _log('[' . $admin['username'] . ']: ' . 'Recharge ' . $cust['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']);
} else {
r2(U . 'prepaid/recharge', 'e', "Failed to recharge account");
}
@@ -189,9 +212,9 @@ switch ($action) {
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
if ($d) {
$ui->assign('d', $d);
- if(in_array($admin['user_type'], array('SuperAdmin', 'Admin'))){
+ if (in_array($admin['user_type'], array('SuperAdmin', 'Admin'))) {
$p = ORM::for_table('tbl_plans')->where_not_equal('type', 'Balance')->find_many();
- }else{
+ } else {
$p = ORM::for_table('tbl_plans')->where('enabled', '1')->where_not_equal('type', 'Balance')->find_many();
}
$ui->assign('p', $p);
diff --git a/system/lan/english.json b/system/lan/english.json
index 7cf1720b..4e8d8977 100644
--- a/system/lan/english.json
+++ b/system/lan/english.json
@@ -468,5 +468,8 @@
"Payment_Gateway_Deleted": "Payment Gateway Deleted",
"Payment_Gateway_not_set__please_set_it_in_Settings": "Payment Gateway not set, please set it in Settings",
"Failed_to_create_Transaction__": "Failed to create Transaction..",
- "Show_To_Customer": "Show To Customer"
+ "Show_To_Customer": "Show To Customer",
+ "Using": "Using",
+ "Default": "Default",
+ "Customer_Balance": "Customer Balance"
}
\ No newline at end of file
diff --git a/ui/ui/autoload.tpl b/ui/ui/autoload.tpl
index caeff1a1..30ff8b96 100644
--- a/ui/ui/autoload.tpl
+++ b/ui/ui/autoload.tpl
@@ -1,4 +1,4 @@
{foreach $d as $ds}
-
+
{/foreach}
\ No newline at end of file
diff --git a/ui/ui/recharge.tpl b/ui/ui/recharge.tpl
index eba82b0e..b07c990d 100644
--- a/ui/ui/recharge.tpl
+++ b/ui/ui/recharge.tpl
@@ -27,7 +27,7 @@