21 lines
564 B
Ruby
21 lines
564 B
Ruby
class Category < ApplicationRecord
|
|
has_many :items, dependent: :restrict_with_error
|
|
|
|
validates :name, presence: true, uniqueness: true
|
|
|
|
# 1. Zählt Artikel im Hauptlager (weder User noch Raum zugewiesen)
|
|
def items_in_storage_count
|
|
items.where(user_id: nil, room_id: nil).count
|
|
end
|
|
|
|
# 2. Zählt Artikel, die bei Mitarbeitern im Umlauf sind
|
|
def items_with_users_count
|
|
items.where.not(user_id: nil).count
|
|
end
|
|
|
|
# 3. Zählt Artikel, die fest in Räumen verbaut sind
|
|
def items_in_rooms_count
|
|
items.where.not(room_id: nil).count
|
|
end
|
|
end
|