adds count on tabs and reports and index

This commit is contained in:
Godfrey M 2025-01-13 14:31:54 -08:00
parent 8a0ed49623
commit 5e1562ae4c
6 changed files with 28 additions and 8 deletions

View file

@ -2,6 +2,7 @@
namespace App\Helpers;
use App\Models\Accessory;
use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Component;
@ -9,6 +10,7 @@ use App\Models\Consumable;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\Depreciation;
use App\Models\LicenseSeat;
use App\Models\Setting;
use App\Models\Statuslabel;
use App\Models\License;
@ -1529,4 +1531,14 @@ class Helper
}
return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'));
}
public static function unReassignableCount($license)
{
if (!$license->reassignable) {
$count = Actionlog::where('action_type', '=', 'checkin from')
->where('item_id', '=', $license->id)
->count();
return $count;
}
}
}

View file

@ -248,16 +248,23 @@ class LicensesController extends Controller
}
$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();
$unreassignable_seats_count = Helper::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'))
->with('users_count', $users_count)
->with('total_seats_count', $total_seats_count)
->with('available_seats_count', $available_seats_count)
->with('checkedout_seats_count', $checkedout_seats_count);
->with('checkedout_seats_count', $checkedout_seats_count)
->with('unreassignable_seats_count', $unreassignable_seats_count);
}

View file

@ -37,7 +37,7 @@ class LicensesTransformer
'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 - Helper::unReassignableCount($license),
'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,

View file

@ -594,7 +594,8 @@ class License extends Depreciable
{
$total = $this->licenseSeatsCount;
$taken = $this->assigned_seats_count;
$diff = ($total - $taken);
$unreassignable = Helper::unReassignableCount($this);
$diff = ($total - $taken - $unreassignable);
return (int) $diff;
}

View file

@ -50,7 +50,7 @@ return array(
'checkin' => array(
'error' => 'There was an issue checking in the license. Please try again.',
'not_reassignable' => 'Seat has been used.',
'not_reassignable' => 'Seat has been used',
'success' => 'The license was checked in successfully'
),

View file

@ -32,7 +32,7 @@
<x-icon type="seats" class="fa-2x" />
</span>
<span class="hidden-xs hidden-sm">{{ trans('admin/licenses/form.seats') }}</span>
<span class="badge badge-secondary">{{ number_format($license->availCount()->count()) }} / {{ number_format($license->seats) }}</span>
<span class="badge badge-secondary">{{ number_format($license->availCount()->count() - number_format($unreassignable_seats_count) ) }} / {{ number_format($license->seats)}}</span>
</a>
</li>