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 detail: 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 1607cb70d3
78 changed files with 215 additions and 173 deletions

View File

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

View File

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

View File

@@ -3,11 +3,11 @@ class Origami::CreditSalesController < BaseOrigamiController
@cashier_type = 'cashier'
@webview = false
if check_mobile
@webview = true
@webview = true
end
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@tables = Table.unscope(:order).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'))
@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")
@@ -15,7 +15,7 @@ class Origami::CreditSalesController < BaseOrigamiController
@sale = Sale.find_by_sale_id(params[:sale_id])
@sale_payment = SalePayment.select("SUM(payment_amount) as payment_amount")
.where("sale_id = ? and payment_method=?", @sale.sale_id, "creditnote")
@sale_taxes = []
sale_taxes = SaleTax.where("sale_id = ?", @sale.sale_id)
if !sale_taxes.empty?
@@ -24,5 +24,5 @@ class Origami::CreditSalesController < BaseOrigamiController
end
end
end
end

View File

@@ -87,7 +87,7 @@ class Origami::CustomersController < BaseOrigamiController
@count_customer = Customer.count_customer
# @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")
# if flash["errors"]
# @crm_customer.valid?

View File

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

View File

@@ -6,7 +6,7 @@ class Origami::DingaController < BaseOrigamiController
@membership_rebate_balance=0
@sale_data = Sale.find_by_sale_id(@sale_id)
@receipt_no = @sale_data.receipt_no
@shop = Shop.first
@shop = Shop.current_shop
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(@sale_data.grand_total)
else
@@ -77,7 +77,7 @@ def create
account_no = params[:account_no]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop.first
shop_details = Shop.current_shop
# rounding adjustment
# if shop_details.is_rounding_adj
# 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)
total = 0
@gift_vouchercount = 0
@shop = Shop.first
@shop = Shop.current_shop
@rounding_adj = 0
@can_gift_voucher = 0
@member_discount = 0
@@ -48,7 +48,7 @@ class Origami::GiftVoucherController < BaseOrigamiController
ref_no = params[:reference_no]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop.first
shop_details = Shop.current_shop
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -66,6 +66,6 @@ class Origami::GiftVoucherController < BaseOrigamiController
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
@shop = Shop.current_shop
end
end

View File

@@ -4,8 +4,8 @@ class Origami::HomeController < BaseOrigamiController
def index
@webview = check_mobile
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscope(:order).all.active.order('status desc')
@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')
@@ -21,8 +21,8 @@ class Origami::HomeController < BaseOrigamiController
@print_settings = PrintSetting.get_precision_delimiter()
@webview = check_mobile
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscope(:order).all.active.order('status desc')
@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')
@customers = Customer.pluck("customer_id, name")
@@ -126,7 +126,7 @@ class Origami::HomeController < BaseOrigamiController
lookup_edit_order = Lookup.collection_of('edit_order')
if !lookup_edit_order.empty?
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')
@edit_order_origami = false
end
@@ -139,14 +139,14 @@ class Origami::HomeController < BaseOrigamiController
lookup_changable_tax = Lookup.collection_of('changable_tax')
if !lookup_changable_tax.empty?
lookup_changable_tax.each do |changable_tax|
if changable_tax[0].downcase == "change"
if changable_tax[1] == '0'
if changable_tax[0].downcase == "change"
if changable_tax[1] == '0'
@changable_tax = false
end
end
end
end
end
def check_emp_access_code

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,8 +5,8 @@ class Origami::OrdersController < BaseOrigamiController
@webview = true
end
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@tables = Table.unscope(:order).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'))
@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])

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
class Origami::RoomsController < BaseOrigamiController
def index
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscope(:order).all.active.order('status desc')
@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')
@shift = ShiftSale.current_open_shift(current_user.id)
@@ -17,8 +17,8 @@ class Origami::RoomsController < BaseOrigamiController
@webview = true
end
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscope(:order).all.active.order('status desc')
@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')
@customers = Customer.pluck("customer_id, name")
@@ -29,7 +29,7 @@ class Origami::RoomsController < BaseOrigamiController
@status_sale = ""
@sale_array = Array.new
@shop = Shop.first
@shop = Shop.current_shop
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all

View File

@@ -5,8 +5,8 @@ class Origami::SalesController < BaseOrigamiController
@webview = true
end
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscope(:order).all.active.order('status desc')
@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')
@customers = Customer.pluck("customer_id, name")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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