This commit is contained in:
Daniel Meltzer 2016-12-27 22:04:11 -05:00
parent d262aec4c3
commit 719463ef54
4 changed files with 22 additions and 28 deletions

View file

@ -518,7 +518,7 @@ class AssetsController extends Controller
$admin = Auth::user();
if (is_null($user = User::find($asset->assigned_to))) {
if (is_null($target = $asset->assignedTo)) {
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in'));
}
@ -531,16 +531,15 @@ class AssetsController extends Controller
$asset->accepted = null;
$asset->name = e(Input::get('name'));
if (Input::has('status_id')) {
$asset->status_id = e(Input::get('status_id'));
}
// Was the asset updated?
if ($asset->save()) {
$logaction = $asset->logCheckin($user, e(request('note')));
$logaction = $asset->logCheckin($target, e(request('note')));
$data['log_id'] = $logaction->id;
$data['first_name'] = $user->first_name;
$data['first_name'] = get_class($target) == User::class ? $target->first_name : '';
$data['item_name'] = $asset->present()->name();
$data['checkin_date'] = $logaction->created_at;
$data['item_tag'] = $asset->asset_tag;

View file

@ -160,7 +160,7 @@ class ReportsController extends Controller
($asset->purchase_cost > 0) ? Helper::formatCurrencyOutput($asset->purchase_cost) : '',
($asset->order_number) ? e($asset->order_number) : '',
($asset->supplier) ? e($asset->supplier->name) : '',
($asset->assigneduser) ? e($asset->assigneduser->present()->fullName()) : '',
($asset->assignedTo) ? e($asset->assignedTo->present()->name()) : '',
($asset->last_checkout!='') ? e($asset->last_checkout) : '',
e($asset->assetLoc->present()->name()),
($asset->notes) ? e($asset->notes) : '',
@ -362,8 +362,7 @@ class ReportsController extends Controller
$activity_target = '';
}
} elseif (($activity->action_type=='accepted') || ($activity->action_type=='declined')) {
$activity_target = '<a href="' . route('users.show', $activity->item->assigneduser->id) . '">' . e($activity->item->assigneduser->present()->fullName()) . '</a>';
$activity_target = $activity->item->assignedTo->nameUrl();
} elseif ($activity->action_type=='requested') {
if ($activity->user) {
$activity_target = '<a href="'.route('users.show', $activity->user_id).'">'.$activity->user->present()->fullName().'</a>';
@ -628,34 +627,25 @@ class ReportsController extends Controller
}
if (e(Input::get('location')) == '1') {
$show_loc = '';
if (($asset->assigned_to > 0) && ($asset->assigneduser) && ($asset->assigneduser->location)) {
$show_loc .= '"' .e($asset->assigneduser->location->name). '"';
} elseif ($asset->rtd_location_id!='') {
$location = Location::find($asset->rtd_location_id);
if ($location) {
$show_loc .= '"' .e($location->name). '"';
if($asset->assetLoc) {
$show_loc = $asset->assetLoc->present()->name();
} else {
$show_loc .= 'Default location '.$asset->rtd_location_id.' is invalid';
$show_loc = 'Default location '.$asset->rtd_location_id.' is invalid';
}
}
$row[] = $show_loc;
}
if (e(Input::get('assigned_to')) == '1') {
if ($asset->assigneduser) {
$row[] = '"' .e($asset->assigneduser->present()->fullName()). '"';
if ($asset->assignedTo) {
$row[] = '"' .e($asset->assignedTo->present()->name()). '"';
} else {
$row[] = ''; // Empty string if unassigned
}
}
if (e(Input::get('username')) == '1') {
// Only works if we're checked out to a user, not anything else.
if ($asset->assigneduser) {
$row[] = '"' .e($asset->assigneduser->username). '"';
} else {
@ -664,6 +654,7 @@ class ReportsController extends Controller
}
if (e(Input::get('employee_num')) == '1') {
// Only works if we're checked out to a user, not anything else.
if ($asset->assigneduser) {
$row[] = '"' .e($asset->assigneduser->employee_num). '"';
} else {
@ -856,7 +847,7 @@ class ReportsController extends Controller
$row[] = str_replace(',', '', e($assetItem->assetlog->model->name));
$row[] = str_replace(',', '', e($assetItem->assetlog->present()->name()));
$row[] = str_replace(',', '', e($assetItem->assetlog->asset_tag));
$row[] = str_replace(',', '', e($assetItem->assetlog->assigneduser->present()->fullName()));
$row[] = str_replace(',', '', e($assetItem->assetlog->assignedTo->present()->name()));
$rows[] = implode($row, ',');
}

View file

@ -119,9 +119,9 @@ class Asset extends Depreciable
if ($this->save()) {
$log = $this->logCheckout($note);
if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
$this->checkOutNotifyMail($log->id, $user, $checkout_at, $expected_checkin, $note);
}
// if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
// $this->checkOutNotifyMail($log->id, $user, $checkout_at, $expected_checkin, $note);
// }
return true;
}
return false;

View file

@ -44,8 +44,9 @@ trait Loggable
$log->user_id = Auth::user()->id;
// @FIXME This needs to be generalized with new asset checkout.
if (!is_null($this->asset_id) || isset($target)) {
$log->target_type = $this->assigned_type;
$log->target_type = Asset::class;
$log->target_id = $this->asset_id;
} else if (!is_null($this->assigned_to)) {
$log->target_type = User::class;
@ -53,6 +54,9 @@ trait Loggable
}
$item = call_user_func(array($log->target_type, 'find'), $log->target_id);
if($this->assignedTo) {
$item = $this->assignedTo;
}
$class = get_class($item);
if($class == Location::class) {
// We can checkout to a location