Merge pull request #15589 from snipe/adds_checkin_action_on_asset_delete

Adds checkin action on asset delete via View UI
This commit is contained in:
snipe 2024-10-01 14:32:48 +01:00 committed by GitHub
commit d274fb6963
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 8 deletions

View file

@ -780,9 +780,16 @@ class AssetsController extends Controller
if ($asset = Asset::find($id)) {
$this->authorize('delete', $asset);
DB::table('assets')
->where('id', $asset->id)
->update(['assigned_to' => null]);
if ($asset->assignedTo) {
$target = $asset->assignedTo;
$checkin_at = date('Y-m-d H:i:s');
$originalValues = $asset->getRawOriginal();
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on delete', $checkin_at, $originalValues));
DB::table('assets')
->where('id', $asset->id)
->update(['assigned_to' => null]);
}
$asset->delete();

View file

@ -428,7 +428,7 @@ class AssetsController extends Controller
* @param int $assetId
* @since [v1.0]
*/
public function destroy($assetId) : RedirectResponse
public function destroy(Request $request, $assetId) : RedirectResponse
{
// Check if the asset exists
if (is_null($asset = Asset::find($assetId))) {
@ -438,9 +438,17 @@ class AssetsController extends Controller
$this->authorize('delete', $asset);
DB::table('assets')
->where('id', $asset->id)
->update(['assigned_to' => null]);
if ($asset->assignedTo) {
$target = $asset->assignedTo;
$checkin_at = date('Y-m-d H:i:s');
$originalValues = $asset->getRawOriginal();
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on delete', $checkin_at, $originalValues));
DB::table('assets')
->where('id', $asset->id)
->update(['assigned_to' => null]);
}
if ($asset->image) {
try {

View file

@ -64,6 +64,7 @@ return [
'checkout' => 'Checkout',
'checkouts_count' => 'Checkouts',
'checkins_count' => 'Checkins',
'checkin_and_delete' => 'Checkin and Delete',
'user_requests_count' => 'Requests',
'city' => 'City',
'click_here' => 'Click here',

View file

@ -255,11 +255,16 @@
@can('delete', $asset)
<div class="col-md-12 hidden-print" style="padding-top: 30px; padding-bottom: 30px;">
@if ($asset->deleted_at=='')
<button class="btn btn-sm btn-block btn-danger btn-social delete-asset" data-toggle="modal" data-title="{{ trans('general.delete') }}" data-content="{{ trans('general.sure_to_delete_var', ['item' => $asset->asset_tag]) }}" data-target="#dataConfirmModal">
<x-icon type="delete" />
{{ trans('general.delete') }}
@if ($asset->assignedTo)
{{ trans('general.checkin_and_delete') }}
@else
{{ trans('general.delete') }}
@endif
</button>
<span class="sr-only">{{ trans('general.delete') }}</span>
@else