license
This commit is contained in:
@@ -29,7 +29,6 @@ module LicenseVerification
|
|||||||
# redirect_to activate_path
|
# redirect_to activate_path
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
authenticate_session_token
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate_session_token
|
def authenticate_session_token
|
||||||
|
|||||||
@@ -1,37 +1,34 @@
|
|||||||
class SeedGenerator < ApplicationRecord
|
class SeedGenerator < ApplicationRecord
|
||||||
# Generate ID for Tables
|
# Generate ID for Tables
|
||||||
def self.generate_id(model, prefix)
|
def self.generate_id(model, prefix)
|
||||||
query = SeedGenerator.select("next").where("model=?",model).first()
|
cur_val, next_val = self.update_seed(model)
|
||||||
|
|
||||||
if query.nil?
|
if (cur_val == 0)
|
||||||
nLast_val = 1
|
cur_val, next_val = self.execute_query(model)
|
||||||
sql = "INSERT INTO seed_generators (model, created_at, updated_at)
|
end
|
||||||
VALUES('#{ model }', NOW(), NOW())
|
|
||||||
ON DUPLICATE KEY UPDATE current = #{nLast_val}, next = #{nLast_val} + 1;"
|
|
||||||
else
|
|
||||||
nLast_val = query.next
|
|
||||||
sql = "UPDATE seed_generators set current = #{nLast_val}, next = #{nLast_val} + 1 WHERE model='#{model}';"
|
|
||||||
end
|
|
||||||
ActiveRecord::Base.connection.execute(sql);
|
|
||||||
|
|
||||||
padding_len = 15 - prefix.length
|
padding_len = 15 - prefix.length
|
||||||
generate_id = prefix +"-"+ nLast_val.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
generate_id = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
||||||
|
return generate_id
|
||||||
return generate_id
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate Receipt No for number order (1,2,3) Don't touch
|
# Generate Receipt No for number order (1,2,3) Don't touch
|
||||||
def self.new_receipt_no
|
def self.new_receipt_no
|
||||||
query = SeedGenerator.select("current").where("model='Sale'").first()
|
seed = SeedGenerator.find_by_model("sale")
|
||||||
new_receipt_no = 0
|
new_receipt_no = 0
|
||||||
|
if (seed.nil?)
|
||||||
if query.nil?
|
seed = SeedGenerator.new()
|
||||||
new_receipt_no = 1
|
seed.model = "sale"
|
||||||
|
new_receipt_no = seed.next
|
||||||
|
seed.save
|
||||||
else
|
else
|
||||||
new_receipt_no = query.current
|
new_receipt_no = seed.next
|
||||||
|
seed.next = seed.next
|
||||||
|
seed.current = new_receipt_no
|
||||||
|
seed.save
|
||||||
end
|
end
|
||||||
|
|
||||||
return new_receipt_no
|
return seed.current
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate for 4 digit Code
|
# Generate for 4 digit Code
|
||||||
@@ -63,43 +60,43 @@ class SeedGenerator < ApplicationRecord
|
|||||||
# return next_code
|
# return next_code
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# def self.execute_query(model)
|
def self.execute_query(model)
|
||||||
# current = 0
|
current = 0
|
||||||
# nex = 0
|
nex = 0
|
||||||
|
|
||||||
# sql = "INSERT INTO seed_generators (model, created_at, updated_at)
|
sql = "INSERT INTO seed_generators (model, created_at, updated_at)
|
||||||
# VALUES('#{ model }', NOW(), NOW())
|
VALUES('#{ model }', NOW(), NOW())
|
||||||
# ON DUPLICATE KEY UPDATE current = next, next = next + 1;"
|
ON DUPLICATE KEY UPDATE current = next, next = next + 1;"
|
||||||
|
|
||||||
# select_sql = "select * from seed_generators where model='#{model}';"
|
select_sql = "select * from seed_generators where model='#{model}';"
|
||||||
|
|
||||||
# ActiveRecord::Base.connection.execute(sql);
|
ActiveRecord::Base.connection.execute(sql);
|
||||||
# select_result = ActiveRecord::Base.connection.execute(select_sql);
|
select_result = ActiveRecord::Base.connection.execute(select_sql);
|
||||||
|
|
||||||
|
|
||||||
# select_result.each do |row|
|
select_result.each do |row|
|
||||||
# current = row [3]
|
current = row [3]
|
||||||
# nex = row[4]
|
nex = row[4]
|
||||||
# end
|
end
|
||||||
|
|
||||||
# return current, nex
|
return current, nex
|
||||||
# end
|
end
|
||||||
|
|
||||||
# def self.update_seed(model)
|
def self.update_seed(model)
|
||||||
# current = 0
|
current = 0
|
||||||
# nex = 0
|
nex = 0
|
||||||
|
|
||||||
# update_sql = "UPDATE seed_generators set current = next, next = next + 1 WHERE model='#{model}';"
|
update_sql = "UPDATE seed_generators set current = next, next = next + 1 WHERE model='#{model}';"
|
||||||
# select_sql = "select * from seed_generators where model='#{model}';"
|
select_sql = "select * from seed_generators where model='#{model}';"
|
||||||
|
|
||||||
# update_result = ActiveRecord::Base.connection.execute(update_sql);
|
update_result = ActiveRecord::Base.connection.execute(update_sql);
|
||||||
# select_result = ActiveRecord::Base.connection.execute(select_sql);
|
select_result = ActiveRecord::Base.connection.execute(select_sql);
|
||||||
|
|
||||||
# select_result.each do |row|
|
select_result.each do |row|
|
||||||
# current = row [3]
|
current = row [3]
|
||||||
# nex = row[4]
|
nex = row[4]
|
||||||
# end
|
end
|
||||||
|
|
||||||
# return current, nex
|
return current, nex
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user