A free open source IT asset/license management system
Change license_seat changing method to properly 'true up' license seats
Brady Wetheringtonc4f900e9af8d
diff --git a/app/Models/License.php b/app/Models/License.phpindex d0e6f5c969..b59387a42e 100755--- a/app/Models/License.php+++ b/app/Models/License.php@@ -123,12 +123,20 @@ class License extends Depreciablestatic::created(function ($license) {$newSeatCount = $license->getAttributes()['seats'];- return static::adjustSeatCount($license, $oldSeatCount = 0, $newSeatCount);+ return static::adjustSeatCount($license, 0, $newSeatCount);});// However, we listen for updating to be able to prevent the edit if we cannot delete enough seats.static::updating(function ($license) {$newSeatCount = $license->getAttributes()['seats'];- $oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;+ //$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;+ /*+ That previous method *did* mostly work, but if you ever managed to get your $license->seats value out of whack+ with your actual count of license_seats *records*, you would never manage to get back 'into whack'.+ The below method actually grabs a count of existing license_seats records, so it will be more accurate.+ This means that if your license_seats are out of whack, you can change the quantity and hit 'save' and it+ will manage to 'true up' and make your counts line up correctly.+ */+ $oldSeatCount = $license->license_seats_count;return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount);});