App\Http\Controllers\AssetsController Class Reference

This class controls all actions related to assets for the Snipe-IT Asset Management application. More...

Inheritance diagram for App\Http\Controllers\AssetsController:
App\Http\Controllers\Controller

Public Member Functions

 __construct ()
 
 getIndex ()
 Returns a view that invokes the ajax tables which actually contains the content for the assets listing, which is generated in getDatatable. More...
 
 getCreate ($model_id=null)
 Returns a view that presents a form to create a new asset. More...
 
 postCreate (AssetRequest $request)
 Validate and process new asset form data. More...
 
 getEdit ($assetId=null)
 Returns a view that presents a form to edit an existing asset. More...
 
 postEdit ($assetId=null)
 Validate and process asset edit form. More...
 
 getDelete ($assetId)
 Delete a given asset (mark as deleted). More...
 
 getCheckout ($assetId)
 Returns a view that presents a form to check an asset out to a user. More...
 
 postCheckout (AssetCheckoutRequest $request, $assetId)
 Validate and process the form data to check out an asset to a user. More...
 
 getCheckin ($assetId, $backto=null)
 Returns a view that presents a form to check an asset back into inventory. More...
 
 postCheckin (AssetCheckinRequest $request, $assetId=null, $backto=null)
 Validate and process the form data to check an asset back into inventory. More...
 
 getView ($assetId=null)
 Returns a view that presents information about an asset for detail view. More...
 
 getQrCode ($assetId=null)
 Return a QR code for the asset. More...
 
 getImportUpload ()
 Get the Asset import upload page. More...
 
 postAPIImportUpload (AssetFileRequest $request)
 Upload the import file via AJAX. More...
 
 getProcessImportFile ($filename)
 Process the uploaded file. More...
 
 getClone ($assetId=null)
 Returns a view that presents a form to clone an asset. More...
 
 getRestore ($assetId=null)
 Retore a deleted asset. More...
 
 postUpload (AssetFileRequest $request, $assetId=null)
 Upload a file to the server. More...
 
 getDeleteFile ($assetId=null, $fileId=null)
 Delete the associated file. More...
 
 displayFile ($assetId=null, $fileId=null)
 Check for permissions and display the file. More...
 
 postBulkEdit ($assets=null)
 Display the bulk edit page. More...
 
 postBulkSave ($assets=null)
 Save bulk edits. More...
 
 postBulkDelete ($assets=null)
 Save bulk deleted. More...
 
 getDatatable ($status=null)
 Generates the JSON used to display the asset listing. More...
 

Protected Attributes

 $qrCodeDimensions = array( 'height' => 3.5, 'width' => 3.5)
 
 $barCodeDimensions = array( 'height' => 2, 'width' => 22)
 

Detailed Description

This class controls all actions related to assets for the Snipe-IT Asset Management application.

Version
v1.0
Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]

Definition at line 50 of file AssetsController.php.

Constructor & Destructor Documentation

App\Http\Controllers\AssetsController::__construct ( )

Definition at line 56 of file AssetsController.php.

57  {
58  $this->middleware('auth');
59  parent::__construct();
60  }

Member Function Documentation

App\Http\Controllers\AssetsController::displayFile (   $assetId = null,
  $fileId = null 
)

Check for permissions and display the file.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
int$fileId
Since
[v1.0]
Returns
View

Definition at line 1036 of file AssetsController.php.

