re-origin seed generate
This commit is contained in:
@@ -2,40 +2,25 @@ class SeedGenerator < ApplicationRecord
|
|||||||
# Generate ID for Tables
|
# Generate ID for Tables
|
||||||
def self.generate_id(model, prefix)
|
def self.generate_id(model, prefix)
|
||||||
seed = SeedGenerator.find_by_model(model)
|
seed = SeedGenerator.find_by_model(model)
|
||||||
next_no = seed.next
|
|
||||||
new_receipt_no = 0
|
new_receipt_no = 0
|
||||||
puts "OOO"
|
|
||||||
puts next_no
|
|
||||||
if (seed.nil?)
|
if (seed.nil?)
|
||||||
seed = SeedGenerator.new()
|
seed = SeedGenerator.new()
|
||||||
seed.model = model
|
seed.model = model
|
||||||
new_receipt_no = seed.next
|
new_receipt_no = seed.next
|
||||||
seed.save
|
seed.save
|
||||||
|
|
||||||
else
|
else
|
||||||
cur_val, next_val = self.update_seed(model, next_no, seed.increase_by)
|
current_no = seed.next
|
||||||
|
seed.next = seed.next + seed.increase_by
|
||||||
# if next_no == cur_val
|
seed.current = current_no
|
||||||
# puts "SSS"
|
seed.save
|
||||||
# puts next_val
|
|
||||||
# cur_val2, next_val2 = self.update_seed(model, next_val, seed.increase_by)
|
|
||||||
# padding_len = 15 - prefix.length
|
|
||||||
# saleOrderId = prefix +"-"+ cur_val2.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
|
||||||
# return saleOrderId
|
|
||||||
|
|
||||||
while next_no == cur_val
|
|
||||||
padding_len = 15 - prefix.length
|
|
||||||
saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
|
||||||
return saleOrderId
|
|
||||||
puts "LLL"
|
|
||||||
puts next_val
|
|
||||||
next_no = next_val
|
|
||||||
cur_val, next_val = self.update_seed(model, next_val, seed.increase_by)
|
|
||||||
padding_len = 15 - prefix.length
|
|
||||||
saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
|
||||||
return saleOrderId
|
|
||||||
end
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
padding_len = 15 - prefix.length
|
||||||
|
saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
||||||
|
return saleOrderId
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate Receipt No
|
# Generate Receipt No
|
||||||
@@ -86,50 +71,4 @@ puts next_no
|
|||||||
next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0')
|
next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0')
|
||||||
return next_code
|
return next_code
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# for duplicate key - with execute query
|
|
||||||
def self.get_seed(model)
|
|
||||||
seed_val = []
|
|
||||||
select_sql = "select * from seed_generators where model='#{model}';"
|
|
||||||
select_result = ActiveRecord::Base.connection.execute(select_sql);
|
|
||||||
select_result.each do |row|
|
|
||||||
p row
|
|
||||||
seed_val = row
|
|
||||||
end
|
|
||||||
|
|
||||||
return seed_val
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.current_no_present(next_val, cur_val)
|
|
||||||
cur_val2, next_val2 = self.update_seed(model, next_val, seed.increase_by)
|
|
||||||
padding_len = 15 - prefix.length
|
|
||||||
saleOrderId = prefix +"-"+ cur_val2.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
|
||||||
return saleOrderId
|
|
||||||
|
|
||||||
if next_val == cur_val2
|
|
||||||
current_no_present(next_val2, cur_val2)
|
|
||||||
end
|
|
||||||
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);
|
|
||||||
|
|
||||||
Rails.logger.debug "SeedGenerator -> " + update_result.to_s
|
|
||||||
|
|
||||||
select_result = ActiveRecord::Base.connection.execute(select_sql);
|
|
||||||
select_result.each do |row|
|
|
||||||
p row[3]
|
|
||||||
cur_val = row [3]
|
|
||||||
next_val = row[4]
|
|
||||||
end
|
|
||||||
|
|
||||||
return cur_val, next_val
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user