Single database for multiple shops

Use ActsAsTenant as Multi-tenancy for shops

See below files:
- app/controllers/concern/multi_tenancy.rb
- app/models/application_record.rb
- app/models/shop.rb

An initializer can be created to control option in ActsAsTenant.
config/initializers/acts_as_tenant.rb
require 'acts_as_tenant/sidekiq'
ActsAsTenant.configure do |config|
  config.require_tenant = false # true
end

more details: https://github.com/ErwinM/acts_as_tenant
This commit is contained in:
Thein Lin Kyaw
2019-12-02 17:19:28 +06:30
parent 5d10d4b6a1
commit 937f40e7c1
78 changed files with 215 additions and 173 deletions

View File

@@ -41,6 +41,9 @@ gem 'material_icons'
gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.2' gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.2'
gem 'rack-cors' gem 'rack-cors'
# Multi-tenancy for shops
gem 'acts_as_tenant'
# image upload # image upload
gem 'carrierwave', '~> 1.0' gem 'carrierwave', '~> 1.0'
gem 'mini_magick' gem 'mini_magick'

View File

@@ -46,6 +46,9 @@ GEM
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
acts_as_tenant (0.4.4)
rails (>= 4.0)
request_store (>= 1.0.5)
aescrypt (1.0.0) aescrypt (1.0.0)
airbrussh (1.4.0) airbrussh (1.4.0)
sshkit (>= 1.6.1, != 1.7.0) sshkit (>= 1.6.1, != 1.7.0)
@@ -219,6 +222,8 @@ GEM
rb-inotify (0.10.0) rb-inotify (0.10.0)
ffi (~> 1.0) ffi (~> 1.0)
redis (3.3.5) redis (3.3.5)
request_store (1.4.1)
rack (>= 1.4)
roo (1.13.2) roo (1.13.2)
nokogiri nokogiri
rubyzip rubyzip
@@ -315,6 +320,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
acts_as_tenant
aescrypt aescrypt
axlsx (= 2.0.1) axlsx (= 2.0.1)
axlsx_rails axlsx_rails
@@ -374,10 +380,8 @@ DEPENDENCIES
web-console (>= 3.3.0) web-console (>= 3.3.0)
whenever whenever
RUBY VERSION RUBY VERSION
ruby 2.4.1p111 ruby 2.4.1p111
BUNDLED WITH BUNDLED WITH
2.0.2 2.0.2

View File

@@ -1,5 +1,5 @@
class Api::ApiController < ActionController::API class Api::ApiController < ActionController::API
include TokenVerification include TokenVerification, MultiTenancy
include ActionController::MimeResponds include ActionController::MimeResponds
# before_action :lookup_domain # before_action :lookup_domain

View File

@@ -106,7 +106,7 @@ class Api::BillController < Api::ApiController
# unique_code = "ReceiptBillPdf" # unique_code = "ReceiptBillPdf"
# #shop detail # #shop detail
# shop_details = Shop.find(1) # shop_details = Shop.current_shop
# customer= Customer.find(@sale_data.customer_id) # customer= Customer.find(@sale_data.customer_id)
# # get member information # # get member information

View File

@@ -23,7 +23,7 @@ class Api::CallWaitersController < ActionController::API
end end
ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time,from: from, shift_ids: shift_ids ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time,from: from, shift_ids: shift_ids
# get printer info # get printer info
@shop = Shop.first @shop = Shop.current_shop
unique_code = "CallWaiterPdf" unique_code = "CallWaiterPdf"
print_settings = PrintSetting.find_by_unique_code(unique_code) print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings) printer = Printer::ReceiptPrinter.new(print_settings)

View File

@@ -70,7 +70,7 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController
order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation) order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation)
if !order_reservation_id.nil? && flag if !order_reservation_id.nil? && flag
shop = Shop.find_by_id(1) shop = Shop.current_shop
if !shop.nil? if !shop.nil?
shop_code = shop.shop_code shop_code = shop.shop_code
order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio") order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio")

View File

@@ -46,7 +46,7 @@ class Api::OrdersController < Api::ApiController
@tax_profile = TaxProfile.where("lower(group_type)='cashier'") @tax_profile = TaxProfile.where("lower(group_type)='cashier'")
# end # end
@shop = Shop.first @shop = Shop.current_shop
puts "Hello world" puts "Hello world"
puts @shop.to_json puts @shop.to_json
return @shop.to_json return @shop.to_json

View File

@@ -14,7 +14,7 @@ class Api::Payment::MobilepaymentController < Api::ApiController
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id)
shop_detail = Shop.first shop_detail = Shop.current_shop
# rounding adjustment # rounding adjustment
if !path.include? ("credit_payment") if !path.include? ("credit_payment")

View File

@@ -2,7 +2,7 @@ class Api::SoundEffectController < Api::ApiController
#sound effect / alarm api for doemal side calling #sound effect / alarm api for doemal side calling
def sound_effect def sound_effect
shop = Shop.find_by_id(1) shop = Shop.current_shop
if !shop.nil? if !shop.nil?
shop_code = shop.shop_code shop_code = shop.shop_code
order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio") order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio")

View File

@@ -1,5 +1,5 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include LoginVerification include LoginVerification, MultiTenancy
#before_action :check_installation #before_action :check_installation
protect_from_forgery with: :exception protect_from_forgery with: :exception

View File

@@ -1,5 +1,6 @@
class BaseController < ActionController::Base class BaseController < ActionController::Base
include MultiTenancy
layout "installation" layout "installation"
protect_from_forgery with: :exception protect_from_forgery with: :exception
end end

View File

@@ -1,5 +1,5 @@
class BaseCrmController < ActionController::Base class BaseCrmController < ActionController::Base
include LoginVerification include LoginVerification,
layout "CRM" layout "CRM"
before_action :check_user before_action :check_user

View File

@@ -1,5 +1,5 @@
class BaseInventoryController < ActionController::Base class BaseInventoryController < ActionController::Base
include LoginVerification include LoginVerification, MultiTenancy
layout "inventory" layout "inventory"
before_action :check_user before_action :check_user

View File

