mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-24 04:03:34 -08:00
Removed old reports methods and routes
We only use the custom asset report now
This commit is contained in:
parent
3662a58ad8
commit
97f748d58e
|
@ -81,137 +81,7 @@ class ReportsController extends Controller
|
|||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display asset report view.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @return View
|
||||
*/
|
||||
public function getAssetsReport()
|
||||
{
|
||||
$settings = \App\Models\Setting::first();
|
||||
return view('reports/asset', compact('assets'))->with('settings', $settings);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Exports the assets to CSV
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function exportAssetReport(Request $request)
|
||||
{
|
||||
|
||||
\Debugbar::disable();
|
||||
|
||||
$customfields = CustomField::get();
|
||||
|
||||
$response = new StreamedResponse(function () use ($customfields, $request) {
|
||||
// Open output stream
|
||||
$handle = fopen('php://output', 'w');
|
||||
|
||||
$assets = Asset::with('assignedTo', 'location','defaultLoc','assignedTo','model','supplier','assetstatus','model.manufacturer');
|
||||
|
||||
// This is used by the sidenav, mostly
|
||||
switch ($request->input('status')) {
|
||||
case 'Deleted':
|
||||
$assets->withTrashed()->Deleted();
|
||||
break;
|
||||
case 'Pending':
|
||||
$assets->Pending();
|
||||
break;
|
||||
case 'RTD':
|
||||
$assets->RTD();
|
||||
break;
|
||||
case 'Undeployable':
|
||||
$assets->Undeployable();
|
||||
break;
|
||||
case 'Archived':
|
||||
$assets->Archived();
|
||||
break;
|
||||
case 'Requestable':
|
||||
$assets->RequestableAssets();
|
||||
break;
|
||||
case 'Deployed':
|
||||
$assets->Deployed();
|
||||
break;
|
||||
}
|
||||
|
||||
$headers=[
|
||||
trans('general.company'),
|
||||
trans('admin/hardware/table.asset_tag'),
|
||||
trans('admin/hardware/form.manufacturer'),
|
||||
trans('general.category'),
|
||||
trans('admin/hardware/form.model'),
|
||||
trans('general.model_no'),
|
||||
trans('general.name'),
|
||||
trans('admin/hardware/table.serial'),
|
||||
trans('general.status'),
|
||||
trans('admin/hardware/table.purchase_date'),
|
||||
trans('admin/hardware/table.purchase_cost'),
|
||||
trans('admin/hardware/form.order'),
|
||||
trans('general.supplier'),
|
||||
trans('admin/hardware/table.checkoutto'),
|
||||
trans('general.type'),
|
||||
trans('admin/hardware/table.checkout_date'),
|
||||
trans('admin/hardware/table.location'),
|
||||
trans('general.notes'),
|
||||
];
|
||||
foreach ($customfields as $field) {
|
||||
$headers[]=$field->name;
|
||||
}
|
||||
fputcsv($handle, $headers);
|
||||
|
||||
$assets->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle, $customfields) {
|
||||
|
||||
|
||||
foreach ($assets as $asset) {
|
||||
|
||||
// Add a new row with data
|
||||
$values=[
|
||||
($asset->company) ? $asset->company->name : '',
|
||||
$asset->asset_tag,
|
||||
($asset->model->manufacturer) ? $asset->model->manufacturer->name : '',
|
||||
($asset->model->category) ? $asset->model->category->name : '',
|
||||
($asset->model) ? $asset->model->name : '',
|
||||
($asset->model->model_number) ? $asset->model->model_number : '',
|
||||
($asset->name) ? $asset->name : '',
|
||||
($asset->serial) ? $asset->serial : '',
|
||||
($asset->assetstatus) ? e($asset->present()->statusText) : '',
|
||||
($asset->purchase_date) ? e($asset->purchase_date) : '',
|
||||
($asset->purchase_cost > 0) ? Helper::formatCurrencyOutput($asset->purchase_cost) : '',
|
||||
($asset->order_number) ? e($asset->order_number) : '',
|
||||
($asset->supplier) ? e($asset->supplier->name) : '',
|
||||
($asset->checkedOutToUser() && $asset->assigned) ? e($asset->assigned->getFullNameAttribute()) : ($asset->assigned ? e($asset->assigned->display_name) : ''),
|
||||
($asset->checkedOutToUser() && $asset->assigned) ? 'user' : e($asset->assignedType()),
|
||||
($asset->last_checkout!='') ? e($asset->last_checkout) : '',
|
||||
($asset->location) ? e($asset->location->name) : '',
|
||||
($asset->notes) ? e($asset->notes) : '',
|
||||
];
|
||||
foreach ($customfields as $field) {
|
||||
$values[]=$asset->{$field->db_column_name()};
|
||||
}
|
||||
fputcsv($handle, $values);
|
||||
}
|
||||
});
|
||||
|
||||
// Close the output stream
|
||||
fclose($handle);
|
||||
}, 200, [
|
||||
'Content-Type' => 'text/csv',
|
||||
'Content-Disposition'
|
||||
=> 'attachment; filename="'.(($request->has('status')) ? trim($request->input('status')) : 'all').'-assets-'.date('Y-m-d-his').'.csv"',
|
||||
]);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show depreciation report for assets.
|
||||
*
|
||||
|
|
|
@ -316,11 +316,7 @@ Route::group(['middleware' => ['auth']], function () {
|
|||
'reports/export/licenses',
|
||||
[ 'as' => 'reports/export/licenses', 'uses' => 'ReportsController@exportLicenseReport' ]
|
||||
);
|
||||
Route::get('reports/assets', [ 'as' => 'reports/assets', 'uses' => 'ReportsController@getAssetsReport' ]);
|
||||
Route::get(
|
||||
'reports/export/assets',
|
||||
[ 'as' => 'reports.export.assets', 'uses' => 'ReportsController@exportAssetReport' ]
|
||||
);
|
||||
|
||||
Route::get('reports/accessories', [ 'as' => 'reports/accessories', 'uses' => 'ReportsController@getAccessoryReport' ]);
|
||||
Route::get(
|
||||
'reports/export/accessories',
|
||||
|
|
Loading…
Reference in a new issue