fixed conflict

This commit is contained in:
Nweni
2019-11-25 09:26:21 +06:30
109 changed files with 1082 additions and 1082 deletions

View File

@@ -375,7 +375,5 @@ DEPENDENCIES
web-console (>= 3.3.0)
whenever
RUBY VERSION
ruby 2.6.3p62
BUNDLED WITH
2.0.2

View File

@@ -25,7 +25,7 @@ class Api::AuthenticateController < Api::ApiController
@employee = Employee.login(emp_id, password)
if @employee && @employee.role == "cashier"
if @employee.is_active
shift = ShiftSale.current_open_shift(@employee.id)
shift = ShiftSale.current_open_shift(@employee)
if !shift.nil?
@status = true
@shift_id = shift.id

View File

@@ -6,7 +6,7 @@ class Api::BillController < Api::ApiController
@status = false
@error_message = "Order ID or Booking ID is require to request for a bill."
# if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
if !ShiftSale.current_shift.nil?
if !ShiftSale.current_shift(@shop.shop_code).nil?
#create Bill by Booking ID
table = 0
if (params[:booking_id])
@@ -161,7 +161,7 @@ class Api::BillController < Api::ApiController
@status, @booking = @order.generate
if @status && @booking
shift = ShiftSale.current_open_shift(current_login_employee.id)
shift = ShiftSale.current_open_shift(current_login_employee)
if !shift.nil?
cashier = Employee.find(shift.employee_id)
if (@booking.booking_id)

View File

@@ -23,7 +23,7 @@ class Api::CallWaitersController < ActionController::API
end
ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time,from: from, shift_ids: shift_ids
# get printer info
@shop = Shop.first
# @shop = Shop.first
unique_code = "CallWaiterPdf"
print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings)

View File

@@ -46,7 +46,7 @@ class Api::OrdersController < Api::ApiController
@tax_profile = TaxProfile.where("lower(group_type)='cashier'")
# end
@shop = Shop.first
# @shop = Shop.first
puts "Hello world"
puts @shop.to_json
return @shop.to_json

View File

@@ -14,11 +14,11 @@ class Api::Payment::MobilepaymentController < Api::ApiController
saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id)
shop_detail = Shop.first
# shop_detail = Shop.first
# rounding adjustment
if !path.include? ("credit_payment")
if shop_detail.is_rounding_adj
if @shop.is_rounding_adj
a = saleObj.grand_total % 25 # Modulus
b = saleObj.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even

View File

@@ -19,12 +19,13 @@ class Api::SurveyController < Api::ApiController
# shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
# puts params.to_json
# set cashier
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
current_shift = ShiftSale.current_shift
open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''")
current_shift = ShiftSale.current_shift(@shop.shop_code)
current_shift_user =Employee.find_by_id(current_shift.employee_id)
if open_cashier.count>0
shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0].id)
shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0])
else
shift_by_terminal = ShiftSale.current_open_shift(current_shift.employee_id)
shift_by_terminal = ShiftSale.current_open_shift(current_shift_user)
end
if params[:survey][:id]>0

View File

@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
#before_action :check_installation
protect_from_forgery with: :exception
helper_method :shop_detail, :order_reservation, :bank_integration
helper_method :shop_detail,:order_reservation, :bank_integration
# lookup domain for db from provision
# before_action :set_locale
# helper_method :current_company,:current_login_employee,:current_user
@@ -17,7 +17,5 @@ class ApplicationController < ActionController::Base
flash[:warning] = exception.message
redirect_to root_path
end
end

View File

@@ -33,10 +33,11 @@ class BaseOrigamiController < ActionController::Base
# CheckinJob.set(wait: 1.minute).perform_later()
# end
##already in LoginVerification
# Get current Cashier
def get_cashier
@cashier = Employee.where("role = 'cashier' AND token_session <> ''")
end
# def get_cashier
# @cashier = Employee.where("role = 'cashier' AND token_session <> ''")
# end
#check webview
def check_mobile

View File

@@ -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,38 @@ module LoginVerification
def current_shop
begin
return Shop.first
shop_code ='263'
@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 = Employee.find_by_token_session_and_shop_code(session[:session_token],@shop.shop_code)
end
def current_user
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
@current_user ||= Employee.find_by_token_session_and_shop_code(session[:session_token],@shop.shop_code) if session[:session_token]
end
# Get current Cashiers
def get_cashier
@cashier = Employee.where("role = 'cashier' AND token_session <> ''")
@cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''")
end
#Shop Name in Navbor
def shop_detail
@shop = Shop.first
shop_code ='263'
@shop = Shop.find_by_shop_code(shop_code)
return @shop
end
#check order reservation used
def order_reservation
order_reserve = Lookup.collection_of('order_reservation')
order_reserve = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation')
status = false
if !order_reserve.empty?
order_reserve.each do |order|
@@ -62,7 +65,7 @@ module LoginVerification
#check bank integration used
def bank_integration
bank_integration = Lookup.collection_of('bank_integration')
bank_integration = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('bank_integration')
status = false
if !bank_integration.empty?
bank_integration.each do |bank|
@@ -88,7 +91,7 @@ module LoginVerification
#@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?

View File

@@ -38,6 +38,7 @@ class Crm::CustomersController < BaseCrmController
@crm_customers.membership_type = response["customer_data"]["member_group_id"]
@crm_customers.customer_type = "Dinein"
@crm_customers.tax_profiles = ["1", "2"]
@crm_customers.shop_code = @shop.shop_code
@crm_customers.save
@crm_customers = Customer.search(filter)
flash[:member_notice]='Customer was successfully created.'
@@ -134,7 +135,7 @@ class Crm::CustomersController < BaseCrmController
params[:type] = nil
params[:customer_id] = params[:id]
@credit_sales = SalePayment.get_credit_sales(params)
@credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code)
#get customer amount
@customer = Customer.find(params[:id])
@@ -259,7 +260,7 @@ class Crm::CustomersController < BaseCrmController
if @checked_contact.nil?
respond_to do |format|
@crm_customers = Customer.new(customer_params)
@crm_customers.shop_code = @shop.shop_code
if @crm_customers.save
# update tax profile
customer = Customer.find(@crm_customers.customer_id)
@@ -619,4 +620,3 @@ class Crm::CustomersController < BaseCrmController
end
end

View File

@@ -6,8 +6,8 @@ class Crm::DiningQueuesController < BaseCrmController
# GET /crm/dining_queues.json
def index
today = DateTime.now.strftime('%Y-%m-%d')
@dining_queues = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status is NULL ", today).order("queue_no asc")
@complete_queue = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status = 'Assign' ", today).order("queue_no asc")
@dining_queues = DiningQueue.where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status is NULL ", today).order("queue_no asc")
@complete_queue = DiningQueue.where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status = 'Assign' ", today).order("queue_no asc")
if params[:term]
@customer = Customer.order(:name).where('lower(name) LIKE ?', "%#{params[:term].downcase}%")
@@ -41,7 +41,7 @@ class Crm::DiningQueuesController < BaseCrmController
def create
puts dining_queue_params
@dining_queue = DiningQueue.new(dining_queue_params)
@dining_queue.shop_code = @shop.shop_code
respond_to do |format|
if @dining_queue.save
@@ -88,7 +88,7 @@ class Crm::DiningQueuesController < BaseCrmController
def assign
@queue = DiningQueue.find(params[:id])
@tables = DiningFacility.where("status = 'available' ")
@tables = DiningFacility.where("status = 'available' and shop_code='#{@shop.shop_code}' and type!='HotelRoom'")
respond_to do |format|
format.html # index.html.erb
end
@@ -105,8 +105,12 @@ class Crm::DiningQueuesController < BaseCrmController
# type = "RoomBooking"
# end
booking = Booking.create({:dining_facility_id => params[:table_id],:type => type,
:checkin_at => Time.now.utc,:customer_id => queue.customer_id,:booking_status => "assign" })
booking = Booking.create({:dining_facility_id => params[:table_id],
:type => type,
:checkin_at => Time.now.utc,
:customer_id => queue.customer_id,
:booking_status => "assign",
:shop_code => @shop.shop_code})
booking.save!
status = queue.update_attributes(dining_facility_id: table_id,status:"Assign")
@@ -135,7 +139,7 @@ class Crm::DiningQueuesController < BaseCrmController
private
# Use callbacks to share common setup or constraints between actions.
def set_dining_queue
@dining_queue = DiningQueue.find(params[:id])
@dining_queue = DiningQueue.find_by_id_and_shop_code(params[:id],@shop.shop_code)
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@@ -11,14 +11,16 @@ 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 = 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()
@@ -35,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(@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
@@ -50,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(@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
@@ -90,31 +92,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 = 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 = Sale::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 = Sale::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 = 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 = 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 = Sale::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 = Sale::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").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 +127,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 +171,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 +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)
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)
shift = ShiftSale.current_open_shift(employee)
if !shift.nil?
redirect_to origami_dashboard_path
# redirect_to origami_root_path

View File

@@ -3,16 +3,14 @@ class Inventory::InventoryController < BaseInventoryController
def index
filter = params[:filter]
@inventory_definitions = InventoryDefinition.get_by_category(filter)
@inventory_definitions = InventoryDefinition.get_by_category(@shop,filter)
end
def show
inventory_definition_id = params[:inventory_definition_id]
inventory = InventoryDefinition.find(inventory_definition_id)
@stock_journals = StockJournal.where(item_code: inventory.item_code).order("id DESC")
inventory = InventoryDefinition.find_by_id_and_shop_code(inventory_definition_id,@shop.shop_code)
@stock_journals = StockJournal.where("item_code=? and shop_code='#{@shop.shop_code}'",inventory.item_code).order("id DESC")
@stock_journals = Kaminari.paginate_array(@stock_journals).page(params[:page]).per(20)
respond_to do |format|
@@ -20,12 +18,4 @@ class Inventory::InventoryController < BaseInventoryController
format.xls
end
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
end

View File

@@ -4,7 +4,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
# GET /inventory_definitions
# GET /inventory_definitions.json
def index
@inventory_definitions = InventoryDefinition.all
@inventory_definitions = InventoryDefinition.where("shop_code='#{@shop.shop_code}'")
end
# GET /inventory_definitions/1
@@ -14,7 +14,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
# GET /inventory_definitions/new
def new
@menus = Menu.all
@menus = Menu.where("shop_code='#{@shop.shop_code}'").order('created_at asc')
@menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
@inventory_definition = InventoryDefinition.new
end
@@ -26,7 +26,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
# POST /inventory_definitions
# POST /inventory_definitions.json
def create
inventory = InventoryDefinition.find_by_item_code(params[:item_code])
inventory = InventoryDefinition.find_by_item_code_and_shop_code(params[:item_code],@shop.shop_code)
if inventory.nil?
@inventory_definition = InventoryDefinition.new
@@ -39,6 +39,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
@inventory_definition.min_order_level = params[:min_order_level]
@inventory_definition.max_stock_level = inventory.max_stock_level.to_i + params[:max_stock_level].to_i
end
@inventory_definition.shop_code = @shop.shop_code
@inventory_definition.created_by = current_user.id
if @inventory_definition.save
result = {:status=> true, :message => "Inventory definition was created successfully",:data=> @inventory_definition}
@@ -83,16 +84,16 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
# DELETE /inventory_definitions/1
# DELETE /inventory_definitions/1.json
def destroy
inventory = InventoryDefinition.find_by_item_code(params[:item_code])
inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code)
@inventory_definition.destroy
respond_to do |format|
format.html { redirect_to inventory_definitions_url, notice: 'Inventory definition was successfully destroyed.' }
format.json { head :no_content }
end
# respond_to do |format|
# format.html { redirect_to inventory_inventory_definitions_url, notice: 'Inventory definition was successfully destroyed.' }
# format.json { head :no_content }
# end
inventory = InventoryDefinition.find(params[:id])
StockJournal.delete_stock_journal(inventory.item_code)
StockCheckItem.delete_stock_check_item(inventory.item_code)
# inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code)
StockJournal.delete_stock_journal(inventory.item_code,@shop)
StockCheckItem.delete_stock_check_item(inventory.item_code,@shop)
if !inventory.nil?
inventory.destroy
flash[:message] = 'Inventory was successfully destroyed.'
@@ -103,16 +104,10 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
end
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
private
# Use callbacks to share common setup or constraints between actions.
def set_inventory_definition
@inventory_definition = InventoryDefinition.find(params[:id])
@inventory_definition = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code)
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@@ -25,7 +25,6 @@ class Inventory::StockCheckItemsController < BaseInventoryController
# POST /stock_check_items.json
def create
@stock_check_item = StockCheckItem.new(stock_check_item_params)
respond_to do |format|
if @stock_check_item.save
format.html { redirect_to inventory_stock_checks_path, notice: 'Stock check item was successfully created.' }
@@ -61,12 +60,6 @@ class Inventory::StockCheckItemsController < BaseInventoryController
end
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
private
# Use callbacks to share common setup or constraints between actions.
def set_stock_check_item

View File

@@ -8,19 +8,23 @@ class Inventory::StockChecksController < BaseInventoryController
.joins("JOIN menu_item_instances mii ON mii.item_instance_code = inventory_definitions.item_code" +
" JOIN menu_items mi ON mi.id = mii.menu_item_id" +
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
.where("inventory_definitions.shop_code='#{@shop.shop_code}'")
.group("mi.menu_category_id")
.order("mi.menu_category_id desc")
unless !@category.nil?
@category_id =@category[0].id
end
end
def create
item_list = JSON.parse(params[:stock_item])
reason = params[:reason]
check = StockCheck.new
@check = check.create(current_user, reason, item_list)
@check = check.create(current_user, reason, item_list,@shop)
end
def show
@check = StockCheck.find(params[:id])
@check = StockCheck.find_by_id_and_shop_code(params[:id],@shop.shop_code)
@stock_check_items = StockCheckItem.get_items_with_category(params[:id])
@@ -28,25 +32,25 @@ class Inventory::StockChecksController < BaseInventoryController
def save_to_journal
check = params[:data]
stockCheck = StockCheck.find(check)
stockCheck = StockCheck.find_by_id_and_shop_code(check,@shop.shop_code)
stockCheck.stock_check_items.each do |item|
StockJournal.from_stock_check(item)
StockJournal.from_stock_check(item,@shop)
end
end
def print_stock_check
stock_id = params[:stock_check_id] # sale_id
stockcheck = StockCheck.find(stock_id)
stockcheck = StockCheck.find_by_id_and_shop_code(stock_id,@shop.shop_code)
stockcheck_items = stockcheck.stock_check_items
member_info = nil
unique_code = 'StockCheckPdf'
shop_details = current_shop
checker = Employee.find(stockcheck.check_by)
print_settings = PrintSetting.find_by_unique_code(unique_code)
checker = Employee.find_by_id_and_shop_code(stockcheck.check_by,@shop.shop_code)
print_settings = PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
if !print_settings.nil?
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker.name, shop_details)
printer.print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker.name, @shop)
end
end

View File

@@ -25,7 +25,7 @@ class StockJournalsController < ApplicationController
# POST /stock_journals.json
def create
@stock_journal = StockJournal.new(stock_journal_params)
@stock_journal.shop_code = @shop.shop_code
respond_to do |format|
if @stock_journal.save
format.html { redirect_to @stock_journal, notice: 'Stock journal was successfully created.' }
@@ -61,12 +61,6 @@ class StockJournalsController < ApplicationController
end
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
private
# Use callbacks to share common setup or constraints between actions.
def set_stock_journal

View File

@@ -81,10 +81,4 @@ class Oqs::EditController < BaseOqsController
render :json => {:status=> false, :message => "Not allowed over quantity!" }
end
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
end

View File

@@ -6,8 +6,8 @@ class Oqs::HomeController < BaseOqsController
# Query for OQS with delivery status true
# @tables = DiningFacility.all.active.order('status desc')
@tables = DiningFacility.where(:type => 'Table').order('status desc')
@rooms = Room.all.active.order('status desc')
@tables = DiningFacility.all.active.where("type = 'Table' and shop_code='#{@shop.shop_code}' ").order('status desc')
@rooms = DiningFacility.all.active.where("type = 'Room' and shop_code='#{@shop.shop_code}' ").order('status desc')
@filter = params[:filter]
@@ -234,7 +234,7 @@ puts items.to_json
left join bookings as bk on bk.booking_id = bo.booking_id
left join dining_facilities as df on df.id = bk.dining_facility_id")
.where("assigned_order_items.created_at between '#{Time.now.beginning_of_day.utc}' and '#{Time.now.end_of_day.utc}'")
query = query.where("df.name LIKE ? OR odt.order_id LIKE ? OR odt.item_name LIKE ? OR cus.name = '#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",)
query = query.where("df.shop_code='#{@shop.shop_code}' and df.name LIKE ? OR odt.order_id LIKE ? OR odt.item_name LIKE ? OR cus.name = '#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",)
.group("odt.order_items_id")
.order("assigned_order_items.created_at desc")

View File

@@ -7,10 +7,10 @@ class Origami::AddordersController < BaseOrigamiController
@webview = true
end
@tables = Table.all.active.order('zone_id asc').group("zone_id")
@rooms = Room.all.active.order('zone_id asc').group("zone_id")
@all_table = Table.all.active.order('status desc')
@all_room = Room.all.active.order('status desc')
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id")
@rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id")
@all_table = Table.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc')
@all_room = Room.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc')
end
def detail
@@ -19,7 +19,7 @@ class Origami::AddordersController < BaseOrigamiController
if check_mobile
@webview = true
end
display_type = Lookup.find_by_lookup_type("display_type")
display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code)
if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
else
@@ -28,10 +28,6 @@ class Origami::AddordersController < BaseOrigamiController
# if params[:menu] == "true"
@menus = []
@menu = []
# else
# @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end
@table_id = params[:id]
@table = DiningFacility.find(@table_id)
@@ -140,7 +136,7 @@ class Origami::AddordersController < BaseOrigamiController
@order.new_booking = true
@order.waiters = current_login_employee.name
@order.employee_name = current_login_employee.name
@order.shop_code =@shop.shop_code
@order.is_extra_time = is_extra_time
@order.extra_time = extra_time
@@ -237,7 +233,7 @@ class Origami::AddordersController < BaseOrigamiController
#Send to background job for processing
order = Order.find(order_id)
sidekiq = Lookup.find_by_lookup_type("sidekiq")
sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",@shop.shop_code)
if ENV["SERVER_MODE"] != 'cloud'
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
@@ -311,10 +307,4 @@ class Origami::AddordersController < BaseOrigamiController
return from
end
private
# def set_dining
# @dining = DiningFacility.find(params[:id])
# end
end

View File

@@ -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
@@ -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.first
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -86,8 +86,8 @@ class Origami::AlipayController < BaseOrigamiController
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
# helper_method :shop_detail
# def shop_detail
# @shop = Shop.first
# end
end

View File

@@ -11,33 +11,32 @@ class Origami::CashInsController < BaseOrigamiController
type = params[:type]
p_jour = PaymentJournal.new
p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user.id)
shift = ShiftSale.current_open_shift(current_user.id)
current_shift = ShiftSale.current_shift
p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user)
shift = ShiftSale.current_open_shift(current_user)
current_shift = ShiftSale.current_shift(@shop.shop_code)
# set cashier
if shift != nil
shift = shift
else
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
if open_cashier.count > 0
shift = ShiftSale.current_open_shift(open_cashier[0].id)
open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''")
if open_cashier.count>0
shift = ShiftSale.current_open_shift(open_cashier[0])
if shift
shift = ShiftSale.current_open_shift(shift.id)
emp = Employee.find_by_id(shift.employee_id)
shift = ShiftSale.current_open_shift(emp)
else
shift = ShiftSale.current_open_shift(current_shift.id)
shift = ShiftSale.current_open_shift(current_shift)
end
else
shift = Employee.find(current_shift.employee_id).name
#shift = current_shift
# shift = Employee.find(current_shift.employee_id).name
shift =current_shift
end
end
puts shift.to_json
shift.cash_in = shift.cash_in + amount.to_f
shift.save
end

View File

@@ -7,28 +7,29 @@ class Origami::CashOutsController < BaseOrigamiController
remark = params[:remark]
amount = params[:amount]
p_jour = PaymentJournal.new
p_jour.cash_out(reference, remark, amount, current_user.id)
shift = ShiftSale.current_open_shift(current_user.id)
p_jour.cash_out(reference, remark, amount, current_user)
shift = ShiftSale.current_open_shift(current_user)
current_shift = ShiftSale.current_shift
current_shift = ShiftSale.current_shift(@shop.shop_code)
# set cashier
if shift != nil
shift = shift
else
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''")
if open_cashier.count>0
shift = ShiftSale.current_open_shift(open_cashier[0].id)
shift = ShiftSale.current_open_shift(open_cashier[0])
if shift
shift = ShiftSale.current_open_shift(shift.id)
emp = Employee.find_by_id(shift.employee_id)
shift = ShiftSale.current_open_shift(emp)
else
shift = ShiftSale.current_open_shift(current_shift.id)
shift = ShiftSale.current_open_shift(current_shift)
end
else
shift = Employee.find(current_shift.employee_id).name
# shift = Employee.find(current_shift.employee_id).name
shift =current_shift
end
end
shift.cash_out = shift.cash_out + amount.to_i

View File

@@ -9,7 +9,6 @@ class Origami::CreditPaymentsController < BaseOrigamiController
@creditcount = 0
others = 0
@shop = Shop.first
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
else
@@ -32,7 +31,6 @@ class Origami::CreditPaymentsController < BaseOrigamiController
sale_id = params[:sale_id]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop.first
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -50,7 +48,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController
def create_credit_payment
arr_sale = JSON.parse(params[:data])
if !ShiftSale.current_shift.nil?
if !ShiftSale.current_shift(@shop.shop_code).nil?
if !arr_sale.nil?
arr_sale.each do |arr_sale|
arr_sale.each do |sale|

View File

@@ -92,12 +92,12 @@ class Origami::CustomersController < BaseOrigamiController
# if flash["errors"]
# @crm_customer.valid?
# end
@membership_types = Lookup.collection_of("member_group_type")
@membership_types = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("member_group_type")
#get paypar accountno
@paypar_accountno = Customer.where("paypar_account_no IS NOT NULL AND paypar_account_no != ''").pluck("paypar_account_no")
#for create customer on/off
@create_flag = true
lookup_customer = Lookup.collection_of('customer_settings')
lookup_customer = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('customer_settings')
if !lookup_customer.empty?
lookup_customer.each do |create_setting|
if create_setting[0].downcase == "create"

View File

@@ -1,36 +1,35 @@
class Origami::DashboardController < BaseOrigamiController
def index
@shop = Shop.first
today = DateTime.now.strftime('%Y-%m-%d')
@display_type = Lookup.find_by_lookup_type("display_type")
@display_type = Lookup.where("shop_code='#{@shop.shop_code}'").find_by_lookup_type("display_type")
@sale_data = Array.new
@total_payment_methods = Sale.total_payment_methods(today,current_user)
@total_payment_methods = Sale.total_payment_methods(@shop,today,current_user)
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)
pay = Sale.payment_sale(@shop,'card', today, current_user)
@sale_data.push({'card' => pay.payment_amount})
else
pay = Sale.payment_sale(payment.payment_method, today, current_user)
pay = Sale.payment_sale(@shop,payment.payment_method, today, current_user)
@sale_data.push({payment.payment_method => pay.payment_amount})
end
end
else
@sale_data = nil
end
@summ_sale = Sale.summary_sale_receipt(today,current_user)
@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)
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time)
# @total_other_customer = Sale.total_other_customer(today,current_user)
@total_order = Sale.total_order(today,current_user)
@total_accounts = Sale.total_account(today,current_user)
@total_order = Sale.total_order(@shop,today,current_user)
@total_accounts = Sale.total_account(@shop,today,current_user)
@account_data = Array.new
if !@total_accounts.nil?
@total_accounts.each do |account|
acc = Sale.account_data(account.account_id, today,current_user)
acc = Sale.account_data(@shop,account.account_id, today,current_user)
if !acc.nil?
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
end
@@ -39,28 +38,28 @@ class Origami::DashboardController < BaseOrigamiController
@account_data = nil
end
@top_items = Sale.top_items(today,current_user)
@total_foc_items = Sale.total_foc_items(today,current_user)
@top_items = Sale.top_items(@shop,today,current_user)
@total_foc_items = Sale.total_foc_items(@shop,today,current_user)
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
@current_user = current_user
#dine-in cashier
dinein_cashier = Lookup.collection_of('dinein_cashier')
dinein_cashier = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dinein_cashier')
@dinein_cashier = 0
if !dinein_cashier[0].nil?
@dinein_cashier = dinein_cashier[0][1]
end
#quick service
quick_service = Lookup.collection_of('quick_service')
quick_service = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quick_service')
@quick_service = 0
if !quick_service[0].nil?
@quick_service = quick_service[0][1]
end
#fourt court
food_court = Lookup.collection_of('food_court')
food_court = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('food_court')
@food_court = 0
@food_court_name = nil
if !food_court[0].nil?
@@ -69,7 +68,7 @@ class Origami::DashboardController < BaseOrigamiController
end
#order reservation
order_reservation = Lookup.collection_of('order_reservation')
order_reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation')
@order_reservation = 0
if !order_reservation.empty?
order_reservation.each do |order_reserve|
@@ -80,7 +79,7 @@ class Origami::DashboardController < BaseOrigamiController
end
#dashboard settings on/off for supervisor and cashier
dashboard_settings = Lookup.collection_of('dashboard_settings')
dashboard_settings = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dashboard_settings')
@setting_flag = true
if !dashboard_settings.empty?
dashboard_settings.each do |setting|
@@ -91,7 +90,7 @@ class Origami::DashboardController < BaseOrigamiController
end
#reservation
reservation = Lookup.collection_of('reservation')
reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('reservation')
@reservation = 0
if !reservation.empty?
reservation.each do |reserve|
@@ -103,13 +102,13 @@ class Origami::DashboardController < BaseOrigamiController
end
def get_all_menu
@menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all
@menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all.where("shop_code='#{@shop.shop_code}'")
@item_attributes = MenuItemAttribute.all.load
@item_options = MenuItemOption.all.load
end
def get_credit_sales
credit_sales = SalePayment.get_credit_sales(params)
credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code)
if !credit_sales.nil?
result = {:status=> true, :data=> credit_sales }
else

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.first
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.first
# rounding adjustment
# if shop_details.is_rounding_adj
# new_total = Sale.get_rounding_adjustment(saleObj.grand_total)

View File

@@ -21,8 +21,8 @@ class Origami::DiscountsController < BaseOrigamiController
end
end
@member_discount = MembershipSetting.find_by_discount(1)
@accounts = Account.all
@member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code)
@accounts = Account.where("shop_code='#{@shop.shop_code}'")
end
#discount page show from origami index with selected order

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.first
@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.first
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -64,8 +64,8 @@ class Origami::GiftVoucherController < BaseOrigamiController
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
# helper_method :shop_detail
# def shop_detail
# @shop = Shop.first
# end
end

View File

@@ -4,15 +4,14 @@ 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')
@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')
@tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@complete = Sale.completed_sale("cashier",@shop.shop_code)
@orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and 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")
@shop = shop_detail
@occupied_table = DiningFacility.where("status='occupied'").count
@shift = ShiftSale.current_open_shift(current_user.id)
@occupied_table = DiningFacility.where("shop_code='#{@shop.shop_code}' and status='occupied'").count
@shift = ShiftSale.current_open_shift(current_user)
end
# origami table detail
@@ -21,20 +20,19 @@ 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')
@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')
@tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@complete = Sale.completed_sale("cashier",@shop.shop_code)
@orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and 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")
@shift = ShiftSale.current_open_shift(current_user.id)
@shift = ShiftSale.current_open_shift(current_user)
@status_order = ""
@status_sale = ""
@sale_array = Array.new
@shop = shop_detail
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all
@membership = MembershipSetting.find_by_shop_code(@shop.shop_code)
@payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'")
@dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ")
#@dining_booking = @dining.bookings.active.where("created_at between '#{DateTime.now.utc - 12.hours}' and '#{DateTime.now.utc}'")
@order_items = Array.new
@@ -106,16 +104,16 @@ class Origami::HomeController < BaseOrigamiController
end
#for bank integration
@checkout_time = Lookup.collection_of('checkout_time')
@checkout_alert_time = Lookup.collection_of('checkout_alert_time')
@checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time')
@checkout_alert_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_alert_time')
accounts = TaxProfile.where("group_type = ?","cashier").order("order_by ASC")
accounts = TaxProfile.where("shop_code='#{@shop.shop_code}' and group_type = ?","cashier").order("order_by ASC")
@tax_arr =[]
accounts.each do |acc|
@tax_arr.push(acc.name)
end
lookup_spit_bill = Lookup.collection_of('split_bill')
lookup_spit_bill = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('split_bill')
@split_bill = 0
if !lookup_spit_bill[0].nil?
@split_bill = lookup_spit_bill[0][1]
@@ -123,7 +121,7 @@ class Origami::HomeController < BaseOrigamiController
#for edit order on/off
@edit_order_origami = true
lookup_edit_order = Lookup.collection_of('edit_order')
lookup_edit_order = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('edit_order')
if !lookup_edit_order.empty?
lookup_edit_order.each do |edit_order|
if edit_order[0].downcase == "editorderorigami"
@@ -136,7 +134,7 @@ class Origami::HomeController < BaseOrigamiController
#for changable on/off
@changable_tax = true
lookup_changable_tax = Lookup.collection_of('changable_tax')
lookup_changable_tax = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('changable_tax')
if !lookup_changable_tax.empty?
lookup_changable_tax.each do |changable_tax|
if changable_tax[0].downcase == "change"

View File

@@ -12,7 +12,7 @@ class Origami::JcbController < BaseOrigamiController
end
total = 0
@jcbcount = 0
@shop = Shop.first
# @shop = Shop.first
@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.first
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -87,8 +87,8 @@ class Origami::JcbController < BaseOrigamiController
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
# helper_method :shop_detail
# def shop_detail
# @shop = Shop.first
# 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.first
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.first
# 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.first
@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.first
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -85,8 +85,8 @@ class Origami::MasterController < BaseOrigamiController
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
# helper_method :shop_detail
# def shop_detail
# @shop = Shop.first
# end
end

View File

@@ -11,7 +11,7 @@ class Origami::MpuController < BaseOrigamiController
end
total = 0
@mpucount = 0
@shop = Shop.first
# @shop = Shop.first
@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.first
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -85,8 +85,8 @@ class Origami::MpuController < BaseOrigamiController
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
# helper_method :shop_detail
# def shop_detail
# @shop = Shop.first
# end
end

View File

@@ -4,7 +4,6 @@ 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)
@receipt_bill = check_receipt_bill
end
@@ -23,7 +22,7 @@ class Origami::OrderReservationController < BaseOrigamiController
order_reserve = OrderReservation.find_by_transaction_ref(params[:ref_no])
if !order_reserve.nil?
if !ShiftSale.current_shift.nil?
if !ShiftSale.current_shift(@shop.shop_code).nil?
if @status == "processed"
if order_reserve.status == "accepted"
result = OrderReservation.create_doemal_order(order_reserve,current_user)
@@ -87,7 +86,7 @@ class Origami::OrderReservationController < BaseOrigamiController
def send_status
order_reservation = OrderReservation.find_by_transaction_ref(params[:ref_no])
if !order_reservation.nil?
if !ShiftSale.current_shift.nil? || params[:status] == 'accepted' || (order_reservation.status == 'new' && params[:status] == 'rejected')
if !ShiftSale.current_shift(@shop.shop_code).nil? || params[:status] == 'accepted' || (order_reservation.status == 'new' && params[:status] == 'rejected')
response = OrderReservation.send_status_to_ordering(params[:url],params[:ref_no],params[:status],params[:waiting_time],params[:min_type],params[:reason])
else
response = { status: false, message: 'No current shift open for this employee!'}
@@ -99,12 +98,12 @@ class Origami::OrderReservationController < BaseOrigamiController
end
def get_order_info
order_reservation = OrderReservation.where("status = 'new'").count()
order_reservation = OrderReservation.where("status = 'new' and shop_code='#{@shop.shop_code}'").count()
render :json => order_reservation
end
def check_receipt_bill
receipt_bill = Lookup.collection_of("order_reservation")
receipt_bill = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("order_reservation")
status = 0
if !receipt_bill.nil?

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.first
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.first
# rounding adjustment
# if shop_details.is_rounding_adj

View File

@@ -17,7 +17,7 @@ class Origami::PaymentsController < BaseOrigamiController
# else
# table = DiningFacility.find(bookings[0].dining_facility_id)
# end
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
@@ -32,7 +32,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
# Print for First Bill to Customer
unique_code = "ReceiptBillPdf"
print_settings = PrintSetting.all
@@ -63,7 +63,7 @@ class Origami::PaymentsController < BaseOrigamiController
# customer= Customer.where('customer_id=' +.customer_id)
customer = Customer.find(sale_data.customer_id)
# rounding adjustment
if shop_detail.is_rounding_adj
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
rounding_adj = new_total - sale_data.grand_total
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
@@ -76,14 +76,14 @@ class Origami::PaymentsController < BaseOrigamiController
remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}"
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
# get member information
rebate = MembershipSetting.find_by_rebate(1)
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
if customer.membership_id != nil && rebate
# member_info = Customer.get_member_account(customer)
# current_balance = SaleAudit.paymal_search(sale_id)
current_balance = 0
end
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# find order id by sale id
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
@@ -99,7 +99,7 @@ class Origami::PaymentsController < BaseOrigamiController
#TODO :: KBZPAY ( QR )
# On/Off setting ( show or not qr )
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => @shop.shop_code).last
status = false
qr = nil
@@ -113,7 +113,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
end
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil)
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, @shop, "Frt",current_balance,nil,other_amount,nil,nil,nil)
result = {
:filepath => filename,
@@ -144,7 +144,7 @@ class Origami::PaymentsController < BaseOrigamiController
#shop_detail = Shop.first
# rounding adjustment
if !path.include? ("credit_payment")
if shop_detail.is_rounding_adj
if @shop.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) if rounding_adj > 0
@@ -178,7 +178,7 @@ class Origami::PaymentsController < BaseOrigamiController
# bookings = Booking.where("sale_id='#{sale_id}'")
bookings = Booking.find_by_sale_id(sale_id)
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
@@ -198,7 +198,7 @@ class Origami::PaymentsController < BaseOrigamiController
# For Print
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
unique_code = "ReceiptBillPdf"
print_settings = PrintSetting.all
if !print_settings.nil?
@@ -226,7 +226,7 @@ class Origami::PaymentsController < BaseOrigamiController
customer= Customer.find(saleObj.customer_id)
# get member information
rebate = MembershipSetting.find_by_rebate(1)
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
if customer.membership_id != nil && rebate && credit_data.nil?
@@ -281,14 +281,14 @@ class Origami::PaymentsController < BaseOrigamiController
card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
#end
end
@@ -313,7 +313,7 @@ class Origami::PaymentsController < BaseOrigamiController
# end
def show
display_type = Lookup.find_by_lookup_type("display_type")
display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code)
if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
else
@@ -333,7 +333,7 @@ class Origami::PaymentsController < BaseOrigamiController
@sale_payment = SalePayment.get_credit_amount_due_left(sale_id)
end
@member_discount = MembershipSetting.find_by_discount(1)
@member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code)
@membership_rebate_balance=0
if Sale.exists?(sale_id)
@@ -358,17 +358,17 @@ class Origami::PaymentsController < BaseOrigamiController
@dining = ''
@other_payment = 0.0
@pdf_view = nil
@lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView")
@lookup_pdf = Lookup.find_by_lookup_type_and_shop_code("ReceiptPdfView",@shop.shop_code)
if !@lookup_pdf.nil?
@pdf_view = @lookup_pdf.value
end
amount = SalePayment.get_kbz_pay_amount(sale_id, current_user)
amount = SalePayment.get_kbz_pay_amount(sale_id, current_user,@shop)
@kbz_pay_amount += amount.to_f
#for changable on/off
@changable_tax = true
lookup_changable_tax = Lookup.collection_of('changable_tax')
lookup_changable_tax = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('changable_tax')
if !lookup_changable_tax.empty?
lookup_changable_tax.each do |changable_tax|
if changable_tax[0].downcase == "change"
@@ -379,7 +379,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
end
@shop = shop_detail #show shop info
# @shop = shop_detail #show shop info
@customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'")
@@ -436,7 +436,7 @@ class Origami::PaymentsController < BaseOrigamiController
#get customer amount
@customer = Customer.find(@sale_data.customer_id)
# accounts = @customer.tax_profiles
accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC")
accounts = TaxProfile.where("group_type = ? and shop_code='#{@shop.shop_code}'",@cashier_type).order("order_by ASC")
@account_arr =[]
@tax_arr =[]
accounts.each do |acc|
@@ -450,7 +450,7 @@ class Origami::PaymentsController < BaseOrigamiController
@account_arr.push(sale_tax)
end
end
rebate = MembershipSetting.find_by_rebate(1)
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
# get member information
if @customer.membership_id != nil && rebate
response = Customer.get_member_account(@customer)
@@ -546,7 +546,7 @@ class Origami::PaymentsController < BaseOrigamiController
# else
# table = DiningFacility.find(bookings[0].dining_facility_id)
# end
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
@@ -612,7 +612,7 @@ class Origami::PaymentsController < BaseOrigamiController
printer = Printer::ReceiptPrinter.new(print_settings)
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
result = {
:status => true,
@@ -664,7 +664,7 @@ class Origami::PaymentsController < BaseOrigamiController
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
@@ -687,7 +687,7 @@ class Origami::PaymentsController < BaseOrigamiController
#shop detail
#shop_detail = Shop.first
printer = PrintSetting.all
printer = PrintSetting.where("shop_code='#{@shop.shop_code}'")
unique_code="ReceiptBillPdf"
if !printer.empty?
@@ -702,7 +702,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
end
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
@@ -711,7 +711,7 @@ class Origami::PaymentsController < BaseOrigamiController
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "FOC",nil,nil,other_amount,nil,nil,nil)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "FOC",nil,nil,other_amount,nil,nil,nil)
result = {
:status => true,
:filepath => filename,
@@ -745,7 +745,6 @@ class Origami::PaymentsController < BaseOrigamiController
def rounding_adj
saleObj = Sale.find(params[:sale_id])
@shop = shop_detail
if @shop.is_rounding_adj
a = saleObj.grand_total % 25 # Modulus
@@ -770,9 +769,9 @@ class Origami::PaymentsController < BaseOrigamiController
if cashier_type.strip.downcase == "doemal_order"
unique_code = "ReceiptBillOrderPdf"
else
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
unique_code = "ReceiptBillPdf"
print_settings = PrintSetting.all
print_settings = PrintSetting.where("shop_code='#{@shop.shop_code}'")
if !print_settings.nil?
print_settings.each do |setting|
if setting.unique_code == 'ReceiptBillPdf'
@@ -795,7 +794,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
end
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)

View File

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

View File

@@ -5,7 +5,7 @@ class Origami::PendingOrderController < BaseOrigamiController
@cashier_type = params[:type]
@sale = Sale.pending_sale(@cashier_type)
@order = Sale.pending_order(@cashier_type)
@completed = Sale.completed_sale(@cashier_type)
@completed = Sale.completed_sale(@cashier_type,@shop.shop_code)
@customers = Customer.pluck("customer_id, name")
@occupied_table = @sale.count.length + @order.count.length
@@ -36,7 +36,7 @@ class Origami::PendingOrderController < BaseOrigamiController
@cashier_type = params[:type]
@sales = Sale.pending_sale(@cashier_type)
@orders = Sale.pending_order(@cashier_type)
@completed = Sale.completed_sale(@cashier_type)
@completed = Sale.completed_sale(@cashier_type,@shop.shop_code)
@customers = Customer.pluck("customer_id, name")
@occupied_table = @sales.count.length + @orders.count.length
@@ -46,7 +46,7 @@ class Origami::PendingOrderController < BaseOrigamiController
@cashier_type = params[:type]
@sales = Sale.pending_sale(@cashier_type)
@orders = Sale.pending_order(@cashier_type)
@completed = Sale.completed_sale(@cashier_type)
@completed = Sale.completed_sale(@cashier_type,@shop.shop_code)
@customers = Customer.pluck("customer_id, name")
@occupied_table = @sales.count.length + @orders.count.length
@@ -81,7 +81,7 @@ class Origami::PendingOrderController < BaseOrigamiController
@cashier_type = params[:type]
@sales = Sale.pending_sale(@cashier_type)
@orders = Sale.pending_order(@cashier_type)
@completed = Sale.completed_sale(@cashier_type)
@completed = Sale.completed_sale(@cashier_type,@shop.shop_code)
@occupied_table = @sales.count.length + @orders.count.length

View File

@@ -13,16 +13,12 @@ class Origami::QuickServiceController < ApplicationController
# if params[:menu] == "true"
@menus = []
@menu = []
# else
# @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end
@zone = Zone.all
@zone = Zone.all.where("shop_code='#{@shop.shop_code}'")
@customer = Customer.all
@tables = Table.all.active.order('status desc')
@rooms = Room.all.active.order('status desc')
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@cashier_type = "quick_service"
display_type = Lookup.find_by_lookup_type("display_type")
display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code)
if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
else
@@ -31,9 +27,7 @@ class Origami::QuickServiceController < ApplicationController
#checked quick_service only
@quick_service_only = false
lookup_dine_in = Lookup.collection_of('quickservice_add_order')
puts 'lookup_dine_in!!!!'
puts lookup_dine_in
lookup_dine_in = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quickservice_add_order')
if !lookup_dine_in.empty?
lookup_dine_in.each do |dine_in|
if dine_in[0].downcase == "quickserviceaddorder"

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.first
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
else

View File

@@ -8,7 +8,7 @@ class Origami::RequestBillsController < ApplicationController
end
# Print Request Bill and add to sale tables
def print
if !ShiftSale.current_shift.nil?
if !ShiftSale.current_shift(@shop.shop_code).nil?
order_id = params[:id] # order_id
order = Order.find(order_id)
booking = order.booking
@@ -45,7 +45,7 @@ class Origami::RequestBillsController < ApplicationController
sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type )
# Promotion Activation
Promotion.promo_activate(sale_data)
Promotion.promo_activate(sale_data,@shop.shop_code)
#bill channel
if ENV["SERVER_MODE"] == 'cloud'
@@ -62,14 +62,14 @@ class Origami::RequestBillsController < ApplicationController
render :json => result.to_json
else
#check checkInOut pdf print
checkout_time = Lookup.collection_of('checkout_time')
checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time')
if !booking.dining_facility_id.nil?
terminal = DiningFacility.find_by_id(booking.dining_facility_id)
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
unique_code = "CheckInOutPdf"
printer = PrintSetting.find_by_unique_code(unique_code)
printer = PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)

View File

@@ -2,9 +2,9 @@ class Origami::RoomsController < BaseOrigamiController
def index
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@complete = Sale.completed_sale("cashier")
@complete = Sale.completed_sale("cashier",@shop.shop_code)
@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)
@shift = ShiftSale.current_open_shift(current_user)
@webview = false
if check_mobile
@webview = true
@@ -19,19 +19,17 @@ class Origami::RoomsController < BaseOrigamiController
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@complete = Sale.completed_sale("cashier")
@complete = Sale.completed_sale("cashier",@shop.shop_code)
@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")
@room = DiningFacility.find(params[:room_id])
@shift = ShiftSale.current_open_shift(current_user.id)
@shift = ShiftSale.current_open_shift(current_user)
@status_order = ""
@status_sale = ""
@sale_array = Array.new
@shop = Shop.first
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all
@membership = MembershipSetting.find_by_shop_code(@shop.shop_code)
@payment_methods = PaymentMethodSetting.find_by_shop_code(@shop.shop_code)
@dining_room = @room.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ")
@order_items = Array.new

View File

@@ -163,9 +163,9 @@ class Origami::SaleEditController < BaseOrigamiController
# end
# end
sale.compute_by_sale_items(saleObj.total_discount, nil, order_source)
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
ProductCommission.edit_product_commission(saleitemObj)
ProductCommission.edit_product_commission(saleitemObj,sale.shop_code)
end
# make cancel void item

View File

@@ -7,7 +7,7 @@ class Origami::SalesController < BaseOrigamiController
@tables = Table.unscoped.all.active.order('status desc')
@rooms = Room.unscoped.all.active.order('status desc')
@complete = Sale.completed_sale("cashier")
@complete = Sale.completed_sale("cashier",@shop.shop_code)
@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")
@sale = Sale.find(params[:sale_id])

View File

@@ -4,7 +4,7 @@ class Origami::ShiftsController < BaseOrigamiController
def show
@cashier_type = params[:type]
@shift = ShiftSale.current_open_shift(current_user.id)
@shift = ShiftSale.current_open_shift(current_user)
#for bank integration
bank_integration = Lookup.collection_of('bank_integration')
@bank_integration = 0
@@ -56,7 +56,7 @@ class Origami::ShiftsController < BaseOrigamiController
cashier_terminal.save
#add shift_sale_id to card_settle_trans
bank_integration = Lookup.find_by_lookup_type('bank_integration')
bank_integration = Lookup.find_by_lookup_type_and_shop_code('bank_integration',@shop.shop_code)
if !bank_integration.nil?
card_settle_trans = CardSettleTran.select('id').where(['shift_sale_id IS NULL and status IS NOT NULL'])
@@ -74,7 +74,7 @@ class Origami::ShiftsController < BaseOrigamiController
# if !close_cashier_print[0].nil?
# @close_cashier_print = close_cashier_print[0][1]
# end
close_cashier_pdf = Lookup.collection_of("print_settings")
close_cashier_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings")
unique_code = "CloseCashierPdf"
if !close_cashier_pdf.empty?
@@ -92,7 +92,7 @@ class Origami::ShiftsController < BaseOrigamiController
#get tax
shift_obj = ShiftSale.where('id =?',@shift.id)
sale_items = ''
@lookup = Lookup.shift_sale_items_lookup_value
@lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code)
if @lookup.to_i == 1
@sale_items = Sale.get_shift_sale_items(@shift.id)
other_charges = Sale.get_other_charges()
@@ -129,7 +129,7 @@ class Origami::ShiftsController < BaseOrigamiController
end
end
end
Employee.logout(session[:session_token])
Employee.logout(@shop,session[:session_token])
session[:session_token] = nil
end
@@ -137,7 +137,7 @@ class Origami::ShiftsController < BaseOrigamiController
end
def sale_summary
@shift = ShiftSale.current_open_shift(current_user.id)
@shift = ShiftSale.current_open_shift(current_user)
# @shift = ShiftSale.find_by_id(shift_id)
if @shift

View File

@@ -100,7 +100,7 @@ class Origami::SplitBillController < BaseOrigamiController
end
status = false
if !ShiftSale.current_shift.nil?
if !ShiftSale.current_shift(@shop.shop_code).nil?
#create Bill by Booking ID
table = 0
if !params[:booking_id].empty?
@@ -133,7 +133,8 @@ class Origami::SplitBillController < BaseOrigamiController
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type,
:checkin_at => Time.now.utc, :checkin_by => current_user.name,
:booking_status => "assign" })
:booking_status => "assign",
:shop_code =>@shop.shop_code})
if !orders.nil?
orders.each do |order|
@@ -333,7 +334,7 @@ class Origami::SplitBillController < BaseOrigamiController
end
end
Promotion.promo_activate(sale_data)
Promotion.promo_activate(sale_data,@shop.shop_code)
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
@@ -358,6 +359,7 @@ class Origami::SplitBillController < BaseOrigamiController
order.waiters = current_user.name
order.employee_name = current_user.name
order.guest_info = nil
order.shop_code = @shop.shop_code
order.save!
return order
@@ -410,10 +412,4 @@ class Origami::SplitBillController < BaseOrigamiController
render :json => { status: true }
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
end

View File

@@ -18,8 +18,8 @@ class Origami::SurveysController < BaseOrigamiController
if @booking.dining_facility_id.to_i>0
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
@table_type = @dining_facility.type
@survey_data = Survey.find_by_dining_name(@dining_facility.name)
survey_process = Survey.find_by_receipt_no(@receipt_no)
@survey_data = Survey.find_by_dining_name_and_shop_code(@dining_facility.name,@shop.shop_code)
survey_process = Survey.find_by_receipt_no_and_shop_code(@receipt_no,@shop.shop_code)
if !survey_process.nil?
@survey_data = survey_process
end
@@ -33,7 +33,7 @@ class Origami::SurveysController < BaseOrigamiController
@table_type = @dining_facility.type
@receipt_no = nil
@grand_total = nil
@survey_data = Survey.find_by_dining_name_and_receipt_no(@dining_facility.name,nil)
@survey_data = Survey.find_by_dining_name_and_receipt_no_and_shop_code(@dining_facility.name,nil,@shop.shop_code)
end
end
@@ -46,12 +46,13 @@ class Origami::SurveysController < BaseOrigamiController
# cashier_zone = CashierTerminalByZone.find_by_zone_id(@dining_facility.zone_id)
# shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
# set cashier
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
current_shift = ShiftSale.current_shift
open_cashier = Employee.where("role = 'cashier' AND token_session <> '' and shop_code='#{@shop.shop_code}'")
current_shift = ShiftSale.current_shift(@shop.shop_code)
current_shift_user =Employee.find_by_id(current_user.employee_id)
if open_cashier.count>0
shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0].id)
shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0])
else
shift_by_terminal = ShiftSale.current_open_shift(current_shift.employee_id)
shift_by_terminal = ShiftSale.current_open_shift(current_shift_user)
end
else
sale = Sale.find(@sale_id)
@@ -75,6 +76,7 @@ class Origami::SurveysController < BaseOrigamiController
@survey = Survey.new(survey_params)
@survey.shift_id = shift_by_terminal.id
@survey.foreigner = params["survey"]["foreigner"].to_json
@survey.shop_code = @shop.shop_code
# respond_to do |format|
if @survey.save
redirect_to @url

View File

@@ -1,7 +1,7 @@
class Origami::TableInvoicesController < BaseOrigamiController
def index
@table = DiningFacility.find(params[:table_id])
shop = Shop.first
# shop = Shop.first
puts "table bookig lenght"
@sale_array = Array.new
@table.bookings.each do |booking|
@@ -11,7 +11,7 @@ class Origami::TableInvoicesController < BaseOrigamiController
else
sale = Sale.find(booking.sale_id)
# rounding adjustment
if shop.is_rounding_adj
if @shop.is_rounding_adj
a = sale.grand_total % 25 # Modulus
b = sale.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
@@ -32,16 +32,17 @@ class Origami::TableInvoicesController < BaseOrigamiController
def show
# puts 'Catch me if you can.......................'
@table = DiningFacility.find(params[:table_id])
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all
shop = Shop.first
@membership = MembershipSetting.find_by_shop_code(@shop.shop_code)
@payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'")
# shop = Shop.first
@sale_array = Array.new
@table.bookings.each do |booking|
if booking.sale_id.nil?
else
sale = Sale.find(booking.sale_id)
# rounding adjustment
if shop.is_rounding_adj
if @shop.is_rounding_adj
a = sale.grand_total % 25 # Modulus
b = sale.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
@@ -64,7 +65,7 @@ class Origami::TableInvoicesController < BaseOrigamiController
@status_sale = 'sale'
@customer = @sale.customer
#for split bill
lookup_spit_bill = Lookup.collection_of('split_bill')
lookup_spit_bill = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('split_bill')
@split_bill = 0
if !lookup_spit_bill[0].nil?
@split_bill = lookup_spit_bill[0][1]

View File

@@ -11,7 +11,7 @@ class Origami::UnionpayController < BaseOrigamiController
end
total = 0
@unionpaycount = 0
@shop = Shop.first
# @shop = Shop.first
@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.first
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -83,8 +83,8 @@ class Origami::UnionpayController < BaseOrigamiController
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
# helper_method :shop_detail
# def shop_detail
# @shop = Shop.first
# end
end

View File

@@ -11,7 +11,7 @@ class Origami::VisaController < BaseOrigamiController
end
total = 0
@visacount = 0
@shop = Shop.first
# @shop = Shop.first
@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.first
# rounding adjustment
# if shop_details.is_rounding_adj
@@ -83,8 +83,8 @@ class Origami::VisaController < BaseOrigamiController
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
# helper_method :shop_detail
# def shop_detail
# @shop = Shop.first
# end
end

View File

@@ -73,7 +73,7 @@ class Origami::VoidController < BaseOrigamiController
# FOr Sale Audit
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
action_by = Employee.find_by_emp_id(access_code).name
action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_code).name
end
# remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
@@ -115,10 +115,8 @@ class Origami::VoidController < BaseOrigamiController
customer= Customer.find(sale.customer_id)
#shop detail
shop_details = current_shop
# get member information
rebate = MembershipSetting.find_by_rebate(1)
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
@@ -126,7 +124,7 @@ class Origami::VoidController < BaseOrigamiController
current_balance = 0
end
printer = PrintSetting.all
printer = PrintSetting.where("shop_code='#{@shop.shop_code}'")
unique_code="ReceiptBillPdf"
if !printer.empty?
@@ -141,13 +139,13 @@ class Origami::VoidController < BaseOrigamiController
end
end
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "VOID",current_balance,nil,other_amount,nil,nil,nil)
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,

View File

@@ -8,7 +8,7 @@ class Origami::VoucherController < BaseOrigamiController
@vouchercount = 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

View File

@@ -55,7 +55,7 @@ class Origami::WasteSpoileController < BaseOrigamiController
# FOr Sale Audit
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
action_by = Employee.find_by_emp_id(access_code).name
action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_code).name
end
# remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,remark )
@@ -88,10 +88,8 @@ class Origami::WasteSpoileController < BaseOrigamiController
# unique_code = "ReceiptBillPdf"
customer= Customer.find(sale.customer_id)
#shop detail
shop_details = current_shop
# get member information
rebate = MembershipSetting.find_by_rebate(1)
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
@@ -99,7 +97,7 @@ class Origami::WasteSpoileController < BaseOrigamiController
current_balance = 0
end
printer = PrintSetting.all
printer = PrintSetting.where("shop_code='#{@shop.shop_code}'")
unique_code="ReceiptBillPdf"
if !printer.empty?
@@ -115,13 +113,13 @@ class Origami::WasteSpoileController < BaseOrigamiController
end
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, remark,current_balance,nil,other_amount,nil,nil,nil)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, remark,current_balance,nil,other_amount,nil,nil,nil)
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,

View File

@@ -11,7 +11,7 @@ class PrintSettingsController < ApplicationController
# GET /print_settings/1
# GET /print_settings/1.json
def show
@lookup = Lookup.shift_sale_items_lookup_value
@lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code)
end
# GET /print_settings/new
@@ -22,7 +22,7 @@ class PrintSettingsController < ApplicationController
# GET /print_settings/1/edit
def edit
@lookup = Lookup.shift_sale_items_lookup_value
@lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code)
@server_mode = ENV["SERVER_MODE"]
end
@@ -30,7 +30,7 @@ class PrintSettingsController < ApplicationController
# POST /print_settings.json
def create
@print_setting = PrintSetting.new(print_setting_params)
@print_setting.shop_code = @shop.shop_code
respond_to do |format|
if @print_setting.save
format.html { redirect_to @print_setting, notice: 'Print setting was successfully created.' }
@@ -48,7 +48,7 @@ class PrintSettingsController < ApplicationController
respond_to do |format|
if @print_setting.update(print_setting_params)
if @print_setting.unique_code == 'CloseCashierPdf'
Lookup.save_shift_sale_items_settings(params[:shift_sale_items])
Lookup.save_shift_sale_items_settings(params[:shift_sale_items],@shop.shop_code)
end
format.html { redirect_to @print_setting, notice: 'Print setting was successfully updated.' }

View File

@@ -24,9 +24,9 @@ authorize_resource :class => false
end
end
@lookup = Lookup.find_by_lookup_type('reprint_receipt')
@lookup = Lookup.find_by_lookup_type_and_shop_code('reprint_receipt',@shop.shop_code)
if @lookup.nil?
@lookup = Lookup.create_reprint_receipt_lookup
@lookup = Lookup.create_reprint_receipt_lookup(@shop.shop_code)
end
payment_type = params[:payment_type]
@@ -152,7 +152,7 @@ authorize_resource :class => false
# else
# table = DiningFacility.find(bookings[0].dining_facility_id)
# end
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else

View File

@@ -5,7 +5,7 @@ class Settings::AccountsController < ApplicationController
# GET /settings/accounts
# GET /settings/accounts.json
def index
@settings_accounts = Account.all
@settings_accounts = Account.all.where("shop_code='#{@shop.shop_code}'")
end
# GET /settings/accounts/1
@@ -26,6 +26,7 @@ class Settings::AccountsController < ApplicationController
# POST /settings/accounts.json
def create
@settings_account = Account.new(account_params)
@settings_account.shop_code = @shop.shop_code
respond_to do |format|
if @settings_account.save
format.html { redirect_to settings_accounts_url, notice: 'Account was successfully created.' }

View File

@@ -28,7 +28,7 @@ class Settings::CashierTerminalsController < ApplicationController
# POST /settings/cashier_terminals.json
def create
@settings_cashier_terminal = CashierTerminal.new(settings_cashier_terminal_params)
@settings_cashier_terminal.shop_code = @shop.shop_code
respond_to do |format|
if @settings_cashier_terminal.save
format.html { redirect_to settings_cashier_terminals_path, notice: 'Cashier terminal was successfully created.' }

View File

@@ -30,6 +30,7 @@ class Settings::CommissionersController < ApplicationController
def create
@commissioner = Commissioner.new(commissioner_params)
@commissioner.created_by = current_user.id
@commissioner.shop_code = @shop.shop_code
unless @commissioner.joined_date.nil?
@commissioner.joined_date = @commissioner.joined_date.utc.getlocal.strftime('%Y-%b-%d')
end

View File

@@ -31,6 +31,7 @@ class Settings::CommissionsController < ApplicationController
@commission = Commission.new(commission_params)
@commission.product_type = 'menu_item'
@commission.product_code = "[]"
@commission.shop_code = @shop.shop_code
respond_to do |format|
if @commission.save

View File

@@ -31,7 +31,7 @@ class Settings::EmployeesController < ApplicationController
# POST /employees.json
def create
@employee = Employee.new(employee_params)
@employee.shop_code = @shop.shop_code
respond_to do |format|
if @employee.save
format.html { redirect_to settings_employees_path, notice: 'Employee was successfully created.' }

View File

@@ -25,7 +25,7 @@ class Settings::LookupsController < ApplicationController
# POST /settings/lookups.json
def create
@settings_lookup = Lookup.new(settings_lookup_params)
@settings_lookup.shop_code = @shop.shop_code
respond_to do |format|
if @settings_lookup.save
format.html { redirect_to settings_lookups_path, notice: 'Lookup was successfully created.' }

View File

@@ -26,7 +26,7 @@ class Settings::MembershipActionsController < ApplicationController
# POST /settings/membership_actions.json
def create
@settings_membership_action = MembershipAction.new(settings_membership_action_params)
@settings_membership_action.shop_code = @shop.shop_code
respond_to do |format|
if @settings_membership_action.save
format.html { redirect_to settings_membership_actions_path, notice: 'Membership action was successfully created.' }

View File

@@ -26,7 +26,7 @@ class Settings::MembershipSettingsController < ApplicationController
# POST /settings/membership_settings.json
def create
@settings_membership_setting = MembershipSetting.new(settings_membership_setting_params)
@settings_membership_setting.shop_code = @shop.shop_code
respond_to do |format|
if @settings_membership_setting.save
format.html { redirect_to settings_membership_settings_path, notice: 'Membership setting was successfully created.' }

View File

@@ -5,7 +5,7 @@ class Settings::MenusController < ApplicationController
# GET /settings/menus
# GET /settings/menus.json
def index
@settings_menus = Menu.all.page(params[:page]).per(10)
@settings_menus = Menu.all.where("shop_code='#{@shop.shop_code}'").page(params[:page]).per(10)
respond_to do |format|
format.html
format.xlsx
@@ -32,6 +32,7 @@ class Settings::MenusController < ApplicationController
def create
@settings_menu = Menu.new(settings_menu_params)
@settings_menu.created_by = current_login_employee.name
@settings_menu.shop_code = @shop.shop_code
respond_to do |format|
if @settings_menu.save
format.html { redirect_to settings_menus_path, notice: 'Menu was successfully created.' }
@@ -73,7 +74,7 @@ class Settings::MenusController < ApplicationController
end
def export
@settings_menus = Menu.all.page(params[:page]).per(10)
@settings_menus = Menu.all.where("shop_code='#{@shop.shop_code}'").page(params[:page]).per(10)
menu = Menu.find(params[:id])
p = Axlsx::Package.new
@@ -154,7 +155,7 @@ class Settings::MenusController < ApplicationController
def import
if params[:file]
status = Menu.import(params[:file], current_user.name)
status = Menu.import(params[:file], current_user.name,@shop)
redirect_to settings_menus_path, notice: status
end
end

View File

@@ -32,6 +32,7 @@ class Settings::OrderQueueStationsController < ApplicationController
@settings_order_queue_station = OrderQueueStation.new(settings_order_queue_station_params)
@settings_order_queue_station.created_by = current_login_employee.name
@settings_order_queue_station.processing_items = "[]"
@settings_order_queue_station.shop_code = @shop.shop_code
respond_to do |format|
if @settings_order_queue_station.save
format.html { redirect_to settings_order_queue_stations_path, notice: 'Order queue station was successfully created.' }

View File

@@ -26,7 +26,7 @@ class Settings::PaymentMethodSettingsController < ApplicationController
# POST /settings/payment_method_settings.json
def create
@settings_payment_method_setting = PaymentMethodSetting.new(settings_payment_method_setting_params)
@settings_payment_method_settings.shop_code = @shop.shop_code
respond_to do |format|
if @settings_payment_method_setting.save
format.html { redirect_to settings_payment_method_settings_path, notice: 'Payment method setting was successfully created.' }

View File

@@ -29,6 +29,7 @@ load_and_authorize_resource except: [:create]
@settings_product = Product.new(settings_product_params)
@settings_product.created_by = current_user.name
@settings_product.shop_code = @shop.shop_code
respond_to do |format|
if @settings_product.save
format.html { redirect_to settings_products_path, notice: 'Product was successfully created.' }

View File

@@ -30,6 +30,7 @@ class Settings::PromotionsController < ApplicationController
def create
@promotion = Promotion.new(promotion_params)
@promotion.created_by = current_login_employee.id
@promotion.shop_code = @shop.shop_code
if !@promotion.promo_start_hour.nil?
@promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30)
end

View File

@@ -29,6 +29,7 @@ class Settings::RoomsController < ApplicationController
@settings_room.type = DiningFacility::ROOM_TYPE
@settings_room.zone_id = params[:zone_id]
@settings_room.created_by = current_login_employee.name
@settings_room.shop_code = @shop.shop_code
respond_to do |format|
if @settings_room.save
format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully created.' }

View File

@@ -28,6 +28,7 @@ class Settings::TablesController < ApplicationController
@settings_table = Table.new(settings_table_params)
@settings_table.type = DiningFacility::TABLE_TYPE
@settings_table.zone_id = params[:zone_id]
@settings_table.shop_code = @shop.shop_code
@settings_table.created_by = current_login_employee.name
respond_to do |format|
if @settings_table.save

View File

@@ -47,7 +47,7 @@ class Settings::TaxProfilesController < ApplicationController
def create
@settings_tax_profile = TaxProfile.new(settings_tax_profile_params)
@settings_tax_profile.created_by = current_login_employee.name
@settings_tax_profile.shop_code = @shop.shop_code
respond_to do |format|
if @settings_tax_profile.save
format.html { redirect_to settings_tax_profiles_path, notice: 'Tax profile was successfully created.' }

View File

@@ -5,7 +5,7 @@ class Settings::ZonesController < ApplicationController
# GET /settings/zones
# GET /settings/zones.json
def index
@settings_zones = Zone.all
@settings_zones = Zone.all.where("shop_code='#{@shop.shop_code}' and is_active= true")
end
# GET /settings/zones/1
@@ -28,6 +28,7 @@ class Settings::ZonesController < ApplicationController
# POST /settings/zones.json
def create
@settings_zone = Zone.new(settings_zone_params)
@settings_zone.shop_code =@shop.shop_code
@settings_zone.created_by = current_login_employee.name
respond_to do |format|
if @settings_zone.save

View File

@@ -9,10 +9,10 @@ class Transactions::BookingsController < ApplicationController
to = params[:to]
if filter.nil? && from.nil? && to.nil?
@bookings = Booking.all.order("sale_id desc")
@bookings = Booking.where("shop_code='#{@shop.shop_code}'").order("sale_id desc")
@bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20)
else
booking = Booking.search(filter,from,to)
booking = Booking.search(filter,from,to).where("bookings.shop_code='#{@shop.shop_code}'")
if booking.count > 0
@bookings = booking
@bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20)

View File

@@ -89,8 +89,8 @@ class Transactions::SalesController < ApplicationController
# GET /transactions/sales/1
# GET /transactions/sales/1.json
def show
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.where("is_active='1'")
@membership = MembershipSetting.find_by_shop_code(@shop.shop_code)
@payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}' and is_active='1'")
@sale = Sale.find(params[:id])
@order_items = []

View File

@@ -36,6 +36,7 @@ class AssignedOrderItem < ApplicationRecord
assigned_order_item.order_queue_station = order_queue_station
assigned_order_item.print_status = false
assigned_order_item.delivery_status = false
assigned_order_item.shop_code =order.shop_code
assigned_order_item.save!
end

View File

@@ -127,4 +127,9 @@ class Booking < ApplicationRecord
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
end
end
def generate_custom_id
if self.booking_id.nil?
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
end
end
end

View File

@@ -32,9 +32,8 @@ class DiningFacility < ApplicationRecord
end
def get_current_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null
# booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_by is null").limit(1) #and checkout_at is null
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null
if booking.count > 0 then
return booking[0]
else
@@ -43,8 +42,8 @@ class DiningFacility < ApplicationRecord
end
def get_moved_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
if booking.count > 0 then
return booking[0]
@@ -70,8 +69,8 @@ class DiningFacility < ApplicationRecord
end
def get_current_checkout_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1)
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1)
if booking.count > 0 then
return booking[0]
else
@@ -82,7 +81,7 @@ class DiningFacility < ApplicationRecord
def get_checkout_booking
booking = self.get_current_checkout_booking
if booking
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")
free_time_min = 0
if !lookup_checkout_time.empty?
now = Time.now.utc
@@ -118,11 +117,11 @@ class DiningFacility < ApplicationRecord
end
def self.get_checkin_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null")
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
bookings = Booking.where("shop_code='#{self.shop_code}' and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null")
arr_booking = Array.new
if bookings
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")
free_time_min = 0
if !lookup_checkout_time.empty?
now = Time.now.utc

View File

@@ -3,7 +3,6 @@ class Employee < ApplicationRecord
has_many :commissioners
has_many :shit_sales
belongs_to :order_queue_station
validates_presence_of :name, :role
validates_presence_of :password, :on => [:create]
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
@@ -20,9 +19,9 @@ class Employee < ApplicationRecord
Employee.select("id, name").map { |e| [e.name, e.id] }
end
def self.login(emp_id, password)
user = Employee.find_by_emp_id(emp_id)
expiry_time = login_expiry_time
def self.login(shop,emp_id, password)
user = Employee.find_by_emp_id_and_shop_code(emp_id,shop.shop_code)
expiry_time = login_expiry_time(shop)
if (user)
#user.authenticate(password)
if (user.authenticate(password))
@@ -37,10 +36,10 @@ class Employee < ApplicationRecord
end
def self.authenticate_by_token(session_token)
def self.authenticate_by_token(session_token,shop)
if (session_token)
user = Employee.find_by_token_session(session_token)
expiry_time = login_expiry_time
user = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code)
expiry_time = login_expiry_time(shop)
if user && user.session_expiry.utc > DateTime.now.utc
#Extend the login time each time authenticatation take place
@@ -55,9 +54,9 @@ class Employee < ApplicationRecord
return false
end
def self.logout(session_token)
def self.logout(shop,session_token)
if (session_token)
user = Employee.find_by_token_session(session_token)
user = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code)
if user
user.token_session = nil
@@ -73,9 +72,9 @@ class Employee < ApplicationRecord
retry
end
def self.login_expiry_time
def self.login_expiry_time(shop)
expiry_time = 30
login_expiry = Lookup.collection_of('expiry_time')
login_expiry = Lookup.where("shop_code='#{shop.shop_code}'").collection_of('expiry_time')
if !login_expiry.empty?
login_expiry.each do |exp_time|
if exp_time[0].downcase == "login"

View File

@@ -8,7 +8,7 @@ class InventoryDefinition < ApplicationRecord
logger.debug saleObj.sale_items.to_json
if !saleObj.nil?
saleObj.sale_items.each do |item|
found, inventory_definition = find_product_in_inventory(item)
found, inventory_definition = find_product_in_inventory(item,saleObj.shop_code)
if found
check_balance(item,inventory_definition)
end
@@ -23,7 +23,7 @@ class InventoryDefinition < ApplicationRecord
end
end
def self.find_product_in_inventory(item,instance_code)
def self.find_product_in_inventory(item,shop_code=nil)
# unless instance_code.empty?
# instance_code = instance_code.to_s
# instance_code[0] = ""
@@ -36,16 +36,15 @@ class InventoryDefinition < ApplicationRecord
# puts "found prodcut+++++++++++++++++++++++++++++++++++==="
# puts prod.to_json
# end
if product = InventoryDefinition.find_by_item_code(item.item_instance_code)
if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code)
if product = InventoryDefinition.find_by_item_code_and_shop_code(item.item_instance_code,shop_code)
if stock_check_item = StockCheckItem.find_by_item_code_and_shop_code(item.item_instance_code,shop_code)
return true, product
end
end
end
def self.check_balance(item, inventory_definition) # item => saleItemOBj
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
stock = StockJournal.where("shop_code='#{inventory_definition.shop_code}' and item_code=?", item.item_instance_code).order("id DESC").first
unless stock.nil?
modify_balance(item, stock, inventory_definition)
else
@@ -94,7 +93,7 @@ class InventoryDefinition < ApplicationRecord
.order("mi.menu_category_id desc")
end
def self.get_by_category(filter)
def self.get_by_category(shop,filter)
# THEN (SELECT min(balance) FROM stock_journals
# least_stock = "SELECT (CASE WHEN stock_journals.remark != 'out of stock'
# THEN (SELECT balance FROM stock_journals
@@ -123,9 +122,9 @@ class InventoryDefinition < ApplicationRecord
" JOIN menu_items mi ON mi.id = mii.menu_item_id" +
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
.joins(" JOIN accounts acc ON acc.id = mi.account_id")
.where("inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ?
.where("inventory_definitions.shop_code='#{shop.shop_code}' and (inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ?
OR inventory_definitions.max_stock_level LIKE ? OR sj.balance LIKE ? OR mi.name LIKE ?
OR mii.item_instance_name LIKE ? OR mc.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%",
OR mii.item_instance_name LIKE ? OR mc.name LIKE ?)","%#{filter}%","%#{filter}%","%#{filter}%",
"%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")
.group("mi.menu_category_id,inventory_definitions.item_code")
.order("balance asc, mi.name asc,acc.title desc,mi.menu_category_id desc")

View File

@@ -1,6 +1,7 @@
class Lookup < ApplicationRecord
has_many :accounts
belongs_to :shop
def available_types
{'Employee Roles' => 'employee_roles',
@@ -21,10 +22,10 @@ class Lookup < ApplicationRecord
# Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] }
# end
def self.get_checkin_time_limit
def self.get_checkin_time_limit(shop_code)
time_limit = 5
lookup = Lookup.find_by_lookup_type('checkin_time_limit')
lookup = Lookup.find_by_lookup_type_and_shop_code('checkin_time_limit',shop_code)
if !lookup.nil?
time_limit = lookup.value.to_i
end
@@ -59,39 +60,41 @@ class Lookup < ApplicationRecord
end
def self.create_shift_sale_lookup
def self.create_shift_sale_lookup(shop_code)
@lookup = Lookup.new
@lookup.lookup_type = 'shift_sale_items'
@lookup.name = 'Shift Sale Items'
@lookup.value = 0
@lookup.shop_code = shop_code
@lookup.save
return @lookup
end
def self.create_reprint_receipt_lookup
def self.create_reprint_receipt_lookup(shop_code)
@lookup = Lookup.new
@lookup.lookup_type = 'reprint_receipt'
@lookup.name = 'Reprint Receipt in Report'
@lookup.value = 0
@lookup.shop_code = shop_code
@lookup.save
return @lookup
end
def self.save_shift_sale_items_settings(val)
@lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last
def self.save_shift_sale_items_settings(val,shop_code)
@lookup = Lookup.where("shop_code='#{shop_code}' and lookup_type=?", 'shift_sale_items').last
if @lookup.nil?
@lookup = Lookup.create_shift_sale_lookup
@lookup = Lookup.create_shift_sale_lookup(shop_code)
end
@lookup.value = val
@lookup.save
end
def self.shift_sale_items_lookup_value
@lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last
def self.shift_sale_items_lookup_value(shop_code)
@lookup = Lookup.where("shop_code='#{shop_code}' and lookup_type=?", 'shift_sale_items').last
if @lookup.nil?
@lookup = Lookup.create_shift_sale_lookup
@lookup = Lookup.create_shift_sale_lookup(shop_code)
end
return @lookup.value
end

View File

@@ -1,5 +1,5 @@
class MembershipSetting < ApplicationRecord
scope :active, -> { where(is_active: true) }
MembershipSetting = MembershipSetting.find_by_id(1)
# MembershipSetting = MembershipSetting.find_by_id(1)
end

View File

@@ -46,7 +46,7 @@ class Menu < ApplicationRecord
end
end
def self.import(file, created_by)
def self.import(file, created_by,shop)
status = ""
spreadsheet = open_spreadsheet(file)
if spreadsheet.sheets.count > 1
@@ -61,9 +61,9 @@ class Menu < ApplicationRecord
# Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
account = Account.find_by_id(row["id"])
if account
Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"],shop_code: shop.shop_code)
else
Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"])
Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"],shop_code: shop.shop_code)
end
elsif sheet_name == "Item Set"
# ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty])
@@ -92,9 +92,9 @@ class Menu < ApplicationRecord
elsif sheet_name == "Menu"
menu = Menu.find_by_id(row["id"])
if menu
Menu.create(name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"])
Menu.create(name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"],shop_code: shop.shop_code)
else
Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"])
Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"],shop_code: shop.shop_code)
end
elsif sheet_name == "Menu Category"
# MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"])
@@ -141,19 +141,13 @@ class Menu < ApplicationRecord
end
else
# Menu by Menu Import
@shop = Shop.first
shop_code = ""
if !@shop.nil?
if @shop.shop_code
shop_code = @shop.shop_code + "_"
end
end
shop_code= shop.shop_code + "_"
sheet = spreadsheet.sheet(0)
menu = sheet.row(1)[1]
is_ordering = sheet.row(1)[3]?sheet.row(1)[3]:0
imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by})
imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by,shop_code: shop.shop_code})
(4..sheet.last_row).each do |ii|
row = Hash[[sheet.row(3),sheet.row(ii)].transpose]
@@ -192,7 +186,7 @@ class Menu < ApplicationRecord
if !menu_itm
account = Account.find_by_title(row["Account"])
if account.nil?
account = Account.create({title: row["Account"], account_type: "0"})
account = Account.create({title: row["Account"], account_type: "0",shop_code: shop.shop_code})
end
image_path = ""

View File

@@ -36,11 +36,13 @@ class Order < ApplicationRecord
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
:checkin_at => Time.now.utc,:checkout_at => Time.now.utc + self.extra_time.to_i,
:checkin_by => self.employee_name,
:booking_status => "assign" })
:booking_status => "assign",
:shop_code=>self.shop_code})
else
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
:checkin_at => Time.now.utc, :checkin_by => self.employee_name,
:booking_status => "assign" })
:booking_status => "assign",
:shop_code=>self.shop_code })
end
#end extra time
@@ -290,11 +292,11 @@ class Order < ApplicationRecord
#Process order items and send to order queue
def self.pay_process_order_queue(id,table_id)
# if ENV["SERVER_MODE"] != 'cloud'
sidekiq = Lookup.find_by_lookup_type("sidekiq")
order = Order.find(id)
sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",order.shop_code)
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(id, table_id)
else
order = Order.find(id)
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id)

View File

@@ -136,7 +136,7 @@ class OrderItem < ApplicationRecord
print instance_code
end
if self.qty != self.qty_before_last_save
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,instance_code)
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.order.shop_code)
if found
InventoryDefinition.check_balance(self, inventory_definition)
end

View File

@@ -16,7 +16,7 @@ class OrderQueueStation < ApplicationRecord
def process_order (order, table_id, order_source = nil, pdf_status = nil ,change_to=nil,current_user=nil)
oqs_stations = OrderQueueStation.active
oqs_stations = OrderQueueStation.active.where("shop_code='#{order.shop_code}'")
order_items = order.order_items
@@ -213,7 +213,7 @@ class OrderQueueStation < ApplicationRecord
#Print order_items in 1 slip
def print_slip(oqs, order, order_items ,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
if pdf_status.nil?
printer = PrintSetting.all.order("id ASC")
printer = PrintSetting.where("shop_code='#{oqs.shop_code}'").order("id ASC")
unique_code="OrderSummaryPdf"
if !printer.empty?
@@ -234,7 +234,7 @@ class OrderQueueStation < ApplicationRecord
end
end
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,oqs.shop_code)
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="")
else
@@ -249,7 +249,7 @@ class OrderQueueStation < ApplicationRecord
def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
if pdf_status.nil?
printer = PrintSetting.all.order("id ASC")
printer = PrintSetting.where("shop_code='#{oqs.shop_code}'").order("id ASC")
unique_code="OrderItemPdf"
if !printer.empty?
@@ -274,7 +274,7 @@ class OrderQueueStation < ApplicationRecord
# order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first()
# print when complete click
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,oqs.shop_code)
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
if !assigned_items.nil?
assigned_items.each do |order_item|
@@ -297,7 +297,7 @@ class OrderQueueStation < ApplicationRecord
@type = (DiningFacility.find(change_to)).type
@moved_by = current_user
@date = DateTime.now
@shop = Shop.first
@shop = Shop.find_by_shop_code(oqs.shop_code)
unique_code = "MoveTablePdf"
# pdf_no = PrintSetting.where(:unique_code => unique_code).count
print_settings = PrintSetting.find_by_unique_code(unique_code)

View File

@@ -157,7 +157,7 @@ class OrderReservation < ApplicationRecord
def self.update_doemal_payment(order,current_user,receipt_bill)
if(Sale.exists?(order.sale_id))
saleObj = Sale.find(order.sale_id)
shop_details = Shop.first
shop_details = Shop.find_by_shop_code(order.shop_code)
# rounding adjustment
if shop_details.is_rounding_adj
a = saleObj.grand_total % 25 # Modulus
@@ -194,7 +194,7 @@ class OrderReservation < ApplicationRecord
shift = ShiftSale.find(saleObj.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
shop_detail = Shop.first
# shop_detail = Shop.first
order_reservation = OrderReservation.get_order_reservation_info(saleObj.sale_id)
if !cashier_terminal.nil?
# Calculate Food and Beverage Total
@@ -203,7 +203,7 @@ class OrderReservation < ApplicationRecord
other_amount = SaleItem.calculate_other_charges(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,saleObj.sale_items,saleObj,saleObj.customer.name, item_price_by_accounts, discount_price_by_accounts, nil,nil,shop_detail, "Paid",nil,nil,other_amount,nil,nil, order_reservation)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,saleObj.sale_items,saleObj,saleObj.customer.name, item_price_by_accounts, discount_price_by_accounts, nil,nil,shop_details, "Paid",nil,nil,other_amount,nil,nil, order_reservation)
#receipt bill pdf setting
result = {:status=> true,

View File

@@ -7,7 +7,8 @@ class PaymentJournal < ApplicationRecord
self.payment_method = payment_method
self.payment_status = 'paid'
self.payment_method_references = payment_method_reference
self.created_by = current_user
self.created_by = current_user.id
self.shop_code = current_user.shop_code
self.save
end
@@ -16,7 +17,8 @@ class PaymentJournal < ApplicationRecord
self.remark = remark
self.debit_amount = amount
self.payment_status = 'paid'
self.created_by = current_user
self.created_by = current_user.id
self.shop_code = current_user.shop_code
self.save
end

View File

@@ -38,8 +38,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
# end
shop = Shop.first
directory_name = 'public/orders_'+shop.shop_code
# shop = Shop.first
directory_name = 'public/orders_'+oqs.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf"
@@ -80,8 +80,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
print_setting = PrintSetting.all.order("id ASC")
order=print_query('order_summary', order_id)
shop = Shop.first
directory_name = 'public/orders_'+shop.shop_code
# shop = Shop.first
directory_name = 'public/orders_'+oqs.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
# For Print Per Item
@@ -192,8 +192,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
order=print_query('booking_summary', booking_id)
shop = Shop.first
directory_name = 'public/orders_'+shop.shop_code
# shop = Shop.first
directory_name = 'public/orders_'+oqs.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
# For Print Per Item

View File

@@ -195,7 +195,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
if !printer_settings.nil?
if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder")
pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
settings = PrintSetting.all
settings = PrintSetting.where("shop_code='#{shop_details.shop_code}'")
if !settings.nil?
settings.each do |setting|
if setting.unique_code == 'ReceiptBillPdf'
@@ -206,7 +206,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
end
end
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
receipt_bill_a5_pdf = Lookup.where("shop_code='#{shop_details.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
if !receipt_bill_a5_pdf.empty?
receipt_bill_a5_pdf.each do |receipt_bilA5|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'

View File

@@ -33,9 +33,9 @@ class ProductCommission < ApplicationRecord
product_commission.save
end
def self.edit_product_commission(saleItemObj)
def self.edit_product_commission(saleItemObj,shop_code)
menu_item = MenuItem.find_by_item_code(saleItemObj.product_code)
commission = Commission.where('product_code = ? AND is_active = ?', menu_item.id, true).take
commission = Commission.where("shop_code='#{shop_code}' and product_code = ? AND is_active = ?", menu_item.id, true).take
product_commission = ProductCommission.where('sale_item_id = ?', saleItemObj.id).take
if !product_commission.nil?

View File

@@ -15,11 +15,11 @@ class Promotion < ApplicationRecord
promo_day.include? Date.today.wday.to_s
end
def self.promo_activate(saleObj)
def self.promo_activate(saleObj,shop_code)
current_day = Time.now.strftime("%Y-%m-%d")
current_time = Time.now.strftime('%H:%M:%S')
day = Date.today.wday
promoList = is_between_promo_datetime(current_day,current_time)
promoList = is_between_promo_datetime(current_day,current_time,shop_code)
promoList.each do |promo|
if promo.is_promo_day
@@ -30,8 +30,8 @@ class Promotion < ApplicationRecord
end
end
def self.is_between_promo_datetime(current_day,current_time) #database is not local time
promoList = Promotion.where("(Date_Format(promo_start_date, '%Y-%m-%d') <=? AND Date_Format(promo_end_date, '%Y-%m-%d') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time)
def self.is_between_promo_datetime(current_day,current_time,shop_code) #database is not local time
promoList = Promotion.where("shop_code='#{shop_code}' and (Date_Format(promo_start_date, '%Y-%m-%d') <=? AND Date_Format(promo_end_date, '%Y-%m-%d') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time)
return promoList
end

View File

@@ -29,7 +29,6 @@ class Sale < ApplicationRecord
scope :date_between, -> (from, to) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) }
scope :time_between, -> (from, to) { where("TIME(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) }
scope :along_with_sale_payments_except_void, -> { joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))") }
def qty_of(item_instance_code)
order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first
end
@@ -136,8 +135,8 @@ class Sale < ApplicationRecord
order = Order.find(order_id)
# current cashier login
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
current_shift = ShiftSale.current_shift
open_cashier = Employee.where("shop_code='#{order.shop_code}' and role = 'cashier' AND token_session <> ''")
current_shift = ShiftSale.current_shift(order.shop_code)
# shift with terminal zone
# set cashier
@@ -145,12 +144,12 @@ class Sale < ApplicationRecord
if !booking.dining_facility_id.nil?
table = DiningFacility.find(booking.dining_facility_id)
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
shift = ShiftSale.where("shop_code='#{order.shop_code}' and shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
#for multiple zone with terminal
if shift.nil?
multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}")
multiple_zone.each do |zone|
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
shift = ShiftSale.where("shop_code='#{order.shop_code}' and shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
if !shift.nil? then
break
end
@@ -158,7 +157,7 @@ class Sale < ApplicationRecord
end
end
else
shift = ShiftSale.current_open_shift(cashier.id)
shift = ShiftSale.current_open_shift(cashier)
end
# set cashier
if shift != nil #if current login employee open shift
@@ -170,7 +169,7 @@ class Sale < ApplicationRecord
# table and terminal in multiple shift
self.cashier_id = open_cashier[0].id
self.cashier_name = open_cashier[0].name
shift_id = ShiftSale.current_open_shift(open_cashier[0].id)
shift_id = ShiftSale.current_open_shift(open_cashier[0])
if shift_id
self.shift_sale_id = shift_id.id
else
@@ -188,7 +187,7 @@ class Sale < ApplicationRecord
self.requested_by = requested_by.name
self.requested_at = DateTime.now.utc.getlocal
self.shop_code = order.shop_code
Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}"
if order
self.customer_id = order.customer_id
@@ -234,15 +233,13 @@ class Sale < ApplicationRecord
#fOR Quick Service pay and create
def self.request_bill(order,current_user,current_login_employee)
if !ShiftSale.current_shift.nil?
if !ShiftSale.current_shift(order.shop_code).nil?
order_id = order.order_id # order_id
bk_order = BookingOrder.find_by_order_id(order_id)
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
if @sale_data = check_booking.sale
# Create Sale if it doesn't exist
# puts "current_login_employee"
# puts current_login_employee.name
@sale_items = SaleItem.where("sale_id=?",@sale_id)
elsif @sale_data = Sale.generate_invoice_from_booking(check_booking,current_login_employee,current_user,order.source)
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
@@ -253,7 +250,7 @@ class Sale < ApplicationRecord
# @sale_data.save
# Promotion Activation
Promotion.promo_activate(@sale_data)
Promotion.promo_activate(@sale_data,order.shop_code)
@status = true
return @status, @sale_data
else
@@ -438,7 +435,7 @@ class Sale < ApplicationRecord
#compute - invoice total
def compute_by_sale_items(total_discount, discount_type=nil, order_source=nil, tax_type=nil, type=nil)
shop = Shop.first
# shop = Shop.first
#Computation Fields
subtotal_price = 0
@@ -505,7 +502,7 @@ class Sale < ApplicationRecord
# Tax Re-Calculte
def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil)
shop = Shop.first
shop = Shop.find_by_shop_code(self.shop_code)
#if tax is not apply create new record
# SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax|
@@ -559,7 +556,7 @@ class Sale < ApplicationRecord
# Tax Calculate
def apply_tax(total_taxable, order_source = nil, tax_type = nil)
shop = Shop.first
shop = Shop.find_by_shop_code(self.shop_code)
#if tax is not apply create new record
# SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax|
@@ -639,7 +636,7 @@ class Sale < ApplicationRecord
end
def adjust_rounding
shop_details = Shop.first
shop_details = Shop.find_by_shop_code(self.shop_code)
# rounding adjustment
if shop_details.is_rounding_adj
new_total = Sale.get_rounding_adjustment(self.grand_total)
@@ -655,7 +652,7 @@ class Sale < ApplicationRecord
#Generate new Receipt No when it is not assigned
def generate_receipt_no
#shop_code and client_code
shop_details = Shop.first
shop_details = Shop.find_by_shop_code(self.shop_code)
#Date-Shift-
if self.receipt_no.nil?
prefix = DateTime.now().utc
@@ -1502,10 +1499,10 @@ end
return tax
end
def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type)
def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type,shop)
if (!from.nil? && !to.nil?) && (from != "" && to!="")
if current_user.nil?
query = Sale.top_bottom(today,nil,from,to,from_time,to_time)
query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time)
if type == "top"
query = query.group('i.product_name')
@@ -1516,7 +1513,7 @@ end
end
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.top_bottom(today,nil,from,to,from_time,to_time)
query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time)
if type == "top"
query = query.group('i.product_name')
.order("SUM(i.qty) DESC").limit(20)
@@ -1525,9 +1522,9 @@ end
.order("SUM(i.qty) ASC").limit(20)
end
else
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
query = Sale.top_bottom(today,shift,from,to,from_time,to_time)
query = Sale.top_bottom(shop,today,shift,from,to,from_time,to_time)
if type == "top"
query = query.group('i.product_name')
.order("SUM(i.qty) DESC").limit(20)
@@ -1540,7 +1537,7 @@ end
end
else
if current_user.nil?
query = Sale.top_bottom(today).group('i.product_name')
query = Sale.top_bottom(shop,today).group('i.product_name')
if type == "top"
query = query.order("SUM(i.qty) DESC").limit(20)
@@ -1549,16 +1546,16 @@ end
end
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.top_bottom(today).group('i.product_name')
query = Sale.top_bottom(shop,today).group('i.product_name')
if type == "top"
query = query.order("SUM(i.qty) DESC").limit(20)
elsif type == "bottom"
query = query.order("SUM(i.qty) ASC").limit(20)
end
else
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
query = Sale.top_bottom(today,shift).group('i.product_name')
query = Sale.top_bottom(shop,today,shift).group('i.product_name')
if type == "top"
query = query.order("SUM(i.qty) DESC").limit(20)
elsif type == "bottom"
@@ -1570,53 +1567,53 @@ end
end
end
def self.hourly_sales(today,current_user,from,to,from_time,to_time)
def self.hourly_sales(today,current_user,from,to,from_time,to_time,shop)
if (!from.nil? && !to.nil?) && (from != "" && to!="")
if current_user.nil?
query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time)
query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time)
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time)
query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time)
else
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
query = Sale.hourly_sale_data(today,shift,from,to,from_time,to_time)
query = Sale.hourly_sale_data(shop,today,shift,from,to,from_time,to_time)
end
end
end
else
if current_user.nil?
query = Sale.hourly_sale_data(today)
query = Sale.hourly_sale_data(shop,today)
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.hourly_sale_data(today)
query = Sale.hourly_sale_data(shop,today)
else
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
query = Sale.hourly_sale_data(today,shift)
query = Sale.hourly_sale_data(shop,today,shift)
end
end
end
end
end
def self.employee_sales(today,current_user,from,to,from_time,to_time)
def self.employee_sales(today,current_user,from,to,from_time,to_time,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.id)
ShiftSale.current_open_shift(current_user)
end
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
query = employee_sale(today, shift, from, to, from_time, to_time)
query = employee_sale(shop,today, shift, from, to, from_time, to_time)
.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'
ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name")
end
def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count")
.where('sale_status = "completed"')
.where("sale_status = 'completed' AND shop_code='#{shop.shop_code}'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
@@ -1627,16 +1624,16 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
return query
end
def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.where('sales.sale_status = "completed" and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")')
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and (sp.payment_method = 'mpu' or sp.payment_method = 'visa' or sp.payment_method = 'master' or sp.payment_method = 'jcb' or sp.payment_method = 'unionpay' or sp.payment_method = 'alipay' or sp.payment_method = 'paymal' or sp.payment_method = 'dinga' or sp.payment_method = 'JunctionPay')")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -1646,20 +1643,20 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query = query.sum("sp.payment_amount")
end
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,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 = ?", 'creditnote', 'completed')
.where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',shop.shop_code)
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.merge(Sale.date_between(from, to))
@@ -1670,7 +1667,7 @@ end
query = query.merge(Sale.date_on(today))
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1678,9 +1675,9 @@ end
return query.sum("sale_payments.payment_amount - IFNULL(payments_for_credits.payment_amount, 0)")
end
def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.summary_sale_receipt(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
.where('sale_status = "completed"')
.where("shop_code='#{shop.shop_code}' and sale_status = 'completed'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -1690,16 +1687,16 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query = query.first()
end
def self.total_payment_methods(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.total_payment_methods(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("distinct sp.payment_method")
.where('sales.sale_status = "completed"')
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed'")
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
@@ -1710,19 +1707,20 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
return query
end
def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.payment_sale(shop,payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
query = Sale.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")
.joins(:sale_payments)
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
.where("sales.shop_code='#{shop.shop_code}'")
.completed
if payment_method == 'card'
@@ -1741,15 +1739,15 @@ end
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query.first
end
def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
total_dinein_takeaway = self.total_dinein_takeaway(today,current_user,from,to,from_time,to_time)
def self.total_customer(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
total_dinein_takeaway = self.total_dinein_takeaway(shop,today,current_user,from,to,from_time,to_time)
dinein_cnt = 0
takeaway_cnt = 0
if !total_dinein_takeaway.nil?
@@ -1758,7 +1756,7 @@ end
takeaway_cnt = total_dinein_takeaway[0].total_take_cus
end
end
membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time)
membership_cnt = self.total_membership(shop,today,current_user,from,to,from_time,to_time)
member_cnt = 0
if !membership_cnt.nil?
member_cnt = membership_cnt.total_memb_cus
@@ -1771,10 +1769,10 @@ end
return total_cus, dinein_cnt, takeaway_cnt, member_cnt
end
def self.total_dinein_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.total_dinein_takeaway(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and c.membership_id is null')
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and c.membership_id is null")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -1784,17 +1782,17 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query = query.first()
end
def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.total_membership(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))')
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and ((c.customer_type = 'Dinein' and c.membership_id is not null) or (c.customer_type = 'Takeaway' and c.membership_id is not null))")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -1804,7 +1802,7 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1857,9 +1855,10 @@ end
# query = query.first()
# end
def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.total_order(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("count(distinct sale_orders.order_id) as total_order")
.joins(:sale_orders)
.where("shop_code='#{shop.shop_code}'")
.completed
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
@@ -1871,7 +1870,7 @@ end
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1879,11 +1878,11 @@ end
query = query.first
end
def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.total_account(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("distinct b.id as account_id, b.title as title")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.joins("JOIN accounts as b ON b.id = a.account_id")
.where('sales.sale_status = "completed"')
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -1893,17 +1892,17 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
return query
end
def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.account_data(shop,account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}'")
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and a.account_id ='#{account_id}'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -1913,17 +1912,17 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query = query.first
end
def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.top_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'")
.where("sales.shop_code='#{shop.shop_code}' and (a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -1933,7 +1932,7 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1942,9 +1941,9 @@ end
.first()
end
def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.total_foc_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'")
.where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -1954,7 +1953,7 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -2016,13 +2015,13 @@ end
query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","#{type}")
.group("bookings.booking_id")
end
def self.completed_sale(type)
def self.completed_sale(type,shop_code)
if type == "cashier"
type = "and orders.source = 'emenu' or orders.source = 'cashier'"
else
type = "and orders.source = '#{type}'"
end
query = Sale.all
query = Sale.where("sales.shop_code='#{shop_code}'")
query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id")
.joins("join orders as orders on orders.order_id = sale_orders.order_id")
query = query.where("sales.sale_status != 'new' AND orders.status = 'billed' #{type}")
@@ -2085,8 +2084,7 @@ def self.get_sale_data_for_other_payment_credit(sale_id)
end
def unique_tax_profiles(order_source, customer_id)
tax_data = TaxProfile
.where(group_type: order_source)
tax_data = TaxProfile.where(group_type: order_source,shop_code: self.shop_code)
customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first
if customer_tax_profiles.present?
@@ -2096,7 +2094,7 @@ def unique_tax_profiles(order_source, customer_id)
return tax_data
end
def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.top_bottom(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
" i.price as unit_price,i.product_name")
@@ -2105,7 +2103,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
" and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'")
else
query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
query = query.where("shop_code='#{shop.shop_code}' and (i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+
" and sale_status= 'completed'")
end
if !shift.nil?
@@ -2115,7 +2113,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
" i.price as unit_price,i.product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
.where("shop_code='#{shop.shop_code}' and (i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
" and sale_status= 'completed'")
if !shift.nil?
query = query.where("shift_sale_id='#{shift.id}'")
@@ -2124,7 +2122,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
return query
end
def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.hourly_sale_data(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
query = Sale.select("grand_total")
if !from_time.nil? && !to_time.nil?
@@ -2135,11 +2133,11 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=
if !shift.nil?
query = query.where("shift_sale_id='#{shift.id}'")
end
query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
query = query.where("shop_code='#{shop.shop_code}'").group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
.order('receipt_date')
else
query = Sale.select("grand_total")
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
.where("shop_code='#{shop.shop_code}' and sale_status = 'completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = ?",today)
if !shift.nil?
query = query.where("shift_sale_id='#{shift.id}'")
end
@@ -2150,10 +2148,10 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=
return query
end
def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.employee_sale(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.joins(:cashier)
.joins(:sale_payments)
.paid.completed
.paid.completed.where("sales.shop_code='#{shop.shop_code}'")
if !from.nil? && !to.nil?
query = query.date_between(from, to)
if !from_time.nil? && !to_time.nil?
@@ -2474,7 +2472,7 @@ private
def update_stock_journal
if self.sale_status == "void" && self.sale_status_before_last_save != "void"
self.sale_items.each do |item|
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item)
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code)
if found
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
unless stock.nil?
@@ -2487,7 +2485,7 @@ private
end
elsif self.sale_status == "waste" || self.sale_status == "spoile" || (self.payment_status == "foc" && self.payment_status_was != "foc")
self.bookings.first.order_items.each do |item|
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item)
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code)
if found
if stock_journal = StockJournal.find_by_trans_ref(item.order_items_id)
stock_journal.update(remark: self.sale_status)

View File

@@ -311,11 +311,11 @@ class SaleItem < ApplicationRecord
cancel_foc = self.status_before_last_save == "foc"
if is_void or cancel_void or is_edit or is_foc or cancel_foc
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.sale.shop_code)
if found
stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first
stock = StockJournal.where("shop_code='#{self.sale.shop_code}' and item_code=?", self.item_instance_code).order("id DESC").first
unless stock.nil?
check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first
check_item = StockCheckItem.where("shop_code='#{self.sale.shop_code}' and item_code=?", self.item_instance_code).order("id DESC").first
if is_void or cancel_void or is_edit
if is_void
qty = -self.qty

View File

@@ -34,9 +34,9 @@ class SalePayment < ApplicationRecord
end
end
def self.get_kbz_pay_amount(sale_id, current_user)
def self.get_kbz_pay_amount(sale_id, current_user,shop)
amount = 0
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => shop.shop_code).last
sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last
if !sale_payment.nil? and !kbz_pay_method.nil?
if sale_payment.payment_status == 'pending'
@@ -136,11 +136,12 @@ class SalePayment < ApplicationRecord
#record an payment in sale-audit
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}"
if payment_for
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
current_shift_user =Employee.find_by_id(self.sale.cashier_id)
shift = ShiftSale.current_open_shift(current_shift_user)
if !shift.nil?
shift_sale_id = shift.id
else
shift = ShiftSale.current_shift
shift = ShiftSale.current_shift(self.sale.shop_code)
shift_sale_id = shift.id
end
@@ -726,11 +727,12 @@ class SalePayment < ApplicationRecord
# update for cashier shift
def update_shift
shift = ShiftSale.current_open_shift(self.action_by.id)
current_shift_user = Employee.find_by_id(self.action_by.id)
shift = ShiftSale.current_open_shift(current_shift_user)
if shift.nil?
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
current_shift_user = Employee.find_by_id(self.sale.cashier_id)
shift = ShiftSale.current_open_shift(current_shift_user)
end
if !shift.nil?
@@ -740,7 +742,7 @@ class SalePayment < ApplicationRecord
self.sale.cashier_name = Employee.find(shift.employee_id).name
self.sale.save
else
shift = ShiftSale.current_shift
shift = ShiftSale.current_shift(self.sale.shop_code)
shift.update(self.sale)
self.sale.shift_sale_id = shift.id
self.sale.cashier_id = shift.employee_id
@@ -972,7 +974,7 @@ class SalePayment < ApplicationRecord
end
#credit payment query
def self.get_credit_sales(params)
def self.get_credit_sales(params,shop_code)
receipt_no = ""
customer = ""
if !params["receipt_no"].blank?
@@ -1001,7 +1003,7 @@ class SalePayment < ApplicationRecord
else
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
end
query = query.group("s.receipt_no")
query = query.where("s.shop_code='#{shop_code}'").group("s.receipt_no")
.order("s.receipt_date ASC, s.receipt_no ASC")
return query
end

View File

@@ -16,10 +16,11 @@ class ShiftSale < ApplicationRecord
belongs_to :cashier_terminal
belongs_to :employee, :foreign_key => 'employee_id'
has_many :sales
belongs_to :shop
def self.current_shift
def self.current_shift(shop_code)
# today_date = DateTime.now.strftime("%Y-%m-%d")
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first
shift = ShiftSale.where("shop_code='#{shop_code}' and shift_started_at is not null and shift_closed_at is null").first
return shift
end
@@ -28,7 +29,7 @@ class ShiftSale < ApplicationRecord
#find open shift where is open today and is not closed and login by current cashier
#DATE(shift_started_at)=? and
today_date = DateTime.now.strftime("%Y-%m-%d")
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take
shift = ShiftSale.where("shop_code='#{current_user.shop_code}' and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user.id}").take
return shift
#end
end

View File

@@ -3,7 +3,6 @@ class Shop < ApplicationRecord
# Shop Image Uploader
mount_uploader :logo, ShopImageUploader
has_many :display_images
accepts_nested_attributes_for :display_images

View File

@@ -1,11 +1,12 @@
class StockCheck < ApplicationRecord
has_many :stock_check_items
def create(user, reason, item_list)
def create(user, reason, item_list,shop)
self.reason = reason
self.check_by = user.id
self.check_start = Time.now
self.check_end = Time.now
self.shop_code = shop.shop_code
save
item_list.each do |item|
stockItem = StockCheckItem.new

View File

@@ -67,7 +67,7 @@ class StockCheckItem < ApplicationRecord
return query
end
def self.delete_stock_check_item(item_code)
self.where("item_code=?", item_code).delete_all
def self.delete_stock_check_item(item_code,shop)
self.where("item_code=? and shop_code='#{shop.shop_code}'", item_code).delete_all
end
end

Some files were not shown because too many files have changed in this diff Show More