@@ -1,5 +1,5 @@
class BaseOqsController < ActionController::Base class BaseOqsController < ActionController::Base
include LoginVerification include LoginVerification, MultiTenancy
layout "OQS" layout "OQS"
before_action :check_user before_action :check_user

View File

@@ -1,5 +1,5 @@
class BaseOrigamiController < ActionController::Base class BaseOrigamiController < ActionController::Base
include LoginVerification include LoginVerification, MultiTenancy
layout "origami" layout "origami"
before_action :check_user before_action :check_user

View File

@@ -1,5 +1,5 @@
class BaseReportController < ActionController::Base class BaseReportController < ActionController::Base
include LoginVerification include LoginVerification, MultiTenancy
layout "application" layout "application"
before_action :check_user before_action :check_user
@@ -69,7 +69,7 @@ class BaseReportController < ActionController::Base
from = from.beginning_of_day from = from.beginning_of_day
to = to.end_of_day to = to.end_of_day
return from, to return from, to
end end

View File

@@ -1,5 +1,5 @@
class BaseWaiterController < ActionController::Base class BaseWaiterController < ActionController::Base
include LoginVerification include LoginVerification, MultiTenancy
layout "waiter" layout "waiter"
before_action :check_user before_action :check_user

View File

@@ -3,7 +3,7 @@ module LoginVerification
included do included do
before_action :authenticate_session_token before_action :authenticate_session_token
helper_method :current_company,:current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail helper_method :current_company, :current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail
end end
#this is base api base controller to need to inherit. #this is base api base controller to need to inherit.
@@ -19,7 +19,7 @@ module LoginVerification
def current_shop def current_shop
begin begin
return Shop.first return Shop.current_shop
rescue rescue
return nil return nil
end end
@@ -41,7 +41,7 @@ module LoginVerification
#Shop Name in Navbor #Shop Name in Navbor
def shop_detail def shop_detail
@shop = Shop.first @shop = current_shop
end end
#check order reservation used #check order reservation used
@@ -78,11 +78,11 @@ module LoginVerification
protected protected
# Authenticate the user with token based authentication # Authenticate the user with token based authentication
def authenticate def authenticate
authenticate_session_token || render_unauthorized authenticate_session_token || render_unauthorized
end end
def authenticate_session_token def authenticate_session_token
token = session[:session_token] token = session[:session_token]
if (token) if (token)
#@current_user = User.find_by(api_key: token) #@current_user = User.find_by(api_key: token)

View File

@@ -0,0 +1,20 @@
module MultiTenancy
extend ActiveSupport::Concern
included do
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
before_action :find_shop_by_subdomain_or_frist if respond_to? :before_action
helper_method :current_shop if respond_to? :helper_method
end
private
def find_shop_by_subdomain_or_frist
if request.subdomain.present?
shop_code = request.subdomain.partition('-').last
shop = Shop.find_by(shop_code: shop_code)
else
shop = Shop.first
end
set_current_tenant(shop)
end
end

View File

@@ -82,7 +82,7 @@ class Crm::CustomersController < BaseCrmController
@membership_types = Lookup.collection_of("member_group_type") @membership_types = Lookup.collection_of("member_group_type")
# @taxes = TaxProfile.where(:group_type => 'cashier') # @taxes = TaxProfile.where(:group_type => 'cashier')
@taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") @taxes = TaxProfile.unscope(:order).select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name")
.order("group_type ASC,order_by ASC") .order("group_type ASC,order_by ASC")
@filter = filter @filter = filter

View File

@@ -91,7 +91,7 @@ class HomeController < ApplicationController
def dashboard def dashboard
@from, @to = get_date_range_from_params @from, @to = get_date_range_from_params
@shop = Shop.first @shop = Shop.current_shop
@orders = Sale.receipt_date_between(@from, @to).where("payment_status = 'new' and sale_status = 'bill'") @orders = Sale.receipt_date_between(@from, @to).where("payment_status = 'new' and sale_status = 'bill'")
@sales = Sale.receipt_date_between(@from, @to).completed @sales = Sale.receipt_date_between(@from, @to).completed

View File

@@ -26,6 +26,6 @@ class Inventory::InventoryController < BaseInventoryController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -106,7 +106,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
private private

View File

@@ -64,7 +64,7 @@ class Inventory::StockCheckItemsController < BaseInventoryController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
private private

View File

@@ -41,7 +41,7 @@ class Inventory::StockChecksController < BaseInventoryController
member_info = nil member_info = nil
unique_code = 'StockCheckPdf' unique_code = 'StockCheckPdf'
shop_details = current_shop shop_details = Shop.current_shop
checker = Employee.find(stockcheck.check_by) checker = Employee.find(stockcheck.check_by)
print_settings = PrintSetting.find_by_unique_code(unique_code) print_settings = PrintSetting.find_by_unique_code(unique_code)
if !print_settings.nil? if !print_settings.nil?
@@ -66,7 +66,7 @@ class Inventory::StockChecksController < BaseInventoryController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = current_shop @shop = Shop.current_shop
end end
# before_action :set_stock_check, only: [:show, :edit, :update, :destroy] # before_action :set_stock_check, only: [:show, :edit, :update, :destroy]

View File

@@ -64,7 +64,7 @@ class StockJournalsController < ApplicationController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
private private

View File

@@ -85,6 +85,6 @@ class Oqs::EditController < BaseOqsController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -11,7 +11,7 @@ class Origami::AlipayController < BaseOrigamiController
end end
total = 0 total = 0
@alipaycount = 0 @alipaycount = 0
@shop = Shop.first @shop = Shop.current_shop
@rounding_adj = 0 @rounding_adj = 0
@can_alipay = 0 @can_alipay = 0
@member_discount = 0 @member_discount = 0
@@ -64,7 +64,7 @@ class Origami::AlipayController < BaseOrigamiController
ref_no = params[:ref_no] ref_no = params[:ref_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj
@@ -88,6 +88,6 @@ class Origami::AlipayController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -9,7 +9,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController
@creditcount = 0 @creditcount = 0
others = 0 others = 0
@shop = Shop.first @shop = Shop.current_shop
if @shop.is_rounding_adj if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total) new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
else else
@@ -32,7 +32,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController
sale_id = params[:sale_id] sale_id = params[:sale_id]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj

View File

