end of day commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
class Section
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :title
|
||||
|
||||
property :path, type: Array, default: []
|
||||
|
||||
belongs_to :supplier
|
||||
has_many :tables
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
def width
|
||||
self.path.last.try(:first).to_f - self.path.first.try(:first).to_f
|
||||
end
|
||||
def height
|
||||
self.path.last.try(:last).to_f - self.path.first.try(:last).to_f
|
||||
end
|
||||
|
||||
def width=(val)
|
||||
val = val.to_f
|
||||
self.path[0] ||= [0.0, 0.0]
|
||||
self.path[1] ||= [0.0, 0.0]
|
||||
unless path[1][0] == val
|
||||
self.path[1][0] = val
|
||||
path_will_change!
|
||||
end
|
||||
end
|
||||
def height=(val)
|
||||
val = val.to_f
|
||||
self.path[0] ||= [0.0, 0.0]
|
||||
self.path[1] ||= [0.0, 0.0]
|
||||
unless path[1][1] == val
|
||||
self.path[1][1] = val
|
||||
path_will_change!
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -10,6 +10,9 @@ class Supplier
|
||||
has_many :tables, dependent: :destroy
|
||||
#has_many :lists, through: :tables
|
||||
has_many :orders
|
||||
has_many :sections, dependent: :destroy
|
||||
|
||||
after_create :add_section_on_create
|
||||
|
||||
def active_orders
|
||||
return @active_orders if @active_orders
|
||||
@@ -31,4 +34,14 @@ class Supplier
|
||||
tables
|
||||
end
|
||||
|
||||
def non_placed_tables
|
||||
tables.reject{|t| t.section_id.present? }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_section_on_create
|
||||
@section = Section.create supplier: self, title: I18n.t('section.first_section_title')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,13 +2,19 @@ class Table
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :number, type: Fixnum, default: 1
|
||||
property :position_x, type: Float
|
||||
property :position_y, type: Float
|
||||
|
||||
belongs_to :supplier
|
||||
belongs_to :section
|
||||
has_many :lists
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :supplier_id, presence: true
|
||||
#validates :list_id, presence: true
|
||||
validates :number, numericality: {greater_than: 0}
|
||||
validates_uniqueness_of :number
|
||||
|
||||
view :active_lists, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
@@ -20,4 +26,8 @@ class Table
|
||||
not self.class.database.view(self.class.active_lists(key: id, reduce: true)).zero?
|
||||
end
|
||||
|
||||
def name
|
||||
number
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user