diff --git a/CHANGELOG.md b/CHANGELOG.md index 273041d8..d3299af2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ # CHANGELOG +## 2023.8.18 + +- Fix Auto Renewall Cronjob + ## 2023.8.16 - Admin Can Add Balance to Customer diff --git a/system/autoload/Balance.php b/system/autoload/Balance.php index 2b3713d2..a3686e7d 100644 --- a/system/autoload/Balance.php +++ b/system/autoload/Balance.php @@ -19,17 +19,17 @@ class Balance { global $config; if ($config['allow_balance_transfer'] == 'yes') { - if(Balance::min($id_customer, $amount)){ - if(Balance::plusByPhone($phoneTarget, $amount)){ + if (Balance::min($id_customer, $amount)) { + if (Balance::plusByPhone($phoneTarget, $amount)) { return true; - }else{ + } else { Balance::plus($id_customer, $amount); return false; } - }else{ + } else { return false; } - }else{ + } else { return false; } } @@ -38,7 +38,7 @@ class Balance { $c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one(); if ($c && $c['balance'] >= $amount) { - $c->balance = $amount - $c['balance']; + $c->balance = $c['balance'] - $amount; $c->save(); return true; } else { @@ -49,7 +49,7 @@ class Balance public static function plusByPhone($phone_customer, $amount) { $c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one(); - if($c){ + if ($c) { $c->balance = $amount + $c['balance']; $c->save(); return true; @@ -61,7 +61,7 @@ class Balance { $c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one(); if ($c && $c['balance'] >= $amount) { - $c->balance = $amount - $c['balance']; + $c->balance = $c['balance'] - $amount; $c->save(); return true; } else { diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 0a803dfc..a62107ec 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -33,7 +33,7 @@ class Package if ($router_name == 'balance') { // insert table transactions - $inv = "INV-" . _raid(5); + $inv = "INV-" . Package::_raid(5); $t = ORM::for_table('tbl_transactions')->create(); $t->invoice = $inv; $t->username = $c['username']; @@ -114,7 +114,7 @@ class Package // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . _raid(5); + $t->invoice = "INV-" . Package::_raid(5); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; @@ -147,7 +147,7 @@ class Package // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . _raid(5); + $t->invoice = "INV-" . Package::_raid(5); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; @@ -188,7 +188,7 @@ class Package // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . _raid(5); + $t->invoice = "INV-" . Package::_raid(5); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; @@ -221,7 +221,7 @@ class Package // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . _raid(5); + $t->invoice = "INV-" . Package::_raid(5); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; @@ -301,4 +301,10 @@ class Package } } } + + + public static function _raid($l) + { + return substr(str_shuffle(str_repeat('0123456789', $l)), 0, $l); + } } diff --git a/system/boot.php b/system/boot.php index 9e458289..b88699b3 100644 --- a/system/boot.php +++ b/system/boot.php @@ -191,10 +191,6 @@ function _admin($login = true) } } -function _raid($l) -{ - return substr(str_shuffle(str_repeat('0123456789', $l)), 0, $l); -} function _log($description, $type = '', $userid = '0') { diff --git a/system/controllers/export.php b/system/controllers/export.php index 0d2ba727..b7a3a82b 100644 --- a/system/controllers/export.php +++ b/system/controllers/export.php @@ -168,7 +168,7 @@ $style $html EOF; $mpdf->WriteHTML($nhtml); - $mpdf->Output(date('Y-m-d') . _raid(4) . '.pdf', 'D'); + $mpdf->Output(date('Y-m-d') . Package::_raid(4) . '.pdf', 'D'); } else { echo 'No Data'; } @@ -340,7 +340,7 @@ $style $html EOF; $mpdf->WriteHTML($nhtml); - $mpdf->Output(date('Y-m-d') . _raid(4) . '.pdf', 'D'); + $mpdf->Output(date('Y-m-d') . Package::_raid(4) . '.pdf', 'D'); } else { echo 'No Data'; } diff --git a/system/controllers/voucher.php b/system/controllers/voucher.php index 22ee64dc..eb322db4 100644 --- a/system/controllers/voucher.php +++ b/system/controllers/voucher.php @@ -73,7 +73,7 @@ switch ($action) { // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . _raid(5); + $t->invoice = "INV-" . Package::_raid(5); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; @@ -106,7 +106,7 @@ switch ($action) { // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . _raid(5); + $t->invoice = "INV-" . Package::_raid(5); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; @@ -150,7 +150,7 @@ switch ($action) { // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . _raid(5); + $t->invoice = "INV-" . Package::_raid(5); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; @@ -183,7 +183,7 @@ switch ($action) { // insert table transactions $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-" . _raid(5); + $t->invoice = "INV-" . Package::_raid(5); $t->username = $c['username']; $t->plan_name = $p['name_plan']; $t->price = $p['price']; diff --git a/system/cron.php b/system/cron.php index e7774867..750e85b4 100644 --- a/system/cron.php +++ b/system/cron.php @@ -59,6 +59,9 @@ $result = ORM::for_table('tbl_appconfig')->find_many(); foreach ($result as $value) { $config[$value['setting']] = $value['value']; } + +$_c = $config; + date_default_timezone_set($config['timezone']); $textExpired = $_notifmsg['expired']; @@ -95,12 +98,20 @@ foreach ($d as $ds) { 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']); + echo "plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n"; + echo "auto renewall Success\n"; } else { + echo "plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n"; + echo "auto renewall Failed\n"; Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] . "\nRouter: " . $router_name . "\nPrice: " . $p['price']); } + }else{ + echo "no renewall | plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n"; } + }else{ + echo "no renewall | balance $config[enable_balance] auto_renewal $c[auto_renewal]\n"; } } else echo " : ACTIVE \r\n"; } else { diff --git a/version.json b/version.json index 167ffc44..53314040 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "2023.8.16" + "version": "2023.8.18" } \ No newline at end of file