Buy Balance Done

This commit is contained in:
Ibnu Maksum 2023-08-14 15:59:53 +07:00
parent e27c0da2aa
commit af0b2cda28
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
8 changed files with 286 additions and 107 deletions

View File

@ -1,20 +1,71 @@
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* This script is for managing user balance
**/
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* This script is for managing user balance
**/
class Balance {
public static function add($customer, $amount, $note){
class Balance
{
public static function plus($id_customer, $amount)
{
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
$c->balance = $amount + $c['balance'];
$c->save();
}
public static function transfer($customer, $phoneTarget){
public static function transfer($id_customer, $phoneTarget, $amount)
{
global $config;
if ($config['allow_balance_transfer'] == 'yes') {
if(Balance::min($id_customer, $amount)){
if(Balance::plusByPhone($phoneTarget, $amount)){
return true;
}else{
Balance::plus($id_customer, $amount);
return false;
}
}else{
return false;
}
}else{
return false;
}
}
public static function pay($customer, $amount, $note){
public static function min($id_customer, $amount)
{
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
if ($c && $c['balance'] >= $amount) {
$c->balance = $amount - $c['balance'];
$c->save();
return true;
} else {
return false;
}
}
public static function plusByPhone($phone_customer, $amount)
{
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
if($c){
$c->balance = $amount + $c['balance'];
$c->save();
return true;
}
return false;
}
public static function minByPhone($phone_customer, $amount)
{
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
if ($c && $c['balance'] >= $amount) {
$c->balance = $amount - $c['balance'];
$c->save();
return true;
} else {
return false;
}
}
}

View File

@ -30,6 +30,49 @@ class Package
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->where('enabled', '1')->find_one();
if ($router_name == 'balance') {
// insert table transactions
$inv = "INV-" . _raid(5);
$t = ORM::for_table('tbl_transactions')->create();
$t->invoice = $inv;
$t->username = $c['username'];
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->expiration = $date_only;
$t->time = $time;
$t->method = "$gateway - $channel";
$t->routers = $router_name;
$t->type = "Balance";
$t->save();
Balance::plus($id_customer, $p['price']);
$textInvoice = $_notifmsg['invoice_balance'];
$textInvoice = str_replace('[[company_name]]', $_c['CompanyName'], $textInvoice);
$textInvoice = str_replace('[[address]]', $_c['address'], $textInvoice);
$textInvoice = str_replace('[[phone]]', $_c['phone'], $textInvoice);
$textInvoice = str_replace('[[invoice]]', $inv, $textInvoice);
$textInvoice = str_replace('[[date]]', date($_c['date_format'], strtotime($date_only)) . " " . $time, $textInvoice);
$textInvoice = str_replace('[[payment_gateway]]', $_c['gateway'], $textInvoice);
$textInvoice = str_replace('[[payment_channel]]', $_c['channel'], $textInvoice);
$textInvoice = str_replace('[[type]]', 'Balance', $textInvoice);
$textInvoice = str_replace('[[plan_name]]', $p['name_plan'], $textInvoice);
$textInvoice = str_replace('[[plan_price]]', $_c['currency_code'] . " " . number_format($p['price'], 2, $_c['dec_point'], $_c['thousands_sep']), $textInvoice);
$textInvoice = str_replace('[[user_name]]', $c['username'], $textInvoice);
$textInvoice = str_replace('[[user_password]]', $c['password'], $textInvoice);
if ($_c['user_notification_payment'] == 'sms') {
Message::sendSMS($c['phonenumber'], $textInvoice);
} else if ($_c['user_notification_payment'] == 'wa') {
Message::sendWhatsapp($c['phonenumber'], $textInvoice);
}
return true;
}
$b = ORM::for_table('tbl_user_recharges')->where('customer_id', $id_customer)->find_one();
$mikrotik = Mikrotik::info($router_name);
@ -202,17 +245,16 @@ class Package
$textInvoice = str_replace('[[company_name]]', $_c['CompanyName'], $textInvoice);
$textInvoice = str_replace('[[address]]', $_c['address'], $textInvoice);
$textInvoice = str_replace('[[phone]]', $_c['phone'], $textInvoice);
$textInvoice = str_replace('[[invoice]]', $_c['CompanyName'], $textInvoice);
$textInvoice = str_replace('[[invoice]]', $in['invoice'], $textInvoice);
$textInvoice = str_replace('[[date]]', $date_now, $textInvoice);
$textInvoice = str_replace('[[date]]', date($_c['date_format'], strtotime($date_now)) . " " . $time, $textInvoice);
$textInvoice = str_replace('[[payment_gateway]]', $_c['gateway'], $textInvoice);
$textInvoice = str_replace('[[payment_channel]]', $_c['channel'], $textInvoice);
$textInvoice = str_replace('[[type]]', $in['type'], $textInvoice);
$textInvoice = str_replace('[[plan_name]]', $in['plan_name'], $textInvoice);
$textInvoice = str_replace('[[plan_price]]', $_c['currency_code'] . " ". number_format($in['price'], 2, $_c['dec_point'], $_c['thousands_sep']), $textInvoice);
$textInvoice = str_replace('[[plan_price]]', $_c['currency_code'] . " " . number_format($in['price'], 2, $_c['dec_point'], $_c['thousands_sep']), $textInvoice);
$textInvoice = str_replace('[[user_name]]', $in['username'], $textInvoice);
$textInvoice = str_replace('[[user_password]]', $c['password'], $textInvoice);
$textInvoice = str_replace('[[expired_date]]', date($_c['date_format'], strtotime($in['expiration'])) . " ".$in['time'], $textInvoice);
$textInvoice = str_replace('[[expired_date]]', date($_c['date_format'], strtotime($in['expiration'])) . " " . $in['time'], $textInvoice);
if ($_c['user_notification_payment'] == 'sms') {
Message::sendSMS($c['phonenumber'], $textInvoice);

View File

@ -35,9 +35,13 @@ switch ($action) {
$ui->assign('_title', 'Order Plan');
$ui->assign('_system_menu', 'package');
$routers = ORM::for_table('tbl_routers')->find_many();
$plans = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many();
$plans_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'PPPOE')->find_many();
$plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Hotspot')->find_many();
$plans_balance = ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many();
$ui->assign('routers', $routers);
$ui->assign('plans', $plans);
$ui->assign('plans_pppoe', $plans_pppoe);
$ui->assign('plans_hotspot', $plans_hotspot);
$ui->assign('plans_balance', $plans_balance);
run_hook('customer_view_order_plan'); #HOOK
$ui->display('user-orderPlan.tpl');
break;
@ -118,12 +122,16 @@ switch ($action) {
run_hook('customer_buy_plan'); #HOOK
include 'system/paymentgateway/' . $config['payment_gateway'] . '.php';
call_user_func($config['payment_gateway'] . '_validate_config');
$router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2'] * 1);
$plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3'] * 1);
if ($routes['2'] != '0') {
$router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2']);
if (empty($router) || empty($plan)) {
r2(U . $back, 'e', Lang::T("Plan Not found"));
}
}else{
$router['id'] = 0;
$router['name'] = 'balance';
}
$plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3']);
$d = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->where('status', 1)
@ -172,5 +180,5 @@ switch ($action) {
}
break;
default:
$ui->display('404.tpl');
r2(U . "order/package/", 's','');
}

View File

@ -356,3 +356,6 @@ $_L['Invoice_Balance_Message'] = 'Invoice Balance Message';
$_L['Invoice_Notification_Payment'] = 'Invoice Notification Payment';
$_L['Balance_Notification_Payment'] = 'Balance Notification Payment';
$_L['Balance_Plans'] = 'Balance Plans';
$_L['Buy_Balance'] = 'Buy Balance?';
$_L['Price'] = 'Price';
$_L['Validity'] = 'Validity';

View File

@ -1,8 +1,8 @@
{
"user_notification_expired_text": "Hello [[name]],\r\nyour internet package [[package]] has been expired.",
"invoice_paid": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\nUsername : *[[user_name]]*\r\nPassword : ***********\r\n\r\nExpired : *[[expired_date]]*\r\n\r\n\r\nThank you...",
"invoice_balance": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\nUsername : *[[user_name]]*\r\nPassword : ***********\r\n\r\nTransaction Date : *[[trx_date]]*\r\n\r\n\r\nThank you...",
"user_notification_expired_text": "Hello [[name]], your internet package [[package]] has been expired.",
"reminder_7_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 7 days.",
"reminder_3_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 3 days.",
"reminder_1_day": "Hello *[[name]]*,\r\n your internet package *[[package]]* will be expired tomorrow."
"reminder_1_day": "Hello *[[name]]*,\r\n your internet package *[[package]]* will be expired tomorrow.",
"invoice_paid": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\nUsername : *[[user_name]]*\r\nPassword : ***********\r\n\r\nExpired : *[[expired_date]]*\r\n\r\n\r\nThank you...",
"invoice_balance": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\nThank you..."
}

View File

@ -90,9 +90,9 @@
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Balance Notification Payment')}</label>
<div class="col-md-6">
<textarea class="form-control" id="invoice_paid" name="invoice_paid"
<textarea class="form-control" id="invoice_balance" name="invoice_balance"
placeholder="Hello [[name]], your internet package [[package]] has been expired"
rows="20">{Lang::htmlspecialchars($_json['invoice_paid'])}</textarea>
rows="20">{Lang::htmlspecialchars($_json['invoice_balance'])}</textarea>
</div>
<p class="col-md-4 help-block">
<b>[[company_name]]</b> Your Company Name at Settings.<br>

View File

@ -5,17 +5,45 @@
<div class="box box-solid box-default">
<div class="box-header">{Lang::T('Order Internet Package')}</div>
</div>
<div class="box box-solid box-primary">
<div class="box-header">{Lang::T('Balance Plans')}</div>
<div class="box-body row">
{foreach $plans_balance as $plan}
<div class="col col-md-4">
<div class="box box-solid box-default">
<div class="box-header">{$plan['name_plan']}</div>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<tbody>
<tr>
<td>{Lang::T('Price')}</td>
<td>{Lang::moneyFormat($plan['price'])}</td>
</tr>
</tbody>
</table>
</div>
<div class="box-body">
<a href="{$_url}order/buy/0/{$plan['id']}"
onclick="return confirm('{Lang::T('Buy Balance?')}')"
class="btn btn-sm btn-block btn-primary">Buy</a>
</div>
</div>
</div>
{/foreach}
</div>
</div>
{foreach $routers as $router}
<div class="box box-solid box-info">
<div class="box-header">{$router['name']}</div>
<div class="box-header text-black">{$router['name']}</div>
{if $router['description'] != ''}
<div class="box-body">
{$router['description']}
</div>
{/if}
{if count($plans_hotspot)>0}
<div class="box-header">Hotspot</div>
<div class="box-body row">
{foreach $plans as $plan}
{foreach $plans_hotspot as $plan}
{if $router['name'] eq $plan['routers']}
<div class="col col-md-4">
<div class="box box-solid box-default">
@ -28,11 +56,11 @@
<td>{$plan['type']}</td>
</tr>
<tr>
<td>Price</td>
<td>{$plan['price']}</td>
<td>{Lang::T('Price')}</td>
<td>{Lang::moneyFormat($plan['price'])}</td>
</tr>
<tr>
<td>Validity</td>
<td>{Lang::T('Validity')}</td>
<td>{$plan['validity']} {$plan['validity_unit']}</td>
</tr>
</tbody>
@ -48,6 +76,44 @@
{/if}
{/foreach}
</div>
{/if}
{if count($plans_pppoe)>0}
<div class="box-header text-sm">PPPOE</div>
<div class="box-body row">
{foreach $plans_pppoe as $plan}
{if $router['name'] eq $plan['routers']}
<div class="col col-md-4">
<div class="box box-solid box-default">
<div class="box-header">{$plan['name_plan']}</div>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<tbody>
<tr>
<td>{Lang::T('Type')}</td>
<td>{$plan['type']}</td>
</tr>
<tr>
<td>{Lang::T('Price')}</td>
<td>{Lang::moneyFormat($plan['price'])}</td>
</tr>
<tr>
<td>{Lang::T('Validity')}</td>
<td>{$plan['validity']} {$plan['validity_unit']}</td>
</tr>
</tbody>
</table>
</div>
<div class="box-body">
<a href="{$_url}order/buy/{$router['id']}/{$plan['id']}"
onclick="return confirm('{Lang::T('Buy this? your active package will be overwrite')}')"
class="btn btn-sm btn-block btn-primary">Buy</a>
</div>
</div>
</div>
{/if}
{/foreach}
</div>
{/if}
</div>
{/foreach}
</div>

View File

@ -3,8 +3,10 @@
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="panel mb20 {if $trx['status']==1}panel-warning{elseif $trx['status']==2}panel-success{elseif $trx['status']==3}panel-danger{elseif $trx['status']==4}panel-danger{else}panel-primary{/if} panel-hovered">
<div
class="panel mb20 {if $trx['status']==1}panel-warning{elseif $trx['status']==2}panel-success{elseif $trx['status']==3}panel-danger{elseif $trx['status']==4}panel-danger{else}panel-primary{/if} panel-hovered">
<div class="panel-footer">Transaction #{$trx['id']}</div>
{if $plan['type']!='Balance'}
<div class="panel-body">
<div class="panel panel-primary panel-hovered">
<div class="panel-heading">{$router['name']}</div>
@ -13,21 +15,25 @@
</div>
</div>
</div>
{/if}
<div class="table-responsive">
<table class="table table-bordered table-striped table-bordered">
<tbody>
<tr>
<td>{Lang::T('Status')}</td>
<td>{if $trx['status']==1}{Lang::T('UNPAID')}{elseif $trx['status']==2}{Lang::T('PAID')}{elseif $trx['status']==3}{Lang::T('FAILED')}{elseif $trx['status']==4}{Lang::T('CANCELED')}{else}{Lang::T('UNKNOWN')}{/if}</td>
<td>{if $trx['status']==1}{Lang::T('UNPAID')}{elseif $trx['status']==2}{Lang::T('PAID')}{elseif $trx['status']==3}{Lang::T('FAILED')}{elseif $trx['status']==4}{Lang::T('CANCELED')}{else}{Lang::T('UNKNOWN')}{/if}
</td>
</tr>
<tr>
<td>{Lang::T('expired')}</td>
<td>{date($_c['date_format'], strtotime($trx['expired_date']))} {date('H:i', strtotime($trx['expired_date']))} </td>
<td>{date($_c['date_format'], strtotime($trx['expired_date']))}
{date('H:i', strtotime($trx['expired_date']))} </td>
</tr>
{if $trx['status']==2}
<tr>
<td>{Lang::T('Paid Date')}</td>
<td>{date($_c['date_format'], strtotime($trx['paid_date']))} {date('H:i', strtotime($trx['paid_date']))} </td>
<td>{date($_c['date_format'], strtotime($trx['paid_date']))}
{date('H:i', strtotime($trx['paid_date']))} </td>
</tr>
{/if}
<tr>
@ -36,12 +42,13 @@
</tr>
<tr>
<td>{$_L['Plan_Price']}</td>
<td>{$plan['price']}</td>
<td>{Lang::moneyFormat($plan['price'])}</td>
</tr>
<tr>
<td>{Lang::T('Type')}</td>
<td>{$plan['type']}</td>
</tr>
{if $plan['type']!='Balance'}
{if $plan['type'] eq 'Hotspot'}
<tr>
<td>{Lang::T('Plan_Type')}</td>
@ -68,23 +75,25 @@
</tr>
<tr>
<td>{$_L['Bandwidth_Plans']}</td>
<td>{$bandw['name_bw']}<br>{$bandw['rate_down']}{$bandw['rate_down_unit']}/{$bandw['rate_up']}{$bandw['rate_up_unit']}</td>
<td>{$bandw['name_bw']}<br>{$bandw['rate_down']}{$bandw['rate_down_unit']}/{$bandw['rate_up']}{$bandw['rate_up_unit']}
</td>
</tr>
{/if}
</tbody>
</table>
</div>
{if $trx['status']==1}
<div class="panel-footer ">
<div class="btn-group btn-group-justified">
<a href="{$trx['pg_url_payment']}"
{if $trx['gateway']=='midtrans'}
target="_blank"
{/if} class="btn btn-primary">{Lang::T('PAY NOW')}</a>
<a href="{$_url}order/view/{$trx['id']}/check" class="btn btn-info">{Lang::T('Check for Payment')}</a>
<a href="{$trx['pg_url_payment']}" {if $trx['gateway']=='midtrans'} target="_blank" {/if}
class="btn btn-primary">{Lang::T('PAY NOW')}</a>
<a href="{$_url}order/view/{$trx['id']}/check"
class="btn btn-info">{Lang::T('Check for Payment')}</a>
</div>
</div>
<div class="panel-footer ">
<a href="{$_url}order/view/{$trx['id']}/cancel" class="btn btn-danger" onclick="return confirm('{Lang::T('Cancel it?')}')">{Lang::T('Cancel')}</a>
<a href="{$_url}order/view/{$trx['id']}/cancel" class="btn btn-danger"
onclick="return confirm('{Lang::T('Cancel it?')}')">{Lang::T('Cancel')}</a>
</div>
{/if}
</div>