@@ -3,11 +3,11 @@ class Origami::CreditSalesController < BaseOrigamiController
@cashier_type = 'cashier' @cashier_type = 'cashier'
@webview = false @webview = false
if check_mobile if check_mobile
@webview = true @webview = true
end end
@tables = Table.unscoped.all.active.order('status desc') @tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc') @rooms = Room.unscope(:order).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')) @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d'))
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@customers = Customer.pluck("customer_id, name") @customers = Customer.pluck("customer_id, name")
@@ -15,7 +15,7 @@ class Origami::CreditSalesController < BaseOrigamiController
@sale = Sale.find_by_sale_id(params[:sale_id]) @sale = Sale.find_by_sale_id(params[:sale_id])
@sale_payment = SalePayment.select("SUM(payment_amount) as payment_amount") @sale_payment = SalePayment.select("SUM(payment_amount) as payment_amount")
.where("sale_id = ? and payment_method=?", @sale.sale_id, "creditnote") .where("sale_id = ? and payment_method=?", @sale.sale_id, "creditnote")
@sale_taxes = [] @sale_taxes = []
sale_taxes = SaleTax.where("sale_id = ?", @sale.sale_id) sale_taxes = SaleTax.where("sale_id = ?", @sale.sale_id)
if !sale_taxes.empty? if !sale_taxes.empty?
@@ -24,5 +24,5 @@ class Origami::CreditSalesController < BaseOrigamiController
end end
end end
end end
end end

View File

@@ -87,7 +87,7 @@ class Origami::CustomersController < BaseOrigamiController
@count_customer = Customer.count_customer @count_customer = Customer.count_customer
# @taxes = TaxProfile.where(:group_type => 'cashier') # @taxes = TaxProfile.where(:group_type => 'cashier')
@taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") @taxes = TaxProfile.unscope(:order).select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name")
.order("group_type ASC,order_by ASC") .order("group_type ASC,order_by ASC")
# if flash["errors"] # if flash["errors"]
# @crm_customer.valid? # @crm_customer.valid?

View File

@@ -1,7 +1,7 @@
class Origami::DashboardController < BaseOrigamiController class Origami::DashboardController < BaseOrigamiController
def index def index
@shop = Shop.first @shop = Shop.current_shop
@display_type = Lookup.find_by_lookup_type("display_type") @display_type = Lookup.find_by_lookup_type("display_type")
@sale_data = Array.new @sale_data = Array.new

View File

