Merge branch 'r-1902001-01' of gitlab.com:code2lab/SXRestaurant into r-1902001-01

This commit is contained in:
NyanLinHtut
2020-06-08 10:14:17 +06:30
33 changed files with 459 additions and 208 deletions

View File

@@ -96,7 +96,6 @@ GEM
concurrent-ruby (1.1.5) concurrent-ruby (1.1.5)
connection_pool (2.2.2) connection_pool (2.2.2)
crass (1.0.5) crass (1.0.5)
cups (0.0.7)
database_cleaner (1.7.0) database_cleaner (1.7.0)
diff-lcs (1.3) diff-lcs (1.3)
erubi (1.9.0) erubi (1.9.0)
@@ -335,7 +334,6 @@ DEPENDENCIES
carrierwave (~> 1.0) carrierwave (~> 1.0)
chartkick chartkick
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
cups (~> 0.0.7)
database_cleaner database_cleaner
factory_girl_rails (~> 4.0) factory_girl_rails (~> 4.0)
faker faker

View File

@@ -11,7 +11,7 @@
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
border: none; border: none;
position: fixed; position: fixed;
top: 0; /*top: 0;*/
left: 0; left: 0;
z-index: 12; z-index: 12;
width: 100%; } width: 100%; }
@@ -6649,7 +6649,7 @@ fieldset[disabled] .form-control {
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
border: none; border: none;
position: fixed; position: fixed;
top: 0; /*top: 0;*/
left: 0; left: 0;
z-index: 12; z-index: 12;
width: 100%; } width: 100%; }

View File

@@ -1,7 +1,6 @@
class InstallController < BaseController class InstallController < BaseController
skip_before_action :lookup_domain # skip_before_action :set_current_tenant_by_subdomain_or_name
skip_before_action :verify_authenticity_token skip_before_action :verify_authenticity_token
# before_action :check_license
def index def index
end end
@@ -30,7 +29,7 @@ class InstallController < BaseController
# aes_iv = ENV["AES_IV"] # aes_iv = ENV["AES_IV"]
# end # end
@license = License.new(ENV["SX_PROVISION_URL"]) @license = License.new(ENV["SX_PROVISION_URL"], request.host)
response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password) response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password)
if response[:status] if response[:status]
redirect_to root_url, notice: response["message"] redirect_to root_url, notice: response["message"]
@@ -39,27 +38,23 @@ class InstallController < BaseController
end end
end end
def check_license def lookup_domain
if License.check_license_file if ENV["SERVER_MODE"] == "cloud"
not_found
elsif ENV["SERVER_MODE"] == "application"
if check_license #(request.host)
redirect_to root_url redirect_to root_url
end end
elsif request.subdomains.last && request.subdomains.last != "www"
if check_license #(request.host)
redirect_to root_url
elsif !check_subdomain(request.host)
not_found
end
else
not_found
end
end end
# def lookup_domain
# if request.subdomain.present? && request.subdomain != "www"
# @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase)
# if (!@license.nil?)
# # logger.info "Location - " + @license.name
# ActiveRecord::Base.establish_connection(website_connection(@license))
# # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
# else
# # reconnect_default_db
# logger.info 'License is nil'
# # redirect_to root_url(:host => request.domain) + "store_error"
# render :json => [{ status: false, message: 'Invalid Access!'}]
# end
# end
# end
# def current_license(url, key) # def current_license(url, key)
# @license = License.new(url, key) # @license = License.new(url, key)

View File

@@ -0,0 +1,17 @@
class RenewLicenseController < ApplicationController
def expire
@license = current_license
@plan = @license.read_license("plan_name")
@bis_name = @license.read_license_no_decrypt("shop_name")
@expired_at = @license.read_license("renewable_date")
@license_status = @license.detail_with_local_file
end
def renew
status, message = current_license.verify_license
redirect_to expire_url(message: message, status: status)
end
end

View File

@@ -5,8 +5,8 @@ module ApplicationHelper
case level case level
when :notice then "alert alert-info fade-in" when :notice then "alert alert-info fade-in"
when :success then "alert alert-success fade-in" when :success then "alert alert-success fade-in"
when :error then "alert alert-error fade-in" when :error then "alert alert-warning fade-in"
when :alert then "alert alert-error fade-in" when :alert then "alert alert-danger fade-in"
end end
end end

View File

