Skip to content

Commit 7c97477

Browse files
committed
Added default location to physical hardware
1 parent ee7d9be commit 7c97477

File tree

6 files changed

+108
-25
lines changed

6 files changed

+108
-25
lines changed

app/controllers/admin/AssetsController.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,12 @@ public function getCreate()
152152
$model_list = array('' => '') + Model::orderBy('name', 'asc')->lists('name', 'id');
153153
$supplier_list = array('' => '') + Supplier::orderBy('name', 'asc')->lists('name', 'id');
154154
$assigned_to = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat (first_name," ",last_name) as full_name, id'))->whereNull('deleted_at')->lists('full_name', 'id');
155+
$location_list = array('' => '') + Location::lists('name', 'id');
155156

156157
// Grab the dropdown list of status
157158
$statuslabel_list = array('' => Lang::get('general.pending')) + array('0' => Lang::get('general.ready_to_deploy')) + Statuslabel::orderBy('name', 'asc')->lists('name', 'id');
158159

159-
return View::make('backend/hardware/edit')->with('supplier_list',$supplier_list)->with('model_list',$model_list)->with('statuslabel_list',$statuslabel_list)->with('assigned_to',$assigned_to)->with('asset',new Asset);
160+
return View::make('backend/hardware/edit')->with('supplier_list',$supplier_list)->with('model_list',$model_list)->with('statuslabel_list',$statuslabel_list)->with('assigned_to',$assigned_to)->with('location_list',$location_list)->with('asset',new Asset);
160161

161162
}
162163

@@ -170,13 +171,13 @@ public function postCreate()
170171
{
171172
// create a new model instance
172173
$asset = new Asset();
173-
174+
174175
//attempt to validate
175176
$validator = Validator::make(Input::all(), $asset->validationRules());
176177

177178
if ($validator->fails())
178179
{
179-
// The given data did not pass validation
180+
// The given data did not pass validation
180181
return Redirect::back()->withInput()->withErrors($validator->messages());
181182
}
182183
// attempt validation
@@ -211,7 +212,7 @@ public function postCreate()
211212
} else {
212213
$asset->assigned_to = e(Input::get('assigned_to'));
213214
}
214-
215+
215216
if (e(Input::get('supplier_id')) == '') {
216217
$asset->supplier_id = 0;
217218
} else {
@@ -231,7 +232,8 @@ public function postCreate()
231232
$asset->order_number = e(Input::get('order_number'));
232233
$asset->notes = e(Input::get('notes'));
233234
$asset->asset_tag = e(Input::get('asset_tag'));
234-
235+
$asset->rtd_location_id = e(Input::get('rtd_location_id'));
236+
235237
$asset->user_id = Sentry::getId();
236238
$asset->archived = '0';
237239
$asset->physical = '1';
@@ -242,7 +244,7 @@ public function postCreate()
242244
// Redirect to the asset listing page
243245
return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.create.success'));
244246
}
245-
}
247+
}
246248

247249
// Redirect to the asset create page with an error
248250
return Redirect::to('assets/create')->with('error', Lang::get('admin/hardware/message.create.error'));
@@ -264,14 +266,16 @@ public function getEdit($assetId = null)
264266
return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.does_not_exist'));
265267
}
266268

269+
267270
// Grab the dropdown list of models
268271
$model_list = array('' => '') + Model::orderBy('name', 'asc')->lists('name', 'id');
269272
$supplier_list = array('' => '') + Supplier::orderBy('name', 'asc')->lists('name', 'id');
273+
$location_list = array('' => '') + Location::lists('name', 'id');
270274

271275
// Grab the dropdown list of status
272276
$statuslabel_list = array('' => Lang::get('general.pending')) + array('0' => Lang::get('general.ready_to_deploy')) + Statuslabel::orderBy('name', 'asc')->lists('name', 'id');
273277

274-
return View::make('backend/hardware/edit', compact('asset'))->with('model_list',$model_list)->with('supplier_list',$supplier_list)->with('statuslabel_list',$statuslabel_list);
278+
return View::make('backend/hardware/edit', compact('asset'))->with('model_list',$model_list)->with('supplier_list',$supplier_list)->with('location_list',$location_list)->with('statuslabel_list',$statuslabel_list);
275279
}
276280

277281

