inventory definition.coffee

This commit is contained in:
yamin
2017-10-23 11:40:37 +06:30
69 changed files with 869 additions and 946 deletions

View File

@@ -1,2 +1,4 @@
class CashierTerminal < ApplicationRecord
has_many :cashier_terminal_by_zones
has_many :zones, through: :cashier_terminal_by_zones
end

View File

@@ -0,0 +1,4 @@
class CashierTerminalByZone < ApplicationRecord
belongs_to :zone
belongs_to :cashier_terminal
end

View File

@@ -2,6 +2,7 @@ class SeedGenerator < ApplicationRecord
# Generate ID for Tables
def self.generate_id(model, prefix)
seed = SeedGenerator.find_by_model(model)
next_no = seed.next
new_receipt_no = 0
if (seed.nil?)
@@ -9,18 +10,33 @@ class SeedGenerator < ApplicationRecord
seed.model = model
new_receipt_no = seed.next
seed.save
else
current_no = seed.next
seed.next = seed.next + seed.increase_by
seed.current = current_no
seed.save
# current_no = seed.next
# seed.next = seed.next + seed.increase_by
# seed.current = current_no
# seed.save
cur_val, next_val = self.update_seed(model, seed.next, seed.increase_by)
if next_no == cur_val
puts "SSS"
puts next_val
cur_val2, next_val2 = self.update_seed(model, next_val, seed.increase_by)
puts next_val2
padding_len = 15 - prefix.length
saleOrderId = prefix +"-"+ cur_val2.to_s.to_s.rjust((14-prefix.length)+1,'0')
puts saleOrderId
return saleOrderId
end
padding_len = 15 - prefix.length
saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0')
return saleOrderId
end
padding_len = 15 - prefix.length
saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
return saleOrderId
end
# Generate Receipt No
@@ -71,4 +87,24 @@ class SeedGenerator < ApplicationRecord
next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0')
return next_code
end
def self.update_seed(model, current, inc)
cur_val = 0
next_val = 0
nex = current + inc
update_sql = "update seed_generators set current= #{current}, next= #{nex} where model='#{model}';";
select_sql = "select * from seed_generators where model='#{model}';"
update_result = ActiveRecord::Base.connection.execute(update_sql);
select_result = ActiveRecord::Base.connection.execute(select_sql);
select_result.each do |row|
p row
cur_val = row [3]
next_val = row[4]
end
return cur_val, next_val
end
end

View File

@@ -3,6 +3,7 @@ class Zone < ApplicationRecord
has_many :tables, dependent: :destroy
has_many :rooms, dependent: :destroy
has_many :order_queue_stations
has_many :cashier_terminals
# validations
validates_presence_of :name, :created_by