current shop changes
This commit is contained in:
@@ -2,9 +2,17 @@ class Api::ApiController < ActionController::API
|
||||
include TokenVerification
|
||||
include ActionController::MimeResponds
|
||||
|
||||
# before_action :lookup_domain
|
||||
before_action :core_allow
|
||||
helper_method :current_token, :current_login_employee, :get_cashier
|
||||
|
||||
|
||||
def core_allow
|
||||
headers['Access-Control-Allow-Origin'] = '*'
|
||||
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
|
||||
headers['Access-Control-Request-Method'] = '*'
|
||||
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
|
||||
end
|
||||
|
||||
private
|
||||
#this is base api base controller to need to inherit.
|
||||
#all token authentication must be done here
|
||||
|
||||
@@ -17,39 +17,33 @@ module LoginVerification
|
||||
end
|
||||
|
||||
def current_shop
|
||||
begin
|
||||
shop_code ='262'
|
||||
@shop =Shop.find_by_shop_code(shop_code)
|
||||
return @shop
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
@current_shop
|
||||
end
|
||||
|
||||
def current_login_employee
|
||||
@employee = Employee.find_by_token_session_and_shop_code(session[:session_token],@shop.shop_code)
|
||||
@employee = Employee.find_by_token_session_and_shop_code(session[:session_token],@current_shop.shop_code)
|
||||
end
|
||||
|
||||
def current_user
|
||||
@current_user ||= Employee.find_by_token_session_and_shop_code(session[:session_token],@shop.shop_code) if session[:session_token]
|
||||
@current_user ||= Employee.find_by_token_session_and_shop_code(session[:session_token],@current_shop.shop_code) if session[:session_token]
|
||||
end
|
||||
|
||||
# Get current Cashiers
|
||||
def get_cashier
|
||||
@cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''")
|
||||
@cashier = Employee.where("shop_code='#{@current_shop.shop_code}' and role = 'cashier' AND token_session <> ''")
|
||||
end
|
||||
|
||||
|
||||
#Shop Name in Navbor
|
||||
def shop_detail
|
||||
shop_code ='262'
|
||||
@shop = Shop.find_by_shop_code(shop_code)
|
||||
return @shop
|
||||
# shop_code ='262'
|
||||
# @shop = Shop.find_by_shop_code(shop_code)
|
||||
return @current_shop
|
||||
end
|
||||
|
||||
#check order reservation used
|
||||
def order_reservation
|
||||
order_reserve = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation')
|
||||
order_reserve = Lookup.where("shop_code='#{@current_shop.shop_code}'").collection_of('order_reservation')
|
||||
status = false
|
||||
if !order_reserve.empty?
|
||||
order_reserve.each do |order|
|
||||
@@ -65,7 +59,7 @@ module LoginVerification
|
||||
|
||||
#check bank integration used
|
||||
def bank_integration
|
||||
bank_integration = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('bank_integration')
|
||||
bank_integration = Lookup.where("shop_code='#{@current_shop.shop_code}'").collection_of('bank_integration')
|
||||
status = false
|
||||
if !bank_integration.empty?
|
||||
bank_integration.each do |bank|
|
||||
@@ -90,8 +84,7 @@ module LoginVerification
|
||||
if (token)
|
||||
#@current_user = User.find_by(api_key: token)
|
||||
#Rails.logger.debug "token - " + token.to_s
|
||||
|
||||
@user = Employee.authenticate_by_token(token,current_shop)
|
||||
@user = Employee.authenticate_by_token(token,@current_shop)
|
||||
if @user
|
||||
return true
|
||||
#Maybe log - login?
|
||||
@@ -99,6 +92,21 @@ module LoginVerification
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate_session_token
|
||||
shop_code = 262
|
||||
if (shop_code)
|
||||
#@current_user = User.find_by(api_key: token)
|
||||
#Rails.logger.debug "token - " + token.to_s
|
||||
@current_shop = Shop.find_by_shop_code(shop_code)
|
||||
if @current_shop
|
||||
return true
|
||||
#Maybe log - login?
|
||||
end
|
||||
else
|
||||
@current_shop = Shop.first
|
||||
end
|
||||
end
|
||||
|
||||
def render_unauthorized
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
@@ -18,8 +18,8 @@ class HomeController < ApplicationController
|
||||
|
||||
def index
|
||||
# @employees = Employee.all_emp_except_waiter.order("name asc")
|
||||
@employees = Employee.all.where("shop_code='#{current_shop.shop_code}' and is_active = true").order("name asc")
|
||||
@roles = Employee.where("shop_code='#{current_shop.shop_code}'").distinct.pluck(:role)
|
||||
@employees = Employee.all.where("shop_code='#{@current_shop.shop_code}' and is_active = true").order("name asc")
|
||||
@roles = Employee.where("shop_code='#{@current_shop.shop_code}'").distinct.pluck(:role)
|
||||
|
||||
# byebug
|
||||
# @roles = Lookup.collection_of("employee_roles")
|
||||
@@ -106,10 +106,10 @@ class HomeController < ApplicationController
|
||||
end
|
||||
|
||||
|
||||
@top_products = Sale.top_bottom_products(current_user,@from,@to,"top")
|
||||
@bottom_products = Sale.top_bottom_products(current_user,@from,@to,"bottom")
|
||||
@hourly_sales = Sale.hourly_sales(current_user,@from,@to)
|
||||
employee_sales = Sale.employee_sales(current_user,@from,@to)
|
||||
@top_products = Sale.top_bottom_products(current_user,@from,@to,"top",current_shop)
|
||||
@bottom_products = Sale.top_bottom_products(current_user,@from,@to,"bottom",current_shop)
|
||||
@hourly_sales = Sale.hourly_sales(current_user,@from,@to,current_shop)
|
||||
employee_sales = Sale.employee_sales(current_user,@from,@to,current_shop)
|
||||
|
||||
@employee_sales = []
|
||||
if !employee_sales.nil?
|
||||
@@ -123,11 +123,11 @@ class HomeController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
@inventories = StockJournal.inventory_balances(@from,@to).sum(:balance)
|
||||
@inventories = StockJournal.inventory_balances(@from,@to, current_shop).sum(:balance)
|
||||
|
||||
@total_trans = Sale.total_trans(current_user,@from,@to)
|
||||
@total_card = Sale.total_card_sale(current_user,@from,@to)
|
||||
@total_credit = Sale.credit_payment(current_user,@from,@to)
|
||||
@total_credit = Sale.credit_payment(current_user,@from,@to, current_shop)
|
||||
|
||||
@sale_data = Array.new
|
||||
@total_payment_methods = Sale.total_payment_methods(current_user,@from,@to)
|
||||
@@ -143,7 +143,7 @@ class HomeController < ApplicationController
|
||||
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(current_user,@from,@to)
|
||||
# @total_other_customer = Sale.total_other_customer(today,current_user)
|
||||
|
||||
@total_order = Sale.total_order(current_user,@from,@to)
|
||||
@total_order = Sale.total_order(current_user,@from,@to, current_shop)
|
||||
@total_accounts = Account.select("accounts.id as account_id, accounts.title as title")
|
||||
@account_data = Array.new
|
||||
if !@total_accounts.nil?
|
||||
|
||||
@@ -98,7 +98,7 @@ class Origami::OrderReservationController < BaseOrigamiController
|
||||
end
|
||||
|
||||
def get_order_info
|
||||
order_reservation = OrderReservation.where("status = 'new' and shop_code='#{@shop.shop_code}'").count()
|
||||
order_reservation = OrderReservation.where("status = 'new' and shop_code='#{current_shop.shop_code}'").count()
|
||||
render :json => order_reservation
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user