1037  {
1038 
1039  $asset = Asset::find($assetId);
1040 
1041  // the asset is valid
1042  if (isset($asset->id)) {
1043 
1044 
1045  if (!Company::isCurrentUserHasAccess($asset)) {
1046  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
1047  }
1048 
1049  $log = Actionlog::find($fileId);
1050  $file = $log->get_src('assets');
1051 
1052  $filetype = Helper::checkUploadIsImage($file);
1053 
1054  if ($filetype) {
1055  $contents = file_get_contents($file);
1056  return Response::make($contents)->header('Content-Type', $filetype);
1057  } else {
1058  return Response::download($file);
1059  }
1060 
1061  } else {
1062  // Prepare the error message
1063  $error = trans('admin/hardware/message.does_not_exist', compact('id'));
1064 
1065  // Redirect to the hardware management page
1066  return Redirect::route('hardware')->with('error', $error);
1067  }
1068  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static checkUploadIsImage($file)
Definition: Helper.php:265
App\Http\Controllers\AssetsController::getCheckin (   $assetId,
  $backto = null 
)

Returns a view that presents a form to check an asset back into inventory.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
string$backto
Since
[v1.0]
Returns
View

Definition at line 505 of file AssetsController.php.

506  {
507  // Check if the asset exists
508  if (is_null($asset = Asset::find($assetId))) {
509  // Redirect to the asset management page with error
510  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
511  } elseif (!Company::isCurrentUserHasAccess($asset)) {
512  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
513  }
514  $statusLabel_list = Helper::statusLabelList();
515  return View::make('hardware/checkin', compact('asset'))->with('statusLabel_list', $statusLabel_list)->with('backto', $backto);
516  }
static statusLabelList()
Definition: Helper.php:87
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AssetsController::getCheckout (   $assetId)

Returns a view that presents a form to check an asset out to a user.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
View

Definition at line 433 of file AssetsController.php.

434  {
435  // Check if the asset exists
436  if (is_null($asset = Asset::find(e($assetId)))) {
437  // Redirect to the asset management page with error
438  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
439  } elseif (!Company::isCurrentUserHasAccess($asset)) {
440  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
441  }
442 
443  // Get the dropdown of users and then pass it to the checkout view
444  $users_list = Helper::usersList();
445 
446  return View::make('hardware/checkout', compact('asset'))->with('users_list', $users_list);
447 
448  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static usersList()
Definition: Helper.php:138
App\Http\Controllers\AssetsController::getClone (   $assetId = null)

Returns a view that presents a form to clone an asset.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
View

Definition at line 854 of file AssetsController.php.

855  {
856  // Check if the asset exists
857  if (is_null($asset_to_clone = Asset::find($assetId))) {
858  // Redirect to the asset management page
859  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
860  } elseif (!Company::isCurrentUserHasAccess($asset_to_clone)) {
861  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
862  }
863 
864  // Grab the dropdown lists
865  $model_list = Helper::modelList();
866  $statuslabel_list = Helper::statusLabelList();
867  $location_list = Helper::locationsList();
868  $manufacturer_list = Helper::manufacturerList();
869  $category_list = Helper::categoryList();
870  $supplier_list = Helper::suppliersList();
871  $assigned_to =Helper::usersList();
872  $statuslabel_types = Helper::statusTypeList();
873  $company_list = Helper::companyList();
874 
875  $asset = clone $asset_to_clone;
876  $asset->id = null;
877  $asset->asset_tag = '';
878  $asset->serial = '';
879  $asset->assigned_to = '';
880 
881  return View::make('hardware/edit')
882  ->with('supplier_list', $supplier_list)
883  ->with('model_list', $model_list)
884  ->with('statuslabel_list', $statuslabel_list)
885  ->with('statuslabel_types', $statuslabel_types)
886  ->with('assigned_to', $assigned_to)
887  ->with('asset', $asset)
888  ->with('location_list', $location_list)
889  ->with('manufacturer', $manufacturer_list)
890  ->with('category', $category_list)
891  ->with('company_list', $company_list);
892 
893  }
static manufacturerList()
Definition: Helper.php:101
static categoryList()
Definition: Helper.php:70
static locationsList()
Definition: Helper.php:94
static companyList()
Definition: Helper.php:61
static statusLabelList()
Definition: Helper.php:87
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static modelList()
Definition: Helper.php:51
static suppliersList()
Definition: Helper.php:79
static statusTypeList()
Definition: Helper.php:109
static usersList()
Definition: Helper.php:138
App\Http\Controllers\AssetsController::getCreate (   $model_id = null)

Returns a view that presents a form to create a new asset.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.0]
Returns
View

Definition at line 84 of file AssetsController.php.

85  {
86  // Grab the dropdown lists
87  $model_list = Helper::modelList();
88  $statuslabel_list = Helper::statusLabelList();
89  $location_list = Helper::locationsList();
90  $manufacturer_list = Helper::manufacturerList();
91  $category_list = Helper::categoryList();
92  $supplier_list = Helper::suppliersList();
93  $company_list = Helper::companyList();
94  $assigned_to = Helper::usersList();
95  $statuslabel_types = Helper::statusTypeList();
96 
97  $view = View::make('hardware/edit');
98  $view->with('supplier_list', $supplier_list);
99  $view->with('company_list', $company_list);
100  $view->with('model_list', $model_list);
101  $view->with('statuslabel_list', $statuslabel_list);
102  $view->with('assigned_to', $assigned_to);
103  $view->with('location_list', $location_list);
104  $view->with('asset', new Asset);
105  $view->with('manufacturer', $manufacturer_list);
106  $view->with('category', $category_list);
107  $view->with('statuslabel_types', $statuslabel_types);
108 
109  if (!is_null($model_id)) {
110  $selected_model = AssetAssetModel::find($model_id);
111  $view->with('selected_model', $selected_model);
112  }
113 
114  return $view;
115  }
static manufacturerList()
Definition: Helper.php:101
static categoryList()
Definition: Helper.php:70
static locationsList()
Definition: Helper.php:94
static companyList()
Definition: Helper.php:61
static statusLabelList()
Definition: Helper.php:87
static modelList()
Definition: Helper.php:51
static suppliersList()
Definition: Helper.php:79
static statusTypeList()
Definition: Helper.php:109
static usersList()
Definition: Helper.php:138
App\Http\Controllers\AssetsController::getDatatable (   $status = null)

Generates the JSON used to display the asset listing.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
string$status
Since
[v2.0]
Returns
String JSON

Definition at line 1322 of file AssetsController.php.

1323  {
1324 
1325 
1326  $assets = Asset::select('assets.*')->with('model', 'assigneduser', 'assigneduser.userloc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.fieldset', 'assetstatus', 'assetloc', 'company')
1327  ->Hardware();
1328 
1329  if (Input::has('search')) {
1330  $assets = $assets->TextSearch(Input::get('search'));
1331  }
1332 
1333  if (Input::has('offset')) {
1334  $offset = e(Input::get('offset'));
1335  } else {
1336  $offset = 0;
1337  }
1338 
1339  if (Input::has('limit')) {
1340  $limit = e(Input::get('limit'));
1341  } else {
1342  $limit = 50;
1343  }
1344 
1345  if (Input::has('order_number')) {
1346  $assets->where('order_number', '=', e(Input::get('order_number')));
1347  }
1348 
1349  switch ($status) {
1350  case 'Deleted':
1351  $assets->withTrashed()->Deleted();
1352  break;
1353  case 'Pending':
1354  $assets->Pending();
1355  break;
1356  case 'RTD':
1357  $assets->RTD();
1358  break;
1359  case 'Undeployable':
1360  $assets->Undeployable();
1361  break;
1362  case 'Archived':
1363  $assets->Archived();
1364  break;
1365  case 'Requestable':
1366  $assets->RequestableAssets();
1367  break;
1368  case 'Deployed':
1369  $assets->Deployed();
1370  break;
1371 
1372  }
1373 
1374  $allowed_columns = [
1375  'id',
1376  'name',
1377  'asset_tag',
1378  'serial',
1379  'model',
1380  'last_checkout',
1381  'category',
1382  'notes',
1383  'expected_checkin',
1384  'order_number',
1385  'companyName',
1386  'location',
1387  'image',
1388  'status_label',
1389  'assigned_to'
1390  ];
1391 
1392  $all_custom_fields=CustomField::all(); //used as a 'cache' of custom fields throughout this page load
1393 
1394  foreach ($all_custom_fields as $field) {
1395  $allowed_columns[]=$field->db_column_name();
1396  }
1397 
1398  $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
1399  $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'asset_tag';
1400 
1401  switch ($sort) {
1402  case 'model':
1403  $assets = $assets->OrderModels($order);
1404  break;
1405  case 'category':
1406  $assets = $assets->OrderCategory($order);
1407  break;
1408  case 'companyName':
1409  $assets = $assets->OrderCompany($order);
1410  break;
1411  case 'location':
1412  $assets = $assets->OrderLocation($order);
1413  break;
1414  case 'status_label':
1415  $assets = $assets->OrderStatus($order);
1416  break;
1417  case 'assigned_to':
1418  $assets = $assets->OrderAssigned($order);
1419  break;
1420  default:
1421  $assets = $assets->orderBy($sort, $order);
1422  break;
1423  }
1424 
1425  $assetCount = $assets->count();
1426  $assets = $assets->skip($offset)->take($limit)->get();
1427 
1428 
1429  $rows = array();
1430  foreach ($assets as $asset) {
1431  $inout = '';
1432  $actions = '';
1433  if ($asset->deleted_at=='') {
1434  $actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset" data-toggle="tooltip"><i class="fa fa-clone"></i></a> <a href="'.route('update/hardware', $asset->id).'" class="btn btn-warning btn-sm" title="Edit asset" data-toggle="tooltip"><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/hardware', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
1435  } elseif ($asset->model->deleted_at=='') {
1436  $actions = '<a href="'.route('restore/hardware', $asset->id).'" title="Restore asset" data-toggle="tooltip" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
1437  }
1438 
1439  if ($asset->assetstatus) {
1440  if ($asset->assetstatus->deployable != 0) {
1441  if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) {
1442  $inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm" title="Checkin this asset" data-toggle="tooltip">'.trans('general.checkin').'</a>';
1443  } else {
1444  $inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Checkout this asset to a user" data-toggle="tooltip">'.trans('general.checkout').'</a>';
1445  }
1446  }
1447  }
1448 
1449  $row = array(
1450  'checkbox' =>'<div class="text-center"><input type="checkbox" name="edit_asset['.$asset->id.']" class="one_required"></div>',
1451  'id' => $asset->id,
1452  'image' => (($asset->image) && ($asset->image!='')) ? '<img src="'.config('app.url').'/uploads/assets/'.$asset->image.'" height=50 width=50>' : ((($asset->model) && ($asset->model->image!='')) ? '<img src="'.config('app.url').'/uploads/models/'.$asset->model->image.'" height=40 width=50>' : ''),
1453  'name' => '<a title="'.e($asset->name).'" href="hardware/'.$asset->id.'/view">'.e($asset->name).'</a>',
1454  'asset_tag' => '<a title="'.e($asset->asset_tag).'" href="hardware/'.$asset->id.'/view">'.e($asset->asset_tag).'</a>',
1455  'serial' => e($asset->serial),
1456  'model' => ($asset->model) ? (string)link_to('/hardware/models/'.$asset->model->id.'/view', e($asset->model->name)) : 'No model',
1457  'status_label' => ($asset->assigneduser) ? 'Deployed' : ((e($asset->assetstatus)) ? e($asset->assetstatus->name) : ''),
1458  'assigned_to' => ($asset->assigneduser) ? (string)link_to('../admin/users/'.$asset->assigned_to.'/view', e($asset->assigneduser->fullName())) : '',
1459  'location' => (($asset->assigneduser) && ($asset->assigneduser->userloc!='')) ? (string)link_to('admin/settings/locations/'.$asset->assigneduser->userloc->id.'/edit', e($asset->assigneduser->userloc->name)) : (($asset->defaultLoc!='') ? (string)link_to('admin/settings/locations/'.$asset->defaultLoc->id.'/edit', e($asset->defaultLoc->name)) : ''),
1460  'category' => (($asset->model) && ($asset->model->category)) ? e($asset->model->category->name) : '',
1461  'eol' => ($asset->eol_date()) ? $asset->eol_date() : '',
1462  'notes' => e($asset->notes),
1463  'order_number' => ($asset->order_number!='') ? '<a href="'.config('app.url').'/hardware?order_number='.e($asset->order_number).'">'.e($asset->order_number).'</a>' : '',
1464  'last_checkout' => ($asset->last_checkout!='') ? e($asset->last_checkout) : '',
1465  'expected_checkin' => ($asset->expected_checkin!='') ? e($asset->expected_checkin) : '',
1466  'change' => ($inout) ? $inout : '',
1467  'actions' => ($actions) ? $actions : '',
1468  'companyName' => is_null($asset->company) ? '' : e($asset->company->name)
1469  );
1470  foreach ($all_custom_fields as $field) {
1471  $row[$field->db_column_name()]=$asset->{$field->db_column_name()};
1472  }
1473  $rows[]=$row;
1474  }
1475 
1476  $data = array('total'=>$assetCount, 'rows'=>$rows);
1477 
1478  return $data;
1479  }
App\Http\Controllers\AssetsController::getDelete (   $assetId)

