From 098ea8e9317b630969ed3bce4d36375d51f4d5a6 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 20 Feb 2018 18:15:55 +0630 Subject: [PATCH 1/7] update edit form --- app/assets/stylesheets/addorder.scss | 3 + app/views/origami/sale_edit/edit.html.erb | 115 ++++++++++++++++++---- 2 files changed, 98 insertions(+), 20 deletions(-) diff --git a/app/assets/stylesheets/addorder.scss b/app/assets/stylesheets/addorder.scss index bf09f726..be126395 100755 --- a/app/assets/stylesheets/addorder.scss +++ b/app/assets/stylesheets/addorder.scss @@ -62,6 +62,9 @@ section .content{ .nav-tabs { background-color: #eeeeee; } +.nav-tabs .nav-link { + padding: 0.7286rem 0.2575 +} .nav-tabs .nav-link.active, .nav-tabs .nav-item.show .nav-link { background-color: #fff; border-left: 6px solid #111; diff --git a/app/views/origami/sale_edit/edit.html.erb b/app/views/origami/sale_edit/edit.html.erb index 1aaa02ca..7372e116 100755 --- a/app/views/origami/sale_edit/edit.html.erb +++ b/app/views/origami/sale_edit/edit.html.erb @@ -1,7 +1,7 @@
-
+
INVOICE DETAILS
@@ -29,12 +29,12 @@ - + - + @@ -53,46 +53,46 @@ unless sale_item.price == 0 %> - - + <% if sale_item.remark != 'void' && sale_item.remark != 'edit' && sale_item.remark != 'foc' %> - - - <% elsif sale_item.qty.to_i < 0 || sale_item.remark == 'edit' %> - - - <% else %> - - @@ -108,7 +108,7 @@
## ItemsQTY - - Price - + QTY + Price + Action
<%= count %> + <%= count %> <%= sale_item.product_name %> + + + + + + + +
- + @@ -117,12 +117,42 @@ - +
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
-
+
- +
@@ -225,4 +255,49 @@ } }); }) + + $( "input" ).focusin(function() { + $('.addfocus').removeClass('addfocus'); + $( this ).addClass('addfocus'); + }); + + $(".cashier_number").on('click', function(event){ + if(event.handled !== true) { + + var original_value=''; + // original_value = $('.addfocus').val(); + + var input_type = $(this).attr("data-type"); + + switch (input_type) { + case 'num': + var input_value = $(this).attr("data-value"); + if (original_value == "0.0"){ + $('.addfocus').val(input_value); + } + else{ + $('.addfocus').val(original_value + '' + input_value); + } + break; + + case 'add': + var input_value = $(this).attr("data-value"); + amount = parseInt(input_value); + $('.addfocus').val(amount); + break; + + case 'del' : + var discount_text=$('.addfocus').val(); + $('.addfocus').val(discount_text.substr(0,discount_text.length-1)); + break; + + case 'clr': + $('.addfocus').val(""); + break; + } + event.handled = true; + } else { + return false; + } + }); From cd95d1d5c9e82c52ec3a43d831e8d6fd8104b917 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 21 Feb 2018 10:12:05 +0630 Subject: [PATCH 2/7] license test --- app/controllers/application_controller.rb | 13 +++++++------ app/controllers/concerns/login_verification.rb | 6 +++--- app/models/license.rb | 2 +- config/secrets.yml | 4 ++-- config/shops.json | 17 ++++++++++++++++- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0966a573..36d3ab43 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -27,8 +27,9 @@ class ApplicationController < ActionController::Base 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 + # logger.info "Location - " + @license.name ActiveRecord::Base.establish_connection(website_connection(@license)) + authentication # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema else # reconnect_default_db @@ -38,11 +39,11 @@ class ApplicationController < ActionController::Base end else # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index ab5823de..6e9cff8d 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -2,7 +2,7 @@ module LoginVerification extend ActiveSupport::Concern included do - before_action :authenticate + # before_action :authenticate helper_method :current_company,:current_login_employee end @@ -10,7 +10,7 @@ module LoginVerification protected # Authenticate the user with token based authentication - def authenticate + def authenticate authenticate_session_token || render_unauthorized end @@ -18,7 +18,7 @@ module LoginVerification token = session[:session_token] if (token) #@current_user = User.find_by(api_key: token) - Rails.logger.debug "token - " + token.to_s + #Rails.logger.debug "token - " + token.to_s @user = Employee.authenticate_by_token(token) if @user diff --git a/app/models/license.rb b/app/models/license.rb index d025e349..ddb9a8c0 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -33,7 +33,7 @@ class License ##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? ##change the d/e key diff --git a/config/secrets.yml b/config/secrets.yml index a0220639..286c1ade 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,8 +12,8 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api - server_mode: application + sx_provision_url: 192.168.1.125:3002/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api + server_mode: cloud cipher_type: AES-256-CBC sx_key: Wh@t1$C2L diff --git a/config/shops.json b/config/shops.json index 268c73f0..dc0e3b46 100644 --- a/config/shops.json +++ b/config/shops.json @@ -1,3 +1,18 @@ { - "data": [] + "data": [ + { + "lookup": "chromis-1.zsai.ws", + "value": { + "key": "877eY5iPvpVzaYnIkc2FgIy0U85FtqpTpQGqoM/RCG0=\n", + "iv": "qSVQaKzOm3TYmRP3DhHdig==\n" + } + }, + { + "lookup": "gw2a-13.zsai.dev", + "value": { + "key": "R0uRkGlvCD5DGaPV4SkhGlwaMR0ohYBBmNna+tpRXMc=\n", + "iv": "AP5iuLM36oJmnvLsWCo9+Q==\n" + } + } + ] } From ebdf838b520ac37346b061ab24beae69375e0786 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 21 Feb 2018 13:12:41 +0630 Subject: [PATCH 3/7] update request sale for another role --- app/models/sale.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index f07a8a2f..f0166491 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -82,16 +82,17 @@ class Sale < ApplicationRecord current_shift = ShiftSale.current_shift shift = ShiftSale.current_open_shift(cashier.id) - # set cashier + # set cashier if shift != nil self.cashier_id = cashier.id self.cashier_name = cashier.name self.shift_sale_id = shift.id else - if open_cashier.nil? - self.cashier_id = requested_by.id - self.cashier_name = requested_by.name - self.shift_sale_id = current_shift.id + if open_cashier.count>0 + self.cashier_id = open_cashier[0].id + self.cashier_name = open_cashier[0].name + shift_id = ShiftSale.current_open_shift(open_cashier[0].id) + self.shift_sale_id = shift_id.id else self.cashier_id = current_shift.employee_id self.cashier_name = Employee.find(current_shift.employee_id).name @@ -99,6 +100,7 @@ class Sale < ApplicationRecord end end + # set waiter self.requested_by = requested_by.name From f206df7c384d43eae2f8454a72a7cb87efc391d3 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 21 Feb 2018 13:16:47 +0630 Subject: [PATCH 4/7] update edit form --- app/views/origami/sale_edit/edit.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/origami/sale_edit/edit.html.erb b/app/views/origami/sale_edit/edit.html.erb index 7372e116..940b497a 100755 --- a/app/views/origami/sale_edit/edit.html.erb +++ b/app/views/origami/sale_edit/edit.html.erb @@ -1,7 +1,7 @@
-
+
INVOICE DETAILS
@@ -117,7 +117,7 @@
-
+
@@ -265,7 +265,7 @@ if(event.handled !== true) { var original_value=''; - // original_value = $('.addfocus').val(); + original_value = $('.addfocus').val(); var input_type = $(this).attr("data-type"); From 3d2d304654e86f5a986e2beb0e3b231be5b86086 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 21 Feb 2018 16:30:14 +0630 Subject: [PATCH 5/7] license update for token --- app/controllers/application_controller.rb | 75 +---------------- app/controllers/base_crm_controller.rb | 2 +- app/controllers/base_inventory_controller.rb | 2 +- app/controllers/base_oqs_controller.rb | 2 +- app/controllers/base_origami_controller.rb | 2 +- app/controllers/base_report_controller.rb | 2 +- app/controllers/base_waiter_controller.rb | 2 +- .../concerns/license_verification.rb | 83 +++++++++++++++++++ .../concerns/login_verification.rb | 9 +- app/controllers/home_controller.rb | 4 +- 10 files changed, 101 insertions(+), 82 deletions(-) create mode 100644 app/controllers/concerns/license_verification.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9eb08f5f..3c061feb 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,10 +1,11 @@ class ApplicationController < ActionController::Base - include LoginVerification + include LicenseVerification + #before_action :check_installation protect_from_forgery with: :exception # lookup domain for db from provision - before_action :lookup_domain, :set_locale + before_action :set_locale helper_method :current_company,:current_login_employee,:current_user # alias_method :current_user, :current_login_employee,:current_user @@ -22,68 +23,6 @@ class ApplicationController < ActionController::Base { locale: I18n.locale } end - def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - 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 - ActiveRecord::Base.establish_connection(website_connection(@license)) - authentication - # 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 - 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) - 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 - end - - def cache_license(url, lookup) - @license = License.new(url, lookup) - - if (@license.detail_with_local_cache(lookup) == true) - return @license - else - return nil - end - end - - def website_connection(license) - default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, - :username => license.dbusername, :password => license.dbpassword) - - end - - def reconnect_default_db - ActiveRecord::Base.establish_connection(Rails.env) - end - - # Regular database.yml configuration hash - def default_connection - @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup - end - rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message redirect_to root_path @@ -112,14 +51,6 @@ class ApplicationController < ActionController::Base @employee = Employee.find_by_token_session(session[:session_token]) end end - - private - def check_license - if License.check_license_file - return true - end - return false - end end diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb index e66c67b9..ff44bbbf 100755 --- a/app/controllers/base_crm_controller.rb +++ b/app/controllers/base_crm_controller.rb @@ -1,5 +1,5 @@ class BaseCrmController < ActionController::Base - include LoginVerification + include LicenseVerification layout "CRM" #before_action :check_installation diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb index 4059ac25..0ef47129 100755 --- a/app/controllers/base_inventory_controller.rb +++ b/app/controllers/base_inventory_controller.rb @@ -1,5 +1,5 @@ class BaseInventoryController < ActionController::Base - include LoginVerification + include LicenseVerification layout "inventory" #before_action :check_installation diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb index db9f8231..4fc58402 100755 --- a/app/controllers/base_oqs_controller.rb +++ b/app/controllers/base_oqs_controller.rb @@ -1,5 +1,5 @@ class BaseOqsController < ActionController::Base - include LoginVerification + include LicenseVerification layout "OQS" #before_action :check_installation diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index ec415bad..318c40f2 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -1,5 +1,5 @@ class BaseOrigamiController < ActionController::Base - include LoginVerification + include LicenseVerification layout "origami" # before_action :checkin_process diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index af9ec4fc..a164c499 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,5 +1,5 @@ class BaseReportController < ActionController::Base - include LoginVerification + include LicenseVerification layout "application" #before_action :check_installation diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb index e86433dc..38749af0 100755 --- a/app/controllers/base_waiter_controller.rb +++ b/app/controllers/base_waiter_controller.rb @@ -1,5 +1,5 @@ class BaseWaiterController < ActionController::Base - include LoginVerification + include LicenseVerification layout "waiter" #before_action :check_installation diff --git a/app/controllers/concerns/license_verification.rb b/app/controllers/concerns/license_verification.rb new file mode 100644 index 00000000..bfa40f03 --- /dev/null +++ b/app/controllers/concerns/license_verification.rb @@ -0,0 +1,83 @@ +module LicenseVerification + extend ActiveSupport::Concern + + included do + before_action :lookup_domain + end + + protected + def lookup_domain + if request.subdomain.present? && request.subdomain != "www" + 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 + ActiveRecord::Base.establish_connection(website_connection(@license)) + authenticate_session_token + # 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 + else + # check for license file + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end + end + end + + def authenticate_session_token + token = session[:session_token] + if (token) + #@current_user = User.find_by(api_key: token) + #Rails.logger.debug "token - " + token.to_s + + @user = Employee.authenticate_by_token(token) + if !@user + flash[:notice] = 'Invalid Access!' + end + end + end + + def current_license(url) + @license = License.new(url) + flag = @license.detail_with_local_file() + if (flag == 0) + flash[:notice] = 'Expired or No License!' + elsif (flag == 2) + flash[:notice] = 'Expiring! Please, License extend...' + else + puts "RUN SAY BYAR" + end + end + + def cache_license(url, lookup) + @license = License.new(url, lookup) + + if (@license.detail_with_local_cache(lookup) == true) + return @license + else + return nil + end + end + + def website_connection(license) + default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, + :username => license.dbusername, :password => license.dbpassword) + + end + + def reconnect_default_db + ActiveRecord::Base.establish_connection(Rails.env) + end + + # Regular database.yml configuration hash + def default_connection + @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup + end +end \ No newline at end of file diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index 6e9cff8d..7ddf3cec 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -2,9 +2,8 @@ module LoginVerification extend ActiveSupport::Concern included do - # before_action :authenticate + before_action :authenticate helper_method :current_company,:current_login_employee - end @@ -24,6 +23,8 @@ module LoginVerification if @user return true #Maybe log - login? + else + flash[:notice] = 'Invalid Access!' end end end @@ -50,6 +51,10 @@ module LoginVerification end private + def check_license + License.check_license_file + end + def check_installation if current_company.nil? redirect_to install_path diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 25fb0d70..5afd383a 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,6 @@ -class HomeController < ApplicationController +class HomeController < ApplicationController # layout "application", except: [:index, :show] - skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy] + skip_before_action only: [:index, :show, :create, :update, :destroy] def index # @employees = Employee.all_emp_except_waiter.order("name asc") From 4552a4a9acec353a55bf522826d84e91cface31f Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 21 Feb 2018 16:42:19 +0630 Subject: [PATCH 6/7] license update, base controllers extends app controller --- app/controllers/base_crm_controller.rb | 3 +-- app/controllers/base_inventory_controller.rb | 3 +-- app/controllers/base_oqs_controller.rb | 3 +-- app/controllers/base_origami_controller.rb | 3 +-- app/controllers/base_report_controller.rb | 3 +-- app/controllers/base_waiter_controller.rb | 5 +---- 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb index ff44bbbf..5c412fcf 100755 --- a/app/controllers/base_crm_controller.rb +++ b/app/controllers/base_crm_controller.rb @@ -1,5 +1,4 @@ -class BaseCrmController < ActionController::Base - include LicenseVerification +class BaseCrmController < ApplicationController layout "CRM" #before_action :check_installation diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb index 0ef47129..f44747d3 100755 --- a/app/controllers/base_inventory_controller.rb +++ b/app/controllers/base_inventory_controller.rb @@ -1,5 +1,4 @@ -class BaseInventoryController < ActionController::Base - include LicenseVerification +class BaseInventoryController < ApplicationController layout "inventory" #before_action :check_installation diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb index 4fc58402..f1f2831a 100755 --- a/app/controllers/base_oqs_controller.rb +++ b/app/controllers/base_oqs_controller.rb @@ -1,5 +1,4 @@ -class BaseOqsController < ActionController::Base - include LicenseVerification +class BaseOqsController < ApplicationController layout "OQS" #before_action :check_installation diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index 318c40f2..58d9b801 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -1,5 +1,4 @@ -class BaseOrigamiController < ActionController::Base - include LicenseVerification +class BaseOrigamiController < ApplicationController layout "origami" # before_action :checkin_process diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index a164c499..f7551f22 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,5 +1,4 @@ -class BaseReportController < ActionController::Base - include LicenseVerification +class BaseReportController < ApplicationController layout "application" #before_action :check_installation diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb index 38749af0..248e32a6 100755 --- a/app/controllers/base_waiter_controller.rb +++ b/app/controllers/base_waiter_controller.rb @@ -1,9 +1,6 @@ -class BaseWaiterController < ActionController::Base - include LicenseVerification +class BaseWaiterController < ApplicationController layout "waiter" #before_action :check_installation protect_from_forgery with: :exception - - end From 643a9d71bea9e532dc73f5f4f9844a8726cdde94 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 21 Feb 2018 17:04:45 +0630 Subject: [PATCH 7/7] remove skip before action in home controller --- app/controllers/home_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 5afd383a..ea411fa0 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,6 @@ class HomeController < ApplicationController # layout "application", except: [:index, :show] - skip_before_action only: [:index, :show, :create, :update, :destroy] + # skip_before_action only: [:index, :show, :create, :update, :destroy] def index # @employees = Employee.all_emp_except_waiter.order("name asc")
Sub Total:Sub Total: <%= sub_total %>