From 690e5912c07b1298676cd6fd891f085ee669d872 Mon Sep 17 00:00:00 2001 From: iBNu Maksum Date: Tue, 7 Jan 2025 16:26:33 +0700 Subject: [PATCH] change disable_coupons != yes to enable_coupons == yes --- system/controllers/order.php | 154 ++++++++++----------- ui/ui/customer/selectGateway.tpl | 222 +++++++++++++++---------------- ui/ui/sections/header.tpl | 2 +- 3 files changed, 190 insertions(+), 188 deletions(-) diff --git a/system/controllers/order.php b/system/controllers/order.php index 2b5a83ba..68e95a10 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -411,89 +411,91 @@ switch ($action) { list($bills, $add_cost) = User::getBills($id_customer); } - if (!isset($_SESSION['coupon_attempts'])) { - $_SESSION['coupon_attempts'] = 0; - $_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) { + if($config['enable_coupons']){ + if (!isset($_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 ($_SESSION['coupon_attempts'] >= 5) { + $timeout = 10 * 60; // 10 minutes in seconds + $time_diff = time() - $_SESSION['last_attempt_time']; - if (!$coupon) { - $_SESSION['coupon_attempts']++; + if ($time_diff >= $timeout) { + $_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(); - 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); diff --git a/ui/ui/customer/selectGateway.tpl b/ui/ui/customer/selectGateway.tpl index e98b3d66..2323ffff 100644 --- a/ui/ui/customer/selectGateway.tpl +++ b/ui/ui/customer/selectGateway.tpl @@ -2,12 +2,12 @@
{if file_exists("$PAGES_PATH/Payment_Info.html")} -
-
-
{Lang::T('Payment Info')}
-
{include file="$PAGES_PATH/Payment_Info.html"}
+
+
+
{Lang::T('Payment Info')}
+
{include file="$PAGES_PATH/Payment_Info.html"}
+
-
{/if}
@@ -16,129 +16,129 @@
{Lang::T('Package Details')}
{if !$custom} -
    -
  • - {Lang::T('Package Name')} - {$plan['name_plan']} -
  • +
      +
    • + {Lang::T('Package Name')} + {$plan['name_plan']} +
    • - {if $plan['is_radius'] or $plan['routers']} -
    • - {Lang::T('Location')} - {if $plan['is_radius']}Radius{else}{$plan['routers']}{/if} -
    • - {/if} + {if $plan['is_radius'] or $plan['routers']} +
    • + {Lang::T('Location')} + {if $plan['is_radius']}Radius{else}{$plan['routers']}{/if} +
    • + {/if} -
    • - {Lang::T('Type')} - - {if $plan['prepaid'] eq 'yes'}{Lang::T('Prepaid')}{else}{Lang::T('Postpaid')}{/if} - {$plan['type']} - -
    • +
    • + {Lang::T('Type')} + + {if $plan['prepaid'] eq 'yes'}{Lang::T('Prepaid')}{else}{Lang::T('Postpaid')}{/if} + {$plan['type']} + +
    • -
    • - {Lang::T('Package Price')} - - {if !empty($plan['price_old'])} - - {Lang::moneyFormat($plan['price_old'])} - - {/if} - {Lang::moneyFormat($plan['price'])} - -
    • +
    • + {Lang::T('Package Price')} + + {if !empty($plan['price_old'])} + + {Lang::moneyFormat($plan['price_old'])} + + {/if} + {Lang::moneyFormat($plan['price'])} + +
    • - {if $plan['validity']} -
    • - {Lang::T('Validity Period')} - {$plan['validity']} {$plan['validity_unit']} -
    • - {/if} -
    + {if $plan['validity']} +
  • + {Lang::T('Validity Period')} + {$plan['validity']} {$plan['validity_unit']} +
  • + {/if} +
{else} -
    -
  • - {Lang::T('Package Name')} - {Lang::T('Custom Balance')} -
  • +
      +
    • + {Lang::T('Package Name')} + {Lang::T('Custom Balance')} +
    • -
    • - {Lang::T('Amount')} - - {Lang::moneyFormat($amount)} - -
    • -
    +
  • + {Lang::T('Amount')} + + {Lang::moneyFormat($amount)} + +
  • +
{/if} - {if $discount == '' && $plan['type'] neq 'Balance' && $custom == ''} - -
-
- -
-
- - - - + {if $discount == '' && $plan['type'] neq 'Balance' && $custom == '' && $_c['enable_coupons'] == 'yes'} + + +
+ +
+
+ + + + +
-
- + {/if}
{Lang::T('Summary')}
    - + {if $add_cost != 0} - {foreach $bills as $k => $v} -
  • - {$k} - {Lang::moneyFormat($v)} -
  • - {/foreach} -
  • - {Lang::T('Additional Cost')} - {Lang::moneyFormat($add_cost)} -
  • + {foreach $bills as $k => $v} +
  • + {$k} + {Lang::moneyFormat($v)} +
  • + {/foreach} +
  • + {Lang::T('Additional Cost')} + {Lang::moneyFormat($add_cost)} +
  • {/if} {if $discount} -
  • - {Lang::T('Discount Applied')} - {Lang::moneyFormat($discount)} -
  • +
  • + {Lang::T('Discount Applied')} + {Lang::moneyFormat($discount)} +
  • {/if} {if $amount neq '' && $custom == '1'} -
  • - {Lang::T('Total')} - - {Lang::moneyFormat($amount)} - -
  • +
  • + {Lang::T('Total')} + + {Lang::moneyFormat($amount)} + +
  • {elseif $plan['type'] eq 'Balance'} -
  • - {Lang::T('Total')} - - {Lang::moneyFormat($plan['price'] + $add_cost)} - -
  • +
  • + {Lang::T('Total')} + + {Lang::moneyFormat($plan['price'] + $add_cost)} + +
  • {else} - {if $tax} -
  • - {Lang::T('Tax')} - {Lang::moneyFormat($tax)} -
  • - {/if} -
  • - {Lang::T('Total')} - - {Lang::moneyFormat($plan['price'] + $add_cost + $tax)} - -
  • + {if $tax} +
  • + {Lang::T('Tax')} + {Lang::moneyFormat($tax)} +
  • + {/if} +
  • + {Lang::T('Total')} + + {Lang::moneyFormat($plan['price'] + $add_cost + $tax)} + +
  • {/if}
@@ -146,8 +146,8 @@
{if $custom == '1' && $amount neq ''} - - + + {/if}
@@ -159,7 +159,7 @@ {/if} {foreach $pgs as $pg} - + {/foreach}
@@ -176,4 +176,4 @@
-{include file="customer/footer.tpl"} +{include file="customer/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/sections/header.tpl b/ui/ui/sections/header.tpl index c6c9fa1b..20d81202 100644 --- a/ui/ui/sections/header.tpl +++ b/ui/ui/sections/header.tpl @@ -1272,7 +1272,7 @@
  • {Lang::T('Vouchers')}
  • {/if} - {if $_c['disable_coupons'] != 'yes'} + {if $_c['enable_coupons'] == 'yes'}
  • {Lang::T('Coupons')}
  • {/if}