diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index 3ea5e188..097896d9 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -316,4 +316,5 @@ ALTER TABLE `tbl_plans` ADD `list_expired` VARCHAR(32) NOT NULL DEFAULT '' COMME ALTER TABLE `tbl_bandwidth` ADD `burst` VARCHAR(128) NOT NULL DEFAULT '' AFTER `rate_up_unit`; ALTER TABLE `tbl_transactions` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `type`; ALTER TABLE `tbl_user_recharges` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `type`; -ALTER TABLE `tbl_plans` CHANGE `allow_purchase` `prepaid` ENUM('yes','no') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'yes' COMMENT 'is prepaid'; \ No newline at end of file +ALTER TABLE `tbl_plans` CHANGE `allow_purchase` `prepaid` ENUM('yes','no') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'yes' COMMENT 'is prepaid'; +ALTER TABLE `tbl_transactions` ADD `note` VARCHAR(256) NOT NULL DEFAULT '' COMMENT 'for note' AFTER `type`; \ No newline at end of file diff --git a/system/autoload/Message.php b/system/autoload/Message.php index 0823ce51..0dc75027 100644 --- a/system/autoload/Message.php +++ b/system/autoload/Message.php @@ -123,8 +123,11 @@ class Message $textInvoice = str_replace('[[plan_name]]', $trx['plan_name'], $textInvoice); $textInvoice = str_replace('[[plan_price]]', Lang::moneyFormat($trx['price']), $textInvoice); $textInvoice = str_replace('[[name]]', $cust['fullname'], $textInvoice); + $textInvoice = str_replace('[[note]]', $cust['note'], $textInvoice); $textInvoice = str_replace('[[user_name]]', $trx['username'], $textInvoice); $textInvoice = str_replace('[[user_password]]', $cust['password'], $textInvoice); + $textInvoice = str_replace('[[username]]', $trx['username'], $textInvoice); + $textInvoice = str_replace('[[password]]', $cust['password'], $textInvoice); $textInvoice = str_replace('[[expired_date]]', Lang::dateAndTimeFormat($trx['expiration'], $trx['time']), $textInvoice); $textInvoice = str_replace('[[footer]]', $config['note'], $textInvoice); diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 8d5e1782..ea65fb37 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -17,7 +17,7 @@ class Package * @param string $channel channel payment gateway * @return boolean */ - public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel) + public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel, $note = '') { global $config, $admin, $c, $p, $b, $t, $d, $zero; $date_now = date("Y-m-d H:i:s"); @@ -34,14 +34,20 @@ class Package // Additional cost $add_cost = 0; - $add_cycle = User::getAttribute("Additional Cycle", $id_customer); + $add_rem = User::getAttribute("Additional Remaining", $id_customer); // if empty then it doesnt have cycle, if zero then it finish - if ($add_cycle != 0) { + if ($add_rem != 0) { $add_cost = User::getAttribute("Additional Cost", $id_customer); if (empty($add_cost)) { $add_cost = 0; } } + if ($add_cost > 0 && $router_name != 'balance') { + $bills = User::getAttributes("Bill", $id_customer); + foreach ($bills as $k => $v) { + $note .= $k . " : " . Lang::moneyFormat($v) . "\n"; + } + } // Zero cost recharge if (isset($zero) && $zero == 1) { @@ -247,6 +253,7 @@ class Package $t->time = $time; $t->method = "$gateway - $channel"; $t->routers = $router_name; + $t->note = $note; $t->type = "Hotspot"; if ($admin) { $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; @@ -333,6 +340,7 @@ class Package $t->time = $time; $t->method = "$gateway - $channel"; $t->routers = $router_name; + $t->note = $note; $t->type = "Hotspot"; if ($admin) { $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; @@ -432,6 +440,7 @@ class Package $t->time = $time; $t->method = "$gateway - $channel"; $t->routers = $router_name; + $t->note = $note; $t->type = "PPPOE"; if ($admin) { $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; @@ -516,6 +525,7 @@ class Package $t->expiration = $date_exp; $t->time = $time; $t->method = "$gateway - $channel"; + $t->note = $note; $t->routers = $router_name; if ($admin) { $t->admin_id = ($admin['id']) ? $admin['id'] : '0'; @@ -552,8 +562,8 @@ class Package "\nPrice: " . Lang::moneyFormat($p['price'])); } } - if ($add_cycle > 0) { - User::setAttribute('Additional Cycle', ($add_cycle - 1), $id_customer); + if ($add_rem > 0) { + User::setAttribute('Additional Remaining', ($add_rem - 1), $id_customer); } run_hook("recharge_user_finish"); Message::sendInvoice($c, $t); @@ -675,7 +685,11 @@ class Package $invoice .= Lang::pads(Lang::T('Plan Name'), $in['plan_name'], ' ') . "\n"; $invoice .= Lang::pads(Lang::T('Plan Price'), Lang::moneyFormat($in['price']), ' ') . "\n"; $invoice .= Lang::pad($in['method'], ' ', 2) . "\n"; - + if(!empty($in['note'])){ + $invoice .= Lang::pad("", '=') . "\n"; + $invoice .= Lang::pad($in['note'], ' ', 2); + } + $invoice .= Lang::pad("", '=') . "\n"; $invoice .= Lang::pads(Lang::T('Username'), $in['username'], ' ') . "\n"; $invoice .= Lang::pads(Lang::T('Password'), '**********', ' ') . "\n"; if ($in['type'] != 'Balance') { @@ -699,7 +713,11 @@ class Package $invoice .= Lang::pads(Lang::T('Plan Name'), $in['plan_name'], ' ') . "\n"; $invoice .= Lang::pads(Lang::T('Plan Price'), Lang::moneyFormat($in['price']), ' ') . "\n"; $invoice .= Lang::pad($in['method'], ' ', 2) . "\n"; - + if(!empty($in['note'])){ + $invoice .= Lang::pad("", '=') . "\n"; + $invoice .= Lang::pad($in['note'], ' ', 2); + } + $invoice .= Lang::pad("", '=') . "\n"; $invoice .= Lang::pads(Lang::T('Username'), $in['username'], ' ') . "\n"; $invoice .= Lang::pads(Lang::T('Password'), '**********', ' ') . "\n"; if ($in['type'] != 'Balance') { diff --git a/system/controllers/customers.php b/system/controllers/customers.php index cfdf23b4..c461be8c 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -12,7 +12,7 @@ $ui->assign('_system_menu', 'customers'); $action = $routes['1']; $ui->assign('_admin', $admin); -if(empty($action)){ +if (empty($action)) { $action = 'list'; } @@ -48,7 +48,7 @@ switch ($action) { case 'csv': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $cs = ORM::for_table('tbl_customers') ->select('tbl_customers.id', 'id') @@ -86,29 +86,63 @@ switch ($action) { } break; case 'add': - if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } run_hook('view_add_customer'); #HOOK $ui->display('customers-add.tpl'); break; case 'recharge': - if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $id_customer = $routes['2']; $b = ORM::for_table('tbl_user_recharges')->where('customer_id', $id_customer)->find_one(); if ($b) { - if (Package::rechargeUser($id_customer, $b['routers'], $b['plan_id'], "Recharge", $admin['fullname'])) { - r2(U . 'customers/view/' . $id_customer, 's', 'Success Recharge Customer'); - } else { - r2(U . 'customers/view/' . $id_customer, 'e', 'Customer plan is inactive'); + $gateway = 'Recharge'; + $channel = $admin['fullname']; + $cust = User::_info($id_customer); + $plan = ORM::for_table('tbl_plans')->find_one($b['plan_id']); + $add_cost = 0; + $add_rem = User::getAttribute("Additional Remaining", $id_customer); + if($add_rem != 0){ + $add_cost = User::getAttribute("Additional Cost", $id_customer); + if (empty($add_cost)) { + $add_cost = 0; + } } + if ($using == 'balance' && $config['enable_balance'] == 'yes') { + if (!$cust) { + r2(U . 'prepaid/recharge', 'e', Lang::T('Customer not found')); + } + if (!$plan) { + r2(U . 'prepaid/recharge', 'e', Lang::T('Plan not found')); + } + if ($cust['balance'] < ($plan['price'] + $add_cost)) { + r2(U . 'prepaid/recharge', 'e', Lang::T('insufficient balance')); + } + $gateway = 'Recharge Balance'; + } + if ($using == 'zero') { + $zero = 1; + $gateway = 'Recharge Zero'; + } + $bills = User::getAttributes("Bill", $id_customer); + $ui->assign('bills', $bills); + $ui->assign('add_cost', $add_cost); + $ui->assign('add_rem', $add_rem); + $ui->assign('cust', $cust); + $ui->assign('gateway', $gateway); + $ui->assign('channel', $channel); + $ui->assign('server', $b['routers']); + $ui->assign('using', 'default'); + $ui->assign('plan', $plan); + $ui->display('recharge-confirm.tpl'); } r2(U . 'customers/view/' . $id_customer, 'e', 'Cannot find active plan'); case 'deactivate': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $id_customer = $routes['2']; $b = ORM::for_table('tbl_user_recharges')->where('customer_id', $id_customer)->find_one(); @@ -215,8 +249,8 @@ switch ($action) { } break; case 'edit': - if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent'])) { + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $id = $routes['2']; run_hook('edit_customer'); #HOOK @@ -236,7 +270,7 @@ switch ($action) { case 'delete': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $id = $routes['2']; run_hook('delete_customer'); #HOOK @@ -277,7 +311,7 @@ switch ($action) { } catch (Throwable $e) { } try { - if($c) $c->delete(); + if ($c) $c->delete(); } catch (Exception $e) { } catch (Throwable $e) { } @@ -499,7 +533,7 @@ switch ($action) { } } } - r2(U . 'customers/list', 's', 'User Updated Successfully'); + r2(U . 'customers/view/' . $id, 's', 'User Updated Successfully'); } else { r2(U . 'customers/edit/' . $id, 'e', $msg); } diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index e26249bf..b9f11034 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -96,37 +96,17 @@ switch ($action) { $ui->display('recharge.tpl'); break; - case 'recharge-user': - if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { - _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); - } - $id = $routes['2']; - $ui->assign('id', $id); - - $c = ORM::for_table('tbl_customers')->find_many(); - $ui->assign('c', $c); - $p = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many(); - $ui->assign('p', $p); - $r = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many(); - $ui->assign('r', $r); - run_hook('view_recharge_customer'); #HOOK - $ui->display('recharge-user.tpl'); - break; - - case 'recharge-post': + case 'recharge-confirm': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $id_customer = _post('id_customer'); - $type = _post('type'); $server = _post('server'); $planId = _post('plan'); $using = _post('using'); - $date_only = date("Y-m-d"); - $time = date("H:i:s"); $msg = ''; - if ($id_customer == '' or $type == '' or $server == '' or $planId == '') { + if ($id_customer == '' or $server == '' or $planId == '' or $using == '') { $msg .= Lang::T('All field is required') . '
'; } @@ -134,19 +114,23 @@ switch ($action) { $gateway = 'Recharge'; $channel = $admin['fullname']; $cust = User::_info($id_customer); - if ($using == 'balance' && $config['enable_balance'] == 'yes') { + $plan = ORM::for_table('tbl_plans')->find_one($planId); + $add_cost = 0; + $add_rem = User::getAttribute("Additional Remaining", $id_customer); + if($add_rem != 0){ $add_cost = User::getAttribute("Additional Cost", $id_customer); - if(empty($add_cost)){ + if (empty($add_cost)) { $add_cost = 0; } - $plan = ORM::for_table('tbl_plans')->find_one($planId); + } + if ($using == 'balance' && $config['enable_balance'] == 'yes') { if (!$cust) { r2(U . 'prepaid/recharge', 'e', Lang::T('Customer not found')); } if (!$plan) { r2(U . 'prepaid/recharge', 'e', Lang::T('Plan not found')); } - if ($cust['balance'] < ($plan['price']+$add_cost)) { + if ($cust['balance'] < ($plan['price'] + $add_cost)) { r2(U . 'prepaid/recharge', 'e', Lang::T('insufficient balance')); } $gateway = 'Recharge Balance'; @@ -155,9 +139,69 @@ switch ($action) { $zero = 1; $gateway = 'Recharge Zero'; } + $bills = User::getAttributes("Bill", $id_customer); + $ui->assign('bills', $bills); + $ui->assign('add_cost', $add_cost); + $ui->assign('add_rem', $add_rem); + $ui->assign('cust', $cust); + $ui->assign('gateway', $gateway); + $ui->assign('channel', $channel); + $ui->assign('server', $server); + $ui->assign('using', $using); + $ui->assign('plan', $plan); + $ui->display('recharge-confirm.tpl'); + } else { + r2(U . 'prepaid/recharge', 'e', $msg); + } + break; + + case 'recharge-post': + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); + } + $id_customer = _post('id_customer'); + $server = _post('server'); + $planId = _post('plan'); + $using = _post('using'); + + $msg = ''; + if ($id_customer == '' or $server == '' or $planId == '' or $using == '') { + $msg .= Lang::T('All field is required') . '
'; + } + + if ($msg == '') { + $gateway = 'Recharge'; + $channel = $admin['fullname']; + $cust = User::_info($id_customer); + $add_cost = 0; + $add_rem = User::getAttribute("Additional Remaining", $id_customer); + if($add_rem != 0){ + $add_cost = User::getAttribute("Additional Cost", $id_customer); + if (empty($add_cost)) { + $add_cost = 0; + } + } + if ($using == 'balance' && $config['enable_balance'] == 'yes') { + $plan = ORM::for_table('tbl_plans')->find_one($planId); + if (!$cust) { + r2(U . 'prepaid/recharge', 'e', Lang::T('Customer not found')); + } + if (!$plan) { + r2(U . 'prepaid/recharge', 'e', Lang::T('Plan not found')); + } + if ($cust['balance'] < ($plan['price'] + $add_cost)) { + r2(U . 'prepaid/recharge', 'e', Lang::T('insufficient balance')); + } + $gateway = 'Recharge Balance'; + } + if ($using == 'zero') { + $add_cost = 0; + $zero = 1; + $gateway = 'Recharge Zero'; + } if (Package::rechargeUser($id_customer, $server, $planId, $gateway, $channel)) { if ($using == 'balance') { - Balance::min($cust['id'], $plan['price']+$add_cost); + Balance::min($cust['id'], $plan['price'] + $add_cost); } $in = ORM::for_table('tbl_transactions')->where('username', $cust['username'])->order_by_desc('id')->find_one(); Package::createInvoice($in); @@ -698,7 +742,7 @@ switch ($action) { $ui->assign('xfooter', $select2_customer); if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { $ui->assign('p', ORM::for_table('tbl_plans')->where('type', 'Balance')->find_many()); - }else{ + } else { $ui->assign('p', ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many()); } run_hook('view_deposit'); #HOOK diff --git a/system/lan/english.json b/system/lan/english.json index e4456d21..01910dc9 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -479,5 +479,12 @@ "PPPOE": "PPPOE", "Bandwidth": "Bandwidth", "Customers": "Customers", - "Actives": "Actives" + "Actives": "Actives", + "Name": "Name", + "Confirm": "Confirm", + "Plan": "Plan", + "Total": "Total", + "Current_Cycle": "Current Cycle", + "Additional_Cost": "Additional Cost", + "Remaining": "Remaining" } \ No newline at end of file diff --git a/system/updates.json b/system/updates.json index 60cd6177..29f3282a 100644 --- a/system/updates.json +++ b/system/updates.json @@ -75,5 +75,8 @@ ], "2024.3.12" : [ "ALTER TABLE `tbl_plans` CHANGE `allow_purchase` `prepaid` ENUM('yes','no') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'yes' COMMENT 'is prepaid';" + ], + "2024.3.14" : [ + "ALTER TABLE `tbl_transactions` ADD `note` VARCHAR(256) NOT NULL DEFAULT '' COMMENT 'for note' AFTER `type`;" ] } \ No newline at end of file diff --git a/ui/ui/customers-add.tpl b/ui/ui/customers-add.tpl index 1b2f026d..acef5cfe 100644 --- a/ui/ui/customers-add.tpl +++ b/ui/ui/customers-add.tpl @@ -92,7 +92,6 @@
-
diff --git a/ui/ui/recharge-confirm.tpl b/ui/ui/recharge-confirm.tpl new file mode 100644 index 00000000..f1496bcf --- /dev/null +++ b/ui/ui/recharge-confirm.tpl @@ -0,0 +1,99 @@ +{include file="sections/header.tpl"} + +
+
+
+
{Lang::T('Confirm')}
+
+
{Lang::T('Customer')}
+
    +
  • + {Lang::T('Username')} {$cust['username']} +
  • +
  • + {Lang::T('Name')} {$cust['fullname']} +
  • +
  • + {Lang::T('Phone Number')} {$cust['phonenumber']} +
  • +
  • + {Lang::T('Email')} {$cust['email']} +
  • +
  • + {Lang::T('Address')} {$cust['address']} +
  • +
  • + {Lang::T('Balance')} {Lang::moneyFormat($cust['balance'])} +
  • +
+
{Lang::T('Plan')}
+
    +
  • + {Lang::T('Plan Name')} {$plan['name_plan']} +
  • +
  • + {Lang::T('Location')} {if $plan['is_radius']}Radius{else}{$plan['routers']}{/if} +
  • +
  • + {Lang::T('Type')} {if $plan['prepaid'] eq 'yes'}Prepaid{else}Postpaid{/if} + {$plan['type']} +
  • +
  • + {Lang::T('Plan Price')} {if $using eq 'zero'}{Lang::moneyFormat(0)}{else}{Lang::moneyFormat($plan['price'])}{/if} +
  • +
  • + {Lang::T('Plan Validity')} {$plan['validity']} + {$plan['validity_unit']} +
  • +
  • + {Lang::T('Using')} {$using} +
  • +
+
{Lang::T('Total')}
+
    + {if $add_rem != 0 and $using neq 'zero' and $add_cost>0} + {foreach $bills as $k => $v} +
  • + {$k} {Lang::moneyFormat($v)} +
  • + {/foreach} +
  • + {Lang::T('Additional Cost')} {Lang::moneyFormat($add_cost)} +
  • + {if $add_rem != ''} +
  • + {Lang::T('Remaining')} {$add_rem} +
  • + {/if} +
  • + {Lang::T('Total')} ({Lang::T('Plan Price')} +{Lang::T('Additional Cost')}){Lang::moneyFormat($plan['price']+$add_cost)} +
  • + {else} +
  • + {Lang::T('Total')} {if $using eq 'zero'}{Lang::moneyFormat(0)}{else}{Lang::moneyFormat($plan['price'])}{/if} +
  • + {/if} +
+
+ + + + +
+
+ {Lang::T('Cancel')} +
+
+
+
+
+
+ +{include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/recharge-user.tpl b/ui/ui/recharge-user.tpl deleted file mode 100644 index 56267c11..00000000 --- a/ui/ui/recharge-user.tpl +++ /dev/null @@ -1,62 +0,0 @@ -{include file="sections/header.tpl"} - -
-
-
-
{Lang::T('Recharge Account')}
-
-
-
- -
- -
-
-
- -
- - -
-
-
- -
- -
-
- -
- -
- -
-
- -
-
- - Or {Lang::T('Cancel')} -
-
-
-
-
-
-
- - -{include file="sections/footer.tpl"} diff --git a/ui/ui/recharge.tpl b/ui/ui/recharge.tpl index 58fd9848..c988f5dc 100644 --- a/ui/ui/recharge.tpl +++ b/ui/ui/recharge.tpl @@ -5,7 +5,7 @@
{Lang::T('Recharge Account')}
-
+