Merge pull request #173 from Focuslinkstech/Development

Update: Tax System
This commit is contained in:
iBNu Maksum 2024-04-15 09:10:08 +07:00 committed by GitHub
commit 6955d3fd8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 375 additions and 19 deletions

View File

@ -245,10 +245,41 @@ switch ($action) {
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown;
$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;
$d->id_bw = $id_bw;
$d->price = $price;
$d->price = $price_with_tax; // Set price with or without tax based on configuration
$d->type = 'Hotspot';
$d->typebp = $typebp;
$d->plan_type = $plan_type;
@ -361,9 +392,39 @@ switch ($action) {
}
}
// 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;
$d->price = $price_with_tax; // Set price with or without tax based on configuration
$d->typebp = $typebp;
$d->limit_type = $limit_type;
$d->time_limit = $time_limit;
@ -518,11 +579,42 @@ switch ($action) {
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown;
$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;
$d->id_bw = $id_bw;
$d->price = $price;
$d->price = $price_with_tax;
$d->plan_type = $plan_type;
$d->validity = $validity;
$d->validity_unit = $validity_unit;
@ -621,9 +713,39 @@ switch ($action) {
}
}
// 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;
$d->price = $price_with_tax;
$d->plan_type = $plan_type;
$d->validity = $validity;
$d->validity_unit = $validity_unit;
@ -700,8 +822,37 @@ 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;
$d->price = $price_with_tax;
$d->enabled = $enabled;
$d->prepaid = 'yes';
$d->save();
@ -730,11 +881,43 @@ 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;
$d->id_bw = 0;
$d->price = $price;
$d->price = $price_with_tax;
$d->validity = 0;
$d->validity_unit = 'Months';
$d->routers = '';

View File

@ -119,7 +119,7 @@ switch ($action) {
die();
}
}
// save all settings
// Save all settings including tax system
foreach ($_POST as $key => $value) {
$d = ORM::for_table('tbl_appconfig')->where('setting', $key)->find_one();
if ($d) {
@ -133,6 +133,33 @@ switch ($action) {
}
}
// Handle tax system separately
$enable_tax = isset($_POST['enable_tax']) ? $_POST['enable_tax'] : 'no';
$tax_rate = isset($_POST['tax_rate']) ? $_POST['tax_rate'] : '0.01'; // Default tax rate 1%
// Save or update tax system settings
$d_tax_enable = ORM::for_table('tbl_appconfig')->where('setting', 'enable_tax')->find_one();
if ($d_tax_enable) {
$d_tax_enable->value = $enable_tax;
$d_tax_enable->save();
} else {
$d_tax_enable = ORM::for_table('tbl_appconfig')->create();
$d_tax_enable->setting = 'enable_tax';
$d_tax_enable->value = $enable_tax;
$d_tax_enable->save();
}
$d_tax_rate = ORM::for_table('tbl_appconfig')->where('setting', 'tax_rate')->find_one();
if ($d_tax_rate) {
$d_tax_rate->value = $tax_rate;
$d_tax_rate->save();
} else {
$d_tax_rate = ORM::for_table('tbl_appconfig')->create();
$d_tax_rate->setting = 'tax_rate';
$d_tax_rate->value = $tax_rate;
$d_tax_rate->save();
}
//checkbox
$checks = ['hide_mrc', 'hide_tms', 'hide_aui', 'hide_al', 'hide_uet', 'hide_vs', 'hide_pg'];
foreach ($checks as $check) {

View File

@ -553,6 +553,69 @@
<p class="help-block col-md-4">{Lang::T('The method which OTP will be sent to user')}</p>
</div>
</div>
<div class="panel-heading">
<div class="btn-group pull-right">
<button class="btn btn-primary btn-xs" title="save" type="submit">
<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>
</button>
</div>
{Lang::T('Tax System')}
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Enable Tax System')}</label>
<div class="col-md-6">
<select name="enable_tax" id="enable_tax" class="form-control">
<option value="no" {if $_c['enable_tax']=='no' }selected="selected" {/if}>
{Lang::T('No')}
</option>
<option value="yes" {if $_c['enable_tax']=='yes' }selected="selected" {/if}>
{Lang::T('Yes')}
</option>
</select>
</div>
<p class="help-block col-md-4">{Lang::T('Tax will be calculated in Internet Plan Price')}</p>
</div>
<div class="form-group">
<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}>
{Lang::T('0.5%')}
</option>
<option value="0.01" {if $_c['tax_rate']=='0.01' }selected="selected" {/if}>
{Lang::T('1%')}
</option>
<option value="0.015" {if $_c['tax_rate']=='0.015' }selected="selected" {/if}>
{Lang::T('1.5%')}
</option>
<option value="0.02" {if $_c['tax_rate']=='0.02' }selected="selected" {/if}>
{Lang::T('2%')}
</option>
<option value="0.05" {if $_c['tax_rate']=='0.05' }selected="selected" {/if}>
{Lang::T('5%')}
</option>
<option value="0.1" {if $_c['tax_rate']=='0.1' }selected="selected" {/if}>
{Lang::T('10%')}
</option>
<!-- Custom tax rate option -->
<option value="custom" {if $_c['tax_rate']=='custom' }selected="selected" {/if}>{Lang::T('Custom')}</option>
</select>
</div>
<p class="help-block col-md-4">{Lang::T('Tax Rates in percentage')}</p>
</div>
<!-- Custom tax rate input field (initially hidden) -->
<div class="form-group" id="customTaxRate" style="display: none;">
<label class="col-md-2 control-label">{Lang::T('Custom Tax Rate')}</label>
<div class="col-md-6">
<input type="text" value="{$_c['custom_tax_rate']}" class="form-control" name="custom_tax_rate" id="custom_tax_rate"
placeholder="{Lang::T('Enter Custom Tax Rate')}">
</div>
<p class="help-block col-md-4">{Lang::T('Enter the custom tax rate (e.g., 3.75 for 3.75%)')}</p>
</div>
</div>
{* <div class="panel-heading" id="envato">
<div class="btn-group pull-right">
<button class="btn btn-primary btn-xs" title="save" type="submit"><span
@ -635,4 +698,26 @@ add dst-host=*.{$_domain}</pre>
window.location.href = '{$_url}settings/app&testTg=test';
}
</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
// Function to toggle visibility of custom tax rate input field
function toggleCustomTaxRate() {
var taxRateSelect = document.getElementById("tax_rate");
var customTaxRateInput = document.getElementById("customTaxRate");
if (taxRateSelect.value === "custom") {
customTaxRateInput.style.display = "block";
} else {
customTaxRateInput.style.display = "none";
}
}
// Call the function when the page loads
toggleCustomTaxRate();
// Call the function whenever the tax rate dropdown value changes
document.getElementById("tax_rate").addEventListener("change", toggleCustomTaxRate);
});
</script>
{include file="sections/footer.tpl"}

