Skip to content

A free open source IT asset/license management system

Merge branch 'develop' into checkin_non_reassignable_license

Godfrey Mee31bfbcd4c3
diff --cc app/Helpers/Helper.php
index 8f653ff353,c7930360bb..3352f0a6a0
--- a/app/Helpers/Helper.php
+++ b/app/Helpers/Helper.php
@@@ -1530,4 -1538,92 +1538,92 @@@ class Helpe
return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'));
}
+ /**
+ * Check for inconsistencies before activating scoped locations with FullMultipleCompanySupport
+ * If there are locations with different companies than related objects unforseen problems could arise
+ *
+ * @author T. Regnery <[email protected]>
+ * @since 7.0
+ *
+ * @param $artisan when false, bail out on first inconsistent entry
+ * @param $location_id when set, only test this specific location
+ * @param $new_company_id in case of updating a location, this is the newly requested company_id
+ * @return string []
+ */
+ static public function test_locations_fmcs($artisan, $location_id = null, $new_company_id = null) {
+ $mismatched = [];
+
+ if ($location_id) {
+ $location = Location::find($location_id);
+ if ($location) {
+ $locations = collect([])->push(Location::find($location_id));
+ }
+ } else {
+ $locations = Location::all();
+ }
+
+ foreach($locations as $location) {
+ // in case of an update of a single location, use the newly requested company_id
+ if ($new_company_id) {
+ $location_company = $new_company_id;
+ } else {
+ $location_company = $location->company_id;
+ }
+
+ // Depending on the relationship, we must use different operations to retrieve the objects
+ $keywords_relation = [
+ 'many' => [
+ 'accessories',
+ 'assets',
+ 'assignedAccessories',
+ 'assignedAssets',
+ 'components',
+ 'consumables',
+ 'rtd_assets',
+ 'users',
+ ],
+ 'one' => [
+ 'manager',
+ 'parent',
+ ]];
+
+ // In case of a single location, the children must be checked as well, because we don't walk every location
+ if ($location_id) {
+ $keywords_relation['many'][] = 'children';
+ }
+
+ foreach ($keywords_relation as $relation => $keywords) {
+ foreach($keywords as $keyword) {
+ if ($relation == 'many') {
+ $items = $location->{$keyword}->all();
+ } else {
+ $items = collect([])->push($location->$keyword);
+ }
+
+ foreach ($items as $item) {
+
+ if ($item && $item->company_id != $location_company) {
+ $mismatched[] = [
+ class_basename(get_class($item)),
+ $item->id,
+ $item->name ?? $item->asset_tag ?? $item->serial ?? $item->username,
+ str_replace('App\\Models\\', '', $item->assigned_type) ?? null,
+ $item->company_id ?? null,
+ $item->company->name ?? null,
+ // $item->defaultLoc->id ?? null,
+ // $item->defaultLoc->name ?? null,
+ // $item->defaultLoc->company->id ?? null,
+ // $item->defaultLoc->company->name ?? null,
+ $item->location->name ?? null,
+ $item->location->company->name ?? null,
+ $location_company ?? null,
+ ];
+
+ }
+ }
+ }
+ }
+ }
+ return $mismatched;
- }
++ }
}
diff --cc app/Http/Controllers/Licenses/LicensesController.php
index 7ef6eeb30b,ab1e3868d2..53841e5030
--- a/app/Http/Controllers/Licenses/LicensesController.php
+++ b/app/Http/Controllers/Licenses/LicensesController.php
@@@ -238,27 -234,14 +234,22 @@@ class LicensesController extends Contro
* @return \Illuminate\Contracts\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
- public function show($licenseId = null)
+ public function show(License $license)
{
- $license = License::with('assignedusers')->find($licenseId);
-
- if (!$license) {
- return redirect()->route('licenses.index')
- ->with('error', trans('admin/licenses/message.does_not_exist'));
- }
+ $license = License::with('assignedusers')->find($license->id);
$users_count = User::where('autoassign_licenses', '1')->count();
- $total_seats_count = $license->totalSeatsByLicenseID();
+
+ $total_seats_count = (int) $license->totalSeatsByLicenseID();
$available_seats_count = $license->availCount()->count();
- $checkedout_seats_count = ($total_seats_count - $available_seats_count);
+ $unreassignable_seats_count = License::unReassignableCount($license);
+
+ if(!$license->reassignable){
+ $checkedout_seats_count = ($total_seats_count - $available_seats_count - $unreassignable_seats_count );
+ }
+ else {
+ $checkedout_seats_count = ($total_seats_count - $available_seats_count);
+ }
$this->authorize('view', $license);
return view('licenses.view', compact('license'))
diff --cc app/Http/Transformers/LicensesTransformer.php
index 3be7b256da,b63a5725a4..d8c6a56ca5
--- a/app/Http/Transformers/LicensesTransformer.php
+++ b/app/Http/Transformers/LicensesTransformer.php
@@@ -37,7 -37,8 +37,8 @@@ class LicensesTransforme
'notes' => Helper::parseEscapedMarkedownInline($license->notes),
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
'seats' => (int) $license->seats,
- 'free_seats_count' => (int) $license->free_seats_count,
+ 'free_seats_count' => (int) $license->free_seats_count - License::unReassignableCount($license),
+ 'remaining' => (int) $license->free_seats_count,
'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,