Model for Assets. More...

Inheritance diagram for App\Models\Asset:
App\Models\Depreciable

Public Member Functions

 company ()
 
 checkOutToUser ($user, $admin, $checkout_at=null, $expected_checkin=null, $note=null, $name=null)
 Checkout asset. More...
 
 checkOutNotifyMail ($log_id, $user, $checkout_at, $expected_checkin, $note)
 
 checkOutNotifySlack ($settings, $admin, $note=null)
 
 validationRules ($id= '0')
 
 createCheckoutLog ($checkout_at=null, $admin, $user, $expected_checkin=null, $note=null)
 
 depreciation ()
 Set depreciation relationship. More...
 
 get_depreciation ()
 Get depreciation attribute from associated asset model. More...
 
 uploads ()
 Get uploads for this asset. More...
 
 assigneduser ()
 
 assetloc ()
 Get the asset's location based on the assigned user. More...
 
 defaultLoc ()
 Get the asset's location based on default RTD location. More...
 
 assetlog ()
 Get action logs for this asset. More...
 
 assetmaintenances ()
 assetmaintenances Get improvements for this asset More...
 
 adminuser ()
 Get action logs for this asset. More...
 
 assetstatus ()
 Get total assets. More...
 
 showAssetName ()
 Get name for EULA. More...
 
 warrantee_expires ()
 
 model ()
 
 licenses ()
 Get the license seat information. More...
 
 licenseseats ()
 
 supplier ()
 
 months_until_eol ()
 
 eol_date ()
 
 checkin_email ()
 
 requireAcceptance ()
 
 getEula ()
 
 scopeHardware ($query)
 

BEGIN QUERY SCOPES

More...
 
 scopePending ($query)
 Query builder scope for pending assets. More...
 
 scopeRTD ($query)
 Query builder scope for RTD assets. More...
 
 scopeUndeployable ($query)
 Query builder scope for Undeployable assets. More...
 
 scopeArchived ($query)
 Query builder scope for Archived assets. More...
 
 scopeDeployed ($query)
 Query builder scope for Deployed assets. More...
 
 scopeRequestableAssets ($query)
 Query builder scope for Requestable assets. More...
 
 scopeDeleted ($query)
 Query builder scope for Deleted assets. More...
 
 scopeInModelList ($query, array $modelIdListing)
 scopeInModelList Get all assets in the provided listing of model ids More...
 
 scopeNotYetAccepted ($query)
 Query builder scope to get not-yet-accepted assets. More...
 
 scopeRejected ($query)
 Query builder scope to get rejected assets. More...
 
 scopeAccepted ($query)
 Query builder scope to get accepted assets. More...
 
 scopeTextSearch ($query, $search)
 Query builder scope to search on text for complex Bootstrap Tables API. More...
 
 scopeOrderModels ($query, $order)
 Query builder scope to order on model. More...
 
 scopeOrderAssigned ($query, $order)
 Query builder scope to order on assigned user. More...
 
 scopeOrderStatus ($query, $order)
 Query builder scope to order on status. More...
 
 scopeOrderCompany ($query, $order)
 Query builder scope to order on company. More...
 
 scopeOrderCategory ($query, $order)
 Query builder scope to order on category. More...
 
 scopeOrderLocation ($query, $order)
 Query builder scope to order on model. More...
 
 getDepreciatedValue ()
 
 time_until_depreciated ()
 
 depreciated_date ()
 

Static Public Member Functions

static assetcount ()
 Get total assets. More...
 
static availassetcount ()
 Get total assets not checked out. More...
 
static getRequestable ()
 Get requestable assets. More...
 
static getExpiringWarrantee ($days=30)
 
static autoincrement_asset ()
 Get auto-increment. More...
 

Protected Attributes

 $table = 'assets'
 
 $injectUniqueIdentifier = true
 
 $rules
 
 $fillable = ['name','model_id','status_id','asset_tag']
 

Detailed Description

Model for Assets.

Version
v1.0

Definition at line 21 of file Asset.php.

Member Function Documentation

App\Models\Asset::adminuser ( )

Get action logs for this asset.

Definition at line 286 of file Asset.php.

287  {
288  return $this->belongsTo('\App\Models\User', 'user_id');
289  }
static App\Models\Asset::assetcount ( )
static

Get total assets.

Definition at line 294 of file Asset.php.

295  {
296 
297  return Asset::where('physical', '=', '1')
298  ->whereNull('deleted_at', 'and')
299  ->count();
300  }
App\Models\Asset::assetloc ( )

