Recharge with balance or zero cost

This commit is contained in:
Ibnu Maksum 2024-03-12 15:09:00 +07:00
parent 6d15437333
commit c9058769ce
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
6 changed files with 69 additions and 16 deletions

View File

@ -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) {

View File

@ -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'])){

View File

@ -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' . '<br>';
if ($id_customer == '' or $type == '' or $server == '' or $planId == '') {
$msg .= Lang::T('All field is required') . '<br>';
}
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);

View File

@ -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"
}

View File

@ -1,4 +1,4 @@
<option value="">Select Plans</option>
{foreach $d as $ds}
<option value="{$ds['id']}">{if $ds['enabled'] neq 1}DISABLED PLAN &bull; {/if}{$ds['name_plan']} &bull; {Lang::moneyFormat($ds['price'])}</option>
<option value="{$ds['id']}">{if $ds['enabled'] neq 1}DISABLED PLAN &bull; {/if}{$ds['name_plan']} &bull; {Lang::moneyFormat($ds['price'])}{if $ds['allow_purchase'] neq 'yes'} &bull; HIDDEN PLAN {/if}</option>
{/foreach}

View File

@ -27,7 +27,7 @@
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Routers')}</label>
<div class="col-md-6">
<select id="server" name="server" class="form-control select2">
<select id="server" data-type="server" name="server" class="form-control select2">
<option value=''>{Lang::T('Select Routers')}</option>
</select>
</div>
@ -41,7 +41,18 @@
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Using')}</label>
<div class="col-md-6">
<select name="using" class="form-control">
<option value="default">{Lang::T('Default')}</option>
{if $_c['enable_balance'] eq 'yes'}
<option value="balance">{Lang::T('Customer Balance')}</option>
{/if}
<option value="zero">{$_c['currency_code']} 0</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success"