2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
|
2017-01-10 16:19:18 -08:00
|
|
|
use App\Models\Actionlog;
|
2016-03-25 01:18:05 -07:00
|
|
|
use App\Models\Company;
|
2017-01-10 16:19:18 -08:00
|
|
|
use App\Models\LicenseSeat;
|
2016-09-06 19:39:42 -07:00
|
|
|
use App\Models\Loggable;
|
2016-12-23 17:52:00 -08:00
|
|
|
use App\Presenters\Presentable;
|
2017-01-10 16:19:18 -08:00
|
|
|
use Carbon\Carbon;
|
2016-03-25 01:18:05 -07:00
|
|
|
use DB;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2017-01-10 16:19:18 -08:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
2016-09-06 19:39:42 -07:00
|
|
|
use Watson\Validating\ValidatingTrait;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
class License extends Depreciable
|
|
|
|
{
|
2016-12-23 17:52:00 -08:00
|
|
|
protected $presenter = 'App\Presenters\LicensePresenter';
|
2018-05-08 00:14:38 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set static properties to determine which checkout/checkin handlers we should use
|
|
|
|
*/
|
|
|
|
public static $checkoutClass = CheckoutLicenseNotification::class;
|
|
|
|
public static $checkinClass = CheckinLicenseNotification::class;
|
|
|
|
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
use SoftDeletes;
|
|
|
|
use CompanyableTrait;
|
2016-12-23 17:52:00 -08:00
|
|
|
use Loggable, Presentable;
|
2016-03-25 01:18:05 -07:00
|
|
|
protected $injectUniqueIdentifier = true;
|
|
|
|
use ValidatingTrait;
|
|
|
|
|
2017-11-09 13:27:58 -08:00
|
|
|
// We set these as protected dates so that they will be easily accessible via Carbon
|
|
|
|
protected $dates = [
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
'deleted_at',
|
|
|
|
'purchase_date'
|
|
|
|
];
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
public $timestamps = true;
|
|
|
|
|
|
|
|
protected $guarded = 'id';
|
|
|
|
protected $table = 'licenses';
|
|
|
|
protected $rules = array(
|
|
|
|
'name' => 'required|string|min:3|max:255',
|
2016-12-14 11:12:21 -08:00
|
|
|
'seats' => 'required|min:1|max:1000000|integer',
|
2017-09-27 22:11:20 -07:00
|
|
|
'license_email' => 'email|nullable|max:120',
|
|
|
|
'license_name' => 'string|nullable|max:100',
|
|
|
|
'notes' => 'string|nullable',
|
2018-05-04 21:01:38 -07:00
|
|
|
'category_id' => 'integer',
|
2016-12-14 11:12:21 -08:00
|
|
|
'company_id' => 'integer|nullable',
|
2016-03-25 01:18:05 -07:00
|
|
|
);
|
|
|
|
|
2017-01-10 16:19:18 -08:00
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2018-02-25 12:10:02 -08:00
|
|
|
'company_id',
|
|
|
|
'depreciation_id',
|
|
|
|
'expiration_date',
|
|
|
|
'license_email',
|
|
|
|
'license_name', //actually licensed_to
|
|
|
|
'maintained',
|
|
|
|
'manufacturer_id',
|
2018-05-04 21:01:38 -07:00
|
|
|
'category_id',
|
2017-01-10 16:19:18 -08:00
|
|
|
'name',
|
2018-02-25 12:10:02 -08:00
|
|
|
'notes',
|
2017-01-10 16:19:18 -08:00
|
|
|
'order_number',
|
2018-02-25 12:10:02 -08:00
|
|
|
'purchase_cost',
|
|
|
|
'purchase_date',
|
|
|
|
'purchase_order',
|
|
|
|
'reassignable',
|
2017-01-10 16:19:18 -08:00
|
|
|
'seats',
|
2018-02-25 12:10:02 -08:00
|
|
|
'serial',
|
2017-01-10 16:19:18 -08:00
|
|
|
'supplier_id',
|
|
|
|
'termination_date',
|
2018-02-25 12:10:02 -08:00
|
|
|
'user_id',
|
2017-01-10 16:19:18 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
public static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
// We need to listen for created for the initial setup so that we have a license ID.
|
|
|
|
static::created(function ($license) {
|
|
|
|
$newSeatCount = $license->getAttributes()['seats'];
|
|
|
|
return static::adjustSeatCount($license, $oldSeatCount = 0, $newSeatCount);
|
|
|
|
});
|
|
|
|
// However, we listen for updating to be able to prevent the edit if we cannot delete enough seats.
|
|
|
|
static::updating(function ($license) {
|
|
|
|
$newSeatCount = $license->getAttributes()['seats'];
|
|
|
|
$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;
|
|
|
|
return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function adjustSeatCount($license, $oldSeats, $newSeats)
|
|
|
|
{
|
|
|
|
// If the seats haven't changed, continue on happily.
|
|
|
|
if ($oldSeats==$newSeats) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// On Create, we just make one for each of the seats.
|
|
|
|
$change = abs($oldSeats - $newSeats);
|
|
|
|
if ($oldSeats > $newSeats) {
|
|
|
|
$license->load('licenseseats.user');
|
2018-05-04 21:01:38 -07:00
|
|
|
|
2017-01-10 16:19:18 -08:00
|
|
|
// Need to delete seats... lets see if if we have enough.
|
|
|
|
$seatsAvailableForDelete = $license->licenseseats->reject(function ($seat) {
|
|
|
|
return (!! $seat->assigned_to) || (!! $seat->asset_id);
|
|
|
|
});
|
|
|
|
|
|
|
|
if ($change > $seatsAvailableForDelete->count()) {
|
|
|
|
Session::flash('error', trans('admin/licenses/message.assoc_users'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for ($i=1; $i <= $change; $i++) {
|
|
|
|
$seatsAvailableForDelete->pop()->delete();
|
|
|
|
}
|
|
|
|
// Log Deletion of seats.
|
|
|
|
$logAction = new Actionlog;
|
|
|
|
$logAction->item_type = License::class;
|
|
|
|
$logAction->item_id = $license->id;
|
|
|
|
$logAction->user_id = Auth::id() ?: 1; // We don't have an id while running the importer from CLI.
|
|
|
|
$logAction->note = "deleted ${change} seats";
|
|
|
|
$logAction->target_id = null;
|
|
|
|
$logAction->logaction('delete seats');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Else we're adding seats.
|
|
|
|
DB::transaction(function () use ($license, $oldSeats, $newSeats) {
|
|
|
|
for ($i = $oldSeats; $i < $newSeats; $i++) {
|
|
|
|
$license->licenseSeatsRelation()->save(new LicenseSeat, ['user_id' => Auth::id()]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// On initail create, we shouldn't log the addition of seats.
|
|
|
|
if ($license->id) {
|
|
|
|
//Log the addition of license to the log.
|
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = License::class;
|
|
|
|
$logAction->item_id = $license->id;
|
|
|
|
$logAction->user_id = Auth::id() ?: 1; // Importer.
|
|
|
|
$logAction->note = "added ${change} seats";
|
|
|
|
$logAction->target_id = null;
|
|
|
|
$logAction->logaction('add seats');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMaintainedAttribute($value)
|
|
|
|
{
|
|
|
|
$this->attributes['maintained'] = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
|
|
|
}
|
|
|
|
public function setReassignableAttribute($value)
|
|
|
|
{
|
|
|
|
$this->attributes['reassignable'] = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
|
|
|
}
|
|
|
|
|
2016-12-26 15:17:46 -08:00
|
|
|
public function setExpirationDateAttribute($value)
|
|
|
|
{
|
2017-01-10 16:19:18 -08:00
|
|
|
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($value == '' || $value == '0000-00-00') {
|
2016-12-26 15:17:46 -08:00
|
|
|
$value = null;
|
2017-01-10 16:19:18 -08:00
|
|
|
} else {
|
|
|
|
$value = (new Carbon($value))->toDateString();
|
2016-12-26 15:17:46 -08:00
|
|
|
}
|
|
|
|
$this->attributes['expiration_date'] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTerminationDateAttribute($value)
|
|
|
|
{
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($value == '' || $value == '0000-00-00') {
|
2016-12-26 15:17:46 -08:00
|
|
|
$value = null;
|
2017-01-10 16:19:18 -08:00
|
|
|
} else {
|
|
|
|
$value = (new Carbon($value))->toDateString();
|
2016-12-26 15:17:46 -08:00
|
|
|
}
|
|
|
|
$this->attributes['termination_date'] = $value;
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\Company', 'company_id');
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:01:38 -07:00
|
|
|
public function category()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\Category', 'category_id');
|
|
|
|
}
|
|
|
|
|
2016-08-16 18:49:54 -07:00
|
|
|
public function manufacturer()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\Manufacturer', 'manufacturer_id');
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:01:38 -07:00
|
|
|
public function checkin_email()
|
|
|
|
{
|
|
|
|
return $this->model->category->checkin_email;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requireAcceptance()
|
|
|
|
{
|
|
|
|
return $this->category->require_acceptance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEula()
|
|
|
|
{
|
|
|
|
$Parsedown = new \Parsedown();
|
|
|
|
|
|
|
|
if ($this->category->eula_text) {
|
|
|
|
return $Parsedown->text(e($this->category->eula_text));
|
|
|
|
} elseif ($this->category->use_default_eula == '1') {
|
|
|
|
return $Parsedown->text(e(Setting::getSettings()->default_eula_text));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
|
|
|
* Get the assigned user
|
|
|
|
*/
|
|
|
|
public function assignedusers()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('\App\Models\User', 'license_seats', 'assigned_to', 'license_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get asset logs for this asset
|
|
|
|
*/
|
|
|
|
public function assetlog()
|
|
|
|
{
|
2016-09-06 19:39:42 -07:00
|
|
|
return $this->hasMany('\App\Models\Actionlog', 'item_id')
|
|
|
|
->where('item_type', '=', License::class)
|
2016-03-25 01:18:05 -07:00
|
|
|
->orderBy('created_at', 'desc');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get uploads for this asset
|
|
|
|
*/
|
|
|
|
public function uploads()
|
|
|
|
{
|
2016-09-06 19:39:42 -07:00
|
|
|
return $this->hasMany('\App\Models\Actionlog', 'item_id')
|
|
|
|
->where('item_type', '=', License::class)
|
2016-03-25 01:18:05 -07:00
|
|
|
->where('action_type', '=', 'uploaded')
|
|
|
|
->whereNotNull('filename')
|
|
|
|
->orderBy('created_at', 'desc');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get admin user for this asset
|
|
|
|
*/
|
|
|
|
public function adminuser()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\User', 'user_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get total licenses
|
|
|
|
*/
|
|
|
|
public static function assetcount()
|
|
|
|
{
|
|
|
|
return LicenseSeat::whereNull('deleted_at')
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get total licenses
|
|
|
|
*/
|
|
|
|
public function totalSeatsByLicenseID()
|
|
|
|
{
|
|
|
|
return LicenseSeat::where('license_id', '=', $this->id)
|
|
|
|
->whereNull('deleted_at')
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
2016-10-28 14:15:13 -07:00
|
|
|
// We do this to eager load the "count" of seats from the controller. Otherwise calling "count()" on each model results in n+1
|
|
|
|
public function licenseSeatsRelation()
|
|
|
|
{
|
|
|
|
return $this->hasMany(LicenseSeat::class)->whereNull('deleted_at')->selectRaw('license_id, count(*) as count')->groupBy('license_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLicenseSeatsCountAttribute()
|
|
|
|
{
|
|
|
|
if ($this->licenseSeatsRelation->first()) {
|
|
|
|
return $this->licenseSeatsRelation->first()->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get total licenses not checked out
|
|
|
|
*/
|
|
|
|
public static function availassetcount()
|
|
|
|
{
|
|
|
|
return LicenseSeat::whereNull('assigned_to')
|
|
|
|
->whereNull('asset_id')
|
|
|
|
->whereNull('deleted_at')
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of available seats
|
|
|
|
*/
|
2016-10-28 14:15:13 -07:00
|
|
|
public function availCount()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
return $this->licenseSeatsRelation()
|
2017-11-02 19:16:09 -07:00
|
|
|
->whereNull('asset_id')
|
|
|
|
->whereNull('assigned_to')
|
2017-11-02 21:07:59 -07:00
|
|
|
->whereNull('deleted_at');
|
2016-10-28 14:15:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAvailSeatsCountAttribute()
|
|
|
|
{
|
|
|
|
if ($this->availCount->first()) {
|
|
|
|
return $this->availCount->first()->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of assigned seats
|
|
|
|
*
|
|
|
|
*/
|
2016-10-28 14:15:13 -07:00
|
|
|
public function assignedCount()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
return $this->licenseSeatsRelation()->where(function ($query) {
|
|
|
|
$query->whereNotNull('assigned_to')
|
|
|
|
->orWhereNotNull('asset_id');
|
|
|
|
});
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-10-28 14:15:13 -07:00
|
|
|
public function getAssignedSeatsCountAttribute()
|
|
|
|
{
|
|
|
|
// dd($this->licenseSeatsRelation->first());
|
|
|
|
if ($this->assignedCount->first()) {
|
|
|
|
return $this->assignedCount->first()->count;
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-10-28 14:15:13 -07:00
|
|
|
return 0;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function remaincount()
|
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
$total = $this->licenseSeatsCount;
|
2016-11-17 15:54:29 -08:00
|
|
|
$taken = $this->assigned_seats_count;
|
2016-03-25 01:18:05 -07:00
|
|
|
$diff = ($total - $taken);
|
|
|
|
return $diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the total number of seats
|
|
|
|
*/
|
|
|
|
public function totalcount()
|
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
$avail = $this->availSeatsCount;
|
2016-03-25 01:18:05 -07:00
|
|
|
$taken = $this->assignedcount();
|
|
|
|
$diff = ($avail + $taken);
|
|
|
|
return $diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get license seat data
|
|
|
|
*/
|
|
|
|
public function licenseseats()
|
|
|
|
{
|
|
|
|
return $this->hasMany('\App\Models\LicenseSeat');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function supplier()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\Supplier', 'supplier_id');
|
|
|
|
}
|
|
|
|
|
2017-09-25 21:40:43 -07:00
|
|
|
/*
|
|
|
|
* Get the next available free seat - used by
|
|
|
|
* the API to populate next_seat
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function freeSeat()
|
|
|
|
{
|
2017-11-20 19:21:05 -08:00
|
|
|
return $this->licenseseats()
|
2016-03-25 01:18:05 -07:00
|
|
|
->whereNull('deleted_at')
|
2017-11-20 19:21:05 -08:00
|
|
|
->where(function ($query) {
|
|
|
|
$query->whereNull('assigned_to')
|
|
|
|
->whereNull('asset_id');
|
|
|
|
})
|
|
|
|
->orderBy('id', 'asc')
|
2016-03-25 01:18:05 -07:00
|
|
|
->first();
|
|
|
|
}
|
|
|
|
|
2017-11-02 19:16:09 -07:00
|
|
|
/*
|
|
|
|
* Get the next available free seat - used by
|
|
|
|
* the API to populate next_seat
|
|
|
|
*/
|
|
|
|
public function freeSeats()
|
|
|
|
{
|
|
|
|
return $this->hasMany('\App\Models\LicenseSeat')->whereNull('assigned_to')->whereNull('deleted_at')->whereNull('asset_id');
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function getExpiringLicenses($days = 60)
|
|
|
|
{
|
|
|
|
|
|
|
|
return License::whereNotNull('expiration_date')
|
|
|
|
->whereNull('deleted_at')
|
|
|
|
->whereRaw(DB::raw('DATE_SUB(`expiration_date`,INTERVAL '.$days.' DAY) <= DATE(NOW()) '))
|
|
|
|
->where('expiration_date', '>', date("Y-m-d"))
|
|
|
|
->orderBy('expiration_date', 'ASC')
|
|
|
|
->get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to search on text
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $search Search term
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeTextSearch($query, $search)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->where(function ($query) use ($search) {
|
|
|
|
|
2016-11-11 19:46:18 -08:00
|
|
|
$query->where('licenses.name', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('licenses.serial', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('licenses.notes', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('licenses.order_number', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('licenses.purchase_order', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('licenses.purchase_date', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('licenses.purchase_cost', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhereHas('manufacturer', function ($query) use ($search) {
|
|
|
|
$query->where(function ($query) use ($search) {
|
|
|
|
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
|
2016-12-29 14:02:18 -08:00
|
|
|
});
|
|
|
|
})
|
2016-11-11 19:46:18 -08:00
|
|
|
->orWhereHas('company', function ($query) use ($search) {
|
|
|
|
$query->where(function ($query) use ($search) {
|
|
|
|
$query->where('companies.name', 'LIKE', '%'.$search.'%');
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 01:18:05 -07:00
|
|
|
});
|
|
|
|
}
|
2016-11-11 19:46:18 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to order on manufacturer
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeOrderManufacturer($query, $order)
|
|
|
|
{
|
|
|
|
return $query->leftJoin('manufacturers', 'licenses.manufacturer_id', '=', 'manufacturers.id')->select('licenses.*')
|
|
|
|
->orderBy('manufacturers.name', $order);
|
|
|
|
}
|
|
|
|
|
2017-08-10 14:38:04 -07:00
|
|
|
/**
|
|
|
|
* Query builder scope to order on supplier
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeOrderSupplier($query, $order)
|
|
|
|
{
|
|
|
|
return $query->leftJoin('suppliers', 'licenses.supplier_id', '=', 'suppliers.id')->select('licenses.*')
|
|
|
|
->orderBy('suppliers.name', $order);
|
|
|
|
}
|
|
|
|
|
2016-11-11 19:46:18 -08:00
|
|
|
/**
|
|
|
|
* Query builder scope to order on company
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeOrderCompany($query, $order)
|
|
|
|
{
|
|
|
|
return $query->leftJoin('companies as companies', 'licenses.company_id', '=', 'companies.id')->select('licenses.*')
|
|
|
|
->orderBy('companies.name', $order);
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|