@@ -6,7 +6,7 @@ class Origami::DingaController < BaseOrigamiController
@membership_rebate_balance=0 @membership_rebate_balance=0
@sale_data = Sale.find_by_sale_id(@sale_id) @sale_data = Sale.find_by_sale_id(@sale_id)
@receipt_no = @sale_data.receipt_no @receipt_no = @sale_data.receipt_no
@shop = Shop.first @shop = Shop.current_shop
if @shop.is_rounding_adj if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(@sale_data.grand_total) new_total = Sale.get_rounding_adjustment(@sale_data.grand_total)
else else
@@ -77,7 +77,7 @@ def create
account_no = params[:account_no] account_no = params[:account_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj
# new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # new_total = Sale.get_rounding_adjustment(saleObj.grand_total)

View File

@@ -6,7 +6,7 @@ class Origami::GiftVoucherController < BaseOrigamiController
sale_data = Sale.find_by_sale_id(@sale_id) sale_data = Sale.find_by_sale_id(@sale_id)
total = 0 total = 0
@gift_vouchercount = 0 @gift_vouchercount = 0
@shop = Shop.first @shop = Shop.current_shop
@rounding_adj = 0 @rounding_adj = 0
@can_gift_voucher = 0 @can_gift_voucher = 0
@member_discount = 0 @member_discount = 0
@@ -48,7 +48,7 @@ class Origami::GiftVoucherController < BaseOrigamiController
ref_no = params[:reference_no] ref_no = params[:reference_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj
@@ -66,6 +66,6 @@ class Origami::GiftVoucherController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -4,8 +4,8 @@ class Origami::HomeController < BaseOrigamiController
def index def index
@webview = check_mobile @webview = check_mobile
@tables = Table.unscoped.all.active.order('status desc') @tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc') @rooms = Room.unscope(:order).all.active.order('status desc')
@complete = Sale.completed_sale("cashier") @complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@@ -21,8 +21,8 @@ class Origami::HomeController < BaseOrigamiController
@print_settings = PrintSetting.get_precision_delimiter() @print_settings = PrintSetting.get_precision_delimiter()
@webview = check_mobile @webview = check_mobile
@tables = Table.unscoped.all.active.order('status desc') @tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc') @rooms = Room.unscope(:order).all.active.order('status desc')
@complete = Sale.completed_sale("cashier") @complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@customers = Customer.pluck("customer_id, name") @customers = Customer.pluck("customer_id, name")
@@ -126,7 +126,7 @@ class Origami::HomeController < BaseOrigamiController
lookup_edit_order = Lookup.collection_of('edit_order') lookup_edit_order = Lookup.collection_of('edit_order')
if !lookup_edit_order.empty? if !lookup_edit_order.empty?
lookup_edit_order.each do |edit_order| lookup_edit_order.each do |edit_order|
if edit_order[0].downcase == "editorderorigami" if edit_order[0].downcase == "editorderorigami"
if edit_order[1] == '0' && (current_login_employee.role == 'cashier' || current_login_employee.role == 'waiter') if edit_order[1] == '0' && (current_login_employee.role == 'cashier' || current_login_employee.role == 'waiter')
@edit_order_origami = false @edit_order_origami = false
end end
@@ -139,14 +139,14 @@ class Origami::HomeController < BaseOrigamiController
lookup_changable_tax = Lookup.collection_of('changable_tax') lookup_changable_tax = Lookup.collection_of('changable_tax')
if !lookup_changable_tax.empty? if !lookup_changable_tax.empty?
lookup_changable_tax.each do |changable_tax| lookup_changable_tax.each do |changable_tax|
if changable_tax[0].downcase == "change" if changable_tax[0].downcase == "change"
if changable_tax[1] == '0' if changable_tax[1] == '0'
@changable_tax = false @changable_tax = false
end end
end end
end end
end end
end end
def check_emp_access_code def check_emp_access_code

View File

@@ -12,7 +12,7 @@ class Origami::JcbController < BaseOrigamiController
end end
total = 0 total = 0
@jcbcount = 0 @jcbcount = 0
@shop = Shop.first @shop = Shop.current_shop
@rounding_adj = 0 @rounding_adj = 0
@can_jcb = 0 @can_jcb = 0
@member_discount= 0 @member_discount= 0
@@ -66,7 +66,7 @@ class Origami::JcbController < BaseOrigamiController
ref_no = params[:ref_no] ref_no = params[:ref_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj
@@ -89,6 +89,6 @@ class Origami::JcbController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -11,7 +11,7 @@ class Origami::JunctionPayController < BaseOrigamiController
@cashier_id = current_user.emp_id @cashier_id = current_user.emp_id
@payment_method_setting_nav = PaymentMethodSetting.all @payment_method_setting_nav = PaymentMethodSetting.all
@shop = Shop.first @shop = Shop.current_shop
if @shop.is_rounding_adj if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total) new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
else else
@@ -52,7 +52,7 @@ class Origami::JunctionPayController < BaseOrigamiController
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj

View File

@@ -12,7 +12,7 @@ class Origami::MasterController < BaseOrigamiController
end end
total = 0 total = 0
@mastercount = 0 @mastercount = 0
@shop = Shop.first @shop = Shop.current_shop
@rounding_adj = 0 @rounding_adj = 0
@can_master = 0 @can_master = 0
@member_discount = 0 @member_discount = 0
@@ -63,7 +63,7 @@ class Origami::MasterController < BaseOrigamiController
ref_no = params[:ref_no] ref_no = params[:ref_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj
@@ -87,6 +87,6 @@ class Origami::MasterController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -105,7 +105,7 @@ class Origami::MovetableController < BaseOrigamiController
# @type = (DiningFacility.find(change_to)).type # @type = (DiningFacility.find(change_to)).type
# @moved_by = @current_user.name # @moved_by = @current_user.name
# @date = DateTime.now # @date = DateTime.now
# @shop = Shop.first # @shop = Shop.current_shop
# unique_code = "MoveTablePdf" # unique_code = "MoveTablePdf"
# pdf_no = PrintSetting.where(:unique_code => unique_code).count # pdf_no = PrintSetting.where(:unique_code => unique_code).count
# #print_settings = PrintSetting.find_by_unique_code(unique_code) # #print_settings = PrintSetting.find_by_unique_code(unique_code)

View File

@@ -11,7 +11,7 @@ class Origami::MpuController < BaseOrigamiController
end end
total = 0 total = 0
@mpucount = 0 @mpucount = 0
@shop = Shop.first @shop = Shop.current_shop
@rounding_adj = 0 @rounding_adj = 0
@can_mpu = 0 @can_mpu = 0
@member_discount = 0 @member_discount = 0
@@ -64,7 +64,7 @@ class Origami::MpuController < BaseOrigamiController
ref_no = params[:ref_no] ref_no = params[:ref_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj
@@ -87,6 +87,6 @@ class Origami::MpuController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -4,7 +4,7 @@ class Origami::OrderReservationController < BaseOrigamiController
@order = OrderReservation.latest_order #.active @order = OrderReservation.latest_order #.active
@count_on_order = OrderReservation.get_count_on_order @count_on_order = OrderReservation.get_count_on_order
@count_on_completed = OrderReservation.get_count_on_completed @count_on_completed = OrderReservation.get_count_on_completed
@shop = Shop.find_by_id(1) @shop = Shop.current_shop
@receipt_bill = check_receipt_bill @receipt_bill = check_receipt_bill
end end

View File

@@ -5,8 +5,8 @@ class Origami::OrdersController < BaseOrigamiController
@webview = true @webview = true
end end
@tables = Table.unscoped.all.active.order('status desc') @tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc') @rooms = Room.unscope(:order).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')) @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d'))
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@order = Order.find(params[:order_id]) @order = Order.find(params[:order_id])

View File

@@ -6,7 +6,7 @@ class Origami::PaymalController < BaseOrigamiController
@membership_rebate_balance=0 @membership_rebate_balance=0
sale_data = Sale.find_by_sale_id(@sale_id) sale_data = Sale.find_by_sale_id(@sale_id)
@receipt_no = sale_data.receipt_no @receipt_no = sale_data.receipt_no
@shop = Shop.first @shop = Shop.current_shop
if @shop.is_rounding_adj if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total) new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
else else
@@ -75,7 +75,7 @@ def create
puts params.to_json puts params.to_json
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj

View File

@@ -59,7 +59,7 @@ class Origami::PaymentsController < BaseOrigamiController
end end
#shop detail #shop detail
## shop_detail = Shop.first ## shop_detail = Shop.current_shop
# customer= Customer.where('customer_id=' +.customer_id) # customer= Customer.where('customer_id=' +.customer_id)
customer = Customer.find(sale_data.customer_id) customer = Customer.find(sale_data.customer_id)
# rounding adjustment # rounding adjustment
@@ -141,7 +141,7 @@ class Origami::PaymentsController < BaseOrigamiController
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id)
#shop_detail = Shop.first #shop_detail = Shop.current_shop
# rounding adjustment # rounding adjustment
if !path.include? ("credit_payment") if !path.include? ("credit_payment")
if shop_detail.is_rounding_adj if shop_detail.is_rounding_adj
@@ -577,7 +577,7 @@ class Origami::PaymentsController < BaseOrigamiController
customer= Customer.find(saleObj.customer_id) customer= Customer.find(saleObj.customer_id)
#shop detail #shop detail
#shop_detail = Shop.first #shop_detail = Shop.current_shop
# get member information # get member information
rebate = MembershipSetting.find_by_rebate(1) rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate if customer.membership_id != nil && rebate
@@ -686,7 +686,7 @@ class Origami::PaymentsController < BaseOrigamiController
customer= Customer.find(saleObj.customer_id) customer= Customer.find(saleObj.customer_id)
#shop detail #shop detail
#shop_detail = Shop.first #shop_detail = Shop.current_shop
printer = PrintSetting.all printer = PrintSetting.all
unique_code="ReceiptBillPdf" unique_code="ReceiptBillPdf"

