A free open source IT asset/license management system
Added variable to determine if “new” modal button should be displayed
snipeff793f1cb517
diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.phpindex c3bc7b4136..d8c2ca6793 100644--- a/app/Http/Controllers/ReportsController.php+++ b/app/Http/Controllers/ReportsController.php@@ -422,261 +422,275 @@ class ReportsController extends Controller* @since [v1.0]* @return \Illuminate\Http\Response*/- public function postCustom()+ public function postCustom(Request $request){- $assets = Asset::orderBy('created_at', 'DESC')->with('company', 'assignedTo', 'location', 'defaultLoc', 'model', 'supplier', 'assetstatus', 'model.manufacturer')->get();- $customfields = CustomField::get();-- $rows = [ ];- $header = [ ];-- if (e(Input::get('company')) == '1') {- $header[] = 'Company Name';- }-- if (e(Input::get('asset_name')) == '1') {- $header[] = 'Asset Name';- }- if (e(Input::get('asset_tag')) == '1') {- $header[] = 'Asset Tag';- }- if (e(Input::get('manufacturer')) == '1') {- $header[] = 'Manufacturer';- }- if (e(Input::get('model')) == '1') {- $header[] = 'Model';- $header[] = 'Model Number';- }- if (e(Input::get('category')) == '1') {- $header[] = 'Category';- }- if (e(Input::get('serial')) == '1') {- $header[] = 'Serial';- }- if (e(Input::get('purchase_date')) == '1') {- $header[] = 'Purchase Date';- }- if (( e(Input::get('purchase_cost')) == '1' ) && ( e(Input::get('depreciation')) != '1' )) {- $header[] = 'Purchase Cost';- }- if (e(Input::get('eol')) == '1') {- $header[] = 'EOL';- }- if (e(Input::get('order')) == '1') {- $header[] = 'Order Number';- }- if (e(Input::get('supplier')) == '1') {- $header[] = 'Supplier';- }- if (e(Input::get('location')) == '1') {- $header[] = 'Location';- }- if (e(Input::get('assigned_to')) == '1') {- $header[] = 'Assigned To';- }- if (e(Input::get('username')) == '1') {- $header[] = 'Username';- }- if (e(Input::get('employee_num')) == '1') {- $header[] = 'Employee No.';- }- if (e(Input::get('status')) == '1') {- $header[] = 'Status';- }- if (e(Input::get('warranty')) == '1') {- $header[] = 'Warranty';- $header[] = 'Warranty Expires';- }- if (e(Input::get('depreciation')) == '1') {- $header[] = 'Purchase Cost';- $header[] = 'Value';- $header[] = 'Diff';- }- if (e(Input::get('expected_checkin')) == '1') {- $header[] = trans('admin/hardware/form.expected_checkin');- }-- if (e(Input::get('notes')) == '1') {- $header[] = trans('general.notes');- }+ \Debugbar::disable();+ $customfields = CustomField::get();+ $response = new StreamedResponse(function () use ($customfields, $request) {- foreach ($customfields as $customfield) {- if (e(Input::get($customfield->db_column_name())) == '1') {- $header[] = $customfield->name;+ // Open output stream+ $handle = fopen('php://output', 'w');++ if ($request->has('use_bom')) {+ fprintf($handle, chr(0xEF) . chr(0xBB) . chr(0xBF));}- }-- $header = array_map('trim', $header);- $rows[] = implode($header, ',');-- foreach ($assets as $asset) {- $row = [ ];+ $header = [];- if (e(Input::get('company')) == '1') {- $row[] = is_null($asset->company) ? '' : '"'.$asset->company->name.'"';+ if ($request->has('company')) {+ $header[] = 'Company Name';}- if (e(Input::get('asset_name')) == '1') {- $row[] = '"' .e($asset->name) . '"';+ if ($request->has('asset_name')) {+ $header[] = 'Asset Name';}- if (e(Input::get('asset_tag')) == '1') {- $row[] = e($asset->asset_tag);+ if ($request->has('asset_tag')) {+ $header[] = 'Asset Tag';}- if (e(Input::get('manufacturer')) == '1') {- if ($asset->model->manufacturer) {- $row[] = '"' .e($asset->model->manufacturer->name) . '"';- } else {- $row[] = '';- }+ if ($request->has('manufacturer')) {+ $header[] = 'Manufacturer';}- if (e(Input::get('model')) == '1') {- $row[] = '"' . e($asset->model->name) . '"';- $row[] = '"' . e($asset->model->model_number) . '"';+ if ($request->has('model')) {+ $header[] = 'Model';+ $header[] = 'Model Number';}- if (e(Input::get('category')) == '1') {- $row[] = '"' .e($asset->model->category->name) . '"';+ if ($request->has('category')) {+ $header[] = 'Category';}-- if (e(Input::get('serial')) == '1') {- $row[] = e($asset->serial);+ if ($request->has('serial')) {+ $header[] = 'Serial';}- if (e(Input::get('purchase_date')) == '1') {- $row[] = e($asset->purchase_date);+ if ($request->has('purchase_date')) {+ $header[] = 'Purchase Date';}- if (e(Input::get('purchase_cost')) == '1' && ( e(Input::get('depreciation')) != '1' )) {- $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"';+ if ($request->has('purchase_cost')) {+ $header[] = 'Purchase Cost';}- if (e(Input::get('eol')) == '1') {- $row[] = '"' .($asset->present()->eol_date()) ? $asset->present()->eol_date() : ''. '"';+ if ($request->has('eol')) {+ $header[] = 'EOL';}- if (e(Input::get('order')) == '1') {- if ($asset->order_number) {- $row[] = e($asset->order_number);- } else {- $row[] = '';- }+ if ($request->has('order')) {+ $header[] = 'Order Number';}- if (e(Input::get('supplier')) == '1') {- if ($asset->supplier) {- $row[] = '"' .e($asset->supplier->name) . '"';- } else {- $row[] = '';- }+ if ($request->has('supplier')) {+ $header[] = 'Supplier';+ }+ if ($request->has('location')) {+ $header[] = 'Location';+ }+ if ($request->has('assigned_to')) {+ $header[] = 'Assigned To';+ $header[] = 'Assigned Type';+ }+ if ($request->has('username')) {+ $header[] = 'Username';+ }+ if ($request->has('employee_num')) {+ $header[] = 'Employee No.';+ }+ if ($request->has('status')) {+ $header[] = 'Status';+ }+ if ($request->has('warranty')) {+ $header[] = 'Warranty';+ $header[] = 'Warranty Expires';+ }+ if ($request->has('depreciation')) {+ $header[] = 'Purchase Cost';+ $header[] = 'Value';+ $header[] = 'Diff';+ }+ if ($request->has('expected_checkin')) {+ $header[] = trans('admin/hardware/form.expected_checkin');}- if (e(Input::get('location')) == '1') {- if($asset->location) {- $show_loc = $asset->location->present()->name();- } else {- $show_loc = 'Default location '.$asset->rtd_location_id.' is invalid';- }- $row[] = $show_loc;+ if ($request->has('notes')) {+ $header[] = trans('general.notes');}- if (e(Input::get('assigned_to')) == '1') {- if ($asset->assignedto) {- $row[] = '"' .e($asset->assignedto->present()->name()). '"';- } else {- $row[] = ''; // Empty string if unassigned+ foreach ($customfields as $customfield) {+ if (e(Input::get($customfield->db_column_name())) == '1') {+ $header[] = $customfield->name;}}- if (e(Input::get('username')) == '1') {- // Only works if we're checked out to a user, not anything else.- if ($asset->checkedOutToUser()) {- if ($asset->assignedto) {- $row[] = '"' .e($asset->assignedto->username). '"';- } else {- $row[] = ''; // Empty string if unassigned- }- } else {- $row[] = ''; // Empty string if unassigned- }- }+ fputcsv($handle, $header);- if (e(Input::get('employee_num')) == '1') {- // Only works if we're checked out to a user, not anything else.- if ($asset->checkedOutToUser()) {- if ($asset->assignedto) {- $row[] = '"' .e($asset->assignedto->employee_num). '"';- } else {- $row[] = ''; // Empty string if unassigned- }+ $assets = Asset::orderBy('created_at', 'DESC')->with('company', 'assignedTo', 'location', 'defaultLoc', 'model', 'supplier', 'assetstatus', 'model.manufacturer');++ if ($request->has('by_location_id')) {+ $assets->where('assets.location_id', $request->input('by_location_id'));+ }- } else {- $row[] = ''; // Empty string if unassigned- }+ if ($request->has('by_supplier_id')) {+ $assets->where('assets.supplier_id', $request->input('by_supplier_id'));}- if (e(Input::get('status')) == '1') {- if (( $asset->status_id == '0' ) && ( $asset->assigned_to == '0' )) {- $row[] = trans('general.ready_to_deploy');- } elseif (( $asset->status_id == '' ) && ( $asset->assigned_to == '0' )) {- $row[] = trans('general.pending');- } elseif ($asset->assetstatus) {- $row[] = '"' .e($asset->assetstatus->name). '"';- } else {- $row[] = '';- }+ if ($request->has('by_company_id')) {+ $assets->where('assets.company_id', $request->input('by_company_id'));}- if (e(Input::get('warranty')) == '1') {- if ($asset->warranty_months) {- $row[] = $asset->warranty_months;- $row[] = $asset->present()->warrantee_expires();- } else {- $row[] = '';- $row[] = '';- }++ if ($request->has('by_model_id')) {+ $assets->where('assets.model_id', $request->input('by_model_id'));}- if (e(Input::get('depreciation')) == '1') {- $depreciation = $asset->getDepreciatedValue();- $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"';- $row[] = '"' . Helper::formatCurrencyOutput($depreciation) . '"';- $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"';++ if ($request->has('by_category_id')) {+ $assets->InCategory($request->input('by_category_id'));}- if (e(Input::get('expected_checkin')) == '1') {- if ($asset->expected_checkin) {- $row[] = '"' .e($asset->expected_checkin). '"';- } else {- $row[] = ''; // Empty string if blankd- }++ if ($request->has('by_order_number')) {+ $assets->where('assets.order_number', $request->input('by_order_number'));}- if (e(Input::get('notes')) == '1') {- if ($asset->notes) {- $row[] = '"' .$asset->notes . '"';- } else {- $row[] = '';- }+ if (($request->has('start')) && ($request->has('end'))) {+ $assets->whereBetween('assets.purchase_date', [$request->input('start'), $request->input('end')]);}++ $assets->orderBy('assets.created_at', 'DESC')->chunk(500, function($assets) use($handle, $customfields, $request) {- foreach ($customfields as $customfield) {- $column_name = $customfield->db_column_name();- if (e(Input::get($customfield->db_column_name())) == '1') {- $row[] = str_replace(",", "\,", $asset->$column_name);+ foreach ($assets as $asset) {+ $row = [];++ if ($request->has('company')) {+ $row[] = ($asset->company) ? $asset->company->name : '';+ }++ if ($request->has('asset_name')) {+ $row[] = ($asset->name) ? $asset->name : '';+ }++ if ($request->has('asset_tag')) {+ $row[] = ($asset->asset_tag) ? $asset->asset_tag : '';+ }++ if ($request->has('manufacturer')) {+ $row[] = ($asset->model && $asset->model->manufacturer) ? $asset->model->manufacturer->name : '';+ }++ if ($request->has('model')) {+ $row[] = ($asset->model) ? $asset->model->name : '';+ $row[] = ($asset->model) ? $asset->model->model_number : '';+ }++ if ($request->has('category')) {+ $row[] = ($asset->model->category) ? $asset->model->category->name : '';+ }++ if ($request->has('serial')) {+ $row[] = ($asset->serial) ? $asset->serial : '';+ }++ if ($request->has('purchase_date')) {+ $row[] = ($asset->purchase_date) ? $asset->purchase_date : '';+ }++ if ($request->has('purchase_cost')) {+ $row[] = ($asset->purchase_cost) ? Helper::formatCurrencyOutput($asset->purchase_cost) : '';+ }++ if ($request->has('eol')) {+ $row[] = ($asset->eol) ? $asset->present()->eol_date() : '';+ }++ if ($request->has('order')) {+ $row[] = ($asset->order_number) ? $asset->order_number : '';+ }++ if ($request->has('supplier')) {+ $row[] = ($asset->location) ? $asset->supplier->name : '';+ }+++ if ($request->has('location')) {+ $row[] = ($asset->location) ? $asset->location->present()->name() : '';+ }++ if ($request->has('assigned_to')) {+ $row[] = ($asset->checkedOutToUser() && $asset->assigned) ? e($asset->assigned->getFullNameAttribute()) : ($asset->assigned ? e($asset->assigned->display_name) : '');+ $row[] = ($asset->checkedOutToUser() && $asset->assigned) ? 'user' : e($asset->assignedType());+ }++ if ($request->has('username')) {+ // Only works if we're checked out to a user, not anything else.+ if ($asset->checkedOutToUser()) {+ $row[] = ($asset->assignedto) ? $asset->assignedto->username : '';+ } else {+ $row[] = ''; // Empty string if unassigned+ }+ }++ if ($request->has('employee_num')) {+ // Only works if we're checked out to a user, not anything else.+ if ($asset->checkedOutToUser()) {+ $row[] = ($asset->assignedto) ? $asset->assignedto->employee_num : '';+ } else {+ $row[] = ''; // Empty string if unassigned+ }+ }++ if ($request->has('status')) {+ if (( $asset->status_id == '0' ) && ( $asset->assigned_to == '0' )) {+ $row[] = trans('general.ready_to_deploy');+ } elseif (( $asset->status_id == '' ) && ( $asset->assigned_to == '0' )) {+ $row[] = trans('general.pending');+ } elseif ($asset->assetstatus) {+ $row[] = $asset->assetstatus->name;+ } else {+ $row[] = '';+ }+ }+++ if ($request->has('warranty')) {+ $row[] = ($asset->warranty_months) ? $asset->warranty_months : '';+ $row[] = $asset->present()->warrantee_expires();+ }++ if ($request->has('depreciation')) {+ if ($asset->purchase_cost!='') {+ $depreciation = $asset->getDepreciatedValue();+ $diff = ($asset->purchase_cost - $depreciation);+ $row[] = Helper::formatCurrencyOutput($asset->purchase_cost);+ $row[] = Helper::formatCurrencyOutput($depreciation);+ $row[] = Helper::formatCurrencyOutput($diff);+ } else {+ $row[] = '';+ }++ }++ if ($request->has('expected_checkin')) {+ $row[] = ($asset->expected_checkin) ? $asset->expected_checkin : '';+ }++ if ($request->has('notes')) {+ $row[] = ($asset->notes) ? $asset->notes : '';+ }++ foreach ($customfields as $customfield) {+ $column_name = $customfield->db_column_name();+ if ($request->has($customfield->db_column_name())) {+ $row[] = $asset->$column_name;+ }+ }+ fputcsv($handle, $row);}- }+ });+ // Close the output stream+ fclose($handle);+ }, 200, [+ 'Content-Type' => 'text/csv',+ 'Content-Disposition'+ => 'attachment; filename="custom-assets-report-'.date('Y-m-d-his').'.csv"',+ ]);++ return $response;- $rows[] = implode($row, ',');- }- // spit out a csv- if (array_filter($rows)) {- $csv = implode($rows, "\n");- $response = Response::make($csv, 200);- $response->header('Content-Type', 'text/csv');- $response->header('Content-disposition', 'attachment;filename='.date('Y-m-d-His').'-custom-asset-report.csv');-- return $response;- } else {- return redirect()->to("reports/custom")- ->with('error', trans('admin/reports/message.error'));- }}diff --git a/resources/views/partials/forms/edit/location-select.blade.php b/resources/views/partials/forms/edit/location-select.blade.phpindex 2214130d2b..ba67bb5166 100644--- a/resources/views/partials/forms/edit/location-select.blade.php+++ b/resources/views/partials/forms/edit/location-select.blade.php@@ -16,7 +16,9 @@<div class="col-md-1 col-sm-1 text-left">@can('create', \App\Models\Location::class)+ @if ((!isset($hide_new)) || ($hide_new!='true'))<a href='{{ route('modal.location') }}' data-toggle="modal" data-target="#createModal" data-dependency="location" data-select='{{ $fieldname }}_location_select' class="btn btn-sm btn-default">New</a>+ @endif@endcan</div>diff --git a/resources/views/partials/forms/edit/model-select.blade.php b/resources/views/partials/forms/edit/model-select.blade.phpindex 84e30f4a93..11917f2dc9 100644--- a/resources/views/partials/forms/edit/model-select.blade.php+++ b/resources/views/partials/forms/edit/model-select.blade.php@@ -3,7 +3,7 @@{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}- <div class="col-md-7 required">+ <div class="col-md-7{{ ((isset($required) && ($required =='true'))) ? ' required' : '' }}"><select class="js-data-ajax" data-endpoint="models" name="{{ $fieldname }}" style="width: 100%" id="model_select_id">@if ($model_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))<option value="{{ $model_id }}" selected="selected">@@ -17,8 +17,10 @@</div><div class="col-md-1 col-sm-1 text-left">@can('create', \App\Models\AssetModel::class)- <a href='{{ route('modal.model') }}' data-toggle="modal" data-target="#createModal" data-dependency="model" data-select='model_select_id' class="btn btn-sm btn-default">New</a>- <span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>+ @if ((!isset($hide_new)) || ($hide_new!='true'))+ <a href='{{ route('modal.model') }}' data-toggle="modal" data-target="#createModal" data-dependency="model" data-select='model_select_id' class="btn btn-sm btn-default">New</a>+ <span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>+ @endif@endcan</div>diff --git a/resources/views/partials/forms/edit/supplier-select.blade.php b/resources/views/partials/forms/edit/supplier-select.blade.phpindex e05f1ccbf9..3471210391 100644--- a/resources/views/partials/forms/edit/supplier-select.blade.php+++ b/resources/views/partials/forms/edit/supplier-select.blade.php@@ -16,7 +16,9 @@<div class="col-md-1 col-sm-1 text-left">@can('create', \App\Models\Supplier::class)- <a href='{{ route('modal.supplier') }}' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select' class="btn btn-sm btn-default">New</a>+ @if ((!isset($hide_new)) || ($hide_new!='true'))+ <a href='{{ route('modal.supplier') }}' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select' class="btn btn-sm btn-default">New</a>+ @endif@endcan</div>diff --git a/resources/views/partials/forms/edit/user-select.blade.php b/resources/views/partials/forms/edit/user-select.blade.phpindex e50fad084a..a4479799f0 100644--- a/resources/views/partials/forms/edit/user-select.blade.php+++ b/resources/views/partials/forms/edit/user-select.blade.php@@ -16,7 +16,9 @@<div class="col-md-1 col-sm-1 text-left">@can('create', \App\Models\User::class)- <a href='{{ route('modal.user') }}' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_user_select' class="btn btn-sm btn-default">New</a>+ @if ((!isset($hide_new)) || ($hide_new!='true'))+ <a href='{{ route('modal.user') }}' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_user_select' class="btn btn-sm btn-default">New</a>+ @endif@endcan</div>