diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index eb15ca3ac..55064c4f0 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -217,6 +217,99 @@ class ReportsController extends Controller } + /** + * Exports the activity report to CSV + * + * @author [A. Gianotto] [] + * @since [v5.0.7] + * @return \Illuminate\Http\Response + */ + public function postActivityReport(Request $request) + { + ini_set('max_execution_time', 12000); + $this->authorize('reports.view'); + + \Debugbar::disable(); + $response = new StreamedResponse(function () { + + \Log::debug('Starting streamed response'); + + // Open output stream + $handle = fopen('php://output', 'w'); + stream_set_timeout($handle, 2000); + + $header = [ + trans('general.date'), + trans('general.admin'), + trans('general.action'), + trans('general.type'), + trans('general.item'), + 'To', + trans('general.notes'), + 'Changed', + + ]; + $executionTime = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; + \Log::debug('Starting headers: '.$executionTime); + fputcsv($handle, $header); + $executionTime = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; + \Log::debug('Added headers: '.$executionTime); + + $actionlogs = Actionlog::with('item', 'user', 'target','location') + ->orderBy('created_at', 'DESC') + ->chunk(20, function($actionlogs) use($handle) { + + $executionTime = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; + \Log::debug('Walking results: '.$executionTime); + $count = 0; + + foreach ($actionlogs as $actionlog) { + + $count++; + $target_name = ''; + + if ($actionlog->target) { + if ($actionlog->targetType()=='user') { + $target_name = $actionlog->target->getFullNameAttribute(); + } else { + $target_name = $actionlog->target->getDisplayNameAttribute(); + } + } + + + $row = [ + $actionlog->created_at, + ($actionlog->user) ? e($actionlog->user->getFullNameAttribute()) : '', + $actionlog->present()->actionType(), + e($actionlog->itemType()), + ($actionlog->itemType()=='user') ? $actionlog->filename : e($actionlog->item->getDisplayNameAttribute()), + $target_name, + ($actionlog->note) ? e($actionlog->note): '', + $actionlog->log_meta, + ]; + fputcsv($handle, $row); + + } + }); + + // Close the output stream + fclose($handle); + $executionTime = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; + \Log::debug('-- SCRIPT COMPLETED IN '. $executionTime); + + }, 200, [ + 'Content-Type' => 'text/csv', + 'Content-Disposition' + => 'attachment; filename="activity-report-'.date('Y-m-d-his').'.csv"', + ]); + + + return $response; + + + } + + /** * Displays license report * diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index f11af2b97..cf936392e 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -79,6 +79,7 @@ 'depreciation_report' => 'Depreciation Report', 'details' => 'Details', 'download' => 'Download', + 'download_all' => 'Download All', 'depreciation' => 'Depreciation', 'editprofile' => 'Edit Your Profile', 'eol' => 'EOL', diff --git a/resources/views/reports/activity.blade.php b/resources/views/reports/activity.blade.php index a580386b8..f0cc5f25e 100644 --- a/resources/views/reports/activity.blade.php +++ b/resources/views/reports/activity.blade.php @@ -6,6 +6,13 @@ @parent @stop +@section('header_right') + {{ Form::open(['method' => 'post', 'class' => 'form-horizontal']) }} + {{csrf_field()}} + + {{ Form::close() }} +@stop + {{-- Page content --}} @section('content') diff --git a/routes/web.php b/routes/web.php index a9cf2162d..c4b64ad69 100644 --- a/routes/web.php +++ b/routes/web.php @@ -324,6 +324,9 @@ Route::group(['middleware' => ['auth']], function () { [ 'as' => 'reports.activity', 'uses' => 'ReportsController@getActivityReport' ] ); + Route::post('reports/activity', 'ReportsController@postActivityReport'); + + Route::get( 'reports/unaccepted_assets',