Delete a given asset (mark as deleted).

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
Redirect

Definition at line 399 of file AssetsController.php.

400  {
401  // Check if the asset exists
402  if (is_null($asset = Asset::find($assetId))) {
403  // Redirect to the asset management page with error
404  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
405  } elseif (!Company::isCurrentUserHasAccess($asset)) {
406  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
407  }
408 
409  DB::table('assets')
410  ->where('id', $asset->id)
411  ->update(array('assigned_to' => null));
412 
413 
414  $asset->delete();
415 
416  // Redirect to the asset management page
417  return Redirect::to('hardware')->with('success', trans('admin/hardware/message.delete.success'));
418 
419 
420 
421 
422  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AssetsController::getDeleteFile (   $assetId = null,
  $fileId = null 
)

Delete the associated file.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
int$fileId
Since
[v1.0]
Returns
View

Definition at line 995 of file AssetsController.php.

996  {
997  $asset = Asset::find($assetId);
998  $destinationPath = config('app.private_uploads').'/imports/assets';
999 
1000  // the asset is valid
1001  if (isset($asset->id)) {
1002 
1003 
1004  if (!Company::isCurrentUserHasAccess($asset)) {
1005  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
1006  }
1007 
1008  $log = Actionlog::find($fileId);
1009  $full_filename = $destinationPath.'/'.$log->filename;
1010  if (file_exists($full_filename)) {
1011  unlink($destinationPath.'/'.$log->filename);
1012  }
1013  $log->delete();
1014  return Redirect::back()->with('success', trans('admin/hardware/message.deletefile.success'));
1015 
1016  } else {
1017  // Prepare the error message
1018  $error = trans('admin/hardware/message.does_not_exist', compact('id'));
1019 
1020  // Redirect to the hardware management page
1021  return Redirect::route('hardware')->with('error', $error);
1022  }
1023  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AssetsController::getEdit (   $assetId = null)

Returns a view that presents a form to edit an existing asset.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
View

Definition at line 232 of file AssetsController.php.

233  {
234  // Check if the asset exists
235  if (is_null($asset = Asset::find($assetId))) {
236  // Redirect to the asset management page
237  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
238  } elseif (!Company::isCurrentUserHasAccess($asset)) {
239  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
240  }
241 
242  // Grab the dropdown lists
243  $model_list = Helper::modelList();
244  $statuslabel_list = Helper::statusLabelList();
245  $location_list = Helper::locationsList();
246  $manufacturer_list = Helper::manufacturerList();
247  $category_list = Helper::categoryList();
248  $supplier_list = Helper::suppliersList();
249  $company_list = Helper::companyList();
250  $assigned_to = Helper::usersList();
251  $statuslabel_types =Helper:: statusTypeList();
252 
253  return View::make('hardware/edit', compact('asset'))
254  ->with('model_list', $model_list)
255  ->with('supplier_list', $supplier_list)
256  ->with('company_list', $company_list)
257  ->with('location_list', $location_list)
258  ->with('statuslabel_list', $statuslabel_list)
259  ->with('assigned_to', $assigned_to)
260  ->with('manufacturer', $manufacturer_list)
261  ->with('statuslabel_types', $statuslabel_types)
262  ->with('category', $category_list);
263  }
static manufacturerList()
Definition: Helper.php:101
static categoryList()
Definition: Helper.php:70
static locationsList()
Definition: Helper.php:94
static companyList()
Definition: Helper.php:61
static statusLabelList()
Definition: Helper.php:87
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static modelList()
Definition: Helper.php:51
static suppliersList()
Definition: Helper.php:79
static statusTypeList()
Definition: Helper.php:109
static usersList()
Definition: Helper.php:138
App\Http\Controllers\AssetsController::getImportUpload ( )

Get the Asset import upload page.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v2.0]
Returns
View

Definition at line 729 of file AssetsController.php.

730  {
731 
732  $path = config('app.private_uploads').'/imports/assets';
733  $files = array();
734 
736  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
737  }
738 
739  if ($handle = opendir($path)) {
740 
741  /* This is the correct way to loop over the directory. */
742  while (false !== ($entry = readdir($handle))) {
743  clearstatcache();
744  if (substr(strrchr($entry, '.'), 1)=='csv') {
745  $files[] = array(
746  'filename' => $entry,
747  'filesize' => Setting::fileSizeConvert(filesize($path.'/'.$entry)),
748  'modified' => filemtime($path.'/'.$entry)
749  );
750  }
751 
752  }
753  closedir($handle);
754  $files = array_reverse($files);
755  }
756 
757  return View::make('hardware/import')->with('files', $files);
758  }
static isCurrentUserAuthorized()
Definition: Company.php:110
static fileSizeConvert($bytes)
Converts bytes into human readable file size.
Definition: Setting.php:78
App\Http\Controllers\AssetsController::getIndex ( )

