public static function modelList() { $models = AssetModel::with('manufacturer')->get(); $model_array[''] = trans('general.select_model'); foreach ($models as $model) { $model_array[$model->id] = $model->displayModelName(); } return $model_array; }
/** * Get the JSON response to populate the data tables on the * Asset Model listing page. * * @author [A. Gianotto] [<*****@*****.**>] * @since [v2.0] * @param string $status * @return String JSON */ public function getDatatable($status = null) { $models = AssetModel::with('category', 'assets', 'depreciation'); switch ($status) { case 'Deleted': $models->withTrashed()->Deleted(); break; } if (Input::has('search')) { $models = $models->TextSearch(Input::get('search')); } if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } $allowed_columns = ['id', 'name', 'modelno']; $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at'; $models = $models->orderBy($sort, $order); $modelCount = $models->count(); $models = $models->skip($offset)->take($limit)->get(); $rows = array(); foreach ($models as $model) { if ($model->deleted_at == '') { $actions = '<div style=" white-space: nowrap;"><a href="' . route('clone/model', $model->id) . '" class="btn btn-info btn-sm" title="Clone Model" data-toggle="tooltip"><i class="fa fa-clone"></i></a> <a href="' . route('update/model', $model->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/model', $model->id) . '" data-content="' . trans('admin/models/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($model->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; } else { $actions = '<a href="' . route('restore/model', $model->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>'; } $rows[] = array('id' => $model->id, 'manufacturer' => (string) link_to('/admin/settings/manufacturers/' . $model->manufacturer->id . '/view', $model->manufacturer->name), 'name' => (string) link_to('/hardware/models/' . $model->id . '/view', $model->name), 'image' => $model->image != '' ? '<img src="' . config('app.url') . '/uploads/models/' . $model->image . '" height=50 width=50>' : '', 'modelnumber' => $model->modelno, 'numassets' => $model->assets->count(), 'depreciation' => $model->depreciation && $model->depreciation->id > 0 ? $model->depreciation->name . ' (' . $model->depreciation->months . ')' : trans('general.no_depreciation'), 'category' => $model->category ? $model->category->name : '', 'eol' => $model->eol ? $model->eol . ' ' . trans('general.months') : '', 'note' => $model->getNote(), 'actions' => $actions); } $data = array('total' => $modelCount, 'rows' => $rows); return $data; }