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
This commit is contained in:
Daniel Meltzer 2016-11-17 17:54:29 -06:00 committed by snipe
parent 19592814d9
commit 55ccc000eb
5 changed files with 13 additions and 9 deletions

View file

@ -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();

View file

@ -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'));
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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;