View File

@@ -7,7 +7,7 @@ class Origami::PayparPaymentsController < BaseOrigamiController
payment_method = "paypar" payment_method = "paypar"
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
if shop_details.is_rounding_adj if shop_details.is_rounding_adj

View File

@@ -6,7 +6,7 @@ class Origami::RedeemPaymentsController < BaseOrigamiController
@membership_rebate_balance=0 @membership_rebate_balance=0
sale_data = Sale.find_by_sale_id(@sale_id) sale_data = Sale.find_by_sale_id(@sale_id)
@shop = Shop.first @shop = Shop.current_shop
if @shop.is_rounding_adj if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total) new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
else else

View File

@@ -90,7 +90,7 @@ class Origami::RequestBillsController < ApplicationController
# Not Use for these printed bill cannot give customer # Not Use for these printed bill cannot give customer
# unique_code = "ReceiptBillPdf" # unique_code = "ReceiptBillPdf"
# #shop detail # #shop detail
# shop_details = Shop.find(1) # shop_details = Shop.current_shop
# # customer= Customer.where('customer_id=' +.customer_id) # # customer= Customer.where('customer_id=' +.customer_id)
# customer= Customer.find(@sale_data.customer_id) # customer= Customer.find(@sale_data.customer_id)
# # get member information # # get member information

View File

@@ -1,7 +1,7 @@
class Origami::RoomsController < BaseOrigamiController class Origami::RoomsController < BaseOrigamiController
def index def index
@tables = Table.unscoped.all.active.order('status desc') @tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc') @rooms = Room.unscope(:order).all.active.order('status desc')
@complete = Sale.completed_sale("cashier") @complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@shift = ShiftSale.current_open_shift(current_user.id) @shift = ShiftSale.current_open_shift(current_user.id)
@@ -17,8 +17,8 @@ class Origami::RoomsController < BaseOrigamiController
@webview = true @webview = true
end end
@tables = Table.unscoped.all.active.order('status desc') @tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc') @rooms = Room.unscope(:order).all.active.order('status desc')
@complete = Sale.completed_sale("cashier") @complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@customers = Customer.pluck("customer_id, name") @customers = Customer.pluck("customer_id, name")
@@ -29,7 +29,7 @@ class Origami::RoomsController < BaseOrigamiController
@status_sale = "" @status_sale = ""
@sale_array = Array.new @sale_array = Array.new
@shop = Shop.first @shop = Shop.current_shop
@membership = MembershipSetting::MembershipSetting @membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all @payment_methods = PaymentMethodSetting.all

View File

@@ -5,8 +5,8 @@ class Origami::SalesController < BaseOrigamiController
@webview = true @webview = true
end end
@tables = Table.unscoped.all.active.order('status desc') @tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc') @rooms = Room.unscope(:order).all.active.order('status desc')
@complete = Sale.completed_sale("cashier") @complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@customers = Customer.pluck("customer_id, name") @customers = Customer.pluck("customer_id, name")

View File

@@ -27,7 +27,7 @@ class Origami::SecondDisplayController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
# helper_method :shop_detail # helper_method :shop_detail
# def shop_detail # def shop_detail
# @shop = Shop.first # @shop = Shop.current_shop
# end # end

View File

@@ -413,7 +413,7 @@ class Origami::SplitBillController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -1,7 +1,7 @@
class Origami::TableInvoicesController < BaseOrigamiController class Origami::TableInvoicesController < BaseOrigamiController
def index def index
@table = DiningFacility.find(params[:table_id]) @table = DiningFacility.find(params[:table_id])
shop = Shop.first shop = Shop.current_shop
puts "table bookig lenght" puts "table bookig lenght"
@sale_array = Array.new @sale_array = Array.new
@table.bookings.each do |booking| @table.bookings.each do |booking|
@@ -34,7 +34,7 @@ class Origami::TableInvoicesController < BaseOrigamiController
@table = DiningFacility.find(params[:table_id]) @table = DiningFacility.find(params[:table_id])
@membership = MembershipSetting::MembershipSetting @membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all @payment_methods = PaymentMethodSetting.all
shop = Shop.first shop = Shop.current_shop
@sale_array = Array.new @sale_array = Array.new
@table.bookings.each do |booking| @table.bookings.each do |booking|
if booking.sale_id.nil? if booking.sale_id.nil?

View File