Get the asset's location based on the assigned user.

Definition at line 238 of file Asset.php.

239  {
240  if ($this->assigneduser) {
241  return $this->assigneduser->userloc();
242  } else {
243  return $this->belongsTo('\App\Models\Location', 'rtd_location_id');
244  }
245  }
App\Models\Asset::assetlog ( )

Get action logs for this asset.

Definition at line 258 of file Asset.php.

259  {
260  return $this->hasMany('\App\Models\Actionlog', 'asset_id')
261  ->where('asset_type', '=', 'hardware')
262  ->orderBy('created_at', 'desc')
263  ->withTrashed();
264  }
App\Models\Asset::assetmaintenances ( )

assetmaintenances Get improvements for this asset

Returns
mixed
Author
Vincent Sposato vince.nosp@m.nt.s.nosp@m.posat.nosp@m.o@gm.nosp@m.ail.c.nosp@m.om
Version
v1.0

Definition at line 275 of file Asset.php.

276  {
277 
278  return $this->hasMany('\App\Models\AssetMaintenance', 'asset_id')
279  ->orderBy('created_at', 'desc')
280  ->withTrashed();
281  }
App\Models\Asset::assetstatus ( )

Get total assets.

Definition at line 329 of file Asset.php.

330  {
331  return $this->belongsTo('\App\Models\Statuslabel', 'status_id');
332  }
App\Models\Asset::assigneduser ( )

Definition at line 229 of file Asset.php.

230  {
231  return $this->belongsTo('\App\Models\User', 'assigned_to')
232  ->withTrashed();
233  }
static App\Models\Asset::autoincrement_asset ( )
static

Get auto-increment.

Definition at line 422 of file Asset.php.

423  {
424 
425  $settings = \App\Models\Setting::getSettings();
426 
427  if ($settings->auto_increment_assets == '1') {
428  $asset_tag = \DB::table('assets')
429  ->where('physical', '=', '1')
430  ->max('id');
431  return $settings->auto_increment_prefix.($asset_tag + 1);
432  } else {
433  return false;
434  }
435  }
static getSettings()
Definition: Setting.php:33
static App\Models\Asset::availassetcount ( )
static

Get total assets not checked out.

Definition at line 305 of file Asset.php.

306  {
307 
308  return Asset::RTD()
309  ->whereNull('deleted_at')
310  ->count();
311 
312  }
App\Models\Asset::checkin_email ( )

Definition at line 437 of file Asset.php.

438  {
439  return $this->model->category->checkin_email;
440  }
App\Models\Asset::checkOutNotifyMail (   $log_id,
  $user,
  $checkout_at,
  $expected_checkin,
  $note 
)

Definition at line 114 of file Asset.php.

115  {
116 
117  $data['log_id'] = $log_id;
118  $data['eula'] = $this->getEula();
119  $data['first_name'] = $user->first_name;
120  $data['item_name'] = $this->showAssetName();
121  $data['checkout_date'] = $checkout_at;
122  $data['expected_checkin'] = $expected_checkin;
123  $data['item_tag'] = $this->asset_tag;
124  $data['note'] = $note;
125  $data['item_serial'] = $this->serial;
126  $data['require_acceptance'] = $this->requireAcceptance();
127 
128  if ((($this->requireAcceptance()=='1') || ($this->getEula())) && (!config('app.lock_passwords'))) {
129 
130  \Mail::send('emails.accept-asset', $data, function ($m) use ($user) {
131  $m->to($user->email, $user->first_name . ' ' . $user->last_name);
132  $m->subject('Confirm asset delivery');
133  });
134  }
135 
136  }
showAssetName()
Get name for EULA.
Definition: Asset.php:337
App\Models\Asset::checkOutNotifySlack (   $settings,
  $admin,
  $note = null 
)

Definition at line 138 of file Asset.php.

