Skip to content

Commit

Permalink
Add username and custom fields option to custom report
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Aug 2, 2016
1 parent 098e7e4 commit 75e0c55
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
33 changes: 30 additions & 3 deletions app/Http/Controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -430,6 +430,7 @@ public function getCustomReport()
public function postCustom()
{
$assets = Asset::orderBy('created_at', 'DESC')->get();
$customfields = CustomField::get();

$rows = [ ];
$header = [ ];
Expand Down Expand Up @@ -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, ',');

Expand Down Expand Up @@ -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');
Expand All @@ -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, ',');
}

Expand Down
17 changes: 17 additions & 0 deletions resources/views/reports/custom.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
{{ trans('admin/licenses/table.assigned_to') }}
</label>
</div>

<div class="checkbox col-md-12">
<label>
{{ Form::checkbox('username', '1') }}
{{ trans('admin/users/table.username') }}
</label>
</div>

<div class="checkbox col-md-12">
<label>
{{ Form::checkbox('status', '1') }}
Expand All @@ -119,6 +127,15 @@
{{ trans('general.depreciation') }}
</label>
</div>

@foreach ($customfields as $customfield)
<div class="checkbox col-md-12">
<label>
{{ Form::checkbox($customfield->db_column_name(), '1') }}
{{ $customfield->name }}
</label>
</div>
@endforeach
</div>


Expand Down

0 comments on commit 75e0c55

Please sign in to comment.