Returns a view that invokes the ajax tables which actually contains the content for the assets listing, which is generated in getDatatable.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
AssetController::getDatatable() method that generates the JSON response
Since
[v1.0]
Returns
View

Definition at line 72 of file AssetsController.php.

73  {
74  return View::make('hardware/index');
75  }
App\Http\Controllers\AssetsController::getProcessImportFile (   $filename)

Process the uploaded file.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
string$filename
Since
[v2.0]
Returns
Redirect

Definition at line 827 of file AssetsController.php.

828  {
829  // php artisan asset-import:csv path/to/your/file.csv --domain=yourdomain.com --email_format=firstname.lastname
830 
832  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
833  }
834 
835  $output = new BufferedOutput;
836  Artisan::call('asset-import:csv', ['filename'=> config('app.private_uploads').'/imports/assets/'.$filename, '--email_format'=>'firstname.lastname', '--username_format'=>'firstname.lastname'], $output);
837  $display_output = $output->fetch();
838  $file = config('app.private_uploads').'/imports/assets/'.str_replace('.csv', '', $filename).'-output-'.date("Y-m-d-his").'.txt';
839  file_put_contents($file, $display_output);
840 
841 
842  return Redirect::to('hardware')->with('success', 'Your file has been imported');
843 
844  }
static isCurrentUserAuthorized()
Definition: Company.php:110
App\Http\Controllers\AssetsController::getQrCode (   $assetId = null)

Return a QR code for the asset.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
Response

Definition at line 699 of file AssetsController.php.

700  {
701  $settings = Setting::getSettings();
702 
703  if ($settings->qr_code == '1') {
704  $asset = Asset::find($assetId);
705  $size = Helper::barcodeDimensions($settings->barcode_type);
706 
707  if (!Company::isCurrentUserHasAccess($asset)) {
708  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
709  }
710 
711  if (isset($asset->id,$asset->asset_tag)) {
712  $barcode = new \Com\Tecnick\Barcode\Barcode();
713  $barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('view/hardware', $asset->id), $size['height'], $size['width'], 'black', array(-2, -2, -2, -2));
714 
715  return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
716  }
717  }
718 
719  }
static barcodeDimensions($barcode_type= 'QRCODE')
Definition: Helper.php:171
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static getSettings()
Definition: Setting.php:33
App\Http\Controllers\AssetsController::getRestore (   $assetId = null)

Retore a deleted asset.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
View

Definition at line 904 of file AssetsController.php.

