continue activate package, when it cannot connect to Device, let admin sync it manual

This commit is contained in:
Ibnu Maksum 2024-08-01 09:25:13 +07:00
parent 67e383375e
commit 721ef32e12
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
2 changed files with 62 additions and 19 deletions

View File

@ -20,7 +20,7 @@ class Package
*/ */
public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel, $note = '') public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel, $note = '')
{ {
global $config, $admin, $c, $p, $b, $t, $d, $zero, $trx, $_app_stage; global $config, $admin, $c, $p, $b, $t, $d, $zero, $trx, $_app_stage, $isChangePlan;
$date_now = date("Y-m-d H:i:s"); $date_now = date("Y-m-d H:i:s");
$date_only = date("Y-m-d"); $date_only = date("Y-m-d");
$time_only = date("H:i:s"); $time_only = date("H:i:s");
@ -29,7 +29,7 @@ class Package
$isVoucher = false; $isVoucher = false;
$c = []; $c = [];
if($trx && $trx['status'] == 2){ if ($trx && $trx['status'] == 2) {
// if its already paid, return it // if its already paid, return it
return; return;
} }
@ -37,18 +37,18 @@ class Package
if ($id_customer == '' or $router_name == '' or $plan_id == '') { if ($id_customer == '' or $router_name == '' or $plan_id == '') {
return false; return false;
} }
if(trim($gateway) == 'Voucher' && $id_customer == 0){ if (trim($gateway) == 'Voucher' && $id_customer == 0) {
$isVoucher = true; $isVoucher = true;
} }
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one(); $p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one();
if(!$isVoucher){ if (!$isVoucher) {
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one(); $c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
if ($c['status'] != 'Active') { if ($c['status'] != 'Active') {
_alert(Lang::T('This account status') . ' : ' . Lang::T($c['status']), 'danger', ""); _alert(Lang::T('This account status') . ' : ' . Lang::T($c['status']), 'danger', "");
} }
}else{ } else {
$c = [ $c = [
'fullname' => $gateway, 'fullname' => $gateway,
'email' => '', 'email' => '',
@ -87,7 +87,7 @@ class Package
// if customer has attribute Expired Date use it // if customer has attribute Expired Date use it
$day_exp = User::getAttribute("Expired Date", $c['id']); $day_exp = User::getAttribute("Expired Date", $c['id']);
if (!$day_exp) { if (!$day_exp) {
// if customer no attribute Expired Date use plan expired date // if customer no attribute Expired Date use plan expired date
$day_exp = 20; $day_exp = 20;
if ($p['prepaid'] == 'no') { if ($p['prepaid'] == 'no') {
$day_exp = $p['expired_date']; $day_exp = $p['expired_date'];
@ -178,9 +178,9 @@ class Package
# because 1 customer can have 1 PPPOE and 1 Hotspot Plan in mikrotik # because 1 customer can have 1 PPPOE and 1 Hotspot Plan in mikrotik
//->where('prepaid', $p['prepaid']) //->where('prepaid', $p['prepaid'])
->left_outer_join('tbl_plans', array('tbl_plans.id', '=', 'tbl_user_recharges.plan_id')); ->left_outer_join('tbl_plans', array('tbl_plans.id', '=', 'tbl_user_recharges.plan_id'));
if($isVoucher){ if ($isVoucher) {
$query->where('username', $c['username']); $query->where('username', $c['username']);
}else{ } else {
$query->where('customer_id', $id_customer); $query->where('customer_id', $id_customer);
} }
$b = $query->find_one(); $b = $query->find_one();
@ -216,6 +216,7 @@ class Package
} }
if ($b) { if ($b) {
$isChangePlan = false;
if ($config['extend_expiry'] != 'no') { if ($config['extend_expiry'] != 'no') {
if ($b['namebp'] == $p['name_plan'] && $b['status'] == 'on') { if ($b['namebp'] == $p['name_plan'] && $b['status'] == 'on') {
// if it same internet plan, expired will extend // if it same internet plan, expired will extend
@ -237,19 +238,41 @@ class Package
$date_exp = $datetime[0]; $date_exp = $datetime[0];
$time = $datetime[1]; $time = $datetime[1];
} }
} else {
$isChangePlan = true;
} }
} }
//if ($b['status'] == 'on') { //if ($b['status'] == 'on') {
$dvc = Package::getDevice($p); $dvc = Package::getDevice($p);
if ($_app_stage != 'demo') { if ($_app_stage != 'demo') {
try {
if (file_exists($dvc)) { if (file_exists($dvc)) {
require_once $dvc; require_once $dvc;
(new $p['device'])->add_customer($c, $p); (new $p['device'])->add_customer($c, $p);
} else { } else {
new Exception(Lang::T("Devices Not Found")); new Exception(Lang::T("Devices Not Found"));
} }
} catch (Throwable $e) {
Message::sendTelegram(
"Sistem Error. When activate Package. You need to sync manually\n" .
"Router: $router_name\n" .
"Customer: u$c[username]\n" .
"Plan: p$p[name_plan]\n" .
$e->getMessage() . "\n" .
$e->getTraceAsString()
);
} catch (Exception $e) {
Message::sendTelegram(
"Sistem Error. When activate Package. You need to sync manually\n" .
"Router: $router_name\n" .
"Customer: u$c[username]\n" .
"Plan: p$p[name_plan]\n" .
$e->getMessage() . "\n" .
$e->getTraceAsString()
);
} }
}
//} //}
$b->customer_id = $id_customer; $b->customer_id = $id_customer;
@ -328,11 +351,31 @@ class Package
// active plan not exists // active plan not exists
$dvc = Package::getDevice($p); $dvc = Package::getDevice($p);
if ($_app_stage != 'demo') { if ($_app_stage != 'demo') {
if (file_exists($dvc)) { try {
require_once $dvc; if (file_exists($dvc)) {
(new $p['device'])->add_customer($c, $p); require_once $dvc;
} else { (new $p['device'])->add_customer($c, $p);
new Exception(Lang::T("Devices Not Found")); } else {
new Exception(Lang::T("Devices Not Found"));
}
} catch (Throwable $e) {
Message::sendTelegram(
"Sistem Error. When activate Package. You need to sync manually\n" .
"Router: $router_name\n" .
"Customer: u$c[username]\n" .
"Plan: p$p[name_plan]\n" .
$e->getMessage() . "\n" .
$e->getTraceAsString()
);
} catch (Exception $e) {
Message::sendTelegram(
"Sistem Error. When activate Package. You need to sync manually\n" .
"Router: $router_name\n" .
"Customer: u$c[username]\n" .
"Plan: p$p[name_plan]\n" .
$e->getMessage() . "\n" .
$e->getTraceAsString()
);
} }
} }
@ -558,10 +601,10 @@ class Package
public static function getDevice($plan) public static function getDevice($plan)
{ {
global $DEVICE_PATH; global $DEVICE_PATH;
if($plan === false){ if ($plan === false) {
return "none"; return "none";
} }
if(!isset($plan['device'])){ if (!isset($plan['device'])) {
return "none"; return "none";
} }
if (!empty($plan['device'])) { if (!empty($plan['device'])) {

View File

@ -242,8 +242,8 @@
<label class="col-md-2 control-label">{Lang::T('Allow Extend')}</label> <label class="col-md-2 control-label">{Lang::T('Allow Extend')}</label>
<div class="col-md-6"> <div class="col-md-6">
<select name="extend_expired" id="extend_expired" class="form-control text-muted"> <select name="extend_expired" id="extend_expired" class="form-control text-muted">
<option value="0">No</option>
<option value="1" {if $_c['extend_expired']}selected="selected" {/if}>Yes</option> <option value="1" {if $_c['extend_expired']}selected="selected" {/if}>Yes</option>
<option value="0">No</option>
</select> </select>
</div> </div>
<p class="help-block col-md-4">Customer can request to extend expirations</p> <p class="help-block col-md-4">Customer can request to extend expirations</p>
@ -599,7 +599,7 @@
<div class="form-group" id="timeout_duration_input" style="display: none;"> <div class="form-group" id="timeout_duration_input" style="display: none;">
<label class="col-md-2 control-label">{Lang::T('Timeout Duration')}</label> <label class="col-md-2 control-label">{Lang::T('Timeout Duration')}</label>
<div class="col-md-6"> <div class="col-md-6">
<input type="number" value="{$_c['session_timeout_duration']}" class="form-control" name="session_timeout_duration" id="session_timeout_duration" <input type="number" value="{$_c['session_timeout_duration']}" class="form-control" name="session_timeout_duration" id="session_timeout_duration"
placeholder="{Lang::T('Enter the session timeout duration (minutes)')}" min="1"> placeholder="{Lang::T('Enter the session timeout duration (minutes)')}" min="1">
</div> </div>
<p class="help-block col-md-4">{Lang::T('Idle Timeout, Logout Admin if Idle for xx minutes')}</p> <p class="help-block col-md-4">{Lang::T('Idle Timeout, Logout Admin if Idle for xx minutes')}</p>