mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Added RMB and include $item so the asset fields are populated
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
172df0d220
commit
f5eedb8d23
|
@ -27,18 +27,12 @@ class AssetCheckinController extends Controller
|
|||
* @param string $backto
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function create($assetId, $backto = null) : View | RedirectResponse
|
||||
public function create(Asset $asset, $backto = null) : View | RedirectResponse
|
||||
{
|
||||
// Check if the asset exists
|
||||
if (is_null($asset = Asset::find($assetId))) {
|
||||
// Redirect to the asset management page with error
|
||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$this->authorize('checkin', $asset);
|
||||
|
||||
// This asset is already checked in, redirect
|
||||
|
||||
if (is_null($asset->assignedTo)) {
|
||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in'));
|
||||
}
|
||||
|
@ -47,7 +41,11 @@ class AssetCheckinController extends Controller
|
|||
return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix'));
|
||||
}
|
||||
|
||||
return view('hardware/checkin', compact('asset'))->with('statusLabel_list', Helper::statusLabelList())->with('backto', $backto)->with('table_name', 'Assets');
|
||||
return view('hardware/checkin', compact('asset'))
|
||||
->with('item', $asset)
|
||||
->with('statusLabel_list', Helper::statusLabelList())
|
||||
->with('backto', $backto)
|
||||
->with('table_name', 'Assets');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,6 +89,17 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->migrateLegacyLocations($asset);
|
||||
|
||||
$asset->location_id = $asset->rtd_location_id;
|
||||
|
@ -127,6 +136,16 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($asset->save()) {
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@ class AssetCheckoutController extends Controller
|
|||
if ($asset->availableForCheckout()) {
|
||||
return view('hardware/checkout', compact('asset'))
|
||||
->with('statusLabel_list', Helper::deployableStatusLabelList())
|
||||
->with('table_name', 'Assets');
|
||||
->with('table_name', 'Assets')
|
||||
->with('item', $asset);
|
||||
}
|
||||
|
||||
return redirect()->route('hardware.index')
|
||||
|
@ -88,6 +89,7 @@ class AssetCheckoutController extends Controller
|
|||
$asset->status_id = $request->get('status_id');
|
||||
}
|
||||
|
||||
|
||||
if(!empty($asset->licenseseats->all())){
|
||||
if(request('checkout_to_type') == 'user') {
|
||||
foreach ($asset->licenseseats as $seat){
|
||||
|
@ -97,23 +99,35 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$settings = \App\Models\Setting::getSettings();
|
||||
|
||||
// We have to check whether $target->company_id is null here since locations don't have a company yet
|
||||
if (($settings->full_multiple_companies_support) && ((!is_null($target->company_id)) && (!is_null($asset->company_id)))) {
|
||||
if ($target->company_id != $asset->company_id){
|
||||
return redirect()->to("hardware/$assetId/checkout")->with('error', trans('general.error_user_company'));
|
||||
return redirect()->route('hardware.checkout.create', $asset)->with('error', trans('general.error_user_company'));
|
||||
}
|
||||
}
|
||||
|
||||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||
|
||||
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) {
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||
->with('success', trans('admin/hardware/message.checkout.success'));
|
||||
}
|
||||
// Redirect to the asset management page with error
|
||||
return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors());
|
||||
return redirect()->route("hardware.checkout.create", $asset)->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors());
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors());
|
||||
} catch (CheckoutNotAllowed $e) {
|
||||
|
|
Loading…
Reference in a new issue