@@ -11,7 +11,7 @@ class Origami::UnionpayController < BaseOrigamiController
end end
total = 0 total = 0
@unionpaycount = 0 @unionpaycount = 0
@shop = Shop.first @shop = Shop.current_shop
@rounding_adj = 0 @rounding_adj = 0
@can_unionpay = 0 @can_unionpay = 0
@member_discount = 0 @member_discount = 0
@@ -61,7 +61,7 @@ class Origami::UnionpayController < BaseOrigamiController
ref_no = params[:ref_no] ref_no = params[:ref_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj
@@ -85,6 +85,6 @@ class Origami::UnionpayController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -11,7 +11,7 @@ class Origami::VisaController < BaseOrigamiController
end end
total = 0 total = 0
@visacount = 0 @visacount = 0
@shop = Shop.first @shop = Shop.current_shop
@rounding_adj = 0 @rounding_adj = 0
@can_visa = 0 @can_visa = 0
@member_discount = 0 @member_discount = 0
@@ -61,7 +61,7 @@ class Origami::VisaController < BaseOrigamiController
ref_no = params[:ref_no] ref_no = params[:ref_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
# if shop_details.is_rounding_adj # if shop_details.is_rounding_adj
@@ -85,6 +85,6 @@ class Origami::VisaController < BaseOrigamiController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -116,7 +116,7 @@ class Origami::VoidController < BaseOrigamiController
customer= Customer.find(sale.customer_id) customer= Customer.find(sale.customer_id)
#shop detail #shop detail
shop_details = current_shop shop_details = Shop.current_shop
# get member information # get member information
rebate = MembershipSetting.find_by_rebate(1) rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate if customer.membership_id != nil && rebate

View File

@@ -8,7 +8,7 @@ class Origami::VoucherController < BaseOrigamiController
@vouchercount = 0 @vouchercount = 0
others = 0 others = 0
@shop = Shop.first @shop = Shop.current_shop
if @shop.is_rounding_adj if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total) new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
else else

View File

@@ -89,7 +89,7 @@ class Origami::WasteSpoileController < BaseOrigamiController
customer= Customer.find(sale.customer_id) customer= Customer.find(sale.customer_id)
#shop detail #shop detail
shop_details = current_shop shop_details = Shop.current_shop
# get member information # get member information
rebate = MembershipSetting.find_by_rebate(1) rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate if customer.membership_id != nil && rebate

View File

@@ -22,6 +22,6 @@ class Reports::ProductSaleController < BaseReportController
#Shop Name in Navbor #Shop Name in Navbor
helper_method :shop_detail helper_method :shop_detail
def shop_detail def shop_detail
@shop = Shop.first @shop = Shop.current_shop
end end
end end

View File

@@ -183,7 +183,7 @@ authorize_resource :class => false
customer= Customer.find(saleObj.customer_id) customer= Customer.find(saleObj.customer_id)
#shop detail #shop detail
#shop_detail = Shop.first #shop_detail = Shop.current_shop
# get member information # get member information
rebate = MembershipSetting.find_by_rebate(1) rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate if customer.membership_id != nil && rebate

View File

@@ -59,11 +59,11 @@ class Settings::ShopsController < ApplicationController
File.delete(delete_path) File.delete(delete_path)
end end
end end
save_path = Rails.root.join("public/#{current_shop.shop_code}_#{a.original_filename}") save_path = Rails.root.join("public/#{Shop.current_shop.shop_code}_#{a.original_filename}")
File.open(save_path, 'wb') do |f| File.open(save_path, 'wb') do |f|
f.write a.read f.write a.read
end end
audio_name = "#{current_shop.shop_code}_#{a.original_filename}" audio_name = "#{Shop.current_shop.shop_code}_#{a.original_filename}"
@settings_shop.display_images.where(:name => "order_audio").destroy_all @settings_shop.display_images.where(:name => "order_audio").destroy_all
@display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :name => "order_audio", :image => audio_name) @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :name => "order_audio", :image => audio_name)
else else

View File

@@ -346,7 +346,7 @@ class Transactions::SalesController < ApplicationController
customer= Customer.find(sale.customer_id) customer= Customer.find(sale.customer_id)
#shop detail #shop detail
shop_details = Shop.find_by_id(1) shop_details = Shop.current_shop
# get member information # get member information
rebate = MembershipSetting.find_by_rebate(1) rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate if customer.membership_id != nil && rebate

View File

@@ -1,3 +1,14 @@
class ApplicationRecord < ActiveRecord::Base class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
def self.inherited(subclass)
super
return unless subclass.superclass == self
return unless subclass.column_names.include? 'shop_id'
subclass.class_eval do
acts_as_tenant(:shop)
end
end
end end

View File

@@ -3,13 +3,13 @@ class KbzPay
KBZ_PAY = 'KBZPay' KBZ_PAY = 'KBZPay'
def self.pay(amount, receipt_no, url, key, app_id, code) def self.pay(amount, receipt_no, url, key, app_id, code)
shop = Shop.first shop = Shop.current_shop
prefix = shop.shop_code prefix = shop.shop_code
receipt_no = "#{prefix}#{receipt_no}" receipt_no = "#{prefix}#{receipt_no}"
datetime = DateTime.now.strftime("%d%m%Y%H%M") datetime = DateTime.now.strftime("%d%m%Y%H%M")
kbz_app_id = app_id kbz_app_id = app_id
kbz_merch_code = code kbz_merch_code = code
kbz_api_key = key kbz_api_key = key
kbz_provider_url = "#{url}/precreate" kbz_provider_url = "#{url}/precreate"
@@ -58,17 +58,17 @@ class KbzPay
# Rails.logger.debug result['Response'] # Rails.logger.debug result['Response']
return false, result['Response'] return false, result['Response']
end end
end end
def self.query(receipt_no, current_user, url, key, app_id, code) def self.query(receipt_no, current_user, url, key, app_id, code)
shop = Shop.first shop = Shop.current_shop
prefix = shop.shop_code prefix = shop.shop_code
receipt_no = "#{prefix}#{receipt_no}" receipt_no = "#{prefix}#{receipt_no}"
amount = 0 amount = 0
datetime = DateTime.now.strftime("%d%m%Y%H%M") datetime = DateTime.now.strftime("%d%m%Y%H%M")
kbz_app_id = app_id kbz_app_id = app_id
kbz_merch_code = code kbz_merch_code = code
kbz_api_key = key kbz_api_key = key
kbz_provider_url = "#{url}/queryorder" kbz_provider_url = "#{url}/queryorder"
@@ -122,7 +122,7 @@ class KbzPay
# return true, "successfully paid by KBZ PAY" # return true, "successfully paid by KBZ PAY"
elsif result['Response']['trade_status'] == "PAY_FAILED" elsif result['Response']['trade_status'] == "PAY_FAILED"
# return false, "pay failed by KBZ PAY" # return false, "pay failed by KBZ PAY"
elsif result['Response']['trade_status'] == "WAIT_PAY" elsif result['Response']['trade_status'] == "WAIT_PAY"
# return false , "Waiting to pay by KBZ PAY" # return false , "Waiting to pay by KBZ PAY"
@@ -135,4 +135,4 @@ class KbzPay
return amount return amount
end end
end end

View File

@@ -141,7 +141,7 @@ class Menu < ApplicationRecord
end end
else else
# Menu by Menu Import # Menu by Menu Import
@shop = Shop.first @shop = Shop.current_shop
shop_code = "" shop_code = ""
if !@shop.nil? if !@shop.nil?
if @shop.shop_code if @shop.shop_code

View File

@@ -297,7 +297,7 @@ class OrderQueueStation < ApplicationRecord
@type = (DiningFacility.find(change_to)).type @type = (DiningFacility.find(change_to)).type
@moved_by = current_user @moved_by = current_user
@date = DateTime.now @date = DateTime.now
@shop = Shop.first @shop = Shop.current_shop
unique_code = "MoveTablePdf" unique_code = "MoveTablePdf"
# pdf_no = PrintSetting.where(:unique_code => unique_code).count # pdf_no = PrintSetting.where(:unique_code => unique_code).count
print_settings = PrintSetting.find_by_unique_code(unique_code) print_settings = PrintSetting.find_by_unique_code(unique_code)

