diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 47eaf6c56..928433f2a 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -29,7 +29,7 @@ class LicensesController extends Controller $offset = request('offset', 0); $limit = request('limit', 50); - $allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company']; + $allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company','license_name','license_email']; $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; @@ -45,7 +45,6 @@ class LicensesController extends Controller break; } - $total = $licenses->count(); $licenses = $licenses->skip($offset)->take($limit)->get(); return (new LicensesTransformer)->transformLicenses($licenses, $total); diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.php index 55305709d..a66b32f96 100644 --- a/app/Http/Transformers/LicensesTransformer.php +++ b/app/Http/Transformers/LicensesTransformer.php @@ -4,6 +4,7 @@ namespace App\Http\Transformers; use App\Models\License; use Gate; use Illuminate\Database\Eloquent\Collection; +use App\Helpers\Helper; class LicensesTransformer { @@ -22,21 +23,23 @@ class LicensesTransformer $array = [ 'id' => $license->id, 'name' => e($license->name), - 'company' => e($license->company->name), - 'manufacturer' => ($license->manufacturer) ? $license->manufacturer : null, - 'serial' => e($license->name), - 'purchase_order' => e($license->order_number), + 'company' => ($license->company) ? ['id' => $license->company->id,'name'=> e($license->company->name)] : null, + 'manufacturer' => ($license->manufacturer) ? ['id' => $license->manufacturer->id,'name'=> e($license->manufacturer->name)] : null, + 'product_key' => e($license->serial), + 'order_number' => e($license->order_number), + 'purchase_order' => e($license->purchase_order), 'purchase_date' => e($license->purchase_date), 'purchase_cost' => e($license->purchase_cost), - 'depreciation' => ($license->depreciation) ? $license->depreciation : null, + 'depreciation' => ($license->depreciation) ? ['id' => $license->depreciation->id,'name'=> e($license->depreciation->name)] : null, 'notes' => e($license->notes), 'expiration_date' => e($license->expiration_date), - 'totalSeats' => e($license->seats), - 'remaining' => $license->remaincount(), - 'license_name' => e($license->license_name), + 'total_seats' => e($license->seats), + 'remaining_qty' => $license->remaincount(), + 'min_qty' => $license->remaincount(), + 'license_name' => Helper::formatCurrencyOutput($license->purchase_cost), 'license_email' => e($license->license_email), 'maintained' => ($license->maintained == 1) ? true : false, - 'supplier' => ($license->supplier) ? $license->supplier : null, + 'supplier' => ($license->supplier) ? ['id' => $license->supplier->id,'name'=> e($license->supplier->name)] : null, 'created_at' => $license->created_at, ]; diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php index 2319973f5..d028f18f5 100644 --- a/app/Presenters/AccessoryPresenter.php +++ b/app/Presenters/AccessoryPresenter.php @@ -25,6 +25,13 @@ class AccessoryPresenter extends Presenter { $layout = [ [ + "field" => "id", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.id'), + "visible" => false + ], [ "field" => "company", "searchable" => true, "sortable" => true, diff --git a/app/Presenters/AssetModelPresenter.php b/app/Presenters/AssetModelPresenter.php index 6da4cbeba..7011a7203 100644 --- a/app/Presenters/AssetModelPresenter.php +++ b/app/Presenters/AssetModelPresenter.php @@ -16,49 +16,7 @@ use App\Helpers\Helper; */ class AssetModelPresenter extends Presenter { - /** - * JSON representation of Accessory for datatable. - * @return array - */ - public function forDataTable() - { - - $actions = '
'; - if ($this->deleted_at == '') { - $actions .= Helper::generateDatatableButton('clone', route('clone/model', $this->id)); - $actions .= Helper::generateDatatableButton('edit', route('models.edit', $this->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('models.destroy', $this->id), - trans('admin/models/message.delete.confirm'), - $this->name - ); - } else { - $actions .= Helper::generateDatatableButton('restore', route('restore/model', $this->id)); - } - $actions .="
"; - - $results = []; - - $results['id'] = $this->id; - $results['manufacturer'] = $this->manufacturerUrl(); - $results['name'] = $this->nameUrl(); - $results['image'] = $this->imageUrl(); - $results['model_number'] = $this->model_number; - $results['numassets'] = $this->assets()->count(); - $results['depreciation'] = trans('general.no_depreciation'); - if (($depreciation = $this->model->depreciation) and $depreciation->id > 0) { - $results['depreciation'] = $depreciation->name.' ('.$depreciation->months.')'; - } - $results['category'] = $this->categoryUrl(); - $results['eol'] = $this->eolText(); - $results['note'] = $this->note(); - $results['fieldset'] = $this->model->fieldset ? link_to_route('custom_fields/model', $this->model->fieldset->name, $this->model->fieldset->id) : ''; - $results['actions'] = $actions; - - return $results; - } - + /** * Formatted note for this model * @return string diff --git a/app/Presenters/CategoryPresenter.php b/app/Presenters/CategoryPresenter.php index d3dbef215..fa93d525e 100644 --- a/app/Presenters/CategoryPresenter.php +++ b/app/Presenters/CategoryPresenter.php @@ -10,31 +10,6 @@ use App\Helpers\Helper; */ class CategoryPresenter extends Presenter { - /** - * JSON representation of category for datatable. - * @return array - */ - public function forDataTable() - { - $actions = Helper::generateDatatableButton('edit', route('categories.edit', $this->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('categories.destroy', $this->id), - $this->itemCount() == 0, /* enabled */ - trans('admin/categories/message.delete.confirm'), - $this->name - ); - $results = []; - $results['id'] = $this->id; - $results['name'] = $this->nameUrl(); - $results['category_type'] = ucwords($this->category_type); - $results['count'] = $this->itemCount(); - $results['acceptance'] = ($this->require_acceptance == '1') ? '' : ''; - $results['eula'] = $this->getEula() ? '' : ''; - $results['actions'] = $actions; - - return $results; - } /** * Link to this categories name diff --git a/app/Presenters/DepreciationPresenter.php b/app/Presenters/DepreciationPresenter.php index c4e6c747a..c6b17c634 100644 --- a/app/Presenters/DepreciationPresenter.php +++ b/app/Presenters/DepreciationPresenter.php @@ -10,28 +10,5 @@ use App\Helpers\Helper; */ class DepreciationPresenter extends Presenter { - /** - * Formatted JSON representation of this Depreciation - * @return array - */ - public function forDataTable() - { - $actions = Helper::generateDatatableButton('edit', route('depreciations.edit', $this->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('depreciations.destroy', $this->id), - true, /*enabled*/ - trans('admin/depreciations/message.delete.confirm'), - $this->name - ); - $results = [ - 'id' => $this->id, - 'name' => $this->name, - 'months' => $this->months, - 'actions' => $actions - ]; - - return $results; - } } diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.php index 7d6153a68..ba265b5c1 100644 --- a/app/Presenters/LicensePresenter.php +++ b/app/Presenters/LicensePresenter.php @@ -12,60 +12,108 @@ use Illuminate\Support\Facades\Gate; class LicensePresenter extends Presenter { /** - * JSON representation of this license for data table. - * @return array + * Json Column Layout for bootstrap table + * @return string */ - public function forDataTable() + public static function dataTableLayout() { - $actions = ''; - - if (Gate::allows('checkout', License::class)) { - $actions .= Helper::generateDatatableButton( - 'checkout', - route('licenses.freecheckout', $this->id), - $this->remaincount() > 0 - ); - } - - if (Gate::allows('create', $this->model)) { - $actions .= Helper::generateDatatableButton('clone', route('clone/license', $this->id)); - } - if (Gate::allows('update', $this->model)) { - $actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $this->id)); - } - if (Gate::allows('delete', $this->model)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('licenses.destroy', $this->id), - true, /*enabled*/ - trans('admin/licenses/message.delete.confirm'), - $this->name - ); - } - $actions .=''; - - $results = [ - 'actions' => $actions, - 'company' => $this->companyUrl(), - 'expiration_date' => $this->expiration_date, - 'id' => $this->id, - 'license_email' => $this->license_email, - 'license_name' => $this->license_name, - 'manufacturer' => $this->manufacturerUrl(), - 'name' => $this->nameUrl(), - 'notes' => $this->notes, - 'order_number' => $this->order_number, - 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost), - 'purchase_date' => $this->purchase_date, - 'purchase_order' => $this->purchase_order, - 'remaining' => $this->remaincount(), - 'serial' => $this->serialUrl(), - 'totalSeats' => $this->model->licenseSeatsCount, + $layout = [ + [ + "field" => "id", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.id'), + "visible" => false + ], [ + "field" => "company", + "searchable" => true, + "sortable" => true, + "switchable" => true, + "title" => trans('admin/companies/table.title'), + "visible" => false, + "formatter" => "companiesLinkObjFormatter" + ], [ + "field" => "name", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/licenses/table.title'), + "formatter" => "licensesLinkFormatter" + ], [ + "field" => "product_key", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/licenses/form.license_key'), + "formatter" => "licensesLinkFormatter" + ], [ + "field" => "expiration_date", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/licenses/form.expiration') + ], [ + "field" => "license_email", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/licenses/form.to_email') + ], [ + "field" => "license_name", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/licenses/form.to_name'), + ], [ + "field" => "manufacturer", + "searchable" => true, + "sortable" => true, + "title" => trans('general.manufacturer'), + "formatter" => "manufacturersLinkObjFormatter", + ], [ + "field" => "total_seats", + "searchable" => false, + "sortable" => false, + "title" => trans('admin/accessories/general.total'), + ], [ + "field" => "remaining_qty", + "searchable" => false, + "sortable" => false, + "title" => trans('admin/accessories/general.remaining'), + ], [ + "field" => "purchase_date", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.purchase_date'), + ], [ + "field" => "purchase_cost", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.purchase_cost'), + ], [ + "field" => "purchase_order", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('admin/licenses/form.purchase_order'), + ], [ + "field" => "order_number", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.order_number'), + ], [ + "field" => "actions", + "searchable" => false, + "sortable" => false, + "switchable" => false, + "title" => trans('table.actions'), + "formatter" => "licensesActionsFormatter", + ] ]; - return $results; + return json_encode($layout); } + /** * Link to this licenses Name * @return string diff --git a/app/Presenters/LocationPresenter.php b/app/Presenters/LocationPresenter.php index ee364fe0a..fdf1a23e8 100644 --- a/app/Presenters/LocationPresenter.php +++ b/app/Presenters/LocationPresenter.php @@ -10,41 +10,6 @@ use App\Helpers\Helper; */ class LocationPresenter extends Presenter { - /** - * JSON representation of this location for data table. - * @return array - */ - public function forDataTable() - { - $actions = ''; - $actions .= Helper::generateDatatableButton('edit', route('locations.edit', $this->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('locations.destroy', $this->id), - true, /*enabled*/ - trans('admin/locations/message.delete.confirm'), - $this->name - ); - $actions .= ''; - - $results = [ - 'actions' => $actions, - 'address' => $this->address, - 'assets_checkedout' => $this->model->assets()->count(), - 'assets_default' => $this->model->assignedassets()->count(), - 'city' => $this->city, - 'country' => $this->country, - 'currency' => $this->currency, - 'id' => $this->id, - 'name' => $this->nameUrl(), - 'parent' => ($this->model->parent) ? $this->model->parent->present()->nameUrl() : '', - 'state' => $this->state, - 'zip' => $this->zip, - // 'assets' => ($this->assets->count() + $this->assignedassets->count()), - ]; - - return $results; - } /** * Link to this locations name diff --git a/app/Presenters/ManufacturerPresenter.php b/app/Presenters/ManufacturerPresenter.php index ab4cc7ad2..1de661fac 100644 --- a/app/Presenters/ManufacturerPresenter.php +++ b/app/Presenters/ManufacturerPresenter.php @@ -11,35 +11,6 @@ use App\Helpers\Helper; class ManufacturerPresenter extends Presenter { - /** - * JSON representation of this manufacturer for data table. - * @return array - */ - public function forDataTable() - { - $actions = ''; - $actions .= Helper::generateDatatableButton('edit', route('manufacturers.edit', $this->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('manufacturers.destroy', $this->id), - true, /*enabled*/ - trans('admin/manufacturers/message.delete.confirm'), - $this->name - ); - $actions .= ''; - - $results = [ - 'accessories' => $this->accessories()->count(), - 'actions' => $actions, - 'assets' => $this->assets()->count(), - 'consumables' => $this->consumables()->count(), - 'id' => $this->id, - 'licenses' => $this->licenses()->count(), - 'name' => $this->nameUrl(), - ]; - - return $results; - } /** * Link to this manufacturers name diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index 128182b76..9c0593c0d 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -35,7 +35,7 @@ class UserPresenter extends Presenter "field" => "id", "searchable" => true, "sortable" => true, - "switchable" => true, + "switchable" => false, "title" => trans('general.id'), "visible" => false, "formatter" => null diff --git a/resources/views/licenses/index.blade.php b/resources/views/licenses/index.blade.php index f1e9f7ccc..683ca2eb1 100755 --- a/resources/views/licenses/index.blade.php +++ b/resources/views/licenses/index.blade.php @@ -31,28 +31,6 @@ data-cookie="true" data-click-to-select="true" data-cookie-id-table="licenseTable"> - - - - {{ trans('general.id') }} - {{ trans('general.company') }} - {{ trans('admin/licenses/table.title') }} - {{ trans('general.manufacturer') }} - {{ trans('admin/licenses/form.license_key') }} - {{ trans('admin/licenses/form.to_name') }} - {{ trans('admin/licenses/form.to_email') }} - {{ trans('admin/licenses/form.seats') }} - {{ trans('admin/licenses/form.remaining_seats') }} - {{ trans('general.purchase_date') }} - {{ trans('general.purchase_cost') }} - {{ trans('admin/licenses/form.purchase_order') }} - {{ trans('admin/licenses/form.expiration') }} - {{ trans('general.created_at') }} - {{ trans('admin/hardware/form.notes') }} - - {{ trans('table.actions') }} - - @@ -64,6 +42,9 @@ @stop @section('moar_scripts') -@include ('partials.bootstrap-table', ['exportFile' => 'licenses-export', 'search' => true]) +@include ('partials.bootstrap-table', [ + 'exportFile' => 'licenses-export', + 'search' => true, + 'columns' => \App\Presenters\LicensePresenter::dataTableLayout()]) @stop