Skip to content

Commit 75e0c55

Browse files
committed
Add username and custom fields option to custom report
1 parent 098e7e4 commit 75e0c55

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

app/Http/Controllers/ReportsController.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use App\Models\Asset;
77
use App\Models\AssetMaintenance;
88
use Carbon\Carbon;
9-
use Category;
109
use App\Models\Company;
1110
use Illuminate\Support\Facades\Lang;
1211
use Illuminate\Support\Facades\Log;
@@ -17,6 +16,7 @@
1716
use App\Models\License;
1817
use App\Models\Location;
1918
use App\Models\AssetModel;
19+
use App\Models\CustomField;
2020
use Redirect;
2121
use App\Models\Setting;
2222
use App\Models\User;
@@ -415,8 +415,8 @@ public function exportLicenseReport()
415415
*/
416416
public function getCustomReport()
417417
{
418-
419-
return View::make('reports/custom');
418+
$customfields = CustomField::get();
419+
return View::make('reports/custom')->with('customfields',$customfields);
420420
}
421421

422422
/**
@@ -430,6 +430,7 @@ public function getCustomReport()
430430
public function postCustom()
431431
{
432432
$assets = Asset::orderBy('created_at', 'DESC')->get();
433+
$customfields = CustomField::get();
433434

434435
$rows = [ ];
435436
$header = [ ];
@@ -484,6 +485,13 @@ public function postCustom()
484485
$header[] = 'Diff';
485486
}
486487

488+
foreach ($customfields as $customfield) {
489+
if (e(Input::get($customfield->db_column_name())) == '1') {
490+
$header[] = $customfield->name;
491+
}
492+
}
493+
494+
487495
$header = array_map('trim', $header);
488496
$rows[] = implode($header, ',');
489497

@@ -562,6 +570,16 @@ public function postCustom()
562570
$row[] = ''; // Empty string if unassigned
563571
}
564572
}
573+
574+
if (e(Input::get('username')) == '1') {
575+
if ($asset->assigned_to > 0) {
576+
$user = User::find($asset->assigned_to);
577+
$row[] = '"' .e($user-username). '"';
578+
} else {
579+
$row[] = ''; // Empty string if unassigned
580+
}
581+
}
582+
565583
if (e(Input::get('status')) == '1') {
566584
if (( $asset->status_id == '0' ) && ( $asset->assigned_to == '0' )) {
567585
$row[] = trans('general.ready_to_deploy');
@@ -588,6 +606,15 @@ public function postCustom()
588606
$row[] = '"' . number_format($depreciation, 2) . '"';
589607
$row[] = '"' . number_format($asset->purchase_cost - $depreciation, 2) . '"';
590608
}
609+
610+
foreach ($customfields as $customfield) {
611+
$column_name = $customfield->db_column_name();
612+
if (e(Input::get($customfield->db_column_name())) == '1') {
613+
$row[] = $asset->$column_name;
614+
}
615+
}
616+
617+
591618
$rows[] = implode($row, ',');
592619
}
593620

resources/views/reports/custom.blade.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@
101101
{{ trans('admin/licenses/table.assigned_to') }}
102102
</label>
103103
</div>
104+
105+
<div class="checkbox col-md-12">
106+
<label>
107+
{{ Form::checkbox('username', '1') }}
108+
{{ trans('admin/users/table.username') }}
109+
</label>
110+
</div>
111+
104112
<div class="checkbox col-md-12">
105113
<label>
106114
{{ Form::checkbox('status', '1') }}
@@ -119,6 +127,15 @@
119127
{{ trans('general.depreciation') }}
120128
</label>
121129
</div>
130+
131+
@foreach ($customfields as $customfield)
132+
<div class="checkbox col-md-12">
133+
<label>
134+
{{ Form::checkbox($customfield->db_column_name(), '1') }}
135+
{{ $customfield->name }}
136+
</label>
137+
</div>
138+
@endforeach
122139
</div>
123140

124141

0 commit comments

Comments
 (0)