Skip to content

A free open source IT asset/license management system

Added numCheckedOut method

snipe79a13e3618b2
diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php
index a234b1e570..7b19d90316 100755
--- a/app/Models/Accessory.php
+++ b/app/Models/Accessory.php
@@ -329,6 +329,20 @@ class Accessory extends SnipeModel
}
+ /**
+ * Check how many items within an accessory are checked out
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @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;
}