45 return View::make(
'models/index');
61 return View::make(
'models/edit')
62 ->with(
'category_list', $category_list)
63 ->with(
'depreciation_list', $depreciation_list)
64 ->with(
'manufacturer_list', $manufacturer_list)
83 if (e(Input::get(
'depreciation_id')) ==
'') {
84 $model->depreciation_id = 0;
86 $model->depreciation_id = e(Input::get(
'depreciation_id'));
89 if (e(Input::get(
'eol')) ==
'') {
92 $model->eol = e(Input::get(
'eol'));
96 $model->name = e(Input::get(
'name'));
97 $model->modelno = e(Input::get(
'modelno'));
98 $model->manufacturer_id = e(Input::get(
'manufacturer_id'));
99 $model->category_id = e(Input::get(
'category_id'));
100 $model->note = e(Input::get(
'note'));
101 $model->user_id = Auth::user()->id;
102 if (Input::get(
'custom_fieldset')!=
'') {
103 $model->fieldset_id = e(Input::get(
'custom_fieldset'));
109 if (Input::file(
'image')) {
110 $image = Input::file(
'image');
111 $file_name = str_random(25).
".".$image->getClientOriginalExtension();
112 $path = public_path(
'uploads/models/'.$file_name);
117 $model->image = $file_name;
121 if ($model->save()) {
123 return Redirect::to(
"hardware/models")->with(
'success', trans(
'admin/models/message.create.success'));
126 return Redirect::back()->withInput()->withErrors($model->getErrors());
143 $settings=Input::all();
148 $model->name=e(Input::get(
'name'));
149 $model->manufacturer_id = e(Input::get(
'manufacturer_id'));
150 $model->category_id = e(Input::get(
'category_id'));
151 $model->modelno = e(Input::get(
'modelno'));
152 $model->user_id = Auth::user()->id;
153 $model->note = e(Input::get(
'note'));
156 if ($model->save()) {
157 return JsonResponse::create($model);
159 return JsonResponse::create([
"error" =>
"Failed validation: ".print_r($model->getErrors()->all(
'<li>:message</li>'),
true)], 500);
175 if (is_null($model = AssetModel::find($modelId))) {
177 return Redirect::to(
'assets/models')->with(
'error', trans(
'admin/models/message.does_not_exist'));
183 $view = View::make(
'models/edit', compact(
'model'));
184 $view->with(
'category_list', $category_list);
185 $view->with(
'depreciation_list', $depreciation_list);
186 $view->with(
'manufacturer_list', $manufacturer_list);
203 if (is_null($model = AssetModel::find($modelId))) {
205 return Redirect::to(
'admin/models')->with(
'error', trans(
'admin/models/message.does_not_exist'));
209 if (e(Input::get(
'depreciation_id')) ==
'') {
210 $model->depreciation_id = 0;
212 $model->depreciation_id = e(Input::get(
'depreciation_id'));
215 if (e(Input::get(
'eol')) ==
'') {
218 $model->eol = e(Input::get(
'eol'));
222 $model->name = e(Input::get(
'name'));
223 $model->modelno = e(Input::get(
'modelno'));
224 $model->manufacturer_id = e(Input::get(
'manufacturer_id'));
225 $model->category_id = e(Input::get(
'category_id'));
226 $model->note = e(Input::get(
'note'));
227 if (Input::get(
'custom_fieldset')==
'') {
228 $model->fieldset_id = null;
230 $model->fieldset_id = e(Input::get(
'custom_fieldset'));
233 if (Input::file(
'image')) {
234 $image = Input::file(
'image');
235 $file_name = str_random(25).
".".$image->getClientOriginalExtension();
236 $path = public_path(
'uploads/models/'.$file_name);
237 Image::make($image->getRealPath())->resize(300, null,
function ($constraint) {
238 $constraint->aspectRatio();
239 $constraint->upsize();
241 $model->image = $file_name;
244 if (Input::get(
'image_delete') == 1 && Input::file(
'image') ==
"") {
245 $model->image = null;
249 if ($model->save()) {
251 return Redirect::to(
"hardware/models")->with(
'success', trans(
'admin/models/message.update.success'));
253 return redirect()->back()->withInput()->withErrors($model->getErrors());
258 return Redirect::to(
"hardware/models/$modelId/edit")->with(
'error', trans(
'admin/models/message.update.error'));
274 if (is_null($model = AssetModel::find($modelId))) {
276 return Redirect::to(
'hardware/models')->with(
'error', trans(
'admin/models/message.not_found'));
279 if ($model->assets->count() > 0) {
281 return Redirect::to(
'hardware/models')->with(
'error', trans(
'admin/models/message.assoc_users'));
288 return Redirect::to(
'hardware/models')->with(
'success', trans(
'admin/models/message.delete.success'));
305 $model = AssetModel::withTrashed()->find($modelId);
307 if (isset($model->id)) {
313 $success = trans(
'admin/models/message.restore.success');
316 return Redirect::back()->with(
'success', $success);
319 return Redirect::back()->with(
'error', trans(
'admin/models/message.not_found'));
335 $model = AssetModel::withTrashed()->find($modelId);
337 if (isset($model->id)) {
338 return View::make(
'models/view', compact(
'model'));
341 $error = trans(
'admin/models/message.does_not_exist', compact(
'id'));
344 return Redirect::route(
'models')->with(
'error', $error);
361 if (is_null($model_to_clone = AssetModel::find($modelId))) {
363 return Redirect::to(
'assets/models')->with(
'error', trans(
'admin/models/message.does_not_exist'));
366 $model = clone $model_to_clone;
370 $depreciation_list = array(
'' =>
'Do Not Depreciate') + Depreciation::lists(
'name',
'id');
371 $manufacturer_list = array(
'' =>
'Select One') + Manufacturer::lists(
'name',
'id');
372 $category_list = array(
'' =>
'') + DB::table(
'categories')->whereNull(
'deleted_at')->lists(
'name',
'id');
373 $view = View::make(
'models/edit');
374 $view->with(
'category_list', $category_list);
375 $view->with(
'depreciation_list', $depreciation_list);
376 $view->with(
'manufacturer_list', $manufacturer_list);
377 $view->with(
'model', $model);
378 $view->with(
'clone_model', $model_to_clone);
394 $model=AssetModel::find($modelId);
395 return View::make(
"models.custom_fields_form")->with(
"model", $model);
412 $models = AssetModel::with(
'category',
'assets',
'depreciation');
416 $models->withTrashed()->Deleted();
421 if (Input::has(
'search')) {
422 $models = $models->TextSearch(Input::get(
'search'));
425 if (Input::has(
'offset')) {
426 $offset = e(Input::get(
'offset'));
431 if (Input::has(
'limit')) {
432 $limit = e(Input::get(
'limit'));
438 $allowed_columns = [
'id',
'name',
'modelno'];
439 $order = Input::get(
'order') ===
'asc' ?
'asc' :
'desc';
440 $sort = in_array(Input::get(
'sort'), $allowed_columns) ? e(Input::get(
'sort')) :
'created_at';
442 $models = $models->orderBy($sort, $order);
444 $modelCount = $models->count();
445 $models = $models->skip($offset)->take($limit)->get();
449 foreach ($models as $model) {
450 if ($model->deleted_at ==
'') {
451 $actions =
'<div style=" white-space: nowrap;"><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>';
453 $actions =
'<a href="'.route(
'restore/model', $model->id).
'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
458 'manufacturer' => (
string)link_to(
'/admin/settings/manufacturers/'.$model->manufacturer->id.
'/view', $model->manufacturer->name),
459 'name' => (
string)link_to(
'/hardware/models/'.$model->id.
'/view', $model->name),
460 'image' => ($model->image!=
'') ?
'<img src="'.config(
'app.url').
'/uploads/models/'.$model->image.
'" height=50 width=50>' :
'',
461 'modelnumber' => $model->modelno,
462 'numassets' => $model->assets->count(),
463 'depreciation' => (($model->depreciation)&&($model->depreciation->id > 0)) ? $model->depreciation->name.
' ('.$model->depreciation->months.
')' : trans(
'general.no_depreciation'),
464 'category' => ($model->category) ? $model->category->name :
'',
465 'eol' => ($model->eol) ? $model->eol.
' '.trans(
'general.months') :
'',
466 'note' => $model->getNote(),
467 'actions' => $actions
471 $data = array(
'total' => $modelCount,
'rows' => $rows);
487 $assets = Asset::where(
'model_id',
'=', $modelID)->withTrashed()->with(
'company');
489 if (Input::has(
'search')) {
490 $assets = $assets->TextSearch(e(Input::get(
'search')));
493 if (Input::has(
'offset')) {
494 $offset = e(Input::get(
'offset'));
499 if (Input::has(
'limit')) {
500 $limit = e(Input::get(
'limit'));
506 $allowed_columns = [
'name',
'serial',
'asset_tag'];
507 $order = Input::get(
'order') ===
'asc' ?
'asc' :
'desc';
508 $sort = in_array(Input::get(
'sort'), $allowed_columns) ? e(Input::get(
'sort')) :
'created_at';
510 $assets = $assets->orderBy($sort, $order);
512 $assetsCount = $assets->count();
513 $assets = $assets->skip($offset)->take($limit)->get();
518 foreach ($assets as $asset) {
521 if ($asset->assetstatus) {
522 if ($asset->assetstatus->deployable != 0) {
523 if (($asset->assigned_to !=
'') && ($asset->assigned_to > 0)) {
524 $actions =
'<a href="'.route(
'checkin/hardware', $asset->id).
'" class="btn btn-primary btn-sm">'.trans(
'general.checkin').
'</a>';
526 $actions =
'<a href="'.route(
'checkout/hardware', $asset->id).
'" class="btn btn-info btn-sm">'.trans(
'general.checkout').
'</a>';
533 'name' => (
string)link_to(
'/hardware/'.$asset->id.
'/view', $asset->showAssetName()),
534 'asset_tag' => (
string)link_to(
'hardware/'.$asset->id.
'/view', $asset->asset_tag),
535 'serial' => $asset->serial,
536 'assigned_to' => ($asset->assigned_to) ? (
string)link_to(
'/admin/users/'.$asset->assigned_to.
'/view', $asset->assigneduser->fullName()) :
'',
537 'actions' => $actions,
542 $data = array(
'total' => $assetsCount,
'rows' => $rows);
getDatatable($status=null)
Get the JSON response to populate the data tables on the Asset Model listing page.
store()
Validates and stores new Asset Model data created from the modal form on the Asset Creation view...
static manufacturerList()
getView($modelId=null)
Get the model information to present to the model view page.
postCreate()
Validate and process the new Asset Model data.
postEdit($modelId=null)
Validates and processes form data from the edit Asset Model form based on the model ID passed...
getCustomFields($modelId)
Get the custom fields form.
getClone($modelId=null)
Get the clone page to clone a model.
getEdit($modelId=null)
Returns a view containing the asset model edit form.
This class controls all actions related to asset models for the Snipe-IT Asset Management application...
getDataView($modelID)
Get the asset information to present to the model view detail page.
getRestore($modelId=null)
Restore a given Asset Model (mark as un-deleted)
getIndex()
Returns a view that invokes the ajax tables which actually contains the content for the accessories l...
static getName($companyable)
getCreate()
Returns a view containing the asset model creation form.
getDelete($modelId)
Validate and delete the given Asset Model.
static depreciationList()