Removed many redundant functions from User::class

This commit is contained in:
Deon George
2022-04-21 16:25:29 +10:00
parent 796c72dd09
commit d53643ef55
25 changed files with 87 additions and 625 deletions

View File

@@ -25,31 +25,31 @@ class SearchController extends Controller
if (! $request->input('term'))
return $result;
$accounts = ($x=Auth::user()->all_accounts())->pluck('id');
$users = $x->transform(function($item) { return $item->user;});
$account_ids = ($x=Auth::user()->accounts)->pluck('id');
$user_ids = $x->transform(function($item) { return $item->user;})->pluck('id');
# Look for User
foreach (User::Search($request->input('term'))
->whereIN('id',$users->pluck('id'))
->whereIN('id',$user_ids)
->orderBy('lastname')
->orderBy('firstname')
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s %s',$o->aid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
$result->push(['name'=>sprintf('%s %s',$o->sid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
}
# Look for Account
foreach (Account::Search($request->input('term'))
->whereIN('user_id',$users->pluck('id'))
->whereIN('user_id',$user_ids)
->orderBy('company')
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s %s',$o->aid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
$result->push(['name'=>sprintf('%s %s',$o->sid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
}
# Look for a Service
foreach (Service::Search($request->input('term'))
->whereIN('account_id',$accounts)
->whereIN('account_id',$account_ids)
->orderBy('id')
->limit(10)->get() as $o)
{
@@ -58,7 +58,7 @@ class SearchController extends Controller
# Look for an Invoice
foreach (Invoice::Search($request->input('term'))
->whereIN('account_id',$accounts)
->whereIN('account_id',$account_ids)
->orderBy('id')
->limit(10)->get() as $o)
{
@@ -67,7 +67,7 @@ class SearchController extends Controller
# Look for an Broadband Service
foreach (Broadband::Search($request->input('term'))
->whereIN('account_id',$accounts)
->whereIN('account_id',$account_ids)
->orderBy('service_number')
->limit(10)->get() as $o)
{
@@ -76,7 +76,7 @@ class SearchController extends Controller
# Look for an Phone Service
foreach (Phone::Search($request->input('term'))
->whereIN('account_id',$accounts)
->whereIN('account_id',$account_ids)
->orderBy('service_number')
->limit(10)->get() as $o)
{
@@ -85,7 +85,7 @@ class SearchController extends Controller
# Look for Domain Name
foreach (Service\Domain::Search($request->input('term'))
->whereIN('account_id',$accounts)
->whereIN('account_id',$account_ids)
->orderBy('domain_name')
->limit(10)->get() as $o)
{
@@ -95,7 +95,7 @@ class SearchController extends Controller
if (Gate::any(['wholesaler'],new Payment)) {
# Look for Payments
foreach (Payment::Search($request->input('term'))
->whereIN('account_id',$accounts)
->whereIN('account_id',$account_ids)
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s ($%s)',$o->id,number_format($o->total,2)),'value'=>'/a/payment/addedit/'.$o->id,'category'=>'Payments']);