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) 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_now = date("Y-m-d H:i:s");
$date_only = date("Y-m-d"); $date_only = date("Y-m-d");
$time_only = date("H:i:s"); $time_only = date("H:i:s");
@ -31,6 +31,20 @@ class Package
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one(); $c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->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') { if ($p['validity_unit'] == 'Period') {
$f = ORM::for_table('tbl_customers_fields')->where('field_name', 'Expired Date')->where('customer_id', $c['id'])->find_one(); $f = ORM::for_table('tbl_customers_fields')->where('field_name', 'Expired Date')->where('customer_id', $c['id'])->find_one();
if (!$f) { if (!$f) {

View File

@ -39,9 +39,11 @@ class User
} }
} }
public static function _info() public static function _info($id = 0)
{ {
if(!$id){
$id = User::getID(); $id = User::getID();
}
$d = ORM::for_table('tbl_customers')->find_one($id); $d = ORM::for_table('tbl_customers')->find_one($id);
if(empty($d['username'])){ if(empty($d['username'])){

View File

@ -120,22 +120,45 @@ switch ($action) {
$id_customer = _post('id_customer'); $id_customer = _post('id_customer');
$type = _post('type'); $type = _post('type');
$server = _post('server'); $server = _post('server');
$plan = _post('plan'); $planId = _post('plan');
$using = _post('using');
$date_only = date("Y-m-d"); $date_only = date("Y-m-d");
$time = date("H:i:s"); $time = date("H:i:s");
$msg = ''; $msg = '';
if ($id_customer == '' or $type == '' or $server == '' or $plan == '') { if ($id_customer == '' or $type == '' or $server == '' or $planId == '') {
$msg .= 'All field is required' . '<br>'; $msg .= Lang::T('All field is required') . '<br>';
} }
if ($msg == '') { if ($msg == '') {
if (Package::rechargeUser($id_customer, $server, $plan, "Recharge", $admin['fullname'])) { $gateway = 'Recharge';
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one(); $channel = $admin['fullname'];
$in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one(); $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); Package::createInvoice($in);
$ui->display('invoice.tpl'); $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 { } else {
r2(U . 'prepaid/recharge', 'e', "Failed to recharge account"); r2(U . 'prepaid/recharge', 'e', "Failed to recharge account");
} }

View File

@ -468,5 +468,8 @@
"Payment_Gateway_Deleted": "Payment Gateway Deleted", "Payment_Gateway_Deleted": "Payment Gateway Deleted",
"Payment_Gateway_not_set__please_set_it_in_Settings": "Payment Gateway not set, please set it in Settings", "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..", "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> <option value="">Select Plans</option>
{foreach $d as $ds} {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} {/foreach}

View File

@ -27,7 +27,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Routers')}</label> <label class="col-md-2 control-label">{Lang::T('Routers')}</label>
<div class="col-md-6"> <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> <option value=''>{Lang::T('Select Routers')}</option>
</select> </select>
</div> </div>
@ -41,7 +41,18 @@
</select> </select>
</div> </div>
</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="form-group">
<div class="col-lg-offset-2 col-lg-10"> <div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success" <button class="btn btn-success"