diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8db3e16b..3b7539a8 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -25,8 +25,7 @@ class ApplicationController < ActionController::Base def lookup_domain if request.subdomain.present? && request.subdomain != "www" - from = request.subdomain.downcase #+ "." + request.domain.downcase - puts from + from = request.subdomain.downcase + "." + request.domain.downcase @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase if (!@license.nil?) # logger.info "Location - " + @license.name diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index c9aeacca..a386416a 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -17,7 +17,7 @@ class InstallController < BaseController db_schema = params[:db_schema] db_user = params[:db_user] db_password = params[:db_password] - phrase = key_base == "<%= ENV['secret_key_base'] %>"? license_key : "<%= ENV['secret_key_base'] %>" + phrase = license_key # Check Exists IV if flag == "<%= ENV['AES_IV'] %>" diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index 190c4918..b58719f6 100755 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -25,6 +25,6 @@ class Oqs::EditController < BaseOqsController print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_item(print_settings, oqs,assigned_item.order_id, assigned_item.instance_code, print_status=" (Edited)" ) + order_queue_printer.print_order_item(print_settings, oqs,order_item.order_id, order_item.item_instance_code, print_status=" (Cancel)" ) end end diff --git a/app/models/license.rb b/app/models/license.rb index afb95cf4..2e9d729a 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -43,7 +43,7 @@ class License if cache_license.nil? ##change the d/e key # @options = { query: {device: "SXlite", lookup: lookup, skey: @secret, token: SECRETS_CONFIG['provision_key']} } - @params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} } + @params = { query: { lookup_type: self.server_mode, lookup: lookup, iv_key: iv} } response = self.class.get("/subdomain", @params) @license = response.parsed_response @@ -83,18 +83,17 @@ class License # License Activation 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 } } + @params = { query: { lookup_type: self.server_mode, 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"]) response = create_license_file(@activate) - if(response["status"]) + if(response[:status]) sym_path = "/home/yan/symmetric/" response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) - if(response["status"]) + if(response[:status]) response = run_symmetric(sym_path) end end @@ -136,12 +135,12 @@ class License end # read line by key for license file - def read_license(key) + def read_license(key) decrypted_line = "" 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_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']) end end @@ -162,20 +161,20 @@ class License begin # Licese File Creation - f = File.open("config/license.yml", "w") - 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") - 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 + 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']}") + end rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end @@ -237,18 +236,19 @@ class License # 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(": ") - # sym_run_status = check_sym_proc_str[1].split(": ") + # 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 + # 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) + 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") @@ -272,18 +272,23 @@ class License # Check Symmetric Running def check_sym_running(status, sym_path) # Run Sym Service - if status.include? "Server is already running" + # 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 - 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 + return false end # Delete License File @@ -318,7 +323,7 @@ class License 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"]) diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index acba4974..4f200c3b 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -13,10 +13,13 @@ class MyAesCrypt # for cloud is lookup # for local is license_key # iv_salt = passphrase+"c2l" + passphrase = passphrase + ENV['SX_KEY'] + passphrase = passphrase.gsub(".","_") digest = Digest::SHA256.new key_digest = digest.update(passphrase) # iv_digest = digest.update(iv_salt) - key = key_digest.digest + 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 diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index f1229bfa..e15c4b79 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -27,28 +27,28 @@ class SaleItem < ApplicationRecord end def self.update_existing_item(qty, item, sale_id, type, item_price, price) - sale_item = SaleItem.new - sale_item.product_code = item.product_code - sale_item.item_instance_code = item.item_instance_code - sale_item.product_name = item.product_name + "(#{type})" - sale_item.product_alt_name = item.product_alt_name - sale_item.account_id = item.account_id - sale_item.remark = type - if type == "foc" || type == "promotion" || type == "void" - sale_item.qty = qty * (-1) - else - sale_item.qty = qty - end + sale_item = SaleItem.new + sale_item.product_code = item.product_code + sale_item.item_instance_code = item.item_instance_code + sale_item.product_name = item.product_name + "(#{type})" + sale_item.product_alt_name = item.product_alt_name + sale_item.account_id = item.account_id + sale_item.remark = type + if type == "foc" || type == "promotion" || type == "void" + sale_item.qty = qty * (-1) + else + sale_item.qty = qty + end - sale_item.unit_price = item_price # * (-1) - sale_item.taxable_price = (price) * (-1) - sale_item.price = (price) * (-1) + sale_item.unit_price = item_price # * (-1) + sale_item.taxable_price = (price) * (-1) + sale_item.price = (price) * (-1) - sale_item.is_taxable = 1 - sale_item.sale_id = sale_id - sale_item.save - sale = Sale.find(sale_id) - sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) + sale_item.is_taxable = 1 + sale_item.sale_id = sale_id + sale_item.save + sale = Sale.find(sale_id) + sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) end def self.get_order_items_details(sale_id) @@ -95,7 +95,7 @@ class SaleItem < ApplicationRecord discount_account = {:name => a.title, :price => 0} # Check for actual sale items - sale_items.where("is_taxable = false AND remark = 'Discount'").find_each do |si| + sale_items.where("remark = 'Discount'").find_each do |si| if si.account_id == a.id discount_account[:price] = (discount_account[:price].abs + si.price.abs) * (-1) end diff --git a/app/views/oqs/edit/index.html.erb b/app/views/oqs/edit/index.html.erb index 0cae40ce..750a04c8 100755 --- a/app/views/oqs/edit/index.html.erb +++ b/app/views/oqs/edit/index.html.erb @@ -98,10 +98,16 @@