class SpecialPrice < ActiveRecord::Base

	##--- Llevar registro de Actividad del usuario
	audited

	belongs_to :product
	belongs_to :customer
	belongs_to :user

	has_many :pre_sales
	has_many :sales_details

	enum status: [ :erased, :active]

	validates_presence_of :product_id, message: "Debe seleccionar un producto.", :on => [:create, :update]
	validates_presence_of :customer_id, message: "Debe seleccionar un cliente.", :on => [:create, :update]

	scope :activos, -> { where( "status = 1") }

	def get_unit_discount(unit_price)
		if self.percent.present?
			(self.percent / 100) * unit_price
		else
			self.price
		end
	end
end
