From 2c67108cf1f9366f2b4b6c7f7028f6b62ef35680 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Thu, 14 Mar 2024 10:28:36 +0700 Subject: [PATCH] add Additional Cycle and check if price is zero --- system/autoload/Package.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/system/autoload/Package.php b/system/autoload/Package.php index ee075a20..8d5e1782 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -33,9 +33,14 @@ class Package $p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one(); // Additional cost - $add_cost = User::getAttribute("Additional Cost", $id_customer); - if(empty($add_cost)){ - $add_cost = 0; + $add_cost = 0; + $add_cycle = User::getAttribute("Additional Cycle", $id_customer); + // if empty then it doesnt have cycle, if zero then it finish + if ($add_cycle != 0) { + $add_cost = User::getAttribute("Additional Cost", $id_customer); + if (empty($add_cost)) { + $add_cost = 0; + } } // Zero cost recharge @@ -307,7 +312,7 @@ class Package $t->invoice = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; - if ($p['validity_unit'] == 'Period') { + if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { // Calculating Price $sd = new DateTime("$date_only"); $ed = new DateTime("$date_exp"); @@ -336,7 +341,7 @@ class Package } $t->save(); - if ($p['validity_unit'] == 'Period') { + if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { // insert to fields $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); if (!$fl) { @@ -435,7 +440,7 @@ class Package } $t->save(); - if ($p['validity_unit'] == 'Period') { + if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { // insert to fields $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); if (!$fl) { @@ -491,7 +496,7 @@ class Package $t->invoice = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; - if ($p['validity_unit'] == 'Period') { + if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { // Calculating Price $sd = new DateTime("$date_only"); $ed = new DateTime("$date_exp"); @@ -520,7 +525,7 @@ class Package $t->type = "PPPOE"; $t->save(); - if ($p['validity_unit'] == 'Period') { + if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { // insert to fields $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); if (!$fl) { @@ -547,6 +552,9 @@ class Package "\nPrice: " . Lang::moneyFormat($p['price'])); } } + if ($add_cycle > 0) { + User::setAttribute('Additional Cycle', ($add_cycle - 1), $id_customer); + } run_hook("recharge_user_finish"); Message::sendInvoice($c, $t); return true;