forked from kevinowino869/mitrobill
Buy Balance Done
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 (empty($router) || empty($plan)) {
|
||||
r2(U . $back, 'e', Lang::T("Plan Not found"));
|
||||
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','');
|
||||
}
|
||||
|
@ -355,4 +355,7 @@ $_L['User_Cannot_change_this_only_admin_if_it_Empty_it_will_use_user_password']
|
||||
$_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['Balance_Plans'] = 'Balance Plans';
|
||||
$_L['Buy_Balance'] = 'Buy Balance?';
|
||||
$_L['Price'] = 'Price';
|
||||
$_L['Validity'] = 'Validity';
|
||||
|
@ -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..."
|
||||
}
|
||||
|
Reference in New Issue
Block a user