App\Http\Controllers\DepreciationsController Class Reference

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

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

Public Member Functions

 getIndex ()
 Returns a view that invokes the ajax tables which actually contains the content for the depreciation listing, which is generated in getDatatable. More...
 
 getCreate ()
 Returns a view that displays a form to create a new depreciation. More...
 
 postCreate ()
 Validates and stores the new depreciation data. More...
 
 getEdit ($depreciationId=null)
 Returns a view that displays a form to update a depreciation. More...
 
 postEdit ($depreciationId=null)
 Validates and stores the updated depreciation data. More...
 
 getDelete ($depreciationId)
 Validates and deletes a selected depreciation. More...
 
 getDatatable ()
 Generates the JSON used to display the depreciation listing. More...
 

Detailed Description

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

Version
v1.0

Definition at line 20 of file DepreciationsController.php.

Member Function Documentation

App\Http\Controllers\DepreciationsController::getCreate ( )

Returns a view that displays a form to create a new depreciation.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
DepreciationsController::postCreate()
Since
[v1.0]
Returns
View

Definition at line 46 of file DepreciationsController.php.

47  {
48  // Show the page
49  $depreciation_options = \App\Helpers\Helper::depreciationList();
50  return View::make('depreciations/edit')->with('depreciation_options', $depreciation_options)->with('depreciation', new Depreciation);
51  }
static depreciationList()
Definition: Helper.php:125
App\Http\Controllers\DepreciationsController::getDatatable ( )

Generates the JSON used to display the depreciation listing.

See also
DepreciationsController::getIndex()
Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Parameters
string$status
Since
[v1.2]
Returns
String JSON

Definition at line 184 of file DepreciationsController.php.

185  {
186  $depreciations = Depreciation::select(array('id','name','months'));
187 
188  if (Input::has('search')) {
189  $depreciations = $depreciations->TextSearch(e(Input::get('search')));
190  }
191 
192  if (Input::has('offset')) {
193  $offset = e(Input::get('offset'));
194  } else {
195  $offset = 0;
196  }
197 
198  if (Input::has('limit')) {
199  $limit = e(Input::get('limit'));
200  } else {
201  $limit = 50;
202  }
203 
204  $allowed_columns = ['id','name','months'];
205  $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
206  $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
207 
208  $depreciations->orderBy($sort, $order);
209 
210  $depreciationsCount = $depreciations->count();
211  $depreciations = $depreciations->skip($offset)->take($limit)->get();
212 
213  $rows = array();
214 
215  foreach ($depreciations as $depreciation) {
216  $actions = '<a href="'.route('update/depreciations', $depreciation->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/depreciations', $depreciation->id).'" data-content="'.trans('admin/depreciations/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($depreciation->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
217 
218  $rows[] = array(
219  'id' => $depreciation->id,
220  'name' => e($depreciation->name),
221  'months' => e($depreciation->months),
222  'actions' => $actions
223  );
224  }
225 
226  $data = array('total' => $depreciationsCount, 'rows' => $rows);
227 
228  return $data;
229 
230  }
App\Http\Controllers\DepreciationsController::getDelete (   $depreciationId)

Validates and deletes a selected depreciation.

This is a hard-delete. We do not currently soft-delete depreciations.

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

Definition at line 152 of file DepreciationsController.php.

153  {
154  // Check if the depreciation exists
155  if (is_null($depreciation = Depreciation::find($depreciationId))) {
156  // Redirect to the blogs management page
157  return Redirect::to('admin/settings/depreciations')->with('error', trans('admin/depreciations/message.not_found'));
158  }
159 
160  if ($depreciation->has_models() > 0) {
161 
162  // Redirect to the asset management page
163  return Redirect::to('admin/settings/depreciations')->with('error', trans('admin/depreciations/message.assoc_users'));
164  } else {
165 
166  $depreciation->delete();
167 
168  // Redirect to the depreciations management page
169  return Redirect::to('admin/settings/depreciations')->with('success', trans('admin/depreciations/message.delete.success'));
170  }
171 
172  }
App\Http\Controllers\DepreciationsController::getEdit (   $depreciationId = null)

Returns a view that displays a form to update a depreciation.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
DepreciationsController::postEdit()
Parameters
int$depreciationId
Since
[v1.0]
Returns
View

Definition at line 95 of file DepreciationsController.php.

96  {
97  // Check if the depreciation exists
98  if (is_null($depreciation = Depreciation::find($depreciationId))) {
99  // Redirect to the blogs management page
100  return Redirect::to('admin/settings/depreciations')->with('error', trans('admin/depreciations/message.does_not_exist'));
101  }
102 
103  // Show the page
104  //$depreciation_options = array('' => 'Top Level') + Depreciation::lists('name', 'id');
105 
106  $depreciation_options = array('' => 'Top Level') + DB::table('depreciations')->where('id', '!=', $depreciationId)->lists('name', 'id');
107  return View::make('depreciations/edit', compact('depreciation'))->with('depreciation_options', $depreciation_options);
108  }
App\Http\Controllers\DepreciationsController::getIndex ( )

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

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

Definition at line 31 of file DepreciationsController.php.

32  {
33  // Show the page
34  return View::make('depreciations/index', compact('depreciations'));
35  }
App\Http\Controllers\DepreciationsController::postCreate ( )

Validates and stores the new depreciation data.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
DepreciationsController::postCreate()
Since
[v1.0]
Returns
Redirect

Definition at line 62 of file DepreciationsController.php.

63  {
64 
65  // get the POST data
66  $new = Input::all();
67 
68  // create a new instance
69  $depreciation = new Depreciation();
70 
71  // Depreciation data
72  $depreciation->name = e(Input::get('name'));
73  $depreciation->months = e(Input::get('months'));
74  $depreciation->user_id = Auth::user()->id;
75 
76  // Was the asset created?
77  if ($depreciation->save()) {
78  // Redirect to the new depreciation page
79  return Redirect::to("admin/settings/depreciations")->with('success', trans('admin/depreciations/message.create.success'));
80  }
81 
82  return Redirect::back()->withInput()->withErrors($depreciation->getErrors());
83 
84  }
App\Http\Controllers\DepreciationsController::postEdit (   $depreciationId = null)

Validates and stores the updated depreciation data.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
DepreciationsController::getEdit()
Parameters
int$depreciationId
Since
[v1.0]
Returns
Redirect

Definition at line 120 of file DepreciationsController.php.

121  {
122  // Check if the depreciation exists
123  if (is_null($depreciation = Depreciation::find($depreciationId))) {
124  // Redirect to the blogs management page
125  return Redirect::to('admin/settings/depreciations')->with('error', trans('admin/depreciations/message.does_not_exist'));
126  }
127 
128  // Depreciation data
129  $depreciation->name = e(Input::get('name'));
130  $depreciation->months = e(Input::get('months'));
131 
132  // Was the asset created?
133  if ($depreciation->save()) {
134  // Redirect to the depreciation page
135  return Redirect::to("admin/settings/depreciations/")->with('success', trans('admin/depreciations/message.update.success'));
136  }
137 
138  return Redirect::back()->withInput()->withErrors($depreciation->getErrors());
139 
140 
141  }

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