58 $this->middleware(
'auth');
59 parent::__construct();
74 return View::make(
'hardware/index');
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);
109 if (!is_null($model_id)) {
110 $selected_model = AssetAssetModel::find($model_id);
111 $view->with(
'selected_model', $selected_model);
127 $asset =
new Asset();
128 $asset->model()->associate(AssetModel::find(e(Input::get(
'model_id'))));
130 $checkModel = config(
'app.url').
'/api/models/'.e(Input::get(
'model_id')).
'/check';
132 $asset->name = e(Input::get(
'name'));
133 $asset->serial = e(Input::get(
'serial'));
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;
146 $asset->status_id = e(Input::get(
'status_id'));
149 if (e(Input::get(
'warranty_months')) ==
'') {
150 $asset->warranty_months = null;
152 $asset->warranty_months = e(Input::get(
'warranty_months'));
155 if (e(Input::get(
'purchase_cost')) ==
'') {
156 $asset->purchase_cost = null;
161 if (e(Input::get(
'purchase_date')) ==
'') {
162 $asset->purchase_date = null;
164 $asset->purchase_date = e(Input::get(
'purchase_date'));
167 if (e(Input::get(
'assigned_to')) ==
'') {
168 $asset->assigned_to = null;
170 $asset->assigned_to = e(Input::get(
'assigned_to'));
173 if (e(Input::get(
'supplier_id')) ==
'') {
174 $asset->supplier_id = 0;
176 $asset->supplier_id = e(Input::get(
'supplier_id'));
179 if (e(Input::get(
'requestable')) ==
'') {
180 $asset->requestable = 0;
182 $asset->requestable = e(Input::get(
'requestable'));
185 if (e(Input::get(
'rtd_location_id')) ==
'') {
186 $asset->rtd_location_id = null;
188 $asset->rtd_location_id = e(Input::get(
'rtd_location_id'));
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();
200 $asset->image = $file_name;
205 if ($asset->save()) {
207 if (Input::get(
'assigned_to')!=
'') {
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');
217 return Redirect::to(
"hardware")->with(
'success', trans(
'admin/hardware/message.create.success'));
220 return Redirect::back()->withInput()->withErrors($asset->getErrors());
235 if (is_null($asset = Asset::find($assetId))) {
237 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
239 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
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);
277 if (is_null($asset = Asset::find($assetId))) {
279 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
281 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
306 if (e(Input::get(
'status_id')) ==
'') {
307 $asset->status_id = null;
309 $asset->status_id = e(Input::get(
'status_id'));
312 if (e(Input::get(
'warranty_months')) ==
'') {
313 $asset->warranty_months = null;
315 $asset->warranty_months = e(Input::get(
'warranty_months'));
318 if (e(Input::get(
'purchase_cost')) ==
'') {
319 $asset->purchase_cost = null;
324 if (e(Input::get(
'purchase_date')) ==
'') {
325 $asset->purchase_date = null;
327 $asset->purchase_date = e(Input::get(
'purchase_date'));
330 if (e(Input::get(
'supplier_id')) ==
'') {
331 $asset->supplier_id = null;
333 $asset->supplier_id = e(Input::get(
'supplier_id'));
336 if (e(Input::get(
'requestable')) ==
'') {
337 $asset->requestable = 0;
339 $asset->requestable = e(Input::get(
'requestable'));
342 if (e(Input::get(
'rtd_location_id')) ==
'') {
343 $asset->rtd_location_id = 0;
345 $asset->rtd_location_id = e(Input::get(
'rtd_location_id'));
348 if (Input::has(
'image_delete')) {
349 unlink(public_path().
'/uploads/assets/'.$asset->image);
355 $checkModel = config(
'app.url').
'/api/models/'.e(Input::get(
'model_id')).
'/check';
358 $asset->name = e(Input::get(
'name'));
359 $asset->serial = e(Input::get(
'serial'));
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';
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();
376 $asset->image = $file_name;
382 if ($asset->save()) {
384 return Redirect::to(
"hardware/$assetId/view")->with(
'success', trans(
'admin/hardware/message.update.success'));
387 return Redirect::back()->withInput()->withErrors($asset->getErrors());
402 if (is_null($asset = Asset::find($assetId))) {
404 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
406 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
410 ->where(
'id', $asset->id)
411 ->update(array(
'assigned_to' => null));
417 return Redirect::to(
'hardware')->with(
'success', trans(
'admin/hardware/message.delete.success'));
436 if (is_null($asset = Asset::find(e($assetId)))) {
438 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
440 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
446 return View::make(
'hardware/checkout', compact(
'asset'))->with(
'users_list', $users_list);
462 if (!$asset = Asset::find($assetId)) {
463 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
465 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
468 $user = User::find(e(Input::get(
'assigned_to')));
469 $admin = Auth::user();
473 if (Input::get(
'checkout_at')!= date(
"Y-m-d")) {
474 $checkout_at = e(Input::get(
'checkout_at')).
' 00:00:00';
476 $checkout_at = date(
"Y-m-d H:i:s");
479 if (Input::has(
'expected_checkin')) {
480 $expected_checkin = e(Input::get(
'expected_checkin'));
482 $expected_checkin =
'';
486 if ($asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get(
'note')), e(Input::get(
'name')))) {
488 return Redirect::to(
"hardware")->with(
'success', trans(
'admin/hardware/message.checkout.success'));
492 return Redirect::to(
"hardware/$assetId/checkout")->with(
'error', trans(
'admin/hardware/message.checkout.error'))->withErrors($asset->getErrors());
508 if (is_null($asset = Asset::find($assetId))) {
510 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
512 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
515 return View::make(
'hardware/checkin', compact(
'asset'))->with(
'statusLabel_list', $statusLabel_list)->with(
'backto', $backto);
530 if (is_null($asset = Asset::find($assetId))) {
532 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
534 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
539 if (!is_null($asset->assigned_to)) {
540 $user = User::find($asset->assigned_to);
542 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.checkin.already_checked_in'));
546 $return_to = $asset->assigned_to;
549 $logaction->checkedout_to = $asset->assigned_to;
552 $asset->assigned_to = null;
553 $asset->accepted = null;
555 $asset->expected_checkin = null;
556 $asset->last_checkout = null;
558 if (Input::has(
'status_id')) {
559 $asset->status_id = e(Input::get(
'status_id'));
562 if ($asset->save()) {
564 if (Input::has(
'checkin_at')) {
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';
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');
581 if ($settings->slack_endpoint) {
584 'username' => $settings->botname,
585 'channel' => $settings->slack_channel,
589 $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
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()).
'>.' 601 'value' => e($logaction->note)
605 ])->send(
'Asset Checked In');
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;
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');
628 if ($backto==
'user') {
629 return Redirect::to(
"admin/users/".$return_to.
'/view')->with(
'success', trans(
'admin/hardware/message.checkin.success'));
631 return Redirect::to(
"hardware")->with(
'success', trans(
'admin/hardware/message.checkin.success'));
637 return Redirect::to(
"hardware")->with(
'error', trans(
'admin/hardware/message.checkin.error'));
651 $asset = Asset::withTrashed()->find($assetId);
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;
661 $default_currency = Setting::first()->default_currency;
663 if ($settings->default_currency!=
'') {
664 $use_currency = $settings->default_currency;
666 $use_currency = trans(
'general.currency');
671 if (isset($asset->id)) {
675 $qr_code = (object) array(
676 'display' => $settings->qr_code ==
'1',
677 'url' => route(
'qr_code/hardware', $asset->id)
680 return View::make(
'hardware/view', compact(
'asset',
'qr_code',
'settings'))->with(
'use_currency', $use_currency);
683 $error = trans(
'admin/hardware/message.does_not_exist', compact(
'id'));
686 return Redirect::route(
'hardware')->with(
'error', $error);
703 if ($settings->qr_code ==
'1') {
704 $asset = Asset::find($assetId);
708 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
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));
715 return response($barcode_obj->getPngData())->header(
'Content-type',
'image/png');
732 $path = config(
'app.private_uploads').
'/imports/assets';
736 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
739 if ($handle = opendir($path)) {
742 while (
false !== ($entry = readdir($handle))) {
744 if (substr(strrchr($entry,
'.'), 1)==
'csv') {
746 'filename' => $entry,
748 'modified' => filemtime($path.
'/'.$entry)
754 $files = array_reverse($files);
757 return View::make(
'hardware/import')->with(
'files', $files);
773 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
775 } elseif (!config(
'app.lock_passwords')) {
777 $files = Input::file(
'files');
778 $path = config(
'app.private_uploads').
'/imports/assets';
781 foreach ($files as $file) {
783 if (!in_array($file->getMimeType(), array(
784 'application/vnd.ms-excel',
787 'text/comma-separated-values',
789 $results[
'error']=
'File type must be CSV';
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;
798 $results[] = compact(
'name',
'filesize');
810 $results[
'error']=trans(
'general.feature_disabled');
832 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
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);
842 return Redirect::to(
'hardware')->with(
'success',
'Your file has been imported');
857 if (is_null($asset_to_clone = Asset::find($assetId))) {
859 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
861 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
875 $asset = clone $asset_to_clone;
877 $asset->asset_tag =
'';
879 $asset->assigned_to =
'';
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);
908 $asset = Asset::withTrashed()->find($assetId);
911 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
912 } elseif (isset($asset->id)) {
918 $success = trans(
'admin/hardware/message.restore.success');
921 return Redirect::route(
'hardware')->with(
'success', $success);
924 return Redirect::to(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
941 if (!$asset = Asset::find($assetId)) {
942 return Redirect::route(
'hardware')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
945 $destinationPath = config(
'app.private_uploads').
'/assets';
950 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
953 if (Input::hasFile(
'assetfile')) {
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);
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');
973 return Redirect::back()->with(
'error', trans(
'admin/hardware/message.upload.nofiles'));
976 if ($upload_success) {
977 return Redirect::back()->with(
'success', trans(
'admin/hardware/message.upload.success'));
979 return Redirect::back()->with(
'error', trans(
'admin/hardware/message.upload.error'));
997 $asset = Asset::find($assetId);
998 $destinationPath = config(
'app.private_uploads').
'/imports/assets';
1001 if (isset($asset->id)) {
1005 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
1008 $log = Actionlog::find($fileId);
1009 $full_filename = $destinationPath.
'/'.$log->filename;
1010 if (file_exists($full_filename)) {
1011 unlink($destinationPath.
'/'.$log->filename);
1014 return Redirect::back()->with(
'success', trans(
'admin/hardware/message.deletefile.success'));
1018 $error = trans(
'admin/hardware/message.does_not_exist', compact(
'id'));
1021 return Redirect::route(
'hardware')->with(
'error', $error);
1039 $asset = Asset::find($assetId);
1042 if (isset($asset->id)) {
1046 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
1049 $log = Actionlog::find($fileId);
1050 $file = $log->get_src(
'assets');
1055 $contents = file_get_contents($file);
1056 return Response::make($contents)->header(
'Content-Type', $filetype);
1058 return Response::download($file);
1063 $error = trans(
'admin/hardware/message.does_not_exist', compact(
'id'));
1066 return Redirect::route(
'hardware')->with(
'error', $error);
1085 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
1087 } elseif (!Input::has(
'edit_asset')) {
1088 return Redirect::back()->with(
'error',
'No assets selected');
1091 $asset_raw_array = Input::get(
'edit_asset');
1092 foreach ($asset_raw_array as $asset_id => $value) {
1093 $asset_ids[] = $asset_id;
1099 if (Input::has(
'bulk_actions')) {
1103 if (Input::get(
'bulk_actions')==
'labels') {
1107 if ($settings->qr_code==
'1') {
1109 $assets = Asset::find($asset_ids);
1110 $assetcount = count($assets);
1113 return View::make(
'hardware/labels')->with(
'assets', $assets)->with(
'settings', $settings)->with(
'count', $count)->with(
'settings', $settings);
1117 return Redirect::to(
"hardware")->with(
'error',
'Barcodes are not enabled in Admin > Settings');
1120 } elseif (Input::get(
'bulk_actions')==
'delete') {
1123 $assets = Asset::with(
'assigneduser',
'assetloc')->find($asset_ids);
1124 return View::make(
'hardware/bulk-delete')->with(
'assets', $assets);
1127 } elseif (Input::get(
'bulk_actions')==
'edit') {
1129 $assets = Input::get(
'edit_asset');
1134 $companies_list = array(
'' =>
'') + array(
'clear' => trans(
'general.remove_company')) +
Helper::companyList();
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);
1148 return Redirect::back()->with(
'error',
'No action selected');
1169 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
1171 } elseif (Input::has(
'bulk_edit')) {
1173 $assets = Input::get(
'bulk_edit');
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'))) {
1177 foreach ($assets as $key => $value) {
1179 $update_array = array();
1181 if (Input::has(
'purchase_date')) {
1182 $update_array[
'purchase_date'] = e(Input::get(
'purchase_date'));
1185 if (Input::has(
'purchase_cost')) {
1186 $update_array[
'purchase_cost'] = e(Input::get(
'purchase_cost'));
1189 if (Input::has(
'supplier_id')) {
1190 $update_array[
'supplier_id'] = e(Input::get(
'supplier_id'));
1193 if (Input::has(
'model_id')) {
1194 $update_array[
'model_id'] = e(Input::get(
'model_id'));
1197 if (Input::has(
'company_id')) {
1198 if (Input::get(
'company_id')==
"clear") {
1199 $update_array[
'company_id'] = null;
1201 $update_array[
'company_id'] = e(Input::get(
'company_id'));
1206 if (Input::has(
'order_number')) {
1207 $update_array[
'order_number'] = e(Input::get(
'order_number'));
1210 if (Input::has(
'warranty_months')) {
1211 $update_array[
'warranty_months'] = e(Input::get(
'warranty_months'));
1214 if (Input::has(
'rtd_location_id')) {
1215 $update_array[
'rtd_location_id'] = e(Input::get(
'rtd_location_id'));
1218 if (Input::has(
'status_id')) {
1219 $update_array[
'status_id'] = e(Input::get(
'status_id'));
1222 if (Input::has(
'requestable')) {
1223 $update_array[
'requestable'] = e(Input::get(
'requestable'));
1227 if (DB::table(
'assets')
1229 ->update($update_array)) {
1232 $logaction->asset_id = $key;
1233 $logaction->asset_type =
'hardware';
1234 $logaction->created_at = date(
"Y-m-d H:i:s");
1236 if (Input::has(
'rtd_location_id')) {
1237 $logaction->location_id = e(Input::get(
'rtd_location_id'));
1239 $logaction->user_id = Auth::user()->id;
1240 $log = $logaction->logaction(
'update');
1246 return Redirect::to(
"hardware")->with(
'success', trans(
'admin/hardware/message.update.success'));
1250 return Redirect::to(
"hardware")->with(
'info', trans(
'admin/hardware/message.update.nothing_updated'));
1257 return Redirect::to(
"hardware");
1273 return Redirect::to(
'hardware')->with(
'error', trans(
'general.insufficient_permissions'));
1274 } elseif (Input::has(
'bulk_edit')) {
1276 $assets = Asset::find(Input::get(
'bulk_edit'));
1280 foreach ($assets as $asset) {
1282 $update_array[
'deleted_at'] = date(
'Y-m-d h:i:s');
1283 $update_array[
'assigned_to'] = null;
1285 if (DB::table(
'assets')
1286 ->where(
'id', $asset->id)
1287 ->update($update_array)) {
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');
1299 return Redirect::to(
"hardware")->with(
'success', trans(
'admin/hardware/message.delete.success'));
1303 return Redirect::to(
"hardware")->with(
'info', trans(
'admin/hardware/message.delete.nothing_updated'));
1308 return Redirect::to(
"hardware");
1326 $assets = Asset::select(
'assets.*')->with(
'model',
'assigneduser',
'assigneduser.userloc',
'assetstatus',
'defaultLoc',
'assetlog',
'model',
'model.category',
'model.fieldset',
'assetstatus',
'assetloc',
'company')
1329 if (Input::has(
'search')) {
1330 $assets = $assets->TextSearch(Input::get(
'search'));
1333 if (Input::has(
'offset')) {
1334 $offset = e(Input::get(
'offset'));
1339 if (Input::has(
'limit')) {
1340 $limit = e(Input::get(
'limit'));
1345 if (Input::has(
'order_number')) {
1346 $assets->where(
'order_number',
'=', e(Input::get(
'order_number')));
1351 $assets->withTrashed()->Deleted();
1359 case 'Undeployable':
1360 $assets->Undeployable();
1363 $assets->Archived();
1366 $assets->RequestableAssets();
1369 $assets->Deployed();
1374 $allowed_columns = [
1392 $all_custom_fields=CustomField::all();
1394 foreach ($all_custom_fields as $field) {
1395 $allowed_columns[]=$field->db_column_name();
1398 $order = Input::get(
'order') ===
'asc' ?
'asc' :
'desc';
1399 $sort = in_array(Input::get(
'sort'), $allowed_columns) ? Input::get(
'sort') :
'asset_tag';
1403 $assets = $assets->OrderModels($order);
1406 $assets = $assets->OrderCategory($order);
1409 $assets = $assets->OrderCompany($order);
1412 $assets = $assets->OrderLocation($order);
1414 case 'status_label':
1415 $assets = $assets->OrderStatus($order);
1418 $assets = $assets->OrderAssigned($order);
1421 $assets = $assets->orderBy($sort, $order);
1425 $assetCount = $assets->count();
1426 $assets = $assets->skip($offset)->take($limit)->get();
1430 foreach ($assets as $asset) {
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>';
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>';
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>';
1450 'checkbox' =>
'<div class="text-center"><input type="checkbox" name="edit_asset['.$asset->id.
']" class="one_required"></div>',
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)
1470 foreach ($all_custom_fields as $field) {
1471 $row[$field->db_column_name()]=$asset->{$field->db_column_name()};
1476 $data = array(
'total'=>$assetCount,
'rows'=>$rows);
postAPIImportUpload(AssetFileRequest $request)
Upload the import file via AJAX.
postUpload(AssetFileRequest $request, $assetId=null)
Upload a file to the server.
static manufacturerList()
Model for the Actionlog (the table that keeps a historical log of checkouts, checkins, and updates).
getImportUpload()
Get the Asset import upload page.
postBulkSave($assets=null)
Save bulk edits.
static getIdForCurrentUser($unescaped_input)
This class controls all actions related to assets for the Snipe-IT Asset Management application...
getCheckin($assetId, $backto=null)
Returns a view that presents a form to check an asset back into inventory.
getCheckout($assetId)
Returns a view that presents a form to check an asset out to a user.
postCheckin(AssetCheckinRequest $request, $assetId=null, $backto=null)
Validate and process the form data to check an asset back into inventory.
displayFile($assetId=null, $fileId=null)
Check for permissions and display the file.
postEdit($assetId=null)
Validate and process asset edit form.
getIndex()
Returns a view that invokes the ajax tables which actually contains the content for the assets listin...
getClone($assetId=null)
Returns a view that presents a form to clone an asset.
static barcodeDimensions($barcode_type= 'QRCODE')
static isCurrentUserHasAccess($companyable)
postBulkDelete($assets=null)
Save bulk deleted.
getCreate($model_id=null)
Returns a view that presents a form to create a new asset.
getEdit($assetId=null)
Returns a view that presents a form to edit an existing asset.
static ParseFloat($floatString)
getRestore($assetId=null)
Retore a deleted asset.
static isCurrentUserAuthorized()
getProcessImportFile($filename)
Process the uploaded file.
getView($assetId=null)
Returns a view that presents information about an asset for detail view.
getQrCode($assetId=null)
Return a QR code for the asset.
getDeleteFile($assetId=null, $fileId=null)
Delete the associated file.
getDelete($assetId)
Delete a given asset (mark as deleted).
static fileSizeConvert($bytes)
Converts bytes into human readable file size.
postBulkEdit($assets=null)
Display the bulk edit page.
static checkUploadIsImage($file)
postCreate(AssetRequest $request)
Validate and process new asset form data.
getDatatable($status=null)
Generates the JSON used to display the asset listing.
postCheckout(AssetCheckoutRequest $request, $assetId)
Validate and process the form data to check out an asset to a user.