App\Http\Controllers\AccessoriesController Class Reference

This controller handles all actions related to Accessories for the Snipe-IT Asset Management application. More...

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

Public Member Functions

 getIndex (Request $request)
 Returns a view that invokes the ajax tables which actually contains the content for the accessories listing, which is generated in getDatatable. More...
 
 getCreate (Request $request)
 Returns a view with a form to create a new Accessory. More...
 
 postCreate (Request $request)
 Validate and save new Accessory from form post. More...
 
 getEdit (Request $request, $accessoryId=null)
 Return view for the Accessory update form, prepopulated with existing data. More...
 
 postEdit (Request $request, $accessoryId=null)
 Save edited Accessory from form post. More...
 
 getDelete (Request $request, $accessoryId)
 Delete the given accessory. More...
 
 getView (Request $request, $accessoryID=null)
 Returns a view that invokes the ajax table which contains the content for the accessory detail view, which is generated in getDataView. More...
 
 getCheckout (Request $request, $accessoryId)
 Return the form to checkout an Accessory to a user. More...
 
 postCheckout (Request $request, $accessoryId)
 Save the Accessory checkout information. More...
 
 getCheckin (Request $request, $accessoryUserId=null, $backto=null)
 Check the accessory back into inventory. More...
 
 postCheckin (Request $request, $accessoryUserId=null, $backto=null)
 Check in the item so that it can be checked out again to someone else. More...
 
 getDatatable (Request $request)
 Generates the JSON response for accessories listing view. More...
 
 getDataView (Request $request, $accessoryID)
 Generates the JSON response for accessory detail view. More...
 

Detailed Description

This controller handles all actions related to Accessories for the Snipe-IT Asset Management application.

Version
v1.0

Definition at line 28 of file AccessoriesController.php.

Member Function Documentation

App\Http\Controllers\AccessoriesController::getCheckin ( Request  $request,
  $accessoryUserId = null,
  $backto = null 
)

Check the accessory back into inventory.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
View

Definition at line 397 of file AccessoriesController.php.

398  {
399  // Check if the accessory exists
400  if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
401  // Redirect to the accessory management page with error
402  return Redirect::to('admin/accessories')->with('error', trans('admin/accessories/message.not_found'));
403  }
404 
405  $accessory = Accessory::find($accessory_user->accessory_id);
406 
407  if (!Company::isCurrentUserHasAccess($accessory)) {
408  return Redirect::to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
409  } else {
410  return View::make('accessories/checkin', compact('accessory'))->with('backto', $backto);
411  }
412  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AccessoriesController::getCheckout ( Request  $request,
  $accessoryId 
)

Return the form to checkout an Accessory to a user.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
View

Definition at line 264 of file AccessoriesController.php.

