test
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
include LoginVerification
|
||||
|
||||
|
||||
#before_action :check_installation
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
helper_method :shop_detail, :order_reservation, :bank_integration
|
||||
helper_method :order_reservation, :bank_integration
|
||||
# lookup domain for db from provision
|
||||
# before_action :set_locale
|
||||
# helper_method :current_company,:current_login_employee,:current_user
|
||||
@@ -18,6 +18,3 @@ class ApplicationController < ActionController::Base
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
module LoginVerification
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :authenticate_session_token
|
||||
helper_method :current_company,:current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail
|
||||
@@ -19,34 +18,37 @@ module LoginVerification
|
||||
|
||||
def current_shop
|
||||
begin
|
||||
return Shop.first
|
||||
shop_code ='262'
|
||||
@shop =Shop.find_by_shop_code(shop_code)
|
||||
return @shop
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def current_login_employee
|
||||
@employee = Employee.find_by_token_session(session[:session_token])
|
||||
@employee = @shop.employees.find_by_token_session(session[:session_token])
|
||||
end
|
||||
|
||||
def current_user
|
||||
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
||||
@current_user ||= @shop.employees.find_by_token_session(session[:session_token]) if session[:session_token]
|
||||
end
|
||||
|
||||
# Get current Cashiers
|
||||
def get_cashier
|
||||
@cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
||||
@cashier = @shop.employees.where("role = 'cashier' AND token_session <> ''")
|
||||
end
|
||||
|
||||
|
||||
#Shop Name in Navbor
|
||||
def shop_detail
|
||||
@shop = Shop.first
|
||||
shop_code ='262'
|
||||
@shop = Shop.find_by_shop_code(shop_code)
|
||||
end
|
||||
|
||||
#check order reservation used
|
||||
def order_reservation
|
||||
order_reserve = Lookup.collection_of('order_reservation')
|
||||
order_reserve = @shop.lookups.collection_of('order_reservation')
|
||||
status = false
|
||||
if !order_reserve.empty?
|
||||
order_reserve.each do |order|
|
||||
@@ -62,7 +64,7 @@ module LoginVerification
|
||||
|
||||
#check bank integration used
|
||||
def bank_integration
|
||||
bank_integration = Lookup.collection_of('bank_integration')
|
||||
bank_integration = @shop.lookups.collection_of('bank_integration')
|
||||
status = false
|
||||
if !bank_integration.empty?
|
||||
bank_integration.each do |bank|
|
||||
@@ -78,17 +80,17 @@ module LoginVerification
|
||||
|
||||
protected
|
||||
# Authenticate the user with token based authentication
|
||||
def authenticate
|
||||
authenticate_session_token || render_unauthorized
|
||||
def authenticate
|
||||
authenticate_session_token || render_unauthorized
|
||||
end
|
||||
|
||||
def authenticate_session_token
|
||||
def authenticate_session_token
|
||||
token = session[:session_token]
|
||||
if (token)
|
||||
#@current_user = User.find_by(api_key: token)
|
||||
#Rails.logger.debug "token - " + token.to_s
|
||||
|
||||
@user = Employee.authenticate_by_token(token)
|
||||
@user =Employee.authenticate_by_token(token,current_shop)
|
||||
if @user
|
||||
return true
|
||||
#Maybe log - login?
|
||||
|
||||
@@ -3,7 +3,7 @@ class HomeController < ApplicationController
|
||||
# skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy]
|
||||
include PrecisionHelper
|
||||
before_action :check_user, only: :dashboard
|
||||
|
||||
|
||||
# Special check for only dashboard
|
||||
def check_user
|
||||
if current_user.nil?
|
||||
@@ -11,14 +11,15 @@ class HomeController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def current_user
|
||||
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
||||
end
|
||||
##already check current_user with helper_method
|
||||
# def current_user
|
||||
# @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
||||
# end
|
||||
|
||||
def index
|
||||
# @employees = Employee.all_emp_except_waiter.order("name asc")
|
||||
@employees = Employee.all.where("is_active = true").order("name asc")
|
||||
@roles = Employee.distinct.pluck(:role)
|
||||
@employees = @shop.employees.all.where("is_active = true").order("name asc")
|
||||
@roles = @shop.employees.distinct.pluck(:role)
|
||||
# byebug
|
||||
# @roles = Lookup.collection_of("employee_roles")
|
||||
@login_form = LoginForm.new()
|
||||
@@ -35,7 +36,7 @@ class HomeController < ApplicationController
|
||||
@login_form = LoginForm.new()
|
||||
@login_form.emp_id = params[:emp_id]
|
||||
@login_form.password = params[:login_form][:password]
|
||||
@employee = Employee.login(@login_form.emp_id, @login_form.password)
|
||||
@employee = Employee.login(@shop,@login_form.emp_id, @login_form.password)
|
||||
|
||||
if @employee != nil
|
||||
session[:session_token] = @employee.token_session
|
||||
@@ -50,7 +51,7 @@ class HomeController < ApplicationController
|
||||
@login_form = LoginForm.new()
|
||||
@login_form.emp_id = params[:login_form][:emp_id]
|
||||
@login_form.password = params[:login_form][:password]
|
||||
@employee = Employee.login(@login_form.emp_id, @login_form.password)
|
||||
@employee = Employee.login(@shop,@login_form.emp_id, @login_form.password)
|
||||
|
||||
if @employee != nil
|
||||
if @employee.is_active
|
||||
@@ -90,31 +91,30 @@ class HomeController < ApplicationController
|
||||
|
||||
def dashboard
|
||||
@from, @to, @from_time, @to_time = get_date_range_from_params
|
||||
@shop = Shop.first
|
||||
today = DateTime.now.strftime('%Y-%m-%d')
|
||||
if !@from.nil? && !@to.nil?
|
||||
if !@from_time.nil? && @to_time.nil?
|
||||
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
|
||||
@orders = @shop.sales::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
|
||||
else
|
||||
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
|
||||
@orders = @shop.sales::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
|
||||
end
|
||||
else
|
||||
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
||||
@orders = @shop.sales::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
||||
end
|
||||
if !@from.nil? && !@to.nil?
|
||||
if !@from_time.nil? && @to_time.nil?
|
||||
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
|
||||
@sales = @shop.sales::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
|
||||
else
|
||||
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
|
||||
@sales = @shop.sales::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
|
||||
end
|
||||
else
|
||||
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
||||
@sales = @shop.sales::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
||||
end
|
||||
@top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top").sum('i.qty')
|
||||
@bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom").sum('i.qty')
|
||||
@hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total)
|
||||
@top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top",@shop).sum('i.qty')
|
||||
@bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom",@shop).sum('i.qty')
|
||||
@hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time,@shop).sum(:grand_total)
|
||||
|
||||
employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time)
|
||||
employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time,@shop)
|
||||
@employee_sales = []
|
||||
if !employee_sales.nil?
|
||||
employee_sales.each do |emp|
|
||||
@@ -126,43 +126,43 @@ class HomeController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
@inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance)
|
||||
@inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time,@shop).sum(:balance)
|
||||
|
||||
@total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time,@shop)
|
||||
@total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time,@shop)
|
||||
@total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time,@shop)
|
||||
|
||||
@sale_data = Array.new
|
||||
@total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_payment_methods = Sale.total_payment_methods(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
|
||||
if !@total_payment_methods.nil?
|
||||
@total_payment_methods.each do |payment|
|
||||
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay"
|
||||
pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time)
|
||||
pay = Sale.payment_sale(@shop,'card', today, current_user,@from,@to,@from_time,@to_time)
|
||||
@sale_data.push({'card' => pay.payment_amount})
|
||||
else
|
||||
pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time)
|
||||
pay = Sale.payment_sale(@shop,payment.payment_method, today, current_user,@from,@to,@from_time,@to_time)
|
||||
@sale_data.push({payment.payment_method => pay.payment_amount})
|
||||
end
|
||||
end
|
||||
end
|
||||
@summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@summ_sale = Sale.summary_sale_receipt(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
|
||||
@total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_order = Sale.total_order(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_accounts = Sale.total_account(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
@account_data = Array.new
|
||||
if !@total_accounts.nil?
|
||||
@total_accounts.each do |account|
|
||||
acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time)
|
||||
acc = Sale.account_data(@shop,account.account_id, today,current_user,@from,@to,@from_time,@to_time)
|
||||
if !acc.nil?
|
||||
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time)
|
||||
@top_items = Sale.top_items(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_foc_items = Sale.total_foc_items(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
|
||||
# get printer info
|
||||
# @print_settings = get_precision_delimiter
|
||||
@@ -170,7 +170,7 @@ class HomeController < ApplicationController
|
||||
|
||||
def destroy
|
||||
# clear in employee session
|
||||
Employee.logout(session[:session_token])
|
||||
Employee.logout(@shop,session[:session_token])
|
||||
session[:session_token] = nil
|
||||
# redirect_to root_path
|
||||
render :json => {:status=> "Success", :url => root_path }.to_json
|
||||
@@ -195,7 +195,7 @@ class HomeController < ApplicationController
|
||||
def route_by_role(employee)
|
||||
if employee.role == "administrator"
|
||||
# redirect_to dashboard_path
|
||||
shift = ShiftSale.current_open_shift(employee.id)
|
||||
shift = ShiftSale.current_open_shift(employee.id,@shop)
|
||||
if !shift.nil?
|
||||
redirect_to origami_root_path
|
||||
else
|
||||
@@ -203,7 +203,7 @@ class HomeController < ApplicationController
|
||||
end
|
||||
elsif employee.role == "cashier"
|
||||
#check if cashier has existing open cashier
|
||||
shift = ShiftSale.current_open_shift(employee.id)
|
||||
shift = ShiftSale.current_open_shift(employee.id,@shop)
|
||||
if !shift.nil?
|
||||
redirect_to origami_dashboard_path
|
||||
# redirect_to origami_root_path
|
||||
|
||||
@@ -21,7 +21,7 @@ class Inventory::InventoryController < BaseInventoryController
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
#Shop Name in Navbor
|
||||
helper_method :shop_detail
|
||||
|
||||
@@ -11,7 +11,7 @@ class Origami::AlipayController < BaseOrigamiController
|
||||
end
|
||||
total = 0
|
||||
@alipaycount = 0
|
||||
@shop = Shop.first
|
||||
@shop = Shop.first
|
||||
@rounding_adj = 0
|
||||
@can_alipay = 0
|
||||
@member_discount = 0
|
||||
@@ -20,15 +20,15 @@ class Origami::AlipayController < BaseOrigamiController
|
||||
@receipt_no = nil
|
||||
if !sale_data.nil?
|
||||
total = sale_data.grand_total
|
||||
|
||||
|
||||
others = 0
|
||||
|
||||
|
||||
if @shop.is_rounding_adj
|
||||
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
||||
else
|
||||
new_total = sale_data.grand_total
|
||||
end
|
||||
@rounding_adj = new_total-sale_data.grand_total
|
||||
@rounding_adj = new_total-sale_data.grand_total
|
||||
if path.include? ("credit_payment")
|
||||
sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data)
|
||||
else
|
||||
@@ -65,12 +65,12 @@ class Origami::AlipayController < BaseOrigamiController
|
||||
if(Sale.exists?(sale_id))
|
||||
saleObj = Sale.find(sale_id)
|
||||
shop_details = Shop.first
|
||||
|
||||
|
||||
# rounding adjustment
|
||||
# if shop_details.is_rounding_adj
|
||||
# new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
||||
# rounding_adj = new_total-saleObj.grand_total
|
||||
# saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
|
||||
# saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
|
||||
# end
|
||||
|
||||
# saleObj = Sale.find(sale_id)
|
||||
|
||||
@@ -9,13 +9,13 @@ class Origami::CreditPaymentsController < BaseOrigamiController
|
||||
@creditcount = 0
|
||||
others = 0
|
||||
|
||||
@shop = Shop.first
|
||||
@shop = Shop.first
|
||||
if @shop.is_rounding_adj
|
||||
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
||||
else
|
||||
new_total = sale_data.grand_total
|
||||
end
|
||||
@rounding_adj = new_total-sale_data.grand_total
|
||||
@rounding_adj = new_total-sale_data.grand_total
|
||||
|
||||
sale_data.sale_payments.each do |sale_payment|
|
||||
if sale_payment.payment_method == "creditnote"
|
||||
@@ -33,12 +33,12 @@ class Origami::CreditPaymentsController < BaseOrigamiController
|
||||
if(Sale.exists?(sale_id))
|
||||
saleObj = Sale.find(sale_id)
|
||||
shop_details = Shop.first
|
||||
|
||||
|
||||
# rounding adjustment
|
||||
# if shop_details.is_rounding_adj
|
||||
# new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
||||
# rounding_adj = new_total-saleObj.grand_total
|
||||
# saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
|
||||
# saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
|
||||
# end
|
||||
|
||||
saleObj = Sale.find(sale_id)
|
||||
@@ -71,7 +71,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController
|
||||
else
|
||||
render :json => {status: false, message: 'No current shift open for this employee!'}
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user