Refactor into method

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-02-22 18:57:18 +00:00
parent e983ee4d0f
commit 19fb45f488
3 changed files with 21 additions and 31 deletions

View file

@ -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()) {

View file

@ -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();

View file

@ -413,6 +413,20 @@ class Asset extends Depreciable
return $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