diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 514f4484c8..d1d3878705 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -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(); diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index dceaa9b08a..dda54f4c8d 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -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 { diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index b566b1f19d..34315c99a8 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -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', diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 0dd2d75c46..1e040b7603 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -255,11 +255,16 @@ @can('delete', $asset)
+ @if ($asset->deleted_at=='') {{ trans('general.delete') }} @else