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
|
||||
|
||||
|
||||
@@ -847,7 +847,6 @@ def self.daily_sales_list(from,to,shop_code)
|
||||
ELSE 0 END as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
|
||||
|
||||
.along_with_sale_payments_except_void_between(from, to)
|
||||
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
|
||||
.group("sale_id").to_sql
|
||||
@@ -1580,10 +1579,11 @@ end
|
||||
end
|
||||
|
||||
|
||||
def self.top_bottom_products(current_user,from,to,type)
|
||||
def self.top_bottom_products(current_user,from,to,type,current_shop)
|
||||
puts @current_shop
|
||||
query = Sale.joins("JOIN sale_items ON sale_items.sale_id = sales.sale_id")
|
||||
.completed
|
||||
.where("qty > 0 AND price > 0 AND shop_code='#{shop.shop_code}'")
|
||||
.where("qty > 0 AND price > 0 AND shop_code='#{current_shop.shop_code}'")
|
||||
.group("SUBSTRING_INDEX(product_name, ' - ', 1)")
|
||||
|
||||
if !from.nil? && !to.nil?
|
||||
@@ -1607,9 +1607,8 @@ end
|
||||
end
|
||||
|
||||
|
||||
def self.hourly_sales(current_user,from,to)
|
||||
def self.hourly_sales(current_user,from,to, current_shop)
|
||||
query = Sale.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '#{Time.zone.formatted_offset}'), '%I %p')")
|
||||
|
||||
.order('receipt_date').completed
|
||||
|
||||
if !from.nil? && !to.nil?
|
||||
@@ -1626,7 +1625,7 @@ end
|
||||
end
|
||||
|
||||
|
||||
def self.employee_sales(current_user,from,to)
|
||||
def self.employee_sales(current_user,from,to, current_shop)
|
||||
|
||||
shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
ShiftSale.current_open_shift(current_user)
|
||||
@@ -1635,8 +1634,7 @@ end
|
||||
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
|
||||
|
||||
|
||||
query = employee_sale(shift, from, to)
|
||||
|
||||
query = employee_sale(shift, from, to, current_shop)
|
||||
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
|
||||
.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount,
|
||||
CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card'
|
||||
@@ -1682,14 +1680,14 @@ end
|
||||
end
|
||||
|
||||
|
||||
def self.credit_payment(current_user=nil,from=nil,to=nil)
|
||||
def self.credit_payment(current_user=nil,from=nil,to=nil, current_shop)
|
||||
|
||||
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
|
||||
|
||||
query = SalePayment.credits
|
||||
.joins(:sale)
|
||||
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sale_payments.sale_id")
|
||||
.where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',shop.shop_code)
|
||||
.where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',current_shop.shop_code)
|
||||
|
||||
if (!from.nil? && !to.nil?)
|
||||
query = query.merge(Sale.receipt_date_between(from, to))
|
||||
@@ -1727,7 +1725,6 @@ end
|
||||
def self.total_payment_methods(current_user=nil,from=nil,to=nil)
|
||||
query = Sale.select("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END as payment_method")
|
||||
.where("sales.sale_status = 'completed'")
|
||||
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
.group("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END")
|
||||
|
||||
@@ -1893,11 +1890,11 @@ end
|
||||
# end
|
||||
|
||||
|
||||
def self.total_order(current_user=nil,from=nil,to=nil)
|
||||
def self.total_order(current_user=nil,from=nil,to=nil, current_shop)
|
||||
|
||||
query = Sale.select("count(distinct sale_orders.order_id) as total_order")
|
||||
.joins(:sale_orders)
|
||||
.where("shop_code='#{shop.shop_code}'")
|
||||
.where("shop_code='#{current_shop.shop_code}'")
|
||||
.completed
|
||||
|
||||
if (!from.nil? && !to.nil?)
|
||||
@@ -2109,11 +2106,11 @@ def unique_tax_profiles(order_source, customer_id)
|
||||
end
|
||||
|
||||
|
||||
def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil, current_shop)
|
||||
|
||||
query = Sale.joins(:cashier)
|
||||
.joins(:sale_payments)
|
||||
.paid.completed.where("sales.shop_code='#{shop.shop_code}'")
|
||||
.paid.completed.where("sales.shop_code='#{current_shop.shop_code}'")
|
||||
if !from.nil? && !to.nil?
|
||||
query = query.receipt_date_between(from, to)
|
||||
end
|
||||
|
||||
@@ -59,7 +59,7 @@ class StockJournal < ApplicationRecord
|
||||
end
|
||||
|
||||
|
||||
def self.inventory_balances(from,to, shop)
|
||||
def self.inventory_balances(from,to, current_shop)
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
.group("mii.item_instance_name")
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-12_ col-md-12 col-sm-12 col-xs-12 text-center">
|
||||
<div class="current-shop-name">
|
||||
<span><%= shop_detail.name %></span>
|
||||
<span><%= @current_shop.name %></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -34,6 +34,6 @@ module SXRestaurants
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user