not done
This commit is contained in:
@@ -9,16 +9,26 @@ class SeedGenerator < ApplicationRecord
|
|||||||
seed.model = model
|
seed.model = model
|
||||||
new_receipt_no = seed.next
|
new_receipt_no = seed.next
|
||||||
seed.save
|
seed.save
|
||||||
|
|
||||||
else
|
else
|
||||||
current_no = seed.next
|
next_current = self.update_seed(model, seed.next, seed.increase_by)
|
||||||
seed.next = seed.next + seed.increase_by
|
puts "OOO"
|
||||||
seed.current = current_no
|
puts seed.next
|
||||||
seed.save
|
|
||||||
end
|
|
||||||
|
|
||||||
|
if seed.next == next_current
|
||||||
|
next_current = next_current + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "MMM"
|
||||||
|
puts next_current
|
||||||
|
currentNo = next_current
|
||||||
|
|
||||||
|
# current_no = seed.next
|
||||||
|
# seed.next = seed.next + seed.increase_by
|
||||||
|
# seed.current = current_no
|
||||||
|
# seed.save
|
||||||
|
end
|
||||||
padding_len = 15 - prefix.length
|
padding_len = 15 - prefix.length
|
||||||
saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
saleOrderId = prefix +"-"+ currentNo.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
||||||
return saleOrderId
|
return saleOrderId
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -71,4 +81,36 @@ class SeedGenerator < ApplicationRecord
|
|||||||
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.update_seed(model, current, inc)
|
||||||
|
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]
|
||||||
|
next_val = row[3]
|
||||||
|
end
|
||||||
|
|
||||||
|
return next_val
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user