2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
use App\Http\Traits\UniqueUndeletedTrait;
|
2016-12-23 17:52:00 -08:00
|
|
|
use App\Presenters\Presentable;
|
|
|
|
use AssetPresenter;
|
2016-09-06 19:39:42 -07:00
|
|
|
use Auth;
|
2016-12-23 17:52:00 -08:00
|
|
|
use Carbon\Carbon;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Config;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Log;
|
|
|
|
use Watson\Validating\ValidatingTrait;
|
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* Model for Assets.
|
|
|
|
*
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class Asset extends Depreciable
|
|
|
|
{
|
2016-12-23 17:52:00 -08:00
|
|
|
protected $presenter = 'App\Presenters\AssetPresenter';
|
|
|
|
use Loggable, Requestable, Presentable;
|
2016-03-25 01:18:05 -07:00
|
|
|
use SoftDeletes;
|
|
|
|
|
2016-12-27 16:24:41 -08:00
|
|
|
const LOCATION = 'location';
|
|
|
|
const ASSET = 'asset';
|
|
|
|
const USER = 'user';
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
|
|
|
* The database table used by the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'assets';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the model should inject it's identifier to the unique
|
|
|
|
* validation rules before attempting validation. If this property
|
|
|
|
* is not set in the model it will default to true.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $injectUniqueIdentifier = true;
|
2016-12-23 17:52:00 -08:00
|
|
|
use ValidatingTrait, UniqueUndeletedTrait;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
protected $rules = [
|
2017-01-12 02:19:36 -08:00
|
|
|
'name' => 'max:255|nullable',
|
2016-03-25 01:18:05 -07:00
|
|
|
'model_id' => 'required|integer',
|
|
|
|
'status_id' => 'required|integer',
|
2016-12-14 09:58:12 -08:00
|
|
|
'company_id' => 'integer|nullable',
|
2016-12-15 15:15:26 -08:00
|
|
|
'warranty_months' => 'numeric|nullable',
|
2016-12-14 09:55:45 -08:00
|
|
|
'physical' => 'numeric|max:1|nullable',
|
2016-12-14 09:58:12 -08:00
|
|
|
'checkout_date' => 'date|max:10|min:10|nullable',
|
|
|
|
'checkin_date' => 'date|max:10|min:10|nullable',
|
2016-12-14 09:55:45 -08:00
|
|
|
'supplier_id' => 'numeric|nullable',
|
2016-07-26 01:39:30 -07:00
|
|
|
'asset_tag' => 'required|min:1|max:255|unique_undeleted',
|
2016-03-25 01:18:05 -07:00
|
|
|
'status' => 'integer',
|
2016-12-14 09:55:45 -08:00
|
|
|
'purchase_cost' => 'numeric|nullable',
|
2016-03-25 01:18:05 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-01-10 16:19:18 -08:00
|
|
|
protected $fillable = [
|
|
|
|
'asset_tag',
|
|
|
|
'assigned_to',
|
|
|
|
'company_id',
|
|
|
|
'image',
|
|
|
|
'model_id',
|
|
|
|
'name',
|
|
|
|
'notes',
|
|
|
|
'purchase_cost',
|
|
|
|
'purchase_date',
|
|
|
|
'rtd_location_id',
|
|
|
|
'serial',
|
|
|
|
'status_id',
|
|
|
|
'supplier_id',
|
|
|
|
'warranty_months',
|
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
public function getDisplayNameAttribute()
|
|
|
|
{
|
|
|
|
return $this->present()->name();
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\Company', 'company_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-16 13:02:42 -07:00
|
|
|
public function availableForCheckout()
|
|
|
|
{
|
2016-12-29 14:02:18 -08:00
|
|
|
return (
|
2016-08-16 13:02:42 -07:00
|
|
|
empty($this->assigned_to) &&
|
|
|
|
$this->assetstatus->deployable == 1 &&
|
|
|
|
empty($this->deleted_at)
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 01:39:30 -07:00
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
/**
|
|
|
|
* Checkout asset
|
|
|
|
* @param User $user
|
|
|
|
* @param User $admin
|
|
|
|
* @param Carbon $checkout_at
|
|
|
|
* @param null $expected_checkin
|
|
|
|
* @param string $note
|
|
|
|
* @param null $name
|
|
|
|
* @return bool
|
|
|
|
*/
|
2016-12-27 16:24:41 -08:00
|
|
|
public function checkOut($target, $admin, $checkout_at = null, $expected_checkin = null, $note = null, $name = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-27 16:24:41 -08:00
|
|
|
if (!$target) {
|
2016-08-16 13:02:42 -07:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if ($expected_checkin) {
|
2016-08-16 13:02:42 -07:00
|
|
|
$this->expected_checkin = $expected_checkin;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->last_checkout = $checkout_at;
|
|
|
|
|
2016-12-27 16:24:41 -08:00
|
|
|
$this->assignedTo()->associate($target);
|
|
|
|
|
2016-08-16 18:23:20 -07:00
|
|
|
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($name != null) {
|
2016-08-16 18:23:20 -07:00
|
|
|
$this->name = $name;
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if ($this->requireAcceptance()) {
|
|
|
|
$this->accepted="pending";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->save()) {
|
2016-12-27 12:03:47 -08:00
|
|
|
$log = $this->logCheckout($note);
|
2016-12-27 19:04:11 -08:00
|
|
|
// if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
|
|
|
|
// $this->checkOutNotifyMail($log->id, $user, $checkout_at, $expected_checkin, $note);
|
|
|
|
// }
|
2016-03-25 01:18:05 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note)
|
|
|
|
{
|
|
|
|
$data['log_id'] = $log_id;
|
|
|
|
$data['eula'] = $this->getEula();
|
|
|
|
$data['first_name'] = $user->first_name;
|
2016-12-23 17:52:00 -08:00
|
|
|
$data['item_name'] = $this->present()->name();
|
2016-03-25 01:18:05 -07:00
|
|
|
$data['checkout_date'] = $checkout_at;
|
|
|
|
$data['expected_checkin'] = $expected_checkin;
|
|
|
|
$data['item_tag'] = $this->asset_tag;
|
|
|
|
$data['note'] = $note;
|
|
|
|
$data['item_serial'] = $this->serial;
|
|
|
|
$data['require_acceptance'] = $this->requireAcceptance();
|
|
|
|
|
|
|
|
if ((($this->requireAcceptance()=='1') || ($this->getEula())) && (!config('app.lock_passwords'))) {
|
|
|
|
|
|
|
|
\Mail::send('emails.accept-asset', $data, function ($m) use ($user) {
|
|
|
|
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
|
2016-09-20 07:20:10 -07:00
|
|
|
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
|
2016-09-26 14:13:07 -07:00
|
|
|
$m->subject(trans('mail.Confirm_asset_delivery'));
|
2016-03-25 01:18:05 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-22 12:27:41 -07:00
|
|
|
public function getDetailedNameAttribute()
|
|
|
|
{
|
2016-12-29 06:31:16 -08:00
|
|
|
if ($this->assignedTo) {
|
|
|
|
$user_name = $this->assignedTo->present()->name();
|
2016-06-22 12:27:41 -07:00
|
|
|
} else {
|
|
|
|
$user_name = "Unassigned";
|
|
|
|
}
|
|
|
|
return $this->asset_tag . ' - ' . $this->name . ' (' . $user_name . ') ' . $this->model->name;
|
2016-05-24 18:05:48 -07:00
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
public function validationRules($id = '0')
|
|
|
|
{
|
|
|
|
return $this->rules;
|
|
|
|
}
|
|
|
|
|
2016-04-23 02:07:40 -07:00
|
|
|
|
2016-05-18 19:26:50 -07:00
|
|
|
/**
|
2016-03-25 01:18:05 -07:00
|
|
|
* Set depreciation relationship
|
|
|
|
*/
|
|
|
|
public function depreciation()
|
|
|
|
{
|
|
|
|
return $this->model->belongsTo('\App\Models\Depreciation', 'depreciation_id');
|
|
|
|
}
|
|
|
|
|
2016-05-18 19:26:50 -07:00
|
|
|
/**
|
|
|
|
* Get components assigned to this asset
|
|
|
|
*/
|
|
|
|
public function components()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('\App\Models\Component', 'components_assets', 'asset_id', 'component_id')->withPivot('id')->withTrashed();
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
|
|
|
* Get depreciation attribute from associated asset model
|
|
|
|
*/
|
|
|
|
public function get_depreciation()
|
|
|
|
{
|
|
|
|
return $this->model->depreciation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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', '=', Asset::class)
|
2016-03-25 01:18:05 -07:00
|
|
|
->where('action_type', '=', 'uploaded')
|
|
|
|
->whereNotNull('filename')
|
|
|
|
->orderBy('created_at', 'desc');
|
|
|
|
}
|
|
|
|
|
2016-12-29 06:31:16 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Even though we allow allow for checkout to things beyond users
|
|
|
|
* this method is an easy way of seeing if we are checked out to a user.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function assigneduser()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\User', 'assigned_to')
|
|
|
|
->withTrashed();
|
|
|
|
}
|
|
|
|
|
2016-12-27 16:24:41 -08:00
|
|
|
public function assignedTo()
|
|
|
|
{
|
|
|
|
return $this->morphTo('assigned', 'assigned_type', 'assigned_to');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function assignedAssets()
|
|
|
|
{
|
|
|
|
return $this->morphMany('App\Models\Asset', 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
|
|
|
* Get the asset's location based on the assigned user
|
|
|
|
**/
|
2016-12-27 16:24:41 -08:00
|
|
|
public function assetLoc()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-27 16:24:41 -08:00
|
|
|
if(!empty($this->assignedType())) {
|
|
|
|
if ($this->assignedType() == self::ASSET) {
|
|
|
|
return $this->assignedTo->assetloc(); // Recurse until we have a final location
|
|
|
|
} elseif ($this->assignedType() == self::LOCATION) {
|
|
|
|
return $this->assignedTo();
|
|
|
|
}
|
2016-12-29 22:23:36 -08:00
|
|
|
if($this->assignedTo) {
|
|
|
|
return $this->assignedTo->userLoc();
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-27 16:24:41 -08:00
|
|
|
return $this->defaultLoc();
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-27 16:24:41 -08:00
|
|
|
public function assignedType()
|
|
|
|
{
|
|
|
|
return strtolower(class_basename($this->assigned_type));
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
|
|
|
* Get the asset's location based on default RTD location
|
|
|
|
**/
|
|
|
|
public function defaultLoc()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\Location', 'rtd_location_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get action 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', '=', Asset::class)
|
2016-03-25 01:18:05 -07:00
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assetmaintenances
|
|
|
|
* Get improvements for this asset
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
public function assetmaintenances()
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->hasMany('\App\Models\AssetMaintenance', 'asset_id')
|
2016-12-01 00:55:00 -08:00
|
|
|
->orderBy('created_at', 'desc');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get action logs for this asset
|
|
|
|
*/
|
|
|
|
public function adminuser()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\User', 'user_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get total assets
|
|
|
|
*/
|
|
|
|
public static function assetcount()
|
|
|
|
{
|
|
|
|
|
2016-07-25 19:46:29 -07:00
|
|
|
return Company::scopeCompanyables(Asset::where('physical', '=', '1'))
|
2016-03-25 01:18:05 -07:00
|
|
|
->whereNull('deleted_at', 'and')
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get total assets not checked out
|
|
|
|
*/
|
|
|
|
public static function availassetcount()
|
|
|
|
{
|
|
|
|
return Asset::RTD()
|
|
|
|
->whereNull('deleted_at')
|
|
|
|
->count();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get requestable assets
|
|
|
|
*/
|
|
|
|
public static function getRequestable()
|
|
|
|
{
|
|
|
|
|
|
|
|
return Asset::Requestable()
|
|
|
|
->whereNull('deleted_at')
|
|
|
|
->count();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-24 16:06:15 -07:00
|
|
|
* Get asset status
|
2016-03-25 01:18:05 -07:00
|
|
|
*/
|
|
|
|
public function assetstatus()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\Statuslabel', 'status_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\AssetModel', 'model_id')->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getExpiringWarrantee($days = 30)
|
|
|
|
{
|
|
|
|
|
|
|
|
return Asset::where('archived', '=', '0')
|
|
|
|
->whereNotNull('warranty_months')
|
|
|
|
->whereNotNull('purchase_date')
|
|
|
|
->whereNull('deleted_at')
|
|
|
|
->whereRaw(\DB::raw('DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) <= DATE(NOW() + INTERVAL '
|
|
|
|
. $days
|
|
|
|
. ' DAY) AND DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) > NOW()'))
|
|
|
|
->orderBy('purchase_date', 'ASC')
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the license seat information
|
|
|
|
**/
|
|
|
|
public function licenses()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('\App\Models\License', 'license_seats', 'asset_id', 'license_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function licenseseats()
|
|
|
|
{
|
|
|
|
return $this->hasMany('\App\Models\LicenseSeat', 'asset_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function supplier()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\Supplier', 'supplier_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get auto-increment
|
|
|
|
*/
|
|
|
|
public static function autoincrement_asset()
|
|
|
|
{
|
|
|
|
|
|
|
|
$settings = \App\Models\Setting::getSettings();
|
|
|
|
|
|
|
|
if ($settings->auto_increment_assets == '1') {
|
2017-01-06 02:54:06 -08:00
|
|
|
$temp_asset_tag = \DB::table('assets')
|
2016-03-25 01:18:05 -07:00
|
|
|
->where('physical', '=', '1')
|
2017-01-06 02:54:06 -08:00
|
|
|
->max('asset_tag');
|
|
|
|
|
2017-01-06 03:14:32 -08:00
|
|
|
$asset_tag_digits = preg_replace('/\D/', '', $temp_asset_tag);
|
|
|
|
$asset_tag = preg_replace('/^0*/', '', $asset_tag_digits);
|
2016-07-27 21:28:00 -07:00
|
|
|
|
|
|
|
if ($settings->zerofill_count > 0) {
|
2016-12-29 14:02:18 -08:00
|
|
|
return $settings->auto_increment_prefix.Asset::zerofill(($asset_tag + 1), $settings->zerofill_count);
|
2016-07-27 21:28:00 -07:00
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
return $settings->auto_increment_prefix.($asset_tag + 1);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 21:28:00 -07:00
|
|
|
|
2016-12-29 14:02:18 -08:00
|
|
|
public static function zerofill($num, $zerofill = 3)
|
2016-07-27 21:28:00 -07:00
|
|
|
{
|
|
|
|
return str_pad($num, $zerofill, '0', STR_PAD_LEFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
public function checkin_email()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
return $this->model->category->checkin_email;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requireAcceptance()
|
|
|
|
{
|
|
|
|
return $this->model->category->require_acceptance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEula()
|
|
|
|
{
|
|
|
|
|
|
|
|
$Parsedown = new \Parsedown();
|
|
|
|
|
|
|
|
if ($this->model->category->eula_text) {
|
|
|
|
return $Parsedown->text(e($this->model->category->eula_text));
|
|
|
|
} elseif ($this->model->category->use_default_eula == '1') {
|
|
|
|
return $Parsedown->text(e(Setting::getSettings()->default_eula_text));
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* -----------------------------------------------
|
|
|
|
* BEGIN QUERY SCOPES
|
|
|
|
* -----------------------------------------------
|
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope for hardware
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopeHardware($query)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->where('physical', '=', '1');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope for pending assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopePending($query)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->whereHas('assetstatus', function ($query) {
|
|
|
|
|
|
|
|
$query->where('deployable', '=', 0)
|
|
|
|
->where('pending', '=', 1)
|
|
|
|
->where('archived', '=', 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-19 20:23:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope for pending assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopeAssetsByLocation($query, $location)
|
|
|
|
{
|
2016-06-22 12:27:41 -07:00
|
|
|
return $query->where(function ($query) use ($location) {
|
2016-09-20 07:20:10 -07:00
|
|
|
|
2016-06-22 12:27:41 -07:00
|
|
|
$query->whereHas('assigneduser', function ($query) use ($location) {
|
2016-09-20 07:20:10 -07:00
|
|
|
|
2016-04-19 20:23:04 -07:00
|
|
|
$query->where('users.location_id', '=', $location->id);
|
2016-06-22 12:27:41 -07:00
|
|
|
})->orWhere(function ($query) use ($location) {
|
2016-09-20 07:20:10 -07:00
|
|
|
|
2016-04-19 20:23:04 -07:00
|
|
|
$query->where('assets.rtd_location_id', '=', $location->id);
|
|
|
|
$query->whereNull('assets.assigned_to');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope for RTD assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
public function scopeRTD($query)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->whereNULL('assigned_to')
|
|
|
|
->whereHas('assetstatus', function ($query) {
|
|
|
|
|
|
|
|
$query->where('deployable', '=', 1)
|
|
|
|
->where('pending', '=', 0)
|
|
|
|
->where('archived', '=', 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope for Undeployable assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopeUndeployable($query)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->whereHas('assetstatus', function ($query) {
|
|
|
|
|
|
|
|
$query->where('deployable', '=', 0)
|
|
|
|
->where('pending', '=', 0)
|
|
|
|
->where('archived', '=', 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-01 13:28:15 -07:00
|
|
|
/**
|
|
|
|
* Query builder scope for non-Archived assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopeNotArchived($query)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->whereHas('assetstatus', function ($query) {
|
|
|
|
|
|
|
|
$query->where('archived', '=', 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
|
|
|
* Query builder scope for Archived assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopeArchived($query)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->whereHas('assetstatus', function ($query) {
|
|
|
|
|
|
|
|
$query->where('deployable', '=', 0)
|
|
|
|
->where('pending', '=', 0)
|
|
|
|
->where('archived', '=', 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope for Deployed assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopeDeployed($query)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->where('assigned_to', '>', '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope for Requestable assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopeRequestableAssets($query)
|
|
|
|
{
|
|
|
|
|
2016-07-26 16:22:56 -07:00
|
|
|
return Company::scopeCompanyables($query->where('requestable', '=', 1))
|
2016-04-19 20:23:04 -07:00
|
|
|
->whereHas('assetstatus', function ($query) {
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-06-22 12:27:41 -07:00
|
|
|
$query->where('deployable', '=', 1)
|
2016-04-19 20:23:04 -07:00
|
|
|
->where('pending', '=', 0)
|
|
|
|
->where('archived', '=', 0);
|
|
|
|
});
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope for Deleted assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function scopeDeleted($query)
|
|
|
|
{
|
|
|
|
return $query->whereNotNull('deleted_at');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scopeInModelList
|
|
|
|
* Get all assets in the provided listing of model ids
|
|
|
|
*
|
|
|
|
* @param $query
|
|
|
|
* @param array $modelIdListing
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
public function scopeInModelList($query, array $modelIdListing)
|
|
|
|
{
|
|
|
|
return $query->whereIn('model_id', $modelIdListing);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to get not-yet-accepted assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeNotYetAccepted($query)
|
|
|
|
{
|
|
|
|
return $query->where("accepted", "=", "pending");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to get rejected assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeRejected($query)
|
|
|
|
{
|
|
|
|
return $query->where("accepted", "=", "rejected");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to get accepted assets
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeAccepted($query)
|
|
|
|
{
|
2016-07-15 11:11:48 -07:00
|
|
|
return $query->where("accepted", "=", "accepted");
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to search on text for complex Bootstrap Tables API
|
|
|
|
*
|
|
|
|
* @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)
|
|
|
|
{
|
|
|
|
$search = explode(' OR ', $search);
|
|
|
|
|
|
|
|
return $query->where(function ($query) use ($search) {
|
|
|
|
|
|
|
|
foreach ($search as $search) {
|
|
|
|
$query->whereHas('model', function ($query) use ($search) {
|
|
|
|
$query->whereHas('category', function ($query) use ($search) {
|
|
|
|
$query->where(function ($query) use ($search) {
|
|
|
|
$query->where('categories.name', 'LIKE', '%'.$search.'%')
|
2016-06-27 22:32:40 -07:00
|
|
|
->orWhere('models.name', 'LIKE', '%'.$search.'%')
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
->orWhere('models.model_number', 'LIKE', '%'.$search.'%');
|
2016-03-25 01:18:05 -07:00
|
|
|
});
|
|
|
|
});
|
2016-05-12 10:38:57 -07:00
|
|
|
})->orWhereHas('model', function ($query) use ($search) {
|
|
|
|
$query->whereHas('manufacturer', function ($query) use ($search) {
|
|
|
|
$query->where(function ($query) use ($search) {
|
|
|
|
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 01:18:05 -07:00
|
|
|
})->orWhere(function ($query) use ($search) {
|
|
|
|
$query->whereHas('assetstatus', function ($query) use ($search) {
|
|
|
|
$query->where('status_labels.name', 'LIKE', '%'.$search.'%');
|
|
|
|
});
|
|
|
|
})->orWhere(function ($query) use ($search) {
|
|
|
|
$query->whereHas('company', function ($query) use ($search) {
|
|
|
|
$query->where('companies.name', 'LIKE', '%'.$search.'%');
|
|
|
|
});
|
|
|
|
})->orWhere(function ($query) use ($search) {
|
|
|
|
$query->whereHas('defaultLoc', function ($query) use ($search) {
|
|
|
|
$query->where('locations.name', 'LIKE', '%'.$search.'%');
|
|
|
|
});
|
|
|
|
})->orWhere(function ($query) use ($search) {
|
|
|
|
$query->whereHas('assigneduser', function ($query) use ($search) {
|
|
|
|
$query->where(function ($query) use ($search) {
|
|
|
|
$query->where('users.first_name', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('users.last_name', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere(function ($query) use ($search) {
|
|
|
|
$query->whereHas('userloc', function ($query) use ($search) {
|
|
|
|
$query->where('locations.name', 'LIKE', '%'.$search.'%');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})->orWhere('assets.name', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('assets.asset_tag', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('assets.serial', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('assets.order_number', 'LIKE', '%'.$search.'%')
|
|
|
|
->orWhere('assets.notes', 'LIKE', '%'.$search.'%');
|
|
|
|
}
|
|
|
|
foreach (CustomField::all() as $field) {
|
|
|
|
$query->orWhere($field->db_column_name(), 'LIKE', "%$search%");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to order on model
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeOrderModels($query, $order)
|
|
|
|
{
|
|
|
|
return $query->join('models', 'assets.model_id', '=', 'models.id')->orderBy('models.name', $order);
|
|
|
|
}
|
|
|
|
|
2016-06-27 22:32:40 -07:00
|
|
|
/**
|
|
|
|
* Query builder scope to order on model number
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeOrderModelNumber($query, $order)
|
|
|
|
{
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
return $query->join('models', 'assets.model_id', '=', 'models.id')->orderBy('models.model_number', $order);
|
2016-06-27 22:32:40 -07:00
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-11-11 19:46:25 -08:00
|
|
|
/**
|
|
|
|
* Query builder scope to order on assigned user
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function scopeOrderAssigned($query, $order)
|
|
|
|
{
|
2016-11-11 20:50:10 -08:00
|
|
|
return $query->leftJoin('users', 'assets.assigned_to', '=', 'users.id')->select('assets.*')->orderBy('users.first_name', $order)->orderBy('users.last_name', $order);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to order on status
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeOrderStatus($query, $order)
|
|
|
|
{
|
|
|
|
return $query->join('status_labels', 'assets.status_id', '=', 'status_labels.id')->orderBy('status_labels.name', $order);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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', 'assets.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to order on category
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeOrderCategory($query, $order)
|
|
|
|
{
|
|
|
|
return $query->join('models', 'assets.model_id', '=', 'models.id')
|
|
|
|
->join('categories', 'models.category_id', '=', 'categories.id')
|
|
|
|
->orderBy('categories.name', $order);
|
|
|
|
}
|
|
|
|
|
2016-05-12 10:38:57 -07: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->join('models', 'assets.model_id', '=', 'models.id')
|
|
|
|
->join('manufacturers', 'models.manufacturer_id', '=', 'manufacturers.id')
|
|
|
|
->orderBy('manufacturers.name', $order);
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
2016-06-28 12:19:14 -07:00
|
|
|
* Query builder scope to order on location
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
* TODO: Extend this method out for checked out assets as well. Right now it
|
|
|
|
* only checks the location name related to rtd_location_id
|
|
|
|
*/
|
|
|
|
public function scopeOrderLocation($query, $order)
|
|
|
|
{
|
|
|
|
return $query->join('locations', 'locations.id', '=', 'assets.rtd_location_id')->orderBy('locations.name', $order);
|
|
|
|
}
|
|
|
|
}
|