From 55ccc000ebba3fd42ae13c9c897e8f157a193886 Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Thu, 17 Nov 2016 17:54:29 -0600 Subject: [PATCH] Fix loggable checkin (#2935) * Log the user items are checked in from This restores functionality that was lost in the port to loggable. I'd still like to figure out a better term for the table, currently it says to, but I wonder if target is a better choice? * Fix display of remaining seats on license view --- app/Http/Controllers/AccessoriesController.php | 2 +- app/Http/Controllers/LicensesController.php | 10 ++++++---- app/Models/Asset.php | 4 ++-- app/Models/License.php | 2 +- app/Models/Loggable.php | 4 +++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index ee11627e9c..e2d8e2565f 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -427,8 +427,8 @@ class AccessoriesController extends Controller return redirect()->to('admin/accessories')->with('error', trans('general.insufficient_permissions')); } - $logaction = $accessory->logCheckin(e(Input::get('note'))); $return_to = e($accessory_user->assigned_to); + $logaction = $accessory->logCheckin(User::find($return_to), e(Input::get('note'))); $admin_user = Auth::user(); diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index fdc7a22df2..d4106fb62d 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -670,8 +670,10 @@ class LicensesController extends Controller // Ooops.. something went wrong return redirect()->back()->withInput()->withErrors($validator); } - $return_to = $licenseseat->assigned_to; - + $return_to = User::find($licenseseat->assigned_to); + if (!$return_to) { + $return_to = Asset::find($licenseseat->asset_id); + } // Update the asset data $licenseseat->assigned_to = null; $licenseseat->asset_id = null; @@ -680,7 +682,7 @@ class LicensesController extends Controller // Was the asset updated? if ($licenseseat->save()) { - $licenseseat->logCheckin(e(Input::get('note'))); + $licenseseat->logCheckin($return_to, e(Input::get('note'))); $settings = Setting::getSettings(); @@ -720,7 +722,7 @@ class LicensesController extends Controller if ($backto=='user') { - return redirect()->to("admin/users/".$return_to.'/view')->with('success', trans('admin/licenses/message.checkin.success')); + return redirect()->to("admin/users/".$return_to->id.'/view')->with('success', trans('admin/licenses/message.checkin.success')); } else { return redirect()->to("admin/licenses/".$licenseseat->license_id."/view")->with('success', trans('admin/licenses/message.checkin.success')); } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 42addbf9e5..44554738df 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -217,7 +217,8 @@ class Asset extends Depreciable $logaction->item_type = Asset::class; $logaction->item_id = $this->id; $logaction->target_type = User::class; - $logaction->target_id = $this->assigned_to; + // On Checkin, this is the user that previously had the asset. + $logaction->target_id = $user->id; $logaction->note = $note; $logaction->user_id = $admin->id; if ($checkout_at!='') { @@ -232,7 +233,6 @@ class Asset extends Depreciable } } else { // Update the asset data to null, since it's being checked in - $logaction->target_id = ''; $logaction->location_id = null; } $logaction->user()->associate($admin); diff --git a/app/Models/License.php b/app/Models/License.php index 29146631b5..07e06fd200 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -170,7 +170,7 @@ class License extends Depreciable public function remaincount() { $total = $this->licenseSeatsCount; - $taken = $this->assigned_seats; + $taken = $this->assigned_seats_count; $diff = ($total - $taken); return $diff; } diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index df2a8c30b3..cba9b125dd 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -63,9 +63,11 @@ trait Loggable * @since [v3.4] * @return \App\Models\Actionlog */ - public function logCheckin($note) + public function logCheckin($target, $note) { $log = new Actionlog; + $log->target_type = get_class($target); + $log->target_id = $target->id; if (static::class == LicenseSeat::class) { $log->item_type = License::class; $log->item_id = $this->license_id;