From c2095b4a616431007e0ac6a363cffa6de37b50f5 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 15 Nov 2017 17:55:51 +0630 Subject: [PATCH 001/231] adding license activation --- app/controllers/install_controller.rb | 8 ++- app/models/license.rb | 82 +++++++++++++++------------ config/routes.rb | 2 +- 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index cf16adfe..9b4d88c2 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -2,13 +2,19 @@ class InstallController < BaseController def index end - def create + def activate restaurant = params[:restaurant_name] license_key = params[:license_key] admin_user = params[:admin_user] admin_password = params[:admin_password] + db_user = params[:db_user] + db_password = params[:db_password] + + end + + def lookup_domain if request.subdomain.present? && request.subdomain != "www" @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) diff --git a/app/models/license.rb b/app/models/license.rb index 31403038..eb81c142 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -80,6 +80,7 @@ class License if has_license puts "VERIFIED" end + end # if cache_license.nil? # ##change the d/e key @@ -119,26 +120,31 @@ class License # return false end - def detail - response = self.class.get("/subdomain", @options) - @license = response.parsed_response + # def detail + # response = self.class.get("/subdomain", @options) + # @license = response.parsed_response - Rails.logger.debug "License - " + response.parsed_response.to_s + # Rails.logger.debug "License - " + response.parsed_response.to_s - if (@license["status"] == true) - assign() + # if (@license["status"] == true) + # assign() - return true - end + # return true + # end + + # return false + # end + + # License Activation + def license_activate - return false end def verify_license api_token = read_license("api_token") - @options = { query: {lookup_type: "application", token: api_token} } - response = self.class.get("/verify", @options) + @params = { query: {lookup_type: "application", token: api_token} } + response = self.class.get("/verify", @params) @varified = response.parsed_response Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s @@ -152,37 +158,36 @@ class License return false end - def check_remote_license(license_key) - # @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} } - @options = { query: {lookup_type: "application", encrypted_key: @secret, token: SECRETS_CONFIG['provision_key']} } - response = self.class.get("/license", @options) + # def check_remote_license(license_key) + # # @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} } + # @options = { query: {lookup_type: "application", encrypted_key: @secret, token: SECRETS_CONFIG['provision_key']} } + # response = self.class.get("/license", @options) - @license = response.parsed_response + # @license = response.parsed_response - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - if (@license["status"]) - assign() - end - return @license["status"] + # Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s + # if (@license["status"]) + # assign() + # end + # return @license["status"] + # end - end + # def verify_by_api_token(api_token) + # @options = { query: {device: "SX", api_token: api_token, skey: @secret, token: SECRETS_CONFIG['provision_key']} } + # response = self.class.get("/verify_token", @options) - def verify_by_api_token(api_token) - @options = { query: {device: "SX", api_token: api_token, skey: @secret, token: SECRETS_CONFIG['provision_key']} } - response = self.class.get("/verify", @options) + # @license = response.parsed_response - @license = response.parsed_response + # Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s + # if (@license["status"]) + # assign() + # end - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - if (@license["status"]) - assign() - end - - return @license["status"] - end + # return @license["status"] + # end #Load License is remove from the cloud license because - this license is must be validated against subdmain instead of license.data from file. - + # Check License expired date from PROVISION SERVER def check_expired(renewal_date) if (renewal_date < Date.today) return true @@ -191,6 +196,7 @@ class License end end + # Check License File exists def self.check_license_file return File.exist?("config/license.yml") end @@ -209,6 +215,13 @@ class License end private + + # Delete License File + def delete_license_file + File.delete("config/license.yml") if File.exist?("config/license.yml") + end + + # Assign db info for Cloud def assign # self.name = @license["name"] # self.address_1 = @license["address_1"] @@ -228,7 +241,6 @@ class License ## self.plan_activation_date = Date.strptime(@license["plan_activation_date"], "%Y-%m-%d") ## self.plan_next_renewal_date = Date.strptime(@license["plan_next_renewal_date"], "%Y-%m-%d") - # self.plan_max_products = @license["plan_max_products"].to_i # self.plan_max_customers = @license["plan_max_customers"].to_i # self.plan_active_connections = @license["plan_active_connections"].to_i diff --git a/config/routes.rb b/config/routes.rb index 64f68262..a44cc1c4 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ scope "(:locale)", locale: /en|mm/ do #--------- SmartSales Installation ------------# get 'install' => 'install#index' - post 'install' => 'install#create' + post 'install' => 'install#activate' #--------- Login/Authentication ------------# get 'auth/:emp_id' => 'home#show', as: :emp_login From b1f98df4e07c10ead078dc9fa3f4a7747acc034a Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 15 Nov 2017 19:10:56 +0630 Subject: [PATCH 002/231] add activation in license --- app/controllers/install_controller.rb | 9 +++-- app/models/license.rb | 50 ++++++++++++++++++++++----- config/license.yml | 2 -- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 9b4d88c2..ab321481 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -10,11 +10,14 @@ class InstallController < BaseController db_user = params[:db_user] db_password = params[:db_password] - + # Export for Key + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(lookup) + + @license = License.new(ENV["SX_PROVISION_URL"]) + @license.license_activate(aes_key, aes_iv, license_key) end - - def lookup_domain if request.subdomain.present? && request.subdomain != "www" @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) diff --git a/app/models/license.rb b/app/models/license.rb index eb81c142..182edecd 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -23,13 +23,13 @@ class License # @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } } end - def shop_code - if ( self.subdomain.length > 3) - return self.subdomain[0,3].upcase - else - return self.subdomain.upcase - end - end + # def shop_code + # if ( self.subdomain.length > 3) + # return self.subdomain[0,3].upcase + # else + # return self.subdomain.upcase + # end + # end def detail_with_local_cache(lookup, key, iv) ##Check from local redis - if available load local otherwise get from remote @@ -137,8 +137,18 @@ class License # end # License Activation - def license_activate + def license_activate (key, iv, license_key) + @params = { query: { lookup_type: self.server_mode, encrypted_key: key, iv_key: iv, license_key: license_key } } + response = self.class.get("/activate", @params) + @activate = response.parsed_response + Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s + + if (@activate["status"]) + return create_license_file(@activate) + else + response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} + end end def verify_license @@ -216,6 +226,30 @@ class License private + # License File Creation + def create_license_file(response_data) + if check_license_file + delete_license_file + end + + begin + # Licese File Creation + f = File.open("config/license.yml", "w") + f.write("name: #{response_data['name']}\n") + f.write("shopname: #{response_data['shopname']}\n") + f.write("dbhost: #{response_data['dbhost']}\n") + f.write("dbschema: #{response_data['dbschema']}\n") + f.write("dbusername: #{response_data['dbusername']}\n") + f.write("dbpassword: #{response_data['dbpassword']}\n") + f.write("api_token: #{response_data['api_token']}\n") + f.write("app_token: #{response_data['app_token']}\n") + f.close + rescue IOError + response = { "status": false, "message": "Can't create license file. Please contact code2lab call center!"} + end + response = { "status": true, "message": "License created"} + end + # Delete License File def delete_license_file File.delete("config/license.yml") if File.exist?("config/license.yml") diff --git a/config/license.yml b/config/license.yml index f98a6e81..e0f6bf7d 100644 --- a/config/license.yml +++ b/config/license.yml @@ -1,5 +1,4 @@ development: - server_mode: cloud license_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk @@ -9,6 +8,5 @@ test: # Do not keep production secrets in the repository, # instead read values from the environment. production: - server_mode: cloud license_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk From 178b3484bed6704b558a566b9404ffa6f1d59d87 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 16 Nov 2017 16:13:26 +0630 Subject: [PATCH 003/231] added license --- app/controllers/application_controller.rb | 2 +- app/controllers/install_controller.rb | 71 +++--- app/models/license.rb | 79 ++++++- app/views/install/_form.html.erb | 12 +- app/views/layouts/login_dashboard.html.erb | 2 +- config/initializers/license.rb | 8 +- config/license.yml | 12 - config/routes.rb | 6 +- config/secrets.yml | 2 +- db/sym_master.sql | 254 +++++++++++---------- 10 files changed, 264 insertions(+), 184 deletions(-) delete mode 100644 config/license.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 83222004..2163d885 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -110,7 +110,7 @@ class ApplicationController < ActionController::Base if License.check_license_file return true else - redirect_to install_path + redirect_to activate_path end end end diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index ab321481..870a10e0 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,12 +1,16 @@ class InstallController < BaseController + before_action :check_license + def index end def activate restaurant = params[:restaurant_name] license_key = params[:license_key] - admin_user = params[:admin_user] - admin_password = params[:admin_password] + # admin_user = params[:admin_user] + # admin_password = params[:admin_password] + db_host = params[:db_host] + db_schema = params[:db_schema] db_user = params[:db_user] db_password = params[:db_password] @@ -15,37 +19,48 @@ class InstallController < BaseController aes_key, aes_iv = aes.export_key(lookup) @license = License.new(ENV["SX_PROVISION_URL"]) - @license.license_activate(aes_key, aes_iv, license_key) + response = @license.license_activate(aes_key, aes_iv, license_key, db_host, db_schema, db_user, db_password) + if response["status"] + redirect_to root_url, notice: response["message"] + else + redirect_to activate_path, notice: response["message"] + 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 + def check_license + if License.check_license_file + redirect_to root_url end end - def current_license(url, key) - @license = License.new(url, key) + # 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 - ##creating md5 hash - md5_hostname = Digest::MD5.new - md5key = md5_hostname.update(request.host) - if (@license.detail_with_local_cache(key, md5key.to_s) == true) - #if (@license.detail == true) + # def current_license(url, key) + # @license = License.new(url, key) - return @license - else - return nil - end - end + # ##creating md5 hash + # md5_hostname = Digest::MD5.new + # md5key = md5_hostname.update(request.host) + # if (@license.detail_with_local_cache(key, md5key.to_s) == true) + # #if (@license.detail == true) + + # return @license + # else + # return nil + # end + # end end diff --git a/app/models/license.rb b/app/models/license.rb index 182edecd..c75eded5 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -75,7 +75,7 @@ class License def detail_with_local_file() - has_license = true #verify_license() + has_license = verify_license() if has_license puts "VERIFIED" @@ -118,7 +118,7 @@ class License # end # end # return false - end + #end # def detail # response = self.class.get("/subdomain", @options) @@ -137,7 +137,7 @@ class License # end # License Activation - def license_activate (key, iv, license_key) + def license_activate (key, iv, license_key, db_host, db_schema, db_user, db_password) @params = { query: { lookup_type: self.server_mode, encrypted_key: key, iv_key: iv, license_key: license_key } } response = self.class.get("/activate", @params) @activate = response.parsed_response @@ -145,10 +145,15 @@ class License Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s if (@activate["status"]) - return create_license_file(@activate) + response = create_license_file(@activate) + if(response["status"]) + sym_path = "/home/yan/symmetric/engines" + response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) + end else response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} end + return response end def verify_license @@ -218,7 +223,7 @@ class License File.open("config/license.yml").each do |line| if line.include? (key) decrypted_line_array = line.split(":") - decrypted_line = AESCrypt.decrypt(decrypted_line_array[1]) + decrypted_line = AESCrypt.decrypt_data(decrypted_line_array[1], ENV['AES_KEY'], ENV['AES_IV'], ENV['CIPHER_TYPE']) end end end @@ -236,7 +241,12 @@ class License # Licese File Creation f = File.open("config/license.yml", "w") f.write("name: #{response_data['name']}\n") - f.write("shopname: #{response_data['shopname']}\n") + f.write("iv_key: #{response_data['iv_key']}\n") + f.write("shop_name: #{response_data['shop_name']}\n") + f.write("email: #{response_data['email']}\n") + f.write("telephone: #{response_data['telephone']}\n") + f.write("fax: #{response_data['fax']}\n") + f.write("address: #{response_data['address']}\n") f.write("dbhost: #{response_data['dbhost']}\n") f.write("dbschema: #{response_data['dbschema']}\n") f.write("dbusername: #{response_data['dbusername']}\n") @@ -245,9 +255,62 @@ class License f.write("app_token: #{response_data['app_token']}\n") f.close rescue IOError - response = { "status": false, "message": "Can't create license file. Please contact code2lab call center!"} + response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} + end + response = { "status": true, "message": "Success Activation. License also created."} + end + + # Symmetric Configuration + def create_symmetric_config(sym_location, db_host, db_schema, db_user, db_password) + if File.directory? (sym_location) + begin + # sx properties create + f = File.open(sym_location + "/sx.properties", "w") + f.write("engine.name=sx\n") + f.write("db.driver=com.mysql.jdbc.Driver\n") + f.write("db.url=jdbc:mysql://#{db_host}/#{db_schema}?tinyInt1isBit=false\n") + f.write("db.user=#{db_user}\n") + f.write("db.password=#{db_password}\n") + f.write("registration.url=\n") + f.write("sync.url=http://#{db_host}:31415/sync/sx\n") + f.write("group.id=sx\n") + f.write("external.id=000\n") + f.write("job.purge.period.time.ms=7200000\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + f.write("initial.load.create.first=true\n") + f.write("initial.load.use.extract.job.enabled=true\n") + f.close + + # read from license file + shop_name = read_license("shop_name") + dbhost = read_license("dbhost") + dbschema = read_license("dbschema") + dbusername = read_license("dbusername") + dbpassword = read_license("dbpassword") + + # shop properties create + f = File.open(sym_location + "/#{shop_name}.properties", "w") + f.write("engine.name=#{shop_name}\n") + f.write("db.driver=com.mysql.jdbc.Driver\n") + f.write("db.url=jdbc:mysql://#{dbhost}/#{dbschema}?tinyInt1isBit=false\n") + f.write("db.user=#{dbusername}\n") + f.write("db.password=#{dbpassword}\n") + f.write("registration.url=http://#{db_host}:31415/sync/sx\n") + f.write("group.id=store\n") + f.write("external.id=001\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + # f.write("initial.load.create.first=true\n") + # f.write("initial.load.use.extract.job.enabled=true\n") + f.close + rescue IOError + response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} + end + response = { "status": true, "message": "Success Activation. License also created."} end - response = { "status": true, "message": "License created"} end # Delete License File diff --git a/app/views/install/_form.html.erb b/app/views/install/_form.html.erb index 288c431a..5127862c 100755 --- a/app/views/install/_form.html.erb +++ b/app/views/install/_form.html.erb @@ -10,7 +10,7 @@ Add License Key from Email -
+
+
+ + +
+
+ + +
diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index d0d2cddd..e38d56f1 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -70,7 +70,7 @@
- +
diff --git a/config/initializers/license.rb b/config/initializers/license.rb index edb075ea..e329f313 100644 --- a/config/initializers/license.rb +++ b/config/initializers/license.rb @@ -1,4 +1,6 @@ -config = YAML.load_file(Rails.root.join("config/license.yml")) -config.fetch(Rails.env, {}).each do |key, value| - ENV[key.upcase] = value.to_s +if File.exist?("config/license.yml") + config = YAML.load_file(Rails.root.join("config/license.yml")) + config.fetch(Rails.env, {}).each do |key, value| + ENV[key.upcase] = value.to_s + end end \ No newline at end of file diff --git a/config/license.yml b/config/license.yml deleted file mode 100644 index e0f6bf7d..00000000 --- a/config/license.yml +++ /dev/null @@ -1,12 +0,0 @@ -development: - license_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk - - -test: - sx_provision_url: "provision.test.ws/api" - -# Do not keep production secrets in the repository, -# instead read values from the environment. -production: - license_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk - diff --git a/config/routes.rb b/config/routes.rb index a44cc1c4..56aa8d23 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,9 +9,9 @@ scope "(:locale)", locale: /en|mm/ do # Action Cable Creation mount ActionCable.server => "/cable" - #--------- SmartSales Installation ------------# - get 'install' => 'install#index' - post 'install' => 'install#activate' + #--------- SmartSales Activation ------------# + get 'activate' => 'install#index' + post 'activate' => 'install#activate' #--------- Login/Authentication ------------# get 'auth/:emp_id' => 'home#show', as: :emp_login diff --git a/config/secrets.yml b/config/secrets.yml index 09555540..28814f4d 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,7 +12,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: provision.zsai.ws/api #192.168.1.94:3002 + sx_provision_url: 192.168.1.94:3002 #provision.zsai.ws/api server_mode: cloud cipher_type: AES-256-CBC aes_key: <%= ENV['AES_KEY'] %> diff --git a/db/sym_master.sql b/db/sym_master.sql index 6b392f58..f070761b 100755 --- a/db/sym_master.sql +++ b/db/sym_master.sql @@ -23,8 +23,8 @@ -- Sample Data ------------------------------------------------------------------------------ -- insert into item (item_id, name) values (11000001, 'Yummy Gum'); --- insert into item_selling_price (item_id, store_id, price, cost) values (11000001, '001',0.20, 0.10); --- insert into item_selling_price (item_id, store_id, price, cost) values (11000001, '002',0.30, 0.20); +-- insert into item_selling_price (item_id, cloud_id, price, cost) values (11000001, '001',0.20, 0.10); +-- insert into item_selling_price (item_id, cloud_id, price, cost) values (11000001, '002',0.30, 0.20); -- insert into sale_transaction (tran_id, store_id, workstation, day, seq) -- values (900, '001', '3', '2012-12-01', 90); @@ -48,6 +48,10 @@ delete from sym_node; # Create Channels for logically grouped tables + # For Initial Data Faster by bulk + update sym_channel set data_loader_type='mysql_bulk', max_batch_size=100000, max_data_to_route=100000 + where channel_id = 'reload'; + insert into sym_channel (channel_id, processing_order, max_batch_size, enabled, description) values('setting', 1, 100000, 1, 'All Settings'); @@ -305,466 +309,466 @@ delete from sym_node; # Create Routers for Nodes insert into sym_router (router_id,source_node_group_id,target_node_group_id,router_type,create_time,last_update_time) - values('sx_2_store', 'sx', 'store', 'default',current_timestamp, current_timestamp); + values('sx_2_cloud', 'sx', 'cloud', 'default',current_timestamp, current_timestamp); insert into sym_router (router_id,source_node_group_id,target_node_group_id,router_type,sync_on_delete,create_time,last_update_time) - values('store_2_sx', 'store', 'sx', 'default',0,current_timestamp, current_timestamp); + values('cloud_2_sx', 'cloud', 'sx', 'default',0,current_timestamp, current_timestamp); -- insert into sym_router -- (router_id,source_node_group_id,target_node_group_id,router_type,router_expression,create_time,last_update_time) --- values('sx_2_one_store', 'sx', 'store', 'column','STORE_ID=:EXTERNAL_ID or OLD_STORE_ID=:EXTERNAL_ID',current_timestamp, current_timestamp); +-- values('sx_2_one_cloud', 'sx', 'cloud', 'column','cloud_ID=:EXTERNAL_ID or OLD_cloud_ID=:EXTERNAL_ID',current_timestamp, current_timestamp); # Add triggers for tables with router -# Setting Channel # From Store to Master +# Setting Channel # From cloud to Master insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('lookups','store_2_sx', 100, current_timestamp, current_timestamp); + values('lookups','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('membership_actions','store_2_sx', 100, current_timestamp, current_timestamp); + values('membership_actions','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('membership_settings','store_2_sx', 100, current_timestamp, current_timestamp); + values('membership_settings','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('payment_method_settings','store_2_sx', 100, current_timestamp, current_timestamp); + values('payment_method_settings','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('print_settings','store_2_sx', 100, current_timestamp, current_timestamp); + values('print_settings','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('shops','store_2_sx', 100, current_timestamp, current_timestamp); + values('shops','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('customers','store_2_sx', 100, current_timestamp, current_timestamp); + values('customers','cloud_2_sx', 100, current_timestamp, current_timestamp); -# Setting Channel # From Master to Store +# Setting Channel # From Master to cloud insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('lookups','sx_2_store', 100, current_timestamp, current_timestamp); + values('lookups','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('membership_actions','sx_2_store', 100, current_timestamp, current_timestamp); + values('membership_actions','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('membership_settings','sx_2_store', 100, current_timestamp, current_timestamp); + values('membership_settings','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('payment_method_settings','sx_2_store', 100, current_timestamp, current_timestamp); + values('payment_method_settings','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('print_settings','sx_2_store', 100, current_timestamp, current_timestamp); + values('print_settings','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('shops','sx_2_store', 100, current_timestamp, current_timestamp); + values('shops','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('customers','sx_2_store', 100, current_timestamp, current_timestamp); + values('customers','sx_2_cloud', 100, current_timestamp, current_timestamp); #End Setting Channel -# Dining Channel # From Store to SX +# Dining Channel # From cloud to SX insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('zones','store_2_sx', 100, current_timestamp, current_timestamp); + values('zones','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('dining_charges','store_2_sx', 100, current_timestamp, current_timestamp); + values('dining_charges','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('dining_facilities','store_2_sx', 100, current_timestamp, current_timestamp); + values('dining_facilities','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('dining_queues','store_2_sx', 100, current_timestamp, current_timestamp); + values('dining_queues','cloud_2_sx', 100, current_timestamp, current_timestamp); -# Dining Channel # From SX to Store +# Dining Channel # From SX to cloud insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('zones','sx_2_store', 100, current_timestamp, current_timestamp); + values('zones','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('dining_charges','sx_2_store', 100, current_timestamp, current_timestamp); + values('dining_charges','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('dining_facilities','sx_2_store', 100, current_timestamp, current_timestamp); + values('dining_facilities','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('dining_queues','sx_2_store', 100, current_timestamp, current_timestamp); + values('dining_queues','sx_2_cloud', 100, current_timestamp, current_timestamp); #end Dining Channel -# Commission/Promotion/Product Channel # From Store to SX +# Commission/Promotion/Product Channel # From cloud to SX insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('commissioners','store_2_sx', 100, current_timestamp, current_timestamp); + values('commissioners','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('commissions','store_2_sx', 100, current_timestamp, current_timestamp); + values('commissions','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('employees','store_2_sx', 100, current_timestamp, current_timestamp); + values('employees','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('in_duties','store_2_sx', 100, current_timestamp, current_timestamp); + values('in_duties','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('inventory_definitions','store_2_sx', 100, current_timestamp, current_timestamp); + values('inventory_definitions','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('product_commissions','store_2_sx', 100, current_timestamp, current_timestamp); + values('product_commissions','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('products','store_2_sx', 100, current_timestamp, current_timestamp); + values('products','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('promotion_products','store_2_sx', 100, current_timestamp, current_timestamp); + values('promotion_products','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('promotions','store_2_sx', 100, current_timestamp, current_timestamp); + values('promotions','cloud_2_sx', 100, current_timestamp, current_timestamp); -# Commission/Promotion/Product Channel # From SX to Store +# Commission/Promotion/Product Channel # From SX to cloud insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('commissioners','sx_2_store', 100, current_timestamp, current_timestamp); + values('commissioners','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('commissions','sx_2_store', 100, current_timestamp, current_timestamp); + values('commissions','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('employees','sx_2_store', 100, current_timestamp, current_timestamp); + values('employees','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('in_duties','sx_2_store', 100, current_timestamp, current_timestamp); + values('in_duties','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('inventory_definitions','sx_2_store', 100, current_timestamp, current_timestamp); + values('inventory_definitions','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('product_commissions','sx_2_store', 100, current_timestamp, current_timestamp); + values('product_commissions','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('products','sx_2_store', 100, current_timestamp, current_timestamp); + values('products','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('promotion_products','sx_2_store', 100, current_timestamp, current_timestamp); + values('promotion_products','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('promotions','sx_2_store', 100, current_timestamp, current_timestamp); + values('promotions','sx_2_cloud', 100, current_timestamp, current_timestamp); #end Commission/Promotion/Product Channel -# Menu Channel # From Store to SX +# Menu Channel # From cloud to SX insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('accounts','store_2_sx', 100, current_timestamp, current_timestamp); + values('accounts','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_item_attributes','store_2_sx', 100, current_timestamp, current_timestamp); + values('menu_item_attributes','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_item_options','store_2_sx', 100, current_timestamp, current_timestamp); + values('menu_item_options','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menus','store_2_sx', 100, current_timestamp, current_timestamp); + values('menus','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_categories','store_2_sx', 100, current_timestamp, current_timestamp); + values('menu_categories','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_items','store_2_sx', 100, current_timestamp, current_timestamp); + values('menu_items','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_item_instances','store_2_sx', 100, current_timestamp, current_timestamp); + values('menu_item_instances','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('item_sets','store_2_sx', 100, current_timestamp, current_timestamp); + values('item_sets','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_item_sets','store_2_sx', 100, current_timestamp, current_timestamp); + values('menu_item_sets','cloud_2_sx', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_instance_item_sets','store_2_sx', 100, current_timestamp, current_timestamp); + values('menu_instance_item_sets','cloud_2_sx', 100, current_timestamp, current_timestamp); -# Menu Channel # From SX to Store +# Menu Channel # From SX to cloud insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('accounts','sx_2_store', 100, current_timestamp, current_timestamp); + values('accounts','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_item_attributes','sx_2_store', 100, current_timestamp, current_timestamp); + values('menu_item_attributes','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_item_options','sx_2_store', 100, current_timestamp, current_timestamp); + values('menu_item_options','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menus','sx_2_store', 100, current_timestamp, current_timestamp); + values('menus','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_categories','sx_2_store', 100, current_timestamp, current_timestamp); + values('menu_categories','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_items','sx_2_store', 100, current_timestamp, current_timestamp); + values('menu_items','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_item_instances','sx_2_store', 100, current_timestamp, current_timestamp); + values('menu_item_instances','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('item_sets','sx_2_store', 100, current_timestamp, current_timestamp); + values('item_sets','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_item_sets','sx_2_store', 100, current_timestamp, current_timestamp); + values('menu_item_sets','sx_2_cloud', 100, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('menu_instance_item_sets','sx_2_store', 100, current_timestamp, current_timestamp); + values('menu_instance_item_sets','sx_2_cloud', 100, current_timestamp, current_timestamp); #End Menu Channel -# Order Channel # From Store to Sx +# Order Channel # From cloud to Sx insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('orders','store_2_sx', 200, current_timestamp, current_timestamp); + values('orders','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('order_items','store_2_sx', 200, current_timestamp, current_timestamp); + values('order_items','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('bookings','store_2_sx', 200, current_timestamp, current_timestamp); + values('bookings','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('booking_orders','store_2_sx', 200, current_timestamp, current_timestamp); + values('booking_orders','cloud_2_sx', 200, current_timestamp, current_timestamp); -# Order Channel # From SX to Store +# Order Channel # From SX to cloud insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('orders','sx_2_store', 200, current_timestamp, current_timestamp); + values('orders','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('order_items','sx_2_store', 200, current_timestamp, current_timestamp); + values('order_items','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('bookings','sx_2_store', 200, current_timestamp, current_timestamp); + values('bookings','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('booking_orders','sx_2_store', 200, current_timestamp, current_timestamp); + values('booking_orders','sx_2_cloud', 200, current_timestamp, current_timestamp); # End Order Channel -# Sale Channel # From Store to Sx +# Sale Channel # From cloud to Sx insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sales','store_2_sx', 200, current_timestamp, current_timestamp); + values('sales','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_items','store_2_sx', 200, current_timestamp, current_timestamp); + values('sale_items','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_audits','store_2_sx', 200, current_timestamp, current_timestamp); + values('sale_audits','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_orders','store_2_sx', 200, current_timestamp, current_timestamp); + values('sale_orders','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_payments','store_2_sx', 200, current_timestamp, current_timestamp); + values('sale_payments','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_taxes','store_2_sx', 200, current_timestamp, current_timestamp); + values('sale_taxes','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('payment_journals','store_2_sx', 200, current_timestamp, current_timestamp); + values('payment_journals','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('shift_sales','store_2_sx', 200, current_timestamp, current_timestamp); + values('shift_sales','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('stock_check_items','store_2_sx', 200, current_timestamp, current_timestamp); + values('stock_check_items','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('stock_checks','store_2_sx', 200, current_timestamp, current_timestamp); + values('stock_checks','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('stock_journals','store_2_sx', 200, current_timestamp, current_timestamp); + values('stock_journals','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('surveys','store_2_sx', 200, current_timestamp, current_timestamp); + values('surveys','cloud_2_sx', 200, current_timestamp, current_timestamp); -# Sale Channel # From SX to Store +# Sale Channel # From SX to cloud insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sales','sx_2_store', 200, current_timestamp, current_timestamp); + values('sales','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_items','sx_2_store', 200, current_timestamp, current_timestamp); + values('sale_items','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_audits','sx_2_store', 200, current_timestamp, current_timestamp); + values('sale_audits','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_orders','sx_2_store', 200, current_timestamp, current_timestamp); + values('sale_orders','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_payments','sx_2_store', 200, current_timestamp, current_timestamp); + values('sale_payments','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('sale_taxes','sx_2_store', 200, current_timestamp, current_timestamp); + values('sale_taxes','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('payment_journals','sx_2_store', 200, current_timestamp, current_timestamp); + values('payment_journals','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('shift_sales','sx_2_store', 200, current_timestamp, current_timestamp); + values('shift_sales','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('stock_check_items','sx_2_store', 200, current_timestamp, current_timestamp); + values('stock_check_items','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('stock_checks','sx_2_store', 200, current_timestamp, current_timestamp); + values('stock_checks','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('stock_journals','sx_2_store', 200, current_timestamp, current_timestamp); + values('stock_journals','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('surveys','sx_2_store', 200, current_timestamp, current_timestamp); + values('surveys','sx_2_cloud', 200, current_timestamp, current_timestamp); # End Sale Channel -# Oqs Channel # From Store to Sx +# Oqs Channel # From cloud to Sx insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('assigned_order_items','store_2_sx', 200, current_timestamp, current_timestamp); + values('assigned_order_items','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('cashier_terminals','store_2_sx', 200, current_timestamp, current_timestamp); + values('cashier_terminals','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('cashier_terminal_by_zones','store_2_sx', 200, current_timestamp, current_timestamp); + values('cashier_terminal_by_zones','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('cashier_login_logs','store_2_sx', 200, current_timestamp, current_timestamp); + values('cashier_login_logs','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('order_queue_process_by_zones','store_2_sx', 200, current_timestamp, current_timestamp); + values('order_queue_process_by_zones','cloud_2_sx', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('order_queue_stations','store_2_sx', 200, current_timestamp, current_timestamp); + values('order_queue_stations','cloud_2_sx', 200, current_timestamp, current_timestamp); -# Oqs Channel # From SX to Store +# Oqs Channel # From SX to cloud insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('assigned_order_items','sx_2_store', 200, current_timestamp, current_timestamp); + values('assigned_order_items','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('cashier_terminals','sx_2_store', 200, current_timestamp, current_timestamp); + values('cashier_terminals','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('cashier_terminal_by_zones','sx_2_store', 200, current_timestamp, current_timestamp); + values('cashier_terminal_by_zones','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('cashier_login_logs','sx_2_store', 200, current_timestamp, current_timestamp); + values('cashier_login_logs','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('order_queue_process_by_zones','sx_2_store', 200, current_timestamp, current_timestamp); + values('order_queue_process_by_zones','sx_2_cloud', 200, current_timestamp, current_timestamp); insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time) - values('order_queue_stations','sx_2_store', 200, current_timestamp, current_timestamp); + values('order_queue_stations','sx_2_cloud', 200, current_timestamp, current_timestamp); # End Oqs Channel insert into sym_node (node_id,node_group_id,external_id,sync_enabled,sync_url,schema_version,symmetric_version,database_type,database_version,heartbeat_time,timezone_offset,batch_to_send_count,batch_in_error_count,created_at_node_id) values ('000','sx','000',1,null,null,null,null,null,current_timestamp,null,0,0,'000'); insert into sym_node (node_id,node_group_id,external_id,sync_enabled,sync_url,schema_version,symmetric_version,database_type,database_version,heartbeat_time,timezone_offset,batch_to_send_count,batch_in_error_count,created_at_node_id) - values ('001','store','001',1,null,null,null,null,null,current_timestamp,null,0,0,'000'); + values ('001','cloud','001',1,null,null,null,null,null,current_timestamp,null,0,0,'000'); -- insert into sym_node (node_id,node_group_id,external_id,sync_enabled,sync_url,schema_version,symmetric_version,database_type,database_version,heartbeat_time,timezone_offset,batch_to_send_count,batch_in_error_count,created_at_node_id) --- values ('002','store','002',1,null,null,null,null,null,current_timestamp,null,0,0,'000'); +-- values ('002','cloud','002',1,null,null,null,null,null,current_timestamp,null,0,0,'000'); insert into sym_node_security (node_id,node_password,registration_enabled,registration_time,initial_load_enabled,initial_load_time,created_at_node_id) From 29322d952e23360ac522bbd14e32aa364656c575 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 16 Nov 2017 20:46:03 +0630 Subject: [PATCH 004/231] license cloud done --- app/controllers/application_controller.rb | 15 ++++-- app/controllers/install_controller.rb | 2 +- app/models/license.rb | 59 +++++++++++++++-------- app/models/my_aes_crypt.rb | 16 ++++-- config/secrets.yml | 2 +- 5 files changed, 64 insertions(+), 30 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2163d885..91103651 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,8 +22,8 @@ class ApplicationController < ActionController::Base { locale: I18n.locale } end - def lookup_domain - if request.subdomain.present? && request.subdomain != "www" + def lookup_domain + if request.subdomain.present? && request.subdomain != "www" @license = cache_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) # request.subdomain.downcase if (!@license.nil?) # logger.info "Location - " + @license.name @@ -54,10 +54,17 @@ class ApplicationController < ActionController::Base end def cache_license(url, lookup) + flag = ENV["AES_IV"] @license = License.new(url, lookup) # Export for Key - aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(lookup) + + if flag == "<%= ENV['AES_IV'] %>" + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(lookup) + else + aes_key = ENV["AES_KEY"] + aes_iv = ENV["AES_IV"] + end if (@license.detail_with_local_cache(lookup, aes_key, aes_iv) == true) return @license diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 870a10e0..52ecc296 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -16,7 +16,7 @@ class InstallController < BaseController # Export for Key aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(lookup) + aes_key, aes_iv = aes.export_key(license_key) @license = License.new(ENV["SX_PROVISION_URL"]) response = @license.license_activate(aes_key, aes_iv, license_key, db_host, db_schema, db_user, db_password) diff --git a/app/models/license.rb b/app/models/license.rb index c75eded5..32f1b48a 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -41,9 +41,11 @@ class License cache_license = nil ##Get redis connection from connection pool - Redis.current do |conn| - cache_license = conn.get(cache_key) - end + redis = Redis.new + cache_license = redis.get(cache_key) + # Redis.current do |conn| + # cache_license = conn.get(cache_key) + # end Rails.logger.info "Cache key - " + cache_key.to_s if cache_license.nil? @@ -54,22 +56,27 @@ class License @license = response.parsed_response if (@license["status"] == true) - assign() Rails.logger.info "License - " + response.parsed_response.to_s - - Redis.current do |conn| - ##Remote - store the remote response in local redis cache - conn.set(cache_key, Marshal.dump(@license)) - ##ADD to List to remove later - conn.sadd("License:cache:keys", cache_key) - end + + redis = Redis.new + redis.set(cache_key, Marshal.dump(@license)) + # redis.sadd("License:cache:keys", cache_key) + # Redis.current do |conn| + # ##Remote - store the remote response in local redis cache + # conn.set(cache_key, Marshal.dump(@license)) + # ##ADD to List to remove later + # conn.sadd("License:cache:keys", cache_key) + # end return true end - - Rails.logger.info 'API License' + else + @license = Marshal.load(cache_license) + assign() + Rails.logger.info 'API License' + return true end end @@ -223,7 +230,7 @@ class License File.open("config/license.yml").each do |line| if line.include? (key) decrypted_line_array = line.split(":") - decrypted_line = AESCrypt.decrypt_data(decrypted_line_array[1], ENV['AES_KEY'], ENV['AES_IV'], ENV['CIPHER_TYPE']) + decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE']) end end end @@ -231,6 +238,10 @@ class License private + def decode_str(str) + return Base64.decode64(str) + end + # License File Creation def create_license_file(response_data) if check_license_file @@ -341,13 +352,21 @@ class License # self.plan_max_products = @license["plan_max_products"].to_i # self.plan_max_customers = @license["plan_max_customers"].to_i # self.plan_active_connections = @license["plan_active_connections"].to_i - salt = @license["secret_key"] + # salt = @license["secret_key"] - if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] ) - self.dbhost = AESCrypt.decrypt(@license["dbhost"], salt) - self.dbschema = AESCrypt.decrypt(@license["dbschema"], salt) - self.dbusername = AESCrypt.decrypt(@license["dbusername"], salt) - self.dbpassword = AESCrypt.decrypt(@license["dbpassword"], salt) + key = Base64.decode64(ENV['AES_KEY']) + iv = Base64.decode64(ENV['AES_IV']) + + if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] ) + host = Base64.decode64(@license["dbhost"]) + dbschema = Base64.decode64(@license["dbschema"]) + dbusername = Base64.decode64(@license["dbusername"]) + dbpassword = Base64.decode64(@license["dbpassword"]) + + self.dbhost = AESCrypt.decrypt_data(host, key, iv, ENV['CIPHER_TYPE']) + self.dbschema = AESCrypt.decrypt_data(dbschema, key, iv, ENV['CIPHER_TYPE']) + self.dbusername = AESCrypt.decrypt_data(dbusername, key, iv, ENV['CIPHER_TYPE']) + self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE']) end # self.exchange_unqiue_id = @license["exchange_unqiue_id"] diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index 7427a000..acba4974 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -1,3 +1,6 @@ +require 'openssl' +require 'base64' + class MyAesCrypt @cipher = "" @@ -7,11 +10,16 @@ class MyAesCrypt def export_key(passphrase) # We want a 256 bit key symetric key based on passphrase + # for cloud is lookup + # for local is license_key + # iv_salt = passphrase+"c2l" digest = Digest::SHA256.new - key = digest.update(passphrase) - key = digest.digest - ENV['AES_KEY'] = cipher_key = key # stores the key in key, and also sets the generated key on the @cipher - ENV['AES_IV'] = cipher_iv = @cipher.random_iv # stores the iv in iv, and also sets the generated iv on the @cipher + key_digest = digest.update(passphrase) + # iv_digest = digest.update(iv_salt) + key = key_digest.digest + # iv = iv_digest.digest + ENV['AES_KEY'] = cipher_key = Base64.encode64(key) # stores the key in key, and also sets the generated key on the @cipher + ENV['AES_IV'] = cipher_iv = Base64.encode64(@cipher.random_iv) # stores the iv in iv, and also sets the generated iv on the @cipher return cipher_key, cipher_iv end diff --git a/config/secrets.yml b/config/secrets.yml index 28814f4d..53d90c23 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,7 +12,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: 192.168.1.94:3002 #provision.zsai.ws/api + sx_provision_url: 192.168.1.94:3002/api #provision.zsai.ws/api server_mode: cloud cipher_type: AES-256-CBC aes_key: <%= ENV['AES_KEY'] %> From 68a0f7eca3bcd1c5b78febc1096c6dae97c228c3 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 17 Nov 2017 13:32:49 +0630 Subject: [PATCH 005/231] license sym config --- app/models/license.rb | 107 +++++------------------------------------- 1 file changed, 12 insertions(+), 95 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index 32f1b48a..c4b9cdd2 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -21,15 +21,7 @@ class License # @secret = ENV["aes_key"] # @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } } - end - - # def shop_code - # if ( self.subdomain.length > 3) - # return self.subdomain[0,3].upcase - # else - # return self.subdomain.upcase - # end - # end + end def detail_with_local_cache(lookup, key, iv) ##Check from local redis - if available load local otherwise get from remote @@ -87,61 +79,7 @@ class License if has_license puts "VERIFIED" end - end - - # if cache_license.nil? - # ##change the d/e key - # @params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} } - - # response = self.class.get("/request_license", @params) - # @license = response.parsed_response - - # if (@license["status"] == true) - - # assign() - - # Rails.logger.info "License - " + response.parsed_response.to_s - - # Redis.current do |conn| - # ##Remote - store the remote response in local redis cache - # conn.set(cache_key, Marshal.dump(@license)) - # ##ADD to List to remove later - # conn.sadd("License:cache:keys", cache_key) - # end - - # return true - # end - - # Rails.logger.info 'API License' - - # else - # @license = Marshal.load(cache_license) if cache_license - - # Rails.logger.info 'Cache License' - - # if (@license["status"] == true) - # assign() - # return true - # end - # end - # return false - #end - - # def detail - # response = self.class.get("/subdomain", @options) - # @license = response.parsed_response - - # Rails.logger.debug "License - " + response.parsed_response.to_s - - - # if (@license["status"] == true) - # assign() - - # return true - # end - - # return false - # end + end # License Activation def license_activate (key, iv, license_key, db_host, db_schema, db_user, db_password) @@ -154,8 +92,11 @@ class License if (@activate["status"]) response = create_license_file(@activate) if(response["status"]) - sym_path = "/home/yan/symmetric/engines" + sym_path = "/home/yan/symmetric/" response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) + if(response["status"]) + run_symmetric(sym_path) + end end else response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} @@ -180,35 +121,6 @@ class License return false end - # def check_remote_license(license_key) - # # @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} } - # @options = { query: {lookup_type: "application", encrypted_key: @secret, token: SECRETS_CONFIG['provision_key']} } - # response = self.class.get("/license", @options) - - # @license = response.parsed_response - - # Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - # if (@license["status"]) - # assign() - # end - # return @license["status"] - # end - - # def verify_by_api_token(api_token) - # @options = { query: {device: "SX", api_token: api_token, skey: @secret, token: SECRETS_CONFIG['provision_key']} } - # response = self.class.get("/verify_token", @options) - - # @license = response.parsed_response - - # Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - # if (@license["status"]) - # assign() - # end - - # return @license["status"] - # end - #Load License is remove from the cloud license because - this license is must be validated against subdmain instead of license.data from file. - # Check License expired date from PROVISION SERVER def check_expired(renewal_date) if (renewal_date < Date.today) @@ -276,7 +188,7 @@ class License if File.directory? (sym_location) begin # sx properties create - f = File.open(sym_location + "/sx.properties", "w") + f = File.open(sym_location + "engines/sx.properties", "w") f.write("engine.name=sx\n") f.write("db.driver=com.mysql.jdbc.Driver\n") f.write("db.url=jdbc:mysql://#{db_host}/#{db_schema}?tinyInt1isBit=false\n") @@ -324,6 +236,11 @@ class License end end + # Run Symmetric + def run_symmetric(sym_path) + check_sym_proc = system(sym_path) + end + # Delete License File def delete_license_file File.delete("config/license.yml") if File.exist?("config/license.yml") From 22b5421603da889df3d756d435ac4d13fca613fc Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 20 Nov 2017 19:15:32 +0630 Subject: [PATCH 006/231] dev done license --- app/models/license.rb | 52 ++++++++++++++++++++++++++++++++++++++++--- db/sym_master.sql | 6 ++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index c4b9cdd2..71a32469 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -74,7 +74,7 @@ class License def detail_with_local_file() - has_license = verify_license() + has_license = true # verify_license() if has_license puts "VERIFIED" @@ -95,7 +95,7 @@ class License sym_path = "/home/yan/symmetric/" response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) if(response["status"]) - run_symmetric(sym_path) + response = run_symmetric(sym_path) end end else @@ -238,7 +238,53 @@ class License # Run Symmetric def run_symmetric(sym_path) - check_sym_proc = system(sym_path) + check_sym_proc_str = `#{sym_path + "bin/sym_service status"}` + check_sym_proc_str = check_sym_proc_str.split("\n") + sym_install_status = check_sym_proc_str[0].split(": ") + # sym_run_status = check_sym_proc_str[1].split(": ") + + # Check Sym Installed + if sym_install_status[1] == "false" + response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"} + end + + # Run Sym Service + sym_run_status = check_sym_running(check_sym_proc_str[1], sym_path) + if sym_run_status + # Create Sym Table + check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables") + if check_sym_table + sym_sql = Rails.root + "db/sym_master.sql" + if File.exist? (sym_sql) + # Import Sym Sql to db and start sym + run_sym_sql = system(sym_path + "bin/dbimport --engine sx " + sym_sql) + run_sym = system(sym_path + "bin/sym") + if run_sym + response = { "status": true, "message": "Activation is success and Configuration done..."} + end + else + response = { "status": false, "message": "Activation is success but Symmetric Sql not Found. \n Please contact code2lab call center!"} + end + end + end + + end + + # Check Symmetric Running + def check_sym_running(status, sym_path) + # Run Sym Service + if status.include? "Server is already running" + return true + elsif status.include? "false" + sym_start_str = `#{sym_path + "bin/sym_service start"}` + if sym_start_str.include? "Started" + return true + else + check_sym_running(sym_start_status[0]) + end + else + return true + end end # Delete License File diff --git a/db/sym_master.sql b/db/sym_master.sql index f070761b..4330b41f 100755 --- a/db/sym_master.sql +++ b/db/sym_master.sql @@ -82,10 +82,10 @@ delete from sym_node; # Create Node Groups and Links insert into sym_node_group (node_group_id) values ('sx'); - insert into sym_node_group (node_group_id) values ('store'); + insert into sym_node_group (node_group_id) values ('cloud'); - insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('sx', 'store', 'W'); - insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('store', 'sx', 'P'); + insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('sx', 'cloud', 'W'); + insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('cloud', 'sx', 'P'); # Create Trigger for Setting Channel From c4e9abbf197c8f58f4b211887fc04308280cb0af Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 24 Nov 2017 10:40:52 +0630 Subject: [PATCH 007/231] amount_due >= 0 for grand total 0 --- app/models/sale_payment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 961a556f..cb6b1249 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -20,7 +20,7 @@ class SalePayment < ApplicationRecord end end - if (amount_due > 0) + if (amount_due >= 0) payment_status = false #route to payment type case payment_method From ef0904245088af7f42aec519d7b4dcdf5b8eb726 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 24 Nov 2017 19:12:33 +0630 Subject: [PATCH 008/231] update sale item report --- app/views/reports/saleitem/index.html.erb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index b943a935..ea823f7d 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -183,12 +183,7 @@ - - +
From b611fcde97c5fe9dac277ba65d48ce2be787ddf6 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 24 Nov 2017 19:15:59 +0630 Subject: [PATCH 009/231] update sale item report --- app/views/reports/saleitem/index.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index ea823f7d..0826b0d9 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -73,7 +73,9 @@ <% @sale_data.each do |sale| %> - <% total_qty += sale.total_item %> + <% if sale.total_item > 0 + total_qty += sale.total_item + end %> <% if !acc_arr.include?(sale.account_id) %> From 2ebecc2fb2bf44d7cf62039a468c86545062e243 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Sat, 25 Nov 2017 16:32:30 +0630 Subject: [PATCH 010/231] update reports --- app/controllers/origami/sale_edit_controller.rb | 2 +- app/controllers/reports/receipt_no_controller.rb | 4 ++++ app/controllers/reports/saleitem_controller.rb | 3 +-- app/models/sale.rb | 12 ++++++------ app/models/sale_payment.rb | 2 +- app/views/reports/payment_method/index.html.erb | 2 +- app/views/reports/receipt_no/index.html.erb | 12 ++++++++---- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index a4dcb31d..c00c35f0 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -43,7 +43,7 @@ class Origami::SaleEditController < BaseOrigamiController @newsaleitem = saleitemObj.dup @newsaleitem.save @newsaleitem.qty = saleitemObj.qty * -1 - @newsaleitem.unit_price = saleitemObj.unit_price * -1 + @newsaleitem.unit_price = saleitemObj.unit_price * 1 @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 @newsaleitem.price = saleitemObj.price * -1 @newsaleitem.product_name = saleitemObj.product_name + ' (FOC)' diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index 3ca19e9d..6d536ee7 100755 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -20,7 +20,11 @@ authorize_resource :class => false payment_type = params[:payment_type] @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type) @sale_taxes = Sale.get_separate_tax(@shift_sale_range,@shift,from,to,payment_type) + @tax_profiles = TaxProfile.order('order_by asc') +puts @sale_taxes.to_json +puts "sssssss" +puts @tax_profiles.to_json @from = from @to = to diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index bd933f83..422c3020 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -16,8 +16,7 @@ class Reports::SaleitemController < BaseReportController end end @sale_data, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED) - puts @sale_data.to_json - puts "SSSSSSSSSSS" + @account_cate_count = Hash.new {|hash, key| hash[key] = 0} diff --git a/app/models/sale.rb b/app/models/sale.rb index 7cacedf3..17f49a12 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -725,19 +725,19 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty query = Sale.all if shift.present? - query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) + query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sales.payment_status= 'paid' and sale_payments.payment_amount != 0", shift.to_a) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .group("sales.sale_id") elsif shift_sale_range.present? - query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a) + query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.payment_status= 'paid' and sales.shift_sale_id in (?)",shift_sale_range.to_a) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .group("sales.sale_id") else - query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sale_payments.payment_amount != 0",from,to) + query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sales.payment_status= 'paid' and sale_payments.payment_amount != 0",from,to) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .group("sales.sale_id") end @@ -795,19 +795,19 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type) .joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id") .where("sales.shift_sale_id in (?) and sale_status= 'completed'", shift.to_a) .group("sale_taxes.tax_name") - .order("sale_taxes.sale_tax_id asc") + .order("sale_taxes.tax_name desc") elsif shift_sale_range.present? query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") .joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id") .where("sales.shift_sale_id in (?) and sale_status= 'completed'", shift_sale_range.to_a) .group("sale_taxes.tax_name") - .order("sale_taxes.sale_tax_id asc") + .order("sale_taxes.tax_name desc") else query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") .joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id") .where("sales.receipt_date between ? and ? and sale_status= 'completed'", from,to) .group("sale_taxes.tax_name") - .order("sale_taxes.sale_tax_id asc") + .order("sale_taxes.tax_name desc") end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 961a556f..c24b8271 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -174,7 +174,7 @@ class SalePayment < ApplicationRecord sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'") sale_items.each do|item| - SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) + SaleItem.update_existing_item(item.qty,item.item_instance_code, item, self.sale.sale_id, "foc", item.unit_price, item.price) end self.payment_method = "foc" diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb index fa32f91c..25d91a7d 100755 --- a/app/views/reports/payment_method/index.html.erb +++ b/app/views/reports/payment_method/index.html.erb @@ -103,7 +103,7 @@ <%= payment.cashier_name rescue '-' %> <%= payment.payment_method rescue '-' %> - <%= payment.payment_amount rescue '-' %> + <%= payment.payment_amount + payment.outstanding_amount%> <%= payment.sale.grand_total rescue '-' %> diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb index 76756e0f..08386eb7 100755 --- a/app/views/reports/receipt_no/index.html.erb +++ b/app/views/reports/receipt_no/index.html.erb @@ -46,8 +46,8 @@ <%= t :cashier %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> - <% @sale_taxes.each do |tax| %> - <%= tax.tax_name %> + <% @tax_profiles.each do |tax| %> + <%= tax.name %> <% end %> <%= t("views.right_panel.detail.grand_total") %> @@ -83,6 +83,9 @@ <%= result.cashier_name rescue '-' %> <%= result.total_amount rescue '-' %> <%= result.total_discount rescue '-' %> + <%if result.customer.customer_type == "Takeaway"%> + 0.0 + <%end%> <% result.sale_taxes.each do |tax| %> <%= tax.tax_payable_amount rescue '-' %> <%end%> @@ -108,8 +111,9 @@   <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> - <% @sale_taxes.each do |tax| %> - <%= tax.tax_name %> + + <% @tax_profiles.each do |tax| %> + <%= tax.name %> <% end %> <%= t("views.right_panel.detail.grand_total") %> <%= t("views.right_panel.detail.rnd_adj_sh") %> From 9226a7b18d768501a7a788054ee179ac2e2379bd Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 26 Nov 2017 14:40:01 +0630 Subject: [PATCH 011/231] only show instance attribute in menu item selected --- app/controllers/settings/menu_item_instances_controller.rb | 3 +++ app/views/settings/menu_item_instances/_form.html.erb | 2 +- app/views/settings/simple_menu_items/show.html.erb | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/settings/menu_item_instances_controller.rb b/app/controllers/settings/menu_item_instances_controller.rb index 336bf7c8..e4030f06 100755 --- a/app/controllers/settings/menu_item_instances_controller.rb +++ b/app/controllers/settings/menu_item_instances_controller.rb @@ -154,6 +154,9 @@ class Settings::MenuItemInstancesController < ApplicationController else @item = MenuItem.find(params[:set_menu_item_id]) end + + # To Only show in Menu item selected attrs + @item.item_attributes = MenuItemAttribute.where(id: @item.item_attributes).select("id, name").map { |e| [e.name, e.id] } end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/views/settings/menu_item_instances/_form.html.erb b/app/views/settings/menu_item_instances/_form.html.erb index 13b2c8ad..5fb18eb2 100755 --- a/app/views/settings/menu_item_instances/_form.html.erb +++ b/app/views/settings/menu_item_instances/_form.html.erb @@ -11,7 +11,7 @@ <%= f.input :item_instance_name %> <%= f.input :price %> - <%= f.input :item_attributes, collection: MenuItemAttribute.collection, input_html: { multiple: true } %> + <%= f.input :item_attributes, collection: @item.item_attributes, input_html: { multiple: true } %> <%= f.input :is_on_promotion %> <%= f.input :promotion_price %> diff --git a/app/views/settings/simple_menu_items/show.html.erb b/app/views/settings/simple_menu_items/show.html.erb index 22a3a930..79d361df 100755 --- a/app/views/settings/simple_menu_items/show.html.erb +++ b/app/views/settings/simple_menu_items/show.html.erb @@ -107,7 +107,9 @@ <%= settings_menu_item.item_instance_code %> <%= settings_menu_item.item_instance_name %> - <%= settings_menu_item.item_attributes %> + + <%= MenuItemAttribute.where(id: settings_menu_item.item_attributes).pluck(:name) %> + <%= settings_menu_item.price %> <%= settings_menu_item.promotion_price %> From 87a27250b7dd44cc0e9eb56eebaafc60b424451d Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 26 Nov 2017 22:23:37 +0630 Subject: [PATCH 012/231] fix minus addorder.js and void and other origami --- app/assets/javascripts/addorder.js | 6 +- app/controllers/origami/void_controller.rb | 15 +- app/models/sale_payment.rb | 2 +- app/models/shift_sale.rb | 2 +- app/pdf/close_cashier_pdf.rb | 15 +- app/views/origami/payments/show.html.erb | 169 ++++++++++----------- lib/tasks/clear_data.rake | 1 + 7 files changed, 111 insertions(+), 99 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 427f9e7b..5cacee2e 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -855,12 +855,12 @@ $(function() { $('#'+minus).on("click", function(){ - var count = parseInt($('#'+id).val()); - var countEl = document.getElementById(id); + // var count = parseInt($('#'+id).val()); + // var countEl = document.getElementById(id); if (count > 1) { count--; - countEl.value = count; + $('#'+id).val(count); if (id=="count") { price = $("#unit_price").text(); diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 80594a26..a243a388 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -8,12 +8,19 @@ class Origami::VoidController < BaseOrigamiController sale = Sale.find_by_sale_id(sale_id) # update count for shift sale - # if(sale.sale_status == "completed") + if(sale.sale_status == "completed") if sale.shift_sale_id != nil shift = ShiftSale.find(sale.shift_sale_id) shift.calculate(sale_id, "void") end - # end + else + # void before sale payment complete + if sale.shift_sale_id != nil + shift = ShiftSale.find(sale.shift_sale_id) + shift.total_void = shift.total_void + sale.grand_total + shift.save + end + end sale.payment_status = 'void' sale.sale_status = 'void' @@ -95,4 +102,8 @@ class Origami::VoidController < BaseOrigamiController end end + def void_before_pay + + end + end \ No newline at end of file diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index e49190a5..cb6b1249 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -174,7 +174,7 @@ class SalePayment < ApplicationRecord sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'") sale_items.each do|item| - SaleItem.update_existing_item(item.qty,item.item_instance_code, item, self.sale.sale_id, "foc", item.unit_price, item.price) + SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) end self.payment_method = "foc" diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index baf11cb3..6c956620 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -54,7 +54,7 @@ class ShiftSale < ApplicationRecord self.cash_sales = self.cash_sales.to_f + cash.to_f self.credit_sales = self.credit_sales.to_i + credit.to_f self.other_sales = self.other_sales.to_i + other_sales.to_f - self.nett_sales = self.nett_sales + (saleobj.total_amount.to_f - self.total_discounts) #self.grand_total.to_i - self.commercial_taxes + self.nett_sales = self.nett_sales + (saleobj.total_amount.to_f - saleobj.total_discount) #self.grand_total.to_i - self.commercial_taxes self.commercial_taxes = self.commercial_taxes.to_i + tax.to_f self.total_rounding = self.total_rounding + saleobj.rounding_adjustment self.total_receipt = self.total_receipt + 1 diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 1f456a07..179e3336 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -263,13 +263,14 @@ class CloseCashierPdf < Prawn::Document end #end total amount by Account - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total Sale :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.total_revenue}", :size => self.item_font_size, :align => :right - end +#COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Total Sale :", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{shift_sale.total_revenue}", :size => self.item_font_size, :align => :right + # end move_down -5 stroke_horizontal_rule diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index a911acf4..291060de 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -359,95 +359,94 @@ }); $( document ).ready(function() { - // Disable click event cash to prevent - $(".payment .cash-color").off('click'); + // Disable click event cash to prevent + $(".payment .cash-color").off('click'); - $('#credit_payment').click(function() { - var sale_id = $('#sale_id').text(); - window.location.href = '/origami/sale/'+ sale_id + "/payment/credit_payment" - return false; - }); - - $('#card_payment').click(function() { - localStorage.setItem("cash",$('#cash').text() ); - var sale_id = $('#sale_id').text(); - window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment" - return false; - }); - - $('#pay').click(function() { - $('#pay').text("Processing, Please wait!") - - $( "#loading_wrapper" ).show(); - - if($('#balance').text() > 0){ - swal ( "Oops" , "Insufficient Amount!" , "error" ); - $( "#loading_wrapper" ).hide(); - }else{ - var sale_id = $('#sale_id').text(); - var item_row = $('.is_card'); - if (item_row.length < 1) { - calculate_member_discount(sale_id); - } - - // payment - var cash = $('#cash').text(); - var credit = $('#credit').text(); - var card = $('#card').text(); - - $.ajax({type: "POST", - url: "<%= origami_payment_cash_path %>", - data: "cash="+ cash + "&sale_id=" + sale_id, - async: false, - success:function(result){ - - localStorage.removeItem("cash"); - if (result.status) { - var msg = result.message; - } - else{ - var msg = ''; - } - $( "#loading_wrapper" ).hide(); - if($('#balance').text() < 0){ - swal({ - title: "Information!", - text: 'Changed amount ' + $('#balance').text() * (-1), - }, function () { - window.location.href = '/origami'; - }); - }else{ - $('#pay').text("Pay"); - swal({ - title: "Information!", - text: 'Thank You !', - }, function () { - window.location.href = '/origami'; - }); - } - } - }); - } + $('#credit_payment').click(function() { + var sale_id = $('#sale_id').text(); + window.location.href = '/origami/sale/'+ sale_id + "/payment/credit_payment" + return false; }); - $('#void').on('click',function () { - swal({ - title: "Information!", - text: 'Are you sure want to Void !', - }, function () { - var sale_id = $('#sale_id').text(); - var ajax_url = "/origami/sale/" + sale_id + '/void'; - $.ajax({ - type: 'POST', - url: ajax_url, - success: function () { - window.location.href = '/origami/'; - } - }) - }); - }); + $('#card_payment').click(function() { + localStorage.setItem("cash",$('#cash').text() ); + var sale_id = $('#sale_id').text(); + window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment" + return false; + }); -}); + $('#pay').click(function() { + $('#pay').text("Processing, Please wait!") + + $( "#loading_wrapper" ).show(); + + if($('#balance').text() > 0){ + swal ( "Oops" , "Insufficient Amount!" , "error" ); + $( "#loading_wrapper" ).hide(); + }else{ + var sale_id = $('#sale_id').text(); + var item_row = $('.is_card'); + if (item_row.length < 1) { + calculate_member_discount(sale_id); + } + + // payment + var cash = $('#cash').text(); + var credit = $('#credit').text(); + var card = $('#card').text(); + + $.ajax({type: "POST", + url: "<%= origami_payment_cash_path %>", + data: "cash="+ cash + "&sale_id=" + sale_id, + async: false, + success:function(result){ + + localStorage.removeItem("cash"); + if (result.status) { + var msg = result.message; + } + else{ + var msg = ''; + } + $( "#loading_wrapper" ).hide(); + if($('#balance').text() < 0){ + swal({ + title: "Information!", + text: 'Changed amount ' + $('#balance').text() * (-1), + }, function () { + window.location.href = '/origami'; + }); + }else{ + $('#pay').text("Pay"); + swal({ + title: "Information!", + text: 'Thank You !', + }, function () { + window.location.href = '/origami'; + }); + } + } + }); + } + }); + + $('#void').on('click',function () { + swal({ + title: "Information!", + text: 'Are you sure want to Void !', + }, function () { + var sale_id = $('#sale_id').text(); + var ajax_url = "/origami/sale/" + sale_id + '/void'; + $.ajax({ + type: 'POST', + url: ajax_url, + success: function () { + window.location.href = '/origami/'; + } + }) + }); + }); + }); function update_balance(){ var cash = $('#cash').text(); diff --git a/lib/tasks/clear_data.rake b/lib/tasks/clear_data.rake index 3071132b..126d8db7 100755 --- a/lib/tasks/clear_data.rake +++ b/lib/tasks/clear_data.rake @@ -9,6 +9,7 @@ namespace :clear do SaleOrder.delete_all SaleItem.delete_all Sale.delete_all + SaleTax.delete_all SaleAudit.delete_all SalePayment.delete_all ShiftSale.delete_all From c1709742241196a56f3a3b514c427510051f7bec Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 27 Nov 2017 09:23:10 +0630 Subject: [PATCH 013/231] change promotion with menu item and menu item instance --- app/controllers/origami/shifts_controller.rb | 14 +++ .../settings/promotions_controller.rb | 25 +++-- app/views/settings/promotions/_form.html.erb | 99 ++++++++++++------- db/seeds.rb | 24 ++--- 4 files changed, 107 insertions(+), 55 deletions(-) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 851be7e5..41bbc846 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -48,16 +48,30 @@ class Origami::ShiftsController < BaseOrigamiController unique_code = "CloseCashierPdf" shop_details = Shop.find(1) + puts "shop details" + p shop_details #get tax shift_obj = ShiftSale.where('id =?',@shift.id) + puts "shift obj" + p shift_obj @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') + puts "sale taxes" + p @sale_taxes #other payment details for mpu or visa like card @other_payment = ShiftSale.get_by_shift_other_payment(@shift) + puts "other payment" + p @other_payment # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') + puts "total amount by account" + p @total_amount_by_account @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') + puts "total_discount_by_account" + p @total_discount_by_account @total_member_discount = ShiftSale.get_total_member_discount(@shift) + puts "total_member_discount" + p @total_member_discount # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index ec09aaab..ec00c5f6 100755 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -29,8 +29,12 @@ class Settings::PromotionsController < ApplicationController def create @promotion = Promotion.new(promotion_params) @promotion.created_by = current_login_employee.id - @promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30) - @promotion.promo_end_hour = @promotion.promo_end_hour.to_datetime.advance(hours: +6, minutes: +30) + if !@promotion.promo_start_hour.nil? + @promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30) + end + if !@promotion.promo_end_hour.nil? + @promotion.promo_end_hour = @promotion.promo_end_hour.to_datetime.advance(hours: +6, minutes: +30) + end respond_to do |format| if @promotion.save promo_pros = @promotion.promotion_products @@ -95,16 +99,23 @@ class Settings::PromotionsController < ApplicationController def find_parent_item res = [] - item = MenuItemInstance.find_by_item_instance_code(params[:item_instance_code]) - if item.nil? + arr_inst = [] + item_inst = MenuItemInstance.find_by_item_instance_code(params[:item_instance_code]) + if item_inst.nil? product = Product.where("item_code = ?",params[:item_instance_code]).pluck(:name,:item_code) res.push(product.name) res.push(product.item_code) else - # menu_item = item.menu_item.pluck(:name,:item_code) - res.push(item.item_instance_name) - res.push(item.menu_item.item_code) + # menu_item = item_inst.menu_item.pluck(:name,:item_code) + # res.push(item_inst.item_instance_name) + # res.push(item_inst.menu_item.item_code) + item_inst.menu_item.menu_item_instances.each do |inst| + arr_inst.push({inst.item_instance_code => inst.item_instance_name}) + end + res.push({item_inst.menu_item.item_code => arr_inst}) end + puts "res" + p res render json: res end diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb index 6150eff8..e90c8ef5 100755 --- a/app/views/settings/promotions/_form.html.erb +++ b/app/views/settings/promotions/_form.html.erb @@ -106,39 +106,39 @@
-->
- <% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %> + <% arr = MenuItem.active.joins("JOIN menu_item_instances as b ON b.menu_item_id=menu_items.id").group("menu_items.id").order("name desc").pluck(:name,:item_code) %> <% Product.order("name desc").pluck(:name,:item_code).each do |p| %> - <% arr.push(p) %> + <% arr.push(p) %> <% end %>
<% sample = [] %> <% if !@promotion.original_product.nil? %> - <% if !MenuItemInstance.find_by_item_instance_code(@promotion.original_product).nil? %> - <% sample = MenuItemInstance.where("item_instance_code=?",@promotion.original_product).pluck(:item_instance_name,:item_instance_code)%> - <% else %> - <% sample = Product.where("item_code=?",@promotion.original_product).pluck(:name,:item_code)%> - <% end %> + <% if !MenuItemInstance.find_by_item_instance_code(@promotion.original_product).nil? %> + <% sample = MenuItemInstance.where("item_instance_code=?",@promotion.original_product).pluck(:item_instance_name,:item_instance_code)%> + <% else %> + <% sample = Product.where("item_code=?",@promotion.original_product).pluck(:name,:item_code)%> + <% end %> <% end %>
<%= f.input :original_product,collection: sample %>
@@ -160,7 +160,7 @@ <%= f.fields_for :promotion_products do |pro| %>
<%= pro.hidden_field :item_code,:class => "promo_product" %> - <% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %> + <% arr = MenuItem.joins("JOIN menu_item_instances as b ON b.menu_item_id=menu_items.id").group("menu_items.id").order("name desc").pluck(:name,:item_code) %> <% Product.order("name desc").pluck(:name,:item_code).each do |p| %> <% arr.push(p) %> <% end %> @@ -247,9 +247,10 @@
From 3878f1644b108495eef0e32f5d958ec41706c09a Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 21 Dec 2017 18:13:24 +0630 Subject: [PATCH 217/231] change UI for menu cats: --- app/views/settings/menu_categories/index.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/settings/menu_categories/index.html.erb b/app/views/settings/menu_categories/index.html.erb index 870c19bc..8d8c044c 100755 --- a/app/views/settings/menu_categories/index.html.erb +++ b/app/views/settings/menu_categories/index.html.erb @@ -30,7 +30,7 @@ <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.alt_name") %> <%= t("views.right_panel.detail.is_available") %> - <%= t("views.right_panel.detail.order_by") %> + <%= t("views.right_panel.detail.parent") %> <%= t("views.right_panel.detail.actions") %> @@ -43,7 +43,7 @@ <%= link_to settings_menu_category.name, settings_menu_category_path(settings_menu_category) %> <%= settings_menu_category.alt_name rescue ''%> <%= settings_menu_category.is_available rescue false%> - <%= settings_menu_category.order_by rescue ''%> + <%= settings_menu_category.parent.name rescue ''%> <%= link_to t("views.btn.edit"), edit_settings_menu_category_path(settings_menu_category),:class => 'btn btn-info btn-sm waves-effect' %> @@ -51,8 +51,8 @@ <% end %> + <%= paginate @settings_menu_categories, param_name: :page, :outer_window => 3 %>
- <%= paginate @settings_menu_categories, param_name: :page, :outer_window => 3 %>
From a10a41f3ed002df67d0f5cba2a224a2fecf03df7 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 21 Dec 2017 19:16:53 +0630 Subject: [PATCH 218/231] update romm show page --- app/views/origami/rooms/show.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index d4869a6a..41d7f612 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -186,7 +186,7 @@
<% if @status_sale == 'sale' %> - +   Customer : <%= @obj_sale.customer.name rescue '-' %> <%else%> @@ -361,7 +361,8 @@ - <% else %> + <% end %> + <% if @status_sale == 'sale' %> From 7d8fddbdeb793486b9bbc0db3ff6bb28ca0fc6ad Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 22 Dec 2017 14:43:59 +0630 Subject: [PATCH 219/231] check order by and code for menu cats: --- app/pdf/receipt_bill_pdf.rb | 21 +++++++++++++------ .../api/restaurant/menu/_menu.json.jbuilder | 2 ++ app/views/print_settings/_form.html.erb | 8 +++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 107e3163..14f05a00 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -5,12 +5,12 @@ class ReceiptBillPdf < Prawn::Document self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.margin = 0 - self.price_width = 40 - self.qty_width = 20 - self.total_width = 40 + self.price_width = 50 + self.qty_width = 35 + self.total_width = 50 self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) self.item_height = 15 - self.item_description_width = (self.page_width-20) / 2 + self.item_description_width = (self.page_width-5) / 2 self.label_width = 100 self.description_width = 150 @@ -22,6 +22,11 @@ class ReceiptBillPdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + #precision checked + if printer_settings.precision.to_i > 2 + printer_settings.precision = 2 + end + # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -124,6 +129,8 @@ class ReceiptBillPdf < Prawn::Document end def line_items(sale_items,precision,delimiter) + item_label_total_front_width = (self.item_width+self.price_width) + 15 + item_label_total_end_width = self.total_width + 14 move_down 5 y_position = cursor move_down 5 @@ -132,7 +139,7 @@ class ReceiptBillPdf < Prawn::Document text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "Total", :at =>[(self.item_width+self.price_width+4),y_position], :width => self.total_width+3, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down -5 stroke_horizontal_rule @@ -141,6 +148,8 @@ class ReceiptBillPdf < Prawn::Document def add_line_item_row(sale_items,precision,delimiter) item_name_width = (self.item_width+self.price_width) + item_total_front_width = item_name_width + 15 + item_total_end_width = self.total_width + 14 y_position = cursor move_down 5 sub_total = 0.0 @@ -163,7 +172,7 @@ class ReceiptBillPdf < Prawn::Document # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down 5 end diff --git a/app/views/api/restaurant/menu/_menu.json.jbuilder b/app/views/api/restaurant/menu/_menu.json.jbuilder index 9441daf9..cf046939 100755 --- a/app/views/api/restaurant/menu/_menu.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu.json.jbuilder @@ -7,6 +7,8 @@ json.valid_time_to menu.valid_time_to.strftime("%H:%M") if (menu.menu_categories) json.categories menu.menu_categories do |category| json.id category.id + json.code category.code + json.order_by category.order_by json.name category.name json.alt_name category.alt_name json.parent_id category.menu_category_id diff --git a/app/views/print_settings/_form.html.erb b/app/views/print_settings/_form.html.erb index 51ee0eaa..201d1411 100755 --- a/app/views/print_settings/_form.html.erb +++ b/app/views/print_settings/_form.html.erb @@ -15,8 +15,8 @@ <%= f.input :api_settings %> <%= f.input :page_width %> <%= f.input :page_height %> - <%= f.input :print_copies, input_html: { min: '1', step: '1', :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanOne(this.value);" } %> - <%= f.input :precision %> + <%= f.input :print_copies, input_html: { min: 1, step: '1', :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanOne(this.value);" } %> + <%= f.input :precision, input_html: { min: 0, max: 2, :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanThree(this.value);" } %> <%= f.input :delimiter %> <%= f.input :heading_space %>
@@ -73,4 +73,8 @@ function greaterThanOne(val){ if(parseInt(val)==0) $("#print_setting_print_copies").val(1); } + + function greaterThanThree(val){ + if(parseInt(val)>2) $("#print_setting_precision").val(2); + } \ No newline at end of file From dad83a1f83fc578c4d63c788088c47faceb39fbd Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 22 Dec 2017 16:33:10 +0630 Subject: [PATCH 220/231] change receipt bill format --- app/pdf/receipt_bill_pdf.rb | 46 ++++++++++++++++++------- app/views/print_settings/_form.html.erb | 4 +-- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 14f05a00..ae02b22d 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -5,10 +5,10 @@ class ReceiptBillPdf < Prawn::Document self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.margin = 0 - self.price_width = 50 - self.qty_width = 35 - self.total_width = 50 - self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) + self.price_width = 60 + self.qty_width = 25 + self.total_width = 60 + self.item_width = self.page_width - ((self.qty_width + self.price_width + self.total_width)) self.item_height = 15 self.item_description_width = (self.page_width-5) / 2 self.label_width = 100 @@ -129,16 +129,26 @@ class ReceiptBillPdf < Prawn::Document end def line_items(sale_items,precision,delimiter) - item_label_total_front_width = (self.item_width+self.price_width) + 15 - item_label_total_end_width = self.total_width + 14 + if precision.to_i > 0 + item_label_qty_front_width = (self.item_width+self.price_width) + 5 + item_label_qty_end_width = self.qty_width + 4 + item_label_total_front_width = (self.item_width+self.price_width) + 10 + item_label_total_end_width = self.total_width + 9 + else + self.item_width = self.item_width.to_i + 8 + item_label_qty_front_width = (self.item_width+self.price_width) + 8 + item_label_qty_end_width = self.qty_width + 7 + item_label_total_front_width = (self.item_width+self.price_width) + 5 + item_label_total_end_width = self.total_width + 4 + end move_down 5 y_position = cursor move_down 5 pad_top(15) { # @item_width.to_i + @half_qty.to_i text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix - text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "Price", :at =>[(self.item_width),y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "Qty", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down -5 @@ -147,9 +157,19 @@ class ReceiptBillPdf < Prawn::Document end def add_line_item_row(sale_items,precision,delimiter) - item_name_width = (self.item_width+self.price_width) - item_total_front_width = item_name_width + 15 - item_total_end_width = self.total_width + 14 + if precision.to_i > 0 + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = (self.item_width+self.price_width) + 5 + item_qty_end_width = self.qty_width + 4 + item_total_front_width = item_name_width + 10 + item_total_end_width = self.total_width + 9 + else + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = item_name_width + 8 + item_qty_end_width = self.qty_width + 7 + item_total_front_width = item_name_width + 5 + item_total_end_width = self.total_width + 4 + end y_position = cursor move_down 5 sub_total = 0.0 @@ -171,7 +191,7 @@ class ReceiptBillPdf < Prawn::Document end # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_name_width,y_position], :width => self.qty_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } move_down 5 @@ -478,7 +498,7 @@ class ReceiptBillPdf < Prawn::Document text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Thank You! See you Again", :left_margin => -10, :size => self.item_font_size,:align => :left + text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :left end move_down 5 diff --git a/app/views/print_settings/_form.html.erb b/app/views/print_settings/_form.html.erb index 201d1411..38e55330 100755 --- a/app/views/print_settings/_form.html.erb +++ b/app/views/print_settings/_form.html.erb @@ -16,7 +16,7 @@ <%= f.input :page_width %> <%= f.input :page_height %> <%= f.input :print_copies, input_html: { min: 1, step: '1', :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanOne(this.value);" } %> - <%= f.input :precision, input_html: { min: 0, max: 2, :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanThree(this.value);" } %> + <%= f.input :precision, input_html: { min: 0, max: 2, :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanTwo(this.value);" } %> <%= f.input :delimiter %> <%= f.input :heading_space %>
@@ -74,7 +74,7 @@ if(parseInt(val)==0) $("#print_setting_print_copies").val(1); } - function greaterThanThree(val){ + function greaterThanTwo(val){ if(parseInt(val)>2) $("#print_setting_precision").val(2); } \ No newline at end of file From da4af7bfc504f98c664401555ce0abfafe87a721 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 22 Dec 2017 16:33:12 +0630 Subject: [PATCH 221/231] license updated --- app/controllers/application_controller.rb | 16 +- app/controllers/install_controller.rb | 24 +- app/models/license.rb | 428 +++++++++--------- app/models/my_aes_crypt.rb | 3 +- .../api/restaurant/menu/_menu.json.jbuilder | 1 + config/license.yml | 30 +- config/routes.rb | 1 + config/secrets.yml | 7 +- 8 files changed, 250 insertions(+), 260 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d10fbbf5..3f789fc4 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,20 +36,23 @@ class ApplicationController < ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end - else + else # check for license file if check_license current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path end end end def current_license(url) @license = License.new(url) - if (@license.detail_with_local_file() == 0) - puts "Expired or No License!" - elsif (@license.detail_with_local_file() == 2) - puts "Expiring! pls, license extend..." + 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 puts "RUN SAY BYAR" end @@ -108,9 +111,8 @@ class ApplicationController < ActionController::Base def check_license if License.check_license_file return true - else - redirect_to activate_path end + return false end end diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index a386416a..fac74926 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,6 +1,6 @@ class InstallController < BaseController skip_before_action :verify_authenticity_token - before_action :check_license + # before_action :check_license def index end @@ -17,20 +17,20 @@ class InstallController < BaseController db_schema = params[:db_schema] db_user = params[:db_user] db_password = params[:db_password] - phrase = license_key + phrase = license_key # Check Exists IV - if flag == "<%= ENV['AES_IV'] %>" - # Export for Key - aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(phrase) - else - aes_key = ENV["AES_KEY"] - aes_iv = ENV["AES_IV"] - end + # if flag == "<%= ENV['AES_IV'] %>" + # # Export for Key + # aes = MyAesCrypt.new + # aes_key, aes_iv = aes.export_key(phrase) + # else + # aes_key = ENV["AES_KEY"] + # aes_iv = ENV["AES_IV"] + # end @license = License.new(ENV["SX_PROVISION_URL"]) - response = @license.license_activate(aes_key, aes_iv, 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] redirect_to root_url, notice: response["message"] else @@ -38,7 +38,7 @@ class InstallController < BaseController end end - def check_license + def check_license if License.check_license_file redirect_to root_url end diff --git a/app/models/license.rb b/app/models/license.rb index e9922084..36ce9b29 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -68,31 +68,9 @@ class License end # For Local System - def detail_with_local_file() - # flag = ENV["AES_KEY"] - # # Check Exists IV - # if flag == "<%= ENV['AES_IV'] %>" - # # Export for Key - # aes = MyAesCrypt.new - # aes_key, aes_iv = aes.export_key(lookup) - # else - # aes_key = ENV["AES_KEY"] - # aes_iv = ENV["AES_IV"] - # end - + def detail_with_local_file() renewal_date_str = read_license("renewable_date") - - # ##Check from local redis - if available load local otherwise get from remote - # renewable_date = "renewable_date:#{renewal_date_str}" - - # ##Get redis connection from connection pool - # redis = Redis.new - # cache_renewable_date = redis.get(renewable_date) - # if cache_renewable_date.nil? - # redis = Redis.new - # redis.set(renewable_date, Marshal.dump(@license)) - # else - # get_renewable_date = Marshal.load(cache_renewable_date) + if check_expiring(renewal_date_str) # return for all ok return 1 @@ -110,13 +88,34 @@ class License end # License Activation - def license_activate (key, iv, license_key, db_host, db_schema, db_user, db_password) - @params = { query: { lookup_type: self.server_mode, iv_key: iv, license_key: license_key } } + def license_activate (shop, license_key, db_host, db_schema, db_user, db_password) + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(license_key) + + @params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } } response = self.class.get("/activate", @params) @activate = response.parsed_response - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s if (@activate["status"]) + ##Check from local redis - if available load local otherwise get from remote + cache_key = "shop:#{@activate["shop_name"]}" + + cache_license = nil + + ##Get redis connection from connection pool + redis = Redis.new + cache_license = redis.get(cache_key) + + Rails.logger.info "Cache key - " + cache_key.to_s + + if cache_license.nil? + cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } + redis = Redis.new + redis.set(cache_key, Marshal.dump(cache)) + end + + Rails.logger.info "License - " + response.parsed_response.to_s + response = create_license_file(@activate) if(response[:status]) sym_path = "/home/yan/symmetric/" @@ -149,19 +148,21 @@ class License end # Check Expired before 30 days - def check_expiring(renewal_date_str) - renewal_date = DateTime.parse(renewal_date_str) - renewal_date > Date.today.advance(:days => 30) + def check_expiring(renewal_date_str) + if !renewal_date_str.empty? + renewal_date = DateTime.parse(renewal_date_str) + renewal_date > Date.today.advance(:days => 30) + end end # Check License expired date from PROVISION SERVER - def check_expired(renewal_date_str) + def check_expired(renewal_date_str) expired_date_str = read_license("renewable_date") - expired_date = DateTime.parse(expired_date_str) renewal_date = DateTime.parse(renewal_date_str) - if(renewal_date != expired_date){ + + if(renewal_date_str != expired_date_str) update_license("renewable_date", renewal_date_str) - } + end if (renewal_date < Date.today) return true @@ -176,16 +177,18 @@ class License end # read line by key for license file - def read_license(key) - decrypted_line = "" + def read_license(key_name) + decrypted_line = "" + key, iv = get_redis_key() + if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| - if line.include? (key) - decrypted_line_array = line.split(": ") - decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE']) + if line.include? (key_name) + decrypted_line_array = line.split(": ") + decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) end end - end + end return decrypted_line end @@ -205,18 +208,19 @@ class License # Update license file for line def update_license(content, new_content) - if !new_content.include? "==" - str = encode_str(new_content) - crypted_str = AESCrypt.encrypt_data(str, ENV['AES_KEY'], ENV['AES_IV'], ENV['CIPHER_TYPE']) - end + key, iv = get_redis_key() + if !new_content.include? "==" + crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) + end + content_str = read_license_no_decrypt(content) if File.exist?("config/license.yml") file_str = File.read("config/license.yml") - new_file_str = file_str.gsub(content, crypted_str) + new_file_str = file_str.gsub(content_str, encode_str(crypted_str)) # 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.puts new_file_str } # File.open("config/license.yml").each do |line| # new_file_str = line.gsub(content, crypted_str) @@ -225,189 +229,187 @@ class License end end - private - def encode_str(str) - return Base64.encode64(str) + private + def get_redis_key + iv = "" + key = "" + shop = read_license_no_decrypt("shop_name") + ##Check from local redis - if available load local otherwise get from remote + cache_key = "shop:#{shop.chomp}" + + cache_shop = nil + + ##Get redis connection from connection pool + redis = Redis.new + cache_shop = redis.get(cache_key) + + if !cache_shop.nil? + @shop = Marshal.load(cache_shop) + key = @shop["key"] + iv = @shop["iv"] + end + return key, iv + end + + def encode_str(str) + return Base64.encode64(str) + end + + def decode_str(str) + return Base64.decode64(str) + end + + # License File Creation + def create_license_file(response_data) + if File.exist?("config/license.yml") + delete_license_file end - def decode_str(str) - return Base64.decode64(str) + begin + # Licese File Creation + File.open("config/license.yml", "w") do |f| + f.puts("iv_key: #{response_data['iv_key']}") + f.puts("shop_name: #{response_data['shop_name']}") + f.puts("email: #{response_data['email']}") + f.puts("telephone: #{response_data['telephone']}") + f.puts("fax: #{response_data['fax']}") + f.puts("address: #{response_data['address']}") + f.puts("dbhost: #{response_data['dbhost']}") + f.puts("dbschema: #{response_data['dbschema']}") + f.puts("dbusername: #{response_data['dbusername']}") + f.puts("dbpassword: #{response_data['dbpassword']}") + f.puts("api_token: #{response_data['api_token']}") + f.puts("app_token: #{response_data['app_token']}") + f.puts("plan_sku: #{response_data['plan_sku']}") + f.puts("renewable_date: #{response_data['renewable_date']}") + f.puts("plan_name: #{response_data['plan_name']}") + end + rescue IOError + response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end + response = { "status": true, "message": "Success Activation. License also created."} + end - # License File Creation - def create_license_file(response_data) - if File.exist?("config/license.yml") - delete_license_file - end - + # Symmetric Configuration + def create_symmetric_config(sym_location, db_host, db_schema, db_user, db_password) + if File.directory? (sym_location) begin - # Licese File Creation - File.open("config/license.yml", "w") do |f| - f.puts("iv_key: #{response_data['iv_key']}") - f.puts("shop_name: #{response_data['shop_name']}") - f.puts("email: #{response_data['email']}") - f.puts("telephone: #{response_data['telephone']}") - f.puts("fax: #{response_data['fax']}") - f.puts("address: #{response_data['address']}") - f.puts("dbhost: #{response_data['dbhost']}") - f.puts("dbschema: #{response_data['dbschema']}") - f.puts("dbusername: #{response_data['dbusername']}") - f.puts("dbpassword: #{response_data['dbpassword']}") - f.puts("api_token: #{response_data['api_token']}") - f.puts("app_token: #{response_data['app_token']}") - f.puts("plan_sku: #{response_data['plan_sku']}") - f.puts("renewable_date: #{response_data['renewable_date']}") - f.puts("plan_name: #{response_data['plan_name']}") - end + # sx properties create + f = File.open(sym_location + "engines/sx.properties", "w") + f.write("engine.name=sx\n") + f.write("db.driver=com.mysql.jdbc.Driver\n") + f.write("db.url=jdbc:mysql://#{db_host}/#{db_schema}?tinyInt1isBit=false\n") + f.write("db.user=#{db_user}\n") + f.write("db.password=#{db_password}\n") + f.write("registration.url=\n") + f.write("sync.url=http://#{db_host}:31415/sync/sx\n") + f.write("group.id=sx\n") + f.write("external.id=000\n") + f.write("job.purge.period.time.ms=7200000\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + f.write("initial.load.create.first=true\n") + f.write("initial.load.use.extract.job.enabled=true\n") + f.close + + # read from license file + shop_name = read_license_no_decrypt("shop_name") + dbhost = read_license("dbhost") + dbschema = read_license("dbschema") + dbusername = read_license("dbusername") + dbpassword = read_license("dbpassword") + + # shop properties create + f = File.open(sym_location + "engines/#{shop_name}.properties", "w") + f.write("engine.name=#{shop_name}\n") + f.write("db.driver=com.mysql.jdbc.Driver\n") + f.write("db.url=jdbc:mysql://#{dbhost}/#{dbschema}?tinyInt1isBit=false\n") + f.write("db.user=#{dbusername}\n") + f.write("db.password=#{dbpassword}\n") + f.write("registration.url=http://#{db_host}:31415/sync/sx\n") + f.write("group.id=store\n") + f.write("external.id=001\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + # f.write("initial.load.create.first=true\n") + # f.write("initial.load.use.extract.job.enabled=true\n") + f.close rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end response = { "status": true, "message": "Success Activation. License also created."} end + end - # Symmetric Configuration - def create_symmetric_config(sym_location, db_host, db_schema, db_user, db_password) - if File.directory? (sym_location) - begin - # sx properties create - f = File.open(sym_location + "engines/sx.properties", "w") - f.write("engine.name=sx\n") - f.write("db.driver=com.mysql.jdbc.Driver\n") - f.write("db.url=jdbc:mysql://#{db_host}/#{db_schema}?tinyInt1isBit=false\n") - f.write("db.user=#{db_user}\n") - f.write("db.password=#{db_password}\n") - f.write("registration.url=\n") - f.write("sync.url=http://#{db_host}:31415/sync/sx\n") - f.write("group.id=sx\n") - f.write("external.id=000\n") - f.write("job.purge.period.time.ms=7200000\n") - f.write("job.routing.period.time.ms=5000\n") - f.write("job.push.period.time.ms=10000\n") - f.write("job.pull.period.time.ms=10000\n") - f.write("initial.load.create.first=true\n") - f.write("initial.load.use.extract.job.enabled=true\n") - f.close + # Run Symmetric + def run_symmetric(sym_path) + # check_sym_proc_str = `#{sym_path + "bin/sym_service status"}` + # check_sym_proc_str = check_sym_proc_str.split("\n") + # sym_install_status = check_sym_proc_str[0].split(": ") + + check_sym_proc_str = `#{"service SymmetricDS status"}` - # read from license file - shop_name = read_license("shop_name") - dbhost = read_license("dbhost") - dbschema = read_license("dbschema") - dbusername = read_license("dbusername") - dbpassword = read_license("dbpassword") + # Check Sym Installed + # if sym_install_status[1] == "false" + # response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"} + # end - # shop properties create - f = File.open(sym_location + "engines/#{shop_name}.properties", "w") - f.write("engine.name=#{shop_name}\n") - f.write("db.driver=com.mysql.jdbc.Driver\n") - f.write("db.url=jdbc:mysql://#{dbhost}/#{dbschema}?tinyInt1isBit=false\n") - f.write("db.user=#{dbusername}\n") - f.write("db.password=#{dbpassword}\n") - f.write("registration.url=http://#{db_host}:31415/sync/sx\n") - f.write("group.id=store\n") - f.write("external.id=001\n") - f.write("job.routing.period.time.ms=5000\n") - f.write("job.push.period.time.ms=10000\n") - f.write("job.pull.period.time.ms=10000\n") - # f.write("initial.load.create.first=true\n") - # f.write("initial.load.use.extract.job.enabled=true\n") - f.close - rescue IOError - response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} - end - response = { "status": true, "message": "Success Activation. License also created."} - end - end - - # Run Symmetric - def run_symmetric(sym_path) - # check_sym_proc_str = `#{sym_path + "bin/sym_service status"}` - # check_sym_proc_str = check_sym_proc_str.split("\n") - # sym_install_status = check_sym_proc_str[0].split(": ") - - check_sym_proc_str = `#{"service SymmetricDS status"}` - - # Check Sym Installed - # if sym_install_status[1] == "false" - # response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"} - # end - - # Run Sym Service - sym_run_status = check_sym_running(check_sym_proc_str, sym_path) - if sym_run_status - # Create Sym Table - check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables") - if check_sym_table - sym_sql = Rails.root + "db/sym_master.sql" - - if File.exist? (sym_sql) - # Import Sym Sql to db and start sym - run_sym_sql = system(sym_path + "bin/dbimport --engine sx " + sym_sql.to_s) - stop_sym = system("service SymmetricDS stop") - run_sym = system("service SymmetricDS start") - if run_sym - response = { "status": true, "message": "Activation is success and Configuration done..."} - end - else - response = { "status": false, "message": "Activation is success but Symmetric Sql not found. \n Please contact code2lab call center!"} + # Run Sym Service + sym_run_status = check_sym_running(check_sym_proc_str, sym_path) + if sym_run_status + # Create Sym Table + check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables") + if check_sym_table + sym_sql = Rails.root + "db/sym_master.sql" + + if File.exist? (sym_sql) + # Import Sym Sql to db and start sym + run_sym_sql = system(sym_path + "bin/dbimport --engine sx " + sym_sql.to_s) + stop_sym = system("service SymmetricDS stop") + run_sym = system("service SymmetricDS start") + if run_sym + response = { "status": true, "message": "Activation is success and Configuration done..."} end + else + response = { "status": false, "message": "Activation is success but Symmetric Sql not found. \n Please contact code2lab call center!"} end - else - response = { "status": false, "message": "Activation is success but Symmetric not running. \n Please contact code2lab call center!"} end + else + response = { "status": false, "message": "Activation is success but Symmetric not running. \n Please contact code2lab call center!"} end + end - # Check Symmetric Running - def check_sym_running(status, sym_path) - # Run Sym Service - # if status.include? "Server is already running" - # return true - # elsif status.include? "false" - # sym_start_str = `#{sym_path + "bin/sym_service start"}` - # if sym_start_str.include? "Started" - # return true - # else - # check_sym_running(sym_start_status[0]) - # end - # else - # return true - # end + # Check Symmetric Running + def check_sym_running(status, sym_path) + # Run Sym Service + # if status.include? "Server is already running" + # return true + # elsif status.include? "false" + # sym_start_str = `#{sym_path + "bin/sym_service start"}` + # if sym_start_str.include? "Started" + # return true + # else + # check_sym_running(sym_start_status[0]) + # end + # else + # return true + # end - if status.include? "Active: active (running)" #"Server is already running" - return true - end - return false + if status.include? "Active: active (running)" || "Active: active (exited)" #"Server is already running" + return true end + return false + end - # Delete License File - def delete_license_file - File.delete("config/license.yml") if File.exist?("config/license.yml") - end + # Delete License File + def delete_license_file + File.delete("config/license.yml") if File.exist?("config/license.yml") + end # Assign db info for Cloud - def assign(aes_key, aes_iv) - # self.name = @license["name"] - # self.address_1 = @license["address_1"] - # self.address_2 = @license["address_2"] - # self.township = @license["township"] - # self.city = @license["city"] - # self.country = @license["country"] - # self.email = @license["email"] - # self.phone = @license["phone"] - # self.fax = @license["fax"] - # self.logo = @license["logo"] - # self.localhost_address = @license["localhost_address"] - # self.subdomain = @license["subdomain"] - # self.plan_activation_date = Date.parse(@license["plan_activation_date"]) - # self.plan_next_renewal_date = Date.parse(@license["plan_next_renewal_date"]) - - ## self.plan_activation_date = Date.strptime(@license["plan_activation_date"], "%Y-%m-%d") - ## self.plan_next_renewal_date = Date.strptime(@license["plan_next_renewal_date"], "%Y-%m-%d") - - # self.plan_max_products = @license["plan_max_products"].to_i - # self.plan_max_customers = @license["plan_max_customers"].to_i - # self.plan_active_connections = @license["plan_active_connections"].to_i - # salt = @license["secret_key"] - + def assign(aes_key, aes_iv) key = Base64.decode64(aes_key) iv = Base64.decode64(aes_iv) @@ -422,18 +424,6 @@ class License self.dbusername = AESCrypt.decrypt_data(dbusername, key, iv, ENV['CIPHER_TYPE']) self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE']) end - - # self.exchange_unqiue_id = @license["exchange_unqiue_id"] - - # self.localqueue_host= @license["localqueue_host"] - # self.localqueue_user= @license["localqueue_user"] - # self.localqueue_password= @license["localqueue_password"] - - # self.remotequeue_host = @license["remotequeue_host"] - # self.remotequeue_user = @license["remotequeue_user"] - # self.remotequeue_password = @license["remotequeue_password"] - - # self.api_token = @license["api_token"] - # self.app_token = @license["app_token"] + end end diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index 569a401d..680d0624 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -17,8 +17,7 @@ class MyAesCrypt passphrase = passphrase + ENV['SX_KEY'] passphrase = passphrase.gsub(".","_") digest = Digest::SHA256.new - key_digest = digest.update(passphrase) - # iv_digest = digest.update(iv_salt) + key_digest = digest.update(passphrase) key = key_digest.digest # iv = iv_digest.digest diff --git a/app/views/api/restaurant/menu/_menu.json.jbuilder b/app/views/api/restaurant/menu/_menu.json.jbuilder index 9441daf9..268a6391 100755 --- a/app/views/api/restaurant/menu/_menu.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu.json.jbuilder @@ -9,6 +9,7 @@ if (menu.menu_categories) json.id category.id json.name category.name json.alt_name category.alt_name + json.order_by category.order_by json.parent_id category.menu_category_id json.is_available category.is_available diff --git a/config/license.yml b/config/license.yml index b96a0256..cc470a1d 100644 --- a/config/license.yml +++ b/config/license.yml @@ -1,15 +1,15 @@ -iv_key: A30HZdW+iDZA0vM5PAqwgg== -shop_name: 7DdPBxVo8m1xpa5T2kIcWQ== -email: yanaung.nyein@code2lab.com -telephone: 111111 -fax: 111111 -address: bitp -dbhost: 9+83FZetcbLZi6COG5PbSw== -dbschema: shztSYIsNmM9nlHkR/4exQ== -dbusername: LapN+Geriht8yk866FxNiQ== -dbpassword: QtboWZ4ATE05vvYw6J+Uqw== -api_token: nGyMizHtoVEFYCjSVEFJuzkxuBJwSsH -app_token: QUdPwSakcsnuVLdfkXgGHhPMiIOcSSfaVwQyA -plan_sku: 9+83FZetcbLZi6COG5PbSw== -renewable_date: shztSYIsNmM9nlHkR/4exQ== -plan_name: LapN+Geriht8yk866FxNiQ== +iv_key: TP8dIx4nBGzr+tYyKn5+Xw== +shop_name: Osaka +email: wathonaun9@gmail.com +telephone: 09979204288 +fax: 09979204288 +address: Yangon +dbhost: nk57NaR38B2eSYyron3Nbw== +dbschema: 3orxFaTi0uQhatBqZGiitQ== +dbusername: EtMle9Gr0/PE3NFHHfwo5A== +dbpassword: 86h61/O38GGo64nekz6oeA== +api_token: FVAGMnjVdaScfydXMbMvPPRWnkEwCSuxs +app_token: IoXPdqzbnQWbHsnxLAjMjimnjEJNySOeIo +plan_sku: PyQJ2sk5NZTudqQ2YIU16A== +renewable_date: d/Fk1deU/iPbZFDOdyKsjA== +plan_name: weWOqr1tZ61Av6YKth1lDw== diff --git a/config/routes.rb b/config/routes.rb index 4c302b94..a4bd24c6 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,7 @@ scope "(:locale)", locale: /en|mm/ do #--------- SmartSales Activation ------------# get 'activate' => 'install#index' post 'activate' => 'install#activate' + get 'run_sym' => 'sym_control#run' #--------- Login/Authentication ------------# get 'auth/:emp_id' => 'home#show', as: :emp_login diff --git a/config/secrets.yml b/config/secrets.yml index af242402..37b1f0b0 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,12 +12,10 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: 192.168.1.147:3002/api #connect.smartsales.asia/api #provision.zsai.ws/api + sx_provision_url: 192.168.1.49:3002/api #connect.smartsales.asia/api #provision.zsai.ws/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L - aes_key: <%= ENV['AES_KEY'] %> - aes_iv: <%= ENV['AES_IV'] %> test: secret_key_base: 5c92143fd4a844fdaf8b22aba0cda22ef1fc68f1b26dd3d40656866893718ae5e58625b4c3a5dc86b04c8be0a505ec0ebc0be3bf52249a3d1e0c1334ee591cf0 @@ -28,7 +26,6 @@ production: secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 sx_provision_url: provision.zsai.ws/api #192.168.1.94:3002 server_mode: cloud + cipher_type: AES-256-CBC sx_key: Wh@t1$C2L - aes_key: <%= ENV['AES_KEY'] %> - aes_iv: <%= ENV['AES_IV'] %> From 11d991240137bf66e4214c310e1f5275b38ea86a Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 22 Dec 2017 16:35:04 +0630 Subject: [PATCH 222/231] license updated --- app/controllers/sym_control_controller.rb | 35 +++++++++++++++++++++++ app/views/sym_control/run.html.erb | 1 + 2 files changed, 36 insertions(+) create mode 100644 app/controllers/sym_control_controller.rb create mode 100755 app/views/sym_control/run.html.erb diff --git a/app/controllers/sym_control_controller.rb b/app/controllers/sym_control_controller.rb new file mode 100644 index 00000000..816b8f2c --- /dev/null +++ b/app/controllers/sym_control_controller.rb @@ -0,0 +1,35 @@ +class SymControlController < BaseController + skip_before_action :verify_authenticity_token + + def run + sym_path = "/home/yan/symmetric/" + check_sym_proc_str = `#{"service SymmetricDS status"}` + # Check Sym Installed + # if sym_install_status[1] == "false" + # response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"} + # end + + if check_sym_proc_str.include? "Active: active (running)" || "Active: active (exited)" #"Server is already running" + # Create Sym Table + check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables") + if check_sym_table + sym_sql = Rails.root + "db/sym_master.sql" + + if File.exist? (sym_sql) + # Import Sym Sql to db and start sym + run_sym_sql = system(sym_path + "bin/dbimport --engine sx " + sym_sql.to_s) + stop_sym = system("service SymmetricDS stop") + run_sym = system("service SymmetricDS start") + if run_sym + render :text => "

Success!

" + end + else + render :text => "

Sym Sql file not found!

" + end + end + else + render :text => "

Sym not running!

" + end + end + +end \ No newline at end of file diff --git a/app/views/sym_control/run.html.erb b/app/views/sym_control/run.html.erb new file mode 100755 index 00000000..8b137891 --- /dev/null +++ b/app/views/sym_control/run.html.erb @@ -0,0 +1 @@ + From 5bd1daa152f16afdaac9dd2a238714a7fa0bfaa1 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 22 Dec 2017 17:51:02 +0630 Subject: [PATCH 223/231] update payment and memberdiscoun --- app/assets/javascripts/origami.js | 27 +++- app/views/origami/home/show.html.erb | 2 +- app/views/origami/payments/show.html.erb | 151 ++++++++++++++--------- app/views/origami/rooms/show.html.erb | 3 +- 4 files changed, 114 insertions(+), 69 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index e649f4b4..725e6353 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -145,30 +145,45 @@ $(document).on('turbolinks:load', function() { }); /* start check first bill or not funs: */ -function checkReceiptNoInFirstBillData(receipt_no) { +function checkReceiptNoInFirstBillData(receipt_no,payment=null) { + // localStorage.removeItem('receipt_lists'); var status = false; if((receipt_no!=undefined) && (receipt_no!="")){ if(localStorage.hasOwnProperty("receipt_lists")===true){ var arr_data = JSON.parse(localStorage.getItem("receipt_lists")); - var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + console.log(arr_data) + if (payment) { + var json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); + }else{ + var json_data = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + } + if((arr_data.length) > (json_data.length)){ status = true; } } } - - return status; + if (payment) { + return json_data[0]["payment"]; + }else{ + return status; + } } -function createReceiptNoInFirstBillData(receipt_no) { +function createReceiptNoInFirstBillData(receipt_no,payment=null) { var arr_data = []; var json_data = []; if(localStorage.hasOwnProperty("receipt_lists")===true){ arr_data = JSON.parse(localStorage.getItem("receipt_lists")); json_data = arr_data.filter(function(e) { return e.receipt_no == receipt_no }); + if (payment) { + jdata = arr_data.filter(function(e) { return e.receipt_no !== receipt_no }); + jdata.push({'receipt_no':receipt_no,'payment':payment}); + localStorage.setItem("receipt_lists",JSON.stringify(jdata)); + } } if(((arr_data.length == 0) && (json_data.length == 0)) || ((arr_data.length > 0) && (json_data.length == 0))){ - arr_data.push({'receipt_no':receipt_no}); + arr_data.push({'receipt_no':receipt_no,'payment':payment}); localStorage.setItem("receipt_lists",JSON.stringify(arr_data)); } } diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 0fa545a3..5471b5e4 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -596,7 +596,7 @@ $( "#loading_wrapper" ).hide(); receipt_no = ($("#receipt_no").html()).trim(); if((receipt_no!=undefined) && (receipt_no!="")) - createReceiptNoInFirstBillData(receipt_no); + createReceiptNoInFirstBillData(receipt_no,type); location.reload(); } diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 848a0b40..1cf61690 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -290,6 +290,21 @@