ajax select customer

This commit is contained in:
Ibnu Maksum 2023-08-23 12:11:07 +07:00
parent 27a2938534
commit 54ff67fa49
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
5 changed files with 69 additions and 48 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/) * PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* used for ajax * used for ajax
@ -35,7 +36,24 @@ switch ($action) {
$ui->display('autoload.tpl'); $ui->display('autoload.tpl');
break; break;
case 'customer_select2':
$s = addslashes(_get('s'));
if (empty($s)) {
$c = ORM::for_table('tbl_customers')->limit(30)->find_many();
} else {
$c = ORM::for_table('tbl_customers')->where_raw("(`username` LIKE '%$s%' OR `fullname` LIKE '%$s%' OR `phonenumber` LIKE '%$s%' OR `email` LIKE '%$s%')", [$s,$s,$s,$s])->limit(30)->find_many();
}
header('Content-Type: application/json');
foreach ($c as $cust){
$json[] = [
'id' => $cust['id'],
'text' => $cust['username'].' - '.$cust['fullname'].' - '.$cust['email']
];
}
echo json_encode(['results'=>$json]);
die();
break;
default: default:
echo 'action not defined'; echo 'action not defined';
} }

View File

@ -18,7 +18,24 @@ if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') {
r2(U . "dashboard", 'e', $_L['Do_Not_Access']); r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
} }
use PEAR2\Net\RouterOS; $select2_customer = <<<EOT
<script>
document.addEventListener("DOMContentLoaded", function(event) {
$('#personSelect').select2({
theme: "bootstrap",
ajax: {
url: function(params) {
if(params.term != undefined){
return './index.php?_route=autoload/customer_select2&s='+params.term;
}else{
return './index.php?_route=autoload/customer_select2';
}
}
}
});
});
</script>
EOT;
require_once 'system/autoload/PEAR2/Autoload.php'; require_once 'system/autoload/PEAR2/Autoload.php';
@ -43,8 +60,7 @@ switch ($action) {
break; break;
case 'recharge': case 'recharge':
$c = ORM::for_table('tbl_customers')->find_many(); $ui->assign('xfooter', $select2_customer);
$ui->assign('c', $c);
$p = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many(); $p = ORM::for_table('tbl_plans')->where('enabled', '1')->find_many();
$ui->assign('p', $p); $ui->assign('p', $p);
$r = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many(); $r = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
@ -341,10 +357,8 @@ switch ($action) {
break; break;
case 'refill': case 'refill':
$ui->assign('xfooter', '<script type="text/javascript" src="ui/ui/scripts/form-elements.init.js"></script>'); $ui->assign('xfooter', $select2_customer);
$ui->assign('_title', $_L['Refill_Account']); $ui->assign('_title', $_L['Refill_Account']);
$c = ORM::for_table('tbl_customers')->find_many();
$ui->assign('c', $c);
run_hook('view_refill'); #HOOK run_hook('view_refill'); #HOOK
$ui->display('refill.tpl'); $ui->display('refill.tpl');
@ -376,7 +390,7 @@ switch ($action) {
break; break;
case 'deposit': case 'deposit':
$ui->assign('_title', Lang::T('Refill Balance')); $ui->assign('_title', Lang::T('Refill Balance'));
$ui->assign('c', ORM::for_table('tbl_customers')->find_many()); $ui->assign('xfooter', $select2_customer);
$ui->assign('p', ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many()); $ui->assign('p', ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many());
run_hook('view_deposit'); #HOOK run_hook('view_deposit'); #HOOK
$ui->display('deposit.tpl'); $ui->display('deposit.tpl');

View File

@ -11,10 +11,6 @@
<div class="col-md-6"> <div class="col-md-6">
<select id="personSelect" class="form-control select2" name="id_customer" style="width: 100%" <select id="personSelect" class="form-control select2" name="id_customer" style="width: 100%"
data-placeholder="{$_L['Select_Customer']}..."> data-placeholder="{$_L['Select_Customer']}...">
<option></option>
{foreach $c as $cs}
<option value="{$cs['id']}">{$cs['username']} - {$cs['fullname']}</option>
{/foreach}
</select> </select>
</div> </div>
</div> </div>

View File

@ -10,10 +10,6 @@
<label class="col-md-2 control-label">{$_L['Select_Account']}</label> <label class="col-md-2 control-label">{$_L['Select_Account']}</label>
<div class="col-md-6"> <div class="col-md-6">
<select id="personSelect" class="form-control select2" name="id_customer" style="width: 100%" data-placeholder="{$_L['Select_Customer']}..."> <select id="personSelect" class="form-control select2" name="id_customer" style="width: 100%" data-placeholder="{$_L['Select_Customer']}...">
<option></option>
{foreach $c as $cs}
<option value="{$cs['id']}">{$cs['username']}</option>
{/foreach}
</select> </select>
</div> </div>
</div> </div>

View File

@ -9,12 +9,8 @@
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">{$_L['Select_Account']}</label> <label class="col-md-2 control-label">{$_L['Select_Account']}</label>
<div class="col-md-6"> <div class="col-md-6">
<select id="personSelect" class="form-control select2" name="id_customer" style="width: 100%" <select id="personSelect" class="form-control select2" name="id_customer"
data-placeholder="{$_L['Select_Customer']}..."> style="width: 100%" data-placeholder="{$_L['Select_Customer']}...">
<option></option>
{foreach $c as $cs}
<option value="{$cs['id']}">{$cs['username']}</option>
{/foreach}
</select> </select>
</div> </div>
</div> </div>
@ -39,4 +35,5 @@
</div> </div>
</div> </div>
{include file="sections/footer.tpl"} {include file="sections/footer.tpl"}