From 31fa0a7044a773a24b85c49aab8b20c65febc9db Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:04:32 +0000 Subject: [PATCH 01/12] Removed logging Signed-off-by: snipe --- app/Http/Controllers/Licenses/LicensesController.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.php index 02e2163207..a818cf4231 100755 --- a/app/Http/Controllers/Licenses/LicensesController.php +++ b/app/Http/Controllers/Licenses/LicensesController.php @@ -245,12 +245,6 @@ class LicensesController extends Controller $available_seats_count = $license->availCount()->count(); $checkedout_seats_count = ($total_seats_count - $available_seats_count); - \Log::debug('Total: '.$total_seats_count); - \Log::debug('Users: '.$users_count); - \Log::debug('Available: '.$available_seats_count); - \Log::debug('Checkedout: '.$checkedout_seats_count); - - $this->authorize('view', $license); return view('licenses.view', compact('license')) ->with('users_count', $users_count) From 9efbcbbd5eec977e4ca4588b9beacba62b592e22 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:04:42 +0000 Subject: [PATCH 02/12] Added min_amt to licenses Signed-off-by: snipe --- app/Http/Controllers/Licenses/LicensesController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.php index a818cf4231..c55181c518 100755 --- a/app/Http/Controllers/Licenses/LicensesController.php +++ b/app/Http/Controllers/Licenses/LicensesController.php @@ -99,6 +99,7 @@ class LicensesController extends Controller $license->category_id = $request->input('category_id'); $license->termination_date = $request->input('termination_date'); $license->user_id = Auth::id(); + $license->min_amt = $request->input('min_amt'); if ($license->save()) { return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.create.success')); @@ -176,6 +177,7 @@ class LicensesController extends Controller $license->manufacturer_id = $request->input('manufacturer_id'); $license->supplier_id = $request->input('supplier_id'); $license->category_id = $request->input('category_id'); + $license->min_amt = $request->input('min_amt'); if ($license->save()) { return redirect()->route('licenses.show', ['license' => $licenseId])->with('success', trans('admin/licenses/message.update.success')); From dff7c43aed4a5fa2ae22698b43c1b5887732a82f Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:05:02 +0000 Subject: [PATCH 03/12] Added minimum account check for licenses Signed-off-by: snipe --- app/Helpers/Helper.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 60474701cc..0f3e271756 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -11,6 +11,7 @@ use App\Models\CustomFieldset; use App\Models\Depreciation; use App\Models\Setting; use App\Models\Statuslabel; +use App\Models\License; use Crypt; use Illuminate\Contracts\Encryption\DecryptException; use Image; @@ -715,18 +716,19 @@ class Helper */ public static function checkLowInventory() { + $alert_threshold = \App\Models\Setting::getSettings()->alert_threshold; $consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get(); $accessories = Accessory::withCount('users as users_count')->whereNotNull('min_amt')->get(); $components = Component::whereNotNull('min_amt')->get(); $asset_models = AssetModel::where('min_amt', '>', 0)->get(); + $licenses = License::where('min_amt', '>', 0)->get(); - $avail_consumables = 0; $items_array = []; $all_count = 0; foreach ($consumables as $consumable) { $avail = $consumable->numRemaining(); - if ($avail < ($consumable->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) { + if ($avail < ($consumable->min_amt) + $alert_threshold) { if ($consumable->qty > 0) { $percent = number_format((($avail / $consumable->qty) * 100), 0); } else { @@ -745,7 +747,7 @@ class Helper foreach ($accessories as $accessory) { $avail = $accessory->qty - $accessory->users_count; - if ($avail < ($accessory->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) { + if ($avail < ($accessory->min_amt) + $alert_threshold) { if ($accessory->qty > 0) { $percent = number_format((($avail / $accessory->qty) * 100), 0); } else { @@ -764,7 +766,7 @@ class Helper foreach ($components as $component) { $avail = $component->numRemaining(); - if ($avail < ($component->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) { + if ($avail < ($component->min_amt) + $alert_threshold) { if ($component->qty > 0) { $percent = number_format((($avail / $component->qty) * 100), 0); } else { @@ -787,7 +789,7 @@ class Helper $total_owned = $asset->where('model_id', '=', $asset_model->id)->count(); $avail = $asset->where('model_id', '=', $asset_model->id)->whereNull('assigned_to')->count(); - if ($avail < ($asset_model->min_amt)+ \App\Models\Setting::getSettings()->alert_threshold) { + if ($avail < ($asset_model->min_amt) + $alert_threshold) { if ($avail > 0) { $percent = number_format((($avail / $total_owned) * 100), 0); } else { @@ -803,6 +805,26 @@ class Helper } } + foreach ($licenses as $license){ + $avail = $license->remaincount(); + if ($avail < ($license->min_amt) + $alert_threshold) { + if ($avail > 0) { + $percent = number_format((($avail / $license->min_amt) * 100), 0); + } else { + $percent = 100; + } + + $items_array[$all_count]['id'] = $license->id; + $items_array[$all_count]['name'] = $license->name; + $items_array[$all_count]['type'] = 'licenses'; + $items_array[$all_count]['percent'] = $percent; + $items_array[$all_count]['remaining'] = $avail; + $items_array[$all_count]['min_amt'] = $license->min_amt; + $all_count++; + } + + } + return $items_array; } From 92b7c4b5ec6d1d89989fed2d626aca43b38cff08 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:05:13 +0000 Subject: [PATCH 04/12] Allow sorting on min_amt Signed-off-by: snipe --- app/Http/Controllers/Api/LicensesController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index d456e3cd64..c35b669d70 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -136,6 +136,7 @@ class LicensesController extends Controller 'seats', 'termination_date', 'depreciation_id', + 'min_amt', ]; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $licenses = $licenses->orderBy($sort, $order); From d0d29e03dbce2db7886f5c76a80b01f08a2464ab Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:06:01 +0000 Subject: [PATCH 05/12] Migration for min_amt on licenses Signed-off-by: snipe --- ...4_02_28_093807_add_min_qty_to_licenses.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 database/migrations/2024_02_28_093807_add_min_qty_to_licenses.php diff --git a/database/migrations/2024_02_28_093807_add_min_qty_to_licenses.php b/database/migrations/2024_02_28_093807_add_min_qty_to_licenses.php new file mode 100644 index 0000000000..0cdfa1f875 --- /dev/null +++ b/database/migrations/2024_02_28_093807_add_min_qty_to_licenses.php @@ -0,0 +1,34 @@ +integer('min_amt')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('licenses', function (Blueprint $table) { + if (Schema::hasColumn('licenses', 'min_amt')) { + $table->dropColumn('min_amt'); + } + }); + } +} From 3ccc55a78f840cdc0b9bf80305cdcfe17a6963b1 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:06:50 +0000 Subject: [PATCH 06/12] Added license min amt formatter for BS table Signed-off-by: snipe --- .../views/partials/bootstrap-table.blade.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index c39b1bd808..a895841023 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -621,6 +621,22 @@ return frags.join(' '); } + // Show the warning if below min qty + function minAmtFormatter(row, value) { + + if ((row) && (row!=undefined)) { + console.log(row.free_seats_count); + console.log(row.min_amt); + + if (value.free_seats_count <= value.min_amt) { + return '' + value.min_amt + ''; + } + + return value.min_amt + } + + } + // Create a linked phone number in the table list function phoneFormatter(value) { From 4ffb7790df1a16b6bbd1a34d3163fa3a4aa318ed Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:07:18 +0000 Subject: [PATCH 07/12] Added min_amt to API transformer/presenter Signed-off-by: snipe --- app/Http/Transformers/LicensesTransformer.php | 9 +++++---- app/Presenters/LicensePresenter.php | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.php index f68ad738d8..fa218da4d1 100644 --- a/app/Http/Transformers/LicensesTransformer.php +++ b/app/Http/Transformers/LicensesTransformer.php @@ -27,8 +27,8 @@ class LicensesTransformer 'company' => ($license->company) ? ['id' => (int) $license->company->id, 'name'=> e($license->company->name)] : null, 'manufacturer' => ($license->manufacturer) ? ['id' => (int) $license->manufacturer->id, 'name'=> e($license->manufacturer->name)] : null, 'product_key' => (Gate::allows('viewKeys', License::class)) ? e($license->serial) : '------------', - 'order_number' => e($license->order_number), - 'purchase_order' => e($license->purchase_order), + 'order_number' => ($license->order_number) ? e($license->order_number) : null, + 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : null, '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, @@ -38,8 +38,9 @@ class LicensesTransformer 'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'), 'seats' => (int) $license->seats, 'free_seats_count' => (int) $license->free_seats_count, - 'license_name' => e($license->license_name), - 'license_email' => e($license->license_email), + 'min_amt' => ($license->min_amt) ? (int) ($license->min_amt) : null, + 'license_name' => ($license->license_name) ? e($license->license_name) : null, + 'license_email' => ($license->license_email) ? e($license->license_email) : null, 'reassignable' => ($license->reassignable == 1) ? true : false, 'maintained' => ($license->maintained == 1) ? true : false, 'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id, 'name'=> e($license->supplier->name)] : null, diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.php index 4b86a35069..c5c8982664 100644 --- a/app/Presenters/LicensePresenter.php +++ b/app/Presenters/LicensePresenter.php @@ -89,7 +89,14 @@ class LicensePresenter extends Presenter 'searchable' => false, 'sortable' => true, 'title' => trans('admin/accessories/general.remaining'), - ], [ + ], + [ + 'field' => 'min_amt', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('mail.min_QTY'), + 'formatter' => 'minAmtFormatter', + ],[ 'field' => 'purchase_date', 'searchable' => true, 'sortable' => true, From 767cf9601049eef97a6a2d71afe5c2ab676e43f2 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:08:33 +0000 Subject: [PATCH 08/12] Added min_amt to form Signed-off-by: snipe --- resources/views/licenses/edit.blade.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/views/licenses/edit.blade.php b/resources/views/licenses/edit.blade.php index b0ff9063f2..34afa4b5c5 100755 --- a/resources/views/licenses/edit.blade.php +++ b/resources/views/licenses/edit.blade.php @@ -22,6 +22,7 @@ @endcan +
@@ -32,6 +33,7 @@
{!! $errors->first('seats', '
') !!} +@include ('partials.forms.edit.minimum_quantity') @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id']) @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id',]) From 4ab7112988635c4044140e78bb5c806adf1ecf76 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:08:47 +0000 Subject: [PATCH 09/12] Added validation and fillable attributes for min_amt Signed-off-by: snipe --- app/Models/License.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Models/License.php b/app/Models/License.php index 2ea10939fa..7fb4f9e4cb 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -53,6 +53,7 @@ class License extends Depreciable 'purchase_date' => 'date_format:Y-m-d|nullable|max:10', 'expiration_date' => 'date_format:Y-m-d|nullable|max:10', 'termination_date' => 'date_format:Y-m-d|nullable|max:10', + 'min_amt' => 'numeric|nullable|gte:0', ]; /** @@ -81,6 +82,7 @@ class License extends Depreciable 'supplier_id', 'termination_date', 'user_id', + 'min_amt', ]; use Searchable; From a0423a9cc3f2bc86a30c9631867ab346ef58bd2f Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:08:56 +0000 Subject: [PATCH 10/12] Added translations Signed-off-by: snipe --- resources/lang/en-US/admin/licenses/general.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/lang/en-US/admin/licenses/general.php b/resources/lang/en-US/admin/licenses/general.php index b2766d063e..79b69a3d94 100644 --- a/resources/lang/en-US/admin/licenses/general.php +++ b/resources/lang/en-US/admin/licenses/general.php @@ -45,4 +45,7 @@ return array( ], ], + + 'below_threshold' => 'There are only :remaining_count seats left for this license with a minimum quantity of :min_amt. You may want to consider purchasing more seats.', + 'below_threshold_short' => 'This item is below the minimum required quantity.', ); From b5603fbfe9822f8f5b9cb89ad622497b11796b82 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:09:07 +0000 Subject: [PATCH 11/12] Added min amt to license blade Signed-off-by: snipe --- resources/views/licenses/view.blade.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php index a0cfac569d..b23023f489 100755 --- a/resources/views/licenses/view.blade.php +++ b/resources/views/licenses/view.blade.php @@ -337,13 +337,23 @@
+ + @if ($license->remaincount() <= ($license->min_amt - \App\Models\Setting::getSettings()->alert_threshold)) + + {{ trans('general.warning') }} + + @endif + {{ $license->seats }} + @if ($license->remaincount() <= ($license->min_amt - \App\Models\Setting::getSettings()->alert_threshold)) + + @endif +
@endif -
From 92eff653f17e5506b7c9fd6abb45db4bc46fd99a Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Feb 2024 11:26:03 +0000 Subject: [PATCH 12/12] Removed logging Signed-off-by: snipe --- resources/views/partials/bootstrap-table.blade.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index a895841023..e69e525e2b 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -625,13 +625,9 @@ function minAmtFormatter(row, value) { if ((row) && (row!=undefined)) { - console.log(row.free_seats_count); - console.log(row.min_amt); - if (value.free_seats_count <= value.min_amt) { return '' + value.min_amt + ''; } - return value.min_amt }