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') +