View File

@@ -157,7 +157,7 @@ class OrderReservation < ApplicationRecord
def self.update_doemal_payment(order,current_user,receipt_bill) def self.update_doemal_payment(order,current_user,receipt_bill)
if(Sale.exists?(order.sale_id)) if(Sale.exists?(order.sale_id))
saleObj = Sale.find(order.sale_id) saleObj = Sale.find(order.sale_id)
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
if shop_details.is_rounding_adj if shop_details.is_rounding_adj
a = saleObj.grand_total % 25 # Modulus a = saleObj.grand_total % 25 # Modulus
@@ -194,7 +194,7 @@ class OrderReservation < ApplicationRecord
shift = ShiftSale.find(saleObj.shift_sale_id) shift = ShiftSale.find(saleObj.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
shop_detail = Shop.first shop_detail = Shop.current_shop
order_reservation = OrderReservation.get_order_reservation_info(saleObj.sale_id) order_reservation = OrderReservation.get_order_reservation_info(saleObj.sale_id)
if !cashier_terminal.nil? if !cashier_terminal.nil?
# Calculate Food and Beverage Total # Calculate Food and Beverage Total
@@ -400,7 +400,7 @@ class OrderReservation < ApplicationRecord
end end
def self.check_new_order def self.check_new_order
shop = Shop.find_by_id(1) shop = Shop.current_shop
if !shop.shop_code.nil? if !shop.shop_code.nil?
shop_code = shop.shop_code shop_code = shop.shop_code
else else
@@ -418,7 +418,7 @@ class OrderReservation < ApplicationRecord
end end
def self.check_order_send_to_kitchen def self.check_order_send_to_kitchen
shop = Shop.find_by_id(1) shop = Shop.current_shop
if !shop.shop_code.nil? if !shop.shop_code.nil?
shop_code = shop.shop_code shop_code = shop.shop_code
else else
@@ -436,7 +436,7 @@ class OrderReservation < ApplicationRecord
end end
def self.check_order_ready_to_delivery def self.check_order_ready_to_delivery
shop = Shop.find_by_id(1) shop = Shop.current_shop
if !shop.shop_code.nil? if !shop.shop_code.nil?
shop_code = shop.shop_code shop_code = shop.shop_code
else else

View File

@@ -38,7 +38,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end end
# end # end
shop = Shop.first shop = Shop.current_shop
directory_name = 'public/orders_'+shop.shop_code directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name) Dir.mkdir(directory_name) unless File.exists?(directory_name)
@@ -80,7 +80,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
print_setting = PrintSetting.all.order("id ASC") print_setting = PrintSetting.all.order("id ASC")
order=print_query('order_summary', order_id) order=print_query('order_summary', order_id)
shop = Shop.first shop = Shop.current_shop
directory_name = 'public/orders_'+shop.shop_code directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name) Dir.mkdir(directory_name) unless File.exists?(directory_name)
@@ -192,7 +192,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
order=print_query('booking_summary', booking_id) order=print_query('booking_summary', booking_id)
shop = Shop.first shop = Shop.current_shop
directory_name = 'public/orders_'+shop.shop_code directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name) Dir.mkdir(directory_name) unless File.exists?(directory_name)

View File

@@ -1,4 +1,3 @@
class Room < DiningFacility class Room < DiningFacility
has_many :bookings, :foreign_key => 'dining_facility_id' has_many :bookings, :foreign_key => 'dining_facility_id'
end end

View File

