change disable_coupons != yes to enable_coupons == yes
This commit is contained in:
parent
0e302a5171
commit
690e5912c0
@ -411,89 +411,91 @@ switch ($action) {
|
|||||||
list($bills, $add_cost) = User::getBills($id_customer);
|
list($bills, $add_cost) = User::getBills($id_customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($_SESSION['coupon_attempts'])) {
|
if($config['enable_coupons']){
|
||||||
$_SESSION['coupon_attempts'] = 0;
|
if (!isset($_SESSION['coupon_attempts'])) {
|
||||||
$_SESSION['last_attempt_time'] = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($_SESSION['coupon_attempts'] >= 5) {
|
|
||||||
$timeout = 10 * 60; // 10 minutes in seconds
|
|
||||||
$time_diff = time() - $_SESSION['last_attempt_time'];
|
|
||||||
|
|
||||||
if ($time_diff >= $timeout) {
|
|
||||||
$_SESSION['coupon_attempts'] = 0;
|
$_SESSION['coupon_attempts'] = 0;
|
||||||
$_SESSION['last_attempt_time'] = time();
|
$_SESSION['last_attempt_time'] = time();
|
||||||
} else {
|
|
||||||
$remaining_time = ceil(($timeout - $time_diff) / 60);
|
|
||||||
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Too many invalid attempts. Please try again after $remaining_time minutes."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_post('coupon')) {
|
|
||||||
if ($plan['routers'] === 'balance') {
|
|
||||||
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon not available for Balance"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$coupon = ORM::for_table('tbl_coupons')->where('code', _post('coupon'))->find_one();
|
if ($_SESSION['coupon_attempts'] >= 5) {
|
||||||
|
$timeout = 10 * 60; // 10 minutes in seconds
|
||||||
|
$time_diff = time() - $_SESSION['last_attempt_time'];
|
||||||
|
|
||||||
if (!$coupon) {
|
if ($time_diff >= $timeout) {
|
||||||
$_SESSION['coupon_attempts']++;
|
$_SESSION['coupon_attempts'] = 0;
|
||||||
|
$_SESSION['last_attempt_time'] = time();
|
||||||
|
} else {
|
||||||
|
$remaining_time = ceil(($timeout - $time_diff) / 60);
|
||||||
|
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Too many invalid attempts. Please try again after $remaining_time minutes."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_post('coupon')) {
|
||||||
|
if ($plan['routers'] === 'balance') {
|
||||||
|
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon not available for Balance"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$coupon = ORM::for_table('tbl_coupons')->where('code', _post('coupon'))->find_one();
|
||||||
|
|
||||||
|
if (!$coupon) {
|
||||||
|
$_SESSION['coupon_attempts']++;
|
||||||
|
$_SESSION['last_attempt_time'] = time();
|
||||||
|
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($coupon['status'] != 'active') {
|
||||||
|
$_SESSION['coupon_attempts']++;
|
||||||
|
$_SESSION['last_attempt_time'] = time();
|
||||||
|
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon is not active"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset attempts after a successful coupon validation
|
||||||
|
$_SESSION['coupon_attempts'] = 0;
|
||||||
$_SESSION['last_attempt_time'] = time();
|
$_SESSION['last_attempt_time'] = time();
|
||||||
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon not found"));
|
|
||||||
|
$today = date('Y-m-d');
|
||||||
|
if ($today < $coupon['start_date'] || $today > $coupon['end_date']) {
|
||||||
|
$_SESSION['coupon_attempts']++;
|
||||||
|
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon is not valid for today"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($coupon['max_usage'] > 0 && $coupon['usage_count'] >= $coupon['max_usage']) {
|
||||||
|
$_SESSION['coupon_attempts']++;
|
||||||
|
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon usage limit reached"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($plan['price'] < $coupon['min_order_amount']) {
|
||||||
|
$_SESSION['coupon_attempts']++;
|
||||||
|
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("The order amount does not meet the minimum requirement for this coupon"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate discount value
|
||||||
|
$discount = 0;
|
||||||
|
switch ($coupon['type']) {
|
||||||
|
case 'percent':
|
||||||
|
$discount = ($coupon['value'] / 100) * $plan['price'];
|
||||||
|
if ($discount > $coupon['max_discount_amount']) {
|
||||||
|
$discount = $coupon['max_discount_amount'];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'fixed':
|
||||||
|
$discount = $coupon['value'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure discount does not exceed the plan price
|
||||||
|
if ($discount >= $plan['price']) {
|
||||||
|
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Discount value exceeds the plan price"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$plan['price'] -= $discount;
|
||||||
|
$coupon->usage_count = $coupon['usage_count'] + 1;
|
||||||
|
$coupon->save();
|
||||||
|
|
||||||
|
$ui->assign('discount', $discount);
|
||||||
|
$ui->assign('notify', Lang::T("Coupon applied successfully. You saved " . Lang::moneyFormat($discount)));
|
||||||
|
$ui->assign('notify_t', 's');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($coupon['status'] != 'active') {
|
|
||||||
$_SESSION['coupon_attempts']++;
|
|
||||||
$_SESSION['last_attempt_time'] = time();
|
|
||||||
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon is not active"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset attempts after a successful coupon validation
|
|
||||||
$_SESSION['coupon_attempts'] = 0;
|
|
||||||
$_SESSION['last_attempt_time'] = time();
|
|
||||||
|
|
||||||
$today = date('Y-m-d');
|
|
||||||
if ($today < $coupon['start_date'] || $today > $coupon['end_date']) {
|
|
||||||
$_SESSION['coupon_attempts']++;
|
|
||||||
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon is not valid for today"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($coupon['max_usage'] > 0 && $coupon['usage_count'] >= $coupon['max_usage']) {
|
|
||||||
$_SESSION['coupon_attempts']++;
|
|
||||||
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Coupon usage limit reached"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($plan['price'] < $coupon['min_order_amount']) {
|
|
||||||
$_SESSION['coupon_attempts']++;
|
|
||||||
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("The order amount does not meet the minimum requirement for this coupon"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate discount value
|
|
||||||
$discount = 0;
|
|
||||||
switch ($coupon['type']) {
|
|
||||||
case 'percent':
|
|
||||||
$discount = ($coupon['value'] / 100) * $plan['price'];
|
|
||||||
if ($discount > $coupon['max_discount_amount']) {
|
|
||||||
$discount = $coupon['max_discount_amount'];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'fixed':
|
|
||||||
$discount = $coupon['value'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure discount does not exceed the plan price
|
|
||||||
if ($discount >= $plan['price']) {
|
|
||||||
r2($_SERVER['HTTP_REFERER'], 'e', Lang::T("Discount value exceeds the plan price"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$plan['price'] -= $discount;
|
|
||||||
$coupon->usage_count = $coupon['usage_count'] + 1;
|
|
||||||
$coupon->save();
|
|
||||||
|
|
||||||
$ui->assign('discount', $discount);
|
|
||||||
$ui->assign('notify', Lang::T("Coupon applied successfully. You saved " . Lang::moneyFormat($discount)));
|
|
||||||
$ui->assign('notify_t', 's');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$tax = Package::tax($plan['price'] + $add_cost, $tax_rate);
|
$tax = Package::tax($plan['price'] + $add_cost, $tax_rate);
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{if file_exists("$PAGES_PATH/Payment_Info.html")}
|
{if file_exists("$PAGES_PATH/Payment_Info.html")}
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="panel panel-warning panel-hovered">
|
<div class="panel panel-warning panel-hovered">
|
||||||
<div class="panel-heading">{Lang::T('Payment Info')}</div>
|
<div class="panel-heading">{Lang::T('Payment Info')}</div>
|
||||||
<div class="panel-body">{include file="$PAGES_PATH/Payment_Info.html"}</div>
|
<div class="panel-body">{include file="$PAGES_PATH/Payment_Info.html"}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
<div class="{if file_exists("$PAGES_PATH/Payment_Info.html")}col-md-6{else}col-md-6 col-md-offset-3{/if}">
|
<div class="{if file_exists("$PAGES_PATH/Payment_Info.html")}col-md-6{else}col-md-6 col-md-offset-3{/if}">
|
||||||
<div class="panel panel-success panel-hovered">
|
<div class="panel panel-success panel-hovered">
|
||||||
@ -16,129 +16,129 @@
|
|||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<center><b>{Lang::T('Package Details')}</b></center>
|
<center><b>{Lang::T('Package Details')}</b></center>
|
||||||
{if !$custom}
|
{if !$custom}
|
||||||
<ul class="list-group list-group-unbordered">
|
<ul class="list-group list-group-unbordered">
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Package Name')}</b>
|
<b>{Lang::T('Package Name')}</b>
|
||||||
<span class="pull-right">{$plan['name_plan']}</span>
|
<span class="pull-right">{$plan['name_plan']}</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
{if $plan['is_radius'] or $plan['routers']}
|
{if $plan['is_radius'] or $plan['routers']}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Location')}</b>
|
<b>{Lang::T('Location')}</b>
|
||||||
<span class="pull-right">{if $plan['is_radius']}Radius{else}{$plan['routers']}{/if}</span>
|
<span class="pull-right">{if $plan['is_radius']}Radius{else}{$plan['routers']}{/if}</span>
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Type')}</b>
|
<b>{Lang::T('Type')}</b>
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
{if $plan['prepaid'] eq 'yes'}{Lang::T('Prepaid')}{else}{Lang::T('Postpaid')}{/if}
|
{if $plan['prepaid'] eq 'yes'}{Lang::T('Prepaid')}{else}{Lang::T('Postpaid')}{/if}
|
||||||
{$plan['type']}
|
{$plan['type']}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Package Price')}</b>
|
<b>{Lang::T('Package Price')}</b>
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
{if !empty($plan['price_old'])}
|
{if !empty($plan['price_old'])}
|
||||||
<sup style="text-decoration: line-through; color: red">
|
<sup style="text-decoration: line-through; color: red">
|
||||||
{Lang::moneyFormat($plan['price_old'])}
|
{Lang::moneyFormat($plan['price_old'])}
|
||||||
</sup>
|
</sup>
|
||||||
{/if}
|
{/if}
|
||||||
{Lang::moneyFormat($plan['price'])}
|
{Lang::moneyFormat($plan['price'])}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
{if $plan['validity']}
|
{if $plan['validity']}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Validity Period')}</b>
|
<b>{Lang::T('Validity Period')}</b>
|
||||||
<span class="pull-right">{$plan['validity']} {$plan['validity_unit']}</span>
|
<span class="pull-right">{$plan['validity']} {$plan['validity_unit']}</span>
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
</ul>
|
</ul>
|
||||||
{else}
|
{else}
|
||||||
<ul class="list-group list-group-unbordered">
|
<ul class="list-group list-group-unbordered">
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Package Name')}</b>
|
<b>{Lang::T('Package Name')}</b>
|
||||||
<span class="pull-right">{Lang::T('Custom Balance')}</span>
|
<span class="pull-right">{Lang::T('Custom Balance')}</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Amount')}</b>
|
<b>{Lang::T('Amount')}</b>
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
{Lang::moneyFormat($amount)}
|
{Lang::moneyFormat($amount)}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{/if}
|
{/if}
|
||||||
{if $discount == '' && $plan['type'] neq 'Balance' && $custom == ''}
|
{if $discount == '' && $plan['type'] neq 'Balance' && $custom == '' && $_c['enable_coupons'] == 'yes'}
|
||||||
<!-- Coupon Code Form -->
|
<!-- Coupon Code Form -->
|
||||||
<form action="{$_url}order/gateway/{$route2}/{$route3}" method="post">
|
<form action="{$_url}order/gateway/{$route2}/{$route3}" method="post">
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-md-4 control-label">{Lang::T('Coupon Code')}</label>
|
<label class="col-md-4 control-label">{Lang::T('Coupon Code')}</label>
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" class="form-control" name="coupon" id="coupon" maxlength="50"
|
<input type="text" class="form-control" name="coupon" id="coupon" maxlength="50"
|
||||||
required placeholder="{Lang::T('Enter your coupon code')}">
|
required placeholder="{Lang::T('Enter your coupon code')}">
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button type="submit" name="add_coupon"
|
<button type="submit" name="add_coupon"
|
||||||
class="btn btn-info btn-flat">{Lang::T('Apply Coupon')}</button>
|
class="btn btn-info btn-flat">{Lang::T('Apply Coupon')}</button>
|
||||||
</span>
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</form>
|
|
||||||
{/if}
|
{/if}
|
||||||
<br>
|
<br>
|
||||||
<center><b>{Lang::T('Summary')}</b></center>
|
<center><b>{Lang::T('Summary')}</b></center>
|
||||||
<ul class="list-group list-group-unbordered">
|
<ul class="list-group list-group-unbordered">
|
||||||
|
|
||||||
{if $add_cost != 0}
|
{if $add_cost != 0}
|
||||||
{foreach $bills as $k => $v}
|
{foreach $bills as $k => $v}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{$k}</b>
|
<b>{$k}</b>
|
||||||
<span class="pull-right">{Lang::moneyFormat($v)}</span>
|
<span class="pull-right">{Lang::moneyFormat($v)}</span>
|
||||||
</li>
|
</li>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Additional Cost')}</b>
|
<b>{Lang::T('Additional Cost')}</b>
|
||||||
<span class="pull-right">{Lang::moneyFormat($add_cost)}</span>
|
<span class="pull-right">{Lang::moneyFormat($add_cost)}</span>
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
{if $discount}
|
{if $discount}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Discount Applied')}</b>
|
<b>{Lang::T('Discount Applied')}</b>
|
||||||
<span class="pull-right">{Lang::moneyFormat($discount)}</span>
|
<span class="pull-right">{Lang::moneyFormat($discount)}</span>
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if $amount neq '' && $custom == '1'}
|
{if $amount neq '' && $custom == '1'}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Total')}</b>
|
<b>{Lang::T('Total')}</b>
|
||||||
<span class="pull-right" style="font-size: large; font-weight: bolder;">
|
<span class="pull-right" style="font-size: large; font-weight: bolder;">
|
||||||
{Lang::moneyFormat($amount)}
|
{Lang::moneyFormat($amount)}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
{elseif $plan['type'] eq 'Balance'}
|
{elseif $plan['type'] eq 'Balance'}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Total')}</b>
|
<b>{Lang::T('Total')}</b>
|
||||||
<span class="pull-right" style="font-size: large; font-weight: bolder;">
|
<span class="pull-right" style="font-size: large; font-weight: bolder;">
|
||||||
{Lang::moneyFormat($plan['price'] + $add_cost)}
|
{Lang::moneyFormat($plan['price'] + $add_cost)}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
{else}
|
{else}
|
||||||
{if $tax}
|
{if $tax}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Tax')}</b>
|
<b>{Lang::T('Tax')}</b>
|
||||||
<span class="pull-right">{Lang::moneyFormat($tax)}</span>
|
<span class="pull-right">{Lang::moneyFormat($tax)}</span>
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<b>{Lang::T('Total')}</b>
|
<b>{Lang::T('Total')}</b>
|
||||||
<span class="pull-right" style="font-size: large; font-weight: bolder;">
|
<span class="pull-right" style="font-size: large; font-weight: bolder;">
|
||||||
{Lang::moneyFormat($plan['price'] + $add_cost + $tax)}
|
{Lang::moneyFormat($plan['price'] + $add_cost + $tax)}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@ -146,8 +146,8 @@
|
|||||||
<form method="post" action="{$_url}order/buy/{$route2}/{$route3}">
|
<form method="post" action="{$_url}order/buy/{$route2}/{$route3}">
|
||||||
<input type="hidden" name="coupon" value="{$discount}">
|
<input type="hidden" name="coupon" value="{$discount}">
|
||||||
{if $custom == '1' && $amount neq ''}
|
{if $custom == '1' && $amount neq ''}
|
||||||
<input type="hidden" name="custom" value="1">
|
<input type="hidden" name="custom" value="1">
|
||||||
<input type="hidden" name="amount" value="{$amount}">
|
<input type="hidden" name="amount" value="{$amount}">
|
||||||
{/if}
|
{/if}
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-md-4">{Lang::T('Payment Gateway')}</label>
|
<label class="col-md-4">{Lang::T('Payment Gateway')}</label>
|
||||||
@ -159,7 +159,7 @@
|
|||||||
</option>
|
</option>
|
||||||
{/if}
|
{/if}
|
||||||
{foreach $pgs as $pg}
|
{foreach $pgs as $pg}
|
||||||
<option value="{$pg}">{ucwords($pg)}</option>
|
<option value="{$pg}">{ucwords($pg)}</option>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1272,7 +1272,7 @@
|
|||||||
<li {if $_routes[1] eq 'voucher' }class="active" {/if}><a
|
<li {if $_routes[1] eq 'voucher' }class="active" {/if}><a
|
||||||
href="{$_url}plan/voucher">{Lang::T('Vouchers')}</a></li>
|
href="{$_url}plan/voucher">{Lang::T('Vouchers')}</a></li>
|
||||||
{/if}
|
{/if}
|
||||||
{if $_c['disable_coupons'] != 'yes'}
|
{if $_c['enable_coupons'] == 'yes'}
|
||||||
<li {if $_routes[0] eq 'coupons' }class="active" {/if}><a
|
<li {if $_routes[0] eq 'coupons' }class="active" {/if}><a
|
||||||
href="{$_url}coupons">{Lang::T('Coupons')}</a></li>
|
href="{$_url}coupons">{Lang::T('Coupons')}</a></li>
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user