905  {
906 
907  // Get user information
908  $asset = Asset::withTrashed()->find($assetId);
909 
910  if (!Company::isCurrentUserHasAccess($asset)) {
911  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
912  } elseif (isset($asset->id)) {
913 
914  // Restore the user
915  $asset->restore();
916 
917  // Prepare the success message
918  $success = trans('admin/hardware/message.restore.success');
919 
920  // Redirect to the user management page
921  return Redirect::route('hardware')->with('success', $success);
922 
923  } else {
924  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
925  }
926 
927  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AssetsController::getView (   $assetId = null)

Returns a view that presents information about an asset for detail view.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
View

Definition at line 649 of file AssetsController.php.

650  {
651  $asset = Asset::withTrashed()->find($assetId);
652  $settings = Setting::getSettings();
653 
654  if (!Company::isCurrentUserHasAccess($asset)) {
655  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
656  } elseif ($asset->userloc) {
657  $use_currency = $asset->userloc->currency;
658  } elseif ($asset->assetloc) {
659  $use_currency = $asset->assetloc->currency;
660  } else {
661  $default_currency = Setting::first()->default_currency;
662 
663  if ($settings->default_currency!='') {
664  $use_currency = $settings->default_currency;
665  } else {
666  $use_currency = trans('general.currency');
667  }
668 
669  }
670 
671  if (isset($asset->id)) {
672 
673 
674 
675  $qr_code = (object) array(
676  'display' => $settings->qr_code == '1',
677  'url' => route('qr_code/hardware', $asset->id)
678  );
679 
680  return View::make('hardware/view', compact('asset', 'qr_code', 'settings'))->with('use_currency', $use_currency);
681  } else {
682  // Prepare the error message
683  $error = trans('admin/hardware/message.does_not_exist', compact('id'));
684 
685  // Redirect to the user management page
686  return Redirect::route('hardware')->with('error', $error);
687  }
688 
689  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static getSettings()
Definition: Setting.php:33
App\Http\Controllers\AssetsController::postAPIImportUpload ( AssetFileRequest  $request)

Upload the import file via AJAX.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v2.0]
Returns
View

Definition at line 769 of file AssetsController.php.

770  {
771 
773  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
774 
775  } elseif (!config('app.lock_passwords')) {
776 
777  $files = Input::file('files');
778  $path = config('app.private_uploads').'/imports/assets';
779  $results = array();
780 
781  foreach ($files as $file) {
782 
783  if (!in_array($file->getMimeType(), array(
784  'application/vnd.ms-excel',
785  'text/csv',
786  'text/plain',
787  'text/comma-separated-values',
788  'text/tsv'))) {
789  $results['error']='File type must be CSV';
790  return $results;
791  }
792 
793  $date = date('Y-m-d-his');
794  $fixed_filename = str_replace(' ', '-', $file->getClientOriginalName());
795  $file->move($path, $date.'-'.$fixed_filename);
796  $name = date('Y-m-d-his').'-'.$fixed_filename;
797  $filesize = Setting::fileSizeConvert(filesize($path.'/'.$name));
798  $results[] = compact('name', 'filesize');
799  }
800 
801  return array(
802  'files' => $results
803  );
804 
805 
806 
807 
808  } else {
809 
810  $results['error']=trans('general.feature_disabled');
811  return $results;
812  }
813 
814 
815 
816  }
static isCurrentUserAuthorized()
Definition: Company.php:110
static fileSizeConvert($bytes)
Converts bytes into human readable file size.
Definition: Setting.php:78
App\Http\Controllers\AssetsController::postBulkDelete (   $assets = null)

Save bulk deleted.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
array$assets
Since
[v2.0]
Returns
View

Definition at line 1269 of file AssetsController.php.

1270  {
1271 
1273  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
1274  } elseif (Input::has('bulk_edit')) {
1275  //$assets = Input::get('bulk_edit');
1276  $assets = Asset::find(Input::get('bulk_edit'));
1277  //print_r($assets);
1278 
1279 
1280  foreach ($assets as $asset) {
1281  //echo '<li>'.$asset;
1282  $update_array['deleted_at'] = date('Y-m-d h:i:s');
1283  $update_array['assigned_to'] = null;
1284 
1285  if (DB::table('assets')
1286  ->where('id', $asset->id)
1287  ->update($update_array)) {
1288 
1289  $logaction = new Actionlog();
1290  $logaction->asset_id = $asset->id;
1291  $logaction->asset_type = 'hardware';
1292  $logaction->created_at = date("Y-m-d H:i:s");
1293  $logaction->user_id = Auth::user()->id;
1294  $log = $logaction->logaction('deleted');
1295 
1296  }
1297 
1298  } // endforeach
1299  return Redirect::to("hardware")->with('success', trans('admin/hardware/message.delete.success'));
1300 
1301  // no values given, nothing to update
1302  } else {
1303  return Redirect::to("hardware")->with('info', trans('admin/hardware/message.delete.nothing_updated'));
1304 
1305  }
1306 
1307  // Something weird happened here - default to hardware
1308  return Redirect::to("hardware");
1309 
1310  }
static isCurrentUserAuthorized()
Definition: Company.php:110
App\Http\Controllers\AssetsController::postBulkEdit (   $assets = null)

Display the bulk edit page.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v2.0]
Returns
View

Definition at line 1081 of file AssetsController.php.

1082  {
1083 
1085  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
1086 
1087  } elseif (!Input::has('edit_asset')) {
1088  return Redirect::back()->with('error', 'No assets selected');
1089 
1090  } else {
1091  $asset_raw_array = Input::get('edit_asset');
1092  foreach ($asset_raw_array as $asset_id => $value) {
1093  $asset_ids[] = $asset_id;
1094 
1095  }
1096 
1097  }
1098 
1099  if (Input::has('bulk_actions')) {
1100 
1101 
1102  // Create labels
1103  if (Input::get('bulk_actions')=='labels') {
1104 
1105 
1106  $settings = Setting::getSettings();
1107  if ($settings->qr_code=='1') {
1108 
1109  $assets = Asset::find($asset_ids);
1110  $assetcount = count($assets);
1111  $count = 0;
1112 
1113  return View::make('hardware/labels')->with('assets', $assets)->with('settings', $settings)->with('count', $count)->with('settings', $settings);
1114 
1115  } else {
1116  // QR codes are not enabled
1117  return Redirect::to("hardware")->with('error', 'Barcodes are not enabled in Admin > Settings');
1118  }
1119 
1120  } elseif (Input::get('bulk_actions')=='delete') {
1121 
1122 
1123  $assets = Asset::with('assigneduser', 'assetloc')->find($asset_ids);
1124  return View::make('hardware/bulk-delete')->with('assets', $assets);
1125 
1126  // Bulk edit
1127  } elseif (Input::get('bulk_actions')=='edit') {
1128 
1129  $assets = Input::get('edit_asset');
1130  $supplier_list = Helper::suppliersList();
1131  $statuslabel_list = Helper::statusLabelList();
1132  $location_list = Helper::locationsList();
1133  $models_list = Helper::modelList();
1134  $companies_list = array('' => '') + array('clear' => trans('general.remove_company')) + Helper::companyList();
1135 
1136  return View::make('hardware/bulk')
1137  ->with('assets', $assets)
1138  ->with('supplier_list', $supplier_list)
1139  ->with('statuslabel_list', $statuslabel_list)
1140  ->with('location_list', $location_list)
1141  ->with('models_list', $models_list)
1142  ->with('companies_list', $companies_list);
1143 
1144 
1145  }
1146 
1147  } else {
1148  return Redirect::back()->with('error', 'No action selected');
1149  }
1150 
1151 
1152 
1153  }
static locationsList()
Definition: Helper.php:94
static companyList()
Definition: Helper.php:61
static statusLabelList()
Definition: Helper.php:87
static modelList()
Definition: Helper.php:51
static getSettings()
Definition: Setting.php:33
static isCurrentUserAuthorized()
Definition: Company.php:110
static suppliersList()
Definition: Helper.php:79
App\Http\Controllers\AssetsController::postBulkSave (   $assets = null)

Save bulk edits.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
array$assets
Since
[v2.0]
Returns
Redirect

