diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 7b26ed8d57..b9bb6b09d2 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -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; diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 00815b8f6e..e14eacff09 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -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 = '' . e($activity->item->assigneduser->present()->fullName()) . ''; - + $activity_target = $activity->item->assignedTo->nameUrl(); } elseif ($activity->action_type=='requested') { if ($activity->user) { $activity_target = ''.$activity->user->present()->fullName().''; @@ -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). '"'; - } else { - $show_loc .= 'Default location '.$asset->rtd_location_id.' is invalid'; - } + if($asset->assetLoc) { + $show_loc = $asset->assetLoc->present()->name(); + } else { + $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, ','); } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 32a6cae796..ff4cd7aea6 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -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; diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index 4845b37b65..e9b4dabfed 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -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