View File

@ -32,6 +32,16 @@
<input type="number" class="form-control" name="price" required>
</div>
</div>
{if $_c['enable_tax'] == 'yes'}
{if $_c['tax_rate'] == 'custom'}
<p class="help-block col-md-4">{number_format($_c['custom_tax_rate'], 2)} % {Lang::T('Tax Rates
will be added')}</p>
{else}
<p class="help-block col-md-4">{number_format($_c['tax_rate'] * 100, 2)} % {Lang::T('Tax Rates
will be added')}</p>
{/if}
{/if}
</div>
<div class="form-group">

View File

@ -32,6 +32,16 @@
<input type="number" class="form-control" name="price" value="{$d['price']}" required>
</div>
</div>
{if $_c['enable_tax'] == 'yes'}
{if $_c['tax_rate'] == 'custom'}
<p class="help-block col-md-4">{number_format($_c['custom_tax_rate'], 2)} % {Lang::T('Tax Rates
will be added')}</p>
{else}
<p class="help-block col-md-4">{number_format($_c['tax_rate'] * 100, 2)} % {Lang::T('Tax Rates
will be added')}</p>
{/if}
{/if}
</div>
<div class="form-group">

View File

@ -106,7 +106,9 @@
$j(document).ready(function () {
$j('#customerTable').DataTable({
"pagingType": "full_numbers"
"pagingType": "full_numbers",
"lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],
"pageLength": 5
});
});
</script>

View File

@ -114,6 +114,16 @@
<input type="number" class="form-control" name="price" required>
</div>
</div>
{if $_c['enable_tax'] == 'yes'}
{if $_c['tax_rate'] == 'custom'}
<p class="help-block col-md-4">{number_format($_c['custom_tax_rate'], 2)} % {Lang::T('Tax Rates
will be added')}</p>
{else}
<p class="help-block col-md-4">{number_format($_c['tax_rate'] * 100, 2)} % {Lang::T('Tax Rates
will be added')}</p>
{/if}
{/if}
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Shared Users')}</label>

View File

@ -133,6 +133,16 @@
<input type="number" class="form-control" name="price" value="{$d['price']}" required>
</div>
</div>
{if $_c['enable_tax'] == 'yes'}
{if $_c['tax_rate'] == 'custom'}
<p class="help-block col-md-4">{number_format($_c['custom_tax_rate'], 2)} % {Lang::T('Tax Rates
will be added')}</p>
{else}
<p class="help-block col-md-4">{number_format($_c['tax_rate'] * 100, 2)} % {Lang::T('Tax Rates
will be added')}</p>
{/if}
{/if}
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Shared Users')}</label>

View File

@ -64,6 +64,15 @@
<input type="number" class="form-control" name="price" required>
</div>
</div>
{if $_c['enable_tax'] == 'yes'}
{if $_c['tax_rate'] == 'custom'}
<p class="help-block col-md-4">{number_format($_c['custom_tax_rate'], 2)} % {Lang::T('Tax Rates
will be added')}</p>
{else}
<p class="help-block col-md-4">{number_format($_c['tax_rate'] * 100, 2)} % {Lang::T('Tax Rates
will be added')}</p>
{/if}
{/if}
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Plan Validity')}</label>

View File

@ -68,6 +68,16 @@
<input type="number" class="form-control" name="price" required value="{$d['price']}">
</div>
</div>
{if $_c['enable_tax'] == 'yes'}
{if $_c['tax_rate'] == 'custom'}
<p class="help-block col-md-4">{number_format($_c['custom_tax_rate'], 2)} % {Lang::T('Tax Rates
will be added')}</p>
{else}
<p class="help-block col-md-4">{number_format($_c['tax_rate'] * 100, 2)} % {Lang::T('Tax Rates
will be added')}</p>
{/if}
{/if}
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Plan Validity')}</label>