Refill Balance with Custom Amount Requested by Javi Tech
This commit is contained in:
parent
bdda199523
commit
dc55957a53
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
}
|
@ -1,23 +1,25 @@
|
||||
{include file="sections/header.tpl"}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12">
|
||||
<div class="col-lg-6 col-lg-offset-3">
|
||||
<div class="panel panel-primary panel-hovered panel-stacked mb30">
|
||||
<div class="panel-heading">{Lang::T('Refill Balance')}</div>
|
||||
<div class="panel-body">
|
||||
<form class="form-horizontal" method="post" role="form" action="{$_url}plan/deposit-post">
|
||||
<input type="hidden" name="stoken" value="{App::getToken()}">
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">{Lang::T('Select Account')}</label>
|
||||
<div class="col-md-6">
|
||||
<select id="personSelect" class="form-control select2" name="id_customer" style="width: 100%"
|
||||
<label class="col-md-3 control-label">{Lang::T('Select Account')}</label>
|
||||
<div class="col-md-9">
|
||||
<select id="personSelect" class="form-control select2" onchange="getBalance(this)" name="id_customer" style="width: 100%"
|
||||
data-placeholder="{Lang::T('Select a customer')}...">
|
||||
</select>
|
||||
<span class="help-block" id="customerBalance">-</span>
|
||||
</div>
|
||||
</div>
|
||||
<span class="help-block">{Lang::T('Select Balance Package or Custom Amount')}</span>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label"><a href="{$_url}services/balance">{Lang::T('Balance Package')}</a></label>
|
||||
<div class="col-md-6">
|
||||
<label class="col-md-3 control-label"><a href="{$_url}services/balance">{Lang::T('Balance Package')}</a></label>
|
||||
<div class="col-md-9">
|
||||
<select id="planSelect" class="form-control select2" name="id_plan" style="width: 100%"
|
||||
data-placeholder="{Lang::T('Select Plans')}...">
|
||||
<option></option>
|
||||
@ -25,11 +27,25 @@
|
||||
<option value="{$pl['id']}">{if $pl['enabled'] neq 1}DISABLED PLAN • {/if}{$pl['name_plan']} - {Lang::moneyFormat($pl['price'])}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
<span class="help-block">{Lang::T('Or custom balance amount below')}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-lg-offset-2 col-lg-10">
|
||||
<label class="col-md-3 control-label">{Lang::T('Balance Amount')}</label>
|
||||
<div class="col-md-9">
|
||||
<input type="number" class="form-control" name="amount" style="width: 100%" placeholder="0">
|
||||
<span class="help-block">{Lang::T('Input custom balance, will ignore plan above')}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label">{Lang::T('Note')}</label>
|
||||
<div class="col-md-9">
|
||||
<textarea class="form-control" name="note" style="width: 100%"></textarea>
|
||||
<span class="help-block"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<button class="btn btn-success"
|
||||
type="submit">{Lang::T('Recharge')}</button>
|
||||
Or <a href="{$_url}customers/list">{Lang::T('Cancel')}</a>
|
||||
@ -41,4 +57,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function getBalance(f){
|
||||
$.get('{$_url}autoload/balance/'+f.value+'/1', function(data) {
|
||||
document.getElementById('customerBalance').innerHTML = data;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
{include file="sections/footer.tpl"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user