mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Bulk Checkout to Assets and Location (#5385)
This commit is contained in:
parent
8d501e1c24
commit
c8cbc55b59
|
@ -1198,23 +1198,25 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
public function postBulkCheckout(Request $request)
|
public function postBulkCheckout(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
|
||||||
"assigned_to" => 'required'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$user = User::find(e(Input::get('assigned_to')));
|
|
||||||
$admin = Auth::user();
|
$admin = Auth::user();
|
||||||
|
// Find checkout to type
|
||||||
if (!$user) {
|
if (request('checkout_to_type')=='location') {
|
||||||
return redirect()->route('hardware/bulkcheckout')->withInput()->with('error', trans('admin/hardware/message.checkout.user_does_not_exist'));
|
$target = Location::find(request('assigned_location'));
|
||||||
|
} elseif (request('checkout_to_type')=='asset') {
|
||||||
|
$target = Asset::find(request('assigned_asset'));
|
||||||
|
} elseif (request('checkout_to_type')=='user') {
|
||||||
|
$target = User::find(request('assigned_user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array(Input::get('selected_assets'))) {
|
if (!is_array(Input::get('selected_assets'))) {
|
||||||
return redirect()->route('hardware/bulkcheckout')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected'));
|
return redirect()->route('hardware/bulkcheckout')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset_ids = array_filter(Input::get('selected_assets'));
|
$asset_ids = array_filter(Input::get('selected_assets'));
|
||||||
|
foreach ($asset_ids as $asset_id) {
|
||||||
|
if ($target->id == $asset_id) {
|
||||||
|
return redirect()->back()->with('error', 'You cannot check an asset out to itself.');
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) {
|
if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) {
|
||||||
$checkout_at = e(Input::get('checkout_at'));
|
$checkout_at = e(Input::get('checkout_at'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1229,21 +1231,19 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
DB::transaction(function () use ($user, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids) {
|
DB::transaction(function () use ($target, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids) {
|
||||||
|
|
||||||
foreach ($asset_ids as $asset_id) {
|
foreach ($asset_ids as $asset_id) {
|
||||||
$asset = Asset::find($asset_id);
|
$asset = Asset::find($asset_id);
|
||||||
$this->authorize('checkout', $asset);
|
$this->authorize('checkout', $asset);
|
||||||
$error = $asset->checkOut($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null);
|
$error = $asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null);
|
||||||
|
|
||||||
if ($user->location_id!='') {
|
if ($target->location_id!='') {
|
||||||
$asset->location_id = $user->location_id;
|
$asset->location_id = $target->location_id;
|
||||||
$asset->unsetEventDispatcher();
|
$asset->unsetEventDispatcher();
|
||||||
$asset->save();
|
$asset->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($error) {
|
if ($error) {
|
||||||
array_merge_recursive($errors, $asset->getErrors()->toArray());
|
array_merge_recursive($errors, $asset->getErrors()->toArray());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ return array(
|
||||||
'about_assets_text' => 'Assets are items tracked by serial number or asset tag. They tend to be higher value items where identifying a specific item matters.',
|
'about_assets_text' => 'Assets are items tracked by serial number or asset tag. They tend to be higher value items where identifying a specific item matters.',
|
||||||
'archived' => 'Archived',
|
'archived' => 'Archived',
|
||||||
'asset' => 'Asset',
|
'asset' => 'Asset',
|
||||||
'bulk_checkout' => 'Checkout Assets to User',
|
'bulk_checkout' => 'Checkout Assets',
|
||||||
'checkin' => 'Checkin Asset',
|
'checkin' => 'Checkin Asset',
|
||||||
'checkout' => 'Checkout Asset',
|
'checkout' => 'Checkout Asset',
|
||||||
'clone' => 'Clone Asset',
|
'clone' => 'Clone Asset',
|
||||||
|
|
|
@ -27,8 +27,12 @@
|
||||||
<form class="form-horizontal" method="post" action="" autocomplete="off">
|
<form class="form-horizontal" method="post" action="" autocomplete="off">
|
||||||
{{ csrf_field() }}
|
{{ csrf_field() }}
|
||||||
|
|
||||||
<!-- User -->
|
<!-- Checkout selector -->
|
||||||
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_to'])
|
@include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true'])
|
||||||
|
|
||||||
|
@include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_user', 'required'=>'true'])
|
||||||
|
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('general.asset'), 'fieldname' => 'assigned_asset', 'unselect' => 'true', 'style' => 'display:none;', 'required'=>'true'])
|
||||||
|
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'assigned_location', 'style' => 'display:none;', 'required'=>'true'])
|
||||||
|
|
||||||
<!-- Checkout/Checkin Date -->
|
<!-- Checkout/Checkin Date -->
|
||||||
<div class="form-group {{ $errors->has('checkout_at') ? 'error' : '' }}">
|
<div class="form-group {{ $errors->has('checkout_at') ? 'error' : '' }}">
|
||||||
|
|
Loading…
Reference in a new issue