139  {
140 
141  if ($settings->slack_endpoint) {
142 
143  $slack_settings = [
144  'username' => $settings->botname,
145  'channel' => $settings->slack_channel,
146  'link_names' => true
147  ];
148 
149  $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
150 
151  try {
152  $client->attach([
153  'color' => 'good',
154  'fields' => [
155  [
156  'title' => 'Checked Out:',
157  'value' => 'HARDWARE asset <'.config('app.url').'/hardware/'.$this->id.'/view'.'|'.$this->showAssetName().'> checked out to <'.config('app.url').'/admin/users/'.$this->assigned_to.'/view|'.$this->assigneduser->fullName().'> by <'.config('app.url').'/hardware/'.$this->id.'/view'.'|'.$admin->fullName().'>.'
158  ],
159  [
160  'title' => 'Note:',
161  'value' => e($note)
162  ],
163  ]
164  ])->send('Asset Checked Out');
165 
166  } catch (Exception $e) {
167  print_r($e);
168  }
169  }
170 
171  }
showAssetName()
Get name for EULA.
Definition: Asset.php:337
App\Models\Asset::checkOutToUser (   $user,
  $admin,
  $checkout_at = null,
  $expected_checkin = null,
  $note = null,
  $name = null 
)

Checkout asset.

Definition at line 74 of file Asset.php.

75  {
76 
77  if ($expected_checkin) {
78  $this->expected_checkin = $expected_checkin ;
79  }
80 
81  $this->last_checkout = $checkout_at;
82 
83  $this->assigneduser()->associate($user);
84  $this->name = $name;
85 
86  $settings = Setting::getSettings();
87 
88  if ($this->requireAcceptance()) {
89  $this->accepted="pending";
90  }
91 
92  if (!$user) {
93  return false;
94  }
95 
96  if ($this->save()) {
97 
98  $log_id = $this->createCheckoutLog($checkout_at, $admin, $user, $expected_checkin, $note);
99 
100  if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
101  $this->checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note);
102  }
103 
104  if ($settings->slack_endpoint) {
105  $this->checkOutNotifySlack($settings, $admin, $note);
106  }
107  return true;
108 
109  }
110  return false;
111 
112  }
createCheckoutLog($checkout_at=null, $admin, $user, $expected_checkin=null, $note=null)
Definition: Asset.php:179
static getSettings()
Definition: Setting.php:33
checkOutNotifySlack($settings, $admin, $note=null)
Definition: Asset.php:138
checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note)
Definition: Asset.php:114
App\Models\Asset::company ( )

Definition at line 65 of file Asset.php.

66  {
67  return $this->belongsTo('\App\Models\Company', 'company_id');
68  }
App\Models\Asset::createCheckoutLog (   $checkout_at = null,
  $admin,
  $user,
  $expected_checkin = null,
  $note = null 
)

Definition at line 179 of file Asset.php.

180  {
181 
182  $logaction = new \App\Models\Actionlog();
183  $logaction->asset_id = $this->id;
184  $logaction->checkedout_to = $this->assigned_to;
185  $logaction->asset_type = 'hardware';
186  if ($user) {
187  $logaction->location_id = $user->location_id;
188  }
189 
190  $logaction->adminlog()->associate($admin);
191  $logaction->note = $note;
192  if ($checkout_at) {
193  $logaction->created_at = $checkout_at;
194  }
195  $log = $logaction->logaction('checkout');
196  return $logaction->id;
197  }
App\Models\Asset::defaultLoc ( )

Get the asset's location based on default RTD location.

Definition at line 250 of file Asset.php.

251  {
252  return $this->belongsTo('\App\Models\Location', 'rtd_location_id');
253  }
App\Models\Depreciable::depreciated_date ( )
inherited

Definition at line 77 of file Depreciable.php.

78  {
79  $date = date_create($this->purchase_date);
80  date_add($date, date_interval_create_from_date_string($this->get_depreciation()->months . ' months'));
81  return $date; //date_format($date, 'Y-m-d'); //don't bake-in format, for internationalization
82  }
App\Models\Asset::depreciation ( )

Set depreciation relationship.

Definition at line 203 of file Asset.php.

204  {
205  return $this->model->belongsTo('\App\Models\Depreciation', 'depreciation_id');
206  }
App\Models\Asset::eol_date ( )

Definition at line 408 of file Asset.php.

409  {
410 
411  if (( $this->purchase_date ) && ( $this->model )) {
412  $date = date_create($this->purchase_date);
413  date_add($date, date_interval_create_from_date_string($this->model->eol . ' months'));
414  return date_format($date, 'Y-m-d');
415  }
416 
417  }
App\Models\Asset::get_depreciation ( )

Get depreciation attribute from associated asset model.

Definition at line 211 of file Asset.php.

212  {
213  return $this->model->depreciation;
214  }
App\Models\Depreciable::getDepreciatedValue ( )
inherited
Returns
float|int

Definition at line 42 of file Depreciable.php.

