Rework the bulk checkout to not change how all checkouts work
This commit is contained in:
parent
6b7af802af
commit
3cf746d7df
3 changed files with 15 additions and 10 deletions
|
@ -575,22 +575,24 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
DB::transaction(function () use ($target, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids, $request) {
|
DB::transaction(function () use ($target, $admin, $checkout_at, $expected_checkin, &$errors, $asset_ids, $request) { //NOTE: $errors is passsed by reference!
|
||||||
foreach ($asset_ids as $asset_id) {
|
foreach ($asset_ids as $asset_id) {
|
||||||
$asset = Asset::findOrFail($asset_id);
|
$asset = Asset::findOrFail($asset_id);
|
||||||
$this->authorize('checkout', $asset);
|
$this->authorize('checkout', $asset);
|
||||||
|
|
||||||
$error = $asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e($request->get('note')), $asset->name, null);
|
$checkout_success = $asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e($request->get('note')), $asset->name, null);
|
||||||
|
|
||||||
|
//TODO - I think this logic is duplicated in the checkOut method?
|
||||||
if ($target->location_id != '') {
|
if ($target->location_id != '') {
|
||||||
$asset->location_id = $target->location_id;
|
$asset->location_id = $target->location_id;
|
||||||
$asset::withoutEvents(function () use ($asset) { // TODO - I don't know why this is being saved without events
|
// TODO - I don't know why this is being saved without events
|
||||||
|
$asset::withoutEvents(function () use ($asset) {
|
||||||
$asset->save();
|
$asset->save();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error) {
|
if (!$checkout_success) {
|
||||||
array_merge_recursive($errors, $asset->getErrors()->toArray());
|
$errors = array_merge_recursive($errors, $asset->getErrors()->toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -600,7 +602,7 @@ class BulkAssetsController extends Controller
|
||||||
return redirect()->to('hardware')->with('success', trans_choice('admin/hardware/message.multi-checkout.success', $asset_ids));
|
return redirect()->to('hardware')->with('success', trans_choice('admin/hardware/message.multi-checkout.success', $asset_ids));
|
||||||
}
|
}
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
return redirect()->route('hardware.bulkcheckout.show')->with('error', trans_choice('admin/hardware/message.multi-checkout.error', $asset_ids))->withErrors($errors);
|
return redirect()->route('hardware.bulkcheckout.show')->withInput()->with('error', trans_choice('admin/hardware/message.multi-checkout.error', $asset_ids))->withErrors($errors);
|
||||||
} catch (ModelNotFoundException $e) {
|
} catch (ModelNotFoundException $e) {
|
||||||
return redirect()->route('hardware.bulkcheckout.show')->with('error', $e->getErrors());
|
return redirect()->route('hardware.bulkcheckout.show')->with('error', $e->getErrors());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Watson\Validating\ValidationException;
|
|
||||||
use App\Events\CheckoutableCheckedOut;
|
use App\Events\CheckoutableCheckedOut;
|
||||||
use App\Exceptions\CheckoutNotAllowed;
|
use App\Exceptions\CheckoutNotAllowed;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -380,9 +379,6 @@ class Asset extends Depreciable
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$validator = $this->makeValidator($this->getRules());
|
|
||||||
|
|
||||||
throw new ValidationException($validator, $this);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,5 +115,12 @@
|
||||||
|
|
||||||
@section('moar_scripts')
|
@section('moar_scripts')
|
||||||
@include('partials/assets-assigned')
|
@include('partials/assets-assigned')
|
||||||
|
<script nonce="{{ csrf_token() }}">
|
||||||
|
$(function () {
|
||||||
|
//if there's already a user selected, make sure their checked-out assets show up
|
||||||
|
// (if there isn't one, it won't do anything)
|
||||||
|
$('#assigned_user').change();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
|
|
Loading…
Add table
Reference in a new issue