Check for location_id being set before trying to set it on checkout via API

This commit is contained in:
snipe 2020-04-06 15:54:40 -07:00
parent 0d3c18d1df
commit 893944403e
No known key found for this signature in database
GPG key ID: 10BFFDA3ED34B5AC

View file

@ -616,16 +616,14 @@ class AssetsController extends Controller
$target = Asset::where('id','!=',$asset_id)->find(request('assigned_asset')); $target = Asset::where('id','!=',$asset_id)->find(request('assigned_asset'));
$asset->location_id = $target->rtd_location_id; $asset->location_id = $target->rtd_location_id;
// Override with the asset's location_id if it has one // Override with the asset's location_id if it has one
if ($target->location_id!='') { $asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
$asset->location_id = ($target) ? $target->location_id : '';
}
$error_payload['target_id'] = $request->input('assigned_asset'); $error_payload['target_id'] = $request->input('assigned_asset');
$error_payload['target_type'] = 'asset'; $error_payload['target_type'] = 'asset';
} elseif (request('checkout_to_type')=='user') { } elseif (request('checkout_to_type')=='user') {
// Fetch the target and set the asset's new location_id // Fetch the target and set the asset's new location_id
$target = User::find(request('assigned_user')); $target = User::find(request('assigned_user'));
$asset->location_id = ($target) ? $target->location_id : ''; $asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
$error_payload['target_id'] = $request->input('assigned_user'); $error_payload['target_id'] = $request->input('assigned_user');
$error_payload['target_type'] = 'user'; $error_payload['target_type'] = 'user';
} }