add seed gen for code with 4 digit

This commit is contained in:
Yan
2017-07-11 15:23:29 +06:30
parent 1e329d1c5f
commit dec6e7de8a
5 changed files with 303 additions and 279 deletions

View File

@@ -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,27 @@ 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