@@ -287,14 +291,14 @@ public function postEdit($assetId = null)
287291
if (is_null($asset = Asset::find($assetId))) {
288292
// Redirect to the asset management page with error
289293
return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.does_not_exist'));
290-
}
291-
294+
}
295+
292296
//attempt to validate
293297
$validator = Validator::make(Input::all(), $asset->validationRules($assetId));
294298

295299
if ($validator->fails())
296300
{
297-
// The given data did not pass validation
301+
// The given data did not pass validation
298302
return Redirect::back()->withInput()->withErrors($validator->messages());
299303
}
300304
// attempt validation
@@ -330,7 +334,7 @@ public function postEdit($assetId = null)
330334
} else {
331335
$asset->supplier_id = e(Input::get('supplier_id'));
332336
}
333-
337+
334338
if (e(Input::get('requestable')) == '') {
335339
$asset->requestable = 0;
336340
} else {
@@ -343,8 +347,9 @@ public function postEdit($assetId = null)
343347
$asset->model_id = e(Input::get('model_id'));
344348
$asset->order_number = e(Input::get('order_number'));
345349
$asset->asset_tag = e(Input::get('asset_tag'));
346-
$asset->notes = e(Input::get('notes'));
350+
$asset->notes = e(Input::get('notes'));
347351
$asset->physical = '1';
352+
$asset->rtd_location_id = e(Input::get('rtd_location_id'));
348353

349354
// Was the asset updated?
350355
if($asset->save()) {
@@ -355,7 +360,7 @@ public function postEdit($assetId = null)
355360
{
356361
return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.does_not_exist'));
357362
}
358-
}
363+
}
359364

360365

361366
// Redirect to the asset management page with error
@@ -406,7 +411,6 @@ public function getCheckout($assetId)
406411
// Get the dropdown of users and then pass it to the checkout view
407412
$users_list = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat(first_name," ",last_name) as full_name, id'))->whereNull('deleted_at')->orderBy('last_name', 'asc')->orderBy('first_name', 'asc')->lists('full_name', 'id');
408413

409-
//print_r($users);
410414
return View::make('backend/hardware/checkout', compact('asset'))->with('users_list',$users_list);
411415

412416
}
@@ -617,6 +621,8 @@ public function getClone($assetId = null)
617621
// Grab the dropdown list of status
618622
$statuslabel_list = array('' => 'Pending') + array('0' => 'Ready to Deploy') + Statuslabel::lists('name', 'id');
619623

624+
$location_list = array('' => '') + Location::lists('name', 'id');
625+
620626
// get depreciation list
621627
$depreciation_list = array('' => '') + Depreciation::lists('name', 'id');
622628
$supplier_list = array('' => '') + Supplier::orderBy('name', 'asc')->lists('name', 'id');
@@ -625,7 +631,7 @@ public function getClone($assetId = null)
625631
$asset = clone $asset_to_clone;
626632
$asset->id = null;
627633
$asset->asset_tag = '';
628-
return View::make('backend/hardware/edit')->with('supplier_list',$supplier_list)->with('model_list',$model_list)->with('statuslabel_list',$statuslabel_list)->with('assigned_to',$assigned_to)->with('asset',$asset);
634+
return View::make('backend/hardware/edit')->with('supplier_list',$supplier_list)->with('model_list',$model_list)->with('statuslabel_list',$statuslabel_list)->with('assigned_to',$assigned_to)->with('asset',$asset)->with('location_list',$location_list);
629635

