From 7ca7877740718e75a9c2a04dd93d18d8acbf82f9 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Wed, 28 Sep 2016 22:57:19 -0700 Subject: [PATCH] Fix mismerged code. (#2705) --- app/Http/Controllers/ReportsController.php | 119 ++++++++++++++++++--- app/Providers/AuthServiceProvider.php | 6 ++ resources/views/models/edit.blade.php | 9 ++ resources/views/reports/custom.blade.php | 7 ++ 4 files changed, 128 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index dcc93e0341..0e16bfdc79 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -33,7 +33,7 @@ class ReportsController extends Controller { /** - * Returns a view that displaysthe accessories report. + * Returns a view that displays the accessories report. * * @author [A. Gianotto] [] * @since [v1.0] @@ -292,11 +292,7 @@ class ReportsController extends Controller public function getActivityReport() { $log_actions = Actionlog::orderBy('created_at', 'DESC') - ->with('adminlog') - ->with('accessorylog') - ->with('assetlog') - ->with('licenselog') - ->with('userlog') + ->with('item') ->orderBy('created_at', 'DESC') ->get(); @@ -304,16 +300,111 @@ class ReportsController extends Controller } /** - * Displays license report - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @return View - */ + * Returns Activity Report JSON. + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @return View + */ + public function getActivityReportDataTable() + { + $activitylogs = Actionlog::orderBy('created_at', 'DESC'); + + if (Input::has('search')) { + $activity = $activity->TextSearch(e(Input::get('search'))); + } + + if (Input::has('offset')) { + $offset = e(Input::get('offset')); + } else { + $offset = 0; + } + + if (Input::has('limit')) { + $limit = e(Input::get('limit')); + } else { + $limit = 50; + } + + + $allowed_columns = ['created_at']; + $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; + $sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at'; + + + $activityCount = $activitylogs->count(); + $activitylogs = $activitylogs->skip($offset)->take($limit)->get(); + + $rows = array(); + + foreach ($activitylogs as $activity) { + + if ($activity->itemType() == "asset") { + $activity_icons = ''; + } elseif ($activity->itemType() == "accessory") { + $activity_icons = ''; + } elseif ($activity->itemType()=="consumable") { + $activity_icons = ''; + } elseif ($activity->itemType()=="license"){ + $activity_icons = ''; + } elseif ($activity->itemType()=="component") { + $activity_icons = ''; + } else { + $activity_icons = ''; + } + + if (($activity->item) && ($activity->itemType()=="asset")) { + $actvity_item = ''.e($activity->item->asset_tag).' - '. e($activity->item->showAssetName()).''; + $item_type = 'asset'; + } elseif ($activity->item) { + $actvity_item = ''.e($activity->item->name).''; + $item_type = $activity->itemType(); + } + + + if (($activity->userasassetlog) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) { + $activity_target = ''.$activity->userasassetlog->fullName().''; + } elseif (($activity->item) && ($activity->target instanceof \App\Models\Asset)) { + $activity_target = ''.$activity->target->showAssetName().''; + } elseif (($activity->item) && ($activity->target instanceof \App\Models\User)) { + $activity_target = ''.$activity->target->fullName().''; + } elseif ($activity->action_type=='requested') { + $activity_target = ''.$activity->user->fullName().''; + } else { + $activity_target = $activity->target; + } + + + $rows[] = array( + 'icon' => $activity_icons, + 'created_at' => date("M d, Y g:iA", strtotime($activity->created_at)), + 'action_type' => strtolower(trans('general.'.str_replace(' ','_',$activity->action_type))), + 'admin' => $activity->user ? (string) link_to('/admin/users/'.$activity->user_id.'/view', $activity->user->fullName()) : 'Deleted Admin', + 'target' => $activity_target, + 'item' => $actvity_item, + 'item_type' => $item_type, + 'note' => e($activity->note), + + ); + } + + $data = array('total'=>$activityCount, 'rows'=>$rows); + + return $data; + + } + + /** + * Displays license report + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @return View + */ public function getLicenseReport() { - $licenses = License::orderBy('created_at', 'DESC') + $licenses = License::with('depreciation')->orderBy('created_at', 'DESC') ->with('company') ->get(); @@ -340,6 +431,7 @@ class ReportsController extends Controller trans('admin/licenses/form.remaining_seats'), trans('admin/licenses/form.expiration'), trans('admin/licenses/form.date'), + trans('admin/licenses/form.depreciation'), trans('admin/licenses/form.cost') ]; @@ -355,6 +447,7 @@ class ReportsController extends Controller $row[] = $license->remaincount(); $row[] = $license->expiration_date; $row[] = $license->purchase_date; + $row[] = ($license->depreciation!='') ? '' : e($license->depreciation->name); $row[] = '"' . Helper::formatCurrencyOutput($license->purchase_cost) . '"'; $rows[] = implode($row, ','); diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 83a1900380..87ea4f74eb 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -261,6 +261,12 @@ class AuthServiceProvider extends ServiceProvider } }); + $gate->define('components.checkout', function ($user) { + if (($user->hasAccess('components.checkout')) || ($user->hasAccess('admin'))) { + return true; + } + }); + // Checks for some level of management $gate->define('components.manage', function ($user) { if (($user->hasAccess('components.edit')) || ($user->hasAccess('components.delete')) || ($user->hasAccess('components.checkout')) || ($user->hasAccess('admin'))) { diff --git a/resources/views/models/edit.blade.php b/resources/views/models/edit.blade.php index 4590fc7bd0..a9605871b5 100755 --- a/resources/views/models/edit.blade.php +++ b/resources/views/models/edit.blade.php @@ -129,6 +129,15 @@ + +
+
+ +
+
+ @if ($model->image)
diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php index 535ddc85b8..38d47ee60f 100644 --- a/resources/views/reports/custom.blade.php +++ b/resources/views/reports/custom.blade.php @@ -48,6 +48,13 @@
+
+ +
+