43  {
44  if (!$this->get_depreciation()) { // will never happen
45  return $this->purchase_cost;
46  }
47 
48  if ($this->get_depreciation()->months <= 0) {
49  return $this->purchase_cost;
50  }
51 
52  // fraction of value left
53  $months_remaining = $this->time_until_depreciated()->m + 12*$this->time_until_depreciated()->y; //UGlY
54  $current_value = round(($months_remaining/ $this->get_depreciation()->months) * $this->purchase_cost, 2);
55 
56  if ($current_value < 0) {
57  $current_value = 0;
58  }
59  return $current_value;
60  }
App\Models\Asset::getEula ( )

Definition at line 447 of file Asset.php.

448  {
449 
450  $Parsedown = new \Parsedown();
451 
452  if ($this->model->category->eula_text) {
453  return $Parsedown->text(e($this->model->category->eula_text));
454  } elseif ($this->model->category->use_default_eula == '1') {
455  return $Parsedown->text(e(Setting::getSettings()->default_eula_text));
456  } else {
457  return null;
458  }
459 
460  }
static getSettings()
Definition: Setting.php:33
static App\Models\Asset::getExpiringWarrantee (   $days = 30)
static

Definition at line 360 of file Asset.php.

361  {
362 
363  return Asset::where('archived', '=', '0')
364  ->whereNotNull('warranty_months')
365  ->whereNotNull('purchase_date')
366  ->whereNull('deleted_at')
367  ->whereRaw(\DB::raw('DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) <= DATE(NOW() + INTERVAL '
368  . $days
369  . ' DAY) AND DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) > NOW()'))
370  ->orderBy('purchase_date', 'ASC')
371  ->get();
372  }
static App\Models\Asset::getRequestable ( )
static

Get requestable assets.

Definition at line 317 of file Asset.php.

318  {
319 
320  return Asset::Requestable()
321  ->whereNull('deleted_at')
322  ->count();
323 
324  }
App\Models\Asset::licenses ( )

Get the license seat information.

Definition at line 377 of file Asset.php.

378  {
379  return $this->belongsToMany('\App\Models\License', 'license_seats', 'asset_id', 'license_id');
380  }
App\Models\Asset::licenseseats ( )

Definition at line 382 of file Asset.php.

383  {
384  return $this->hasMany('\App\Models\LicenseSeat', 'asset_id');
385  }
App\Models\Asset::model ( )

Definition at line 355 of file Asset.php.

356  {
357  return $this->belongsTo('\App\Models\AssetModel', 'model_id')->withTrashed();
358  }
App\Models\Asset::months_until_eol ( )

Definition at line 392 of file Asset.php.

393  {
394 
395  $today = date("Y-m-d");
396  $d1 = new DateTime($today);
397  $d2 = new DateTime($this->eol_date());
398 
399  if ($this->eol_date() > $today) {
400  $interval = $d2->diff($d1);
401  } else {
402  $interval = null;
403  }
404 
405  return $interval;
406  }
App\Models\Asset::requireAcceptance ( )

Definition at line 442 of file Asset.php.

443  {
444  return $this->model->category->require_acceptance;
445  }
App\Models\Asset::scopeAccepted (   $query)

Query builder scope to get accepted assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 656 of file Asset.php.

657  {
658  return $uery->where("accepted", "=", "accepted");
659  }
App\Models\Asset::scopeArchived (   $query)

Query builder scope for Archived assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 549 of file Asset.php.

550  {
551 
552  return $query->whereHas('assetstatus', function ($query) {
553 
554  $query->where('deployable', '=', 0)
555  ->where('pending', '=', 0)
556  ->where('archived', '=', 1);
557  });
558  }
App\Models\Asset::scopeDeleted (   $query)

Query builder scope for Deleted assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 603 of file Asset.php.

604  {
605  return $query->whereNotNull('deleted_at');
606  }
App\Models\Asset::scopeDeployed (   $query)

Query builder scope for Deployed assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 568 of file Asset.php.

569  {
570 
571  return $query->where('assigned_to', '>', '0');
572  }
App\Models\Asset::scopeHardware (   $query)


BEGIN QUERY SCOPES

Query builder scope for hardware

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 477 of file Asset.php.

478  {
479 
480  return $query->where('physical', '=', '1');
481  }
App\Models\Asset::scopeInModelList (   $query,
array  $modelIdListing 
)

scopeInModelList Get all assets in the provided listing of model ids

