Skip to content

A free open source IT asset/license management system

Remove global scope when counting check outs

Marcus Moorebee80fcf8a42
diff --git a/app/Models/Component.php b/app/Models/Component.php
index 671b0101c4..536e06d0af 100644
--- a/app/Models/Component.php
+++ b/app/Models/Component.php
@@ -205,7 +205,11 @@ class Component extends SnipeModel
public function numCheckedOut()
{
$checkedout = 0;
- foreach ($this->assets as $checkout) {
+
+ // In case there are elements checked out to assets that belong to a different company
+ // than this asset and full multiple company support is on we'll remove the global scope,
+ // so they are included in the count.
+ foreach ($this->assets()->withoutGlobalScope(new CompanyableScope)->get() as $checkout) {
$checkedout += $checkout->pivot->assigned_qty;
}