Added customfields to asset CSV export

This commit is contained in:
snipe 2016-09-27 15:09:47 -07:00
parent f1c458185d
commit 67f199b09d

View file

@ -115,53 +115,63 @@ class ReportsController extends Controller
\Debugbar::disable(); \Debugbar::disable();
$customfields = CustomField::get();
$response = new StreamedResponse(function(){ $response = new StreamedResponse(function(){
// Open output stream // Open output stream
$handle = fopen('php://output', 'w'); $handle = fopen('php://output', 'w');
Asset::with('assigneduser', 'assetloc','defaultLoc','assigneduser.userloc','model','supplier','assetstatus','model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle) { Asset::with('assigneduser', 'assetloc','defaultLoc','assigneduser.userloc','model','supplier','assetstatus','model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle) {
fputcsv($handle, [ $headers=[
trans('general.company'), trans('general.company'),
trans('admin/hardware/table.asset_tag'), trans('admin/hardware/table.asset_tag'),
trans('admin/hardware/form.manufacturer'), trans('admin/hardware/form.manufacturer'),
trans('admin/hardware/form.model'), trans('admin/hardware/form.model'),
trans('general.model_no'), trans('general.model_no'),
trans('general.name'), trans('general.name'),
trans('admin/hardware/table.serial'), trans('admin/hardware/table.serial'),
trans('general.status'), trans('general.status'),
trans('admin/hardware/table.purchase_date'), trans('admin/hardware/table.purchase_date'),
trans('admin/hardware/table.purchase_cost'), trans('admin/hardware/table.purchase_cost'),
trans('admin/hardware/form.order'), trans('admin/hardware/form.order'),
trans('admin/hardware/form.supplier'), trans('admin/hardware/form.supplier'),
trans('admin/hardware/table.checkoutto'), trans('admin/hardware/table.checkoutto'),
trans('admin/hardware/table.checkout_date'), trans('admin/hardware/table.checkout_date'),
trans('admin/hardware/table.location'), trans('admin/hardware/table.location'),
trans('general.notes'), trans('general.notes'),
]); ];
foreach($customfields as $field) {
$headers[]=$field->name;
}
fputcsv($handle, $headers);
foreach ($assets as $asset) { foreach ($assets as $asset) {
// Add a new row with data // Add a new row with data
fputcsv($handle, [ $values=[
($asset->company) ? $asset->company->name : '', ($asset->company) ? $asset->company->name : '',
$asset->asset_tag, $asset->asset_tag,
($asset->model->manufacturer) ? $asset->model->manufacturer->name : '', ($asset->model->manufacturer) ? $asset->model->manufacturer->name : '',
($asset->model) ? $asset->model->name : '', ($asset->model) ? $asset->model->name : '',
($asset->model->modelno) ? $asset->model->modelno : '', ($asset->model->modelno) ? $asset->model->modelno : '',
($asset->name) ? $asset->name : '', ($asset->name) ? $asset->name : '',
($asset->serial) ? $asset->serial : '', ($asset->serial) ? $asset->serial : '',
($asset->assetstatus) ? e($asset->assetstatus->name) : '', ($asset->assetstatus) ? e($asset->assetstatus->name) : '',
($asset->purchase_date) ? e($asset->purchase_date) : '', ($asset->purchase_date) ? e($asset->purchase_date) : '',
($asset->purchase_cost > 0) ? Helper::formatCurrencyOutput($asset->purchase_cost) : '', ($asset->purchase_cost > 0) ? Helper::formatCurrencyOutput($asset->purchase_cost) : '',
($asset->order_number) ? e($asset->order_number) : '', ($asset->order_number) ? e($asset->order_number) : '',
($asset->supplier) ? e($asset->supplier->name) : '', ($asset->supplier) ? e($asset->supplier->name) : '',
($asset->assigneduser) ? e($asset->assigneduser->fullName()) : '', ($asset->assigneduser) ? e($asset->assigneduser->fullName()) : '',
($asset->last_checkout!='') ? e($asset->last_checkout) : '', ($asset->last_checkout!='') ? e($asset->last_checkout) : '',
($asset->assigneduser && $asset->assigneduser->userloc!='') ? ($asset->assigneduser && $asset->assigneduser->userloc!='') ?
e($asset->assigneduser->userloc->name) : ( ($asset->defaultLoc!='') ? e($asset->defaultLoc->name) : ''), e($asset->assigneduser->userloc->name) : ( ($asset->defaultLoc!='') ? e($asset->defaultLoc->name) : ''),
($asset->notes) ? e($asset->notes) : '', ($asset->notes) ? e($asset->notes) : '',
]); ];
} foreach($customfields as $field) {
}); $values[]=$asset->{$field->db_column_name()};
}
fputcsv($handle, $values);
}
});
// Close the output stream // Close the output stream
fclose($handle); fclose($handle);