265  {
266  // Check if the accessory exists
267  if (is_null($accessory = Accessory::find($accessoryId))) {
268  // Redirect to the accessory management page with error
269  return Redirect::to('accessories')->with('error', trans('admin/accessories/message.not_found'));
270  } elseif (!Company::isCurrentUserHasAccess($accessory)) {
271  return Redirect::to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
272  }
273 
274  // Get the dropdown of users and then pass it to the checkout view
275  $users_list = Helper::usersList();
276 
277  return View::make('accessories/checkout', compact('accessory'))->with('users_list', $users_list);
278 
279  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static usersList()
Definition: Helper.php:138
App\Http\Controllers\AccessoriesController::getCreate ( Request  $request)

Returns a view with a form to create a new Accessory.

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

Definition at line 52 of file AccessoriesController.php.

53  {
54  // Show the page
55  $category_list = array('' => '') + DB::table('categories')->where('category_type', '=', 'accessory')->whereNull('deleted_at')->orderBy('name', 'ASC')->lists('name', 'id');
56  $company_list = Helper::companyList();
57  $location_list = Helper::locationsList();
58  return View::make('accessories/edit')
59  ->with('accessory', new Accessory)
60  ->with('category_list', $category_list)
61  ->with('company_list', $company_list)
62  ->with('location_list', $location_list);
63  }
static locationsList()
Definition: Helper.php:94
static companyList()
Definition: Helper.php:61
App\Http\Controllers\AccessoriesController::getDatatable ( Request  $request)

Generates the JSON response for accessories listing view.

Example: { "actions": "(links to available actions)", "category": "(link to category)", "companyName": "My Company", "location": "My Location", "min_amt": 2, "name": "(link to accessory), "numRemaining": 6, "order_number": null, "purchase_cost": "0.00", "purchase_date": null, "qty": 7 },

The names of the fields in the returns JSON correspond directly to the the names of the fields in the bootstrap-tables in the view.

For debugging, see at /api/accessories/list

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
string JSON containing accessories and their associated atrributes.

Definition at line 548 of file AccessoriesController.php.

549  {
550  $accessories = Accessory::select('accessories.*')->with('category', 'company')
551  ->whereNull('accessories.deleted_at');
552 
553  if (Input::has('search')) {
554  $accessories = $accessories->TextSearch(e(Input::get('search')));
555  }
556 
557  if (Input::has('offset')) {
558  $offset = e(Input::get('offset'));
559  } else {
560  $offset = 0;
561  }
562 
563  if (Input::has('limit')) {
564  $limit = e(Input::get('limit'));
565  } else {
566  $limit = 50;
567  }
568 
569 
570  $allowed_columns = ['name','min_amt','order_number','purchase_date','purchase_cost','companyName','category'];
571  $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
572  $sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at';
573 
574  switch ($sort) {
575  case 'category':
576  $accessories = $accessories->OrderCategory($order);
577  break;
578  case 'companyName':
579  $accessories = $accessories->OrderCompany($order);
580  break;
581  default:
582  $accessories = $accessories->orderBy($sort, $order);
583  break;
584  }
585 
586  $accessCount = $accessories->count();
587  $accessories = $accessories->skip($offset)->take($limit)->get();
588 
589  $rows = array();
590 
591  foreach ($accessories as $accessory) {
592  $actions = '<nobr><a href="'.route('checkout/accessory', $accessory->id).'" style="margin-right:5px;" class="btn btn-info btn-sm" '.(($accessory->numRemaining() > 0 ) ? '' : ' disabled').'>'.trans('general.checkout').'</a><a href="'.route('update/accessory', $accessory->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/accessory', $accessory->id).'" data-content="'.trans('admin/accessories/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($accessory->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';
593  $company = $accessory->company;
594 
595  $rows[] = array(
596  'name' => '<a href="'.url('admin/accessories/'.$accessory->id).'/view">'. $accessory->name.'</a>',
597  'category' => ($accessory->category) ? (string)link_to('admin/settings/categories/'.$accessory->category->id.'/view', $accessory->category->name) : '',
598  'qty' => e($accessory->qty),
599  'order_number' => e($accessory->order_number),
600  'min_amt' => e($accessory->min_amt),
601  'location' => ($accessory->location) ? e($accessory->location->name): '',
602  'purchase_date' => e($accessory->purchase_date),
603  'purchase_cost' => number_format($accessory->purchase_cost, 2),
604  'numRemaining' => $accessory->numRemaining(),
605  'actions' => $actions,
606  'companyName' => is_null($company) ? '' : e($company->name)
607  );
608  }
609 
610  $data = array('total'=>$accessCount, 'rows'=>$rows);
611 
612  return $data;
613  }
App\Http\Controllers\AccessoriesController::getDataView ( Request  $request,
  $accessoryID 
)

Generates the JSON response for accessory detail view.

Example: { "rows": [ { "actions": "(link to available actions)", "name": "(link to user)" } ], "total": 1 }

The names of the fields in the returns JSON correspond directly to the the names of the fields in the bootstrap-tables in the view.

For debugging, see at /api/accessories/$accessoryID/view

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
string JSON containing accessories and their associated atrributes.

Definition at line 641 of file AccessoriesController.php.

642  {
643  $accessory = Accessory::find($accessoryID);
644 
645  if (!Company::isCurrentUserHasAccess($accessory)) {
646  return ['total' => 0, 'rows' => []];
647  }
648 
649  $accessory_users = $accessory->users;
650  $count = $accessory_users->count();
651 
652  $rows = array();
653 
654  foreach ($accessory_users as $user) {
655  $actions = '<a href="'.route('checkin/accessory', $user->pivot->id).'" class="btn btn-info btn-sm">Checkin</a>';
656 
657  $rows[] = array(
658  'name' =>(string) link_to('/admin/users/'.$user->id.'/view', e($user->fullName())),
659  'actions' => $actions
660  );
661  }
662 
663  $data = array('total'=>$count, 'rows'=>$rows);
664 
665  return $data;
666  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AccessoriesController::getDelete ( Request  $request,
  $accessoryId 
)

Delete the given accessory.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
Redirect

Definition at line 201 of file AccessoriesController.php.

202  {
203  // Check if the blog post exists
204  if (is_null($accessory = Accessory::find($accessoryId))) {
205  // Redirect to the blogs management page
206  return Redirect::to('admin/accessories')->with('error', trans('admin/accessories/message.not_found'));
207  } elseif (!Company::isCurrentUserHasAccess($accessory)) {
208  return Redirect::to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
209  }
210 
211 
212  if ($accessory->hasUsers() > 0) {
213  return Redirect::to('admin/accessories')->with('error', trans('admin/accessories/message.assoc_users', array('count'=> $accessory->hasUsers())));
214  } else {
215  $accessory->delete();
216 
217  // Redirect to the locations management page
218  return Redirect::to('admin/accessories')->with('success', trans('admin/accessories/message.delete.success'));
219 
220  }
221  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AccessoriesController::getEdit ( Request  $request,
  $accessoryId = null 
)

Return view for the Accessory update form, prepopulated with existing data.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
View

Definition at line 118 of file AccessoriesController.php.

119  {
120  // Check if the accessory exists
121  if (is_null($accessory = Accessory::find($accessoryId))) {
122  // Redirect to the blogs management page
123  return Redirect::to('admin/accessories')->with('error', trans('admin/accessories/message.does_not_exist'));
124  } elseif (!Company::isCurrentUserHasAccess($accessory)) {
125  return Redirect::to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
126  }
127 
128  $category_list = array('' => '') + DB::table('categories')->where('category_type', '=', 'accessory')->whereNull('deleted_at')->orderBy('name', 'ASC')->lists('name', 'id');
129  $company_list = Helper::companyList();
130  $location_list = Helper::locationsList();
131 
132  return View::make('accessories/edit', compact('accessory'))
133  ->with('category_list', $category_list)
134  ->with('company_list', $company_list)
135  ->with('location_list', $location_list);
136  }
static locationsList()
Definition: Helper.php:94
static companyList()
Definition: Helper.php:61
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AccessoriesController::getIndex ( Request  $request)

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

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

Definition at line 40 of file AccessoriesController.php.

41  {
42  return View::make('accessories/index');
43  }
App\Http\Controllers\AccessoriesController::getView ( Request  $request,
  $accessoryID = null 
)

Returns a view that invokes the ajax table which contains the content for the accessory detail view, which is generated in getDataView.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
See also
AccessoriesController::getDataView() method that generates the JSON response
Since
[v1.0]
Returns
View

Definition at line 235 of file AccessoriesController.php.

236  {
237  $accessory = Accessory::find($accessoryID);
238 
239  if (isset($accessory->id)) {
240 
241  if (!Company::isCurrentUserHasAccess($accessory)) {
242  return Redirect::to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
243  } else {
244  return View::make('accessories/view', compact('accessory'));
245  }
246  } else {
247  // Prepare the error message
248  $error = trans('admin/accessories/message.does_not_exist', compact('id'));
249 
250  // Redirect to the user management page
251  return Redirect::route('accessories')->with('error', $error);
252  }
253 
254 
255  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
App\Http\Controllers\AccessoriesController::postCheckin ( Request  $request,
  $accessoryUserId = null,
  $backto = null 
)

Check in the item so that it can be checked out again to someone else.

Accessory::checkin_email() to determine if an email can and should be sent

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
Redirect

Definition at line 423 of file AccessoriesController.php.

424  {
425  // Check if the accessory exists
426  if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
427  // Redirect to the accessory management page with error
428  return Redirect::to('admin/accessories')->with('error', trans('admin/accessories/message.not_found'));
429  }
430 
431 
432  $accessory = Accessory::find($accessory_user->accessory_id);
433 
434  if (!Company::isCurrentUserHasAccess($accessory)) {
435  return Redirect::to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
436  }
437 
438  $logaction = new Actionlog();
439  $logaction->checkedout_to = e($accessory_user->assigned_to);
440  $return_to = e($accessory_user->assigned_to);
441  $admin_user = Auth::user();
442 
443 
444  // Was the accessory updated?
445  if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {
446 
447  $logaction->accessory_id = e($accessory->id);
448  $logaction->location_id = null;
449  $logaction->asset_type = 'accessory';
450  $logaction->user_id = e($admin_user->id);
451  $logaction->note = e(Input::get('note'));
452 
453  $settings = Setting::getSettings();
454 
455  if ($settings->slack_endpoint) {
456 
457 
458  $slack_settings = [
459  'username' => e($settings->botname),
460  'channel' => e($settings->slack_channel),
461  'link_names' => true
462  ];
463 
464  $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
465 
466  try {
467  $client->attach([
468  'color' => 'good',
469  'fields' => [
470  [
471  'title' => 'Checked In:',
472  'value' => strtoupper($logaction->asset_type).' <'.config('app.url').'/admin/accessories/'.e($accessory->id).'/view'.'|'.e($accessory->name).'> checked in by <'.config('app.url').'/admin/users/'.e($admin_user->id).'/view'.'|'.e($admin_user->fullName()).'>.'
473  ],
474  [
475  'title' => 'Note:',
476  'value' => e($logaction->note)
477  ],
478 
479  ]
480  ])->send('Accessory Checked In');
481 
482  } catch (Exception $e) {
483 
484  }
485 
486  }
487 
488 
489  $log = $logaction->logaction('checkin from');
490 
491  if (!is_null($accessory_user->assigned_to)) {
492  $user = User::find($accessory_user->assigned_to);
493  }
494 
495  $data['log_id'] = $logaction->id;
496  $data['first_name'] = e($user->first_name);
497  $data['item_name'] = e($accessory->name);
498  $data['checkin_date'] = e($logaction->created_at);
499  $data['item_tag'] = '';
500  $data['note'] = e($logaction->note);
501 
502  if (($accessory->checkin_email()=='1')) {
503 
504  Mail::send('emails.checkin-asset', $data, function ($m) use ($user) {
505  $m->to($user->email, $user->first_name . ' ' . $user->last_name);
506  $m->subject('Confirm Accessory Checkin');
507  });
508  }
509 
510  if ($backto=='user') {
511  return Redirect::to("admin/users/".$return_to.'/view')->with('success', trans('admin/accessories/message.checkin.success'));
512  } else {
513  return Redirect::to("admin/accessories/".$accessory->id."/view")->with('success', trans('admin/accessories/message.checkin.success'));
514  }
515  }
516 
517  // Redirect to the accessory management page with error
518  return Redirect::to("admin/accessories")->with('error', trans('admin/accessories/message.checkin.error'));
519  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static getSettings()
Definition: Setting.php:33
App\Http\Controllers\AccessoriesController::postCheckout ( Request  $request,
  $accessoryId 
)

Save the Accessory checkout information.

If Slack is enabled and/or asset acceptance is enabled, it will also trigger a Slack message and send an email.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
Redirect

Definition at line 291 of file AccessoriesController.php.

292  {
293  // Check if the accessory exists
294  if (is_null($accessory = Accessory::find($accessoryId))) {
295  // Redirect to the accessory management page with error
296  return Redirect::to('accessories')->with('error', trans('admin/accessories/message.user_not_found'));
297  } elseif (!Company::isCurrentUserHasAccess($accessory)) {
298  return Redirect::to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
299  }
300 
301  if (!$user = User::find(Input::get('assigned_to'))) {
302  return Redirect::to('admin/accessories')->with('error', trans('admin/accessories/message.not_found'));
303  }
304 
305  // Update the accessory data
306  $accessory->assigned_to = e(Input::get('assigned_to'));
307 
308  $accessory->users()->attach($accessory->id, array(
309  'accessory_id' => $accessory->id,
310  'assigned_to' => e(Input::get('assigned_to'))));
311 
312  $admin_user = Auth::user();
313 
314  $logaction = new Actionlog();
315  $logaction->accessory_id = $accessory->id;
316  $logaction->checkedout_to = $accessory->assigned_to;
317  $logaction->asset_type = 'accessory';
318  $logaction->location_id = Auth::user()->location_id;
319  $logaction->user_id = $admin_user->id;
320  $logaction->note = e(Input::get('note'));
321 
322 
323 
324  $settings = Setting::getSettings();
325 
326  if ($settings->slack_endpoint) {
327 
328 
329  $slack_settings = [
330  'username' => $settings->botname,
331  'channel' => $settings->slack_channel,
332  'link_names' => true
333  ];
334 
335  $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
336 
337  try {
338  $client->attach([
339  'color' => 'good',
340  'fields' => [
341  [
342  'title' => 'Checked Out:',
343  'value' => strtoupper($logaction->asset_type).' <'.config('app.url').'/admin/accessories/'.$accessory->id.'/view'.'|'.$accessory->name.'> checked out to <'.config('app.url').'/admin/users/'.$user->id.'/view|'.$user->fullName().'> by <'.config('app.url').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.'
344  ],
345  [
346  'title' => 'Note:',
347  'value' => e($logaction->note)
348  ],
349  ]
350  ])->send('Accessory Checked Out');
351  } catch (Exception $e) {
352 
353  }
354 
355  }
356 
357 
358 
359  $log = $logaction->logaction('checkout');
360 
361  $accessory_user = DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first();
362 
363  $data['log_id'] = $logaction->id;
364  $data['eula'] = $accessory->getEula();
365  $data['first_name'] = $user->first_name;
366  $data['item_name'] = $accessory->name;
367  $data['checkout_date'] = $logaction->created_at;
368  $data['item_tag'] = '';
369  $data['expected_checkin'] = '';
370  $data['note'] = $logaction->note;
371  $data['require_acceptance'] = $accessory->requireAcceptance();
372 
373 
374  if (($accessory->requireAcceptance()=='1') || ($accessory->getEula())) {
375 
376  Mail::send('emails.accept-accessory', $data, function ($m) use ($user) {
377  $m->to($user->email, $user->first_name . ' ' . $user->last_name);
378  $m->subject('Confirm accessory delivery');
379  });
380  }
381 
382  // Redirect to the new accessory page
383  return Redirect::to("admin/accessories")->with('success', trans('admin/accessories/message.checkout.success'));
384 
385 
386 
387  }
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96
static getSettings()
Definition: Setting.php:33
App\Http\Controllers\AccessoriesController::postCreate ( Request  $request)

Validate and save new Accessory from form post.

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

Definition at line 72 of file AccessoriesController.php.

73  {
74 
75  // create a new model instance
76  $accessory = new Accessory();
77 
78  // Update the accessory data
79  $accessory->name = e(Input::get('name'));
80  $accessory->category_id = e(Input::get('category_id'));
81  $accessory->location_id = e(Input::get('location_id'));
82  $accessory->min_amt = e(Input::get('min_amt'));
83  $accessory->company_id = Company::getIdForCurrentUser(Input::get('company_id'));
84  $accessory->order_number = e(Input::get('order_number'));
85 
86  if (e(Input::get('purchase_date')) == '') {
87  $accessory->purchase_date = null;
88  } else {
89  $accessory->purchase_date = e(Input::get('purchase_date'));
90  }
91 
92  if (e(Input::get('purchase_cost')) == '0.00') {
93  $accessory->purchase_cost = null;
94  } else {
95  $accessory->purchase_cost = e(Input::get('purchase_cost'));
96  }
97 
98  $accessory->qty = e(Input::get('qty'));
99  $accessory->user_id = Auth::user()->id;
100 
101  // Was the accessory created?
102  if ($accessory->save()) {
103  // Redirect to the new accessory page
104  return Redirect::to("admin/accessories")->with('success', trans('admin/accessories/message.create.success'));
105  }
106 
107 
108  return Redirect::back()->withInput()->withErrors($accessory->getErrors());
109  }
static getIdForCurrentUser($unescaped_input)
Definition: Company.php:81
App\Http\Controllers\AccessoriesController::postEdit ( Request  $request,
  $accessoryId = null 
)

Save edited Accessory from form post.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
int$accessoryId
Returns
Redirect

Definition at line 146 of file AccessoriesController.php.

147  {
148  // Check if the blog post exists
149  if (is_null($accessory = Accessory::find($accessoryId))) {
150  // Redirect to the blogs management page
151  return Redirect::to('admin/accessories')->with('error', trans('admin/accessories/message.does_not_exist'));
152  } elseif (!Company::isCurrentUserHasAccess($accessory)) {
153  return Redirect::to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
154  }
155 
156  // Update the accessory data
157  $accessory->name = e(Input::get('name'));
158 
159  if (e(Input::get('location_id')) == '') {
160  $accessory->location_id = null;
161  } else {
162  $accessory->location_id = e(Input::get('location_id'));
163  }
164  $accessory->min_amt = e(Input::get('min_amt'));
165  $accessory->category_id = e(Input::get('category_id'));
166  $accessory->company_id = Company::getIdForCurrentUser(Input::get('company_id'));
167  $accessory->order_number = e(Input::get('order_number'));
168 
169  if (e(Input::get('purchase_date')) == '') {
170  $accessory->purchase_date = null;
171  } else {
172  $accessory->purchase_date = e(Input::get('purchase_date'));
173  }
174 
175  if (e(Input::get('purchase_cost')) == '0.00') {
176  $accessory->purchase_cost = null;
177  } else {
178  $accessory->purchase_cost = e(Input::get('purchase_cost'));
179  }
180 
181  $accessory->qty = e(Input::get('qty'));
182 
183  // Was the accessory created?
184  if ($accessory->save()) {
185  // Redirect to the new accessory page
186  return Redirect::to("admin/accessories")->with('success', trans('admin/accessories/message.update.success'));
187  }
188 
189 
190  return Redirect::back()->withInput()->withErrors($accessory->getErrors());
191 
192  }
static getIdForCurrentUser($unescaped_input)
Definition: Company.php:81
static isCurrentUserHasAccess($companyable)
Definition: Company.php:96

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