630636
}
631637
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class AddRtdLocationToAssets extends Migration {
7+
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
//
16+
Schema::table('assets', function ($table) {
17+
$table->integer('rtd_location_id')->nullable()->default(NULL);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
//
29+
Schema::table('assets', function ($table) {
30+
$table->dropColumn('rtd_location_id');
31+
});
32+
}
33+
34+
}

app/lang/en/admin/hardware/form.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'date' => 'Purchase Date',
1010
'depreciates_on' => 'Depreciates On',
1111
'depreciation' => 'Depreciation',
12+
'default_location' => 'Default Location',
1213
'eol_date' => 'EOL Date',
1314
'eol_rate' => 'EOL Rate',
1415
'expires' => 'Expires',

app/models/Asset.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ class Asset extends Elegant
44
{
55
protected $table = 'assets';
66
protected $softDelete = true;
7-
7+
88
protected $errors;
99
protected $rules = array(
10-
'name' => 'alpha_space|min:6|max:255',
11-
'model_id' => 'required',
10+
'name' => 'alpha_space|min:6|max:255',
11+
'model_id' => 'required',
1212
'warranty_months' => 'integer|min:0|max:240',
1313
'note' => 'alpha_space',
1414
'notes' => 'alpha_space',
@@ -64,6 +64,16 @@ public function assetloc()
6464
return $this->assigneduser->userloc();
6565
}
6666

67+
68+
/**
69+
* Get the asset's location based on the assigned user
70+
**/
71+
public function defaultLoc()
72+
{
73+
return $this->hasOne('Location', 'id', 'rtd_location_id');
74+
}
75+
76+
6777
/**
6878
* Get action logs for this asset
6979
*/

app/routes.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,28 @@
1111

1212
Route::group(array('prefix' => 'hardware'), function () {
1313

14-
Route::get('/', array('as' => '', 'uses' => 'Controllers\Admin\AssetsController@getIndex'));
15-
Route::get('/', array('as' => 'hardware', 'uses' => 'Controllers\Admin\AssetsController@getIndex'));
16-
Route::get('create', array('as' => 'create/hardware', 'uses' => 'Controllers\Admin\AssetsController@getCreate'));
17-
Route::post('create', 'Controllers\Admin\AssetsController@postCreate');
18-
Route::get('{assetId}/edit', array('as' => 'update/hardware', 'uses' => 'Controllers\Admin\AssetsController@getEdit'));
14+
15+
16+
Route::get('/', array(
17+
'as' => 'hardware',
18+
'uses' => 'Controllers\Admin\AssetsController@getIndex')
19+
);
20+
21+
Route::get('create', array(
22+
'as' => 'create/hardware',
23+
'uses' => 'Controllers\Admin\AssetsController@getCreate')
24+
);
25+
26+
Route::post('create', array(
27+
'as' => 'savenew/hardware',
28+
'uses' => 'Controllers\Admin\AssetsController@postCreate')
29+
);
30+
31+
Route::get('{assetId}/edit', array(
32+
'as' => 'update/hardware',
33+
'uses' => 'Controllers\Admin\AssetsController@getEdit')
34+
);
35+
1936
Route::post('{assetId}/edit', 'Controllers\Admin\AssetsController@postEdit');
2037
Route::get('{assetId}/clone', array('as' => 'clone/hardware', 'uses' => 'Controllers\Admin\AssetsController@getClone'));
2138
Route::post('{assetId}/clone', 'Controllers\Admin\AssetsController@postCreate');

app/views/backend/hardware/edit.blade.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
<!-- left column -->
3232
<div class="col-md-12 column">
3333

34-
<form class="form-horizontal" method="post" action="" autocomplete="off" role="form">
34+
@if ($asset->id)
35+
<form class="form-horizontal" method="post" action="{{ route('update/hardware',$asset->id) }}" autocomplete="off" role="form">
36+
@else
37+
<form class="form-horizontal" method="post" action="{{ route('savenew/hardware') }}" autocomplete="off" role="form">
38+
@endif
39+
3540
<!-- CSRF Token -->
3641
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
3742

@@ -114,7 +119,7 @@
114119
</div>
115120
</div>
116121
</div>
117-
122+
118123
<!-- Warrantee -->
119124
<div class="form-group {{ $errors->has('warranty_months') ? ' has-error' : '' }}">
120125
<label for="warranty_months" class="col-md-2 control-label">@lang('admin/hardware/form.warranty')</label>
@@ -144,6 +149,16 @@
144149
</div>
145150
</div>
146151

152+
<!-- Default Location -->
153+
<div class="form-group {{ $errors->has('status_id') ? ' has-error' : '' }}">
154+
<label for="status_id" class="col-md-2 control-label">@lang('admin/hardware/form.default_location')</label>
155+
<div class="col-md-7">
156+
{{ Form::select('rtd_location_id', $location_list , Input::old('rtd_location_id', $asset->rtd_location_id), array('class'=>'select2', 'style'=>'width:350px')) }}
157+
{{ $errors->first('status_id', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
158+
</div>
159+
</div>
160+
161+
147162
@if (!$asset->id)
148163
<!-- Assigned To -->
149164
<div class="form-group {{ $errors->has('assigned_to') ? ' has-error' : '' }}">

0 commit comments

Comments
 (0)