@@ -440,7 +440,7 @@ class Sale < ApplicationRecord
#compute - invoice total #compute - invoice total
def compute_by_sale_items(total_discount, discount_type=nil, order_source=nil, tax_type=nil, type=nil) def compute_by_sale_items(total_discount, discount_type=nil, order_source=nil, tax_type=nil, type=nil)
shop = Shop.first shop = Shop.current_shop
#Computation Fields #Computation Fields
subtotal_price = 0 subtotal_price = 0
@@ -507,7 +507,7 @@ class Sale < ApplicationRecord
# Tax Re-Calculte # Tax Re-Calculte
def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil) def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil)
shop = Shop.first shop = Shop.current_shop
#if tax is not apply create new record #if tax is not apply create new record
# SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| # SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax|
@@ -627,7 +627,7 @@ class Sale < ApplicationRecord
# Tax Calculate # Tax Calculate
def apply_tax(total_taxable, order_source = nil, tax_type = nil) def apply_tax(total_taxable, order_source = nil, tax_type = nil)
shop = Shop.first shop = Shop.current_shop
#if tax is not apply create new record #if tax is not apply create new record
# SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| # SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax|
@@ -645,7 +645,7 @@ class Sale < ApplicationRecord
order_source = "cashier" order_source = "cashier"
end end
# tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id) # tax_data = TaxProfile.unscope(:order).where("group_type=?",order_source).pluck(:id)
# customer = Customer.find(self.customer_id).tax_profiles # customer = Customer.find(self.customer_id).tax_profiles
tax_profiles = unique_tax_profiles(order_source, self.customer_id) tax_profiles = unique_tax_profiles(order_source, self.customer_id)
@@ -710,7 +710,7 @@ class Sale < ApplicationRecord
end end
def adjust_rounding def adjust_rounding
shop_details = Shop.first shop_details = Shop.current_shop
# rounding adjustment # rounding adjustment
if shop_details.is_rounding_adj if shop_details.is_rounding_adj
new_total = Sale.get_rounding_adjustment(self.grand_total) new_total = Sale.get_rounding_adjustment(self.grand_total)
@@ -726,7 +726,7 @@ class Sale < ApplicationRecord
#Generate new Receipt No when it is not assigned #Generate new Receipt No when it is not assigned
def generate_receipt_no def generate_receipt_no
#shop_code and client_code #shop_code and client_code
shop_details = Shop.first shop_details = Shop.current_shop
#Date-Shift- #Date-Shift-
if self.receipt_no.nil? if self.receipt_no.nil?
prefix = DateTime.now().utc prefix = DateTime.now().utc
@@ -1239,7 +1239,7 @@ end
#product sale report query #product sale report query
def self.get_menu_item_query(order_by) def self.get_menu_item_query(order_by)
query = MenuItem.unscoped.select("acc.id as account_id, query = MenuItem.unscope(:order).select("acc.id as account_id,
acc.title as account_name, acc.title as account_name,
mii.item_instance_code as item_code, " + mii.item_instance_code as item_code, " +
"(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," + "(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," +

View File

@@ -1,13 +1,17 @@
class Shop < ApplicationRecord class Shop < ApplicationRecord
#ShopDetail = Shop.find_by_id(1) #ShopDetail = Shop.current_shop
# Shop Image Uploader # Shop Image Uploader
mount_uploader :logo, ShopImageUploader mount_uploader :logo, ShopImageUploader
has_many :display_images has_many :display_images
accepts_nested_attributes_for :display_images accepts_nested_attributes_for :display_images
def file_data=(input_data) def file_data=(input_data)
self.data = input_data.read self.data = input_data.read
end end
def self.current_shop
ActsAsTenant.current_tenant
end
end end

View File

@@ -20,11 +20,11 @@ class CommissionerImageUploader < CarrierWave::Uploader::Base
end end
def filename def filename
if Shop.first.shop_code.nil? if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present? "#{original_filename}" if original_filename.present?
else else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end end
end end
# def cache_dir # def cache_dir
@@ -62,6 +62,6 @@ class CommissionerImageUploader < CarrierWave::Uploader::Base
# Avoid using model.id or version_name here, see uploader/store.rb for details. # Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename # def filename
# "something.jpg" if original_filename # "something.jpg" if original_filename
# end # end
end end

View File

@@ -20,11 +20,11 @@ class CustomerImageUploader < CarrierWave::Uploader::Base
end end
def filename def filename
if Shop.first.shop_code.nil? if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present? "#{original_filename}" if original_filename.present?
else else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end end
end end
# def cache_dir # def cache_dir
@@ -62,6 +62,6 @@ class CustomerImageUploader < CarrierWave::Uploader::Base
# Avoid using model.id or version_name here, see uploader/store.rb for details. # Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename # def filename
# "something.jpg" if original_filename # "something.jpg" if original_filename
# end # end
end end

View File

@@ -20,11 +20,11 @@ class EmployeeImageUploader < CarrierWave::Uploader::Base
end end
def filename def filename
if Shop.first.shop_code.nil? if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present? "#{original_filename}" if original_filename.present?
else else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end end
end end
# def cache_dir # def cache_dir
@@ -62,6 +62,6 @@ class EmployeeImageUploader < CarrierWave::Uploader::Base
# Avoid using model.id or version_name here, see uploader/store.rb for details. # Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename # def filename
# "something.jpg" if original_filename # "something.jpg" if original_filename
# end # end
end end

View File

@@ -15,16 +15,16 @@ class MenuItemImageUploader < CarrierWave::Uploader::Base
# Override the directory where uploaded files will be stored. # Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted: # This is a sensible default for uploaders that are meant to be mounted:
def store_dir def store_dir
"image/menu_images/#{Shop.first.shop_code}" "image/menu_images/#{Shop.current_shop.shop_code}"
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end end
def filename def filename
if Shop.first.shop_code.nil? if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present? "#{original_filename}" if original_filename.present?
else else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end end
end end
# def cache_dir # def cache_dir
@@ -42,7 +42,7 @@ class MenuItemImageUploader < CarrierWave::Uploader::Base
# Process files as they are uploaded: # Process files as they are uploaded:
# process scale: [200, 300] # process scale: [200, 300]
process :resize_to_fit => [400, 250]#[200, 150] process :resize_to_fit => [400, 250]#[200, 150]
# #
# def scale(width, height) # def scale(width, height)
# # do something # # do something

View File

@@ -20,11 +20,11 @@ class ProductImageUploader < CarrierWave::Uploader::Base
end end
def filename def filename
if Shop.first.shop_code.nil? if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present? "#{original_filename}" if original_filename.present?
else else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end end
end end
# def cache_dir # def cache_dir

View File

@@ -20,11 +20,11 @@ class ShopImageUploader < CarrierWave::Uploader::Base
end end
def filename def filename
if Shop.first.shop_code.nil? if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present? "#{original_filename}" if original_filename.present?
else else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end end
end end
# def cache_dir # def cache_dir
@@ -62,6 +62,6 @@ class ShopImageUploader < CarrierWave::Uploader::Base
# Avoid using model.id or version_name here, see uploader/store.rb for details. # Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename # def filename
# "something.jpg" if original_filename # "something.jpg" if original_filename
# end # end
end end

View File

@@ -8,7 +8,7 @@ json.valid_time_to menu.valid_time_to.strftime("%H:%M")
if (menu.menu_categories) if (menu.menu_categories)
order_by = Lookup.find_by_lookup_type("order_by") order_by = Lookup.find_by_lookup_type("order_by")
# if !order_by.nil? && order_by.value == "name" # if !order_by.nil? && order_by.value == "name"
# categories = MenuCategory.unscoped.where("menu_id ='#{menu.id}'").order("name asc") # categories = MenuCategory.unscope(:order).where("menu_id ='#{menu.id}'").order("name asc")
# else # else
# categories = menu.menu_categories # categories = menu.menu_categories
# end # end

View File

@@ -3,7 +3,7 @@ namespace :consolidate do
task :receipt => :environment do task :receipt => :environment do
# Receipt.delete_all # Receipt.delete_all
sales = Sale.all_receipts sales = Sale.all_receipts
shop = Shop.first #current_shop shop = Shop.current_shop #Shop.current_shop
sales.each do |sale| sales.each do |sale|
if sale.shift_sale_id.present? if sale.shift_sale_id.present?
@@ -57,7 +57,7 @@ namespace :consolidate do
ReceiptDetail.delete_all ReceiptDetail.delete_all
sales = Sale.all_receipt_details sales = Sale.all_receipt_details
shop = Shop.first #current_shop shop = Shop.current_shop #Shop.current_shop
sale_id = '' sale_id = ''
count = 0 count = 0