Add plan details to gateway
This commit is contained in:
Focuslinkstech 2024-05-17 10:59:41 +01:00
parent 6b8501313d
commit fded62b39d
5 changed files with 82 additions and 201 deletions

View File

@ -820,4 +820,11 @@ class Package
$ui->assign('whatsapp', urlencode("```$invoice```"));
$ui->assign('in', $in);
}
public static function tax($price, $tax_rate = 1)
{
// Convert tax rate to decimal
$tax_rate_decimal = $tax_rate / 100;
$tax = $price * $tax_rate_decimal;
return $tax;
}
}

View File

@ -131,7 +131,7 @@ switch ($action) {
$router = Mikrotik::info($trx['routers']);
$plan = ORM::for_table('tbl_plans')->find_one($trx['plan_id']);
$bandw = ORM::for_table('tbl_bandwidth')->find_one($plan['id_bw']);
$invoice = ORM::for_table('tbl_transactions')->where("invoice",$trx['trx_invoice'])->find_one();
$invoice = ORM::for_table('tbl_transactions')->where("invoice", $trx['trx_invoice'])->find_one();
$ui->assign('invoice', $invoice);
$ui->assign('trx', $trx);
$ui->assign('router', $router);
@ -280,6 +280,16 @@ switch ($action) {
if (strpos($user['email'], '@') === false) {
r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address"));
}
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : null;
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : null;
if ($tax_rate_setting === 'custom') {
$tax_rate = $custom_tax_rate;
} else {
$tax_rate = $tax_rate_setting;
}
$plan = ORM::for_table('tbl_plans')->find_one($routes['3']);
$tax = Package::tax($plan['price'], $tax_rate);
$pgs = array_values(explode(',', $config['payment_gateway']));
if (count($pgs) == 0) {
sendTelegram("Payment Gateway not set, please set it in Settings");
@ -288,11 +298,12 @@ switch ($action) {
}
if (count($pgs) > 1) {
$ui->assign('pgs', $pgs);
//$ui->assign('pgs', $pgs);
if ($tax_enable === 'yes') {
$ui->assign('tax', $tax);
}
$ui->assign('route2', $routes[2]);
$ui->assign('route3', $routes[3]);
//$ui->assign('plan', $plan);
$ui->assign('plan', $plan);
$ui->display('user-selectGateway.tpl');
break;
} else {

View File

@ -244,37 +244,6 @@ switch ($action) {
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
$rate = trim($rate . " " . $b['burst']);
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
// Create new plan
$d = ORM::for_table('tbl_plans')->create();
$d->name_plan = $name;
@ -391,37 +360,6 @@ switch ($action) {
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
}
}
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
$d->name_plan = $name;
$d->id_bw = $id_bw;
$d->price = $price_with_tax; // Set price with or without tax based on configuration
@ -578,38 +516,6 @@ switch ($action) {
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
$rate = trim($rate . " " . $b['burst']);
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
$d = ORM::for_table('tbl_plans')->create();
$d->type = 'PPPOE';
$d->name_plan = $name;
@ -712,37 +618,6 @@ switch ($action) {
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
}
}
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
$d->name_plan = $name;
$d->id_bw = $id_bw;
$d->price = $price_with_tax;
@ -822,35 +697,6 @@ switch ($action) {
}
run_hook('edit_ppoe'); #HOOK
if ($msg == '') {
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
$d->name_plan = $name;
$d->price = $price_with_tax;
$d->enabled = $enabled;
@ -881,38 +727,6 @@ switch ($action) {
}
run_hook('add_ppoe'); #HOOK
if ($msg == '') {
// Check if tax is enabled in config
$tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no';
// Default tax rate
$default_tax_rate = 0.01; // Default tax rate 1%
// Check if tax rate is set to custom in config
$tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : $default_tax_rate;
// Check if tax rate is custom
if ($tax_rate_setting === 'custom') {
// Check if custom tax rate is set in config
$custom_tax_rate = isset($config['custom_tax_rate']) ? (float)$config['custom_tax_rate'] : $default_tax_rate;
// Convert custom tax rate to decimal
$custom_tax_rate_decimal = $custom_tax_rate / 100;
$tax_rate = $custom_tax_rate_decimal;
} else {
// Use tax rate
$tax_rate = $tax_rate_setting;
}
// Calculate the new price with tax if tax is enabled
if ($tax_enable === 'yes') {
$price_with_tax = $price + ($price * $tax_rate);
} else {
// If tax is not enabled, use the original price
$price_with_tax = $price;
}
$d = ORM::for_table('tbl_plans')->create();
$d->type = 'Balance';
$d->name_plan = $name;

View File

@ -631,22 +631,22 @@
<label class="col-md-2 control-label">{Lang::T('Tax Rate')}</label>
<div class="col-md-6">
<select name="tax_rate" id="tax_rate" class="form-control">
<option value="0.005" {if $_c['tax_rate']=='0.005' }selected="selected" {/if}>
<option value="0.5" {if $_c['tax_rate']=='0.5' }selected="selected" {/if}>
{Lang::T('0.5%')}
</option>
<option value="0.01" {if $_c['tax_rate']=='0.01' }selected="selected" {/if}>
<option value="1" {if $_c['tax_rate']=='1' }selected="selected" {/if}>
{Lang::T('1%')}
</option>
<option value="0.015" {if $_c['tax_rate']=='0.015' }selected="selected" {/if}>
<option value="1.5" {if $_c['tax_rate']=='1.5' }selected="selected" {/if}>
{Lang::T('1.5%')}
</option>
<option value="0.02" {if $_c['tax_rate']=='0.02' }selected="selected" {/if}>
<option value="0.20" {if $_c['tax_rate']=='2' }selected="selected" {/if}>
{Lang::T('2%')}
</option>
<option value="0.05" {if $_c['tax_rate']=='0.05' }selected="selected" {/if}>
<option value="0.50" {if $_c['tax_rate']=='5' }selected="selected" {/if}>
{Lang::T('5%')}
</option>
<option value="0.1" {if $_c['tax_rate']=='0.1' }selected="selected" {/if}>
<option value="10" {if $_c['tax_rate']=='10' }selected="selected" {/if}>
{Lang::T('10%')}
</option>
<!-- Custom tax rate option -->

View File

@ -11,15 +11,64 @@
<div class="col-md-8">
<select name="gateway" id="gateway" class="form-control">
{foreach $pgs as $pg}
<option value="{$pg}">
{ucwords($pg)}</option>
<option value="{$pg}">
{ucwords($pg)}</option>
{/foreach}
</select>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-block btn-primary">{Lang::T('Pay Now')}</button>
</div>
</div>
</div>
<div class="panel-body">
<center><b>{Lang::T('Package Details')}</b></center>
<ul class="list-group list-group-unbordered">
<li class="list-group-item">
<b>{Lang::T('Plan Name')}</b> <span class="pull-right">{$plan['name_plan']}</span>
</li>
{if $plan['is_radius'] or $plan['routers']}
<li class="list-group-item">
<b>{Lang::T('Location')}</b> <span class="pull-right">{if
$plan['is_radius']}Radius{else}{$plan['routers']}{/if}</span>
</li>
{/if}
<li class="list-group-item">
<b>{Lang::T('Type')}</b> <span class="pull-right">{if $plan['prepaid'] eq
'yes'}Prepaid{else}Postpaid{/if}
{$plan['type']}</span>
</li>
<li class="list-group-item">
<b>{Lang::T('Plan Price')}</b> <span class="pull-right">{if $using eq
'zero'}{Lang::moneyFormat(0)}{else}{Lang::moneyFormat($plan['price'])}{/if}</span>
</li>
{if $plan['validity']}
<li class="list-group-item">
<b>{Lang::T('Plan Validity')}</b> <span class="pull-right">{$plan['validity']}
{$plan['validity_unit']}</span>
</li>
{/if}
</ul>
<center><b>{Lang::T('Summary')}</b></center>
<ul class="list-group list-group-unbordered">
{if $tax}
<li class="list-group-item">
<b>{Lang::T('Tax')}</b> <span
class="pull-right">{Lang::moneyFormat($tax)}</span>
</li>
<li class="list-group-item">
<b>{Lang::T('Total')}</b> <small>({Lang::T('Plan Price')} + {Lang::T('Tax')})</small><span class="pull-right"
style="font-size: large; font-weight:bolder; font-family: 'Courier New', Courier, monospace; ">{Lang::moneyFormat($plan['price']+$tax)}</span>
</li>
{else}
<li class="list-group-item">
<b>{Lang::T('Total')}</b> <span class="pull-right"
style="font-size: large; font-weight:bolder; font-family: 'Courier New', Courier, monospace; ">
{Lang::moneyFormat($plan['price'])}</span>
</li>
{/if}
</ul>
<center>
<button type="submit" class="btn btn-primary">{Lang::T('Pay Now')}</button><br>
<a class="btn btn-link" href="{$_url}home">{Lang::T('Cancel')}</a>
</center>
</form>
</div>
</div>