Definition at line 1165 of file AssetsController.php.

1166  {
1167 
1169  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
1170 
1171  } elseif (Input::has('bulk_edit')) {
1172 
1173  $assets = Input::get('bulk_edit');
1174 
1175  if ((Input::has('purchase_date')) || (Input::has('purchase_cost')) || (Input::has('supplier_id')) || (Input::has('order_number')) || (Input::has('warranty_months')) || (Input::has('rtd_location_id')) || (Input::has('requestable')) || (Input::has('company_id')) || (Input::has('status_id')) || (Input::has('model_id'))) {
1176 
1177  foreach ($assets as $key => $value) {
1178 
1179  $update_array = array();
1180 
1181  if (Input::has('purchase_date')) {
1182  $update_array['purchase_date'] = e(Input::get('purchase_date'));
1183  }
1184 
1185  if (Input::has('purchase_cost')) {
1186  $update_array['purchase_cost'] = e(Input::get('purchase_cost'));
1187  }
1188 
1189  if (Input::has('supplier_id')) {
1190  $update_array['supplier_id'] = e(Input::get('supplier_id'));
1191  }
1192 
1193  if (Input::has('model_id')) {
1194  $update_array['model_id'] = e(Input::get('model_id'));
1195  }
1196 
1197  if (Input::has('company_id')) {
1198  if (Input::get('company_id')=="clear") {
1199  $update_array['company_id'] = null;
1200  } else {
1201  $update_array['company_id'] = e(Input::get('company_id'));
1202  }
1203 
1204  }
1205 
1206  if (Input::has('order_number')) {
1207  $update_array['order_number'] = e(Input::get('order_number'));
1208  }
1209 
1210  if (Input::has('warranty_months')) {
1211  $update_array['warranty_months'] = e(Input::get('warranty_months'));
1212  }
1213 
1214  if (Input::has('rtd_location_id')) {
1215  $update_array['rtd_location_id'] = e(Input::get('rtd_location_id'));
1216  }
1217 
1218  if (Input::has('status_id')) {
1219  $update_array['status_id'] = e(Input::get('status_id'));
1220  }
1221 
1222  if (Input::has('requestable')) {
1223  $update_array['requestable'] = e(Input::get('requestable'));
1224  }
1225 
1226 
1227  if (DB::table('assets')
1228  ->where('id', $key)
1229  ->update($update_array)) {
1230 
1231  $logaction = new Actionlog();
1232  $logaction->asset_id = $key;
1233  $logaction->asset_type = 'hardware';
1234  $logaction->created_at = date("Y-m-d H:i:s");
1235 
1236  if (Input::has('rtd_location_id')) {
1237  $logaction->location_id = e(Input::get('rtd_location_id'));
1238  }
1239  $logaction->user_id = Auth::user()->id;
1240  $log = $logaction->logaction('update');
1241 
1242  }
1243 
1244  } // endforeach
1245 
1246  return Redirect::to("hardware")->with('success', trans('admin/hardware/message.update.success'));
1247 
1248  // no values given, nothing to update
1249  } else {
1250  return Redirect::to("hardware")->with('info', trans('admin/hardware/message.update.nothing_updated'));
1251 
1252  }
1253 
1254 
1255  } // endif
1256 
1257  return Redirect::to("hardware");
1258 
1259  }
static isCurrentUserAuthorized()
Definition: Company.php:110
App\Http\Controllers\AssetsController::postCheckin ( AssetCheckinRequest  $request,
  $assetId = null,
  $backto = null 
)

Validate and process the form data to check an asset back into inventory.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
Redirect

Definition at line 527 of file AssetsController.php.

528  {
529  // Check if the asset exists
530  if (is_null($asset = Asset::find($assetId))) {
531  // Redirect to the asset management page with error
532  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
533  } elseif (!Company::isCurrentUserHasAccess($asset)) {
534  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
535  }
536 
537  // Check for a valid user to checkout fa-random
538  // This will need to be tweaked for checkout to location
539  if (!is_null($asset->assigned_to)) {
540  $user = User::find($asset->assigned_to);
541  } else {
542  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.checkin.already_checked_in'));
543  }
544 
545  // This is just used for the redirect
546  $return_to = $asset->assigned_to;
547 
548  $logaction = new Actionlog();
549  $logaction->checkedout_to = $asset->assigned_to;
550 
551  // Update the asset data to null, since it's being checked in
552  $asset->assigned_to = null;
553  $asset->accepted = null;
554 
555  $asset->expected_checkin = null;
556  $asset->last_checkout = null;
557 
558  if (Input::has('status_id')) {
559  $asset->status_id = e(Input::get('status_id'));
560  }
561  // Was the asset updated?
562  if ($asset->save()) {
563 
564  if (Input::has('checkin_at')) {
565 
566  if (!strtotime(Input::get('checkin_at'))) {
567  $logaction->created_at = date("Y-m-d H:i:s");
568  } elseif (Input::get('checkin_at')!= date("Y-m-d")) {
569  $logaction->created_at = e(Input::get('checkin_at')).' 00:00:00';
570  }
571  }
572 
573  $logaction->asset_id = $asset->id;
574  $logaction->location_id = null;
575  $logaction->asset_type = 'hardware';
576  $logaction->note = e(Input::get('note'));
577  $logaction->user_id = Auth::user()->id;
578  $log = $logaction->logaction('checkin from');
579  $settings = Setting::getSettings();
580 
581  if ($settings->slack_endpoint) {
582 
583  $slack_settings = [
584  'username' => $settings->botname,
585  'channel' => $settings->slack_channel,
586  'link_names' => true
587  ];
588 
589  $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
590 
591  try {
592  $client->attach([
593  'color' => 'good',
594  'fields' => [
595  [
596  'title' => 'Checked In:',
597  'value' => strtoupper($logaction->asset_type).' asset <'.config('app.url').'/hardware/'.$asset->id.'/view'.'|'.e($asset->showAssetName()).'> checked in by <'.config('app.url').'/hardware/'.$asset->id.'/view'.'|'.e(Auth::user()->fullName()).'>.'
598  ],
599  [
600  'title' => 'Note:',
601  'value' => e($logaction->note)
602  ],
603 
604  ]
605  ])->send('Asset Checked In');
606 
607  } catch (Exception $e) {
608 
609  }
610 
611  }
612 
613  $data['log_id'] = $logaction->id;
614  $data['first_name'] = $user->first_name;
615  $data['item_name'] = $asset->showAssetName();
616  $data['checkin_date'] = $logaction->created_at;
617  $data['item_tag'] = $asset->asset_tag;
618  $data['item_serial'] = $asset->serial;
619  $data['note'] = $logaction->note;
620 
621  if ((($asset->checkin_email()=='1')) && ($user) && (!config('app.lock_passwords'))) {
622  Mail::send('emails.checkin-asset', $data, function ($m) use ($user) {
623  $m->to($user->email, $user->first_name . ' ' . $user->last_name);
624  $m->subject('Confirm Asset Checkin');
625  });
626  }
627 
628  if ($backto=='user') {
629  return Redirect::to("admin/users/".$return_to.'/view')->with('success', trans('admin/hardware/message.checkin.success'));
630  } else {
631  return Redirect::to("hardware")->with('success', trans('admin/hardware/message.checkin.success'));
632  }
633 
634  }
635 
636  // Redirect to the asset management page with error
637  return Redirect::to("hardware")->with('error', trans('admin/hardware/message.checkin.error'));
638  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static getSettings()
Definition: Setting.php:33
App\Http\Controllers\AssetsController::postCheckout ( AssetCheckoutRequest  $request,
  $assetId 
)

Validate and process the form data to check out an asset to a user.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
Redirect

Definition at line 458 of file AssetsController.php.

459  {
460 
461  // Check if the asset exists
462  if (!$asset = Asset::find($assetId)) {
463  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
464  } elseif (!Company::isCurrentUserHasAccess($asset)) {
465  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
466  }
467 
468  $user = User::find(e(Input::get('assigned_to')));
469  $admin = Auth::user();
470 
471 
472 
473  if (Input::get('checkout_at')!= date("Y-m-d")) {
474  $checkout_at = e(Input::get('checkout_at')).' 00:00:00';
475  } else {
476  $checkout_at = date("Y-m-d H:i:s");
477  }
478 
479  if (Input::has('expected_checkin')) {
480  $expected_checkin = e(Input::get('expected_checkin'));
481  } else {
482  $expected_checkin = '';
483  }
484 
485 
486  if ($asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), e(Input::get('name')))) {
487  // Redirect to the new asset page
488  return Redirect::to("hardware")->with('success', trans('admin/hardware/message.checkout.success'));
489  }
490 
491  // Redirect to the asset management page with error
492  return Redirect::to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors());
493  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AssetsController::postCreate ( AssetRequest  $request)