Parameters
$query
array$modelIdListing
Returns
mixed
Author
Vincent Sposato vince.nosp@m.nt.s.nosp@m.posat.nosp@m.o@gm.nosp@m.ail.c.nosp@m.om
Version
v1.0

Definition at line 619 of file Asset.php.

620  {
621  return $query->whereIn('model_id', $modelIdListing);
622  }
App\Models\Asset::scopeNotYetAccepted (   $query)

Query builder scope to get not-yet-accepted assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 631 of file Asset.php.

632  {
633  return $query->where("accepted", "=", "pending");
634  }
App\Models\Asset::scopeOrderAssigned (   $query,
  $order 
)

Query builder scope to order on assigned user.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 742 of file Asset.php.

743  {
744  return $query->join('users', 'assets.assigned_to', '=', 'users.id')->orderBy('users.first_name', $order)->orderBy('users.last_name', $order);
745  }
App\Models\Asset::scopeOrderCategory (   $query,
  $order 
)

Query builder scope to order on category.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 781 of file Asset.php.

782  {
783  return $query->join('models', 'assets.model_id', '=', 'models.id')
784  ->join('categories', 'models.category_id', '=', 'categories.id')
785  ->orderBy('categories.name', $order);
786  }
App\Models\Asset::scopeOrderCompany (   $query,
  $order 
)

Query builder scope to order on company.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 768 of file Asset.php.

