Added numCheckedOut method

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-18 00:26:58 +01:00
parent d9b7df5b85
commit 79a13e3618

View file

@ -329,6 +329,20 @@ class Accessory extends SnipeModel
}
/**
* Check how many items within an accessory are checked out
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v5.0]
* @return int
*/
public function numCheckedOut()
{
\Log::debug('numCheckedOut: '.$this->users_count ?? $this->users->count());
return $this->users_count ?? $this->users->count();
}
/**
* Check how many items of an accessory remain.
*
@ -342,10 +356,14 @@ class Accessory extends SnipeModel
*/
public function numRemaining()
{
$checkedout = $this->users_count;
$checkedout = $this->numCheckedOut();
$total = $this->qty;
$remaining = $total - $checkedout;
\Log::debug('checked out: '.$checkedout);
\Log::debug('total: '.$total);
\Log::debug('remaining: '.$remaining);
return (int) $remaining;
}