@@ -1,12 +1,15 @@
require 'yaml'
class License class License
include HTTParty include HTTParty
include ActionDispatch::Http
base_uri "connect.smartsales.asia/api" base_uri "https://l.doemal.app//api"
attr_accessor :name, :address_1, :address_2, :township, :city, :country, :email, :phone, :fax, :logo, :subdomain, attr_accessor :name, :address_1, :address_2, :township, :city, :country, :email, :phone, :fax, :logo, :subdomain,
:plan_activation_date, :plan_next_renewal_date, :plan_max_products,:plan_max_customers, :plan_active_connections, :plan_activation_date, :plan_next_renewal_date, :plan_max_products,:plan_max_customers, :plan_active_connections,
:dbhost, :dbschema, :dbusername, :dbpassword, :exchange_unqiue_id, :localqueue_host,:server_mode,:localhost_address, :dbhost, :dbschema, :dbusername, :dbpassword, :exchange_unqiue_id, :localqueue_host,:server_mode,:localhost_address,
:localqueue_user, :localqueue_password, :remotequeue_host, :remotequeue_user, :remotequeue_password, :api_token, :app_token :localqueue_user, :localqueue_password, :remotequeue_host, :remotequeue_user, :remotequeue_password, :api_token, :app_token, :lookup
@license = nil @license = nil
@secret = nil @secret = nil
@@ -14,14 +17,17 @@ class License
def initialize(server = "", lookup = "") def initialize(server = "", lookup = "")
#this code is hard-code to reflect server mode - Very important. #this code is hard-code to reflect server mode - Very important.
self.server_mode = ENV["SERVER_MODE"] self.server_mode = ENV["SERVER_MODE"]
unless ENV["SERVER_MODE"] == "cloud"
self.server_mode = "application"
end
self.lookup = lookup
if (server != "") if (server != "")
self.class.base_uri server self.class.base_uri server
end end
end end
# For Cloud # For Cloud
def detail_with_local_cache(lookup) def detail_with_local_cache
aes = MyAesCrypt.new aes = MyAesCrypt.new
aes_key, aes_iv = aes.export_to_file(lookup) aes_key, aes_iv = aes.export_to_file(lookup)
@@ -69,53 +75,49 @@ class License
end end
# For Local System # For Local System
def detail_with_local_file() def detail_with_local_file
renewal_date_str = read_license("renewable_date") if expired?
if check_expiring(renewal_date_str) return 0
# return for all ok elsif expire_in?(10)
return 1
else
has_license = verify_license()
if has_license
# return for expiring
return 2 return 2
else else
return 0 return 1
end end
end end
# end
end
# License Activation # License Activation
def license_activate (shop, license_key, db_host, db_schema, db_user, db_password) def license_activate (shop, license_key, db_host, db_schema, db_user, db_password)
aes = MyAesCrypt.new aes = MyAesCrypt.new
aes_key, aes_iv = aes.export_key(license_key) aes_key, aes_iv = aes.export_key(license_key)
@params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } } @params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } }
begin
response = self.class.get("/activate", @params) response = self.class.get("/activate", @params)
@activate = response.parsed_response @activate = response.parsed_response
if (@activate["status"]) if (@activate["status"])
##Check from local redis - if available load local otherwise get from remote ##Check from local redis - if available load local otherwise get from remote
cache_key = "shop:#{@activate["shop_name"]}" cache_key = "shop:#{@activate["shop_name"]}"
cache_license = nil
##Get redis connection from connection pool ##Get redis connection from connection pool
redis = Redis.new # redis = Redis.new
cache_license = redis.get(cache_key) # cache_license = redis.get(cache_key)
Rails.logger.info "Cache key - " + cache_key.to_s Rails.logger.info "Cache key - " + cache_key.to_s
if cache_license.nil? # if cache_license.nil?
cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] }
redis = Redis.new redis = Redis.new
redis.set(cache_key, Marshal.dump(cache)) redis.set(cache_key, Marshal.dump(cache))
end # end
Rails.logger.info "License - " + response.parsed_response.to_s Rails.logger.info "License - " + response.parsed_response.to_s
response = create_license_file(@activate) response = create_license_file(@activate)
if(response[:status]) if(response[:status])
#sym_path = "/home/user/symmetric/" #sym_path = "/home/user/symmetric/"
sym_path = File.expand_path("~/symmetric/") sym_path = File.expand_path("~/symmetric/")
@@ -129,21 +131,43 @@ class License
else else
response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"}
end end
rescue SocketError => e
Rails.logger.debug "In SocketError No Internet connection !"
response = { "status": false, "message": "In SocketError No Internet connection !"}
rescue HTTParty::Error
Rails.logger.debug "Server Error HTTParty"
response = { "status": false, "message": "Server Error HTTParty"}
rescue Net::OpenTimeout
Rails.logger.debug "connection Timeout"
response = { "status": false, "message": "Connection Timeout"}
rescue OpenURI::HTTPError
Rails.logger.debug "Can't connect server"
response = { "status": false, "message": "Can't connect server"}
end
return response return response
end end
def verify_license def verify_license
api_token = read_license_no_decrypt("api_token") api_token = read_license_no_decrypt("api_token")
@params = { query: {lookup_type: "application", api_token: api_token} } @params = { query: {lookup_type: "application", api_token: api_token} }
old_renewable_date = read_license("renewable_date")
begin begin
response = self.class.get("/verify", @params) response = self.class.get("/verify", @params)
@varified = response.parsed_response @varified = response.parsed_response
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
if (@varified["status"]) if (@varified["status"])
if (!check_expired(@varified["renewable_date"])) if old_renewable_date.to_date == @varified['renewable_date'].to_date
return true message = "*** License can't be verified. ***"
status = 2
elsif old_renewable_date.to_date < @varified['renewable_date'].to_date
update_license("renewable_date", @varified['renewable_date'])
status = 1
message = "*** License con be verified. ***"
end end
return status, message
else else
delete_license_file delete_license_file
end end
@@ -164,12 +188,23 @@ class License
return false return false
end end
def expired?
# Check Expired before 30 days if renewal_date_str = read_license("renewable_date")
def check_expiring(renewal_date_str)
if !renewal_date_str.empty?
renewal_date = DateTime.parse(renewal_date_str) renewal_date = DateTime.parse(renewal_date_str)
renewal_date > Date.today.advance(:days => 30) renewal_date < Date.today
end
end
def expire_in?(days)
if renewal_date_str = read_license("renewable_date")
renewal_date = DateTime.parse(renewal_date_str)
renewal_date < days.days.from_now
end
end
def days_to_expire
if renewal_date_str = read_license("renewable_date")
Date.today - DateTime.parse(renewal_date_str).to_date
end end
end end
@@ -188,39 +223,59 @@ class License
end end
end end
def check_license_subdomain
aes = MyAesCrypt.new
aes_key, aes_iv = aes.export_key(lookup)
params = { query: { lookup_type: "cloud", lookup: lookup, iv_key: aes_iv} }
response = self.class.get("/subdomain", params)
response.parsed_response["status"]
end
# Check License File exists # Check License File exists
def self.check_license_file def self.check_license_file(lookup)
return File.exist?("config/license.yml") return unless File.exist?("config/license.yml")
if license = YAML.load_file("config/license.yml")
if license[lookup].nil?
if ENV["SERVER_MODE"] == "application"
license[lookup] = license.values.first
else
tld_length = Rails.application.config.action_dispatch.tld_length
subdomains = URL.extract_subdomains(lookup, tld_length)
if key = license.keys.find { |k| URL.extract_subdomains(k, tld_length).last == subdomains.last}
license[lookup] = license[key]
end
end
if license[lookup]
File.open("config/license.yml", "w") { |file| file.write license.to_yaml }
end
end
return license[lookup]
end
end end
# read line by key for license file # read line by key for license file
def read_license(key_name) def read_license(key_name)
decrypted_line = ""
key, iv = get_redis_key() key, iv = get_redis_key()
if File.exist?("config/license.yml") if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line| if license = YAML.load(File.read("config/license.yml"))
if line.include? (key_name) if license[lookup]
decrypted_line_array = line.split(": ") AESCrypt.decrypt_data(decode_str(license[lookup][key_name]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
end end
end end
end end
return decrypted_line
end end
# read line by key for license file without decrypt # read line by key for license file without decrypt
def read_license_no_decrypt(key) def read_license_no_decrypt(key)
decrypted_line = ""
if File.exist?("config/license.yml") if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line| if license = YAML.load_file("config/license.yml")
if line.include? (key) if license[lookup]
decrypted_line_array = line.split(": ") decrypted_line = license[lookup][key]
decrypted_line = decrypted_line_array[1]
end end
end end
end end
return decrypted_line
end end
# Update license file for line # Update license file for line
@@ -231,18 +286,13 @@ class License
crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
end end
content_str = read_license_no_decrypt(content)
if File.exist?("config/license.yml") if File.exist?("config/license.yml")
file_str = File.read("config/license.yml") if license = YAML.load_file("config/license.yml")
new_file_str = file_str.gsub(content_str, encode_str(crypted_str)) license[lookup][content] = encode_str(crypted_str)
# To write changes to the file, use: # To write changes to the file, use:
File.open("config/license.yml", "w") {|file| file.puts new_file_str } File.open("config/license.yml", "w") {|file| file.write(license.to_yaml) }
end
# File.open("config/license.yml").each do |line|
# new_file_str = line.gsub(content, crypted_str)
# f.put
# end
end end
end end
@@ -284,8 +334,6 @@ class License
##Check from local redis - if available load local otherwise get from remote ##Check from local redis - if available load local otherwise get from remote
cache_key = "shop:#{shop.chomp}" cache_key = "shop:#{shop.chomp}"
cache_shop = nil
##Get redis connection from connection pool ##Get redis connection from connection pool
redis = Redis.new redis = Redis.new
cache_shop = redis.get(cache_key) cache_shop = redis.get(cache_key)
@@ -308,29 +356,38 @@ class License
# License File Creation # License File Creation
def create_license_file(response_data) def create_license_file(response_data)
if File.exist?("config/license.yml")
delete_license_file
end
begin begin
# Licese File Creation # Licese File Creation
File.open("config/license.yml", "w") do |f| config = { "iv_key" => response_data['iv_key'],
f.puts("iv_key: #{response_data['iv_key']}") "shop_name" => response_data['shop_name'],
f.puts("shop_name: #{response_data['shop_name']}") "email" => response_data['email'],
f.puts("email: #{response_data['email']}") "telephone" => response_data['telephone'],
f.puts("telephone: #{response_data['telephone']}") "fax" => response_data['fax'],
f.puts("fax: #{response_data['fax']}") "address" => response_data['address'],
f.puts("address: #{response_data['address']}") "dbhost" => response_data['dbhost'],
f.puts("dbhost: #{response_data['dbhost']}") "dbschema" => response_data['dbschema'],
f.puts("dbschema: #{response_data['dbschema']}") "dbusername" => response_data['dbusername'],
f.puts("dbusername: #{response_data['dbusername']}") "dbpassword" => response_data['dbpassword'],
f.puts("dbpassword: #{response_data['dbpassword']}") "api_token" => response_data['api_token'],
f.puts("api_token: #{response_data['api_token']}") "app_token" => response_data['app_token'],
f.puts("app_token: #{response_data['app_token']}") "plan_sku" => response_data['plan_sku'],
f.puts("plan_sku: #{response_data['plan_sku']}") "renewable_date" => response_data['renewable_date'],
f.puts("renewable_date: #{response_data['renewable_date']}") "plan_name" => response_data['plan_name'] }
f.puts("plan_name: #{response_data['plan_name']}")
if File.exist?("config/license.yml")
license = YAML.load_file("config/license.yml")
end end
if license
license.each do |k,v|
license[k] = config if v["shop_name"] == config["shop_name"]
end
license[lookup] = config
end
license ||= {lookup => config}
File.open("config/license.yml", "w"){ |file| file.write(license.to_yaml) }
rescue IOError rescue IOError
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
end end
@@ -387,10 +444,10 @@ class License
# f.write("initial.load.use.extract.job.enabled=true\n") # f.write("initial.load.use.extract.job.enabled=true\n")
f.close f.close
rescue IOError rescue IOError
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} return { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
end end
response = { "status": true, "message": "Success Activation. License also created."}
end end
{ "status": true, "message": "Success Activation. License also created." }
end end
# Run Symmetric # Run Symmetric

View File

@@ -189,7 +189,7 @@
<td align="right"><%= @summ_sale.total_receipt %></td> <td align="right"><%= @summ_sale.total_receipt %></td>
</tr> </tr>
<tr> <tr>
<% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> <% revenue = @summ_sale.grand_total - @summ_sale.total_discount - @summ_sale.total_tax %>
<td><%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : </td> <td><%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : </td>
<td align="right"><%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %></td> <td align="right"><%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %></td>
</tr> </tr>

View File

@@ -31,6 +31,7 @@
<p>Please wait...</p> <p>Please wait...</p>
</div> </div>
</div> </div>
<%= render 'shared/license_expire_warning' %>
<!-- #END# Page Loader --> <!-- #END# Page Loader -->
<!-- Overlay For Sidebars --> <!-- Overlay For Sidebars -->
<div class="overlay"></div> <div class="overlay"></div>

View File

@@ -35,6 +35,7 @@
<p>Please wait...</p> <p>Please wait...</p>
</div> </div>
</div> </div>
<%= render 'shared/license_expire_warning' %>
<!-- #END# Page Loader --> <!-- #END# Page Loader -->
<!-- Overlay For Sidebars --> <!-- Overlay For Sidebars -->
<div class="overlay"></div> <div class="overlay"></div>

View File

@@ -32,6 +32,7 @@
<p>Please wait...</p> <p>Please wait...</p>
</div> </div>
</div> </div>
<%= render 'shared/license_expire_warning' %>
<!-- #END# Page Loader --> <!-- #END# Page Loader -->
<!-- Overlay For Sidebars --> <!-- Overlay For Sidebars -->
<div class="overlay"></div> <div class="overlay"></div>

View File

@@ -31,6 +31,7 @@
<p>Please wait...</p> <p>Please wait...</p>
</div> </div>
</div> </div>
<%= render 'shared/license_expire_warning' %>
<!-- #END# Page Loader --> <!-- #END# Page Loader -->
<!-- Overlay For Sidebars --> <!-- Overlay For Sidebars -->
<div class="overlay"></div> <div class="overlay"></div>

View File

@@ -31,6 +31,7 @@
<p>Please wait...</p> <p>Please wait...</p>
</div> </div>
</div> </div>
<%= render 'shared/license_expire_warning' %>
<!-- #END# Page Loader --> <!-- #END# Page Loader -->
<!-- Overlay For Sidebars --> <!-- Overlay For Sidebars -->
<div class="overlay"></div> <div class="overlay"></div>

View File

@@ -14,6 +14,7 @@
</head> </head>
<body> <body>
<%= render 'shared/license_expire_warning' %>
<%= render 'layouts/header' %> <%= render 'layouts/header' %>
<div class="container-fluid"> <div class="container-fluid">
<% flash.each do |type, message| %> <% flash.each do |type, message| %>

View File

@@ -1,5 +1,5 @@
<!-- Column One --> <!-- Column One -->
<div class="row clearfix" style=""> <div class="row clearfix m-top-100" style="">
<div class="col-lg-7 col-md-7 col-sm-7"> <div class="col-lg-7 col-md-7 col-sm-7">
<p class="hidden filter"><%= @filter %></p> <p class="hidden filter"><%= @filter %></p>
<div class="card"> <div class="card">

View File

@@ -4,7 +4,7 @@
<% type = request.path_info.include?('quick_service') || request.path_info.include?('food_court')%> <% type = request.path_info.include?('quick_service') || request.path_info.include?('food_court')%>
<% modify_order = request.path_info.include?('modify_order')%> <% modify_order = request.path_info.include?('modify_order')%>
<div class="container-fluid " style="padding:0px 3px 0px 3px;"> <div class="container-fluid addorder-pages" style="padding:0px 3px 0px 3px;">
<div id="oqs_loading_wrapper" style="display:none;"> <div id="oqs_loading_wrapper" style="display:none;">
<div id="oqs_loading"></div> <div id="oqs_loading"></div>
</div> </div>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div class='row'> <div class='row'>
<div class="col-lg-10 col-md-10 col-sm-10"> <div class="col-lg-10 col-md-10 col-sm-10">
<h2> <%= t :cash_in %> </h2> <h2> <%= t :cash_in %> </h2>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div class='row'> <div class='row'>
<div class="col-lg-10 col-md-10 col-sm-10"> <div class="col-lg-10 col-md-10 col-sm-10">
<h2><%= t :cash_out %></h2> <h2><%= t :cash_out %></h2>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div id="loading_wrapper" style="display:none;"> <div id="loading_wrapper" style="display:none;">
<div id="loading"></div> <div id="loading"></div>
</div> </div>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div id="loading_wrapper" style="display:none;"> <div id="loading_wrapper" style="display:none;">
<div id="loading"></div> <div id="loading"></div>
</div> </div>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div id="loading_wrapper" style="display:none;"> <div id="loading_wrapper" style="display:none;">
<div id="loading"></div> <div id="loading"></div>
</div> </div>

View File

@@ -1,6 +1,6 @@
<%= stylesheet_link_tag 'order_reservation', media: 'all', 'data-turbolinks-track': 'reload' %> <%= stylesheet_link_tag 'order_reservation', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'order_reservation', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'order_reservation', 'data-turbolinks-track': 'reload' %>
<div class="container-fluid"> <div class="container-fluid m-top-100">
<!-- start count function --> <!-- start count function -->
<% <%
pending_count = 0 pending_count = 0

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div class="row"> <div class="row">
<!-- Column One --> <!-- Column One -->
<div class="col-lg-6 col-md-6 col-sm-6"> <div class="col-lg-6 col-md-6 col-sm-6">
@@ -202,7 +202,7 @@
<%else%> <%else%>
<button type="button" class="btn bg-default btn-block" onclick="window.location.href = '/origami/sale/<%=@sale_data.sale_id%>/<%=@cashier_type%>/payment'"><i class="material-icons">reply</i> Back </button> <button type="button" class="btn bg-default btn-block" onclick="window.location.href = '/origami/sale/<%=@sale_data.sale_id%>/<%=@cashier_type%>/payment'"><i class="material-icons">reply</i> Back </button>
<%end%> <%end%>
<button id="charge_other" class="btn bg-primary btn-block action-btn">Enter</button> <button id="charge_other" class="btn bg-primary btn-block action-btn" style="height: 35px">Enter</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div id="loading_wrapper" style="display:none;"> <div id="loading_wrapper" style="display:none;">
<div id="loading"></div> <div id="loading"></div>
</div> </div>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div class="row clearfix"> <div class="row clearfix">
<!-- Column One --> <!-- Column One -->
<div class="col-lg-10 col-md-10 col-sm-10"> <div class="col-lg-10 col-md-10 col-sm-10">

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div class="row"> <div class="row">
<!-- Column One --> <!-- Column One -->
<div class="col-lg-5 col-md-5 col-sm-5"> <div class="col-lg-5 col-md-5 col-sm-5">

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div id="loading_wrapper" style="display:none;"> <div id="loading_wrapper" style="display:none;">
<div id="loading"></div> <div id="loading"></div>
</div> </div>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid"> <div class="container-fluid m-top-100">
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-12 col-md-7 col-lg-7"> <div class="col-xs-12 col-sm-12 col-md-7 col-lg-7">
<div class="card"> <div class="card">

View File

@@ -0,0 +1,82 @@
<% renewable_date = current_license.read_license("renewable_date") %>
<% date_count = (renewable_date.to_date - Date.today).to_i %>
<% day = pluralize( date_count, 'day' )%>
<% if @license_status == 0
text = 'Your license has been expired.'
elsif @license_status == 2
text = "Your license will expire in #{day}."
end
%>
<style>
.centered {
position: fixed;
/*width: 850px;*/
padding: 10px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
<div class="container-fluid">
<div class="row">
<div class="col-sm-2"></div>
<div class="card col-sm-8 centered">
<div class="card-block">
<h3 class="pt-2 d-inline">Review Your License</h3>
<%= link_to origami_dashboard_url do %>
<img src="/image/logo.png" style="margin-left: 25pc; width: 150px">
<% end %>
<% if params[:message].present?
if params[:status].to_i == 1
color = 'text-success'
else
color = 'text-danger'
end
%>
<p class="<%= color %> m-t--30" style="font-weight: bold; font-size: 18px;"><%= params[:message] %></p><br>
<% end %>
<% if text %>
<h6 class="mb-2 "><%= text %></h6><br>
<% end %>
<h6 class="mb-2">Call Center Phone No: <a href="tel:+6494461709">+959 445 665 311</a></h6>
<br>
<h6>License Info:</h6>
<br>
<div class="container">
<div class="form-group row">
<label class="card-subtitle mb-2 col-md-4">Business Name:</label>
<label class="card-subtitle mb-2 "><strong><%= @bis_name %></strong></label>
</div>
<div class="form-group row">
<label class="card-subtitle mb-2 col-md-4">Plan:</label>
<label class="card-subtitle mb-2 "><strong><%= @plan %></strong></label>
</div>
</div>
<div class="form-group row">
<label class="card-subtitle mb-2 col-md-4 pl-4">Expired At: </label>
<label class="card-subtitle mb-2 "><strong><%= @expired_at.to_date.strftime('%B %d, %Y') %></strong></label>
</div>
</div>
<br>
<div class="col-md-12" style="padding-bottom: 20px;">
<%= link_to 'Review License', renew_url, class: 'btn btn-primary btn-lg float-right m-l-10 m-r-5' %>
<%= link_to 'Go To Home', origami_dashboard_url, class: 'btn btn-default btn-lg float-right' %>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</div>
<script>
$(document).ready(function() {
$('.alert-danger, .navbar').hide()
$('html, section').css('background-color', '#61B8C9')
// $('html').css('overflow-x', 'hidden')
$('section.content').css('margin', '70px 0 0 0')
})
</script>

View File

@@ -0,0 +1,47 @@
<% license_status = current_license.detail_with_local_file %>
<% renewable_date = current_license.read_license("renewable_date") %>
<% date_count = (renewable_date.to_date - Date.today).to_i %>
<% day = pluralize( date_count, 'day' )%>
<% if license_status == 0
text = 'Your license has expired.'
elsif license_status == 2
text = "Your license will expire in #{day}."
end
%>
<% if license_status == 0 || license_status == 2 %>
<div class="alert alert-danger fade show text-center" role="alert">
<strong style="margin-left: 40px !important"><%= text %></strong>
<%= link_to 'Review License', expire_url, class: 'btn btn-sm btn-primary', style: "margin-left: 20px !important"%>
<button type="button" class="close btn-close" data-dismiss="alert" aria-label="Close" style="padding-top: 5px;">
<span aria-hidden="true" class="text-white">&times;</span>
</button>
</div>
<% end %>
<script>
$(document).ready(function() {
if (<%= license_status %> == 1) {
$('.navbar').css("top", 0)
$('section.content').css('margin-top', '0 !important')
}
else {
$('.navbar').css("top", '45px')
$('.block-header, .addorder-pages').css('margin-top', '115px')
$('.page-header, .m-top-100').css('margin-top', '100px')
$('.alert-danger').css({
'top': 0,
'position': 'fixed',
'z-index': 999,
'width': '100%'
})
}
$('.btn-close').on ('click', function() {
$('.navbar').css("top", '0')
$('.block-header, .addorder-pages').css('margin-top', '')
$('.page-header, .m-top-100').css('margin-top', '')
})
})
</script>

View File

@@ -1,58 +1,65 @@
class ActionController::Base class ActionController::Base
before_action :lookup_domain, :set_locale before_action :lookup_domain if Rails.env.production?
before_action :set_locale
helper_method :current_license,
def not_found
respond_to do |format|
format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
format.json { head :not_found }
end
end
private private
def lookup_domain def lookup_domain
if request.subdomain.present? && request.subdomain != "www" if ENV["SERVER_MODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
from = request.subdomain.downcase + "." + request.domain.downcase if license = cache_license # request.subdomain.downcase
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase logger.info "Location - " + license.dbschema
if (!@license.nil?) ActiveRecord::Base.establish_connection(website_connection(license))
logger.info "Location - " + @license.dbschema
ActiveRecord::Base.establish_connection(website_connection(@license))
# authenticate_session_token
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
else else
# reconnect_default_db # reconnect_default_db
logger.info 'License is nil' logger.info 'License is nil'
# redirect_to root_url(:host => request.domain) + "store_error" not_found
render :json => [{ status: false, message: 'Invalid Access!'}]
end end
else elsif ENV["SERVER_MODE"] == "application" || request.subdomains.last && request.subdomains.last != "www"
# check for license file # check for license file
# if check_license if !check_license
# current_license(ENV["SX_PROVISION_URL"]) if ENV["SERVER_MODE"] == "application" || check_subdomain
# else redirect_to activate_path
# redirect_to activate_path
# end
end
end
def current_license(url)
@license = License.new(url)
flag = @license.detail_with_local_file()
if (flag == 0)
flash[:notice] = 'Expired or No License!'
elsif (flag == 2)
flash[:notice] = 'Expiring! Please, License extend...'
else else
puts "RUN SAY BYAR" not_found
end
end
else
not_found
end end
end end
def cache_license(url, lookup) def current_license
@license = License.new(url, lookup) @license ||= License.new(ENV["SX_PROVISION_URL"], request.host)
end
if (@license.detail_with_local_cache(lookup) == true) def cache_license
return @license if (current_license.detail_with_local_cache == true)
return current_license
else else
return nil return nil
end end
end end
def check_subdomain
current_license.check_license_subdomain
end
def check_license def check_license
License.check_license_file if License.check_license_file(request.host)
if current_license.expired?
return false
end
return true
end
end end
def check_installation def check_installation
@@ -64,7 +71,6 @@ class ActionController::Base
def website_connection(license) def website_connection(license)
default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase,
:username => license.dbusername, :password => license.dbpassword) :username => license.dbusername, :password => license.dbpassword)
end end
def reconnect_default_db def reconnect_default_db
@@ -89,42 +95,58 @@ class ActionController::Base
end end
class ActionController::API class ActionController::API
before_action :lookup_domain before_action :lookup_domain if Rails.env.production?
def not_found
respond_to do |format|
format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
format.json { head :not_found }
end
end
private private
def lookup_domain def lookup_domain
if request.subdomain.present? && request.subdomain != "www" if ENV["SERVER_CODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
from = request.subdomain.downcase + "." + request.domain.downcase if license = cache_license # request.subdomain.downcase
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase logger.info "Location - " + license.dbschema
if (!@license.nil?) ActiveRecord::Base.establish_connection(website_connection(license))
logger.info "Location - " + @license.dbschema
ActiveRecord::Base.establish_connection(website_connection(@license))
# authenticate_session_token
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
else else
# reconnect_default_db # reconnect_default_db
logger.info 'License is nil' logger.info 'License is nil'
# redirect_to root_url(:host => request.domain) + "store_error" not_found
render :json => [{ status: false, message: 'Invalid Access!'}]
end end
elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www")
not_found unless check_license
else
not_found
end end
end end
def cache_license(url, lookup) def current_license
@license = License.new(url, lookup) @license ||= License.new(ENV["SX_PROVISION_URL"], request.host)
end
if (@license.detail_with_local_cache(lookup) == true) def cache_license
return @license if (current_license.detail_with_local_cache == true)
return current_license
else else
return nil return nil
end end
end end
def check_license
if License.check_license_file(request.host)
if current_license.expired?
return false
end
return true
end
end
def website_connection(license) def website_connection(license)
default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase,
:username => license.dbusername, :password => license.dbpassword) :username => license.dbusername, :password => license.dbpassword)
end end
def reconnect_default_db def reconnect_default_db

17
config/license.yml Normal file
View File

@@ -0,0 +1,17 @@
---
localhost:
iv_key: 03TLQUDDVSOPa/lEEHqhVw==
shop_name: scdemo3
email: hanwintun@code2lab.com
telephone: ''
fax: ''
address: ''
dbhost: gG0jQLrVX6l0dZaA5wVP9bNTrfgzotwAcjcFKQmM9WUQ5121pkwg+9mYh5XDrIwL4//1UNjRR6CNZPorBMGtAw==
dbschema: M9ddWoBb89JN51Ld1r7vTw==
dbusername: 8Lc2lKIyJld/xfG6+ZxcOw==
dbpassword: "+EhtSe5kJuVKp+wFMRlmoA=="
api_token: UQFLAbMvJxUCnDVCOhIdqYZEGRqVQMvI
app_token: DvRXGlomaBFpGVLYsidekVVZyqosntouTA
plan_sku: 2NY6p1HAlR7UqE8AsBEytg==
renewable_date: vlKVqrJyCB6LxXTkv63COg==
plan_name: 6NSPpVHcwHBoFZPcVNjkvD6F5quXIWVaWieCRzpspbE=

View File

@@ -29,6 +29,9 @@ scope "(:locale)", locale: /en|mm/ do
delete 'logout' => 'home#destroy' delete 'logout' => 'home#destroy'
get 'dashboard' => 'home#dashboard' get 'dashboard' => 'home#dashboard'
get 'expire' => 'renew_license#expire'
get 'renew' => 'renew_license#renew'
namespace :induties do namespace :induties do
# resources :assign_in_duties # resources :assign_in_duties
get ':booking_id/assign' => 'assign_in_duties#index', as: :assign_in_duties get ':booking_id/assign' => 'assign_in_duties#index', as: :assign_in_duties

View File

@@ -1049,6 +1049,13 @@
"key": "MdrjwSyyNPqIU+HO3rwsHHSlG6xCKC5y3pQ1ywGbX2k=\n", "key": "MdrjwSyyNPqIU+HO3rwsHHSlG6xCKC5y3pQ1ywGbX2k=\n",
"iv": "8+fEFUROBPpGp23jrRnb3Q==\n" "iv": "8+fEFUROBPpGp23jrRnb3Q==\n"
} }
},
{
"lookup": "localhost",
"value": {
"key": "wyo9gq9KYY0FS1r1+cMmmAGEVGxQ2aTpVjfVYCoC9z4=\n",
"iv": "T2UNnKc4EFLiDiALvjybdg==\n"
}
} }
] ]
} }