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; } 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); diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.php index 02e2163207..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')); @@ -245,12 +247,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) 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/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; 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, 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'); + } + }); + } +} 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.', ); 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 +