diff --git a/system/autoload/Package.php b/system/autoload/Package.php index df0ccc1c..09f568d9 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -21,7 +21,6 @@ class Package public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel, $note = '') { global $config, $admin, $c, $p, $b, $t, $d, $zero, $trx, $_app_stage, $isChangePlan; - $date_now = date("Y-m-d H:i:s"); $date_only = date("Y-m-d"); $time_only = date("H:i:s"); $time = date("H:i:s"); @@ -100,57 +99,7 @@ class Package if ($router_name == 'balance') { - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = $inv = "INV-" . Package::_raid(); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - $t->price = $p['price']; - $t->recharged_on = $date_only; - $t->recharged_time = date("H:i:s"); - $t->expiration = $date_only; - $t->time = $time; - $t->method = "$gateway - $channel"; - $t->routers = $router_name; - $t->type = "Balance"; - if ($admin) { - $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; - } else { - $t->admin_id = '0'; - } - $t->save(); - - $balance_before = $c['balance']; - Balance::plus($id_customer, $p['price']); - $balance = $c['balance'] + $p['price']; - - $textInvoice = Lang::getNotifText('invoice_balance'); - $textInvoice = str_replace('[[company_name]]', $config['CompanyName'], $textInvoice); - $textInvoice = str_replace('[[address]]', $config['address'], $textInvoice); - $textInvoice = str_replace('[[phone]]', $config['phone'], $textInvoice); - $textInvoice = str_replace('[[invoice]]', $inv, $textInvoice); - $textInvoice = str_replace('[[date]]', Lang::dateTimeFormat($date_now), $textInvoice); - $textInvoice = str_replace('[[payment_gateway]]', $gateway, $textInvoice); - $textInvoice = str_replace('[[payment_channel]]', $channel, $textInvoice); - $textInvoice = str_replace('[[type]]', 'Balance', $textInvoice); - $textInvoice = str_replace('[[plan_name]]', $p['name_plan'], $textInvoice); - $textInvoice = str_replace('[[plan_price]]', Lang::moneyFormat($p['price']), $textInvoice); - $textInvoice = str_replace('[[name]]', $c['fullname'], $textInvoice); - $textInvoice = str_replace('[[user_name]]', $c['username'], $textInvoice); - $textInvoice = str_replace('[[user_password]]', $c['password'], $textInvoice); - $textInvoice = str_replace('[[footer]]', $config['note'], $textInvoice); - $textInvoice = str_replace('[[balance_before]]', Lang::moneyFormat($balance_before), $textInvoice); - $textInvoice = str_replace('[[balance]]', Lang::moneyFormat($balance), $textInvoice); - - if ($config['user_notification_payment'] == 'sms') { - Message::sendSMS($c['phonenumber'], $textInvoice); - } else if ($config['user_notification_payment'] == 'wa') { - Message::sendWhatsapp($c['phonenumber'], $textInvoice); - } else if ($config['user_notification_payment'] == 'email') { - Message::sendEmail($c['email'], '[' . $config['CompanyName'] . '] ' . Lang::T("Invoice") . ' ' . $inv, $textInvoice); - } - - return true; + return self::rechargeBalance($c, $p, $gateway, $channel); } /** @@ -493,6 +442,62 @@ class Package return $inv; } + public static function rechargeBalance($customer, $plan, $gateway, $channel, $note = '') + { + global $admin, $config; + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = $inv = "INV-" . Package::_raid(); + $t->username = $customer['username']; + $t->plan_name = $plan['name_plan']; + $t->price = $plan['price']; + $t->recharged_on = date("Y-m-d"); + $t->recharged_time = date("H:i:s"); + $t->expiration = date("Y-m-d"); + $t->time = date("H:i:s"); + $t->method = "$gateway - $channel"; + $t->routers = 'balance'; + $t->type = "Balance"; + $t->note = $note; + if ($admin) { + $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; + } else { + $t->admin_id = '0'; + } + $t->save(); + + $balance_before = $customer['balance']; + Balance::plus($customer['id'], $plan['price']); + $balance = $customer['balance'] + $plan['price']; + + $textInvoice = Lang::getNotifText('invoice_balance'); + $textInvoice = str_replace('[[company_name]]', $config['CompanyName'], $textInvoice); + $textInvoice = str_replace('[[address]]', $config['address'], $textInvoice); + $textInvoice = str_replace('[[phone]]', $config['phone'], $textInvoice); + $textInvoice = str_replace('[[invoice]]', $inv, $textInvoice); + $textInvoice = str_replace('[[date]]', Lang::dateTimeFormat(date("Y-m-d")), $textInvoice); + $textInvoice = str_replace('[[payment_gateway]]', $gateway, $textInvoice); + $textInvoice = str_replace('[[payment_channel]]', $channel, $textInvoice); + $textInvoice = str_replace('[[type]]', 'Balance', $textInvoice); + $textInvoice = str_replace('[[plan_name]]', $plan['name_plan'], $textInvoice); + $textInvoice = str_replace('[[plan_price]]', Lang::moneyFormat($plan['price']), $textInvoice); + $textInvoice = str_replace('[[name]]', $customer['fullname'], $textInvoice); + $textInvoice = str_replace('[[user_name]]', $customer['username'], $textInvoice); + $textInvoice = str_replace('[[user_password]]', $customer['password'], $textInvoice); + $textInvoice = str_replace('[[footer]]', $config['note'], $textInvoice); + $textInvoice = str_replace('[[balance_before]]', Lang::moneyFormat($balance_before), $textInvoice); + $textInvoice = str_replace('[[balance]]', Lang::moneyFormat($balance), $textInvoice); + + if ($config['user_notification_payment'] == 'sms') { + Message::sendSMS($customer['phonenumber'], $textInvoice); + } else if ($config['user_notification_payment'] == 'wa') { + Message::sendWhatsapp($customer['phonenumber'], $textInvoice); + } else if ($config['user_notification_payment'] == 'email') { + Message::sendEmail($customer['email'], '[' . $config['CompanyName'] . '] ' . Lang::T("Invoice") . ' ' . $inv, $textInvoice); + } + return $t->id(); + } + public static function _raid() { return ORM::for_table('tbl_transactions')->max('id') + 1; diff --git a/system/autoload/User.php b/system/autoload/User.php index dfccc711..732ff5ce 100644 --- a/system/autoload/User.php +++ b/system/autoload/User.php @@ -190,8 +190,22 @@ class User if ($d['status'] == 'Banned') { _alert(Lang::T('This account status') . ' : ' . Lang::T($d['status']), 'danger', "logout"); } - if (empty($d['username'])) { - r2(U . 'logout', 'd', ''); + return $d; + } + + public static function _infoByName($username) + { + global $config; + if ($config['maintenance_mode'] == true) { + if ($config['maintenance_mode_logout'] == true) { + r2(U . 'logout', 'd', ''); + } else { + displayMaintenanceMessage(); + } + } + $d = ORM::for_table('tbl_customers')->where("username", $username)->find_one(); + if ($d['status'] == 'Banned') { + _alert(Lang::T('This account status') . ' : ' . Lang::T($d['status']), 'danger', "logout"); } return $d; } diff --git a/system/controllers/autoload.php b/system/controllers/autoload.php index 0dbab54c..26e5a781 100644 --- a/system/controllers/autoload.php +++ b/system/controllers/autoload.php @@ -32,6 +32,14 @@ switch ($action) { $bw = ORM::for_table('tbl_bandwidth')->select("name_bw")->find_one($routes['2']); echo $bw['name_bw']; die(); + case 'balance': + $balance = ORM::for_table('tbl_customers')->select("balance")->find_one($routes['2'])['balance']; + if($routes['3']=='1'){ + echo Lang::moneyFormat($balance); + }else{ + echo $balance; + } + die(); case 'server': $d = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many(); $ui->assign('d', $d); diff --git a/system/controllers/plan.php b/system/controllers/plan.php index 2de31de7..ed7560e1 100644 --- a/system/controllers/plan.php +++ b/system/controllers/plan.php @@ -797,24 +797,42 @@ switch ($action) { _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $user = _post('id_customer'); + $amount = _post('amount'); $plan = _post('id_plan'); + $note = _post('note'); $stoken = _req('stoken'); + $c = ORM::for_table('tbl_customers')->find_one($user); if (App::getTokenValue($stoken)) { - $c = ORM::for_table('tbl_customers')->where('id', $user)->find_one(); - $in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one(); + $in = ORM::for_table('tbl_transactions')->find_one(App::getTokenValue($stoken)); Package::createInvoice($in); $ui->display('invoice.tpl'); die(); } run_hook('deposit_customer'); #HOOK - if (!empty($user) && !empty($plan)) { - if (Package::rechargeUser($user, 'balance', $plan, "Deposit", $admin['fullname'])) { - $c = ORM::for_table('tbl_customers')->where('id', $user)->find_one(); - $in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one(); + if (!empty($user) && strlen($amount)>0 && $amount != 0) { + $plan = []; + $plan['name_plan'] = Lang::T('Balance'); + $plan['price'] = $amount; + $trxId = Package::rechargeBalance($c, $plan, "Deposit", $admin['fullname'], $note); + if ($trxId > 0) { + $in = ORM::for_table('tbl_transactions')->find_one($trxId); Package::createInvoice($in); if (!empty($stoken)) { - App::setToken($stoken, $in['id']); + App::setToken($stoken, $trxId); + } + $ui->display('invoice.tpl'); + } else { + r2(U . 'plan/refill', 'e', "Failed to refill account"); + } + }else if (!empty($user) && !empty($plan)) { + $p = ORM::for_table('tbl_plans')->find_one($plan); + $trxId = Package::rechargeBalance($c, $p, "Deposit", $admin['fullname'], $note); + if ($trxId > 0) { + $in = ORM::for_table('tbl_transactions')->find_one($trxId); + Package::createInvoice($in); + if (!empty($stoken)) { + App::setToken($stoken, $trxId); } $ui->display('invoice.tpl'); } else { diff --git a/system/lan/english.json b/system/lan/english.json index 7ace29bd..d0508cfe 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -853,5 +853,18 @@ "Registration_code": "Registration code", "Admin_can_only_have_single_session_login__it_will_logout_another_session": "Admin can only have single session login, it will logout another session", "Single_session_Admin": "Single session Admin", - "Get_Directions": "Get Directions" + "Get_Directions": "Get Directions", + "Buy_Balance_Plans": "Buy Balance Plans", + "Buy": "Buy", + "Cron_Job_last_ran_on": "Cron Job last ran on", + "VPN_Plans": "VPN Plans", + "Postpaid_Recharge_for_the_first_time_use": "Postpaid Recharge for the first time use", + "Or": "Or", + "Balance_Package": "Balance Package", + "Balance_Custom": "Balance Custom", + "Balance_Amount": "Balance Amount", + "Select_Balance_Package_or_Custom_Amount": "Select Balance Package or Custom Amount", + "Note": "Note", + "Or_custom_balance_amount_below": "Or custom balance amount below", + "Input_custom_balance__will_ignore_plan_above": "Input custom balance, will ignore plan above" } \ No newline at end of file diff --git a/ui/ui/deposit.tpl b/ui/ui/deposit.tpl index f901ec5b..f11eed82 100644 --- a/ui/ui/deposit.tpl +++ b/ui/ui/deposit.tpl @@ -1,23 +1,25 @@ {include file="sections/header.tpl"}