Validate and process new asset form data.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.0]
Returns
Redirect

Definition at line 124 of file AssetsController.php.

125  {
126  // create a new model instance
127  $asset = new Asset();
128  $asset->model()->associate(AssetModel::find(e(Input::get('model_id'))));
129 
130  $checkModel = config('app.url').'/api/models/'.e(Input::get('model_id')).'/check';
131 
132  $asset->name = e(Input::get('name'));
133  $asset->serial = e(Input::get('serial'));
134  $asset->company_id = Company::getIdForCurrentUser(e(Input::get('company_id')));
135  $asset->model_id = e(Input::get('model_id'));
136  $asset->order_number = e(Input::get('order_number'));
137  $asset->notes = e(Input::get('notes'));
138  $asset->asset_tag = e(Input::get('asset_tag'));
139  $asset->user_id = Auth::user()->id;
140  $asset->archived = '0';
141  $asset->physical = '1';
142  $asset->depreciate = '0';
143  if (e(Input::get('status_id')) == '') {
144  $asset->status_id = null;
145  } else {
146  $asset->status_id = e(Input::get('status_id'));
147  }
148 
149  if (e(Input::get('warranty_months')) == '') {
150  $asset->warranty_months = null;
151  } else {
152  $asset->warranty_months = e(Input::get('warranty_months'));
153  }
154 
155  if (e(Input::get('purchase_cost')) == '') {
156  $asset->purchase_cost = null;
157  } else {
158  $asset->purchase_cost = \App\Helpers\Helper::ParseFloat(e(Input::get('purchase_cost')));
159  }
160 
161  if (e(Input::get('purchase_date')) == '') {
162  $asset->purchase_date = null;
163  } else {
164  $asset->purchase_date = e(Input::get('purchase_date'));
165  }
166 
167  if (e(Input::get('assigned_to')) == '') {
168  $asset->assigned_to = null;
169  } else {
170  $asset->assigned_to = e(Input::get('assigned_to'));
171  }
172 
173  if (e(Input::get('supplier_id')) == '') {
174  $asset->supplier_id = 0;
175  } else {
176  $asset->supplier_id = e(Input::get('supplier_id'));
177  }
178 
179  if (e(Input::get('requestable')) == '') {
180  $asset->requestable = 0;
181  } else {
182  $asset->requestable = e(Input::get('requestable'));
183  }
184 
185  if (e(Input::get('rtd_location_id')) == '') {
186  $asset->rtd_location_id = null;
187  } else {
188  $asset->rtd_location_id = e(Input::get('rtd_location_id'));
189  }
190 
191  // Create the image (if one was chosen.)
192  if (Input::file('image')) {
193  $image = Input::file('image');
194  $file_name = str_random(25).".".$image->getClientOriginalExtension();
195  $path = public_path('uploads/assets/'.$file_name);
196  Image::make($image->getRealPath())->resize(300, null, function ($constraint) {
197  $constraint->aspectRatio();
198  $constraint->upsize();
199  })->save($path);
200  $asset->image = $file_name;
201 
202  }
203 
204  // Was the asset created?
205  if ($asset->save()) {
206 
207  if (Input::get('assigned_to')!='') {
208  $logaction = new Actionlog();
209  $logaction->asset_id = $asset->id;
210  $logaction->checkedout_to = $asset->assigned_to;
211  $logaction->asset_type = 'hardware';
212  $logaction->user_id = Auth::user()->id;
213  $logaction->note = e(Input::get('note'));
214  $log = $logaction->logaction('checkout');
215  }
216  // Redirect to the asset listing page
217  return Redirect::to("hardware")->with('success', trans('admin/hardware/message.create.success'));
218  }
219 
220  return Redirect::back()->withInput()->withErrors($asset->getErrors());
221 
222  }
static getIdForCurrentUser($unescaped_input)
Definition: Company.php:81
static ParseFloat($floatString)
Definition: Helper.php:41
App\Http\Controllers\AssetsController::postEdit (   $assetId = null)

Validate and process asset edit form.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
Redirect

Definition at line 274 of file AssetsController.php.

