diff --git a/README.md b/README.md index 43a2091e..0605a14a 100755 --- a/README.md +++ b/README.md @@ -188,6 +188,14 @@ Add Base URL for DOEMAL 1) settings/lookups => { type:order_reservation, name: BaseURL, value:'{doemal url}' } 2) settings/lookups => { type:order_reservation, name: Token, value:'{doemal token}' } +Add Feature for Quick Service + ** '0' means can not use quick service and '1' means can use quick service ** + => settings/lookups => { type:quick_service, name: QuickService, value:'{0 or 1}' } + +Add Feature for Order and Reservation + ** '0' means can not use order reservation and '1' means can use order reservation ** + => settings/lookups => { type:order_reservation, name: OrderReservation, value:'{0 or 1}' } + * ToDo list 1. Migration diff --git a/app/assets/javascripts/channels/order_reservation.js b/app/assets/javascripts/channels/order_reservation.js index 605afe16..e3c06e47 100644 --- a/app/assets/javascripts/channels/order_reservation.js +++ b/app/assets/javascripts/channels/order_reservation.js @@ -18,13 +18,16 @@ App.checkin = App.cable.subscriptions.create('OrderReservationChannel', { var time = [date.getHours() - (isPM && !isMidday ? 12 : 0), date.getMinutes() || '00'].join(':') + (isPM ? ' PM' : 'AM'); + var requested_date = date.getDate() + '-' + date.getMonth() + '-' + date.getFullYear() row = '' +''+rowCount +'' - +''+time + +''+requested_date +'' - +''+order.grand_total + +''+time + +'' + +''+order.grand_total +'' +'' +''+ order.status +'' diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 2c3c0df1..a5112ffe 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -23,46 +23,45 @@ class Api::ApiController < ActionController::API @employee = Employee.find_by_token_session(current_token) 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.dbhost - 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 - end - 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.dbhost + # 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 + # 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) + # def website_connection(license) + # default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, + # :username => license.dbusername, :password => license.dbpassword) + # end - end + # def reconnect_default_db + # ActiveRecord::Base.establish_connection(Rails.env) + # 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 - # Regular database.yml configuration hash - def default_connection - @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup - end + # def cache_license(url, lookup) + # @license = License.new(url, lookup) - 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 + # if (@license.detail_with_local_cache(lookup) == true) + # return @license + # else + # return nil + # end + # end end diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 994f6fe4..2fb3d621 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -47,7 +47,9 @@ class Api::BillController < Api::ApiController Promotion.promo_activate(@sale) #BillBroadcastJob.perform_later(table) - ActionCable.server.broadcast "bill_channel",table: table + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "bill_channel",table: table + #end else @status = false @error_message = "No Current Open Shift" diff --git a/app/controllers/api/call_waiters_controller.rb b/app/controllers/api/call_waiters_controller.rb index b695dc33..b8c11897 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -6,8 +6,9 @@ class Api::CallWaitersController < ActionController::API @time = params[:time] @table = DiningFacility.find(@table_id) # CallWaiterJob.perform_later(@table,@time) - ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time - + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time + #end # get printer info @shop = Shop.first unique_code = "CallWaiterPdf" diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 42768d58..da5f6471 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -56,10 +56,13 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController end if status == true - order_reservation_id, flag = OrderReservation.addOrderReservationInfo(params) + order_reservation = params + order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation) order_reservation = OrderReservation.find(order_reservation_id) - ActionCable.server.broadcast "order_reservation_channel",data: order_reservation + if flag #&& ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "order_reservation_channel",data: order_reservation + end if flag render :json => { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is successfully created!" } diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 2eab460a..100635cd 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -184,11 +184,9 @@ puts items_arr.to_json @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) # for second display - if ENV["SERVER_MODE"] != 'cloud' - - ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale" - - end + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale" + #end result = {:status=> @status, :data => @sale } render :json => result.to_json end diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index f888ac57..8bdd5c27 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -56,6 +56,22 @@ class Origami::DashboardController < BaseOrigamiController # get printer info @print_settings = PrintSetting.get_precision_delimiter() @current_user = current_user + #quick service + quick_service = Lookup.collection_of('quick_service') + @quick_service = 0 + if !quick_service[0].nil? + @quick_service = quick_service[0][1] + end + #order reservation + order_reservation = Lookup.collection_of('order_reservation') + @order_reservation = 0 + if !order_reservation.empty? + order_reservation.each do |order_reserve| + if order_reserve[0] == 'OrderReservation' + @order_reservation = order_reserve[1] + end + end + end end end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 493e4680..745d6f33 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -9,7 +9,7 @@ class Origami::HomeController < BaseOrigamiController @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @shop = Shop.first - + # @shift = ShiftSale.current_open_shift(current_user.id) end @@ -21,7 +21,7 @@ class Origami::HomeController < BaseOrigamiController @rooms = Room.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') - + @status_order = "" @status_sale = "" @sale_array = Array.new diff --git a/app/controllers/origami/order_reservation_controller.rb b/app/controllers/origami/order_reservation_controller.rb index 562eaaed..0d5d5277 100644 --- a/app/controllers/origami/order_reservation_controller.rb +++ b/app/controllers/origami/order_reservation_controller.rb @@ -1,7 +1,7 @@ class Origami::OrderReservationController < BaseOrigamiController def index - @order = OrderReservation.all + @order = OrderReservation.latest_order end def update diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index dbd1cbb1..5337bac5 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -6,7 +6,7 @@ class Origami::PaymentsController < BaseOrigamiController def first_bill sale_id = params[:sale_id] # sale_id sale_data = Sale.find_by_sale_id(sale_id) - sale_items = SaleItem.where("sale_id=?",sale_id) + sale_items = SaleItem.select("sale_id,product_code,item_instance_code,product_name,product_alt_name,account_id,status,remark,SUM(qty) as qty,unit_price,taxable_price,price,is_taxable").where("sale_id=?",sale_id).group("item_instance_code,price") member_info = nil # For Cashier by Zone diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 05dbdce4..0c50a5da 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -39,7 +39,9 @@ class Origami::RequestBillsController < ApplicationController # Promotion Activation Promotion.promo_activate(@sale) #bill channel - ActionCable.server.broadcast "bill_channel",table: table + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "bill_channel",table: table + #end if order.source == "quick_service" result = {:status=> @status, :data => @sale.sale_id } render :json => result.to_json diff --git a/app/controllers/origami/second_display_controller.rb b/app/controllers/origami/second_display_controller.rb index 611b49a9..ac869719 100644 --- a/app/controllers/origami/second_display_controller.rb +++ b/app/controllers/origami/second_display_controller.rb @@ -13,9 +13,9 @@ class Origami::SecondDisplayController < BaseOrigamiController else tax_profiles = nil end - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status] - end + # end end #Shop Name in Navbor helper_method :shop_detail diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index 8cd68d9c..5f074bb5 100755 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -335,9 +335,9 @@ class Origami::SplitBillController < BaseOrigamiController end Promotion.promo_activate(sale) - - ActionCable.server.broadcast "bill_channel",table: table - + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "bill_channel",table: table + #end render :json => { status: status } else render :json => { status: false, error_message: 'No Current Open Shift!'} diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 50fc6a52..cff5fd60 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -156,13 +156,17 @@ class DiningFacility < ApplicationRecord table = DiningFacility.find(table_id) #Send to background job for processing # CheckInBookingJob.perform_later(table) - ActionCable.server.broadcast "check_in_booking_channel",table: table + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "check_in_booking_channel",table: table + #end end def self.checkin_time table = DiningFacility.get_checkin_booking if table.length > 0 - ActionCable.server.broadcast "checkin_channel",table: table + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "checkin_channel",table: table + end end end diff --git a/app/models/license.rb b/app/models/license.rb index 13931376..9ef7d956 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -60,8 +60,8 @@ class License return true end else - # @license = Marshal.load(cache_license) - # assign(aes_key, aes_iv) + @license = Marshal.load(cache_license) + assign(aes_key, aes_iv) # Rails.logger.info 'API License' return true end diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index 7c86b158..8f3cde09 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -64,7 +64,7 @@ class MyAesCrypt shop_json["data"].each do |j| if j["lookup"] == from # add [0...44] for production cloud for remove \n - if(j["value"]["key"][0...44] == token) + if(j["value"]["key"] == token) return true end end diff --git a/app/models/order.rb b/app/models/order.rb index e4ab883b..01a7b583 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -321,7 +321,9 @@ class Order < ApplicationRecord end else msg = ' Print Error ! Please contact to service' - ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' + #end if !sidekiq.nil? OrderQueueProcessorJob.perform_later(self.id, self.table_id) else @@ -335,7 +337,9 @@ class Order < ApplicationRecord end end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + #end end end @@ -372,7 +376,9 @@ class Order < ApplicationRecord type = 'order' #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "order_channel",table: table,type:type + #end end end @@ -526,7 +532,9 @@ class Order < ApplicationRecord end end end - ActionCable.server.broadcast "second_display_channel",data: @data_array,status:@status + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "second_display_channel",data: @data_array,status:@status + #end end private diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 5aab27ba..296523cb 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -7,45 +7,48 @@ class OrderReservation < ApplicationRecord has_many :order_reservation_items belongs_to :delivery + scope :latest_order, -> { order("order_reservation_id desc, requested_time asc") } + SEND_TO_KITCHEN = "send_to_kitchen" READY_TO_DELIVERY = "ready_to_deliver" DELIVERED = "delivered" COMPLETED = "completed" - def self.addOrderReservationInfo(params) - check_order_reservation = OrderReservation.where("transaction_ref = ?",params[:reference]) + def self.addOrderReservationInfo(order_reserve) + Rails.logger.debug order_reserve.to_s + check_order_reservation = OrderReservation.where("transaction_ref = ?",order_reserve[:reference]) if check_order_reservation.empty? order_reservation = OrderReservation.new - order_reservation.order_reservation_type = params[:order_type] - order_reservation.customer_id = params[:cus_info] - order_reservation.requested_time = DateTime.parse(params[:requested_time]).utc.strftime("%Y-%m-%d %H:%M:%S") - order_reservation.callback_url = params[:callback_url] - order_reservation.transaction_ref = params[:reference] - if params[:order_info] - order_reservation.item_count = params[:order_info][:items].count - order_reservation.payment_type = params[:payment_info][:payment_type] - order_reservation.payment_status = params[:payment_info][:payment_status] - order_reservation.payment_ref = params[:payment_info][:payment_ref] - order_reservation.total_amount = params[:payment_info][:sub_total] - order_reservation.total_tax = params[:payment_info][:total_tax] - order_reservation.discount_amount = params[:payment_info][:discount_amount] - order_reservation.grand_total = params[:payment_info][:grand_total] - order_reservation.order_remark = params[:order_info][:order_remark] + order_reservation.order_reservation_type = order_reserve[:order_type] + order_reservation.customer_id = order_reserve[:cus_info] + order_reservation.requested_time = DateTime.parse(order_reserve[:requested_time]).utc.strftime("%Y-%m-%d %H:%M:%S") + order_reservation.callback_url = order_reserve[:callback_url] + order_reservation.transaction_ref = order_reserve[:reference] + if order_reserve[:order_info] + order_reservation.item_count = order_reserve[:order_info][:items].count + order_reservation.payment_type = order_reserve[:payment_info][:payment_type] + order_reservation.payment_status = order_reserve[:payment_info][:payment_status] + order_reservation.payment_ref = order_reserve[:payment_info][:payment_ref] + order_reservation.total_amount = order_reserve[:payment_info][:sub_total] + order_reservation.total_tax = order_reserve[:payment_info][:total_tax] + order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount] + order_reservation.grand_total = order_reserve[:payment_info][:grand_total] + order_reservation.order_remark = order_reserve[:order_info][:order_remark] end - if params[:reservation_info] - order_reservation.total_customer = params[:reservation_info][:total_user] - order_reservation.reservation_remark = params[:reservation_info][:reservation_note] + if order_reserve[:reservation_info] + order_reservation.total_customer = order_reserve[:reservation_info][:total_user] + order_reservation.reservation_remark = order_reserve[:reservation_info][:reservation_note] end order_reservation.save! - if params[:order_info][:items] - params[:order_info][:items].each do |oritem| + if order_reserve[:order_info][:items] + order_reserve[:order_info][:items].each do |oritem| OrderReservationItem.process_order_reservation_item(oritem[:product_code],oritem[:item_instance_code],oritem[:product_name],oritem[:product_alt_name], oritem[:account_id],oritem[:qty],oritem[:price],oritem[:unit_price], oritem[:options],nil,order_reservation.id) end end - if params[:delivery_info] - Delivery.addDeliveryInfo(params[:delivery_info],order_reservation.id) + if order_reserve[:delivery_info] + Delivery.addDeliveryInfo(order_reserve[:delivery_info],order_reservation.id) end return order_reservation.id, true else diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 29d755d7..3dba0a9b 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -607,7 +607,9 @@ class SalePayment < ApplicationRecord type = 'payment' #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) - ActionCable.server.broadcast "order_channel",table: table,type:type + #if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "order_channel",table: table,type:type + #end end end end diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 1b6a554e..330c963f 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -18,6 +18,7 @@
+ <% if @quick_service == '1' %>
@@ -26,6 +27,7 @@
<%= t :quick_service %>
+ <% end %>
@@ -34,6 +36,7 @@
<%= t :dine_in_cashier %>
+ <% if @order_reservation == '1' %>
@@ -42,6 +45,7 @@
<%= t :order_reservation %>
+ <% end %>
<% if !@current_user.nil? && @current_user.role != 'waiter' %> diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 8c67a36d..31386cfe 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -46,18 +46,18 @@ <% else %>
<% end %> -
+
Zone <%= table.zone_id %>
Table <%= table.name %> ( <%= table.seater %> Seat )
- <% else %> - <% if table.get_checkout_booking.nil? %> -
- <% else %> -
- <% end %> -
+ <% else %> + <% if table.get_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %> +
Zone <%= table.zone_id %>
Table <%= table.name %> ( <%= table.seater %> Seat )
@@ -112,7 +112,7 @@ <% end %>
- +
diff --git a/app/views/origami/order_reservation/index.html.erb b/app/views/origami/order_reservation/index.html.erb index 15f173ce..87533715 100644 --- a/app/views/origami/order_reservation/index.html.erb +++ b/app/views/origami/order_reservation/index.html.erb @@ -31,10 +31,13 @@ <%=i%> - + + <%= order.requested_time.utc.getlocal.strftime("%d-%m-%Y") %> + + <%= order.requested_time.utc.getlocal.strftime("%I:%M %p") %> - + <%=order.grand_total%> @@ -63,10 +66,13 @@ <%=i%> - + + <%= order.requested_time.utc.getlocal.strftime("%d-%m-%Y") %> + + <%= order.requested_time.utc.getlocal.strftime("%I:%M %p") %> - + <%=order.grand_total%> @@ -94,10 +100,13 @@ <%=i%> - + + <%= order.requested_time.utc.getlocal.strftime("%d-%m-%Y") %> + + <%= order.requested_time.utc.getlocal.strftime("%I:%M %p") %> - + <%=order.grand_total%> @@ -125,10 +134,13 @@ <%=i%> - + + <%= order.requested_time.utc.getlocal.strftime("%d-%m-%Y") %> + + <%= order.requested_time.utc.getlocal.strftime("%I:%M %p") %> - + <%=order.grand_total%> diff --git a/app/views/print_settings/_form.html.erb b/app/views/print_settings/_form.html.erb index ae1f90c1..e07da111 100755 --- a/app/views/print_settings/_form.html.erb +++ b/app/views/print_settings/_form.html.erb @@ -16,7 +16,7 @@ <% if(@server_mode != 'cloud') %> <%= f.input :printer_name, :as => :select, :collection => Printer::PrinterWorker.printers, include_blank: false %> <% else %> - <%= f.input :printer_name, :as => :select, :collection => [] %> + <%= f.input :printer_name %> <% end %> <%= f.input :brand_name %> <%= f.input :printer_type %> diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 92add0d2..4f1413c4 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -86,3 +86,64 @@ class ActionController::Base end end + +class ActionController::API + before_action :lookup_domain + + private + + 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.dbhost + 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 + 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 + + #change locallization + def set_locale + I18n.locale = params[:locale] || I18n.default_locale + end + + # RESTful url for localize + def default_url_options + { locale: I18n.locale } + end + +end + diff --git a/config/initializers/mysql2_adapter.rb b/config/initializers/mysql2_adapter.rb index 6a8e43fa..11b20b0f 100755 --- a/config/initializers/mysql2_adapter.rb +++ b/config/initializers/mysql2_adapter.rb @@ -24,7 +24,7 @@ module ActiveRecord end client = Mysql2::Client.new(config.symbolize_keys) - options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], config[:wait_timeout], 0] + options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], config[:pool], config[:wait_timeout], 0] ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config) end end diff --git a/config/secrets.yml b/config/secrets.yml index 218234f1..b0d7c5c8 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -13,7 +13,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 sx_provision_url: https://connect.pos-myanmar.com/bensai/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api - server_mode: application + server_mode: cloud cipher_type: AES-256-CBC sx_key: Wh@t1$C2L