Merge branch 'osaka' of bitbucket.org:code2lab/sxrestaurant into discount
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
class MenuCategory < ApplicationRecord
|
||||
|
||||
class MenuCategory < ApplicationRecord
|
||||
before_create :generate_menu_category_code
|
||||
|
||||
belongs_to :menu
|
||||
@@ -7,7 +6,7 @@ class MenuCategory < ApplicationRecord
|
||||
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
|
||||
has_many :menu_items
|
||||
|
||||
validates_presence_of :name, :menu, :code, :order_by
|
||||
validates_presence_of :name, :menu, :order_by
|
||||
|
||||
default_scope { order('order_by asc') }
|
||||
|
||||
@@ -38,7 +37,7 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def generate_menu_category_code
|
||||
self.code = SeedGenerator.generate_id(self.class.name, "C")
|
||||
def generate_menu_category_code
|
||||
self.code = SeedGenerator.generate_code(self.class.name, "C")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ class MenuItem < ApplicationRecord
|
||||
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
|
||||
belongs_to :account
|
||||
|
||||
validates_presence_of :item_code, :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
|
||||
validates_presence_of :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
|
||||
|
||||
default_scope { order('item_code asc') }
|
||||
|
||||
@@ -73,7 +73,7 @@ class MenuItem < ApplicationRecord
|
||||
private
|
||||
|
||||
def generate_menu_item_code
|
||||
self.item_code = SeedGenerator.generate_id(self.class.name, "I")
|
||||
self.item_code = SeedGenerator.generate_code(self.class.name, "I")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -14,6 +14,6 @@ class MenuItemInstance < ApplicationRecord
|
||||
private
|
||||
|
||||
def generate_menu_item_instance_code
|
||||
self.item_instance_code = SeedGenerator.generate_id(self.class.name, "II")
|
||||
self.item_instance_code = SeedGenerator.generate_code(self.class.name, "II")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class SeedGenerator < ApplicationRecord
|
||||
|
||||
# Generate ID for Tables
|
||||
def self.generate_id(model, prefix)
|
||||
seed = SeedGenerator.find_by_model(model)
|
||||
new_receipt_no = 0
|
||||
@@ -23,6 +23,7 @@ class SeedGenerator < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
# Generate Receipt No
|
||||
def self.new_receipt_no
|
||||
seed = SeedGenerator.find_by_model("sale")
|
||||
new_receipt_no = 0
|
||||
@@ -41,4 +42,26 @@ class SeedGenerator < ApplicationRecord
|
||||
|
||||
return seed.current
|
||||
end
|
||||
|
||||
# Generate for 4 digit Code
|
||||
def self.generate_code(model, prefix)
|
||||
seed = SeedGenerator.find_by_model(model)
|
||||
new_code = 0
|
||||
|
||||
if (seed.nil?)
|
||||
seed = SeedGenerator.new()
|
||||
seed.model = model
|
||||
new_code = seed.next
|
||||
seed.save
|
||||
else
|
||||
current_no = seed.next
|
||||
seed.next = seed.next + seed.increase_by
|
||||
seed.current = current_no
|
||||
seed.save
|
||||
end
|
||||
|
||||
padding_len = 5 - prefix.length
|
||||
next_code = prefix + seed.current.to_s.to_s.rjust((4-prefix.length)+1,'0')
|
||||
return next_code
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user