From 65cd28aad3903e11879e01faba382454dec7e75c Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 27 Nov 2013 03:39:28 -0500 Subject: [PATCH 1/2] Fixes #14 --- app/controllers/admin/AssetsController.php | 88 ++++++++++-- app/models/Asset.php | 3 +- app/routes.php | 2 + app/views/backend/assets/clone.blade.php | 156 +++++++++++++++++++++ app/views/backend/assets/view.blade.php | 5 +- 5 files changed, 241 insertions(+), 13 deletions(-) create mode 100644 app/views/backend/assets/clone.blade.php diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index 0c2fbf4d9f..2d25883e33 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -108,19 +108,42 @@ class AssetsController extends AdminController { if ($asset->validate($new)) { + if ( e(Input::get('status_id')) == '') { + $asset->status_id = NULL; + } else { + $asset->status_id = e(Input::get('status_id')); + } + + if (e(Input::get('warranty_months')) == '') { + $asset->warranty_months = NULL; + } else { + $asset->warranty_months = e(Input::get('warranty_months')); + } + + if (e(Input::get('purchase_cost')) == '') { + $asset->purchase_cost = NULL; + } else { + $asset->purchase_cost = e(Input::get('purchase_cost')); + } + + if (e(Input::get('purchase_date')) == '') { + $asset->purchase_date = NULL; + } else { + $asset->purchase_date = e(Input::get('purchase_date')); + } + // Save the asset data $asset->name = e(Input::get('name')); $asset->serial = e(Input::get('serial')); $asset->model_id = e(Input::get('model_id')); - $asset->purchase_date = e(Input::get('purchase_date')); - $asset->purchase_cost = e(Input::get('purchase_cost')); $asset->order_number = e(Input::get('order_number')); $asset->notes = e(Input::get('notes')); $asset->asset_tag = e(Input::get('asset_tag')); - $asset->status_id = e(Input::get('status_id')); - $asset->warranty_months = e(Input::get('warranty_months')); $asset->user_id = Sentry::getId(); + $asset->assigned_to = '0'; + $asset->archived = '0'; $asset->physical = '1'; + $asset->depreciate = '0'; // Was the asset created? @@ -193,7 +216,8 @@ class AssetsController extends AdminController { 'asset_tag' => 'required|alpha_dash|min:3', 'model_id' => 'required', 'serial' => 'required|alpha_space|min:3', - 'warranty_months' => 'required|integer', + 'warranty_months' => 'integer', + 'notes' => 'alpha_space', ); // Create a new validator instance from our validation rules @@ -206,17 +230,37 @@ class AssetsController extends AdminController { return Redirect::back()->withInput()->withErrors($validator); } + if ( e(Input::get('status_id')) == '') { + $asset->status_id = NULL; + } else { + $asset->status_id = e(Input::get('status_id')); + } + + if (e(Input::get('warranty_months')) == '') { + $asset->warranty_months = NULL; + } else { + $asset->warranty_months = e(Input::get('warranty_months')); + } + + if (e(Input::get('purchase_cost')) == '') { + $asset->purchase_cost = NULL; + } else { + $asset->purchase_cost = e(Input::get('purchase_cost')); + } + + if (e(Input::get('purchase_date')) == '') { + $asset->purchase_date = NULL; + } else { + $asset->purchase_date = e(Input::get('purchase_date')); + } + // Update the asset data $asset->name = e(Input::get('name')); $asset->serial = e(Input::get('serial')); $asset->model_id = e(Input::get('model_id')); - $asset->purchase_date = e(Input::get('purchase_date')); - $asset->purchase_cost = e(Input::get('purchase_cost')); $asset->order_number = e(Input::get('order_number')); $asset->asset_tag = e(Input::get('asset_tag')); - $asset->status_id = e(Input::get('status_id')); - $asset->warranty_months = e(Input::get('warranty_months')); $asset->notes = e(Input::get('notes')); $asset->physical = '1'; @@ -432,6 +476,32 @@ class AssetsController extends AdminController { } + /** + * Asset update. + * + * @param int $assetId + * @return View + */ + public function getClone($assetId = null) + { + // Check if the asset exists + if (is_null($asset = Asset::find($assetId))) + { + // Redirect to the asset management page + return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.does_not_exist')); + } + + // Grab the dropdown list of models + $model_list = array('' => '') + Model::lists('name', 'id'); + + // Grab the dropdown list of status + $statuslabel_list = array('' => 'Pending') + array('1' => 'Ready to Deploy') + Statuslabel::lists('name', 'id'); + + // get depreciation list + $depreciation_list = array('' => '') + Depreciation::lists('name', 'id'); + + return View::make('backend/assets/clone', compact('asset'))->with('model_list',$model_list)->with('depreciation_list',$depreciation_list)->with('statuslabel_list',$statuslabel_list); + } } diff --git a/app/models/Asset.php b/app/models/Asset.php index d156a403c5..8d90d42702 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -9,8 +9,9 @@ class Asset extends Elegant { 'asset_tag' => 'required|alpha_space|min:3|unique:assets', 'model_id' => 'required', 'serial' => 'required|alpha_dash|min:3', - 'warranty_months' => 'integer|min:1', + 'warranty_months' => 'integer', 'note' => 'alpha_space', + 'notes' => 'alpha_space', ); diff --git a/app/routes.php b/app/routes.php index af222ba1ce..5b10d37a83 100755 --- a/app/routes.php +++ b/app/routes.php @@ -34,6 +34,8 @@ Route::group(array('prefix' => 'assets'), function() Route::post('create', 'Controllers\Admin\AssetsController@postCreate'); Route::get('{assetId}/edit', array('as' => 'update/asset', 'uses' => 'Controllers\Admin\AssetsController@getEdit')); Route::post('{assetId}/edit', 'Controllers\Admin\AssetsController@postEdit'); + Route::get('{assetId}/clone', array('as' => 'clone/asset', 'uses' => 'Controllers\Admin\AssetsController@getClone')); + Route::post('{assetId}/clone', 'Controllers\Admin\AssetsController@postCreate'); Route::get('{assetId}/delete', array('as' => 'delete/asset', 'uses' => 'Controllers\Admin\AssetsController@getDelete')); Route::get('{assetId}/checkout', array('as' => 'checkout/asset', 'uses' => 'Controllers\Admin\AssetsController@getCheckout')); Route::post('{assetId}/checkout', 'Controllers\Admin\AssetsController@postCheckout'); diff --git a/app/views/backend/assets/clone.blade.php b/app/views/backend/assets/clone.blade.php new file mode 100644 index 0000000000..77da3d76e4 --- /dev/null +++ b/app/views/backend/assets/clone.blade.php @@ -0,0 +1,156 @@ +@extends('backend/layouts/default') + +{{-- Page title --}} +@section('title') + Clone Asset +@parent +@stop + +{{-- Page content --}} +@section('content') + + + +
+ + + + +
+ +
+ + + + +
+ +
+ + {{ $errors->first('asset_tag', ' :message') }} +
+
+ +
+ +
+ + {{ $errors->first('name', ' :message') }} +
+
+ + + +
+ +
+ + {{ $errors->first('serial', ' :message') }} +
+
+ + +
+ +
+ + {{ $errors->first('order_number', ' :message') }} +
+
+ + +
+ +
+ {{ Form::select('model_id', $model_list , Input::old('model_id', $asset->model_id), array('class'=>'select2', 'style'=>'min-width:350px')) }} + {{ $errors->first('model_id', ' :message') }} +
+
+ + +
+ +
+ + {{ $errors->first('purchase_date', ' :message') }} + +
+
+ + +
+ +
+
+ $ + + {{ $errors->first('purchase_cost', ' :message') }} +
+
+
+ + +
+ +
+ months + {{ $errors->first('warranty_months', ' :message') }} +
+
+ + +
+ +
+
+ {{ Form::select('depreciation_id', $depreciation_list , Input::old('depreciation_id', $asset->depreciation_id), array('class'=>'select2', 'style'=>'width:250px')) }} + {{ $errors->first('depreciation_id', ' :message') }} +
+
+
+ + +
+ +
+
+ {{ Form::select('status_id', $statuslabel_list , Input::old('status_id', $asset->status_id), array('class'=>'select2', 'style'=>'width:250px')) }} + {{ $errors->first('depreciation_id', ' :message') }} +
+
+
+ + + +
+ +
+ + {{ $errors->first('notes', ' :message') }} +
+
+ + + + +
+ + +
+
+ Cancel + +
+
+ + + +@stop diff --git a/app/views/backend/assets/view.blade.php b/app/views/backend/assets/view.blade.php index 098c556e15..b6aafe1a20 100644 --- a/app/views/backend/assets/view.blade.php +++ b/app/views/backend/assets/view.blade.php @@ -25,6 +25,7 @@ View Asset {{ $asset->asset_tag }} ::
  • Checkout
  • @endif
  • Edit Asset
  • +
  • Clone Asset
  • @@ -110,7 +111,7 @@ View Asset {{ $asset->asset_tag }} :: @endif @if ($asset->purchase_cost) -
  • Purchase Cost: ${{ number_format($asset->purchase_cost) }}
  • +
  • Purchase Cost: ${{ number_format($asset->purchase_cost,2) }}
  • @endif @if ($asset->order_number)
  • Order #: {{ $asset->order_number }}
  • @@ -166,8 +167,6 @@ View Asset {{ $asset->asset_tag }} :: @else @endif From acd9505597ff29b7115fb216e845d3183e1ba8c3 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 27 Nov 2013 03:40:01 -0500 Subject: [PATCH 2/2] Two-digit decimal for purchase_cost --- app/views/backend/licenses/view.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/backend/licenses/view.blade.php b/app/views/backend/licenses/view.blade.php index 4c0faa82ca..4ee6abf83e 100644 --- a/app/views/backend/licenses/view.blade.php +++ b/app/views/backend/licenses/view.blade.php @@ -163,7 +163,7 @@ View License {{ $license->name }} ::
  • Purchase Date: {{ $license->purchase_date }}
  • @endif @if ($license->purchase_cost) -
  • Purchase Cost: ${{ number_format($license->purchase_cost) }}
  • +
  • Purchase Cost: ${{ number_format($license->purchase_cost,2) }}
  • @endif @if ($license->order_number)
  • Order #: {{ $license->order_number }}