moves counts to licenses, allows bulk check in of unreassignable licenses

This commit is contained in:
Godfrey M
2025-01-22 10:46:28 -08:00
parent 2143952a1e
commit 34e8360b10
7 changed files with 39 additions and 55 deletions
+19 -3
View File
@@ -533,6 +533,7 @@ class License extends Depreciable
return $this->licenseSeatsRelation()
->whereNull('asset_id')
->whereNull('assigned_to')
->where('unreassignable_seat', '=', false)
->whereNull('deleted_at');
}
@@ -582,7 +583,22 @@ class License extends Depreciable
return 0;
}
/**
* Calculates the number of unreassignable seats
*
* @author G. Martinez
* @since [v7.1.15]
*/
public static function unReassignableCount($license) : int
{
$count = 0;
if (!$license->reassignable) {
$count = licenseSeat::query()->where('unreassignable_seat', '=', true)
->where('license_id', '=', $license->id)
->count();
}
return $count;
}
/**
* Calculates the number of remaining seats
*
@@ -590,11 +606,11 @@ class License extends Depreciable
* @since [v1.0]
* @return int
*/
public function remaincount()
public function remaincount() : int
{
$total = $this->licenseSeatsCount;
$taken = $this->assigned_seats_count;
$unreassignable = LicenseSeat::unReassignableCount($this);
$unreassignable = self::unReassignableCount($this);
$diff = ($total - $taken - $unreassignable);
return (int) $diff;