275  {
276  // Check if the asset exists
277  if (is_null($asset = Asset::find($assetId))) {
278  // Redirect to the asset management page with error
279  return Redirect::to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
280  } elseif (!Company::isCurrentUserHasAccess($asset)) {
281  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
282  }
283 
284  // $input=Input::all();
285  // // return "INPUT IS: <pre>".print_r($input,true)."</pre>";
286  // $rules=$asset->validationRules($assetId);
287  // $model=AssetModel::find(e(Input::get('model_id'))); //validate by the NEW model's custom fields, not the current one
288  // if($model->fieldset)
289  // {
290  // foreach($model->fieldset->fields AS $field) {
291  // $input[$field->db_column_name()]=$input['fields'][$field->db_column_name()];
292  // $asset->{$field->db_column_name()}=$input[$field->db_column_name()];
293  // }
294  // $rules+=$model->fieldset->validation_rules();
295  // unset($input['fields']);
296  // }
297 
298  //return "Rules: <pre>".print_r($rules,true)."</pre>";
299 
300  //attempt to validate
301  // $validator = Validator::make($input, $rules );
302  //
303  // $custom_errors=[];
304 
305 
306  if (e(Input::get('status_id')) == '') {
307  $asset->status_id = null;
308  } else {
309  $asset->status_id = e(Input::get('status_id'));
310  }
311 
312  if (e(Input::get('warranty_months')) == '') {
313  $asset->warranty_months = null;
314  } else {
315  $asset->warranty_months = e(Input::get('warranty_months'));
316  }
317 
318  if (e(Input::get('purchase_cost')) == '') {
319  $asset->purchase_cost = null;
320  } else {
321  $asset->purchase_cost = \App\Helpers\Helper::ParseFloat(e(Input::get('purchase_cost')));
322  }
323 
324  if (e(Input::get('purchase_date')) == '') {
325  $asset->purchase_date = null;
326  } else {
327  $asset->purchase_date = e(Input::get('purchase_date'));
328  }
329 
330  if (e(Input::get('supplier_id')) == '') {
331  $asset->supplier_id = null;
332  } else {
333  $asset->supplier_id = e(Input::get('supplier_id'));
334  }
335 
336  if (e(Input::get('requestable')) == '') {
337  $asset->requestable = 0;
338  } else {
339  $asset->requestable = e(Input::get('requestable'));
340  }
341 
342  if (e(Input::get('rtd_location_id')) == '') {
343  $asset->rtd_location_id = 0;
344  } else {
345  $asset->rtd_location_id = e(Input::get('rtd_location_id'));
346  }
347 
348  if (Input::has('image_delete')) {
349  unlink(public_path().'/uploads/assets/'.$asset->image);
350  $asset->image = '';
351  }
352 
353 
354 
355  $checkModel = config('app.url').'/api/models/'.e(Input::get('model_id')).'/check';
356 
357  // Update the asset data
358  $asset->name = e(Input::get('name'));
359  $asset->serial = e(Input::get('serial'));
360  $asset->company_id = Company::getIdForCurrentUser(e(Input::get('company_id')));
361  $asset->model_id = e(Input::get('model_id'));
362  $asset->order_number = e(Input::get('order_number'));
363  $asset->asset_tag = e(Input::get('asset_tag'));
364  $asset->notes = e(Input::get('notes'));
365  $asset->physical = '1';
366 
367  // Update the image
368  if (Input::file('image')) {
369  $image = Input::file('image');
370  $file_name = str_random(25).".".$image->getClientOriginalExtension();
371  $path = public_path('uploads/assets/'.$file_name);
372  Image::make($image->getRealPath())->resize(300, null, function ($constraint) {
373  $constraint->aspectRatio();
374  $constraint->upsize();
375  })->save($path);
376  $asset->image = $file_name;
377  }
378 
379 
380 
381  // Was the asset updated?
382  if ($asset->save()) {
383  // Redirect to the new asset page
384  return Redirect::to("hardware/$assetId/view")->with('success', trans('admin/hardware/message.update.success'));
385  }
386 
387  return Redirect::back()->withInput()->withErrors($asset->getErrors());
388 
389  }
static getIdForCurrentUser($unescaped_input)
Definition: Company.php:81
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static ParseFloat($floatString)
Definition: Helper.php:41
App\Http\Controllers\AssetsController::postUpload ( AssetFileRequest  $request,
  $assetId = null 
)

Upload a file to the server.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$assetId
Since
[v1.0]
Returns
Redirect

Definition at line 938 of file AssetsController.php.

939  {
940 
941  if (!$asset = Asset::find($assetId)) {
942  return Redirect::route('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
943  }
944 
945  $destinationPath = config('app.private_uploads').'/assets';
946 
947 
948 
949  if (!Company::isCurrentUserHasAccess($asset)) {
950  return Redirect::to('hardware')->with('error', trans('general.insufficient_permissions'));
951  }
952 
953  if (Input::hasFile('assetfile')) {
954 
955  foreach (Input::file('assetfile') as $file) {
956  $extension = $file->getClientOriginalExtension();
957  $filename = 'hardware-'.$asset->id.'-'.str_random(8);
958  $filename .= '-'.str_slug($file->getClientOriginalName()).'.'.$extension;
959  $upload_success = $file->move($destinationPath, $filename);
960 
961  //Log the deletion of seats to the log
962  $logaction = new Actionlog();
963  $logaction->asset_id = $asset->id;
964  $logaction->asset_type = 'hardware';
965  $logaction->user_id = Auth::user()->id;
966  $logaction->note = e(Input::get('notes'));
967  $logaction->checkedout_to = null;
968  $logaction->created_at = date("Y-m-d H:i:s");
969  $logaction->filename = $filename;
970  $log = $logaction->logaction('uploaded');
971  }
972  } else {
973  return Redirect::back()->with('error', trans('admin/hardware/message.upload.nofiles'));
974  }
975 
976  if ($upload_success) {
977  return Redirect::back()->with('success', trans('admin/hardware/message.upload.success'));
978  } else {
979  return Redirect::back()->with('error', trans('admin/hardware/message.upload.error'));
980  }
981 
982 
983 
984  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96

Member Data Documentation

App\Http\Controllers\AssetsController::$barCodeDimensions = array( 'height' => 2, 'width' => 22)
protected

Definition at line 53 of file AssetsController.php.

App\Http\Controllers\AssetsController::$qrCodeDimensions = array( 'height' => 3.5, 'width' => 3.5)
protected

Definition at line 52 of file AssetsController.php.


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