From 75e0c5565c87cbee6294291688f6826cd85a9050 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 2 Aug 2016 15:04:10 -0700 Subject: [PATCH] Add username and custom fields option to custom report --- app/Http/Controllers/ReportsController.php | 33 ++++++++++++++++++++-- resources/views/reports/custom.blade.php | 17 +++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 67adca563d7e..8b62f38737c7 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -6,7 +6,6 @@ use App\Models\Asset; use App\Models\AssetMaintenance; use Carbon\Carbon; -use Category; use App\Models\Company; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Log; @@ -17,6 +16,7 @@ use App\Models\License; use App\Models\Location; use App\Models\AssetModel; +use App\Models\CustomField; use Redirect; use App\Models\Setting; use App\Models\User; @@ -415,8 +415,8 @@ public function exportLicenseReport() */ public function getCustomReport() { - - return View::make('reports/custom'); + $customfields = CustomField::get(); + return View::make('reports/custom')->with('customfields',$customfields); } /** @@ -430,6 +430,7 @@ public function getCustomReport() public function postCustom() { $assets = Asset::orderBy('created_at', 'DESC')->get(); + $customfields = CustomField::get(); $rows = [ ]; $header = [ ]; @@ -484,6 +485,13 @@ public function postCustom() $header[] = 'Diff'; } + foreach ($customfields as $customfield) { + if (e(Input::get($customfield->db_column_name())) == '1') { + $header[] = $customfield->name; + } + } + + $header = array_map('trim', $header); $rows[] = implode($header, ','); @@ -562,6 +570,16 @@ public function postCustom() $row[] = ''; // Empty string if unassigned } } + + if (e(Input::get('username')) == '1') { + if ($asset->assigned_to > 0) { + $user = User::find($asset->assigned_to); + $row[] = '"' .e($user-username). '"'; + } else { + $row[] = ''; // Empty string if unassigned + } + } + if (e(Input::get('status')) == '1') { if (( $asset->status_id == '0' ) && ( $asset->assigned_to == '0' )) { $row[] = trans('general.ready_to_deploy'); @@ -588,6 +606,15 @@ public function postCustom() $row[] = '"' . number_format($depreciation, 2) . '"'; $row[] = '"' . number_format($asset->purchase_cost - $depreciation, 2) . '"'; } + + foreach ($customfields as $customfield) { + $column_name = $customfield->db_column_name(); + if (e(Input::get($customfield->db_column_name())) == '1') { + $row[] = $asset->$column_name; + } + } + + $rows[] = implode($row, ','); } diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php index 1fa2433f7595..6a5f48938343 100644 --- a/resources/views/reports/custom.blade.php +++ b/resources/views/reports/custom.blade.php @@ -101,6 +101,14 @@ {{ trans('admin/licenses/table.assigned_to') }} + +
+ +
+
+ + @foreach ($customfields as $customfield) +
+ +
+ @endforeach