diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 552bc118..adb577ba 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,:shop_detail # alias_method :current_user, :current_login_employee,:current_user @@ -22,67 +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)) - # 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 @@ -115,14 +55,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..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 LoginVerification +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 4059ac25..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 LoginVerification +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 db9f8231..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 LoginVerification +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 c6a302a4..6af6c1d4 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -1,5 +1,4 @@ -class BaseOrigamiController < ActionController::Base - include LoginVerification +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 af9ec4fc..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 LoginVerification +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 e86433dc..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 LoginVerification +class BaseWaiterController < ApplicationController layout "waiter" #before_action :check_installation protect_from_forgery with: :exception - - end 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 ab5823de..7ddf3cec 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -4,13 +4,12 @@ module LoginVerification included do before_action :authenticate helper_method :current_company,:current_login_employee - end protected # Authenticate the user with token based authentication - def authenticate + def authenticate authenticate_session_token || render_unauthorized end @@ -18,12 +17,14 @@ 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 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 97c413c0..1ba21a5a 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") diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index e7786b05..e79e92f6 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -93,7 +93,7 @@ class Origami::PaymentsController < BaseOrigamiController #end rounding adjustment sale_payment = SalePayment.new - sale_payment.process_payment(saleObj, @user, cash, "cash") + sale_payment.process_payment(saleObj, @usercurrent_user.name, cash, "cash") render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error "}) rebate_amount = nil @@ -350,6 +350,7 @@ class Origami::PaymentsController < BaseOrigamiController cash = params[:cash] sale_id = params[:sale_id] sub_total = params[:sub_total] + remark = params[:remark] member_info = nil rebate_amount = nil current_balance = nil @@ -363,7 +364,7 @@ class Origami::PaymentsController < BaseOrigamiController end sale_payment = SalePayment.new - sale_payment.process_payment(saleObj, @user, cash, "foc") + sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark) # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 4c9aa0c1..5bbc9ac3 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -3,7 +3,7 @@ class Origami::VoidController < BaseOrigamiController def overall_void sale_id = params[:sale_id] - + remark = params[:remark] if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) @@ -69,12 +69,8 @@ class Origami::VoidController < BaseOrigamiController end # FOr Sale Audit - action_by = current_user.id - if table.nil? - remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table -> nil" - else - remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" - end + action_by = current_user.name + # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" sale_audit = SaleAudit.record_audit_for_edit(sale_id,sale.cashier_id, action_by,remark,"SALEVOID" ) # For Print diff --git a/app/models/license.rb b/app/models/license.rb index cdebdbdd..1cbce908 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/app/models/sale_audit.rb b/app/models/sale_audit.rb index 55541851..633db6fe 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -24,9 +24,9 @@ class SaleAudit < ApplicationRecord sale_audit.sale_id = sale_id sale_audit.action = "SALECOMPLETE" sale_audit.action_at = DateTime.now.utc - sale_audit.action_by = action_by + sale_audit.action_by = Sale.find(sale_id).cashier_id sale_audit.remark = remark - sale_audit.approved_by = Time.now + sale_audit.approved_by = action_by sale_audit.save! end @@ -72,9 +72,9 @@ class SaleAudit < ApplicationRecord sale_audit.sale_id = sale_id sale_audit.action = "SALEPAYMENT" sale_audit.action_at = DateTime.now.utc - sale_audit.action_by = action_by + sale_audit.action_by = Sale.find(sale_id).cashier_id sale_audit.remark = remark - sale_audit.approved_by = Time.now + sale_audit.approved_by = action_by sale_audit.save! end @@ -83,9 +83,9 @@ class SaleAudit < ApplicationRecord sale_audit.sale_id = sale_id sale_audit.action = "PAYMAL" sale_audit.action_at = DateTime.now.utc - sale_audit.action_by = action_by + sale_audit.action_by = Sale.find(sale_id).cashier_id sale_audit.remark = remark - sale_audit.approved_by = Time.now + sale_audit.approved_by = action_by sale_audit.save! end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index c2fce169..ee5a6a17 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -8,7 +8,7 @@ class SalePayment < ApplicationRecord attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status - def process_payment(invoice, action_by, cash_amount, payment_method) + def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil) self.sale = invoice self.received_amount = cash_amount amount_due = invoice.grand_total @@ -53,7 +53,7 @@ class SalePayment < ApplicationRecord end #record an payment in sale-audit - remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" + # remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) # update complete order items in oqs @@ -67,7 +67,7 @@ class SalePayment < ApplicationRecord return true, self.save else #record an payment in sale-audit - remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" + # remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by) return false, "No outstanding Amount" diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 557b523f..6e70730a 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -473,7 +473,8 @@ <% if current_login_employee.role != "waiter" %> - + + <% end %> @@ -536,6 +537,30 @@ + +