From 8dbd9fb299899ce5ebbf5f6f47563b9fae397e8a Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 11 Mar 2017 12:14:10 -0800 Subject: [PATCH] Added additional permissions for checkin/checkout buttons --- .../Transformers/AccessoriesTransformer.php | 8 +- app/Http/Transformers/AssetsTransformer.php | 2 +- .../ComponentsAssetsTransformer.php | 4 +- .../Transformers/ConsumablesTransformer.php | 6 + app/Presenters/AccessoryPresenter.php | 7 + app/Presenters/ConsumablePresenter.php | 123 ++++++++++++++++++ 6 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 app/Presenters/ConsumablePresenter.php diff --git a/app/Http/Transformers/AccessoriesTransformer.php b/app/Http/Transformers/AccessoriesTransformer.php index 8eadedd407..a3c03f60bf 100644 --- a/app/Http/Transformers/AccessoriesTransformer.php +++ b/app/Http/Transformers/AccessoriesTransformer.php @@ -42,11 +42,17 @@ class AccessoriesTransformer $permissions_array['available_actions'] = [ 'checkout' => Gate::allows('checkout', Accessory::class) ? true : false, - 'checkin' => Gate::allows('checkin', Accessory::class) ? true : false, + 'checkin' => false, 'update' => Gate::allows('update', Accessory::class) ? true : false, 'delete' => Gate::allows('delete', Accessory::class) ? true : false, ]; + $permissions_array['user_can_checkout'] = false; + + if ($accessory->numRemaining() > 0) { + $permissions_array['user_can_checkout'] = true; + } + $array += $permissions_array; return $array; diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index 826b3751d2..d8cabc8f77 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -49,7 +49,7 @@ class AssetsTransformer 'last_checkout' => Helper::getFormattedDateObject($asset->last_checkout, 'datetime'), 'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'), 'purchase_cost' => $asset->purchase_cost, - 'can_checkout' => $asset->availableForCheckout(), + 'user_can_checkout' => $asset->availableForCheckout(), ]; diff --git a/app/Http/Transformers/ComponentsAssetsTransformer.php b/app/Http/Transformers/ComponentsAssetsTransformer.php index 65054b4209..f8a169ca32 100644 --- a/app/Http/Transformers/ComponentsAssetsTransformer.php +++ b/app/Http/Transformers/ComponentsAssetsTransformer.php @@ -26,7 +26,7 @@ class ComponentsAssetsTransformer 'name' => e($asset->name), 'created_at' => $asset->created_at->format('Y-m-d'), 'qty' => $asset->components()->count(), - 'can_checkout' => $asset->availableForCheckout(), + 'user_can_checkout' => $asset->availableForCheckout(), ]; $permissions_array['available_actions'] = [ @@ -36,6 +36,8 @@ class ComponentsAssetsTransformer 'delete' => Gate::allows('delete', Asset::class) ? true : false, ]; + + $array += $permissions_array; if ($asset->model->fieldset) { diff --git a/app/Http/Transformers/ConsumablesTransformer.php b/app/Http/Transformers/ConsumablesTransformer.php index 3c98d67982..0511b0ff53 100644 --- a/app/Http/Transformers/ConsumablesTransformer.php +++ b/app/Http/Transformers/ConsumablesTransformer.php @@ -39,6 +39,12 @@ class ConsumablesTransformer 'updated_at' => Helper::getFormattedDateObject($consumable->updated_at, 'datetime'), ]; + $permissions_array['user_can_checkout'] = false; + + if ($consumable->numRemaining() > 0) { + $permissions_array['user_can_checkout'] = true; + } + $permissions_array['available_actions'] = [ 'checkout' => Gate::allows('checkout', Consumable::class) ? true : false, 'checkin' => Gate::allows('checkin', Consumable::class) ? true : false, diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php index 681db50833..6a8821a2fb 100644 --- a/app/Presenters/AccessoryPresenter.php +++ b/app/Presenters/AccessoryPresenter.php @@ -102,6 +102,13 @@ class AccessoryPresenter extends Presenter "sortable" => true, "visible" => false, "title" => trans('general.order_number'), + ],[ + "field" => "change", + "searchable" => false, + "sortable" => false, + "visible" => true, + "title" => trans('general.change'), + "formatter" => "accessoriesInOutFormatter", ], [ "field" => "actions", "searchable" => false, diff --git a/app/Presenters/ConsumablePresenter.php b/app/Presenters/ConsumablePresenter.php new file mode 100644 index 0000000000..40ba6703f1 --- /dev/null +++ b/app/Presenters/ConsumablePresenter.php @@ -0,0 +1,123 @@ + "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" => 'companiesLinkObjFormatter', + ], + [ + "field" => "name", + "searchable" => true, + "sortable" => true, + "title" => trans('general.name'), + "visible" => true, + "formatter" => 'componentsLinkFormatter', + ], [ + "field" => "category", + "searchable" => true, + "sortable" => true, + "title" => trans('general.category'), + "formatter" => "categoriesLinkObjFormatter" + ],[ + "field" => "item_no", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/consumables/general.item_no') + ], [ + "field" => "qty", + "searchable" => false, + "sortable" => false, + "title" => trans('admin/components/general.total'), + "visible" => true, + ], [ + "field" => "remaining", + "searchable" => false, + "sortable" => false, + "title" => trans('admin/components/general.remaining'), + "visible" => true, + ], [ + "field" => "min_amt", + "searchable" => false, + "sortable" => false, + "title" => trans('general.min_amt'), + "visible" => true, + ], [ + "field" => "order_number", + "searchable" => true, + "sortable" => true, + "title" => trans('general.order_number'), + "visible" => true, + ],[ + "field" => "purchase_date", + "searchable" => true, + "sortable" => true, + "title" => trans('general.purchase_date'), + "visible" => true, + "formatter" => "dateDisplayFormatter", + ],[ + "field" => "purchase_cost", + "searchable" => true, + "sortable" => true, + "title" => trans('general.purchase_cost'), + "visible" => true, + ],[ + "field" => "change", + "searchable" => false, + "sortable" => false, + "visible" => true, + "title" => trans('general.change'), + "formatter" => "consumablesInOutFormatter", + ], [ + "field" => "actions", + "searchable" => false, + "sortable" => false, + "switchable" => false, + "title" => trans('table.actions'), + "visible" => true, + "formatter" => "consumablesActionsFormatter", + ] + ]; + + return json_encode($layout); + } + + /** + * Url to view this item. + * @return string + */ + public function viewUrl() + { + return route('consumables.show', $this->id); + } + + +}