diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index a7e6d6ef..602f8364 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -56,6 +56,7 @@ CREATE TABLE `phonenumber` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0', `email` varchar(128) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '1', `balance` decimal(15,2) NOT NULL COMMENT 'For Money Deposit', + `auto_renewal` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Auto renewal from balance', `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `last_login` datetime DEFAULT NULL ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; diff --git a/system/cron.php b/system/cron.php index 5f8118e2..e7774867 100644 --- a/system/cron.php +++ b/system/cron.php @@ -19,9 +19,9 @@ ORM::configure('logging', true); include "autoload/Hookers.php"; // notification message -if(file_exists("uploads/notifications.json")){ - $_notifmsg =json_decode(file_get_contents('uploads/notifications.json'), true); -}else{ +if (file_exists("uploads/notifications.json")) { + $_notifmsg = json_decode(file_get_contents('uploads/notifications.json'), true); +} else { $_notifmsg = json_decode(file_get_contents('uploads/notifications.default.json'), true); } @@ -87,6 +87,21 @@ foreach ($d as $ds) { //update database user dengan status off $u->status = 'off'; $u->save(); + + // autorenewal from deposit + if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) { + $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); + if ($p && $p['enabled'] && $c['balance'] >= $p['price']) { + if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) { + // if success, then get the balance + Balance::min($ds['customer_id'], $p['price']); + } else { + Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] . + "\nRouter: " . $router_name . + "\nPrice: " . $p['price']); + } + } + } } else echo " : ACTIVE \r\n"; } else { $date_now = strtotime(date("Y-m-d H:i:s")); @@ -107,6 +122,21 @@ foreach ($d as $ds) { $u->status = 'off'; $u->save(); + + // autorenewal from deposit + if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) { + $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); + if ($p && $p['enabled'] && $c['balance'] >= $p['price']) { + if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) { + // if success, then get the balance + Balance::min($ds['customer_id'], $p['price']); + } else { + Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] . + "\nRouter: " . $router_name . + "\nPrice: " . $p['price']); + } + } + } } else echo " : ACTIVE \r\n"; } } diff --git a/system/updates.json b/system/updates.json index 5413b575..7dce27f7 100644 --- a/system/updates.json +++ b/system/updates.json @@ -8,6 +8,7 @@ "2023.8.14": [ "ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '1' COMMENT 'For PPPOE Login' AFTER `password`;", "ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;", - "ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;" + "ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;", + "ALTER TABLE `tbl_customers` ADD `auto_renewal` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Auto renewall using balance' AFTER `balance`;" ] } \ No newline at end of file diff --git a/system/uploads/notifications.default.json b/system/uploads/notifications.default.json index 9731b244..aff56897 100644 --- a/system/uploads/notifications.default.json +++ b/system/uploads/notifications.default.json @@ -1,5 +1,5 @@ { - "user_notification_expired_text": "Hello [[name]], your internet package [[package]] has been expired.", + "expired": "Hello [[name]], your internet package [[package]] has been expired.", "reminder_7_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 7 days.", "reminder_3_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 3 days.", "reminder_1_day": "Hello *[[name]]*,\r\n your internet package *[[package]]* will be expired tomorrow.", diff --git a/ui/ui/app-notifications.tpl b/ui/ui/app-notifications.tpl index baed6f1b..ab5a40e1 100644 --- a/ui/ui/app-notifications.tpl +++ b/ui/ui/app-notifications.tpl @@ -15,8 +15,8 @@
-