From ede876ea27fd27779a7fee9e8c46384d1357cacd Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 27 Dec 2017 16:42:37 +0630 Subject: [PATCH 01/16] index / home --- app/controllers/origami/home_controller.rb | 6 +++--- app/views/origami/home/index.html.erb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 8e5b33c2..12c7fb76 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -7,7 +7,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.all.order('date desc') @shop = Shop.find_by_id(1) - + # @shift = ShiftSale.current_open_shift(current_user.id) end @@ -17,7 +17,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.all.order('date desc') - + @status_order = "" @status_sale = "" @sale_array = Array.new @@ -70,7 +70,7 @@ class Origami::HomeController < BaseOrigamiController end end end - + end private diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 4e3d27c1..ad7c8b58 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -42,7 +42,7 @@ <% if table.status == 'occupied' %> <% if table.get_booking.nil? %>
-
+
Zone <%= table.zone_id %>
Table <%= table.name %> ( <%= table.seater %> Seat )
@@ -53,7 +53,7 @@ <% else %>
<% end %> -
+
Zone <%= table.zone_id %>
Table <%= table.name %> ( <%= table.seater %> Seat )
@@ -104,7 +104,7 @@ <% end %>
- +
From a009f359fadb2cec92c0e5cc00ef62602383a8b2 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Wed, 18 Apr 2018 14:44:25 +0630 Subject: [PATCH 02/16] update puma production --- config/puma.rb | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100755 config/puma.rb diff --git a/config/puma.rb b/config/puma.rb deleted file mode 100755 index c8e0145e..00000000 --- a/config/puma.rb +++ /dev/null @@ -1,48 +0,0 @@ -# Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers a minimum and maximum. -# Any libraries that use thread pools should be configured to match -# the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum, this matches the default thread size of Active Record. -# -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i -threads threads_count, threads_count - -# Specifies the `port` that Puma will listen on to receive requests, default is 3000. -# -port ENV.fetch("PORT") { 3000 } - -# Specifies the `environment` that Puma will run in. -# -environment ENV.fetch("RAILS_ENV") { "development" } - -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked webserver processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). -# -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } - -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. If you use this option -# you need to make sure to reconnect any threads in the `on_worker_boot` -# block. -# -# preload_app! - -# The code in the `on_worker_boot` will be called if you are using -# clustered mode by specifying a number of `workers`. After each worker -# process is booted this block will be run, if you are using `preload_app!` -# option you will want to use this block to reconnect to any threads -# or connections that may have been created at application boot, Ruby -# cannot share connections between processes. -# -# on_worker_boot do -# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) -# end - -# Allow puma to be restarted by `rails restart` command. - -plugin :tmp_restart From 924edd823a96221c707d7637981342996ef36689 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 19 Apr 2018 10:49:58 +0630 Subject: [PATCH 03/16] update shift_sale migration file and secret yml --- config/secrets.yml | 2 +- db/migrate/20170626191519_create_shift_sales.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/secrets.yml b/config/secrets.yml index 6e8b73d4..b0d7c5c8 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -24,7 +24,7 @@ test: # instead read values from the environment. production: secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 - sx_provision_url: connect.smartsales.asia/api #192.168.1.147:3002/api + sx_provision_url: https://connect.pos-myanmar.com/api #192.168.1.147:3002/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L diff --git a/db/migrate/20170626191519_create_shift_sales.rb b/db/migrate/20170626191519_create_shift_sales.rb index f18a2c1c..bd19a8cf 100755 --- a/db/migrate/20170626191519_create_shift_sales.rb +++ b/db/migrate/20170626191519_create_shift_sales.rb @@ -21,7 +21,7 @@ class CreateShiftSales < ActiveRecord::Migration[5.1] t.integer :dining_count, :default => 0 t.integer :takeaway_count, :default => 0 t.integer :member_count, :default => 0 - t.decimal :total_rounding,, :precision => 10, :scale => 2, :null => false, :default => 0.00 + t.decimal :total_rounding, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.integer :total_receipt, :default => 0 t.decimal :total_void, :default => 0 t.timestamps From 509d3a2b181fecc537a5efb5ad326030d8e2e699 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 23 Apr 2018 11:49:36 +0630 Subject: [PATCH 04/16] add mysql config option wait timeout --- app/models/my_aes_crypt.rb | 5 +++-- config/initializers/mysql2_adapter.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index 20f747c9..7c86b158 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -62,8 +62,9 @@ class MyAesCrypt shop_json = JSON.parse(shop_data) shop_json["data"].each do |j| - if j["lookup"] == from - if(j["value"]["key"] == token) + if j["lookup"] == from + # add [0...44] for production cloud for remove \n + if(j["value"]["key"][0...44] == token) return true end end diff --git a/config/initializers/mysql2_adapter.rb b/config/initializers/mysql2_adapter.rb index 09424ddf..6a8e43fa 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], 0] + options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], config[:wait_timeout], 0] ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config) end end From cbb7a14621243f39185bc2bd01b2f63bb6ac4134 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 23 Apr 2018 14:17:56 +0630 Subject: [PATCH 05/16] update action cable for cloud --- app/controllers/origami/addorders_controller.rb | 4 ++-- app/controllers/origami/second_display_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index e3122ded..499c20a7 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -184,11 +184,11 @@ puts items_arr.to_json @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) # for second display - if ENV["SERVER_MODE"] != 'cloud' + # if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale" - end + # end result = {:status=> @status, :data => @sale } render :json => result.to_json end diff --git a/app/controllers/origami/second_display_controller.rb b/app/controllers/origami/second_display_controller.rb index 4f2c06f8..611b49a9 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 From b92889fb237e3b7867c2b6f38580274cde593410 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 23 Apr 2018 14:41:07 +0630 Subject: [PATCH 06/16] change base url settings --- README.md | 3 +++ app/controllers/concerns/token_verification.rb | 3 ++- app/models/order_reservation.rb | 14 +++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fcc35040..712d61a9 100755 --- a/README.md +++ b/README.md @@ -184,6 +184,9 @@ For MoveTablePdf in print settings Add Kitchen Role of Employee => 1) settings/lookups => { type:employee_roles, name: Kitchen, value:kitchen } +Add Base URL for DOEMAL + 1) settings/lookups => { type:order_reservation, name: BaseURL, value:'{doemal url}' } + * ToDo list 1. Migration diff --git a/app/controllers/concerns/token_verification.rb b/app/controllers/concerns/token_verification.rb index b49ef597..85c9b858 100755 --- a/app/controllers/concerns/token_verification.rb +++ b/app/controllers/concerns/token_verification.rb @@ -24,7 +24,8 @@ module TokenVerification end end - @user = Employee.authenticate_by_token(token) + @user = Employee. + (token) if @user return true #Maybe log - login? diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 2fa99cf4..2d931d36 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -219,7 +219,19 @@ class OrderReservation < ApplicationRecord end def self.send_status_to_ordering(url,ref_no,status) - base_url = "http://192.168.1.186:3002" + base_url = 'https://api.doemal.com' + order_reservation = Lookup.collection_of("order_reservation") + if !order_reservation.empty? + order_reservation.each do |order_reserve| + if order_reserve[0] == 'BaseURL' + base_url = order_reserve[1] + end + end + else + Rails.logger.debug "Add order reservation BaseURL " + response = {status: false} + end + Rails.logger.debug "Doemal URL" + base_url post_url = base_url + url begin From 5ea950f5aa75108223d3abc53345983c772dc8a8 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 23 Apr 2018 14:43:27 +0630 Subject: [PATCH 07/16] update addore cable for second display closed --- app/controllers/origami/addorders_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 499c20a7..2eab460a 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -184,11 +184,11 @@ puts items_arr.to_json @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) # for second display - # if ENV["SERVER_MODE"] != 'cloud' + if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale" - # end + end result = {:status=> @status, :data => @sale } render :json => result.to_json end From 2255fcd2d473d2ac694285bd5ed121de0db0a748 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 23 Apr 2018 15:09:04 +0630 Subject: [PATCH 08/16] add token in lookups --- README.md | 1 + app/models/order_reservation.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 712d61a9..43a2091e 100755 --- a/README.md +++ b/README.md @@ -186,6 +186,7 @@ Add Kitchen Role of Employee 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}' } * ToDo list diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 2d931d36..5aab27ba 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -220,11 +220,14 @@ class OrderReservation < ApplicationRecord def self.send_status_to_ordering(url,ref_no,status) base_url = 'https://api.doemal.com' + token = '3T-tnlYtFJ-5Z1vY6XQqxQ' order_reservation = Lookup.collection_of("order_reservation") if !order_reservation.empty? order_reservation.each do |order_reserve| if order_reserve[0] == 'BaseURL' base_url = order_reserve[1] + elsif order_reserve[0] == 'Token' + token = order_reserve[1] end end else @@ -234,11 +237,12 @@ class OrderReservation < ApplicationRecord Rails.logger.debug "Doemal URL" + base_url post_url = base_url + url + begin response = HTTParty.post(post_url, :body => { id: ref_no, status: status}.to_json, :headers => { - 'Authorization' => 'Token token=3T-tnlYtFJ-5Z1vY6XQqxQ', + 'Authorization' => 'Token token='+token, 'Content-Type' => 'application/json', 'Accept' => 'application/json; version=3' }, :timeout => 10 From 6e3a5300a69733b36548725719d407bd8cfb1341 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 23 Apr 2018 15:39:56 +0630 Subject: [PATCH 09/16] close cable in cloud mode --- app/controllers/api/bill_controller.rb | 4 +++- app/controllers/api/call_waiters_controller.rb | 5 +++-- .../order_reserve/order_reservation_controller.rb | 5 +++-- .../origami/request_bills_controller.rb | 4 +++- app/controllers/origami/split_bill_controller.rb | 6 +++--- app/models/dining_facility.rb | 8 ++++++-- app/models/order.rb | 14 +++++++++++--- app/models/sale_payment.rb | 4 +++- 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 994f6fe4..a4c8b383 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..d0a0e3df 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..486e0c9e 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -59,8 +59,9 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation_id, flag = OrderReservation.addOrderReservationInfo(params) order_reservation = OrderReservation.find(order_reservation_id) - ActionCable.server.broadcast "order_reservation_channel",data: order_reservation - + if 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!" } else diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 05dbdce4..8c1d3a43 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/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index 8cd68d9c..547a8a7e 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..793ba287 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/order.rb b/app/models/order.rb index e4ab883b..a4f27778 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/sale_payment.rb b/app/models/sale_payment.rb index 29d755d7..098b5733 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 From 3d39e398df07dd0028a0bddc86258841ef69246e Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 23 Apr 2018 16:16:41 +0630 Subject: [PATCH 10/16] remove actioncable --- .../api/order_reserve/order_reservation_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 486e0c9e..c3c9f39b 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -59,9 +59,9 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation_id, flag = OrderReservation.addOrderReservationInfo(params) order_reservation = OrderReservation.find(order_reservation_id) - if ENV["SERVER_MODE"] != 'cloud' - ActionCable.server.broadcast "order_reservation_channel",data: order_reservation - end + # if 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!" } else From 403f70480dab70e5e0b954db336d0c0f9b9fd9c2 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 23 Apr 2018 16:23:00 +0630 Subject: [PATCH 11/16] api cloud update --- app/controllers/api/api_controller.rb | 73 ++++++++++++------------ app/models/license.rb | 4 +- app/models/my_aes_crypt.rb | 2 +- config/initializers/action_controller.rb | 61 ++++++++++++++++++++ config/secrets.yml | 2 +- 5 files changed, 101 insertions(+), 41 deletions(-) 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/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/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 8a149cb7..a3b19ebe 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/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 From e62ba4d6c2cf320adde95eac11fd11a6b7772c88 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 23 Apr 2018 19:20:03 +0630 Subject: [PATCH 12/16] change params --- .../order_reservation_controller.rb | 3 +- app/models/order_reservation.rb | 48 +++++++++---------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index c3c9f39b..61e89c39 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -56,7 +56,8 @@ 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) # if ENV["SERVER_MODE"] != 'cloud' diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 5aab27ba..8ab87c55 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -12,40 +12,40 @@ class OrderReservation < ApplicationRecord DELIVERED = "delivered" COMPLETED = "completed" - def self.addOrderReservationInfo(params) - check_order_reservation = OrderReservation.where("transaction_ref = ?",params[:reference]) + def self.addOrderReservationInfo(order_reservation) + check_order_reservation = OrderReservation.where("transaction_ref = ?",order_reservation[: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_reservation[:order_type] + order_reservation.customer_id = order_reservation[:cus_info] + order_reservation.requested_time = DateTime.parse(order_reservation[:requested_time]).utc.strftime("%Y-%m-%d %H:%M:%S") + order_reservation.callback_url = order_reservation[:callback_url] + order_reservation.transaction_ref = order_reservation[:reference] + if order_reservation[:order_info] + order_reservation.item_count = order_reservation[:order_info][:items].count + order_reservation.payment_type = order_reservation[:payment_info][:payment_type] + order_reservation.payment_status = order_reservation[:payment_info][:payment_status] + order_reservation.payment_ref = order_reservation[:payment_info][:payment_ref] + order_reservation.total_amount = order_reservation[:payment_info][:sub_total] + order_reservation.total_tax = order_reservation[:payment_info][:total_tax] + order_reservation.discount_amount = order_reservation[:payment_info][:discount_amount] + order_reservation.grand_total = order_reservation[:payment_info][:grand_total] + order_reservation.order_remark = order_reservation[: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_reservation[:reservation_info] + order_reservation.total_customer = order_reservation[:reservation_info][:total_user] + order_reservation.reservation_remark = order_reservation[:reservation_info][:reservation_note] end order_reservation.save! - if params[:order_info][:items] - params[:order_info][:items].each do |oritem| + if order_reservation[:order_info][:items] + order_reservation[: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_reservation[:delivery_info] + Delivery.addDeliveryInfo(order_reservation[:delivery_info],order_reservation.id) end return order_reservation.id, true else From d0ad95c8d69c9c3883ce25084033ca92684b19ca Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 23 Apr 2018 19:32:32 +0630 Subject: [PATCH 13/16] change name --- app/models/order_reservation.rb | 49 +++++++++++++++++---------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 8ab87c55..3c401e31 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -12,40 +12,41 @@ class OrderReservation < ApplicationRecord DELIVERED = "delivered" COMPLETED = "completed" - def self.addOrderReservationInfo(order_reservation) - check_order_reservation = OrderReservation.where("transaction_ref = ?",order_reservation[: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 = order_reservation[:order_type] - order_reservation.customer_id = order_reservation[:cus_info] - order_reservation.requested_time = DateTime.parse(order_reservation[:requested_time]).utc.strftime("%Y-%m-%d %H:%M:%S") - order_reservation.callback_url = order_reservation[:callback_url] - order_reservation.transaction_ref = order_reservation[:reference] - if order_reservation[:order_info] - order_reservation.item_count = order_reservation[:order_info][:items].count - order_reservation.payment_type = order_reservation[:payment_info][:payment_type] - order_reservation.payment_status = order_reservation[:payment_info][:payment_status] - order_reservation.payment_ref = order_reservation[:payment_info][:payment_ref] - order_reservation.total_amount = order_reservation[:payment_info][:sub_total] - order_reservation.total_tax = order_reservation[:payment_info][:total_tax] - order_reservation.discount_amount = order_reservation[:payment_info][:discount_amount] - order_reservation.grand_total = order_reservation[:payment_info][:grand_total] - order_reservation.order_remark = order_reservation[: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 order_reservation[:reservation_info] - order_reservation.total_customer = order_reservation[:reservation_info][:total_user] - order_reservation.reservation_remark = order_reservation[: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 order_reservation[:order_info][:items] - order_reservation[: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 order_reservation[:delivery_info] - Delivery.addDeliveryInfo(order_reservation[: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 From 9b0a564b9a3af8f8c33e7f77ac276e3f36393844 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 25 Apr 2018 13:18:54 +0630 Subject: [PATCH 14/16] update cable for cloud --- app/controllers/api/bill_controller.rb | 4 ++-- app/controllers/api/call_waiters_controller.rb | 4 ++-- .../order_reservation_controller.rb | 2 +- app/controllers/origami/addorders_controller.rb | 8 +++----- .../origami/request_bills_controller.rb | 4 ++-- .../origami/second_display_controller.rb | 4 ++-- app/controllers/origami/split_bill_controller.rb | 4 ++-- app/models/dining_facility.rb | 4 ++-- app/models/order.rb | 16 ++++++++-------- app/models/sale_payment.rb | 4 ++-- 10 files changed, 26 insertions(+), 28 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index a4c8b383..2fb3d621 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -47,9 +47,9 @@ class Api::BillController < Api::ApiController Promotion.promo_activate(@sale) #BillBroadcastJob.perform_later(table) - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "bill_channel",table: table - end + #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 d0a0e3df..b8c11897 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -6,9 +6,9 @@ class Api::CallWaitersController < ActionController::API @time = params[:time] @table = DiningFacility.find(@table_id) # CallWaiterJob.perform_later(@table,@time) - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time - end + #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 61e89c39..89571a9a 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -61,7 +61,7 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation = OrderReservation.find(order_reservation_id) # if ENV["SERVER_MODE"] != 'cloud' - # ActionCable.server.broadcast "order_reservation_channel",data: order_reservation + 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/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 8c1d3a43..0c50a5da 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -39,9 +39,9 @@ class Origami::RequestBillsController < ApplicationController # Promotion Activation Promotion.promo_activate(@sale) #bill channel - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "bill_channel",table: table - end + #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 547a8a7e..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) - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "bill_channel",table: table - end + #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 793ba287..cff5fd60 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -156,9 +156,9 @@ class DiningFacility < ApplicationRecord table = DiningFacility.find(table_id) #Send to background job for processing # CheckInBookingJob.perform_later(table) - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "check_in_booking_channel",table: table - end + #end end def self.checkin_time diff --git a/app/models/order.rb b/app/models/order.rb index a4f27778..01a7b583 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -321,9 +321,9 @@ class Order < ApplicationRecord end else msg = ' Print Error ! Please contact to service' - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' - end + #end if !sidekiq.nil? OrderQueueProcessorJob.perform_later(self.id, self.table_id) else @@ -337,9 +337,9 @@ class Order < ApplicationRecord end end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "order_queue_station_channel",order: assign_order - end + #end end end @@ -376,9 +376,9 @@ class Order < ApplicationRecord type = 'order' #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "order_channel",table: table,type:type - end + #end end end @@ -532,9 +532,9 @@ class Order < ApplicationRecord end end end - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "second_display_channel",data: @data_array,status:@status - end + #end end private diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 098b5733..3dba0a9b 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -607,9 +607,9 @@ class SalePayment < ApplicationRecord type = 'payment' #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) - if ENV["SERVER_MODE"] != 'cloud' + #if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "order_channel",table: table,type:type - end + #end end end end From 32fb28660e295ff4bab2be6c05245fd61500c622 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 25 Apr 2018 14:15:04 +0630 Subject: [PATCH 15/16] add pool zine in adapter --- config/initializers/mysql2_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From b41c85132dd13dfc34867d59a566ae08d842de0d Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 25 Apr 2018 15:07:43 +0630 Subject: [PATCH 16/16] add order and reservation, quick service in lookups and add date and order by in order reservation --- README.md | 8 ++++++ .../javascripts/channels/order_reservation.js | 7 +++-- .../order_reservation_controller.rb | 6 ++-- .../origami/dashboard_controller.rb | 16 +++++++++++ .../origami/order_reservation_controller.rb | 2 +- .../origami/payments_controller.rb | 2 +- app/models/order_reservation.rb | 2 ++ app/views/origami/dashboard/index.html.erb | 4 +++ .../origami/order_reservation/index.html.erb | 28 +++++++++++++------ app/views/print_settings/_form.html.erb | 2 +- 10 files changed, 61 insertions(+), 16 deletions(-) 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/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 61e89c39..81e12952 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -60,9 +60,9 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation) order_reservation = OrderReservation.find(order_reservation_id) - # if ENV["SERVER_MODE"] != 'cloud' - # ActionCable.server.broadcast "order_reservation_channel",data: order_reservation - # end + 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!" } else 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/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/models/order_reservation.rb b/app/models/order_reservation.rb index 3c401e31..296523cb 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -7,6 +7,8 @@ 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" 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/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 %>