diff --git a/app/Actions/Assets/UpdateAssetAction.php b/app/Actions/Assets/UpdateAssetAction.php index 10b3801ab8..e7b09fc7ee 100644 --- a/app/Actions/Assets/UpdateAssetAction.php +++ b/app/Actions/Assets/UpdateAssetAction.php @@ -104,13 +104,13 @@ class UpdateAssetAction $asset->rtd_location_id = $rtd_location_id ?? $asset->rtd_location_id; if ($request->has('model_id')) { - $asset->model()->associate(AssetModel::find($request->validated()['model_id'])); + $asset->model()->associate(AssetModel::find($request->validated('model_id'))); } if ($request->has('company_id')) { - $asset->company_id = Company::getIdForCurrentUser($request->validated()['company_id']); + $asset->company_id = Company::getIdForCurrentUser($request->validated('company_id')); } if ($request->has('rtd_location_id') && !$request->has('location_id')) { - $asset->location_id = $request->validated()['rtd_location_id']; + $asset->location_id = $request->validated('rtd_location_id'); } if ($request->input('last_audit_date')) { $asset->last_audit_date = Carbon::parse($request->input('last_audit_date'))->startOfDay()->format('Y-m-d H:i:s'); @@ -121,13 +121,17 @@ class UpdateAssetAction // This is a non-deployable status label - we should check the asset back in. if (($status && $status->getStatuslabelType() != 'deployable') && ($target = $asset->assignedTo)) { + dump('status logic'); $originalValues = $asset->getRawOriginal(); $asset->assigned_to = null; $asset->assigned_type = null; $asset->accepted = null; + dump($asset->assigned_to); event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on asset update', date('Y-m-d H:i:s'), $originalValues)); + // reset this to null so checkout logic doesn't happen below + $target = null; } //this is causing an issue while setting location_id - this came from the gui but doesn't seem to work as expected in the api - @@ -239,6 +243,7 @@ class UpdateAssetAction } if (isset($target)) { + dump($target); $asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update', e($request->get('name')), $location); } diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 555174d9eb..cf460ab401 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -241,7 +241,7 @@ class AssetsController extends Controller $asset_tag = $request->input('asset_tags')[1]; } - $asset = UpdateAssetAction::run( + $updatedAsset = UpdateAssetAction::run( asset: $asset, request: $request, status_id: $request->validated('status_id'), @@ -264,13 +264,14 @@ class AssetsController extends Controller asset_tag: $asset_tag, // same as serials notes: $request->validated('notes'), ); - return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets')) + dump('returned'.$asset->assigned_to); + return redirect()->to(Helper::getRedirectOption($request, $updatedAsset->id, 'Assets')) ->with('success', trans('admin/hardware/message.update.success')); } catch (ValidationException $e) { return redirect()->back()->withInput()->withErrors($e->getErrors()); } catch (\Exception $e) { report($e); - return redirect()->back()->with('error', trans('admin/hardware/message.update.error'), $asset); + return redirect()->back()->with('error', trans('admin/hardware/message.update.error')); } } diff --git a/tests/Feature/Assets/Ui/EditAssetTest.php b/tests/Feature/Assets/Ui/EditAssetTest.php index 27f00b5313..ebe7bf9a97 100644 --- a/tests/Feature/Assets/Ui/EditAssetTest.php +++ b/tests/Feature/Assets/Ui/EditAssetTest.php @@ -74,7 +74,7 @@ class EditAssetTest extends TestCase $user = User::factory()->create(); $deployable_status = Statuslabel::factory()->rtd()->create(); - $achived_status = Statuslabel::factory()->archived()->create(); + $archived_status = Statuslabel::factory()->archived()->create(); $asset = Asset::factory()->assignedToUser($user)->create(['status_id' => $deployable_status->id]); $this->assertTrue($asset->assignedTo->is($user)); @@ -83,7 +83,7 @@ class EditAssetTest extends TestCase $this->actingAs(User::factory()->viewAssets()->editAssets()->create()) ->from(route('hardware.edit', $asset->id)) ->put(route('hardware.update', $asset->id), [ - 'status_id' => $achived_status->id, + 'status_id' => $archived_status->id, 'model_id' => $asset->model_id, 'asset_tags' => $asset->asset_tag, ], @@ -95,7 +95,7 @@ class EditAssetTest extends TestCase $asset = Asset::find($asset->id); $this->assertNull($asset->assigned_to); $this->assertNull($asset->assigned_type); - $this->assertEquals($achived_status->id, $asset->status_id); + $this->assertEquals($archived_status->id, $asset->status_id); Event::assertDispatched(function (CheckoutableCheckedIn $event) use ($currentTimestamp) { return Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp) < 2;