Fix search and psql like queries need to be ilike for case insensitivity
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 34s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
Deon George 2024-07-06 22:56:51 +10:00
parent 61fe84498a
commit 54cc99eac3
7 changed files with 32 additions and 33 deletions

View File

@ -32,7 +32,7 @@ class BroadbandTraffic extends Command
public function handle() public function handle()
{ {
if ($this->option('supplier')) { if ($this->option('supplier')) {
$o = Supplier::where('name','like',$this->option('supplier'))->singleOrFail(); $o = Supplier::where('name','ilike',$this->option('supplier'))->singleOrFail();
Job::dispatchSync($o->id); Job::dispatchSync($o->id);
return; return;

View File

@ -7,7 +7,7 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
use App\Models\{Account,Invoice,Payment,Service,Supplier,User}; use App\Models\{Account,Invoice,Payment,Service,User};
class SearchController extends Controller class SearchController extends Controller
{ {
@ -29,12 +29,11 @@ class SearchController extends Controller
if (! $request->input('term')) if (! $request->input('term'))
return $result; return $result;
$account_ids = ($x=Auth::user()->accounts)->pluck('id'); $account_ids = ($x=Auth::user()->accounts_all)->pluck('id');
$user_ids = $x->transform(function($item) { return $item->user;})->pluck('id');
# Look for User // Look for User
foreach (User::Search($request->input('term')) foreach (User::Search($request->input('term'))
->whereIN('id',$user_ids) ->whereIN('id',$x->pluck('user_id')->unique())
->orderBy('lastname') ->orderBy('lastname')
->orderBy('firstname') ->orderBy('firstname')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
@ -42,7 +41,7 @@ class SearchController extends Controller
$result->push(['name'=>sprintf('%s (%s) - %s',$o->name,$o->lid,$o->email),'value'=>'/u/home/'.$o->id,'category'=>'Users']); $result->push(['name'=>sprintf('%s (%s) - %s',$o->name,$o->lid,$o->email),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
} }
# Look for User by Supplier // Look for User by their Supplier ID with some suppliers
if (is_numeric($request->input('term'))) if (is_numeric($request->input('term')))
foreach (User::select(['users.*','suppliers.name AS supplier_name','supplier_user.id AS pivot_id']) foreach (User::select(['users.*','suppliers.name AS supplier_name','supplier_user.id AS pivot_id'])
->join('supplier_user',['supplier_user.user_id'=>'users.id']) ->join('supplier_user',['supplier_user.user_id'=>'users.id'])
@ -56,16 +55,16 @@ class SearchController extends Controller
$result->push(['name'=>sprintf('%s (%s:%s)',$o->name,$o->supplier_name,$o->pivot_id),'value'=>'/u/home/'.$o->id,'category'=>'Suppliers']); $result->push(['name'=>sprintf('%s (%s:%s)',$o->name,$o->supplier_name,$o->pivot_id),'value'=>'/u/home/'.$o->id,'category'=>'Suppliers']);
} }
# Look for Account // Look for Account
foreach (Account::Search($request->input('term')) foreach (Account::Search($request->input('term'))
->whereIN('user_id',$user_ids) ->whereIN('id',$account_ids)
->orderBy('company') ->orderBy('company')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
$result->push(['name'=>sprintf('%s (%s)',$o->company,$o->lid),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']); $result->push(['name'=>sprintf('%s (%s)',$o->company,$o->lid),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
} }
# Look for a Service // Look for a Service
foreach (Service::Search($request->input('term')) foreach (Service::Search($request->input('term'))
->whereIN('account_id',$account_ids) ->whereIN('account_id',$account_ids)
->orderBy('id') ->orderBy('id')
@ -74,7 +73,7 @@ class SearchController extends Controller
$result->push(['name'=>sprintf('%s (%s) %s',$o->name,$o->lid,$o->active ? '' : '<small>INACT</small>'),'value'=>'/u/service/'.$o->id,'category'=>$o->category_name]); $result->push(['name'=>sprintf('%s (%s) %s',$o->name,$o->lid,$o->active ? '' : '<small>INACT</small>'),'value'=>'/u/service/'.$o->id,'category'=>$o->category_name]);
} }
# Look for an Invoice // Look for an Invoice
foreach (Invoice::Search($request->input('term')) foreach (Invoice::Search($request->input('term'))
->whereIN('account_id',$account_ids) ->whereIN('account_id',$account_ids)
->orderBy('id') ->orderBy('id')
@ -84,7 +83,7 @@ class SearchController extends Controller
} }
if (Gate::any(['wholesaler'],new Payment)) { if (Gate::any(['wholesaler'],new Payment)) {
# Look for Payments // Look for Payments
foreach (Payment::Search($request->input('term')) foreach (Payment::Search($request->input('term'))
->whereIN('account_id',$account_ids) ->whereIN('account_id',$account_ids)
->limit(10)->get() as $o) ->limit(10)->get() as $o)

View File

@ -180,10 +180,10 @@ class Account extends Model implements IDs
$query->where('id','like','%'.$term.'%'); $query->where('id','like','%'.$term.'%');
} else { } else {
$query->where('company','like','%'.$term.'%') $query->where('company','ilike','%'.$term.'%')
->orWhere('address1','like','%'.$term.'%') ->orWhere('address1','ilike','%'.$term.'%')
->orWhere('address2','like','%'.$term.'%') ->orWhere('address2','ilike','%'.$term.'%')
->orWhere('city','like','%'.$term.'%'); ->orWhere('city','ilike','%'.$term.'%');
} }
return $query; return $query;

View File

@ -530,18 +530,18 @@ class Service extends Model implements IDs
return $query->select('services.*') return $query->select('services.*')
->where('services.id','like',$t) ->where('services.id','like',$t)
->leftJoin('service_broadband',['service_broadband.service_id'=>'services.id']) ->leftJoin('service_broadband',['service_broadband.service_id'=>'services.id'])
->orWhere('service_broadband.service_number','like',$t) ->orWhere('service_broadband.service_number','ilike',$t)
->orWhere('service_broadband.service_address','like',$t) ->orWhere('service_broadband.service_address','ilike',$t)
->orWhere('service_broadband.ipaddress','like',$t) ->orWhere('service_broadband.ipaddress','ilike',$t)
->leftJoin('service_phone',['service_phone.service_id'=>'services.id']) ->leftJoin('service_phone',['service_phone.service_id'=>'services.id'])
->orWhere('service_phone.service_number','like',$t) ->orWhere('service_phone.service_number','ilike',$t)
->orWhere('service_phone.service_address','like',$t) ->orWhere('service_phone.service_address','ilike',$t)
->leftJoin('service_domain',['service_domain.service_id'=>'services.id']) ->leftJoin('service_domain',['service_domain.service_id'=>'services.id'])
->orWhere('service_domain.domain_name','like',$t) ->orWhere('service_domain.domain_name','ilike',$t)
->leftJoin('service_email',['service_email.service_id'=>'services.id']) ->leftJoin('service_email',['service_email.service_id'=>'services.id'])
->orWhere('service_email.domain_name','like',$t) ->orWhere('service_email.domain_name','ilike',$t)
->leftJoin('service_host',['service_host.service_id'=>'services.id']) ->leftJoin('service_host',['service_host.service_id'=>'services.id'])
->orWhere('service_host.domain_name','like',$t); ->orWhere('service_host.domain_name','ilike',$t);
} }
/* ATTRIBUTES */ /* ATTRIBUTES */

View File

@ -189,27 +189,27 @@ class User extends Authenticatable implements IDs
{ {
// Build our where clause // Build our where clause
// First Name, Last name // First Name, Last name
if (preg_match('/\ /',$term)) { if (preg_match('/\s+/',$term)) {
[$fn,$ln] = explode(' ',$term,2); [$fn,$ln] = explode(' ',$term,2);
$query->where(function($query1) use ($fn,$ln,$term) { $query->where(function($query1) use ($fn,$ln,$term) {
$query1->where(function($query2) use ($fn,$ln) { $query1->where(function($query2) use ($fn,$ln) {
return $query2 return $query2
->where('firstname','like','%'.$fn.'%') ->where('firstname','ilike','%'.$fn.'%')
->where('lastname','like','%'.$ln.'%'); ->where('lastname','ilike','%'.$ln.'%');
}); });
}); });
} elseif (is_numeric($term)) { } elseif (is_numeric($term)) {
$query->where('users.id','like','%'.$term.'%'); $query->where('users.id','like','%'.$term.'%');
} elseif (preg_match('/\@/',$term)) { } elseif (preg_match('/@/',$term)) {
$query->where('email','like','%'.$term.'%'); $query->where('email','ilike','%'.$term.'%');
} else { } else {
$query $query
->Where('firstname','like','%'.$term.'%') ->Where('firstname','ilike','%'.$term.'%')
->orWhere('lastname','like','%'.$term.'%'); ->orWhere('lastname','ilike','%'.$term.'%');
} }
return $query; return $query;

View File

@ -54,6 +54,6 @@ trait ServiceDomains
// Build our where clause // Build our where clause
return parent::scopeSearch($query,$term) return parent::scopeSearch($query,$term)
->orwhere('domain_name','like','%'.$term.'%'); ->orwhere('domain_name','ilike','%'.$term.'%');
} }
} }