add Additional Cycle and check if price is zero

This commit is contained in:
Ibnu Maksum 2024-03-14 10:28:36 +07:00
parent dee4c78e93
commit 2c67108cf1
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -33,9 +33,14 @@ class Package
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one(); $p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one();
// Additional cost // Additional cost
$add_cost = User::getAttribute("Additional Cost", $id_customer); $add_cost = 0;
if(empty($add_cost)){ $add_cycle = User::getAttribute("Additional Cycle", $id_customer);
$add_cost = 0; // 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 // Zero cost recharge
@ -307,7 +312,7 @@ class Package
$t->invoice = "INV-" . Package::_raid(); $t->invoice = "INV-" . Package::_raid();
$t->username = $c['username']; $t->username = $c['username'];
$t->plan_name = $p['name_plan']; $t->plan_name = $p['name_plan'];
if ($p['validity_unit'] == 'Period') { if ($p['validity_unit'] == 'Period' && $p['price'] != 0) {
// Calculating Price // Calculating Price
$sd = new DateTime("$date_only"); $sd = new DateTime("$date_only");
$ed = new DateTime("$date_exp"); $ed = new DateTime("$date_exp");
@ -336,7 +341,7 @@ class Package
} }
$t->save(); $t->save();
if ($p['validity_unit'] == 'Period') { if ($p['validity_unit'] == 'Period' && $p['price'] != 0) {
// insert to fields // insert to fields
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one();
if (!$fl) { if (!$fl) {
@ -435,7 +440,7 @@ class Package
} }
$t->save(); $t->save();
if ($p['validity_unit'] == 'Period') { if ($p['validity_unit'] == 'Period' && $p['price'] != 0) {
// insert to fields // insert to fields
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one();
if (!$fl) { if (!$fl) {
@ -491,7 +496,7 @@ class Package
$t->invoice = "INV-" . Package::_raid(); $t->invoice = "INV-" . Package::_raid();
$t->username = $c['username']; $t->username = $c['username'];
$t->plan_name = $p['name_plan']; $t->plan_name = $p['name_plan'];
if ($p['validity_unit'] == 'Period') { if ($p['validity_unit'] == 'Period' && $p['price'] != 0) {
// Calculating Price // Calculating Price
$sd = new DateTime("$date_only"); $sd = new DateTime("$date_only");
$ed = new DateTime("$date_exp"); $ed = new DateTime("$date_exp");
@ -520,7 +525,7 @@ class Package
$t->type = "PPPOE"; $t->type = "PPPOE";
$t->save(); $t->save();
if ($p['validity_unit'] == 'Period') { if ($p['validity_unit'] == 'Period' && $p['price'] != 0) {
// insert to fields // insert to fields
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one();
if (!$fl) { if (!$fl) {
@ -547,6 +552,9 @@ class Package
"\nPrice: " . Lang::moneyFormat($p['price'])); "\nPrice: " . Lang::moneyFormat($p['price']));
} }
} }
if ($add_cycle > 0) {
User::setAttribute('Additional Cycle', ($add_cycle - 1), $id_customer);
}
run_hook("recharge_user_finish"); run_hook("recharge_user_finish");
Message::sendInvoice($c, $t); Message::sendInvoice($c, $t);
return true; return true;