diff --git a/app/Console/Commands/PaveIt.php b/app/Console/Commands/PaveIt.php index 21392d7e37..185f6b4ef6 100644 --- a/app/Console/Commands/PaveIt.php +++ b/app/Console/Commands/PaveIt.php @@ -77,6 +77,8 @@ class PaveIt extends Command DB::statement('delete from asset_logs'); DB::statement('delete from asset_maintenances'); DB::statement('delete from asset_uploads'); + DB::statement('delete from action_logs'); + DB::statement('delete from checkout_requests'); DB::statement('delete from consumables_users'); DB::statement('delete from custom_field_custom_fieldset'); DB::statement('delete from custom_fields'); @@ -92,10 +94,12 @@ class PaveIt extends Command \DB::statement('drop table IF EXISTS accessories_users'); \DB::statement('drop table IF EXISTS accessories'); \DB::statement('drop table IF EXISTS asset_logs'); + \DB::statement('drop table IF EXISTS action_logs'); \DB::statement('drop table IF EXISTS asset_maintenances'); \DB::statement('drop table IF EXISTS asset_uploads'); \DB::statement('drop table IF EXISTS assets'); \DB::statement('drop table IF EXISTS categories'); + \DB::statement('drop table IF EXISTS checkout_requests'); \DB::statement('drop table IF EXISTS companies'); \DB::statement('drop table IF EXISTS consumables_users'); \DB::statement('drop table IF EXISTS consumables'); diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 7f8c6debea..334c573387 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -309,14 +309,7 @@ class AccessoriesController extends Controller 'user_id' => Auth::user()->id, 'assigned_to' => e(Input::get('assigned_to')))); - $logaction = new Actionlog(); - $logaction->accessory_id = $accessory->id; - $logaction->asset_id = 0; - $logaction->checkedout_to = $accessory->assigned_to; - $logaction->asset_type = 'accessory'; - $logaction->location_id = $user->location_id; - $logaction->user_id = Auth::user()->id; - $logaction->note = e(Input::get('note')); + $logaction = $accessory->logCheckout(e(Input::get('note'))); @@ -340,11 +333,11 @@ class AccessoriesController extends Controller 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => strtoupper($logaction->asset_type).' <'.config('app.url').'/admin/accessories/'.$accessory->id.'/view'.'|'.$accessory->name.'> checked out to <'.config('app.url').'/admin/users/'.$user->id.'/view|'.$user->fullName().'> by <'.config('app.url').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' + 'value' => 'Accessory <'.config('app.url').'/admin/accessories/'.$accessory->id.'/view'.'|'.$accessory->name.'> checked out to <'.config('app.url').'/admin/users/'.$user->id.'/view|'.$user->fullName().'> by <'.config('app.url').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' ], [ 'title' => 'Note:', - 'value' => e($logaction->note) + 'value' => e(Input::get('note')) ], ] ])->send('Accessory Checked Out'); @@ -355,9 +348,6 @@ class AccessoriesController extends Controller } - - $log = $logaction->logaction('checkout'); - $accessory_user = DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first(); $data['log_id'] = $logaction->id; @@ -435,8 +425,7 @@ class AccessoriesController extends Controller return redirect()->to('admin/accessories')->with('error', trans('general.insufficient_permissions')); } - $logaction = new Actionlog(); - $logaction->checkedout_to = e($accessory_user->assigned_to); + $logaction = $accessory->logCheckin(e(Input::get('note'))); $return_to = e($accessory_user->assigned_to); $admin_user = Auth::user(); @@ -444,12 +433,6 @@ class AccessoriesController extends Controller // Was the accessory updated? if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) { - $logaction->accessory_id = e($accessory->id); - $logaction->location_id = null; - $logaction->asset_type = 'accessory'; - $logaction->user_id = e($admin_user->id); - $logaction->note = e(Input::get('note')); - $settings = Setting::getSettings(); if ($settings->slack_endpoint) { @@ -469,7 +452,7 @@ class AccessoriesController extends Controller 'fields' => [ [ 'title' => 'Checked In:', - 'value' => strtoupper($logaction->asset_type).' <'.config('app.url').'/admin/accessories/'.e($accessory->id).'/view'.'|'.e($accessory->name).'> checked in by <'.config('app.url').'/admin/users/'.e($admin_user->id).'/view'.'|'.e($admin_user->fullName()).'>.' + 'value' => class_basename(strtoupper($logaction->item_type)).' <'.config('app.url').'/admin/accessories/'.e($accessory->id).'/view'.'|'.e($accessory->name).'> checked in by <'.config('app.url').'/admin/users/'.e($admin_user->id).'/view'.'|'.e($admin_user->fullName()).'>.' ], [ 'title' => 'Note:', @@ -485,9 +468,6 @@ class AccessoriesController extends Controller } - - $log = $logaction->logaction('checkin from'); - if (!is_null($accessory_user->assigned_to)) { $user = User::find($accessory_user->assigned_to); } diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index e7512a2530..14ec149b79 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -659,7 +659,7 @@ class AssetsController extends Controller 'fields' => [ [ 'title' => 'Checked In:', - 'value' => strtoupper($logaction->asset_type).' asset <'.config('app.url').'/hardware/'.$asset->id.'/view'.'|'.e($asset->showAssetName()).'> checked in by <'.config('app.url').'/admin/users/'.Auth::user()->id.'/view'.'|'.e(Auth::user()->fullName()).'>.' + 'value' => class_basename(strtoupper($logaction->item_type)).' asset <'.config('app.url').'/hardware/'.$asset->id.'/view'.'|'.e($asset->showAssetName()).'> checked in by <'.config('app.url').'/admin/users/'.Auth::user()->id.'/view'.'|'.e(Auth::user()->fullName()).'>.' ], [ 'title' => 'Note:', @@ -1150,11 +1150,12 @@ class AssetsController extends Controller $item[$asset_tag][$batch_counter]['user_id'] = $user->id; Actionlog::firstOrCreate(array( - 'asset_id' => $asset->id, - 'asset_type' => 'hardware', + 'item_id' => $asset->id, + 'item_type' => Asset::class, 'user_id' => Auth::user()->id, 'note' => 'Checkout imported by '.Auth::user()->fullName().' from history importer', - 'checkedout_to' => $item[$asset_tag][$batch_counter]['user_id'], + 'target_id' => $item[$asset_tag][$batch_counter]['user_id'], + 'target_type' => User::class, 'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'], 'action_type' => 'checkout' ) @@ -1190,11 +1191,11 @@ class AssetsController extends Controller $asset_batch[$x]['real_checkin'] = $checkin_date; Actionlog::firstOrCreate(array( - 'asset_id' => $asset_batch[$x]['asset_id'], - 'asset_type' => 'hardware', + 'item_id' => $asset_batch[$x]['asset_id'], + 'item_type' => Asset::class, 'user_id' => Auth::user()->id, 'note' => 'Checkin imported by ' . Auth::user()->fullName() . ' from history importer', - 'checkedout_to' => null, + 'target_id' => null, 'created_at' => $checkin_date, 'action_type' => 'checkin' ) @@ -1272,15 +1273,8 @@ class AssetsController extends Controller $upload_success = $file->move($destinationPath, $filename); //Log the deletion of seats to the log - $logaction = new Actionlog(); - $logaction->asset_id = $asset->id; - $logaction->asset_type = 'hardware'; - $logaction->user_id = Auth::user()->id; - $logaction->note = e(Input::get('notes')); - $logaction->checkedout_to = null; - $logaction->created_at = date("Y-m-d H:i:s"); - $logaction->filename = $filename; - $log = $logaction->logaction('uploaded'); + $asset->logUpload($filename, e(Input::get('notes'))); + } } else { return redirect()->back()->with('error', trans('admin/hardware/message.upload.nofiles')); @@ -1537,8 +1531,8 @@ class AssetsController extends Controller ->update($update_array)) { $logaction = new Actionlog(); - $logaction->asset_id = $key; - $logaction->asset_type = 'hardware'; + $logaction->item_type = Asset::class; + $logaction->item_id = $key; $logaction->created_at = date("Y-m-d H:i:s"); if (Input::has('rtd_location_id')) { @@ -1595,8 +1589,8 @@ class AssetsController extends Controller ->update($update_array)) { $logaction = new Actionlog(); - $logaction->asset_id = $asset->id; - $logaction->asset_type = 'hardware'; + $logaction->item_type = Asset::class; + $logaction->item_id = $asset->id; $logaction->created_at = date("Y-m-d H:i:s"); $logaction->user_id = Auth::user()->id; $log = $logaction->logaction('deleted'); diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index b550944b8a..83b252409e 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -349,13 +349,7 @@ class ComponentsController extends Controller 'assigned_qty' => e(Input::get('assigned_qty')), 'asset_id' => $asset_id)); - $logaction = new Actionlog(); - $logaction->component_id = $component->id; - $logaction->asset_id = $asset_id; - $logaction->asset_type = 'component'; - $logaction->location_id = $asset->location_id; - $logaction->user_id = Auth::user()->id; - $logaction->note = e(Input::get('note')); + $logaction = $component->logCheckout(e(Input::get('note')), $asset_id); $settings = Setting::getSettings(); @@ -375,7 +369,7 @@ class ComponentsController extends Controller 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => strtoupper($logaction->asset_type).' <'.config('app.url').'/admin/components/'.$component->id.'/view'.'|'.$component->name.'> checked out to <'.config('app.url').'/hardware/'.$asset->id.'/view|'.$asset->showAssetName().'> by <'.config('app.url').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' + 'value' => class_basename(strtoupper($logaction->item_type)).' <'.config('app.url').'/admin/components/'.$component->id.'/view'.'|'.$component->name.'> checked out to <'.config('app.url').'/hardware/'.$asset->id.'/view|'.$asset->showAssetName().'> by <'.config('app.url').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' ], [ 'title' => 'Note:', @@ -389,9 +383,6 @@ class ComponentsController extends Controller } } - - $log = $logaction->logaction('checkout'); - // Redirect to the new component page return redirect()->to("admin/components")->with('success', trans('admin/components/message.checkout.success')); diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 821c388fda..feb75f5d4c 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -316,14 +316,7 @@ class ConsumablesController extends Controller 'user_id' => $admin_user->id, 'assigned_to' => e(Input::get('assigned_to')))); - $logaction = new Actionlog(); - $logaction->consumable_id = $consumable->id; - $logaction->checkedout_to = $consumable->assigned_to; - $logaction->asset_type = 'consumable'; - $logaction->asset_id = 0; - $logaction->location_id = $user->location_id; - $logaction->user_id = Auth::user()->id; - $logaction->note = e(Input::get('note')); + $logaction = $consumable->logCheckout(e(Input::get('note'))); $settings = Setting::getSettings(); @@ -343,7 +336,7 @@ class ConsumablesController extends Controller 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => strtoupper($logaction->asset_type).' <'.config('app.url').'/admin/consumables/'.$consumable->id.'/view'.'|'.$consumable->name.'> checked out to <'.config('app.url').'/admin/users/'.$user->id.'/view|'.$user->fullName().'> by <'.config('app.url').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' + 'value' => strtoupper($logaction->item_type).' <'.config('app.url').'/admin/consumables/'.$consumable->id.'/view'.'|'.$consumable->name.'> checked out to <'.config('app.url').'/admin/users/'.$user->id.'/view|'.$user->fullName().'> by <'.config('app.url').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' ], [ 'title' => 'Note:', @@ -357,9 +350,6 @@ class ConsumablesController extends Controller } } - - $log = $logaction->logaction('checkout'); - $consumable_user = DB::table('consumables_users')->where('assigned_to', '=', $consumable->assigned_to)->where('consumable_id', '=', $consumable->id)->first(); $data['log_id'] = $logaction->id; diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 60204367a0..5cc95632b6 100755 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -30,8 +30,8 @@ class DashboardController extends Controller // Show the page if (Auth::user()->hasAccess('admin')) { - $recent_activity = Actionlog::orderBy('created_at', 'DESC') - ->with('accessorylog', 'consumablelog', 'licenselog', 'assetlog', 'adminlog', 'userlog', 'componentlog') + $recent_activity = Actionlog::latest() + ->with('item') ->take(20) ->get(); diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index e03d17bce1..cd50f90c55 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -334,11 +334,11 @@ class LicensesController extends Controller //Log the deletion of seats to the log $logaction = new Actionlog(); - $logaction->asset_id = $license->id; - $logaction->asset_type = 'software'; + $logaction->item_type = License::class; + $logaction->item_id = $license->id; $logaction->user_id = Auth::user()->id; - $logaction->note = abs($difference)." seats"; - $logaction->checkedout_to = null; + $logaction->note = '-'.abs($difference)." seats"; + $logaction->target_id = null; $log = $logaction->logaction('delete seats'); } else { @@ -359,10 +359,11 @@ class LicensesController extends Controller //Log the addition of license to the log. $logaction = new Actionlog(); - $logaction->asset_id = $license->id; - $logaction->asset_type = 'software'; + $logaction->item_type = License::class; + $logaction->item_id = $license->id; $logaction->user_id = Auth::user()->id; - $logaction->note = abs($difference)." seats"; + $logaction->note = '+'.abs($difference)." seats"; + $logaction->target_id = null; $log = $logaction->logaction('add seats'); } $license->seats = e(Input::get('seats')); @@ -543,14 +544,10 @@ class LicensesController extends Controller // Was the asset updated? if ($licenseseat->save()) { - $logaction = new Actionlog(); - - //$logaction->location_id = $assigned_to->location_id; - $logaction->asset_type = 'software'; - $logaction->user_id = Auth::user()->id; - $logaction->note = e(Input::get('note')); - $logaction->asset_id = $licenseseat->license_id; + $licenseseat->logCheckout(e(Input::get('note'))); + $data['license_id'] =$licenseseat->license_id; + $data['note'] = e(Input::get('note')); $license = License::find($licenseseat->license_id); $settings = Setting::getSettings(); @@ -558,11 +555,9 @@ class LicensesController extends Controller // Update the asset data if (e(Input::get('assigned_to')) == '') { - $logaction->checkedout_to = null; - $slack_msg = strtoupper($logaction->asset_type).' license <'.config('app.url').'/admin/licenses/'.$license->id.'/view'.'|'.$license->name.'> checked out to <'.config('app.url').'/hardware/'.$asset->id.'/view|'.$asset->showAssetName().'> by <'.config('app.url').'/admin/users/'.$user->id.'/view'.'|'.$user->fullName().'>.'; + $slack_msg = 'License <'.config('app.url').'/admin/licenses/'.$license->id.'/view'.'|'.$license->name.'> checked out to <'.config('app.url').'/hardware/'.$asset->id.'/view|'.$asset->showAssetName().'> by <'.config('app.url').'/admin/users/'.$user->id.'/view'.'|'.$user->fullName().'>.'; } else { - $logaction->checkedout_to = e(Input::get('assigned_to')); - $slack_msg = strtoupper($logaction->asset_type).' license <'.config('app.url').'/admin/licenses/'.$license->id.'/view'.'|'.$license->name.'> checked out to <'.config('app.url').'/admin/users/'.$user->id.'/view|'.$is_assigned_to->fullName().'> by <'.config('app.url').'/admin/users/'.$user->id.'/view'.'|'.$user->fullName().'>.'; + $slack_msg = 'License <'.config('app.url').'/admin/licenses/'.$license->id.'/view'.'|'.$license->name.'> checked out to <'.config('app.url').'/admin/users/'.$user->id.'/view|'.$is_assigned_to->fullName().'> by <'.config('app.url').'/admin/users/'.$user->id.'/view'.'|'.$user->fullName().'>.'; } @@ -588,7 +583,7 @@ class LicensesController extends Controller ], [ 'title' => 'Note:', - 'value' => e($logaction->note) + 'value' => e(Input::get('note')) ], @@ -602,9 +597,6 @@ class LicensesController extends Controller } - $log = $logaction->logaction('checkout'); - - // Redirect to the new asset page return redirect()->to("admin/licenses")->with('success', trans('admin/licenses/message.checkout.success')); } @@ -683,8 +675,6 @@ class LicensesController extends Controller return redirect()->back()->withInput()->withErrors($validator); } $return_to = $licenseseat->assigned_to; - $logaction = new Actionlog(); - $logaction->checkedout_to = $licenseseat->assigned_to; // Update the asset data $licenseseat->assigned_to = null; @@ -694,11 +684,7 @@ class LicensesController extends Controller // Was the asset updated? if ($licenseseat->save()) { - $logaction->asset_id = $licenseseat->license_id; - $logaction->location_id = null; - $logaction->asset_type = 'software'; - $logaction->note = e(Input::get('note')); - $logaction->user_id = $user->id; + $licenseseat->logCheckin(e(Input::get('note'))); $settings = Setting::getSettings(); @@ -719,11 +705,11 @@ class LicensesController extends Controller 'fields' => [ [ 'title' => 'Checked In:', - 'value' => strtoupper($logaction->asset_type).' <'.config('app.url').'/admin/licenses/'.$license->id.'/view'.'|'.$license->name.'> checked in by <'.config('app.url').'/admin/users/'.$user->id.'/view'.'|'.$user->fullName().'>.' + 'value' => 'License: <'.config('app.url').'/admin/licenses/'.$license->id.'/view'.'|'.$license->name.'> checked in by <'.config('app.url').'/admin/users/'.$user->id.'/view'.'|'.$user->fullName().'>.' ], [ 'title' => 'Note:', - 'value' => e($logaction->note) + 'value' => e(Input::get('note')) ], ] @@ -736,9 +722,6 @@ class LicensesController extends Controller } - $log = $logaction->logaction('checkin from'); - - if ($backto=='user') { return redirect()->to("admin/users/".$return_to.'/view')->with('success', trans('admin/licenses/message.checkin.success')); @@ -853,16 +836,8 @@ class LicensesController extends Controller $filename .= '-'.str_slug($file->getClientOriginalName()).'.'.$extension; $upload_success = $file->move($destinationPath, $filename); - //Log the deletion of seats to the log - $logaction = new Actionlog(); - $logaction->asset_id = $license->id; - $logaction->asset_type = 'software'; - $logaction->user_id = Auth::user()->id; - $logaction->note = e(Input::get('notes')); - $logaction->checkedout_to = null; - $logaction->created_at = date("Y-m-d h:i:s"); - $logaction->filename = $filename; - $log = $logaction->logaction('uploaded'); + //Log the upload to the log + $license->logUpload($filename, e(Input::get('notes'))); } else { return redirect()->back()->with('error', trans('admin/licenses/message.upload.invalidfiles')); } diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 6b8e05c34e..a10b7f07bc 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -330,12 +330,8 @@ class ReportsController extends Controller public function getActivityReport() { $log_actions = Actionlog::orderBy('created_at', 'DESC') - ->with('adminlog') - ->with('accessorylog') - ->with('assetlog') - ->with('licenselog') - ->with('userlog') - ->orderBy('created_at', 'DESC') + ->with('user') + ->with('item') ->get(); return View::make('reports/activity', compact('log_actions')); @@ -755,11 +751,11 @@ class ReportsController extends Controller foreach ($assetsForReport as $assetItem) { $row = [ ]; - $row[] = str_replace(',', '', e($assetItem->assetlog->model->category->name)); - $row[] = str_replace(',', '', e($assetItem->assetlog->model->name)); - $row[] = str_replace(',', '', e($assetItem->assetlog->showAssetName())); - $row[] = str_replace(',', '', e($assetItem->assetlog->asset_tag)); - $row[] = str_replace(',', '', e($assetItem->assetlog->assigneduser->fullName())); + $row[] = str_replace(',', '', e($assetItem->item->model->category->name)); + $row[] = str_replace(',', '', e($assetItem->item->model->name)); + $row[] = str_replace(',', '', e($assetItem->item->showAssetName())); + $row[] = str_replace(',', '', e($assetItem->item->asset_tag)); + $row[] = str_replace(',', '', e($assetItem->item->assigneduser->fullName())); $rows[] = implode($row, ','); } diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 6dcc42c8df..ff4fef3822 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -495,9 +495,10 @@ class UsersController extends Controller // Update the asset log $logaction = new Actionlog(); - $logaction->asset_id = $asset->id; - $logaction->checkedout_to = $asset->assigned_to; - $logaction->asset_type = 'hardware'; + $logaction->item_id = $asset->id; + $logaction->item_type = Asset::class; + $logaction->target_id = $asset->assigned_to; + $logaction->target_type = User::class; $logaction->user_id = Auth::user()->id; $logaction->note = 'Bulk checkin asset and delete user'; $logaction->logaction('checkin from'); @@ -514,9 +515,10 @@ class UsersController extends Controller $accessory_array[] = $accessory->accessory_id; // Update the asset log $logaction = new Actionlog(); - $logaction->accessory_id = $accessory->id; - $logaction->checkedout_to = $accessory->assigned_to; - $logaction->asset_type = 'accessory'; + $logaction->item_id = $accessory->id; + $logaction->item_type = Accessory::class; + $logaction->target_id = $accessory->assigned_to; + $logaction->target_type = User::class; $logaction->user_id = Auth::user()->id; $logaction->note = 'Bulk checkin accessory and delete user'; $logaction->logaction('checkin from'); @@ -528,9 +530,10 @@ class UsersController extends Controller $license_array[] = $license->id; // Update the asset log $logaction = new Actionlog(); - $logaction->asset_id = $license->id; - $logaction->checkedout_to = $license->assigned_to; - $logaction->asset_type = 'software'; + $logaction->item_id = $license->id; + $logaction->item_type = License::class; + $logaction->target_id = $license->assigned_to; + $logaction->target_type = User::class; $logaction->user_id = Auth::user()->id; $logaction->note = 'Bulk checkin license and delete user'; $logaction->logaction('checkin from'); @@ -598,7 +601,7 @@ class UsersController extends Controller $user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId); - $userlog = $user->userlog->load('assetlog', 'consumablelog', 'assetlog.model', 'licenselog', 'accessorylog', 'userlog', 'adminlog'); + $userlog = $user->userlog->load('item'); if (isset($user->id)) { @@ -1017,11 +1020,11 @@ class UsersController extends Controller //Log the deletion of seats to the log $logaction = new Actionlog(); - $logaction->asset_id = $user->id; - $logaction->asset_type = 'user'; + $logaction->item_id = $user->id; + $logaction->item_type = User::class; $logaction->user_id = Auth::user()->id; $logaction->note = e(Input::get('notes')); - $logaction->checkedout_to = null; + $logaction->target_id = null; $logaction->created_at = date("Y-m-d h:i:s"); $logaction->filename = $filename; $logaction->action_type = 'uploaded'; diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index fd3710b172..aec7794c4a 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -39,7 +39,7 @@ class ViewAssetsController extends Controller $user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find(Auth::user()->id); - $userlog = $user->userlog->load('assetlog', 'consumablelog', 'assetlog.model', 'licenselog', 'accessorylog', 'userlog', 'adminlog'); + $userlog = $user->userlog->load('item', 'item.model', 'user', 'target'); @@ -79,14 +79,15 @@ class ViewAssetsController extends Controller } else { $logaction = new Actionlog(); - $logaction->asset_id = $data['asset_id'] = $asset->id; - $logaction->asset_type = $data['asset_type'] = 'hardware'; + $logaction->item_id = $data['asset_id'] = $asset->id; + $logaction->item_type = Asset::class; $logaction->created_at = $data['requested_date'] = date("Y-m-d h:i:s"); - + $data['asset_type'] = 'hardware'; if ($user->location_id) { $logaction->location_id = $user->location_id; } - $logaction->user_id = $data['user_id'] = Auth::user()->id; + $logaction->target_id = $data['user_id'] = Auth::user()->id; + $logaction->target_type = User::class; $log = $logaction->logaction('requested'); $data['requested_by'] = $user->fullName(); @@ -119,7 +120,7 @@ class ViewAssetsController extends Controller 'fields' => [ [ 'title' => 'REQUESTED:', - 'value' => strtoupper($logaction->asset_type).' asset <'.config('app.url').'/hardware/'.$asset->id.'/view'.'|'.$asset->showAssetName().'> requested by <'.config('app.url').'/hardware/'.$asset->id.'/view'.'|'.Auth::user()->fullName().'>.' + 'value' => class_basename(strtoupper($logaction->item_type)).' asset <'.config('app.url').'/hardware/'.$asset->id.'/view'.'|'.$asset->showAssetName().'> requested by <'.config('app.url').'/hardware/'.$asset->id.'/view'.'|'.Auth::user()->fullName().'>.' ] ] @@ -143,7 +144,7 @@ class ViewAssetsController extends Controller public function getAcceptAsset($logID = null) { - if (!$findlog = DB::table('asset_logs')->where('id', '=', $logID)->first()) { + if (!$findlog = Actionlog::where('id', $logID)->first()) { echo 'no record'; //return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist')); } @@ -155,23 +156,7 @@ class ViewAssetsController extends Controller return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.incorrect_user_accepted')); } - // Asset - if (($findlog->asset_id!='') && ($findlog->asset_type=='hardware')) { - $item = Asset::find($findlog->asset_id); - - // software - } elseif (($findlog->asset_id!='') && ($findlog->asset_type=='software')) { - $item = License::find($findlog->asset_id); - // accessories - } elseif ($findlog->accessory_id!='') { - $item = Accessory::find($findlog->accessory_id); - // consumable - } elseif ($findlog->consumable_id!='') { - $item = Consumable::find($findlog->consumable_id); - // components - } elseif ($findlog->component_id!='') { - $item = Component::find($findlog->component_id); - } + $item = $findlog->item; // Check if the asset exists if (is_null($item)) { @@ -189,7 +174,7 @@ class ViewAssetsController extends Controller { // Check if the asset exists - if (is_null($findlog = DB::table('asset_logs')->where('id', '=', $logID)->first())) { + if (is_null($findlog = Actionlog::where('id', $logID)->first())) { // Redirect to the asset management page return redirect()->to('account/view-assets')->with('error', trans('admin/hardware/message.does_not_exist')); } @@ -221,56 +206,24 @@ class ViewAssetsController extends Controller $accepted="rejected"; $return_msg = trans('admin/users/message.declined'); } - + $logaction->item_id = $findlog->item_id; + $logaction->item_type = $findlog->item_type; // Asset - if (($findlog->asset_id!='') && ($findlog->asset_type=='hardware')) { - $logaction->asset_id = $findlog->asset_id; - $logaction->accessory_id = null; - $logaction->asset_type = 'hardware'; - + if (($findlog->item_id!='') && ($findlog->item_type==Asset::class)) { if (Input::get('asset_acceptance')!='accepted') { DB::table('assets') - ->where('id', $findlog->asset_id) + ->where('id', $findlog->item_id) ->update(array('assigned_to' => null)); } - - - // software - } elseif (($findlog->asset_id!='') && ($findlog->asset_type=='software')) { - $logaction->asset_id = $findlog->asset_id; - $logaction->accessory_id = null; - $logaction->component_id = null; - $logaction->asset_type = 'software'; - - // accessories - } elseif ($findlog->accessory_id!='') { - $logaction->asset_id = null; - $logaction->component_id = null; - $logaction->accessory_id = $findlog->accessory_id; - $logaction->asset_type = 'accessory'; - // accessories - } elseif ($findlog->consumable_id!='') { - $logaction->asset_id = null; - $logaction->accessory_id = null; - $logaction->component_id = null; - $logaction->consumable_id = $findlog->consumable_id; - $logaction->asset_type = 'consumable'; - } elseif ($findlog->component_id!='') { - $logaction->asset_id = null; - $logaction->accessory_id = null; - $logaction->consumable_id = null; - $logaction->component_id = $findlog->component_id; - $logaction->asset_type = 'component'; } - - $logaction->checkedout_to = $findlog->checkedout_to; + $logaction->target_id = $findlog->target_id; $logaction->note = e(Input::get('note')); $logaction->user_id = $user->id; $logaction->accepted_at = date("Y-m-d h:i:s"); $log = $logaction->logaction($logaction_msg); - $update_checkout = DB::table('asset_logs') + $update_checkout = DB::table('action_logs') ->where('id', $findlog->id) ->update(array('accepted_id' => $logaction->id)); diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 8bd139b499..4325e8cca4 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -1,6 +1,7 @@ hasMany('\App\Models\Actionlog', 'accessory_id')->where('asset_type', '=', 'accessory')->orderBy('created_at', 'desc')->withTrashed(); + return $this->hasMany('\App\Models\Actionlog', 'item_id')->where('item_type', Accessory::class)->orderBy('created_at', 'desc')->withTrashed(); } diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index 1ea4291fdd..b824883b5b 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -19,77 +19,51 @@ class Actionlog extends Model implements ICompanyableChild protected $dates = [ 'deleted_at' ]; - protected $table = 'asset_logs'; + protected $table = 'action_logs'; public $timestamps = true; - protected $fillable = [ 'created_at', 'asset_type','user_id','asset_id','action_type','note','checkedout_to' ]; + protected $fillable = [ 'created_at', 'item_type','user_id','item_id','action_type','note','target_id', 'target_type' ]; public function getCompanyableParents() { return [ 'accessorylog', 'assetlog', 'licenselog', 'consumablelog' ]; } - public function assetlog() + // Eloquent Relationships below + public function item() { + return $this->morphTo('item')->withTrashed(); + } - return $this->belongsTo('\App\Models\Asset', 'asset_id') - ->withTrashed(); + public function itemType() + { + // dd($this); + return camel_case(class_basename($this->item_type)); } public function uploads() { - return $this->belongsTo('\App\Models\Asset', 'asset_id') + return $this->morphTo('item') ->where('action_type', '=', 'uploaded') ->withTrashed(); } - public function licenselog() - { - - return $this->belongsTo('\App\Models\License', 'asset_id') - ->withTrashed(); - } - - public function componentlog() - { - - return $this->belongsTo('\App\Models\Component', 'component_id') - ->withTrashed(); - } - - public function accessorylog() - { - - return $this->belongsTo('\App\Models\Accessory', 'accessory_id') - ->withTrashed(); - } - - public function consumablelog() - { - - return $this->belongsTo('\App\Models\Consumable', 'consumable_id') - ->withTrashed(); - } - - public function adminlog() - { - - return $this->belongsTo('\App\Models\User', 'user_id') - ->withTrashed(); - } - public function userlog() { - return $this->belongsTo('\App\Models\User', 'checkedout_to') + // return $this->belongsTo(User::class, 'target_id') + return $this->target(); + } + + public function user() + { + return $this->belongsTo(User::class, 'user_id') ->withTrashed(); } - public function userasassetlog() + public function target() { - - return $this->belongsTo('\App\Models\User', 'asset_id') - ->withTrashed(); + return $this->morphTo('target'); } public function childlogs() @@ -141,44 +115,10 @@ class Actionlog extends Model implements ICompanyableChild public function getListingOfActionLogsChronologicalOrder() { - return DB::table('asset_logs') - ->select('*') + return $this->all() ->where('action_type', '!=', 'uploaded') - ->orderBy('asset_id', 'asc') + ->orderBy('item_id', 'asc') ->orderBy('created_at', 'asc') ->get(); } - - /** - * getLatestCheckoutActionForAssets - * - * @return mixed - * @author Vincent Sposato - * @version v1.0 - */ - public function getLatestCheckoutActionForAssets() - { - - return DB::table('asset_logs') - ->select(DB::raw('asset_id, MAX(created_at) as last_created')) - ->where('action_type', '=', 'checkout') - ->groupBy('asset_id') - ->get(); - } - - /** - * scopeCheckoutWithoutAcceptance - * - * @param $query - * - * @return mixed - * @author Vincent Sposato - * @version v1.0 - */ - public function scopeCheckoutWithoutAcceptance($query) - { - - return $query->where('action_type', '=', 'checkout') - ->where('accepted_id', '=', null); - } } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index c6b1bb2916..8c857b507c 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1,20 +1,21 @@ asset_id = $this->id; - $logaction->checkedout_to = $this->assigned_to; - $logaction->asset_type = 'hardware'; + $logaction->item_type = Asset::class; + $logaction->item_id = $this->id; + $logaction->target_type = User::class; + $logaction->target_id = $this->assigned_to; $logaction->note = $note; + $logaction->user_id = $admin->id; if ($checkout_at!='') { $logaction->created_at = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s', strtotime($checkout_at))); } else { @@ -225,15 +229,10 @@ class Asset extends Depreciable } } else { // Update the asset data to null, since it's being checked in - $logaction->checkedout_to = $asset->assigned_to; - $logaction->checkedout_to = ''; - $logaction->asset_id = $asset->id; + $logaction->target_id = ''; $logaction->location_id = null; - $logaction->asset_type = 'hardware'; - $logaction->note = $note; - $logaction->user_id = $admin->id; } - $logaction->adminlog()->associate($admin); + $logaction->user()->associate($admin); $log = $logaction->logaction($action); return $logaction; @@ -270,8 +269,8 @@ class Asset extends Depreciable public function uploads() { - return $this->hasMany('\App\Models\Actionlog', 'asset_id') - ->where('asset_type', '=', 'hardware') + return $this->hasMany('\App\Models\Actionlog', 'item_id') + ->where('item_type', '=', Asset::class) ->where('action_type', '=', 'uploaded') ->whereNotNull('filename') ->orderBy('created_at', 'desc'); @@ -308,8 +307,8 @@ class Asset extends Depreciable */ public function assetlog() { - return $this->hasMany('\App\Models\Actionlog', 'asset_id') - ->where('asset_type', '=', 'hardware') + return $this->hasMany('\App\Models\Actionlog', 'item_id') + ->where('item_type', '=', Asset::class) ->orderBy('created_at', 'desc') ->withTrashed(); } diff --git a/app/Models/Component.php b/app/Models/Component.php index 2e2b97545f..a13b164181 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -1,12 +1,13 @@ hasMany('\App\Models\Actionlog', 'component_id')->where('asset_type', '=', 'component')->orderBy('created_at', 'desc')->withTrashed(); + return $this->hasMany('\App\Models\Actionlog', 'item_id')->where('item_type', Component::class)->orderBy('created_at', 'desc')->withTrashed(); } diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index a8ec373eef..a94f8f4162 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -1,20 +1,22 @@ hasMany('\App\Models\Actionlog', 'consumable_id')->where('asset_type', '=', 'consumable')->orderBy('created_at', 'desc')->withTrashed(); + return $this->hasMany('\App\Models\Actionlog', 'item_id')->where('item_type', Consumable::class)->orderBy('created_at', 'desc')->withTrashed(); } diff --git a/app/Models/License.php b/app/Models/License.php index 4444ac6497..3e42d38d72 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -2,15 +2,16 @@ namespace App\Models; use App\Models\Company; +use App\Models\Loggable; use DB; -use Watson\Validating\ValidatingTrait; - use Illuminate\Database\Eloquent\SoftDeletes; +use Watson\Validating\ValidatingTrait; class License extends Depreciable { use SoftDeletes; use CompanyableTrait; + use Loggable; protected $injectUniqueIdentifier = true; use ValidatingTrait; @@ -54,8 +55,8 @@ class License extends Depreciable */ public function assetlog() { - return $this->hasMany('\App\Models\Actionlog', 'asset_id') - ->where('asset_type', '=', 'software') + return $this->hasMany('\App\Models\Actionlog', 'item_id') + ->where('item_type', '=', License::class) ->orderBy('created_at', 'desc'); } @@ -64,8 +65,8 @@ class License extends Depreciable */ public function uploads() { - return $this->hasMany('\App\Models\Actionlog', 'asset_id') - ->where('asset_type', '=', 'software') + return $this->hasMany('\App\Models\Actionlog', 'item_id') + ->where('item_type', '=', License::class) ->where('action_type', '=', 'uploaded') ->whereNotNull('filename') ->orderBy('created_at', 'desc'); diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.php index 54c40a43cf..b1c9a5c3a7 100755 --- a/app/Models/LicenseSeat.php +++ b/app/Models/LicenseSeat.php @@ -1,6 +1,7 @@ morphMany(Actionlog::class, 'item'); + } + + public function logCheckout($note, $target = null /*target is overridable for components*/) + { + $log = new Actionlog; + // We need to special case licenses because of license_seat vs license. So much for clean polymorphism :) + if (static::class == LicenseSeat::class) { + $log->item_type = License::class; + $log->item_id = $this->license_id; + } else { + $log->item_type = static::class; + $log->item_id = $this->id; + } + $log->user_id = Auth::user()->id; + if (!is_null($this->asset_id) || isset($target)) { + $log->target_type = Asset::class; + $log->target_id = $this->asset_id; + } else if (!is_null($this->assigned_to)) { + $log->target_type = User::class; + $log->target_id = $this->assigned_to; + } + $item =call_user_func(array($log->target_type, 'find'), $log->target_id); + $log->location_id = $item->location_id; + $log->note = $note; + $log->logaction('checkout'); + + return $log; + } + + public function logCheckin($note) + { + $log = new Actionlog; + if (static::class == LicenseSeat::class) { + $log->item_type = License::class; + $log->item_id = $this->license_id; + } else { + $log->item_type = static::class; + $log->item_id = $this->id; + } + $log->location_id = null; + $log->note = $note; + $log->user_id = Auth::user()->id; + $log->logaction('checkin from'); + + return $log; + } + + public function logUpload($filename, $note) + { + $log = new Actionlog; + if (static::class == LicenseSeat::class) { + $log->item_type = License::class; + $log->item_id = $this->license_id; + } else { + $log->item_type = static::class; + $log->item_id = $this->id; + } + $log->user_id = Auth::user()->id; + $log->note = $note; + $log->target_id = null; + $log->created_at = date("Y-m-d h:i:s"); + $log->filename = $filename; + $log->logaction('uploaded'); + + return $log; + } + +} diff --git a/app/Models/User.php b/app/Models/User.php index eae06ac50b..67a86782be 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -202,7 +202,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function userlog() { - return $this->hasMany('\App\Models\Actionlog', 'checkedout_to')->orderBy('created_at', 'DESC')->withTrashed(); + return $this->hasMany('\App\Models\Actionlog', 'target_id')->orderBy('created_at', 'DESC')->withTrashed(); } /** @@ -255,8 +255,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function uploads() { - return $this->hasMany('\App\Models\Actionlog', 'asset_id') - ->where('asset_type', '=', 'user') + return $this->hasMany('\App\Models\Actionlog', 'item_id') + ->where('item_type', User::class) ->where('action_type', '=', 'uploaded') ->whereNotNull('filename') ->orderBy('created_at', 'desc'); diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index f0432c7c8f..82652aca86 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -268,10 +268,11 @@ $factory->defineAs(App\Models\Actionlog::class, 'asset-checkout', function (Fake return [ 'user_id' => 1, 'action_type' => 'checkout', - 'asset_id' => $faker->numberBetween(1, 10), - 'checkedout_to' => 1, + 'item_id' => $faker->numberBetween(1, 10), + 'target_id' => 1, + 'target_type' => 'App\\Models\\User', 'created_at' => $faker->dateTime(), - 'asset_type' => 'hardware', + 'item_type' => 'App\\Models\\Asset', 'note' => $faker->sentence, 'user_id' => '1', ]; diff --git a/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php b/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php index f14f001d44..4a0e45bbef 100644 --- a/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php +++ b/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php @@ -64,39 +64,39 @@ public function up() { - if (!Schema::hasColumn('asset_logs', 'thread_id')) { + // if (!Schema::hasColumn('asset_logs', 'thread_id')) { - Schema::table( 'asset_logs', function ( Blueprint $table ) { + // Schema::table( 'asset_logs', function ( Blueprint $table ) { - $table->integer( 'thread_id' ) - ->nullable() - ->default( null ); - $table->index( 'thread_id' ); - } ); - } + // $table->integer( 'thread_id' ) + // ->nullable() + // ->default( null ); + // $table->index( 'thread_id' ); + // } ); + // } - $this->actionlog = new App\Models\Actionlog(); - $this->assetLogs = $this->actionlog->getListingOfActionLogsChronologicalOrder(); + // $this->actionlog = new App\Models\Actionlog(); + // $this->assetLogs = $this->actionlog->getListingOfActionLogsChronologicalOrder(); - foreach ($this->assetLogs as $assetLog) { + // foreach ($this->assetLogs as $assetLog) { - if ($this->hasAssetChanged( $assetLog )) { - $this->resetCurrentAssetInformation( $assetLog ); - } + // if ($this->hasAssetChanged( $assetLog )) { + // $this->resetCurrentAssetInformation( $assetLog ); + // } - if ($this->hasBegunNewChain( $assetLog )) { - $this->startOfCurrentThread = false; - continue; - } + // if ($this->hasBegunNewChain( $assetLog )) { + // $this->startOfCurrentThread = false; + // continue; + // } - $this->updateAssetLogWithThreadInformation( $assetLog ); + // $this->updateAssetLogWithThreadInformation( $assetLog ); - if ($this->hasReachedEndOfChain( $assetLog ) - ) { - $this->clearCurrentAssetInformation(); - } + // if ($this->hasReachedEndOfChain( $assetLog ) + // ) { + // $this->clearCurrentAssetInformation(); + // } - } + // } } diff --git a/database/migrations/2016_09_04_180400_create_actionlog_table.php b/database/migrations/2016_09_04_180400_create_actionlog_table.php new file mode 100644 index 0000000000..7d99f07b24 --- /dev/null +++ b/database/migrations/2016_09_04_180400_create_actionlog_table.php @@ -0,0 +1,47 @@ +increments('id'); + $table->integer('user_id')->nullable(); + $table->string('action_type'); + $table->integer('target_id')->nullable(); // Was checkedout_to + $table->integer('target_type')->nullable(); // For polymorphic thingies + $table->integer('location_id')->nullable(); + $table->text('note')->nullable(); + $table->text('filename')->nullable(); + $table->string('item_type'); + $table->integer('item_id'); // Replaces asset_id, accessory_id, etc. + $table->date('expected_checkin')->nullable()->default(null); + $table->integer('accepted_id')->nullable(); + $table->timestamps(); + $table->softDeletes(); + + $table->integer('thread_id') + ->nullable() + ->default(null); + $table->index('thread_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('action_logs'); + } +} diff --git a/database/migrations/2016_09_04_182149_migrate_asset_log_to_action_log.php b/database/migrations/2016_09_04_182149_migrate_asset_log_to_action_log.php new file mode 100644 index 0000000000..05d3a26e8d --- /dev/null +++ b/database/migrations/2016_09_04_182149_migrate_asset_log_to_action_log.php @@ -0,0 +1,78 @@ +get(); + + foreach ($logs as $log) { + // protected $fillable = [ 'created_at', 'asset_type','user_id','asset_id','action_type','note','checkedout_to' ]; + $a = new Actionlog(compact($log)); + // var_dump($log); + $a->user_id = $log->user_id; + + if (!is_null($log->asset_id)) { + $a->item_id = $log->asset_id; + if ($log->asset_type == "hardware") { + $a->item_type = 'App\\Models\\Asset'; + } else { + $a->item_type = 'App\\Models\\License'; + } + } + if (!is_null($log->accessory_id)) { + $a->item_id = $log->accessory_id; + $a->item_type = 'App\\Models\\Accessory'; + } else if (!is_null($log->consumable_id)) { + $a->item_id = $log->consumable_id; + $a->item_type = 'App\\Models\\Consumable'; + } else if (!is_null($log->component_id)) { + $a->item_id = $log->component_id; + $a->item_type = 'App\\Models\\Component'; + } + $a->action_type = $log->action_type; + // $a->checkout_to = $log->checkout_to; + if(!is_null($log->checkedout_to)) { + $a->target_id = $log->checkedout_to; + $a->target_type = User::class; + } + if(!is_null($log->accepted_id)) { + $a->target_id = $log->accepted_id; + $a->target_type = User::class; + } + $a->location_id = $log->location_id; + $a->created_at = $log->created_at; + $a->updated_at = $log->updated_at; + $a->deleted_at = $log->deleted_at; + $a->note = $log->note; + $a->expected_checkin = $log->expected_checkin; + $a->thread_id = $log->thread_id; + $a->accepted_id = $log->accepted_id; + + $a->save(); + + } + // dd($logs); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index f294de0961..43736277f3 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -247,65 +247,45 @@ View Assets for {{ $user->fullName() }} @foreach ($user->userlog as $log) - @if (($log->assetlog) && ($log->asset_type=="hardware")) + @if ($log->itemType()=="asset") - @elseif (($log->accessorylog) && ($log->asset_type=="accessory")) + @elseif ($log->itemType()=="accessory") - @elseif (($log->consumablelog) && ($log->asset_type=="consumable")) + @elseif ($log->itemType()=="consumable") - @elseif (($log->licenselog) && ($log->asset_type=="software")) + @elseif ($log->itemType()=="license") @else - + @endif {{ $log->action_type }} - @if (($log->assetlog) && ($log->asset_type=="hardware")) + @if ($log->itemType()=="asset") + @if ($log->item->deleted_at=='') - @if ($log->assetlog->deleted_at=='') - - {{ $log->assetlog->showAssetName() }} + {{ $log->item->showAssetName() }} @else - {{ $log->assetlog->showAssetName() }} (deleted) + {{ $log->item->showAssetName() }} (deleted) @endif - @elseif (($log->licenselog) && ($log->asset_type=="software")) - - @if ($log->licenselog->deleted_at=='') - - {{ $log->licenselog->name }} - - @else - {{ $log->licenselog->name }} (deleted) - @endif - - @elseif (($log->consumablelog) && ($log->asset_type=="consumable")) - - @if ($log->consumablelog->deleted_at=='') - {{ $log->consumablelog->name }} + @elseif (!is_null($log->itemType())) + @if ($log->item->deleted_at=='') + {{ $log->item->name }} @else - {{ $log->consumablelog->name }} (deleted) + {{ $log->item->name }} (deleted) @endif - - @elseif (($log->accessorylog) && ($log->asset_type=="accessory")) - @if ($log->accessorylog->deleted_at=='') - {{ $log->accessorylog->name }} - @else - {{ $log->accessorylog->name }} (deleted) - @endif - @else {{ trans('general.bad_data') }} @endif - @if ($log->adminlog) - {{ $log->adminlog->fullName() }} + @if ($log->user) + {{ $log->user->fullName() }} @endif {{ $log->created_at }} diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index a2edef1c58..4571d68cb3 100755 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -111,15 +111,15 @@ @foreach ($recent_activity as $activity) - @if ($activity->asset_type=="hardware") + @if ($activity->itemType()=="asset") - @elseif ($activity->asset_type=="accessory") + @elseif ($activity->itemType()=="accessory") - @elseif ($activity->asset_type=="consumable") + @elseif ($activity->itemType()=="consumable") - @elseif ($activity->asset_type=="license") + @elseif ($activity->itemType()=="license") - @elseif ($activity->asset_type=="component") + @elseif ($activity->itemType()=="component") @else @@ -128,8 +128,8 @@ {{ date("M d, Y g:iA", strtotime($activity->created_at)) }} @if ($activity->action_type!='requested') - @if ($activity->adminlog) - {{ $activity->adminlog->fullName() }} + @if ($activity->user) + {{ $activity->user->fullName() }} @else Deleted Admin @endif @@ -140,34 +140,23 @@ {{ strtolower(trans('general.'.str_replace(' ','_',$activity->action_type))) }} - @if (($activity->assetlog) && ($activity->asset_type=="hardware")) - {{ $activity->assetlog->asset_tag }} - {{ $activity->assetlog->showAssetName() }} - @elseif (($activity->licenselog) && ($activity->asset_type=="software")) - {{ $activity->licenselog->name }} - @elseif (($activity->consumablelog) && ($activity->asset_type=="consumable")) - {{ $activity->consumablelog->name }} - @elseif (($activity->accessorylog) && ($activity->asset_type=="accessory")) - {{ $activity->accessorylog->name }} - @elseif (($activity->componentlog) && ($activity->asset_type=="component")) - {{ $activity->componentlog->name }} - @elseif (($activity->assetlog) && ($activity->action_type=="uploaded") && ($activity->asset_type=="hardware")) - {{ $activity->assetlog->showAssetName() }} - + @if (($activity->item) && ($activity->itemType()=="asset")) + {{ $activity->item->asset_tag }} - {{ $activity->item->showAssetName() }} + @elseif ($activity->item) + {{ $activity->item->name }} @endif - @if (($activity->userasassetlog) && ($activity->action_type=="uploaded") && ($activity->asset_type=="user")) - {{ $activity->userasassetlog->fullName() }} - @elseif (($activity->componentlog) && ($activity->asset_type=="component")) - {{ $activity->assetlog->showAssetName() }} - @elseif($activity->action_type=='requested') - @if ($activity->adminlog) - {{ $activity->adminlog->fullName() }} - @endif - @elseif ($activity->userlog) - {{ $activity->userlog->fullName() }} + @if (($activity->userasassetlog) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) + {{ $activity->userasassetlog->fullName() }} + @elseif (($activity->item) && ($activity->target instanceof \App\Models\Asset)) + {{ $activity->target->showAssetName() }} + @elseif (($activity->item) && ($activity->target instanceof \App\Models\User)) + {{ $activity->target->fullName() }} + @elseif ($activity->action_type=='requested') + {{ $activity->user->fullName() }} @endif diff --git a/resources/views/hardware/qr-view.blade.php b/resources/views/hardware/qr-view.blade.php index b0dbca9e69..b234e7a1cb 100644 --- a/resources/views/hardware/qr-view.blade.php +++ b/resources/views/hardware/qr-view.blade.php @@ -273,19 +273,19 @@ {{ $log->created_at }} @if (isset($log->user_id)) - {{ $log->adminlog->fullName() }} + {{ $log->user->fullName() }} @endif {{ $log->action_type }} - @if ((isset($log->checkedout_to)) && ($log->checkedout_to!=0) && ($log->checkedout_to!='')) + @if ((isset($log->target_id)) && ($log->target_id!=0) && ($log->target_id!='')) - @if ($log->userlog->deleted_at=='') - - {{ $log->userlog->fullName() }} + @if ($log->target->deleted_at=='') + + {{ $log->user->fullName() }} @else - {{ $log->userlog->fullName() }} + {{ $log->user->fullName() }} @endif @endif diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 676061b8ed..4c1b7c09b1 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -513,26 +513,42 @@ {{ $log->created_at }} - @if (isset($log->adminlog)) - {{ $log->adminlog->fullName() }} - @else - Deleted Admin + @if ($log->action_type != 'requested') + @if (isset($log->user)) + {{ $log->user->fullName() }} + @else + Deleted Admin + @endif @endif {{ $log->action_type }} - @if ((isset($log->checkedout_to)) && ($log->checkedout_to!=0) && ($log->checkedout_to!='')) - @if ($log->userlog) + @if ($log->action_type=='uploaded') - @if ($log->userlog->deleted_at=='') - - {{ $log->userlog->fullName() }} + {{ $log->filename }} + @elseif ((isset($log->target_id)) && ($log->target_id!=0) && ($log->target_id!='')) + + + @if ($log->target instanceof \App\Models\User) + + @if ($log->target->deleted_at=='') + + {{ $log->target->fullName() }} @else - {{ $log->userlog->fullName() }} + {{ $log->target->fullName() }} @endif + @elseif($log->target instanceof \App\Models\Asset) + @if ($log->target->deleted_at=='') + + {{ $log->target->showAssetName() }} + + + @else + {{ $log->target->showAssetName() }} + @endif @else Deleted User @endif diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php index 42e2cc70a5..a656ef07b9 100755 --- a/resources/views/licenses/view.blade.php +++ b/resources/views/licenses/view.blade.php @@ -370,14 +370,14 @@ {{ $log->created_at }} @if (isset($log->user_id)) - {{ $log->adminlog->fullName() }} + {{ $log->user->fullName() }} @endif {{ $log->action_type }} - @if (($log->userlog) && ($log->userlog->id!='0')) - + @if (($log->target) && ($log->target->id!='0')) + {{ $log->userlog->fullName() }} diff --git a/resources/views/reports/activity.blade.php b/resources/views/reports/activity.blade.php index 73b546d1dc..c0f9e6e9ac 100644 --- a/resources/views/reports/activity.blade.php +++ b/resources/views/reports/activity.blade.php @@ -40,36 +40,36 @@ @foreach ($log_actions as $log_action) - {{ $log_action->adminlog->fullName() }} + + @if($log_action->user) + {{ $log_action->user->fullName() }} + @endif + {{ $log_action->action_type }} - @if ($log_action->asset_type=="hardware") - Asset - @elseif ($log_action->asset_type=="software") - License - @elseif ($log_action->asset_type=="accessory") - Accessory - @elseif ($log_action->asset_type=="consumable") - Consumable - @endif + {{ title_case($log_action->itemType()) }} - @if (($log_action->assetlog) && ($log_action->asset_type=="hardware")) - {{ $log_action->assetlog->showAssetName() }} - @elseif (($log_action->licenselog) && ($log_action->asset_type=="software")) - {{ $log_action->licenselog->name }} - @elseif (($log_action->consumablelog) && ($log_action->asset_type=="consumable")) - {{ $log_action->consumablelog->name }} - @elseif (($log_action->accessorylog) && ($log_action->asset_type=="accessory")) - {{ $log_action->accessorylog->name }} - @else - {{ trans('general.bad_data') }} - @endif + + @if ($item = $log_action->item) + @if ($log_action->itemType()=="asset") + {{ $item->showAssetName() }} + @else + {{ $item->name }} + @endif + @else + {{ trans('general.bad_data') }} + @endif - @if ($log_action->userlog) - {{ $log_action->userlog->fullName() }} + @if ($log_action->target) + @if ($log_action->target instanceof \App\Models\User) + {{ $log_action->target->fullName() }} + @elseif ($log_action->target instanceof \App\Models\Asset) + {{ $log_action->target->showAssetName() }} + @endif + @endif diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 88d5c635ef..b7ec6697ca 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -385,13 +385,13 @@ @foreach ($userlog as $log) - @if (($log->assetlog) && ($log->asset_type=="hardware")) + @if ($log->itemType()=="asset") - @elseif (($log->accessorylog) && ($log->asset_type=="accessory")) + @elseif ($log->itemType()=="accessory") - @elseif (($log->consumablelog) && ($log->asset_type=="consumable")) + @elseif ($log->itemType()=="consumable") - @elseif (($log->licenselog) && ($log->asset_type=="software")) + @elseif ($log->itemType()=="license") @else @@ -402,58 +402,23 @@ {{ $log->action_type }} - @if (($log->assetlog) && ($log->asset_type=="hardware")) - - @if ($log->assetlog->deleted_at=='') - - {{ $log->assetlog->showAssetName() }} - - @else - {{ $log->assetlog->showAssetName() }} (deleted) - @endif - - @elseif (($log->licenselog) && ($log->asset_type=="software")) - - @if ($log->licenselog->deleted_at=='') - - {{ $log->licenselog->name }} - - @else - {{ $log->licenselog->name }} (deleted) - @endif - - @elseif (($log->consumablelog) && ($log->asset_type=="consumable")) - - @if ($log->consumablelog->deleted_at=='') - {{ $log->consumablelog->name }} - @else - {{ $log->consumablelog->name }} (deleted) - @endif - - @elseif (($log->accessorylog) && ($log->asset_type=="accessory")) - @if ($log->accessorylog->deleted_at=='') - {{ $log->accessorylog->name }} - @else - {{ $log->accessorylog->name }} (deleted) - @endif - - @else - {{ trans('general.bad_data') }} - @endif + @if (($log->item) && ($log->itemType()=="asset")) + {{ $log->item->asset_tag }} - {{ $log->item->showAssetName() }} + @elseif ($log->item) + {{ $log->item->name }} - @if ($log->adminlog) - - @if ($log->adminlog->deleted_at=='') - - {{ $log->adminlog->fullName() }} - + + @if ($log->action_type != 'requested') + @if (isset($log->user)) + {{ $log->user->fullName() }} @else - {{ $log->adminlog->fullName() }} + Deleted Admin @endif - @else - Deleted User - @endif + @endif @endforeach