mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Added location to checkout in API
This commit is contained in:
parent
5b489e003d
commit
cc7be5f947
|
@ -421,6 +421,8 @@ class AssetsController extends Controller
|
||||||
$asset->requestable = $request->get('requestable') : '';
|
$asset->requestable = $request->get('requestable') : '';
|
||||||
($request->has('rtd_location_id')) ?
|
($request->has('rtd_location_id')) ?
|
||||||
$asset->rtd_location_id = $request->get('rtd_location_id') : '';
|
$asset->rtd_location_id = $request->get('rtd_location_id') : '';
|
||||||
|
($request->has('rtd_location_id')) ?
|
||||||
|
$asset->location_id = $request->get('rtd_location_id') : '';
|
||||||
($request->has('company_id')) ?
|
($request->has('company_id')) ?
|
||||||
$asset->company_id = Company::getIdForCurrentUser($request->get('company_id')) : '';
|
$asset->company_id = Company::getIdForCurrentUser($request->get('company_id')) : '';
|
||||||
|
|
||||||
|
@ -438,14 +440,17 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
if ($request->get('assigned_user')) {
|
if ($request->get('assigned_user')) {
|
||||||
$target = User::find(request('assigned_user'));
|
$target = User::find(request('assigned_user'));
|
||||||
|
$location = $target->location_id;
|
||||||
} elseif ($request->get('assigned_asset')) {
|
} elseif ($request->get('assigned_asset')) {
|
||||||
$target = Asset::find(request('assigned_asset'));
|
$target = Asset::find(request('assigned_asset'));
|
||||||
|
$location = $target->location_id;
|
||||||
} elseif ($request->get('assigned_location')) {
|
} elseif ($request->get('assigned_location')) {
|
||||||
$target = Location::find(request('assigned_location'));
|
$target = Location::find(request('assigned_location'));
|
||||||
|
$location = $target->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($target)) {
|
if (isset($target)) {
|
||||||
$asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update', e($request->get('name')));
|
$asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update', e($request->get('name')), $location);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success')));
|
||||||
|
@ -512,14 +517,18 @@ class AssetsController extends Controller
|
||||||
];
|
];
|
||||||
if ($request->has('user_id')) {
|
if ($request->has('user_id')) {
|
||||||
$target = User::find($request->input('user_id'));
|
$target = User::find($request->input('user_id'));
|
||||||
|
$location = $target->location_id;
|
||||||
$error_payload['target_id'] = $request->input('user_id');
|
$error_payload['target_id'] = $request->input('user_id');
|
||||||
$error_payload['target_type'] = User::class;
|
$error_payload['target_type'] = User::class;
|
||||||
// Don't let the user check an asset out to itself
|
// Don't let the user check an asset out to itself
|
||||||
} elseif ($request->has('asset_id')) {
|
} elseif ($request->has('asset_id')) {
|
||||||
$target = Asset::where('id','!=',$asset_id)->find($request->input('asset_id'));
|
$target = Asset::where('id','!=',$asset_id)->find($request->input('asset_id'));
|
||||||
|
$location = $target->location_id;
|
||||||
$error_payload['target_id'] = $request->input('asset_id');
|
$error_payload['target_id'] = $request->input('asset_id');
|
||||||
$error_payload['target_type'] = Asset::class;
|
$error_payload['target_type'] = Asset::class;
|
||||||
} elseif ($request->has('location_id')) {
|
} elseif ($request->has('location_id')) {
|
||||||
|
$target = Location::find($request->input('location_id'));
|
||||||
|
$location = $target->id;
|
||||||
$target = Location::find($request->input('location_id'));
|
$target = Location::find($request->input('location_id'));
|
||||||
$error_payload['target_id'] = $request->input('location_id');
|
$error_payload['target_id'] = $request->input('location_id');
|
||||||
$error_payload['target_type'] = Location::class;
|
$error_payload['target_type'] = Location::class;
|
||||||
|
@ -541,13 +550,11 @@ class AssetsController extends Controller
|
||||||
$asset->location_id = $target->rtd_location_id;
|
$asset->location_id = $target->rtd_location_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite that if the target has a location ID though
|
$asset->location_id = $location;
|
||||||
if ($target->location_id!='') {
|
|
||||||
$asset->location_id = $target->location_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($asset->checkOut($target, Auth::user(), $checkout_at, $expected_checkin, $note, $asset_name)) {
|
if ($asset->checkOut($target, Auth::user(), $checkout_at, $expected_checkin, $note, $asset_name, $location)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +570,7 @@ class AssetsController extends Controller
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function checkin($asset_id)
|
public function checkin(Request $request, $asset_id)
|
||||||
{
|
{
|
||||||
$this->authorize('checkin', Asset::class);
|
$this->authorize('checkin', Asset::class);
|
||||||
$asset = Asset::findOrFail($asset_id);
|
$asset = Asset::findOrFail($asset_id);
|
||||||
|
@ -581,6 +588,13 @@ class AssetsController extends Controller
|
||||||
$asset->assignedTo()->disassociate($asset);
|
$asset->assignedTo()->disassociate($asset);
|
||||||
$asset->accepted = null;
|
$asset->accepted = null;
|
||||||
$asset->name = e(Input::get('name'));
|
$asset->name = e(Input::get('name'));
|
||||||
|
$asset->location_id = $asset->rtd_location_id;
|
||||||
|
|
||||||
|
if ($request->has('location_id')) {
|
||||||
|
$asset->location_id = $request->input('location_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
$asset->location_id = $asset->rtd_location_id;
|
||||||
|
|
||||||
if (Input::has('status_id')) {
|
if (Input::has('status_id')) {
|
||||||
$asset->status_id = e(Input::get('status_id'));
|
$asset->status_id = e(Input::get('status_id'));
|
||||||
|
|
Loading…
Reference in a new issue