geneate random barcode

This commit is contained in:
nandar
2018-08-02 14:42:35 +06:30
parent 21b58c4bcf
commit f937789d1d

View File

@@ -41,12 +41,14 @@ class BatchLineItem < ApplicationRecord
end end
def self.generate_barcode def self.generate_barcode
o = [('0'..'9')].map { |i| i.to_a }.flatten # o = [('0'..'9')].map { |i| i.to_a }.flatten
barcode = (0...8).map { o[rand(o.length)] }.join # barcode = (0...8).map { o[rand(o.length)] }.join
barcode= rand(1_000_000_0..9_999_999_9)
find_account_no = BatchLineItem.find_by_barcode(barcode) find_account_no = BatchLineItem.find_by_barcode(barcode)
if !find_account_no.nil? if !find_account_no.nil?
o = [('0'..'9')].map { |i| i.to_a }.flatten # o = [('0'..'9')].map { |i| i.to_a }.flatten
barcode = (0...8).map { o[rand(o.length)] }.join # barcode = (0...8).map { o[rand(o.length)] }.join
barcode = rand(1_000_000_0..9_999_999_9)
end end
return barcode return barcode
end end