Additional Cost Customer side

This commit is contained in:
Ibnu Maksum 2024-03-14 14:42:20 +07:00
parent 68d3c9181c
commit cc8d810d45
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
6 changed files with 99 additions and 25 deletions

View File

@ -671,6 +671,8 @@ class Package
$_admin = Admin::_info($in['admin_id']); $_admin = Admin::_info($in['admin_id']);
// if admin not deleted // if admin not deleted
if ($_admin) $admin = $_admin; if ($_admin) $admin = $_admin;
}else{
$admin['fullname'] = 'Customer';
} }
//print //print
$invoice = Lang::pad($config['CompanyName'], ' ', 2) . "\n"; $invoice = Lang::pad($config['CompanyName'], ' ', 2) . "\n";

View File

@ -124,16 +124,26 @@ switch ($action) {
$trx = ORM::for_table('tbl_payment_gateway') $trx = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username']) ->where('username', $user['username'])
->find_one($trxid); ->find_one($trxid);
if ('midtrans' == $trx['gateway']) {
//Hapus invoice link
}
} }
if (empty($trx)) { if (empty($trx)) {
r2(U . "order/package", 'e', Lang::T("Transaction Not found")); r2(U . "order/package", 'e', Lang::T("Transaction Not found"));
} }
$router = ORM::for_table('tbl_routers')->find_one($trx['routers_id']); $router = Mikrotik::info($trx['routers']);
$plan = ORM::for_table('tbl_plans')->find_one($trx['plan_id']); $plan = ORM::for_table('tbl_plans')->find_one($trx['plan_id']);
$bandw = ORM::for_table('tbl_bandwidth')->find_one($plan['id_bw']); $bandw = ORM::for_table('tbl_bandwidth')->find_one($plan['id_bw']);
$add_cost = 0;
$add_rem = User::getAttribute("Additional Remaining", $id_customer);
if ($add_rem != 0) {
$add_cost = User::getAttribute("Additional Cost", $id_customer);
if (empty($add_cost)) {
$add_cost = 0;
}else{
$bills = User::getAttributes("Bill", $id_customer);
$ui->assign('bills', $bills);
}
}
$ui->assign('add_cost', $add_cost);
$ui->assign('trx', $trx); $ui->assign('trx', $trx);
$ui->assign('router', $router); $ui->assign('router', $router);
$ui->assign('plan', $plan); $ui->assign('plan', $plan);
@ -157,11 +167,19 @@ switch ($action) {
} else { } else {
$router_name = $plan['routers']; $router_name = $plan['routers'];
} }
$add_cost = 0;
$add_rem = User::getAttribute("Additional Remaining", $id_customer);
if ($add_rem != 0) {
$add_cost = User::getAttribute("Additional Cost", $id_customer);
if (empty($add_cost)) {
$add_cost = 0;
}
}
if ($plan && $plan['enabled'] && $user['balance'] >= $plan['price']) { if ($plan && $plan['enabled'] && $user['balance'] >= $plan['price']) {
if (Package::rechargeUser($user['id'], $router_name, $plan['id'], 'Customer', 'Balance')) { if (Package::rechargeUser($user['id'], $router_name, $plan['id'], 'Customer', 'Balance')) {
// if success, then get the balance // if success, then get the balance
Balance::min($user['id'], $plan['price']); Balance::min($user['id'], $plan['price'] + $add_cost);
r2(U . "home", 's', Lang::T("Success to buy package")); r2(U . "voucher/invoice/", 's', Lang::T("Success to buy package"));
} else { } else {
r2(U . "order/package", 'e', Lang::T("Failed to buy package")); r2(U . "order/package", 'e', Lang::T("Failed to buy package"));
Message::sendTelegram("Buy Package with Balance Failed\n\n#u$c[username] #buy \n" . $plan['name_plan'] . Message::sendTelegram("Buy Package with Balance Failed\n\n#u$c[username] #buy \n" . $plan['name_plan'] .
@ -190,6 +208,16 @@ switch ($action) {
} else { } else {
$router_name = $plan['routers']; $router_name = $plan['routers'];
} }
$add_rem = User::getAttribute("Additional Remaining", $id_customer);
if ($add_rem != 0) {
$add_cost = User::getAttribute("Additional Cost", $id_customer);
if (!empty($add_cost)) {
$bills = User::getAttributes("Bill", $id_customer);
$ui->assign('bills', $bills);
$ui->assign('add_cost', $add_cost);
$plan['price'] += $add_cost;
}
}
if (isset($_POST['send']) && $_POST['send'] == 'plan') { if (isset($_POST['send']) && $_POST['send'] == 'plan') {
$target = ORM::for_table('tbl_customers')->where('username', _post('username'))->find_one(); $target = ORM::for_table('tbl_customers')->where('username', _post('username'))->find_one();
if (!$target) { if (!$target) {
@ -267,13 +295,13 @@ switch ($action) {
r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address")); r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address"));
} }
$pgs = array_values(explode(',', $config['payment_gateway'])); $pgs = array_values(explode(',', $config['payment_gateway']));
if(count($pgs)==0){ if (count($pgs) == 0) {
sendTelegram("Payment Gateway not set, please set it in Settings"); sendTelegram("Payment Gateway not set, please set it in Settings");
_log(Lang::T("Payment Gateway not set, please set it in Settings")); _log(Lang::T("Payment Gateway not set, please set it in Settings"));
r2(U . "home", 'e', Lang::T("Failed to create Transaction..")); r2(U . "home", 'e', Lang::T("Failed to create Transaction.."));
} }
if(count($pgs)>1){ if (count($pgs) > 1) {
$ui->assign('pgs',$pgs ); $ui->assign('pgs', $pgs);
//$ui->assign('pgs', $pgs); //$ui->assign('pgs', $pgs);
$ui->assign('route2', $routes[2]); $ui->assign('route2', $routes[2]);
$ui->assign('route3', $routes[3]); $ui->assign('route3', $routes[3]);
@ -281,12 +309,12 @@ switch ($action) {
//$ui->assign('plan', $plan); //$ui->assign('plan', $plan);
$ui->display('user-selectGateway.tpl'); $ui->display('user-selectGateway.tpl');
break; break;
}else{ } else {
if(empty($pgs[0])){ if (empty($pgs[0])) {
sendTelegram("Payment Gateway not set, please set it in Settings"); sendTelegram("Payment Gateway not set, please set it in Settings");
_log(Lang::T("Payment Gateway not set, please set it in Settings")); _log(Lang::T("Payment Gateway not set, please set it in Settings"));
r2(U . "home", 'e', Lang::T("Failed to create Transaction..")); r2(U . "home", 'e', Lang::T("Failed to create Transaction.."));
}else{ } else {
$_POST['gateway'] = $pgs[0]; $_POST['gateway'] = $pgs[0];
} }
} }
@ -333,6 +361,16 @@ switch ($action) {
} }
} }
} }
$add_cost = 0;
if ($router['name'] != 'balance') {
$add_rem = User::getAttribute("Additional Remaining", $id_customer);
if ($add_rem != 0) {
$add_cost = User::getAttribute("Additional Cost", $id_customer);
if (empty($add_cost)) {
$add_cost = 0;
}
}
}
if (empty($id)) { if (empty($id)) {
$d = ORM::for_table('tbl_payment_gateway')->create(); $d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $user['username']; $d->username = $user['username'];
@ -341,7 +379,7 @@ switch ($action) {
$d->plan_name = $plan['name_plan']; $d->plan_name = $plan['name_plan'];
$d->routers_id = $router['id']; $d->routers_id = $router['id'];
$d->routers = $router['name']; $d->routers = $router['name'];
$d->price = $plan['price']; $d->price = ($plan['price'] + $add_cost);
$d->created_date = date('Y-m-d H:i:s'); $d->created_date = date('Y-m-d H:i:s');
$d->status = 1; $d->status = 1;
$d->save(); $d->save();
@ -353,7 +391,7 @@ switch ($action) {
$d->plan_name = $plan['name_plan']; $d->plan_name = $plan['name_plan'];
$d->routers_id = $router['id']; $d->routers_id = $router['id'];
$d->routers = $router['name']; $d->routers = $router['name'];
$d->price = $plan['price']; $d->price = ($plan['price'] + $add_cost);
$d->created_date = date('Y-m-d H:i:s'); $d->created_date = date('Y-m-d H:i:s');
$d->status = 1; $d->status = 1;
$d->save(); $d->save();

View File

@ -51,9 +51,17 @@ switch ($action) {
break; break;
case 'invoice': case 'invoice':
$id = $routes[2]; $id = $routes[2];
$in = ORM::for_table('tbl_transactions')->where('username', $user['username'])->where('id', $id)->find_one(); if(empty($id)){
Package::createInvoice($in); $in = ORM::for_table('tbl_transactions')->where('username', $user['username'])->order_by_desc('id')->find_one();
$ui->display('invoice-customer.tpl'); }else{
$in = ORM::for_table('tbl_transactions')->where('username', $user['username'])->where('id', $id)->find_one();
}
if($in){
Package::createInvoice($in);
$ui->display('invoice-customer.tpl');
}else{
r2(U . 'voucher/list-activated', 'e', Lang::T('Not Found'));
}
default: default:
$ui->display('a404.tpl'); $ui->display('a404.tpl');
} }

View File

@ -487,5 +487,7 @@
"Current_Cycle": "Current Cycle", "Current_Cycle": "Current Cycle",
"Additional_Cost": "Additional Cost", "Additional_Cost": "Additional Cost",
"Remaining": "Remaining", "Remaining": "Remaining",
"": "" "": "",
"Not_Found": "Not Found",
"Cash": "Cash"
} }

View File

@ -6,7 +6,7 @@
<div <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"> 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> <div class="panel-footer">Transaction #{$trx['id']}</div>
{if $trx['routers']!='balance'} {if !in_array($trx['routers'],['balance','radius'])}
<div class="panel-body"> <div class="panel-body">
<div class="panel panel-primary panel-hovered"> <div class="panel panel-primary panel-hovered">
<div class="panel-heading">{$router['name']}</div> <div class="panel-heading">{$router['name']}</div>
@ -30,8 +30,8 @@
{date('H:i', strtotime($trx['paid_date']))} </td> {date('H:i', strtotime($trx['paid_date']))} </td>
</tr> </tr>
<tr> <tr>
{if $trx['plan_name'] == 'Receive Balance'} {if $trx['plan_name'] == 'Receive Balance'}
<td>{Lang::T('From')}</td> <td>{Lang::T('From')}</td>
{else} {else}
<td>{Lang::T('To')}</td> <td>{Lang::T('To')}</td>
{/if} {/if}
@ -67,9 +67,21 @@
<td>{Lang::T('Plan Name')}</td> <td>{Lang::T('Plan Name')}</td>
<td>{$plan['name_plan']}</td> <td>{$plan['name_plan']}</td>
</tr> </tr>
{if $add_cost>0}
{foreach $bills as $k => $v}
<tr>
<td>{$k}</td>
<td>{Lang::moneyFormat($v)}</td>
</tr>
{/foreach}
<tr>
<td>{Lang::T('Additional Cost')}</td>
<td>{Lang::moneyFormat($add_cost)}</td>
</tr>
{/if}
<tr> <tr>
<td>{Lang::T('Plan Price')}</td> <td>{Lang::T('Plan Price')}{if $add_cost>0}<small> + {Lang::T('Additional Cost')}{/if}</small></td>
<td>{Lang::moneyFormat($plan['price'])}</td> <td style="font-size: large; font-weight:bolder; font-family: 'Courier New', Courier, monospace; ">{Lang::moneyFormat($trx['price'])}</td>
</tr> </tr>
<tr> <tr>
<td>{Lang::T('Type')}</td> <td>{Lang::T('Type')}</td>

View File

@ -12,9 +12,21 @@
<td>{Lang::T('Type')}</td> <td>{Lang::T('Type')}</td>
<td>{$plan['type']}</td> <td>{$plan['type']}</td>
</tr> </tr>
{if $add_cost>0}
{foreach $bills as $k => $v}
<tr>
<td>{$k}</td>
<td>{Lang::moneyFormat($v)}</td>
</tr>
{/foreach}
<tr>
<td>{Lang::T('Additional Cost')}</td>
<td>{Lang::moneyFormat($add_cost)}</td>
</tr>
{/if}
<tr> <tr>
<td>{Lang::T('Price')}</td> <td>{Lang::T('Price')}{if $add_cost>0}<small> + {Lang::T('Additional Cost')}{/if}</td>
<td>{Lang::moneyFormat($plan['price'])}</td> <td style="font-size: large; font-weight:bolder; font-family: 'Courier New', Courier, monospace; ">{Lang::moneyFormat($plan['price'])}</td>
</tr> </tr>
<tr> <tr>
<td>{Lang::T('Validity')}</td> <td>{Lang::T('Validity')}</td>