From f7deb828ac5ee992293865f36f0d9c0f82daa16f Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Mon, 29 Apr 2024 13:18:07 +0700 Subject: [PATCH] don't delete customer when plan not change --- system/autoload/Package.php | 40 +++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 28a22ad..6178f0b 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -185,9 +185,12 @@ class Package $date_exp = $datetime[0]; $time = $datetime[1]; } - + $isChangePlan = false; if ($p['type'] == 'Hotspot') { if ($b) { + if($plan_id!=$b['plan_id']){ + $isChangePlan = true; + } if ($b['namebp'] == $p['name_plan'] && $b['status'] == 'on') { // if it same internet plan, expired will extend if ($p['validity_unit'] == 'Months') { @@ -210,13 +213,15 @@ class Package } } - if ($p['is_radius']) { - Radius::customerAddPlan($c, $p, "$date_exp $time"); - } else { - $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - Mikrotik::removeHotspotUser($client, $c['username']); - Mikrotik::removeHotspotActiveUser($client, $c['username']); - Mikrotik::addHotspotUser($client, $p, $c); + if($isChangePlan){ + if ($p['is_radius']) { + Radius::customerAddPlan($c, $p, "$date_exp $time"); + } else { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removeHotspotUser($client, $c['username']); + Mikrotik::removeHotspotActiveUser($client, $c['username']); + Mikrotik::addHotspotUser($client, $p, $c); + } } $b->customer_id = $id_customer; @@ -384,6 +389,9 @@ class Package } else { if ($b) { + if($plan_id!=$b['plan_id']){ + $isChangePlan = true; + } if ($b['namebp'] == $p['name_plan'] && $b['status'] == 'on') { // if it same internet plan, expired will extend if ($p['validity_unit'] == 'Months') { @@ -406,13 +414,15 @@ class Package } } - if ($p['is_radius']) { - Radius::customerAddPlan($c, $p, "$date_exp $time"); - } else { - $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - Mikrotik::removePpoeUser($client, $c['username']); - Mikrotik::removePpoeActive($client, $c['username']); - Mikrotik::addPpoeUser($client, $p, $c); + if($isChangePlan){ + if ($p['is_radius']) { + Radius::customerAddPlan($c, $p, "$date_exp $time"); + } else { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePpoeUser($client, $c['username']); + Mikrotik::removePpoeActive($client, $c['username']); + Mikrotik::addPpoeUser($client, $p, $c); + } } $b->customer_id = $id_customer;