shop code

This commit is contained in:
Myat Zin Wai Maw
2019-11-22 18:24:02 +06:30
parent 5a3f328789
commit d1ab2c194d
106 changed files with 834 additions and 895 deletions

View File

@@ -18,8 +18,9 @@ class HomeController < ApplicationController
def index
# @employees = Employee.all_emp_except_waiter.order("name asc")
@employees = @shop.employees.all.where("is_active = true").order("name asc")
@roles = @shop.employees.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")
@login_form = LoginForm.new()
@@ -36,7 +37,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(@shop,@login_form.emp_id, @login_form.password)
@employee = Employee.login(current_shop,@login_form.emp_id, @login_form.password)
if @employee != nil
session[:session_token] = @employee.token_session
@@ -51,7 +52,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(@shop,@login_form.emp_id, @login_form.password)
@employee = Employee.login(current_shop,@login_form.emp_id, @login_form.password)
if @employee != nil
if @employee.is_active
@@ -94,21 +95,21 @@ class HomeController < ApplicationController
today = DateTime.now.strftime('%Y-%m-%d')
if !@from.nil? && !@to.nil?
if !@from_time.nil? && @to_time.nil?
@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()
@orders = Sale::where("shop_code='#{@shop.shop_code}' and 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 = @shop.sales::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
@orders = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
end
else
@orders = @shop.sales::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
@orders = Sale::where("shop_code='#{@shop.shop_code}' and 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 = @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()
@sales = Sale::where("shop_code='#{@shop.shop_code}' and 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 = @shop.sales::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
@sales = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
end
else
@sales = @shop.sales::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
@sales = Sale::where("shop_code='#{@shop.shop_code}' and 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",@shop).sum('i.qty')
@bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom",@shop).sum('i.qty')
@@ -195,7 +196,7 @@ class HomeController < ApplicationController
def route_by_role(employee)
if employee.role == "administrator"
# redirect_to dashboard_path
shift = ShiftSale.current_open_shift(employee.id,@shop)
shift = ShiftSale.current_open_shift(employee)
if !shift.nil?
redirect_to origami_root_path
else
@@ -203,7 +204,7 @@ class HomeController < ApplicationController
end
elsif employee.role == "cashier"
#check if cashier has existing open cashier
shift = ShiftSale.current_open_shift(employee.id,@shop)
shift = ShiftSale.current_open_shift(employee)
if !shift.nil?
redirect_to origami_dashboard_path
# redirect_to origami_root_path