diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 746042e67e..b892b46e19 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -293,17 +293,109 @@ 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(); return View::make('reports/activity', compact('log_actions')); } + + /** + * 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 = ['name','min_amt','order_number','purchase_date','purchase_cost','companyName','category']; + $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 *