mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Added option to download activity report
This commit is contained in:
parent
dcd98a7bf1
commit
1f5bcf2475
|
@ -217,6 +217,99 @@ class ReportsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exports the activity report to CSV
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @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
|
* Displays license report
|
||||||
*
|
*
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
'depreciation_report' => 'Depreciation Report',
|
'depreciation_report' => 'Depreciation Report',
|
||||||
'details' => 'Details',
|
'details' => 'Details',
|
||||||
'download' => 'Download',
|
'download' => 'Download',
|
||||||
|
'download_all' => 'Download All',
|
||||||
'depreciation' => 'Depreciation',
|
'depreciation' => 'Depreciation',
|
||||||
'editprofile' => 'Edit Your Profile',
|
'editprofile' => 'Edit Your Profile',
|
||||||
'eol' => 'EOL',
|
'eol' => 'EOL',
|
||||||
|
|
|
@ -6,6 +6,13 @@
|
||||||
@parent
|
@parent
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
|
@section('header_right')
|
||||||
|
{{ Form::open(['method' => 'post', 'class' => 'form-horizontal']) }}
|
||||||
|
{{csrf_field()}}
|
||||||
|
<button type="submit" class="btn btn-default"><i class="fa fa-download icon-white" aria-hidden="true"></i> {{ trans('general.download_all') }}</button>
|
||||||
|
{{ Form::close() }}
|
||||||
|
@stop
|
||||||
|
|
||||||
{{-- Page content --}}
|
{{-- Page content --}}
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
|
|
|
@ -324,6 +324,9 @@ Route::group(['middleware' => ['auth']], function () {
|
||||||
[ 'as' => 'reports.activity', 'uses' => 'ReportsController@getActivityReport' ]
|
[ 'as' => 'reports.activity', 'uses' => 'ReportsController@getActivityReport' ]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Route::post('reports/activity', 'ReportsController@postActivityReport');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Route::get(
|
Route::get(
|
||||||
'reports/unaccepted_assets',
|
'reports/unaccepted_assets',
|
||||||
|
|
Loading…
Reference in a new issue