From 630f20094a962c2db3c5c0e896de9194f6b852a0 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Thu, 8 Aug 2024 14:58:04 +0700 Subject: [PATCH] don't put to tbl_transactions if customer redeem voucher code Created by Voucher Device --- system/autoload/Package.php | 115 +++++++++++++++++++----------------- system/autoload/User.php | 5 ++ 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 7674ca8c..18d28b6c 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -299,36 +299,40 @@ class Package $b->save(); } - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = $inv = "INV-" . Package::_raid(); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - if ($p['validity_unit'] == 'Period') { - // Postpaid price from field - $add_inv = User::getAttribute("Invoice", $id_customer); - if (empty($add_inv) or $add_inv == 0) { - $t->price = $p['price'] + $add_cost; + if($gateway == 'Voucher' && User::isUserVoucher($channel)){ + // maybe someday i will do something in here + }else{ + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = $inv = "INV-" . Package::_raid(); + $t->username = $c['username']; + $t->plan_name = $p['name_plan']; + if ($p['validity_unit'] == 'Period') { + // Postpaid price from field + $add_inv = User::getAttribute("Invoice", $id_customer); + if (empty($add_inv) or $add_inv == 0) { + $t->price = $p['price'] + $add_cost; + } else { + $t->price = $add_inv + $add_cost; + } } else { - $t->price = $add_inv + $add_cost; + $t->price = $p['price'] + $add_cost; } - } else { - $t->price = $p['price'] + $add_cost; + $t->recharged_on = $date_only; + $t->recharged_time = $time_only; + $t->expiration = $date_exp; + $t->time = $time; + $t->method = "$gateway - $channel"; + $t->routers = $router_name; + $t->note = $note; + $t->type = $p['type']; + if ($admin) { + $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; + } else { + $t->admin_id = '0'; + } + $t->save(); } - $t->recharged_on = $date_only; - $t->recharged_time = $time_only; - $t->expiration = $date_exp; - $t->time = $time; - $t->method = "$gateway - $channel"; - $t->routers = $router_name; - $t->note = $note; - $t->type = $p['type']; - if ($admin) { - $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; - } else { - $t->admin_id = '0'; - } - $t->save(); if ($p['validity_unit'] == 'Period') { // insert price to fields for invoice next month @@ -407,33 +411,38 @@ class Package } $d->save(); } - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = $inv = "INV-" . Package::_raid(); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - if ($p['validity_unit'] == 'Period') { - // Postpaid price always zero for first time - $note = ''; - $bills = []; - $t->price = 0; - } else { - $t->price = $p['price'] + $add_cost; + + if($gateway == 'Voucher' && User::isUserVoucher($channel)){ + // maybe someday i will do something in here + }else{ + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = $inv = "INV-" . Package::_raid(); + $t->username = $c['username']; + $t->plan_name = $p['name_plan']; + if ($p['validity_unit'] == 'Period') { + // Postpaid price always zero for first time + $note = ''; + $bills = []; + $t->price = 0; + } else { + $t->price = $p['price'] + $add_cost; + } + $t->recharged_on = $date_only; + $t->recharged_time = $time_only; + $t->expiration = $date_exp; + $t->time = $time; + $t->method = "$gateway - $channel"; + $t->note = $note; + $t->routers = $router_name; + if ($admin) { + $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; + } else { + $t->admin_id = '0'; + } + $t->type = $p['type']; + $t->save(); } - $t->recharged_on = $date_only; - $t->recharged_time = $time_only; - $t->expiration = $date_exp; - $t->time = $time; - $t->method = "$gateway - $channel"; - $t->note = $note; - $t->routers = $router_name; - if ($admin) { - $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; - } else { - $t->admin_id = '0'; - } - $t->type = $p['type']; - $t->save(); if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { // insert price to fields for invoice next month diff --git a/system/autoload/User.php b/system/autoload/User.php index 6e6ae651..e9358620 100644 --- a/system/autoload/User.php +++ b/system/autoload/User.php @@ -196,6 +196,11 @@ class User return $d; } + public static function isUserVoucher($kode) { + $regex = '/^GC\d+C.{10}$/'; + return preg_match($regex, $kode); + } + public static function _billing($id = 0) { if (!$id) {