A free open source IT asset/license management system
Handle array of asset tags
snipe476b58632b0c
diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.phpindex 1baf6235a7..ef4371b475 100755--- a/app/Http/Controllers/Assets/AssetsController.php+++ b/app/Http/Controllers/Assets/AssetsController.php@@ -111,75 +111,92 @@ class AssetsController extends Controller{$this->authorize(Asset::class);+ // Handle asset tags - there could be one, or potentially many.+ // This is only necessary on create, not update, since bulk editing is handled+ // differently+ $asset_tags = $request->input('asset_tags');++ $success = false;+ for ($a = 1; $a <= count($asset_tags); $a++) {++ $asset = new Asset();+ $asset->model()->associate(AssetModel::find($request->input('model_id')));+ $asset->name = $request->input('name');+ $asset->serial = $request->input('serial');+ $asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));+ $asset->model_id = $request->input('model_id');+ $asset->order_number = $request->input('order_number');+ $asset->notes = $request->input('notes');+ $asset->user_id = Auth::id();+ $asset->archived = '0';+ $asset->physical = '1';+ $asset->depreciate = '0';+ $asset->status_id = request('status_id', 0);+ $asset->warranty_months = request('warranty_months', null);+ $asset->purchase_cost = Helper::ParseFloat($request->get('purchase_cost'));+ $asset->purchase_date = request('purchase_date', null);+ $asset->assigned_to = request('assigned_to', null);+ $asset->supplier_id = request('supplier_id', 0);+ $asset->requestable = request('requestable', 0);+ $asset->rtd_location_id = request('rtd_location_id', null);++ if ($asset->assigned_to=='') {+ $asset->location_id = $request->input('rtd_location_id', null);+ }- $asset = new Asset();- $asset->model()->associate(AssetModel::find($request->input('model_id')));-- $asset->name = $request->input('name');- $asset->serial = $request->input('serial');- $asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));- $asset->model_id = $request->input('model_id');- $asset->order_number = $request->input('order_number');- $asset->notes = $request->input('notes');- $asset->asset_tag = $request->input('asset_tag');- $asset->user_id = Auth::id();- $asset->archived = '0';- $asset->physical = '1';- $asset->depreciate = '0';- $asset->status_id = request('status_id', 0);- $asset->warranty_months = request('warranty_months', null);- $asset->purchase_cost = Helper::ParseFloat($request->get('purchase_cost'));- $asset->purchase_date = request('purchase_date', null);- $asset->assigned_to = request('assigned_to', null);- $asset->supplier_id = request('supplier_id', 0);- $asset->requestable = request('requestable', 0);- $asset->rtd_location_id = request('rtd_location_id', null);- if ($asset->assigned_to=='') {- $asset->location_id = $request->input('rtd_location_id', null);- }- $asset = $request->handleImages($asset);+ $asset->asset_tag = $asset_tags[$a];+ $asset = $request->handleImages($asset);- // Update custom fields in the database.- // Validation for these fields is handled through the AssetRequest form request- $model = AssetModel::find($request->get('model_id'));+ // Update custom fields in the database.+ // Validation for these fields is handled through the AssetRequest form request+ $model = AssetModel::find($request->get('model_id'));- if (($model) && ($model->fieldset)) {- foreach ($model->fieldset->fields as $field) {- if ($field->field_encrypted=='1') {- if (Gate::allows('admin')) {- $asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));+ if (($model) && ($model->fieldset)) {+ foreach ($model->fieldset->fields as $field) {+ if ($field->field_encrypted=='1') {+ if (Gate::allows('admin')) {+ $asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));+ }+ } else {+ $asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());}- } else {- $asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());}}- }- // Was the asset created?- if ($asset->save()) {+ // Was the asset created?+ if ($asset->save()) {++ if (request('assigned_user')) {+ $target = User::find(request('assigned_user'));+ $location = $target->location_id;+ } elseif (request('assigned_asset')) {+ $target = Asset::find(request('assigned_asset'));+ $location = $target->location_id;+ } elseif (request('assigned_location')) {+ $target = Location::find(request('assigned_location'));+ $location = $target->id;+ }++ if (isset($target)) {+ $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e($request->get('name')), $location);+ }+ $success = true;- if (request('assigned_user')) {- $target = User::find(request('assigned_user'));- $location = $target->location_id;- } elseif (request('assigned_asset')) {- $target = Asset::find(request('assigned_asset'));- $location = $target->location_id;- } elseif (request('assigned_location')) {- $target = Location::find(request('assigned_location'));- $location = $target->id;- }- if (isset($target)) {- $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e($request->get('name')), $location);}++ }++ if ($success) {// Redirect to the asset listing pagereturn redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.create.success'));}+return redirect()->back()->withInput()->withErrors($asset->getErrors());}diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.phpindex 05d54e5557..7768db45a9 100755--- a/resources/views/hardware/edit.blade.php+++ b/resources/views/hardware/edit.blade.php@@ -23,7 +23,7 @@<!-- we are editing an existing asset -->@if ($item->id)<div class="col-md-7 col-sm-12{{ (\App\Helpers\Helper::checkIfRequired($item, 'asset_tag')) ? ' required' : '' }}">- <input class="form-control" type="text" name="asset_tag" id="asset_tag" value="{{ Input::old('asset_tag', $item->asset_tag) }}" data-validation="required">+ <input class="form-control" type="text" name="asset_tags[1]" id="asset_tag" value="{{ Input::old('asset_tag', $item->asset_tag) }}" data-validation="required"></div>@else<!-- we are creating a new asset - let people use more than one asset tag -->