Fix search and psql like queries need to be ilike for case insensitivity

This commit is contained in:
2024-07-06 22:56:51 +10:00
parent 61fe84498a
commit 70e94bf6e6
7 changed files with 33 additions and 33 deletions

View File

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