From 0031fab0fe25132258f289013e84634097ae1dbc Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 27 Jan 2021 01:34:32 -0800 Subject: [PATCH] Added termination date, depreciation in license column selection [ch14505] (#9052) --- .../Controllers/Api/LicensesController.php | 23 +++++++++++++++++- app/Http/Transformers/LicensesTransformer.php | 2 ++ app/Models/License.php | 1 + app/Presenters/LicensePresenter.php | 21 +++++++++++++++- resources/views/licenses/view.blade.php | 24 ++++++++++++++----- 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 2a3d004d1f..bb6d9165a6 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -103,11 +103,32 @@ class LicensesController extends Controller case 'category': $licenses = $licenses->leftJoin('categories', 'licenses.category_id', '=', 'categories.id')->orderBy('categories.name', $order); break; + case 'depreciation': + $licenses = $licenses->leftJoin('depreciations', 'licenses.depreciation_id', '=', 'depreciations.id')->orderBy('depreciations.name', $order); + break; case 'company': $licenses = $licenses->leftJoin('companies', 'licenses.company_id', '=', 'companies.id')->orderBy('companies.name', $order); break; default: - $allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','company','category','license_name','license_email','free_seats_count','seats']; + $allowed_columns = + [ + 'id', + 'name', + 'purchase_cost', + 'expiration_date', + 'purchase_order', + 'order_number', + 'notes', + 'purchase_date', + 'serial', + 'company', + 'category', + 'license_name', + 'license_email', + 'free_seats_count', + 'seats', + 'termination_date', + ]; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $licenses = $licenses->orderBy($sort, $order); break; diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.php index dfce3d42b4..48d5152688 100644 --- a/app/Http/Transformers/LicensesTransformer.php +++ b/app/Http/Transformers/LicensesTransformer.php @@ -29,6 +29,8 @@ class LicensesTransformer 'order_number' => e($license->order_number), 'purchase_order' => e($license->purchase_order), 'purchase_date' => Helper::getFormattedDateObject($license->purchase_date, 'date'), + 'termination_date' => Helper::getFormattedDateObject($license->termination_date, 'date'), + 'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null, 'purchase_cost' => e($license->purchase_cost), 'notes' => e($license->notes), 'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'), diff --git a/app/Models/License.php b/app/Models/License.php index 649eb063f5..8f0fbdfaab 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -108,6 +108,7 @@ class License extends Depreciable 'manufacturer' => ['name'], 'company' => ['name'], 'category' => ['name'], + 'depreciation' => ['name'], ]; /** diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.php index 520b27e13f..be5a600c4f 100644 --- a/app/Presenters/LicensePresenter.php +++ b/app/Presenters/LicensePresenter.php @@ -97,7 +97,26 @@ class LicensePresenter extends Presenter "visible" => false, "title" => trans('general.purchase_date'), 'formatter' => 'dateDisplayFormatter' - ], [ + ], + [ + "field" => "termination_date", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('admin/licenses/form.termination_date'), + 'formatter' => 'dateDisplayFormatter' + ], + [ + "field" => "depreciation", + "searchable" => true, + "sortable" => true, + "switchable" => true, + "title" => trans('admin/hardware/form.depreciation'), + "visible" => false, + "formatter" => "depreciationsLinkObjFormatter", + ], + + [ "field" => "maintained", "searchable" => false, "sortable" => true, diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php index c5e201e11d..a578efc0a3 100755 --- a/resources/views/licenses/view.blade.php +++ b/resources/views/licenses/view.blade.php @@ -167,11 +167,24 @@
- {{ $license->expiration_date }} + {{ \App\Helpers\Helper::getFormattedDateObject($license->expiration_date, 'date', false) }}
@endif + @if ($license->termination_date) +
+
+ + {{ trans('admin/licenses/form.termination_date') }} + +
+
+ {{ \App\Helpers\Helper::getFormattedDateObject($license->termination_date, 'date', false) }} +
+
+ @endif + @if ($license->depreciation)
@@ -188,8 +201,6 @@
- -
@@ -197,7 +208,7 @@
- {{ $license->depreciated_date()->format("Y-m-d") }} + {{ \App\Helpers\Helper::getFormattedDateObject($license->depreciated_date(), 'date', false) }}
@@ -233,13 +244,14 @@ @endif - @if (isset($license->purchase_date)) + @if (isset($license->purchase_date))
{{ trans('general.purchase_date') }}
- {{ $license->purchase_date }} + {{ \App\Helpers\Helper::getFormattedDateObject($license->purchase_date, 'date', false) }} +
@endif