Fix Recharge time

This commit is contained in:
Ibnu Maksum
2023-08-28 09:44:57 +07:00
parent 51ac162642
commit b4f5cf8954
17 changed files with 124 additions and 282 deletions

View File

@ -22,6 +22,7 @@ class Package
global $_c, $_L, $_notifmsg;
$date_now = date("Y-m-d H:i:s");
$date_only = date("Y-m-d");
$time_only = date("H:i:s");
$time = date("H:i:s");
if ($id_customer == '' or $router_name == '' or $plan_id == '') {
@ -40,6 +41,7 @@ class Package
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->recharge_time = date("H:i:s");
$t->expiration = $date_only;
$t->time = $time;
$t->method = "$gateway - $channel";
@ -105,6 +107,7 @@ class Package
$b->plan_id = $plan_id;
$b->namebp = $p['name_plan'];
$b->recharged_on = $date_only;
$b->recharge_time = $time_only;
$b->expiration = $date_exp;
$b->time = $time;
$b->status = "on";
@ -120,6 +123,7 @@ class Package
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->recharge_time = $time_only;
$t->expiration = $date_exp;
$t->time = $time;
$t->method = "$gateway - $channel";
@ -139,6 +143,7 @@ class Package
$d->plan_id = $plan_id;
$d->namebp = $p['name_plan'];
$d->recharged_on = $date_only;
$d->recharge_time = $time_only;
$d->expiration = $date_exp;
$d->time = $time;
$d->status = "on";
@ -154,6 +159,7 @@ class Package
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->recharge_time = $time_only;
$t->expiration = $date_exp;
$t->time = $time;
$t->method = "$gateway - $channel";
@ -181,6 +187,7 @@ class Package
$b->plan_id = $plan_id;
$b->namebp = $p['name_plan'];
$b->recharged_on = $date_only;
$b->recharge_time = $time_only;
$b->expiration = $date_exp;
$b->time = $time;
$b->status = "on";
@ -196,6 +203,7 @@ class Package
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->recharge_time = $time_only;
$t->expiration = $date_exp;
$t->time = $time;
$t->method = "$gateway - $channel";
@ -215,6 +223,7 @@ class Package
$d->plan_id = $plan_id;
$d->namebp = $p['name_plan'];
$d->recharged_on = $date_only;
$d->recharge_time = $time_only;
$d->expiration = $date_exp;
$d->time = $time;
$d->status = "on";
@ -230,6 +239,7 @@ class Package
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->recharge_time = $time_only;
$t->expiration = $date_exp;
$t->time = $time;
$t->method = "$gateway - $channel";

View File

@ -181,7 +181,7 @@ switch ($action) {
run_hook('edit_customer_plan'); #HOOK
$d->username = $username;
$d->plan_id = $id_plan;
$d->recharged_on = $recharged_on;
//$d->recharged_on = $recharged_on;
$d->expiration = $expiration;
$d->time = $time;
$d->save();

View File

@ -26,187 +26,16 @@ switch ($action) {
case 'activation-post':
$code = _post('code');
$v1 = ORM::for_table('tbl_voucher')->where('code', $code)->where('status', 0)->find_one();
$c = ORM::for_table('tbl_customers')->find_one($user['id']);
$p = ORM::for_table('tbl_plans')->find_one($v1['id_plan']);
$b = ORM::for_table('tbl_user_recharges')->where('customer_id', $user['id'])->find_one();
$date_now = date("Y-m-d H:i:s");
$date_only = date("Y-m-d");
$time = date("H:i:s");
$mikrotik = Mikrotik::info($v1['routers']);
if ($p['validity_unit'] == 'Months') {
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month'));
} else if ($p['validity_unit'] == 'Days') {
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' day'));
} else if ($p['validity_unit'] == 'Hrs') {
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' hour')));
$date_exp = $datetime[0];
$time = $datetime[1];
} else if ($p['validity_unit'] == 'Mins') {
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' minute')));
$date_exp = $datetime[0];
$time = $datetime[1];
}
run_hook('customer_activate_voucher'); #HOOK
if ($v1) {
if ($v1['type'] == 'Hotspot') {
if ($b) {
if (!$config['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::addHotspotUser($client, $p, $c);
}
$b->customer_id = $user['id'];
$b->username = $c['username'];
$b->plan_id = $v1['id_plan'];
$b->namebp = $p['name_plan'];
$b->recharged_on = $date_only;
$b->expiration = $date_exp;
$b->time = $time;
$b->status = "on";
$b->method = "voucher";
$b->routers = $v1['routers'];
$b->type = "Hotspot";
$b->save();
// insert table transactions
$t = ORM::for_table('tbl_transactions')->create();
$t->invoice = "INV-" . Package::_raid(5);
$t->username = $c['username'];
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->expiration = $date_exp;
$t->time = $time;
$t->method = "voucher";
$t->routers = $v1['routers'];
$t->type = "Hotspot";
$t->save();
} else {
if (!$config['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addHotspotUser($client, $p, $c);
}
$d = ORM::for_table('tbl_user_recharges')->create();
$d->customer_id = $user['id'];
$d->username = $c['username'];
$d->plan_id = $v1['id_plan'];
$d->namebp = $p['name_plan'];
$d->recharged_on = $date_only;
$d->expiration = $date_exp;
$d->time = $time;
$d->status = "on";
$d->method = "voucher";
$d->routers = $v1['routers'];
$d->type = "Hotspot";
$d->save();
// insert table transactions
$t = ORM::for_table('tbl_transactions')->create();
$t->invoice = "INV-" . Package::_raid(5);
$t->username = $c['username'];
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->expiration = $date_exp;
$t->time = $time;
$t->method = "voucher";
$t->routers = $v1['routers'];
$t->type = "Hotspot";
$t->save();
}
if (Package::rechargeUser($user, $v1['routers'], $v1['id_plan'], "Activation", "Voucher")) {
$v1->status = "1";
$v1->user = $c['username'];
$v1->save();
// Telegram to Admin
Message::sendTelegram('#u' . $c['username'] . " Activate #Voucher #Hotspot\n" . $p['name_plan'] .
"\nCode: " . $code .
"\nRouter: " . $v1['routers'] .
"\nPrice: " . $p['price']);
r2(U . "voucher/list-activated", 's', $_L['Activation_Vouchers_Successfully']);
} else {
if ($b) {
if (!$config['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removePpoeUser($client, $c['username']);
Mikrotik::addPpoeUser($client, $p, $c);
}
$b->customer_id = $user['id'];
$b->username = $c['username'];
$b->plan_id = $v1['id_plan'];
$b->namebp = $p['name_plan'];
$b->recharged_on = $date_only;
$b->expiration = $date_exp;
$b->time = $time;
$b->status = "on";
$b->method = "voucher";
$b->routers = $v1['routers'];
$b->type = "PPPOE";
$b->save();
// insert table transactions
$t = ORM::for_table('tbl_transactions')->create();
$t->invoice = "INV-" . Package::_raid(5);
$t->username = $c['username'];
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->expiration = $date_exp;
$t->time = $time;
$t->method = "voucher";
$t->routers = $v1['routers'];
$t->type = "PPPOE";
$t->save();
} else {
if (!$config['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addPpoeUser($client, $p, $c);
}
$d = ORM::for_table('tbl_user_recharges')->create();
$d->customer_id = $user['id'];
$d->username = $c['username'];
$d->plan_id = $v1['id_plan'];
$d->namebp = $p['name_plan'];
$d->recharged_on = $date_only;
$d->expiration = $date_exp;
$d->time = $time;
$d->status = "on";
$d->method = "voucher";
$d->routers = $v1['routers'];
$d->type = "PPPOE";
$d->save();
// insert table transactions
$t = ORM::for_table('tbl_transactions')->create();
$t->invoice = "INV-" . Package::_raid(5);
$t->username = $c['username'];
$t->plan_name = $p['name_plan'];
$t->price = $p['price'];
$t->recharged_on = $date_only;
$t->expiration = $date_exp;
$t->time = $time;
$t->method = "voucher";
$t->routers = $v1['routers'];
$t->type = "PPPOE";
$t->save();
}
$v1->status = "1";
$v1->user = $c['username'];
$v1->save();
// Telegram to Admin
Message::sendTelegram('#u' . $c['username'] . " Activate #Voucher #PPPOE\n" . $p['name_plan'] .
"\nCode: " . $code .
"\nRouter: " . $v1['routers'] .
"\nPrice: " . $p['price']);
r2(U . 'voucher/activation', 'e', "Failed to refill account");
}
r2(U . "voucher/list-activated", 's', $_L['Activation_Vouchers_Successfully']);
} else {
r2(U . 'voucher/activation', 'e', $_L['Voucher_Not_Valid']);
}

View File

@ -15,6 +15,7 @@
"ALTER TABLE `tbl_customers` CHANGE `pppoe_password` `pppoe_password` VARCHAR(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT 'For PPPOE Login';"
],
"2023.8.28" : [
"ALTER TABLE `tbl_user_recharges` CHANGE `recharged_on` `recharged_on` DATETIME NOT NULL;"
"ALTER TABLE `tbl_user_recharges` ADD `recharged_time` time NOT NULL DEFAULT '00:00:00' AFTER `recharged_on`;",
"ALTER TABLE `tbl_transactions` ADD `recharged_time` time NOT NULL DEFAULT '00:00:00' AFTER `recharged_on`;"
]
}