43 'name' =>
'min:2|max:255',
44 'model_id' =>
'required|integer',
45 'status_id' =>
'required|integer',
46 'company_id' =>
'integer',
47 'warranty_months' =>
'integer|min:0|max:240',
48 'physical' =>
'integer',
49 'checkout_date' =>
'date|max:10|min:10',
50 'checkin_date' =>
'date|max:10|min:10',
51 'supplier_id' =>
'integer',
52 'asset_tag' =>
'required|min:2|max:255|unique:assets,asset_tag,NULL,deleted_at',
53 'status' =>
'integer',
62 protected $fillable = [
'name',
'model_id',
'status_id',
'asset_tag'];
67 return $this->belongsTo(
'\App\Models\Company',
'company_id');
74 public function checkOutToUser($user, $admin, $checkout_at = null, $expected_checkin = null, $note = null, $name = null)
77 if ($expected_checkin) {
78 $this->expected_checkin = $expected_checkin ;
81 $this->last_checkout = $checkout_at;
89 $this->accepted=
"pending";
98 $log_id = $this->
createCheckoutLog($checkout_at, $admin, $user, $expected_checkin, $note);
104 if ($settings->slack_endpoint) {
117 $data[
'log_id'] = $log_id;
118 $data[
'eula'] = $this->
getEula();
119 $data[
'first_name'] = $user->first_name;
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;
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');
141 if ($settings->slack_endpoint) {
144 'username' => $settings->botname,
145 'channel' => $settings->slack_channel,
149 $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
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().
'>.' 164 ])->send(
'Asset Checked Out');
179 public function createCheckoutLog($checkout_at = null, $admin, $user, $expected_checkin = null, $note = null)
182 $logaction = new \App\Models\Actionlog();
183 $logaction->asset_id = $this->id;
184 $logaction->checkedout_to = $this->assigned_to;
185 $logaction->asset_type =
'hardware';
187 $logaction->location_id = $user->location_id;
190 $logaction->adminlog()->associate($admin);
191 $logaction->note = $note;
193 $logaction->created_at = $checkout_at;
195 $log = $logaction->logaction(
'checkout');
196 return $logaction->id;
205 return $this->
model->belongsTo(
'\App\Models\Depreciation',
'depreciation_id');
213 return $this->
model->depreciation;
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');
231 return $this->belongsTo(
'\App\Models\User',
'assigned_to')
243 return $this->belongsTo(
'\App\Models\Location',
'rtd_location_id');
252 return $this->belongsTo(
'\App\Models\Location',
'rtd_location_id');
260 return $this->hasMany(
'\App\Models\Actionlog',
'asset_id')
261 ->where(
'asset_type',
'=',
'hardware')
262 ->orderBy(
'created_at',
'desc')
278 return $this->hasMany(
'\App\Models\AssetMaintenance',
'asset_id')
279 ->orderBy(
'created_at',
'desc')
288 return $this->belongsTo(
'\App\Models\User',
'user_id');
297 return Asset::where(
'physical',
'=',
'1')
298 ->whereNull(
'deleted_at',
'and')
309 ->whereNull(
'deleted_at')
320 return Asset::Requestable()
321 ->whereNull(
'deleted_at')
331 return $this->belongsTo(
'\App\Models\Statuslabel',
'status_id');
340 if ($this->name ==
'') {
341 return $this->
model->name;
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');
357 return $this->belongsTo(
'\App\Models\AssetModel',
'model_id')->withTrashed();
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 ' 369 .
' DAY) AND DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) > NOW()'))
370 ->orderBy(
'purchase_date',
'ASC')
379 return $this->belongsToMany(
'\App\Models\License',
'license_seats',
'asset_id',
'license_id');
384 return $this->hasMany(
'\App\Models\LicenseSeat',
'asset_id');
389 return $this->belongsTo(
'\App\Models\Supplier',
'supplier_id');
395 $today = date(
"Y-m-d");
400 $interval = $d2->diff($d1);
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');
427 if ($settings->auto_increment_assets ==
'1') {
428 $asset_tag = \DB::table(
'assets')
429 ->where(
'physical',
'=',
'1')
431 return $settings->auto_increment_prefix.($asset_tag + 1);
439 return $this->
model->category->checkin_email;
444 return $this->
model->category->require_acceptance;
450 $Parsedown = new \Parsedown();
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') {
480 return $query->where(
'physical',
'=',
'1');
494 return $query->whereHas(
'assetstatus',
function ($query) {
496 $query->where(
'deployable',
'=', 0)
497 ->where(
'pending',
'=', 1)
498 ->where(
'archived',
'=', 0);
513 return $query->whereNULL(
'assigned_to')
514 ->whereHas(
'assetstatus',
function ($query) {
516 $query->where(
'deployable',
'=', 1)
517 ->where(
'pending',
'=', 0)
518 ->where(
'archived',
'=', 0);
533 return $query->whereHas(
'assetstatus',
function ($query) {
535 $query->where(
'deployable',
'=', 0)
536 ->where(
'pending',
'=', 0)
537 ->where(
'archived',
'=', 0);
552 return $query->whereHas(
'assetstatus',
function ($query) {
554 $query->where(
'deployable',
'=', 0)
555 ->where(
'pending',
'=', 0)
556 ->where(
'archived',
'=', 1);
571 return $query->where(
'assigned_to',
'>',
'0');
585 return $query->where(
'requestable',
'=', 1)
586 ->whereHas(
'assetstatus',
function ($query) {
588 $query->where(
'deployable',
'=', 1)
589 ->where(
'pending',
'=', 0)
590 ->where(
'archived',
'=', 0);
605 return $query->whereNotNull(
'deleted_at');
621 return $query->whereIn(
'model_id', $modelIdListing);
633 return $query->where(
"accepted",
"=",
"pending");
645 return $query->where(
"accepted",
"=",
"rejected");
658 return $uery->where(
"accepted",
"=",
"accepted");
672 $search = explode(
' OR ', $search);
674 return $query->where(
function ($query) use ($search) {
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.
'%');
684 })->orWhere(
function ($query) use ($search) {
685 $query->whereHas(
'assetstatus',
function ($query) use ($search) {
686 $query->where(
'status_labels.name',
'LIKE',
'%'.$search.
'%');
688 })->orWhere(
function ($query) use ($search) {
689 $query->whereHas(
'company',
function ($query) use ($search) {
690 $query->where(
'companies.name',
'LIKE',
'%'.$search.
'%');
692 })->orWhere(
function ($query) use ($search) {
693 $query->whereHas(
'defaultLoc',
function ($query) use ($search) {
694 $query->where(
'locations.name',
'LIKE',
'%'.$search.
'%');
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.
'%');
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.
'%');
714 foreach (CustomField::all() as $field) {
715 $query->orWhere($field->db_column_name(),
'LIKE',
"%$search%");
730 return $query->join(
'models',
'assets.model_id',
'=',
'models.id')->orderBy(
'models.name', $order);
744 return $query->join(
'users',
'assets.assigned_to',
'=',
'users.id')->orderBy(
'users.first_name', $order)->orderBy(
'users.last_name', $order);
757 return $query->join(
'status_labels',
'assets.status_id',
'=',
'status_labels.id')->orderBy(
'status_labels.name', $order);
770 return $query->leftJoin(
'companies',
'assets.company_id',
'=',
'companies.id')->orderBy(
'companies.name', $order);
783 return $query->join(
'models',
'assets.model_id',
'=',
'models.id')
784 ->join(
'categories',
'models.category_id',
'=',
'categories.id')
785 ->orderBy(
'categories.name', $order);
800 return $query->join(
'locations',
'locations.id',
'=',
'assets.rtd_location_id')->orderBy(
'locations.name', $order);
defaultLoc()
Get the asset's location based on default RTD location.
scopeOrderStatus($query, $order)
Query builder scope to order on status.
scopeHardware($query)
BEGIN QUERY SCOPES
scopeUndeployable($query)
Query builder scope for Undeployable assets.
scopeOrderCompany($query, $order)
Query builder scope to order on company.
scopeRTD($query)
Query builder scope for RTD assets.
assetstatus()
Get total assets.
get_depreciation()
Get depreciation attribute from associated asset model.
uploads()
Get uploads for this asset.
createCheckoutLog($checkout_at=null, $admin, $user, $expected_checkin=null, $note=null)
validationRules($id= '0')
checkOutToUser($user, $admin, $checkout_at=null, $expected_checkin=null, $note=null, $name=null)
Checkout asset.
static assetcount()
Get total assets.
static autoincrement_asset()
Get auto-increment.
adminuser()
Get action logs for this asset.
scopeNotYetAccepted($query)
Query builder scope to get not-yet-accepted assets.
showAssetName()
Get name for EULA.
static getExpiringWarrantee($days=30)
scopeArchived($query)
Query builder scope for Archived assets.
scopeDeployed($query)
Query builder scope for Deployed assets.
assetmaintenances()
assetmaintenances Get improvements for this asset
scopeDeleted($query)
Query builder scope for Deleted assets.
scopeAccepted($query)
Query builder scope to get accepted assets.
static availassetcount()
Get total assets not checked out.
scopeRejected($query)
Query builder scope to get rejected assets.
scopePending($query)
Query builder scope for pending assets.
scopeOrderModels($query, $order)
Query builder scope to order on model.
checkOutNotifySlack($settings, $admin, $note=null)
assetlog()
Get action logs for this asset.
scopeTextSearch($query, $search)
Query builder scope to search on text for complex Bootstrap Tables API.
checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note)
depreciation()
Set depreciation relationship.
scopeOrderCategory($query, $order)
Query builder scope to order on category.
scopeInModelList($query, array $modelIdListing)
scopeInModelList Get all assets in the provided listing of model ids
static getRequestable()
Get requestable assets.
licenses()
Get the license seat information.
scopeRequestableAssets($query)
Query builder scope for Requestable assets.
assetloc()
Get the asset's location based on the assigned user.
scopeOrderAssigned($query, $order)
Query builder scope to order on assigned user.
scopeOrderLocation($query, $order)
Query builder scope to order on model.