Improved search performance
This commit is contained in:
parent
8777024cd8
commit
606f357839
@ -32,6 +32,8 @@ class HomeController extends Controller
|
||||
if (! $o->exists)
|
||||
$o = Auth::user();
|
||||
|
||||
$o->load(['services.invoice_items','services.type']);
|
||||
|
||||
return View('u.home',['o'=>$o]);
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,9 @@ class SearchController extends Controller
|
||||
foreach (Service::Search($request->input('term'))
|
||||
->whereIN('account_id',$account_ids)
|
||||
->orderBy('id')
|
||||
->limit(10)->get() as $o)
|
||||
->limit(20)->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->name,$o->lid),'value'=>'/u/service/'.$o->id,'category'=>'Services']);
|
||||
$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
|
||||
@ -65,36 +65,6 @@ class SearchController extends Controller
|
||||
$result->push(['name'=>sprintf('%s: %s',$o->lid,$o->account->name),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']);
|
||||
}
|
||||
|
||||
# Look for a Broadband Service
|
||||
foreach (Broadband::Search($request->input('term'))
|
||||
->whereIN('account_id',$account_ids)
|
||||
->orderBy('service_number')
|
||||
->with(['service'])
|
||||
->limit(10)->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Broadband']);
|
||||
}
|
||||
|
||||
# Look for a Phone Service
|
||||
foreach (Phone::Search($request->input('term'))
|
||||
->whereIN('account_id',$account_ids)
|
||||
->orderBy('service_number')
|
||||
->with(['service'])
|
||||
->limit(10)->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Phone']);
|
||||
}
|
||||
|
||||
# Look for Domain Name
|
||||
foreach (Service\Domain::Search($request->input('term'))
|
||||
->whereIN('account_id',$account_ids)
|
||||
->orderBy('domain_name')
|
||||
->with(['service'])
|
||||
->limit(10)->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Domains']);
|
||||
}
|
||||
|
||||
if (Gate::any(['wholesaler'],new Payment)) {
|
||||
# Look for Payments
|
||||
foreach (Payment::Search($request->input('term'))
|
||||
@ -105,6 +75,6 @@ class SearchController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $result->sortBy(function($item) { return $item['category'].$item['name']; })->values();
|
||||
}
|
||||
}
|
@ -88,9 +88,9 @@ class Service extends Model implements IDs
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'invoice_items',
|
||||
'product.type.supplied',
|
||||
'type',
|
||||
//'invoice_items',
|
||||
//'product.type.supplied',
|
||||
//'type',
|
||||
];
|
||||
|
||||
public const INACTIVE_STATUS = [
|
||||
@ -455,7 +455,23 @@ class Service extends Model implements IDs
|
||||
*/
|
||||
public function scopeSearch($query,string $term)
|
||||
{
|
||||
return $query->where('id','like','%'.$term.'%');
|
||||
$t = '%'.$term.'%';
|
||||
|
||||
return $query->select('services.*')
|
||||
->where('services.id','like',$t)
|
||||
->leftJoin('service_broadband',['service_broadband.service_id'=>'services.id'])
|
||||
->orWhere('service_broadband.service_number','like',$t)
|
||||
->orWhere('service_broadband.service_address','like',$t)
|
||||
->orWhere('service_broadband.ipaddress','like',$t)
|
||||
->leftJoin('service_phone',['service_phone.service_id'=>'services.id'])
|
||||
->orWhere('service_phone.service_number','like',$t)
|
||||
->orWhere('service_phone.service_address','like',$t)
|
||||
->leftJoin('service_domain',['service_domain.service_id'=>'services.id'])
|
||||
->orWhere('service_domain.domain_name','like',$t)
|
||||
->leftJoin('service_email',['service_email.service_id'=>'services.id'])
|
||||
->orWhere('service_email.domain_name','like',$t)
|
||||
->leftJoin('service_host',['service_host.service_id'=>'services.id'])
|
||||
->orWhere('service_host.domain_name','like',$t);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
@ -25,24 +25,6 @@ class Broadband extends Type implements ServiceUsage
|
||||
];
|
||||
protected $table = 'service_broadband';
|
||||
|
||||
/* ABSTRACT */
|
||||
|
||||
/**
|
||||
* Search for a record
|
||||
*
|
||||
* @param $query
|
||||
* @param string $term
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeSearch($query,string $term)
|
||||
{
|
||||
// Build our where clause
|
||||
return parent::scopeSearch($query,$term)
|
||||
->orwhere('service_number','like','%'.$term.'%')
|
||||
->orWhere('service_address','like','%'.$term.'%')
|
||||
->orWhere('ipaddress','like','%'.$term.'%');
|
||||
}
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,7 @@ namespace App\Models\Service;
|
||||
// @todo Document how this is used.
|
||||
class Generic extends Type
|
||||
{
|
||||
protected $table = 'service__generic';
|
||||
protected $table = 'service_generic';
|
||||
public $timestamps = FALSE;
|
||||
|
||||
/* INTERFACE */
|
||||
|
@ -14,23 +14,6 @@ class Phone extends Type
|
||||
];
|
||||
protected $table = 'service_phone';
|
||||
|
||||
/* ABSTRACT */
|
||||
|
||||
/**
|
||||
* Search for a record
|
||||
*
|
||||
* @param $query
|
||||
* @param string $term
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeSearch($query,string $term)
|
||||
{
|
||||
// Build our where clause
|
||||
return parent::scopeSearch($query,$term)
|
||||
->orwhere('service_number','like','%'.$term.'%')
|
||||
->orWhere('service_address','like','%'.$term.'%');
|
||||
}
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
/**
|
||||
|
@ -33,20 +33,6 @@ class SSL extends Type
|
||||
});
|
||||
}
|
||||
|
||||
/* ABSTRACT */
|
||||
|
||||
/**
|
||||
* Search for a record
|
||||
*
|
||||
* @param $query
|
||||
* @param string $term
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeSearch($query,string $term)
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
/**
|
||||
|
@ -39,23 +39,6 @@ abstract class Type extends Model implements ServiceItem
|
||||
return $this->morphOne(Service::class,'type','model','id','service_id');
|
||||
}
|
||||
|
||||
/* SCOPES */
|
||||
|
||||
/**
|
||||
* Search for a record
|
||||
*
|
||||
* @param $query
|
||||
* @param string $term
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeSearch($query,string $term)
|
||||
{
|
||||
return $query
|
||||
->with(['service'])
|
||||
->join('services','services.id','=',$this->getTable().'.service_id')
|
||||
->Where('services.id','like','%'.$term.'%');
|
||||
}
|
||||
|
||||
/* INTERFACE */
|
||||
|
||||
public function getContractTermAttribute(): int
|
||||
|
@ -303,6 +303,7 @@ class User extends Authenticatable implements IDs
|
||||
public function next_invoice_items(bool $future=FALSE): DatabaseCollection
|
||||
{
|
||||
$result = new DatabaseCollection;
|
||||
$this->services->load(['invoice_items.taxes']);
|
||||
|
||||
foreach ($this->services as $o) {
|
||||
if ($future) {
|
||||
|
Loading…
Reference in New Issue
Block a user