mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -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)
|
||||
{
|
||||
$this->validate($request, [
|
||||
"assigned_to" => 'required'
|
||||
]);
|
||||
|
||||
$user = User::find(e(Input::get('assigned_to')));
|
||||
$admin = Auth::user();
|
||||
|
||||
if (!$user) {
|
||||
return redirect()->route('hardware/bulkcheckout')->withInput()->with('error', trans('admin/hardware/message.checkout.user_does_not_exist'));
|
||||
// Find checkout to type
|
||||
if (request('checkout_to_type')=='location') {
|
||||
$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'))) {
|
||||
return redirect()->route('hardware/bulkcheckout')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected'));
|
||||
}
|
||||
|
||||
$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"))) {
|
||||
$checkout_at = e(Input::get('checkout_at'));
|
||||
} else {
|
||||
|
@ -1229,21 +1231,19 @@ class AssetsController extends Controller
|
|||
|
||||
|
||||
$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) {
|
||||
$asset = Asset::find($asset_id);
|
||||
$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!='') {
|
||||
$asset->location_id = $user->location_id;
|
||||
if ($target->location_id!='') {
|
||||
$asset->location_id = $target->location_id;
|
||||
$asset->unsetEventDispatcher();
|
||||
$asset->save();
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($error) {
|
||||
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.',
|
||||
'archived' => 'Archived',
|
||||
'asset' => 'Asset',
|
||||
'bulk_checkout' => 'Checkout Assets to User',
|
||||
'bulk_checkout' => 'Checkout Assets',
|
||||
'checkin' => 'Checkin Asset',
|
||||
'checkout' => 'Checkout Asset',
|
||||
'clone' => 'Clone Asset',
|
||||
|
|
|
@ -27,10 +27,14 @@
|
|||
<form class="form-horizontal" method="post" action="" autocomplete="off">
|
||||
{{ csrf_field() }}
|
||||
|
||||
<!-- User -->
|
||||
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_to'])
|
||||
<!-- Checkout selector -->
|
||||
@include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true'])
|
||||
|
||||
<!-- Checkout/Checkin Date -->
|
||||
@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 -->
|
||||
<div class="form-group {{ $errors->has('checkout_at') ? 'error' : '' }}">
|
||||
{{ Form::label('name', trans('admin/hardware/form.checkout_date'), array('class' => 'col-md-3 control-label')) }}
|
||||
<div class="col-md-8">
|
||||
|
|
Loading…
Reference in a new issue