module Ecom module Core class EquipmentItem < ApplicationRecord # Equipment Statuses READY = 'Ready'.freeze UNDER_MAINTENANCE = 'Under Maintenance'.freeze EQUIPMENT_STATUSES = [READY, UNDER_MAINTENANCE].freeze # Duty Statuses AVAILABLE = 'Available'.freeze BOOKED = 'Booked'.freeze ON_DUTY = 'On Duty'.freeze DUTY_STATUSES = [AVAILABLE, BOOKED, ON_DUTY].freeze belongs_to :equipment belongs_to :country belongs_to :current_location, class_name: 'Ecom::Core::EquipmentLocation' validates :name, :status, :serial_number, :purchase_date, :purchase_price, presence: true validates :status, inclusion: EQUIPMENT_STATUSES validates :duty_status, inclusion: DUTY_STATUSES validates :serial_number, uniqueness: true def self.search(param) search_term = "%#{param.downcase}%" Ecom::Core::EquipmentItem .joins(:equipment) .where( 'lower(ecom_core_equipment_items.name) LIKE ? OR lower(ecom_core_equipment.name) LIKE ?', search_term, search_term ) end end end end