A free open source IT asset/license management system
Refactor into method
snipe19fb45f4889a
diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.phpindex 0541fa926e..4452bfa51d 100644--- a/app/Http/Controllers/Assets/AssetCheckinController.php+++ b/app/Http/Controllers/Assets/AssetCheckinController.php@@ -89,16 +89,8 @@ class AssetCheckinController extends Controller$asset->status_id = e($request->get('status_id'));}- // Check to see if any of the custom fields were included on the form and if they have any values- if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields)) {- foreach ($asset->model->fieldset->fields as $field) {- if ($field->display_checkin == 1) {- if ($request->has($field->db_column)) {- $asset->{$field->db_column} = $request->get($field->db_column);- }- }- }- }+ // Add any custom fields that should be included in the checkout+ $asset->customFieldsForCheckinCheckout('display_checkin');$this->migrateLegacyLocations($asset);@@ -136,16 +128,9 @@ class AssetCheckinController extends Controller});session()->put('redirect_option', $request->get('redirect_option'));- // Check to see if any of the custom fields were included on the form and if they have any values- if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields)) {- foreach ($asset->model->fieldset->fields as $field) {- if ($field->display_checkin == 1) {- if ($request->filled($field->db_column)) {- $asset->{$field->db_column} = $request->get($field->db_column);- }- }- }- }++ // Add any custom fields that should be included in the checkout+ $asset->customFieldsForCheckinCheckout('display_checkin');if ($asset->save()) {diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.phpindex cce8c34d11..4d8c9ffda2 100644--- a/app/Http/Controllers/Assets/AssetCheckoutController.php+++ b/app/Http/Controllers/Assets/AssetCheckoutController.php@@ -99,17 +99,8 @@ class AssetCheckoutController extends Controller}}- // Check to see if any of the custom fields were included on the form and if they have any values- if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields)) {- foreach ($asset->model->fieldset->fields as $field) {- if ($field->display_checkout == 1) {- if ($request->has($field->db_column)) {- $asset->{$field->db_column} = $request->get($field->db_column);- }- }- }- }-+ // Add any custom fields that should be included in the checkout+ $asset->customFieldsForCheckinCheckout('display_checkout');$settings = \App\Models\Setting::getSettings();diff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex 0d4606e4b4..c07ebbfecd 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -413,6 +413,20 @@ class Asset extends Depreciablereturn $this->rules;}+ public function customFieldsForCheckinCheckout($type) {+ // Check to see if any of the custom fields were included on the form and if they have any values+ if (($this->model) && ($this->model->fieldset) && ($this->model->fieldset->fields)) {+ foreach ($this->model->fieldset->fields as $field) {++ if ($field->{$type} == 1) {+ if (request()->has($field->db_column)) {+ $this->{$field->db_column} = request()->get($field->db_column);+ }+ }+ }+ }+ }+/*** Establishes the asset -> depreciation relationship