769  {
770  return $query->leftJoin('companies', 'assets.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
771  }
App\Models\Asset::scopeOrderLocation (   $query,
  $order 
)

Query builder scope to order on model.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate 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

Definition at line 798 of file Asset.php.

799  {
800  return $query->join('locations', 'locations.id', '=', 'assets.rtd_location_id')->orderBy('locations.name', $order);
801  }
App\Models\Asset::scopeOrderModels (   $query,
  $order 
)

Query builder scope to order on model.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 728 of file Asset.php.

729  {
730  return $query->join('models', 'assets.model_id', '=', 'models.id')->orderBy('models.name', $order);
731  }
App\Models\Asset::scopeOrderStatus (   $query,
  $order 
)

Query builder scope to order on status.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 755 of file Asset.php.

756  {
757  return $query->join('status_labels', 'assets.status_id', '=', 'status_labels.id')->orderBy('status_labels.name', $order);
758  }
App\Models\Asset::scopePending (   $query)

Query builder scope for pending assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 491 of file Asset.php.

492  {
493 
494  return $query->whereHas('assetstatus', function ($query) {
495 
496  $query->where('deployable', '=', 0)
497  ->where('pending', '=', 1)
498  ->where('archived', '=', 0);
499  });
500  }
App\Models\Asset::scopeRejected (   $query)

Query builder scope to get rejected assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 643 of file Asset.php.

644  {
645  return $query->where("accepted", "=", "rejected");
646  }
App\Models\Asset::scopeRequestableAssets (   $query)

Query builder scope for Requestable assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 582 of file Asset.php.

583  {
584 
585  return $query->where('requestable', '=', 1)
586  ->whereHas('assetstatus', function ($query) {
587 
588  $query->where('deployable', '=', 1)
589  ->where('pending', '=', 0)
590  ->where('archived', '=', 0);
591  });
592  }
App\Models\Asset::scopeRTD (   $query)

Query builder scope for RTD assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 510 of file Asset.php.

511  {
512 
513  return $query->whereNULL('assigned_to')
514  ->whereHas('assetstatus', function ($query) {
515 
516  $query->where('deployable', '=', 1)
517  ->where('pending', '=', 0)
518  ->where('archived', '=', 0);
519  });
520  }
App\Models\Asset::scopeTextSearch (   $query,
  $search 
)

Query builder scope to search on text for complex Bootstrap Tables API.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$searchSearch term
Returns
Illuminate Modified query builder

Definition at line 670 of file Asset.php.

671  {
672  $search = explode(' OR ', $search);
673 
674  return $query->where(function ($query) use ($search) {
675 
676  foreach ($search as $search) {
677  $query->whereHas('model', function ($query) use ($search) {
678  $query->whereHas('category', function ($query) use ($search) {
679  $query->where(function ($query) use ($search) {
680  $query->where('categories.name', 'LIKE', '%'.$search.'%')
681  ->orWhere('models.name', 'LIKE', '%'.$search.'%');
682  });
683  });
684  })->orWhere(function ($query) use ($search) {
685  $query->whereHas('assetstatus', function ($query) use ($search) {
686  $query->where('status_labels.name', 'LIKE', '%'.$search.'%');
687  });
688  })->orWhere(function ($query) use ($search) {
689  $query->whereHas('company', function ($query) use ($search) {
690  $query->where('companies.name', 'LIKE', '%'.$search.'%');
691  });
692  })->orWhere(function ($query) use ($search) {
693  $query->whereHas('defaultLoc', function ($query) use ($search) {
694  $query->where('locations.name', 'LIKE', '%'.$search.'%');
695  });
696  })->orWhere(function ($query) use ($search) {
697  $query->whereHas('assigneduser', function ($query) use ($search) {
698  $query->where(function ($query) use ($search) {
699  $query->where('users.first_name', 'LIKE', '%'.$search.'%')
700  ->orWhere('users.last_name', 'LIKE', '%'.$search.'%')
701  ->orWhere(function ($query) use ($search) {
702  $query->whereHas('userloc', function ($query) use ($search) {
703  $query->where('locations.name', 'LIKE', '%'.$search.'%');
704  });
705  });
706  });
707  });
708  })->orWhere('assets.name', 'LIKE', '%'.$search.'%')
709  ->orWhere('assets.asset_tag', 'LIKE', '%'.$search.'%')
710  ->orWhere('assets.serial', 'LIKE', '%'.$search.'%')
711  ->orWhere('assets.order_number', 'LIKE', '%'.$search.'%')
712  ->orWhere('assets.notes', 'LIKE', '%'.$search.'%');
713  }
714  foreach (CustomField::all() as $field) {
715  $query->orWhere($field->db_column_name(), 'LIKE', "%$search%");
716  }
717  });
718  }
App\Models\Asset::scopeUndeployable (   $query)

Query builder scope for Undeployable assets.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
Returns
Illuminate Modified query builder

Definition at line 530 of file Asset.php.

531  {
532 
533  return $query->whereHas('assetstatus', function ($query) {
534 
535  $query->where('deployable', '=', 0)
536  ->where('pending', '=', 0)
537  ->where('archived', '=', 0);
538  });
539  }
App\Models\Asset::showAssetName ( )

Get name for EULA.

Definition at line 337 of file Asset.php.

338  {
339 
340  if ($this->name == '') {
341  return $this->model->name;
342  } else {
343  return $this->name;
344  }
345  }
App\Models\Asset::supplier ( )

Definition at line 387 of file Asset.php.

388  {
389  return $this->belongsTo('\App\Models\Supplier', 'supplier_id');
390  }
App\Models\Depreciable::time_until_depreciated ( )
inherited

Definition at line 62 of file Depreciable.php.

63  {
64  // @link http://www.php.net/manual/en/class.datetime.php
65  $d1 = new \DateTime();
66  $d2 = $this->depreciated_date();
67 
68  // @link http://www.php.net/manual/en/class.dateinterval.php
69  $interval = $d1->diff($d2);
70  if (!$interval->invert) {
71  return $interval;
72  } else {
73  return new \DateInterval("PT0S"); //null interval (zero seconds from now)
74  }
75  }
App\Models\Asset::uploads ( )

Get uploads for this asset.

Definition at line 219 of file Asset.php.

220  {
221 
222  return $this->hasMany('\App\Models\Actionlog', 'asset_id')
223  ->where('asset_type', '=', 'hardware')
224  ->where('action_type', '=', 'uploaded')
225  ->whereNotNull('filename')
226  ->orderBy('created_at', 'desc');
227  }
App\Models\Asset::validationRules (   $id = '0')

Definition at line 174 of file Asset.php.

175  {
176  return $this->rules;
177  }
App\Models\Asset::warrantee_expires ( )

Definition at line 347 of file Asset.php.

348  {
349  $date = date_create($this->purchase_date);
350  date_add($date, date_interval_create_from_date_string($this->warranty_months . ' months'));
351  return date_format($date, 'Y-m-d');
352  }

Member Data Documentation

App\Models\Asset::$fillable = ['name','model_id','status_id','asset_tag']
protected

Definition at line 62 of file Asset.php.

App\Models\Asset::$injectUniqueIdentifier = true
protected

Definition at line 39 of file Asset.php.

App\Models\Asset::$rules
protected
Initial value:
= [
'name' => 'min:2|max:255'

Definition at line 42 of file Asset.php.

App\Models\Asset::$table = 'assets'
protected

Definition at line 30 of file Asset.php.


The documentation for this class was generated from the following file: