From 05a85c628f8ebc10714a17cccceb46f0125486e1 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 5 May 2019 19:20:17 -0400 Subject: [PATCH] Added audit presenter --- app/Presenters/AssetAuditPresenter.php | 273 +++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 app/Presenters/AssetAuditPresenter.php diff --git a/app/Presenters/AssetAuditPresenter.php b/app/Presenters/AssetAuditPresenter.php new file mode 100644 index 0000000000..bfc917eea5 --- /dev/null +++ b/app/Presenters/AssetAuditPresenter.php @@ -0,0 +1,273 @@ + "id", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.id'), + "visible" => false + ], [ + "field" => "company", + "searchable" => true, + "sortable" => true, + "switchable" => true, + "title" => trans('general.company'), + "visible" => false, + "formatter" => 'assetCompanyObjFilterFormatter' + ], [ + "field" => "name", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/hardware/form.name'), + "visible" => true, + "formatter" => "hardwareLinkFormatter" + ], [ + "field" => "image", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('admin/hardware/table.image'), + "visible" => false, + "formatter" => "imageFormatter" + ], [ + "field" => "asset_tag", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/hardware/table.asset_tag'), + "visible" => true, + "formatter" => "hardwareLinkFormatter" + ], [ + "field" => "serial", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/hardware/form.serial'), + "visible" => true, + "formatter" => "hardwareLinkFormatter" + ], [ + "field" => "model", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/hardware/form.model'), + "visible" => true, + "formatter" => "modelsLinkObjFormatter" + ], [ + "field" => "model_number", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/models/table.modelnumber'), + "visible" => false + ], [ + "field" => "category", + "searchable" => true, + "sortable" => true, + "title" => trans('general.category'), + "visible" => false, + "formatter" => "categoriesLinkObjFormatter" + ], [ + "field" => "status_label", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/hardware/table.status'), + "visible" => true, + "formatter" => "statuslabelsLinkObjFormatter" + ], [ + "field" => "assigned_to", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/hardware/form.checkedout_to'), + "visible" => true, + "formatter" => "polymorphicItemFormatter" + ], [ + "field" => "location", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/hardware/table.location'), + "visible" => true, + "formatter" => "deployedLocationFormatter" + ], [ + "field" => "rtd_location", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/hardware/form.default_location'), + "visible" => false, + "formatter" => "deployedLocationFormatter" + ], [ + "field" => "manufacturer", + "searchable" => true, + "sortable" => true, + "title" => trans('general.manufacturer'), + "visible" => false, + "formatter" => "manufacturersLinkObjFormatter" + ], [ + "field" => "purchase_date", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.purchase_date'), + "formatter" => "dateDisplayFormatter" + ], [ + "field" => "purchase_cost", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.purchase_cost'), + "footerFormatter" => 'sumFormatter', + ], [ + "field" => "order_number", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.order_number'), + 'formatter' => "orderNumberObjFilterFormatter" + ], [ + "field" => "eol", + "searchable" => false, + "sortable" => false, + "visible" => false, + "title" => trans('general.eol'), + "formatter" => "dateDisplayFormatter" + ], [ + "field" => "warranty_months", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('admin/hardware/form.warranty') + ],[ + "field" => "warranty_expires", + "searchable" => false, + "sortable" => false, + "visible" => false, + "title" => trans('admin/hardware/form.warranty_expires'), + "formatter" => "dateDisplayFormatter" + ],[ + "field" => "notes", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.notes'), + + ], [ + "field" => "checkout_counter", + "searchable" => false, + "sortable" => true, + "visible" => false, + "title" => trans('general.checkouts_count') + + ],[ + "field" => "checkin_counter", + "searchable" => false, + "sortable" => true, + "visible" => false, + "title" => trans('general.checkins_count') + + ], [ + "field" => "requests_counter", + "searchable" => false, + "sortable" => true, + "visible" => false, + "title" => trans('general.user_requests_count') + + ], [ + "field" => "created_at", + "searchable" => false, + "sortable" => true, + "visible" => false, + "title" => trans('general.created_at'), + "formatter" => "dateDisplayFormatter" + ], [ + "field" => "updated_at", + "searchable" => false, + "sortable" => true, + "visible" => false, + "title" => trans('general.updated_at'), + "formatter" => "dateDisplayFormatter" + ], [ + "field" => "last_checkout", + "searchable" => false, + "sortable" => true, + "visible" => false, + "title" => trans('admin/hardware/table.checkout_date'), + "formatter" => "dateDisplayFormatter" + ], [ + "field" => "expected_checkin", + "searchable" => false, + "sortable" => true, + "visible" => false, + "title" => trans('admin/hardware/form.expected_checkin'), + "formatter" => "dateDisplayFormatter" + ], [ + "field" => "last_audit_date", + "searchable" => false, + "sortable" => true, + "visible" => true, + "title" => trans('general.last_audit'), + "formatter" => "dateDisplayFormatter" + ], [ + "field" => "next_audit_date", + "searchable" => false, + "sortable" => true, + "visible" => true, + "title" => trans('general.next_audit_date'), + "formatter" => "dateDisplayFormatter" + ], + ]; + + // This looks complicated, but we have to confirm that the custom fields exist in custom fieldsets + // *and* those fieldsets are associated with models, otherwise we'll trigger + // javascript errors on the bootstrap tables side of things, since we're asking for properties + // on fields that will never be passed through the REST API since they're not associated with + // models. We only pass the fieldsets that pertain to each asset (via their model) so that we + // don't junk up the REST API with tons of custom fields that don't apply + + $fields = CustomField::whereHas('fieldset', function ($query) { + $query->whereHas('models'); + })->get(); + + foreach ($fields as $field) { + $layout[] = [ + "field" => 'custom_fields.'.$field->convertUnicodeDbSlug(), + "searchable" => true, + "sortable" => true, + "visible" => false, + "switchable" => true, + "title" => ($field->field_encrypted=='1') ?' '.e($field->name) : e($field->name), + "formatter" => "customFieldsFormatter" + ]; + + } + + + $layout[] = [ + "field" => "actions", + "searchable" => false, + "sortable" => false, + "switchable" => false, + "title" => trans('table.actions'), + "formatter" => "hardwareAuditFormatter", + ]; + + return json_encode($layout); + } + + + +}