Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2020-11-13 16:48:58 -08:00
commit 849966d2c5
4 changed files with 104 additions and 0 deletions

View file

@ -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
*

View file

@ -79,6 +79,7 @@
'depreciation_report' => 'Depreciation Report',
'details' => 'Details',
'download' => 'Download',
'download_all' => 'Download All',
'depreciation' => 'Depreciation',
'editprofile' => 'Edit Your Profile',
'eol' => 'EOL',

View file

@ -6,6 +6,13 @@
@parent
@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 --}}
@section('content')

View file

@ -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',