2016-12-23 17:52:00 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Presenters;
|
2016-12-29 14:02:18 -08:00
|
|
|
|
2017-02-06 18:49:08 -08:00
|
|
|
use App\Models\CustomField;
|
2016-12-23 17:52:00 -08:00
|
|
|
use DateTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AssetPresenter
|
|
|
|
* @package App\Presenters
|
|
|
|
*/
|
|
|
|
class AssetPresenter extends Presenter
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2017-02-03 22:20:11 -08:00
|
|
|
* Json Column Layout for bootstrap table
|
2016-12-23 17:52:00 -08:00
|
|
|
* @return string
|
|
|
|
*/
|
2017-02-03 22:20:11 -08:00
|
|
|
public static function dataTableLayout()
|
2016-12-23 17:52:00 -08:00
|
|
|
{
|
2017-02-03 22:20:11 -08:00
|
|
|
$layout = [
|
|
|
|
[
|
2017-02-06 18:49:08 -08:00
|
|
|
"field" => "checkbox",
|
|
|
|
"checkbox" => true
|
|
|
|
],[
|
|
|
|
"field" => "id",
|
|
|
|
"searchable" => false,
|
|
|
|
"sortable" => true,
|
|
|
|
"title" => trans('general.id'),
|
|
|
|
"visible" => false,
|
|
|
|
"formatter" => null
|
|
|
|
], [
|
2017-02-03 22:20:11 -08:00
|
|
|
"field" => "company",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"switchable" => true,
|
2017-02-06 18:49:08 -08:00
|
|
|
"title" => trans('general.company'),
|
|
|
|
"visible" => false,
|
2017-02-03 22:20:11 -08:00
|
|
|
"formatter" => "companiesLinkObjFormatter"
|
|
|
|
], [
|
|
|
|
"field" => "name",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
2017-02-06 18:49:08 -08:00
|
|
|
"title" => trans('admin/hardware/form.name'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "hardwareLinkFormatter"
|
2017-02-03 22:20:11 -08:00
|
|
|
], [
|
2017-02-06 18:49:08 -08:00
|
|
|
"field" => "image",
|
|
|
|
"searchable" => false,
|
|
|
|
"sortable" => true,
|
|
|
|
"switchable" => true,
|
|
|
|
"title" => trans('admin/hardware/table.image'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "imageFormatter"
|
|
|
|
], [
|
|
|
|
"field" => "asset_tag",
|
2017-02-03 22:20:11 -08:00
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
2017-02-06 18:49:08 -08:00
|
|
|
"title" => trans('admin/hardware/table.asset_tag'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "hardwareLinkFormatter"
|
|
|
|
], [
|
|
|
|
"field" => "serial",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"title" => trans('admin/hardware/form.serial'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "hardwareLinkFormatter"
|
|
|
|
], [
|
|
|
|
"field" => "model",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"title" => trans('admin/hardware/form.model'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "modelsLinkObjFormatter"
|
2017-02-03 22:20:11 -08:00
|
|
|
], [
|
|
|
|
"field" => "model_number",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"title" => trans('admin/models/table.modelnumber'),
|
2017-02-06 18:49:08 -08:00
|
|
|
"visible" => false,
|
|
|
|
"formatter" => null
|
2017-02-03 22:20:11 -08:00
|
|
|
], [
|
2017-02-06 18:49:08 -08:00
|
|
|
"field" => "category",
|
2017-02-03 22:20:11 -08:00
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
2017-02-06 18:49:08 -08:00
|
|
|
"title" => trans('general.category'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "categoriesLinkObjFormatter"
|
|
|
|
], [
|
|
|
|
"field" => "status_label",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"title" => trans('admin/hardware/table.status'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "statuslabelsLinkObjFormatter"
|
2017-02-03 22:20:11 -08:00
|
|
|
], [
|
2017-02-06 18:49:08 -08:00
|
|
|
"field" => "assigned_to",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"title" => trans('admin/hardware/form.checkedout_to'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "usersLinkObjFormatter"
|
|
|
|
],[
|
2017-02-03 22:20:11 -08:00
|
|
|
"field" => "location",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
2017-02-06 18:49:08 -08:00
|
|
|
"title" => trans('admin/hardware/table.location'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "locationsLinkObjFormatter"
|
2017-02-03 22:20:11 -08:00
|
|
|
], [
|
2017-02-06 18:49:08 -08:00
|
|
|
"field" => "category",
|
|
|
|
"searchable" => true,
|
2017-02-03 22:20:11 -08:00
|
|
|
"sortable" => true,
|
2017-02-06 18:49:08 -08:00
|
|
|
"title" => trans('general.category'),
|
|
|
|
"visible" => true,
|
|
|
|
"formatter" => "categoriesLinkObjFormatter"
|
2017-02-03 22:20:11 -08:00
|
|
|
], [
|
2017-02-06 18:49:08 -08:00
|
|
|
"field" => "manufacturer",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"title" => trans('general.manufacturer'),
|
|
|
|
"visible" => false,
|
|
|
|
"formatter" => "manufacturersLinkObjFormatter"
|
2017-02-03 22:20:11 -08:00
|
|
|
], [
|
|
|
|
"field" => "purchase_date",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"visible" => false,
|
|
|
|
"title" => trans('general.purchase_date'),
|
|
|
|
], [
|
|
|
|
"field" => "purchase_cost",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"title" => trans('general.purchase_cost'),
|
|
|
|
], [
|
|
|
|
"field" => "order_number",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"visible" => false,
|
|
|
|
"title" => trans('general.order_number'),
|
|
|
|
], [
|
2017-02-06 18:49:08 -08:00
|
|
|
"field" => "notes",
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"visible" => false,
|
|
|
|
"title" => trans('general.notes'),
|
2017-02-03 22:20:11 -08:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2017-02-06 18:49:08 -08:00
|
|
|
$fields = CustomField::all();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$layout[] = ["field" => $field->convertUnicodeDbSlug(),
|
|
|
|
"searchable" => true,
|
|
|
|
"sortable" => true,
|
|
|
|
"switchable" => true,
|
|
|
|
"title" => ($field->field_encrypted=='1') ?
|
|
|
|
'<i class="fa fa-lock"></i> '.e($field->name) : e($field->name),
|
|
|
|
"formatter" => null ];
|
|
|
|
}
|
|
|
|
|
|
|
|
$layout[] = [
|
|
|
|
"field" => "actions",
|
|
|
|
"searchable" => false,
|
|
|
|
"sortable" => false,
|
|
|
|
"switchable" => false,
|
|
|
|
"title" => trans('table.actions'),
|
|
|
|
"formatter" => "hardwareActionsFormatter",
|
|
|
|
];
|
|
|
|
|
2017-02-03 22:20:11 -08:00
|
|
|
return json_encode($layout);
|
2016-12-23 17:52:00 -08:00
|
|
|
}
|
|
|
|
|
2017-02-06 18:49:08 -08:00
|
|
|
|
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
/**
|
|
|
|
* Generate html link to this items name.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function nameUrl()
|
|
|
|
{
|
|
|
|
return (string) link_to_route('hardware.show', e($this->name), $this->id);
|
|
|
|
}
|
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
public function modelUrl()
|
|
|
|
{
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($this->model->model) {
|
2016-12-23 19:23:07 -08:00
|
|
|
return $this->model->model->present()->nameUrl();
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
/**
|
|
|
|
* Generate img tag to this items image.
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
public function imageUrl()
|
|
|
|
{
|
|
|
|
$imagePath = '';
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($this->image && !empty($this->image)) {
|
2016-12-23 17:52:00 -08:00
|
|
|
$imagePath = $this->image;
|
2016-12-29 14:02:18 -08:00
|
|
|
} elseif ($this->model && !empty($this->model->image)) {
|
2016-12-23 17:52:00 -08:00
|
|
|
$imagePath = $this->model->image;
|
|
|
|
}
|
|
|
|
$url = config('app.url');
|
2016-12-29 14:02:18 -08:00
|
|
|
if (!empty($imagePath)) {
|
2016-12-23 17:52:00 -08:00
|
|
|
$imagePath = "<img src='{$url}/uploads/assets/{$imagePath}' height=50 width=50>";
|
|
|
|
}
|
|
|
|
return $imagePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Displayable Name
|
|
|
|
* @return string
|
|
|
|
**/
|
|
|
|
public function name()
|
|
|
|
{
|
|
|
|
if (empty($this->name)) {
|
|
|
|
if (isset($this->model)) {
|
|
|
|
return $this->model->name.' ('.$this->asset_tag.')';
|
|
|
|
}
|
|
|
|
return $this->asset_tag;
|
|
|
|
} else {
|
2016-12-27 12:03:47 -08:00
|
|
|
return $this->name.' ('.$this->asset_tag.')';
|
2016-12-23 17:52:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 15:19:04 -08:00
|
|
|
/**
|
|
|
|
* Helper for notification polymorphism.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function fullName()
|
|
|
|
{
|
|
|
|
return $this->name();
|
|
|
|
}
|
2016-12-23 17:52:00 -08:00
|
|
|
/**
|
|
|
|
* Returns the date this item hits EOL.
|
|
|
|
* @return false|string
|
|
|
|
*/
|
|
|
|
public function eol_date()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (( $this->purchase_date ) && ( $this->model )) {
|
|
|
|
$date = date_create($this->purchase_date);
|
|
|
|
date_add($date, date_interval_create_from_date_string($this->model->model->eol . ' months'));
|
|
|
|
return date_format($date, 'Y-m-d');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How many months until this asset hits EOL.
|
|
|
|
* @return null
|
|
|
|
*/
|
|
|
|
public function months_until_eol()
|
|
|
|
{
|
|
|
|
|
|
|
|
$today = date("Y-m-d");
|
|
|
|
$d1 = new DateTime($today);
|
|
|
|
$d2 = new DateTime($this->eol_date());
|
|
|
|
|
|
|
|
if ($this->eol_date() > $today) {
|
|
|
|
$interval = $d2->diff($d1);
|
|
|
|
} else {
|
|
|
|
$interval = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $interval;
|
|
|
|
}
|
|
|
|
|
2017-01-03 16:55:43 -08:00
|
|
|
public function statusText()
|
|
|
|
{
|
|
|
|
if ($this->model->assignedTo) {
|
|
|
|
return trans('general.deployed');
|
|
|
|
}
|
|
|
|
return $this->model->assetstatus->name;
|
|
|
|
}
|
2016-12-23 17:52:00 -08:00
|
|
|
/**
|
|
|
|
* Date the warantee expires.
|
|
|
|
* @return false|string
|
|
|
|
*/
|
|
|
|
public function warrantee_expires()
|
|
|
|
{
|
|
|
|
$date = date_create($this->purchase_date);
|
|
|
|
date_add($date, date_interval_create_from_date_string($this->warranty_months . ' months'));
|
|
|
|
return date_format($date, 'Y-m-d');
|
|
|
|
}
|
2016-12-26 15:19:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Url to view this item.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function viewUrl()
|
|
|
|
{
|
|
|
|
return route('hardware.show', $this->id);
|
|
|
|
}
|
2016-12-29 18:12:27 -08:00
|
|
|
|
|
|
|
public function glyph()
|
|
|
|
{
|
|
|
|
return '<i class="fa fa-barcode"></i>';
|
|
|
|
}
|
2016-12-23 17:52:00 -08:00
|
|
|
}
|
2017-02-06 18:49:08 -08:00
|
|
|
|