Advertisement
Guest User

Untitled

a guest
May 27th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. class CoworkingSpace < ActiveRecord::Base
  2. has_many :tables
  3. has_many :products
  4. belongs_to :user
  5. belongs_to :city
  6. belongs_to :category
  7. has_many :image_coworking_spaces
  8. has_many :images, :through => :image_coworking_spaces
  9. has_many :item_categories, dependent: :destroy
  10.  
  11. mount_uploader :map_file, ImageUploader
  12.  
  13. attr_accessor :category_name
  14. attr_accessible :start_time_download_coupons, :end_time_download_coupons, :name,
  15. :description, :city_id, :lat, :long, :address, :user_id, :category_id, :url, :map_file, :map_text_url, :remove_map_file
  16.  
  17. scope :promotions, scoped
  18. scope :hot_promotions, promotions.limit(3)
  19.  
  20. def map_url
  21. return self.map_file_url if self.map_file?
  22. return self.map_text_url if self.map_text_url?
  23. end
  24.  
  25. def create_tables
  26. end
  27.  
  28. def price
  29. if percentage_booked <= 0.3
  30. green
  31. elsif percentage_booked <= 0.6
  32. yellow
  33. else
  34. red
  35. end
  36. end
  37.  
  38. def tables_left(type)
  39. (tables.where('tipo = ?', type).count) - (tables.where('booked = ? and tipo = ? ', true, type).count)
  40. end
  41.  
  42. def percentage_booked
  43. tables_booked / tables.where(:tipo => 'resource').count.to_f
  44.  
  45. end
  46.  
  47. def tables_booked
  48. tables.where('tipo = ? ', 'resource').select(&:booked).count
  49. end
  50.  
  51. def prices
  52. @prices ||= []
  53.  
  54. item_categories.each do |category|
  55. @prices << category.price(self)
  56. end
  57.  
  58. @prices
  59. end
  60.  
  61. def products_quantity
  62. return 0 if item_categories.empty?
  63. item_categories.sum(:num_tables)
  64. end
  65.  
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement