Merge branch 'foodcourt' of gitlab.com:code2lab/SXRestaurant into foodcourt
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
class Api::ApiController < ActionController::API
|
class Api::ApiController < ActionController::API
|
||||||
|
|
||||||
|
|
||||||
|
include MultiTenancy
|
||||||
include TokenVerification
|
include TokenVerification
|
||||||
include ActionView::Rendering
|
|
||||||
include ActionController::MimeResponds
|
include ActionController::MimeResponds
|
||||||
|
include ActionView::Rendering
|
||||||
|
|
||||||
before_action :core_allow
|
before_action :core_allow
|
||||||
helper_method :current_token, :current_login_employee, :get_cashier
|
helper_method :current_token, :current_login_employee, :get_cashier
|
||||||
@@ -15,6 +18,12 @@ class Api::ApiController < ActionController::API
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# ActionView::Rendering override render_to_body breaks render :json,
|
||||||
|
# resulting in an ActionView::MissingTemplate error.
|
||||||
|
def render_to_body(options)
|
||||||
|
_render_to_body_with_renderer(options) || super
|
||||||
|
end
|
||||||
|
|
||||||
#this is base api base controller to need to inherit.
|
#this is base api base controller to need to inherit.
|
||||||
#all token authentication must be done here
|
#all token authentication must be done here
|
||||||
#response format must be set to JSON
|
#response format must be set to JSON
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ class Api::OrdersController < Api::ApiController
|
|||||||
def create
|
def create
|
||||||
Rails.logger.debug "Order Source - " + params[:order_source].to_s
|
Rails.logger.debug "Order Source - " + params[:order_source].to_s
|
||||||
Rails.logger.debug "Table ID - " + params[:table_id].to_s
|
Rails.logger.debug "Table ID - " + params[:table_id].to_s
|
||||||
@shop = Shop.find_by_shop_code(params[:shop_code])
|
# @shop = Shop.find_by_shop_code(params[:shop_code])
|
||||||
current_shift = ShiftSale.current_shift(@shop.shop_code)
|
current_shift = ShiftSale.current_shift
|
||||||
if current_shift.nil?
|
if current_shift.nil?
|
||||||
@status = false
|
@status = false
|
||||||
@message = "No Current Open Shift for This Employee"
|
@message = "No Current Open Shift for This Employee"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
include LoginVerification, MultiTenancy
|
include MultiTenancy
|
||||||
|
include LoginVerification
|
||||||
|
|
||||||
#before_action :check_installation
|
#before_action :check_installation
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
@@ -17,5 +18,4 @@ class ApplicationController < ActionController::Base
|
|||||||
flash[:warning] = exception.message
|
flash[:warning] = exception.message
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
class BaseCrmController < ActionController::Base
|
class BaseCrmController < ActionController::Base
|
||||||
include LoginVerification, MultiTenancy
|
|
||||||
|
|
||||||
|
include MultiTenancy
|
||||||
|
include LoginVerification
|
||||||
layout "CRM"
|
layout "CRM"
|
||||||
|
|
||||||
before_action :check_user
|
before_action :check_user
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
class BaseInventoryController < ActionController::Base
|
class BaseInventoryController < ActionController::Base
|
||||||
include LoginVerification, MultiTenancy
|
|
||||||
|
include MultiTenancy
|
||||||
|
include LoginVerification
|
||||||
layout "inventory"
|
layout "inventory"
|
||||||
|
|
||||||
before_action :check_user
|
before_action :check_user
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
class BaseOqsController < ActionController::Base
|
class BaseOqsController < ActionController::Base
|
||||||
include LoginVerification, MultiTenancy
|
|
||||||
|
include MultiTenancy
|
||||||
|
include LoginVerification
|
||||||
|
|
||||||
layout "OQS"
|
layout "OQS"
|
||||||
|
|
||||||
before_action :check_user
|
before_action :check_user
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
class BaseOrigamiController < ActionController::Base
|
class BaseOrigamiController < ActionController::Base
|
||||||
include LoginVerification, MultiTenancy
|
|
||||||
|
include MultiTenancy
|
||||||
|
include LoginVerification
|
||||||
layout "origami"
|
layout "origami"
|
||||||
|
|
||||||
before_action :check_user
|
before_action :check_user
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
class BaseReportController < ActionController::Base
|
class BaseReportController < ActionController::Base
|
||||||
include LoginVerification, MultiTenancy
|
|
||||||
|
include MultiTenancy
|
||||||
|
include LoginVerification
|
||||||
layout "application"
|
layout "application"
|
||||||
|
|
||||||
before_action :check_user
|
before_action :check_user
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
class BaseWaiterController < ActionController::Base
|
class BaseWaiterController < ActionController::Base
|
||||||
include LoginVerification, MultiTenancy
|
|
||||||
|
include MultiTenancy
|
||||||
|
include LoginVerification
|
||||||
layout "waiter"
|
layout "waiter"
|
||||||
|
|
||||||
before_action :check_user
|
before_action :check_user
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController
|
|||||||
.joins("JOIN orders ON orders.order_id=booking_orders.order_id")
|
.joins("JOIN orders ON orders.order_id=booking_orders.order_id")
|
||||||
.joins("JOIN order_items ON orders.order_id=order_items.order_id")
|
.joins("JOIN order_items ON orders.order_id=order_items.order_id")
|
||||||
.joins("JOIN customers ON orders.customer_id=customers.customer_id")
|
.joins("JOIN customers ON orders.customer_id=customers.customer_id")
|
||||||
.where("orders.source='app' and bookings.shop_code='#{@shop.shop_code}'").order("bookings.created_at desc").uniq
|
.where("orders.source='app'").order("bookings.created_at desc").uniq
|
||||||
end
|
end
|
||||||
def completed
|
def completed
|
||||||
customer =Customer.find_by_customer_id(params[:customer_id])
|
customer =Customer.find_by_customer_id(params[:customer_id])
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class Foodcourt::VoidController < BaseFoodcourtController
|
|||||||
# FOr Sale Audit
|
# FOr Sale Audit
|
||||||
action_by = current_user.name
|
action_by = current_user.name
|
||||||
if access_code != "null" && current_user.role == "cashier"
|
if access_code != "null" && current_user.role == "cashier"
|
||||||
action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_code).name
|
action_by = Employee.find_by_emp_id_and_shop_code(access_code,Shop.current_shop.shop_code).name
|
||||||
end
|
end
|
||||||
|
|
||||||
# remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
|
# remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
|
||||||
@@ -116,7 +116,7 @@ class Foodcourt::VoidController < BaseFoodcourtController
|
|||||||
customer= Customer.find(sale.customer_id)
|
customer= Customer.find(sale.customer_id)
|
||||||
|
|
||||||
# get member information
|
# get member information
|
||||||
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
|
rebate = MembershipSetting.find_by_rebate(1)
|
||||||
if customer.membership_id != nil && rebate
|
if customer.membership_id != nil && rebate
|
||||||
member_info = Customer.get_member_account(customer)
|
member_info = Customer.get_member_account(customer)
|
||||||
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
|
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
|
||||||
@@ -124,7 +124,7 @@ class Foodcourt::VoidController < BaseFoodcourtController
|
|||||||
current_balance = 0
|
current_balance = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
printer = PrintSetting.where("shop_code='#{@shop.shop_code}'")
|
printer = PrintSetting.where("shop_code='#{Shop.current_shop.shop_code}'")
|
||||||
|
|
||||||
unique_code="ReceiptBillPdf"
|
unique_code="ReceiptBillPdf"
|
||||||
if !printer.empty?
|
if !printer.empty?
|
||||||
@@ -139,13 +139,13 @@ class Foodcourt::VoidController < BaseFoodcourtController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
# get printer info
|
# get printer info
|
||||||
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
|
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,Shop.current_shop.shop_code)
|
||||||
# Calculate Food and Beverage Total
|
# Calculate Food and Beverage Total
|
||||||
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
|
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)
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
|
||||||
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
|
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
|
||||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
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, "VOID",current_balance,nil,other_amount,nil,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.current_shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil)
|
||||||
result = {
|
result = {
|
||||||
:filepath => filename,
|
:filepath => filename,
|
||||||
:printer_model => print_settings.brand_name,
|
:printer_model => print_settings.brand_name,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
if check_mobile
|
if check_mobile
|
||||||
@webview = true
|
@webview = true
|
||||||
end
|
end
|
||||||
|
@shop = Shop.current_shop
|
||||||
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id")
|
@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")
|
@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_table = Table.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc')
|
||||||
@@ -19,6 +19,7 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
if check_mobile
|
if check_mobile
|
||||||
@webview = true
|
@webview = true
|
||||||
end
|
end
|
||||||
|
@shop = Shop.current_shop
|
||||||
display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code)
|
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
|
if !display_type.nil? && display_type.value.to_i ==2
|
||||||
@display_type = display_type.value
|
@display_type = display_type.value
|
||||||
@@ -224,7 +225,7 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
def process_order_queue(order_id,table_id,order_source)
|
def process_order_queue(order_id,table_id,order_source)
|
||||||
print_status = nil
|
print_status = nil
|
||||||
cup_status = nil
|
cup_status = nil
|
||||||
|
@shop = Shop.current_shop
|
||||||
#Send to background job for processing
|
#Send to background job for processing
|
||||||
order = Order.find(order_id)
|
order = Order.find(order_id)
|
||||||
sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",@shop.shop_code)
|
sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",@shop.shop_code)
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ class Origami::HomeController < BaseOrigamiController
|
|||||||
def index
|
def index
|
||||||
@webview = check_mobile
|
@webview = check_mobile
|
||||||
|
|
||||||
@tables = Table.unscope(:order).all.active.order('status desc')
|
|
||||||
@rooms = Room.unscope(:order).all.active.order('status desc')
|
@tables = Table.unscope(:order).includes(:zone).all.active.order('status desc')
|
||||||
|
@rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc')
|
||||||
@complete = Sale.completed_sale("cashier")
|
@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')
|
@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')
|
||||||
|
|
||||||
@@ -22,8 +23,9 @@ class Origami::HomeController < BaseOrigamiController
|
|||||||
@print_settings = PrintSetting.get_precision_delimiter()
|
@print_settings = PrintSetting.get_precision_delimiter()
|
||||||
@webview = check_mobile
|
@webview = check_mobile
|
||||||
|
|
||||||
@tables = Table.unscope(:order).all.active.order('status desc')
|
|
||||||
@rooms = Room.unscope(:order).all.active.order('status desc')
|
@tables = Table.unscope(:order).includes(:zone).all.active.order('status desc')
|
||||||
|
@rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc')
|
||||||
@complete = Sale.completed_sale("cashier")
|
@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')
|
@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')
|
||||||
|
|
||||||
|
|||||||
@@ -176,14 +176,14 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
|
|
||||||
# For Cashier by Zone
|
# For Cashier by Zone
|
||||||
# bookings = Booking.where("sale_id='#{sale_id}'")
|
# bookings = Booking.where("sale_id='#{sale_id}'")
|
||||||
bookings = Booking.find_by_sale_id(sale_id)
|
bookings = saleObj.bookings[0]
|
||||||
|
|
||||||
shift = ShiftSale.current_open_shift(current_user)
|
shift = ShiftSale.current_open_shift(current_user)
|
||||||
if !shift.nil?
|
if !shift.nil?
|
||||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||||
else
|
else
|
||||||
if bookings.dining_facility_id.to_i > 0
|
if bookings.dining_facility_id.to_i > 0
|
||||||
table = DiningFacility.find(bookings.dining_facility_id)
|
table = bookings.dining_facility
|
||||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||||
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
||||||
|
|
||||||
|
|||||||
@@ -32,50 +32,27 @@ class DiningFacility < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_current_booking
|
def get_current_booking
|
||||||
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
|
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||||
if booking.count > 0 then
|
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null
|
||||||
return booking[0]
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_moved_booking
|
def get_moved_booking
|
||||||
checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code)
|
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||||
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)
|
Booking.where(dining_facility_id: self.id, booking_status: 'moved', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
|
||||||
|
|
||||||
if booking.count > 0 then
|
|
||||||
return booking[0]
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_new_booking
|
def get_new_booking
|
||||||
# query for new
|
# query for new
|
||||||
# if status
|
Booking.where(dining_facility_id: self.id, booking_status: 'assign', sale_id: nil, checkout_at: nil).first
|
||||||
# to ask when req bill booking_status?
|
|
||||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1)
|
|
||||||
# else
|
|
||||||
# booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1)
|
|
||||||
# end
|
|
||||||
|
|
||||||
if booking.count > 0 then
|
|
||||||
return booking[0].booking_id
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_current_checkout_booking
|
def get_current_checkout_booking
|
||||||
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)
|
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||||
if booking.count > 0 then
|
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
|
||||||
return booking[0]
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_checkout_booking
|
def get_checkout_booking
|
||||||
@@ -117,8 +94,10 @@ class DiningFacility < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.get_checkin_booking
|
def self.get_checkin_booking
|
||||||
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")
|
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||||
|
bookings = Booking.where(booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago)
|
||||||
|
|
||||||
arr_booking = Array.new
|
arr_booking = Array.new
|
||||||
if bookings
|
if bookings
|
||||||
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")
|
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ class Lookup < ApplicationRecord
|
|||||||
|
|
||||||
scope :number_formats, -> { where(lookup_type: 'number_format')}
|
scope :number_formats, -> { where(lookup_type: 'number_format')}
|
||||||
|
|
||||||
|
TIME_LIMIT = 5
|
||||||
|
|
||||||
def available_types
|
def available_types
|
||||||
{'Employee Roles' => 'employee_roles',
|
{'Employee Roles' => 'employee_roles',
|
||||||
'Dining Facilities Status' => 'dining_facilities_status',
|
'Dining Facilities Status' => 'dining_facilities_status',
|
||||||
@@ -24,15 +26,15 @@ class Lookup < ApplicationRecord
|
|||||||
# Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] }
|
# Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] }
|
||||||
# end
|
# end
|
||||||
|
|
||||||
def self.get_checkin_time_limit(shop_code)
|
|
||||||
time_limit = 5
|
|
||||||
|
|
||||||
lookup = Lookup.find_by_lookup_type_and_shop_code('checkin_time_limit',shop_code)
|
def self.time_limit
|
||||||
if !lookup.nil?
|
TIME_LIMIT
|
||||||
time_limit = lookup.value.to_i
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return time_limit
|
|
||||||
|
def self.get_checkin_time_limit
|
||||||
|
return RequestStore[:checkin_time_limit] if RequestStore[:checkin_time_limit]
|
||||||
|
RequestStore[:checkin_time_limit] = Lookup.find_by_lookup_type('checkin_time_limit').value.to_i rescue time_limit
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sync_url
|
def self.sync_url
|
||||||
@@ -59,7 +61,6 @@ class Lookup < ApplicationRecord
|
|||||||
|
|
||||||
def self.collection_of(type)
|
def self.collection_of(type)
|
||||||
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] }
|
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_shift_sale_lookup(shop_code)
|
def self.create_shift_sale_lookup(shop_code)
|
||||||
|
|||||||
@@ -140,8 +140,8 @@ class Sale < ApplicationRecord
|
|||||||
order = Order.find(order_id)
|
order = Order.find(order_id)
|
||||||
|
|
||||||
# current cashier login
|
# current cashier login
|
||||||
open_cashier = Employee.where("shop_code='#{order.shop_code}' and role = 'cashier' AND token_session <> ''")
|
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
||||||
current_shift = ShiftSale.current_shift(order.shop_code)
|
current_shift = ShiftSale.current_shift
|
||||||
# shift with terminal zone
|
# shift with terminal zone
|
||||||
|
|
||||||
# set cashier
|
# set cashier
|
||||||
@@ -238,7 +238,7 @@ class Sale < ApplicationRecord
|
|||||||
|
|
||||||
#fOR Quick Service pay and create
|
#fOR Quick Service pay and create
|
||||||
def self.request_bill(order,current_user,current_login_employee)
|
def self.request_bill(order,current_user,current_login_employee)
|
||||||
if !ShiftSale.current_shift(order.shop_code).nil?
|
if !ShiftSale.current_shift.nil?
|
||||||
order_id = order.order_id # order_id
|
order_id = order.order_id # order_id
|
||||||
bk_order = BookingOrder.find_by_order_id(order_id)
|
bk_order = BookingOrder.find_by_order_id(order_id)
|
||||||
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
|
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
|
||||||
@@ -2057,17 +2057,17 @@ end
|
|||||||
query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","#{type}")
|
query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","#{type}")
|
||||||
.group("bookings.booking_id")
|
.group("bookings.booking_id")
|
||||||
end
|
end
|
||||||
def self.completed_sale(type,shop_code)
|
def self.completed_sale(type)
|
||||||
if type == "cashier"
|
if type == "cashier"
|
||||||
type = "and orders.source = 'emenu' or orders.source = 'cashier'"
|
type = "and orders.source = 'emenu' or orders.source = 'cashier'"
|
||||||
else
|
else
|
||||||
type = "and orders.source = '#{type}'"
|
type = "and orders.source = '#{type}'"
|
||||||
end
|
end
|
||||||
query = Sale.where("sales.shop_code='#{shop_code}'")
|
query = Sale.where("sales.shop_code='#{Shop.current_shop.shop_code}'")
|
||||||
query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id")
|
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")
|
.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}")
|
query = query.where("sales.sale_status != 'new' AND orders.status = 'billed' #{type}")
|
||||||
query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? ",DateTime.now.strftime('%Y-%m-%d'))
|
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
|
||||||
.group("sales.sale_id")
|
.group("sales.sale_id")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2456,7 +2456,7 @@ private
|
|||||||
def update_stock_journal
|
def update_stock_journal
|
||||||
if self.sale_status == "void" && self.sale_status_before_last_save != "void"
|
if self.sale_status == "void" && self.sale_status_before_last_save != "void"
|
||||||
self.sale_items.each do |item|
|
self.sale_items.each do |item|
|
||||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code)
|
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item)
|
||||||
if found
|
if found
|
||||||
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
|
stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first
|
||||||
unless stock.nil?
|
unless stock.nil?
|
||||||
@@ -2469,7 +2469,7 @@ private
|
|||||||
end
|
end
|
||||||
elsif self.sale_status == "waste" || self.sale_status == "spoile" || (self.payment_status == "foc" && self.payment_status_was != "foc")
|
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|
|
self.bookings.first.order_items.each do |item|
|
||||||
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code)
|
found, inventory_definition = InventoryDefinition.find_product_in_inventory(item)
|
||||||
if found
|
if found
|
||||||
if stock_journal = StockJournal.find_by_trans_ref(item.order_items_id)
|
if stock_journal = StockJournal.find_by_trans_ref(item.order_items_id)
|
||||||
if self.payment_status == "foc" && self.payment_status_was != "foc"
|
if self.payment_status == "foc" && self.payment_status_was != "foc"
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class SalePayment < ApplicationRecord
|
|||||||
amount_due = amount_due - payment.payment_amount
|
amount_due = amount_due - payment.payment_amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (amount_due >= 0)
|
if (amount_due > 0)
|
||||||
payment_status = false
|
payment_status = false
|
||||||
membership_data = nil
|
membership_data = nil
|
||||||
#route to payment type
|
#route to payment type
|
||||||
@@ -777,27 +777,14 @@ class SalePayment < ApplicationRecord
|
|||||||
def table_update_status(sale_obj)
|
def table_update_status(sale_obj)
|
||||||
status = true
|
status = true
|
||||||
sale_count = 0
|
sale_count = 0
|
||||||
booking = Booking.find_by_sale_id(sale_obj.id)
|
if booking = sale_obj.bookings[0]
|
||||||
if booking
|
|
||||||
if booking.dining_facility_id.to_i > 0
|
if booking.dining_facility_id.to_i > 0
|
||||||
table = DiningFacility.find(booking.dining_facility_id)
|
table = booking.dining_facility
|
||||||
bookings = table.bookings
|
if Booking.left_joins(:sale).where(dining_facility_id: booking.dining_facility_id).where.not(booking_status: 'moved').where("sales.sale_status NOT IN ('completed', 'void', 'spoile', 'waste') OR sales.sale_status IS NULL").exists?
|
||||||
bookings.each do |tablebooking|
|
status = false
|
||||||
if tablebooking.booking_status != 'moved'
|
|
||||||
if tablebooking.sale_id
|
|
||||||
if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste'
|
|
||||||
status = false
|
|
||||||
sale_count += 1
|
|
||||||
else
|
|
||||||
status = true
|
|
||||||
end
|
|
||||||
else
|
|
||||||
status = false
|
|
||||||
sale_count += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if status && sale_count == 0
|
|
||||||
|
if status
|
||||||
table.update_attributes(status: "available")
|
table.update_attributes(status: "available")
|
||||||
# table.status = "available"
|
# table.status = "available"
|
||||||
# table.save
|
# table.save
|
||||||
@@ -969,38 +956,34 @@ class SalePayment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
#credit payment query
|
#credit payment query
|
||||||
def self.get_credit_sales(params,shop_code)
|
|
||||||
receipt_no = ""
|
def self.get_credit_sales(params)
|
||||||
customer = ""
|
payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount")
|
||||||
if !params["receipt_no"].blank?
|
.select("SUM(sale_payments.payment_amount) OVER (PARTITION BY sale_payments.sale_id) total_payment_amount")
|
||||||
receipt_no = " and s.receipt_no LIKE '%#{params["receipt_no"]}%'"
|
|
||||||
|
credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name")
|
||||||
|
.select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name")
|
||||||
|
.joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders)
|
||||||
|
.completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount")
|
||||||
|
.group(:receipt_no)
|
||||||
|
.order(:receipt_date).order(:receipt_no)
|
||||||
|
|
||||||
|
if params["receipt_no"].present?
|
||||||
|
credit_sales = credit_sales.where("sales.receipt_no LIKE ?", "%#{params["receipt_no"]}%")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if !params["customer_id"].blank?
|
if params["customer_id"].present?
|
||||||
customer = " and s.customer_id = '#{params["customer_id"]}'"
|
credit_sales = credit_sales.where("sales.customer_id = ?", params["customer_id"])
|
||||||
end
|
end
|
||||||
|
|
||||||
order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=s.sale_id GROUP BY so.sale_id)"
|
if params[:type].present?
|
||||||
|
sources = []
|
||||||
query = SalePayment.select("s.receipt_no, sale_payments.sale_payment_id,
|
sources << params[:type]
|
||||||
sale_payments.payment_method,
|
sources << 'emenu' if params[:type] == 'cashier'
|
||||||
SUM(sale_payments.payment_amount) as payment_amount,
|
credit_sales = credit_sales.where("orders.source IN (?)", sources)
|
||||||
s.receipt_date as sale_date,
|
|
||||||
s.sale_id,
|
|
||||||
s.cashier_name as cashier_name, c.name as customer_name")
|
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
|
||||||
.joins("INNER JOIN customers c ON c.customer_id = s.customer_id")
|
|
||||||
|
|
||||||
if params[:type].nil?
|
|
||||||
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' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
|
|
||||||
elsif params[:type] == "cashier"
|
|
||||||
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]}' OR #{order_source_query}='emenu' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
|
|
||||||
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
|
end
|
||||||
query = query.where("s.shop_code='#{shop_code}'").group("s.receipt_no")
|
|
||||||
.order("s.receipt_date ASC, s.receipt_no ASC")
|
|
||||||
return query
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_credit_amount_due_left(sale_id)
|
def self.get_credit_amount_due_left(sale_id)
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ class ShiftSale < ApplicationRecord
|
|||||||
belongs_to :employee, :foreign_key => 'employee_id'
|
belongs_to :employee, :foreign_key => 'employee_id'
|
||||||
has_many :sales
|
has_many :sales
|
||||||
|
|
||||||
def self.current_shift(shop_code)
|
def self.current_shift
|
||||||
# today_date = DateTime.now.strftime("%Y-%m-%d")
|
# today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||||
shift = ShiftSale.where("shop_code='#{shop_code}' and shift_started_at is not null and shift_closed_at is null").first
|
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first
|
||||||
return shift
|
return shift
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user