merge with r-19

This commit is contained in:
NyanLinHtut
2020-01-11 11:08:33 +06:30
106 changed files with 2722 additions and 3024 deletions

View File

@@ -1,10 +1,9 @@
class Api::ApiController < ActionController::API
include MultiTenancy
include TokenVerification
include ActionController::MimeResponds
include ActionView::Rendering
include Customers
before_action :core_allow
helper_method :current_token, :current_login_employee, :get_cashier

View File

@@ -10,7 +10,7 @@ class Api::BillController < Api::ApiController
if !ShiftSale.current_shift.nil?
#create Bill by Booking ID
table = 0
if (params[:booking_id])
if params[:booking_id].present?
booking = Booking.find(params[:booking_id])
if booking.booking_orders.count > 0
if booking.checkin_at.utc.strftime("%Y-%m-%d %H:%M") > Time.now.utc.strftime("%Y-%m-%d %H:%M") && booking.checkout_at.nil?
@@ -52,13 +52,6 @@ class Api::BillController < Api::ApiController
@status = false
@error_message = "There is no order for '#{params[:booking_id]}'"
end
# elsif (params[:order_id])
# order = Order.find(params[:order_id])
# @status, @sale_id = Sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier, order.source)
#
# # for Job
# booking = Booking.find_by_sale_id(@sale_id)
# table = DiningFacility.find(booking.dining_facility_id)
end
# Bind shift sale id to sale
@@ -148,7 +141,7 @@ class Api::BillController < Api::ApiController
@order = Order.new
@order.source = "cashier"
@order.order_type = "Takeaway"
@order.customer_id = "CUS-000000000002" # for no customer id from mobile
@order.customer_id = takeaway.customer_id # for no customer id from mobile
@order.items = params[:order_items]
@order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id

View File

@@ -1,8 +1,8 @@
class Api::CheckInProcessController < Api::ApiController
# before_action :authenticate
def check_in_time
if params[:dining_id]
dining_facility = DiningFacility.find(params[:dining_id])
if params[:dining_id]
dining_facility = DiningFacility.find(params[:dining_id])
if params[:booking_id]
data = Booking.where("dining_facility_id = #{params[:dining_id]} AND booking_id = '#{params[:booking_id]}'")
if data.count > 0
@@ -10,7 +10,7 @@ class Api::CheckInProcessController < Api::ApiController
else
booking = nil
end
else
else
booking = dining_facility.get_current_booking
end
if !booking.nil?
@@ -21,7 +21,7 @@ class Api::CheckInProcessController < Api::ApiController
#Send to background job for processing
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
else
from = ""
end
ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
@@ -37,7 +37,7 @@ class Api::CheckInProcessController < Api::ApiController
end
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
if !lookup_checkout_time.empty?
now = Time.now.utc
lookup_checkout_time.each do |checkout_time|
@@ -52,16 +52,18 @@ class Api::CheckInProcessController < Api::ApiController
else
render :json => { :status => true }
end
else
else
render :json => { :status => false, :error_message => "No current booking!" }
end
else
render :json => { :status => false }
end
end
def check_in_process
if params[:dining_id]
dining_facility = DiningFacility.find(params[:dining_id])
dining_facility = DiningFacility.find(params[:dining_id])
if dining_facility.is_active && dining_facility.status == "available"
if params[:checkin_time]
checkin_at = nil
@@ -75,7 +77,7 @@ class Api::CheckInProcessController < Api::ApiController
if dining_facility.check_time(checkin_at, "checkin")
booking = dining_facility.get_current_booking
if booking.nil?
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
:checkin_by=>current_login_employee.name,:checkin_at => checkin_at,:checkout_at =>nil, :booking_status => "assign", :reserved_at => nil, :reserved_by => nil })
if booking.save!
@@ -95,10 +97,10 @@ class Api::CheckInProcessController < Api::ApiController
render :json => { :status => false, :error_message => "Operation failed!" }
end
else
booking = dining_facility.get_current_checkout_booking
booking = dining_facility.current_checkout_booking
if booking.nil?
lookup_checkout_time = Lookup.collection_of("checkout_time")
if !lookup_checkout_time.empty?
today = Time.now.utc.getlocal
checkout_at = Time.now.utc.getlocal
@@ -118,7 +120,7 @@ class Api::CheckInProcessController < Api::ApiController
# else
# type = "RoomBooking"
# end
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
:checkin_by=>current_login_employee.name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => current_login_employee.name })
if booking.save!
@@ -133,13 +135,13 @@ class Api::CheckInProcessController < Api::ApiController
unique_code = "CheckInOutPdf"
printer = PrintSetting.find_by_unique_code(unique_code)
# print when complete click
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil?
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility)
end
end
end
render :json => { :status => true, :booking_id => booking.booking_id, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
else
render :json => { :status => true }
@@ -176,7 +178,7 @@ class Api::CheckInProcessController < Api::ApiController
booking.save!
render :json => { :status => true, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
elsif !params[:booking_id].nil? && params[:time].nil?
elsif !params[:booking_id].nil? && params[:time].nil?
error_message = "time is required!"
render :json => { :status => false, :error_message => error_message }
elsif params[:booking_id].nil? && !params[:time].nil?

View File

@@ -71,15 +71,10 @@ class Api::OrdersController < Api::ApiController
current_user =Employee.find(current_shift.employee_id)
if checkin_checkout_time(params[:booking_id])
if params[:booking_id].present?
booking = Booking.find(params[:booking_id])
end
if params[:table_id].present?
if booking.nil? || booking.dining_facility_id.to_i != params[:table_id].to_i
table = DiningFacility.find(params[:table_id])
booking = table.get_current_booking
end
end
table = DiningFacility.find(params[:table_id]) if params[:table_id].present?
booking = table.current_checkin_booking if table
booking ||= Booking.find(params[:booking_id]) if params[:booking_id].present?
#for extratime
is_extra_time = false
@@ -102,14 +97,14 @@ class Api::OrdersController < Api::ApiController
@order = Order.new
@order.source = params[:order_source]
@order.order_type = params[:order_type]
@order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
@order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
@order.items = params[:order_items]
@order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id
@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
@@ -122,8 +117,9 @@ class Api::OrdersController < Api::ApiController
end
@status, @booking = @order.generate
if params[:order_source] != "app"
@order.process_order_queue(@order.order_id,@order.table_id,@order.source)
if @status && @booking
Order.process_order_queue(@order.order_id,@order.table_id,@order.source)
end
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
@@ -131,11 +127,12 @@ class Api::OrdersController < Api::ApiController
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end
if current_user.role != "waiter" && params[:create_type] == "create_pay"
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') || (@order.source == 'app')
@status, @sale = Sale.request_bill(@order,current_user,current_user)
end
end
# # for parallel order
# remoteIP = ""
# begin
# @status, @booking = @order.generate
# remoteIP = request.remote_ip
# end while request.remote_ip != remoteIP
else
return return_json_status_with_code(406, "Checkout time is over!")
end
@@ -198,7 +195,7 @@ class Api::OrdersController < Api::ApiController
#checked checkin and checkout time
def checkin_checkout_time(booking_id)
status = true
if !booking_id.nil?
if booking_id.present?
if booking = Booking.find(booking_id)
if booking.checkout_at.present?
if booking.checkout_at.utc <= Time.now.utc

View File

@@ -8,8 +8,8 @@ class Api::Restaurant::MenuController < Api::ApiController
param_checksum = params[:checksum]
# checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp
shop_code = params[:shop_code]
all_menu = Menu.where('shop_code=?',shop_code).active.all
all_menu = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
@request_url = ''
if ENV["SERVER_MODE"] == "cloud"
@request_url = request.base_url
@@ -17,10 +17,7 @@ class Api::Restaurant::MenuController < Api::ApiController
# to hash
menu_array = []
all_menu.each do |m|
menu_array.push(m.to_json(:include => {:menu_categories =>
{ :include => { :menu_items =>
{ :include => [:menu_item_sets, :menu_item_instances =>
{ :include => :menu_instance_item_sets}]} } }}))
menu_array.push(m.to_json(:include => { :menu_categories => { :include => { :menu_items => { :include => [ :item_sets, :menu_item_instances => { :include => :menu_instance_item_sets } ] } } } } ))
end
#export Checksum file generate by md5
@@ -29,6 +26,10 @@ class Api::Restaurant::MenuController < Api::ApiController
if menu_checksum != param_checksum
response.headers['CHECKSUM'] = menu_checksum
@menus = all_menu
@item_attributes = MenuItemAttribute.all.load
@item_options = MenuItemOption.all.load
else
render :json => nil
end
# @current_menu = Menu.current_menu
end

View File

@@ -2,8 +2,8 @@ class Api::Restaurant::ZonesController < Api::ApiController
def index
if (params[:filter] && params[:filter] = "all" )
@all_tables = Table.active
@all_rooms = Room.active
@all_tables = Table.includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active
@all_rooms = Room.includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active
else
@zones = Zone.includes([:tables, :rooms]).where("is_active = true")
end

View File

@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
include MultiTenancy
include LoginVerification
include Customers
#before_action :check_installation
protect_from_forgery with: :exception

View File

@@ -1,6 +1,4 @@
class BaseCrmController < ActionController::Base
include MultiTenancy
include LoginVerification
layout "CRM"

View File

@@ -1,5 +1,4 @@
class BaseInventoryController < ActionController::Base
include MultiTenancy
include LoginVerification
layout "inventory"

View File

@@ -1,8 +1,7 @@
class BaseOqsController < ActionController::Base
include MultiTenancy
include LoginVerification
layout "OQS"
before_action :check_user

View File

@@ -1,7 +1,8 @@
class BaseOrigamiController < ActionController::Base
include MultiTenancy
include LoginVerification
include Customers
layout "origami"
before_action :check_user

View File

@@ -1,5 +1,4 @@
class BaseReportController < ActionController::Base
include MultiTenancy
include LoginVerification
layout "application"
@@ -34,6 +33,7 @@ class BaseReportController < ActionController::Base
if params[:from].present? && params[:to].present?
from = Time.parse(params[:from])
to = Time.parse(params[:to])
else
case period.to_i
when PERIOD["today"]

View File

@@ -1,5 +1,4 @@
class BaseWaiterController < ActionController::Base
include MultiTenancy
include LoginVerification
layout "waiter"

View File

@@ -0,0 +1,18 @@
module Customers
extend ActiveSupport::Concern
included do
helper_method :walkin, :takeaway if respond_to? :helper_method
end
def walkin
return @walkin if defined? @walkin
@walkin = Customer.walkin
end
def takeaway
return @takeaway if defined? @takeaway
@takeaway = Customer.takeaway
end
end

View File

@@ -4,7 +4,6 @@ module MultiTenancy
included do
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
before_action :find_shop_by_subdomain_or_frist if respond_to? :before_action
helper_method :current_shop if respond_to? :helper_method
end
private

View File

@@ -8,7 +8,7 @@ module NumberFormattable
@precision = @number_formats.find? { |x| x.name.parameterize.underscore == 'precision'}.value.to_i rescue nil
end
if @precision.nil?
@print_settings = PrintSetting.get_precision_delimiter if !defined? @number_formats
@print_settings = PrintSetting.get_precision_delimiter if !defined? @print_settings
if @print_settings
@precision = @print_settings.precision.to_i
else
@@ -24,7 +24,7 @@ module NumberFormattable
@delimiter = @number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'}.value.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") } rescue nil
end
if @delimiter.nil?
@print_settings = PrintSetting.get_precision_delimiter if !defined? @number_formats
@print_settings = PrintSetting.get_precision_delimiter if !defined? @print_settings
if @print_settings && @print_settings.delimiter
@delimiter = ","
else
@@ -42,10 +42,10 @@ module NumberFormattable
end
def number_format(number, options = {})
options[:precision] = options[:precision] || precision
options[:precision] = options[:precision] || precision
# options[:delimiter] = options[:delimiter] || delimiter
options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros
number = number.to_f.round(options[:precision])
if options[:precision] > 0

View File

@@ -83,8 +83,9 @@ class Crm::CustomersController < BaseCrmController
@membership_types = Lookup.collection_of("member_group_type")
# @taxes = TaxProfile.where(:group_type => 'cashier')
@taxes = TaxProfile.unscope(:order).select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name")
.order("group_type ASC,order_by ASC")
@taxes = TaxProfile.unscope(:order).select("tax_profiles.id, CONCAT(tax_profiles.name, '(', lookups.name, ')') as name")
.joins(:lookup)
.order("group_type ASC, order_by ASC")
@filter = filter
@@ -147,104 +148,101 @@ class Crm::CustomersController < BaseCrmController
def new
@crm_customer = Customer.new
@membership = Customer.get_member_group()
end
# GET /crm/customers/1/edit
def edit
@customer = Customer.find(params[:id])
end
def sync
@customer = Customer.find(params[:id])
respond_to do |format|
name = @customer.name
phone = @customer.contact_no
email = @customer.email
dob = @customer.date_of_birth
address = @customer.address
nrc = @customer.nrc_no
card_no = @customer.card_no
paypar_account_no = @customer.paypar_account_no
id = @crm_customer.membership_id
member_group_id = @customer.membership_type
if !id.present? && !member_group_id.nil?
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
merchant_uid = memberaction.merchant_account_id.to_s
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
respond_to do |format|
name = @customer.name
phone = @customer.contact_no
email = @customer.email
dob = @customer.date_of_birth
address = @customer.address
nrc = @customer.nrc_no
card_no = @customer.card_no
paypar_account_no = @customer.paypar_account_no
id = @customer.membership_id
member_group_id = @customer.membership_type
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
merchant_uid = memberaction.merchant_account_id.to_s
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
member_params = { name: name,phone: phone,email: email,
dob: dob,address: address,nrc:nrc,card_no:card_no,
member_group_id: member_group_id,
id:id,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
member_params = { name: name,phone: phone,email: email,
dob: dob,address: address,nrc:nrc,card_no:card_no,
member_group_id: member_group_id,
id:id,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
# Check for paypar account exists
# if paypar_account_no != nil || paypar_account_no != ''
if paypar_account_no.present?
member_params = { name: name,phone: phone,email: email,
dob: dob,address: address,nrc:nrc,card_no:card_no,
paypar_account_no: paypar_account_no,
member_group_id: member_group_id,
id:id,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
# Check for paypar account exists
# if paypar_account_no != nil || paypar_account_no != ''
if paypar_account_no.present?
member_params = { name: name,phone: phone,email: email,
dob: dob,address: address,nrc:nrc,card_no:card_no,
paypar_account_no: paypar_account_no,
member_group_id: member_group_id,
id:id,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
end
begin
response = HTTParty.post(url,
:body => member_params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10
)
begin
response = HTTParty.post(url,
:body => member_params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10
)
rescue HTTParty::Error
response = {"status" => false, "message" => "No internet connection "}
rescue HTTParty::Error
response = {"status" => false, "message" => "No internet connection "}
rescue Net::OpenTimeout
response = {"status" => false, "message" => "No internet connection "}
rescue Net::OpenTimeout
response = {"status" => false, "message" => "No internet connection "}
rescue OpenURI::HTTPError
response = {"status" => false, "message" => "No internet connection "}
rescue OpenURI::HTTPError
response = {"status" => false, "message" => "No internet connection "}
rescue SocketError
response = {"status" => false, "message" => "No internet connection "}
end
customer = Customer.find(@crm_customer.customer_id)
Rails.logger.debug "--------Sync Member response -------"
Rails.logger.debug response.to_json
if response["status"] == true
status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
# Check membership id and bind to user
if response["membership_id"] != nil
status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
status = customer.update_attributes(membership_type:member_group_id)
end
# When paypar account no not exist in paypar
if response["message"] == "Account does not exist."
customer.destroy
format.html { redirect_to crm_customers_path }
flash[:member_error] ='Member cannot created.Invalid Account.'
else
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
end
rescue SocketError
response = {"status" => false, "message" => "No internet connection "}
end
customer = Customer.find(@crm_customer.customer_id)
Rails.logger.debug "--------Sync Member response -------"
Rails.logger.debug response.to_json
if response["status"] == true
status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
# Check membership id and bind to user
if response["membership_id"] != nil
status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
status = customer.update_attributes(membership_type:member_group_id)
end
# When paypar account no not exist in paypar
if response["message"] == "Account does not exist."
customer.destroy
format.html { redirect_to crm_customers_path }
flash[:member_error] ='Member cannot created.Invalid Account.'
else
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
end
end
end
# POST /crm/customers
# POST /crm/customers.json

View File

@@ -30,7 +30,7 @@ class Foodcourt::FoodCourtController < ApplicationController
else
@display_type = nil
end
@quick_service_only = true
lookup_dine_in = Lookup.collection_of('dinein_cashier')
if !lookup_dine_in.empty?
@@ -47,7 +47,7 @@ class Foodcourt::FoodCourtController < ApplicationController
.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 customers ON orders.customer_id=customers.customer_id")
.where("orders.source='app' and bookings.shop_code='#{@shop.shop_code}' and DATE(bookings.created_at) = '#{Date.today}' and bookings.booking_status='assign'").uniq.length
.where("orders.source='app' and DATE(bookings.created_at) = '#{Date.today}' and bookings.booking_status='assign'").uniq.length
render "foodcourt/addorders/detail"
end

View File

@@ -71,7 +71,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController
.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 customers ON orders.customer_id=customers.customer_id")
.where("sales.sale_status !=? and orders.source='app' and bookings.shop_code=? and DATE(bookings.created_at)=?",'void',@shop.shop_code,Date.today).order("bookings.created_at desc").uniq
.where("sales.sale_status !=? and orders.source='app' and DATE(bookings.created_at)=?",'void',@shop.shop_code,Date.today).order("bookings.created_at desc").uniq
end
def completed
customer =Customer.find_by_customer_id(params[:customer_id])

View File

@@ -86,10 +86,10 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
def destroy
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_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_by_id_and_shop_code(params[:id],@shop.shop_code)
StockJournal.delete_stock_journal(inventory.item_code,@shop)

View File

@@ -21,7 +21,7 @@ class Oqs::HomeController < BaseOqsController
zone_id = qid.zone_id
i=i+1
end
end
end
end
@queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i })
end
@@ -57,14 +57,6 @@ class Oqs::HomeController < BaseOqsController
end
end
# booking_id = dining.get_new_booking
# BookingOrder.where("booking_id='#{ booking_id }'").find_each do |bo|
# order=Order.find(bo.order_id);
# order.order_items.each do |oi|
# items.push(oi)
# end
# end
render :json => items.to_json
end
@@ -88,7 +80,7 @@ class Oqs::HomeController < BaseOqsController
end
# Query for OQS with delivery status
def queue_items_query(status)
def queue_items_query(status)
AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at")
.joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id

View File

@@ -6,10 +6,11 @@ class Origami::AddordersController < BaseOrigamiController
if check_mobile
@webview = true
end
@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')
@tables = Table.active.order('zone_id asc').group("zone_id")
@rooms = Room.active.order('zone_id asc').group("zone_id")
@all_table = Table.active.order('status desc')
@all_room = Room.active.order('status desc')
end
def detail
@@ -33,10 +34,11 @@ class Origami::AddordersController < BaseOrigamiController
@booking = @table.get_booking
if @booking
@booking_id = @booking.booking_id
@obj_order = @booking.orders.first
@customer = @obj_order.customer
@date = @obj_order.created_at
@order_items = @booking.order_items
if @obj_order = @booking.orders.first
@customer = @obj_order.customer
@date = @obj_order.created_at
@order_items = @booking.order_items
end
end
end
@@ -98,87 +100,85 @@ class Origami::AddordersController < BaseOrigamiController
items_arr = []
JSON.parse(params[:order_items]).each { |i|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
if i["item_instance_code"].include? "ext"
is_extra_time = true
arr_exts = i["item_instance_code"].split("_")
if arr_exts[1].match(/^(\d)+$/)
if i["item_instance_code"].include? "ext"
is_extra_time = true
arr_exts = i["item_instance_code"].split("_")
if arr_exts[1].match(/^(\d)+$/)
time = arr_exts[1].to_i*60*i["quantity"].to_i
extra_time = Time.at(time)
end
end
if i["parent_order_item_id"];
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
else
end
end
if i["parent_order_item_id"]
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
else
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
end
items_arr.push(items)
}
end
items_arr.push(items)
}
# begin
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
customer_id = "CUS-000000000002" # for no customer id from mobile
customer_id = takeaway.customer_id # for no customer id from mobile
else
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
end
@order = Order.new
@order.source = params[:order_source]
@order.order_type = params[:order_type]
@order.customer_id = customer_id
@order.items = items_arr
@order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id
@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
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
Order.transaction do
@order = Order.new
@order.source = params[:order_source]
@order.order_type = params[:order_type]
@order.customer_id = customer_id
@order.items = items_arr
@order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id
@order.new_booking = true
else
@order.new_booking = false
@order.booking_id = booking.booking_id
end
@order.waiters = current_login_employee.name
@order.employee_name = current_login_employee.name
@status, @booking = @order.generate
if @status && @booking
#send order broadcast to order_channel
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
@order.is_extra_time = is_extra_time
@order.extra_time = extra_time
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
@order.new_booking = true
else
@order.new_booking = false
@order.booking_id = booking.booking_id
end
if params[:order_source] != "quick_service" && params[:order_source] != "food_court"
process_order_queue(@order.order_id,@order.table_id,@order.source)
end
end
@status, @booking = @order.generate
if @status && @booking
#send order broadcast to order_channel
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel", table: table,type:type,from:from
end
if params[:order_source] != "quick_service" && params[:order_source] != "food_court"
process_order_queue(@order.order_id,@order.table_id,@order.source)
end
end
# Order.send_customer_view(@booking)
if current_user.role != "waiter" && params[:create_type] == "create_pay"
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
if current_user.role != "waiter" && params[:create_type] == "create_pay"
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
# for second display
if @order.source == 'quick_service'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from
# for second display
if @order.source == 'quick_service'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from
end
#end
result = {:status=> @status, :data => @sale }
render :json => result.to_json
end
#end
result = {:status=> @status, :data => @sale }
else
result = {:status=> @status, :data => 0 }
render :json => result.to_json
end
else
result = {:status=> @status, :data => 0 }
render :json => result.to_json
end
end
# render json for http status code
@@ -220,66 +220,29 @@ class Origami::AddordersController < BaseOrigamiController
end
end
def process_order_queue(order_id,table_id,order_source)
print_status = nil
cup_status = nil
#Send to background job for processing
order = Order.find(order_id)
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)
def process_order_queue(order_id, table_id, order_source)
#Send to background job for processing
order = Order.find(order_id)
sidekiq = Lookup.find_by_lookup_type("sidekiq")
if ENV["SERVER_MODE"] != 'cloud'
if Printer::PrinterWorker.printers.blank?
msg = 'Print Error ! Please contact to service'
ActionCable.server.broadcast "call_waiter_channel", table: msg, time:'print_error', from: ''
end
end
if print_status
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
if ENV["SERVER_MODE"] != 'cloud'
cup_start = `#{"sudo service cups start"}`
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
end
if print_status
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
if ENV["SERVER_MODE"] != 'cloud'
from = ""
msg = ' Print Error ! Please contact to service'
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error',from:from
end
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
from = getCloudDomain #get sub domain in cloud mode
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
end
end
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
from = getCloudDomain #get sub domain in cloud mode
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
ActionCable.server.broadcast "order_queue_station_channel", order: assign_order, from: from
end
end
def check_cup_status(status)

View File

@@ -55,7 +55,7 @@ class Origami::CustomersController < BaseOrigamiController
@cashier_type = params[:type]
@page = params[:dir_page]
if(@sale_id[0,3] == "SAL")
if @sale_id.include? "SAL"
@booking = Booking.find_by_sale_id(@sale_id)
if @booking.dining_facility_id.to_i > 0
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
@@ -117,7 +117,7 @@ class Origami::CustomersController < BaseOrigamiController
def update_sale_by_customer
id = params[:sale_id][0,3]
id = params[:sale_id]
customer_id = params[:customer_id]
customer = Customer.find(customer_id)
order_source = params[:type]
@@ -129,7 +129,7 @@ class Origami::CustomersController < BaseOrigamiController
# end
# end
if(id == "SAL")
if id.include? "SAL"
sale = Sale.find(params[:sale_id])
status = sale.update_attributes(customer_id: customer_id)
sale.sale_orders.each do |sale_order|
@@ -153,7 +153,7 @@ class Origami::CustomersController < BaseOrigamiController
if status == true
render json: JSON.generate({:status => true})
if(id == "SAL")
if id.include? "SAL"
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
end
else

View File

@@ -104,9 +104,7 @@ class Origami::DashboardController < BaseOrigamiController
end
def get_all_menu
@menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.shop
@menus = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
@item_attributes = MenuItemAttribute.all.load
@item_options = MenuItemOption.all.load
end

View File

@@ -22,7 +22,6 @@ class Origami::FoodCourtController < ApplicationController
@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 = "food_court"
display_type = Lookup.find_by_lookup_type("display_type")
if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
@@ -57,7 +56,7 @@ class Origami::FoodCourtController < ApplicationController
# @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end
if(params[:id][0,3] == "BKI")
if params[:id].include? "BKI"
@table_id = nil
@table = nil
@booking = Booking.find(params[:id])
@@ -114,7 +113,7 @@ class Origami::FoodCourtController < ApplicationController
order = Order.new
order.source = params[:order_source]
order.order_type = params[:order_type]
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
order.items = items_arr
order.guest = params[:guest_info]
order.table_id = params[:table_id] # this is dining facilities's id

View File

@@ -4,10 +4,8 @@ class Origami::HomeController < BaseOrigamiController
def index
@webview = check_mobile
@tables = Table.unscope(:order).includes(:zone).shop.active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone).shop.active.order('status desc')
@tables = Table.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).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')
@@ -23,9 +21,8 @@ class Origami::HomeController < BaseOrigamiController
@print_settings = PrintSetting.get_precision_delimiter()
@webview = check_mobile
@tables = Table.unscope(:order).includes(:zone).shop.active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone).shop.active.order('status desc')
@tables = Table.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).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')
@@ -36,77 +33,44 @@ class Origami::HomeController < BaseOrigamiController
@status_sale = ""
@sale_array = Array.new
@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
@shop = shop_detail
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all
@dining_booking = @dining.current_bookings
@order_items = Array.new
@dining_booking.each do |booking|
if booking.sale_id.nil? && booking.booking_status != 'moved'
@order_items = Array.new
# @assigned_order_items = Array.new
if booking.booking_orders.empty?
@booking = booking
else
booking.booking_orders.each do |booking_order|
order = Order.find(booking_order.order_id)
if (order.status == "new")
@obj_order = order
@customer = order.customer
@date = order.created_at
@booking= booking
order.order_items.each do |item|
@order_items.push(item)
# assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id)
# if !assigned_order_items.nil?
# @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id})
# end
end
@account_arr = Array.new
if @customer.tax_profiles
accounts = @customer.tax_profiles
@account_arr =[]
accounts.each do |acc|
account = TaxProfile.find_by_id(acc)
if !account.nil?
@account_arr.push(account)
end
end
end
end
end
end
@status_order = 'order'
else
sale = Sale.find(booking.sale_id)
if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste'
@sale_array.push(sale)
if @status_order == 'order'
@status_order = 'sale'
end
@booking= booking
@date = sale.created_at
@status_sale = 'sale'
@obj_sale = sale
@customer = sale.customer
accounts = @customer.tax_profiles
@account_arr =[]
accounts.each do |acc|
account = TaxProfile.find_by_id(acc)
if !account.nil?
@account_arr.push(account)
end
end
end
@sale_taxes = []
sale_taxes = SaleTax.where("sale_id = ?", sale.sale_id)
if !sale_taxes.empty?
sale_taxes.each do |sale_tax|
@sale_taxes.push(sale_tax)
end
end
if @obj_sale || @booking.blank?
@booking = booking
end
if booking.sale_id
@obj_sale = booking.sale
@sale_array.push(@obj_sale)
@sale_taxes = @obj_sale.sale_taxes
@status_sale = 'sale'
else
@order_items += booking.order_items
@obj_order = booking.orders.first
end
if @obj_sale || @customer.blank?
if obj = @obj_sale || @obj_order
@customer = obj.customer
@date = obj.created_at
end
end
end
if @obj_sale
@status_order = 'sale'
else
@status_order = 'order'
end
if (@obj_sale || @account_arr.blank?) && @customer
@account_arr = TaxProfile.find_by(id: @customer.tax_profiles)
end
end
#for bank integration
@checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time')

View File

@@ -1,9 +1,8 @@
class Origami::HomeController < ApplicationController
def index
if params[:booking_id] != nil
type=params[:booking_id].split('-')[0];
# Sale
if type == "SAL"
if params[:booking_id].include? "SAL"
@selected_item = Sale.find(params[:booking_id])
@selected_item_type="Sale"
# Booking
@@ -25,9 +24,8 @@ class Origami::HomeController < ApplicationController
def selection(selected_id, is_ajax)
str = []
type=selected_id.split('-')[0];
# Sale
if type == "SAL"
if selected_id.include? "SAL"
@order_details = SaleItem.get_order_items_details(params[:booking_id])
@order_details.each do |ord_detail|
str.push(ord_detail)
@@ -48,9 +46,7 @@ class Origami::HomeController < ApplicationController
end
def update_sale_by_customer
id = params[:sale_id][0,3]
if(id == "SAL")
if id.inlude? "SAL"
sale = Sale.find(params[:sale_id])
else
sale = Order.find(params[:sale_id])

View File

@@ -10,121 +10,73 @@ class Origami::PaymentsController < BaseOrigamiController
member_info = nil
# For Cashier by Zone
booking = Booking.find_by_sale_id(sale_id)
# if bookings.count > 1
# # for Multiple Booking
# table = DiningFacility.find(bookings[0].dining_facility_id)
# else
# table = DiningFacility.find(bookings[0].dining_facility_id)
# end
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
if booking.dining_facility_id.to_i > 0
table = DiningFacility.find(booking.dining_facility_id)
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
else
shift = ShiftSale.find(sale_data.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
booking = sale_data.booking
if current_user.role == 'cashier'
cashier_terminal = current_user.cashier_terminal
elsif booking.dining_facility
cashier_terminal = booking.cashier_terminal_by_dining_facility
end
cashier_terminal ||= sale_data.cashier_terminal_by_shift_sale
customer = sale_data.customer
#record for sale audit
action_by = current_user.name
type = "FIRST_BILL"
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)
if customer.membership_id != nil && rebate
# member_info = Customer.get_member_account(customer)
# current_balance = SaleAudit.paymal_search(sale_id)
current_balance = 0
end
# find order id by sale id
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
print_settings = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first
printer = Printer::ReceiptPrinter.new(print_settings)
#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
status = false
qr = nil
if !kbz_pay_method.nil?
if kbz_pay_method.is_active == true
sale_payment = SalePayment.new
sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending')
status, qr = KbzPay.pay(sale_data.grand_total.to_i, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
end
end
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
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
if !print_settings.nil?
print_settings.each do |setting|
if setting.unique_code == 'ReceiptBillPdf'
unique_code = "ReceiptBillPdf"
elsif setting.unique_code == 'ReceiptBillStarPdf'
unique_code = "ReceiptBillStarPdf"
end
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)
if !receipt_bill_a5_pdf.empty?
receipt_bill_a5_pdf.each do |receipt_bilA5|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
if receipt_bilA5[1] == '1'
unique_code = "ReceiptBillA5Pdf"
else
unique_code = unique_code#{}"ReceiptBillPdf"
end
end
end
end
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
#shop detail
## shop_detail = @shop
# customer= Customer.where('customer_id=' +.customer_id)
customer = Customer.find(sale_data.customer_id)
# rounding adjustment
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
end
#end rounding adjustment
#record for sale audit
action_by = current_user.name
type = "FIRST_BILL"
# status, qr = KbzPay.query(sale_payment.sale_payment_id)
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_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_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)
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
#TODO :: KBZPAY ( QR )
# On/Off setting ( show or not qr )
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => @shop.shop_code).last
status = false
qr = nil
if !kbz_pay_method.nil?
if kbz_pay_method.is_active == true
sale_payment = SalePayment.new
sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending')
status, qr = KbzPay.pay(sale_data.grand_total.to_i, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
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, "Frt",current_balance,nil,other_amount,nil,nil,nil,nil)
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# status, qr = KbzPay.query(sale_payment.sale_payment_id)
# Mobile Print
render :json => result.to_json
# Mobile Print
render :json => result.to_json
# end
end
@@ -138,25 +90,9 @@ class Origami::PaymentsController < BaseOrigamiController
latest_order_no = nil
is_kbz = params[:is_kbz]
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
if saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id)
#shop_detail = @shop
# rounding adjustment
if !path.include? ("credit_payment")
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
end
end
#end rounding adjustment
# if pay_from = 'kbzpay'
# salePayment = SalePayment.find(sale_payment_id)
# salePayment.process_kbz_payment(salePayment.sale_id, sale_data.grand_total, cash, 'paid')
# else
sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last
if is_kbz == 'false'
Rails.logger.info '################ CASH PAYMENT #################'
sale_payment = SalePayment.new
@@ -166,134 +102,110 @@ class Origami::PaymentsController < BaseOrigamiController
sale_payment.process_payment(saleObj, current_user, cash, "cash")
end
else
sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
end
# end
if !path.include? ("credit_payment")
rebate_amount = nil
# For Cashier by Zone
# bookings = Booking.where("sale_id='#{sale_id}'")
bookings = saleObj.bookings[0]
booking = saleObj.booking
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
if bookings.dining_facility_id.to_i > 0
table = bookings.dining_facility
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
if current_user.role == 'cashier'
cashier_terminal = current_user.cashier_terminal
elsif booking.dining_facility
cashier_terminal = booking.cashier_terminal_by_dining_facility
end
type = 'payment'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
else
shift = ShiftSale.find(saleObj.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
end
cashier_terminal ||= saleObj.cashier_terminal_by_shift_sale
if booking.dining_facility
ActionCable.server.broadcast(
"order_channel",
table: booking.dining_facility,
type: 'payment',
from: getCloudDomain
)
end
# For Print
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
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?
print_settings.each do |setting|
if setting.unique_code == 'ReceiptBillPdf'
unique_code = "ReceiptBillPdf"
elsif setting.unique_code == 'ReceiptBillStarPdf'
unique_code = "ReceiptBillStarPdf"
end
end
if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf
unique_code = "ReceiptBillA5Pdf"
else
unique_code = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code
end
customer = saleObj.customer
# get member information
rebate = MembershipSetting.find_by_rebate(1)
credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
if customer.membership_id != nil && rebate && credit_data.nil?
member_info = Customer.get_member_account(customer)
if member_info["status"] == true
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
current_balance = SaleAudit.paymal_search(sale_id)
end
end
#orders print out
if type == "quick_service"
if booking.dining_facility_id.present?
table_id = booking.dining_facility_id
else
table_id = 0
end
if !receipt_bill_a5_pdf.empty?
receipt_bill_a5_pdf.each do |receipt_bilA5|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
if receipt_bilA5[1] == '1'
unique_code = "ReceiptBillA5Pdf"
# else
end
end
end
latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
if !latest_order.nil?
latest_order_no = latest_order.order_id
end
customer= Customer.find(saleObj.customer_id)
booking.booking_orders.each do |order|
# Order.pay_process_order_queue(order.order_id, table_id)
oqs = OrderQueueStation.new
oqs.pay_process_order_queue(order.order_id, table_id)
# get member information
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?
member_info = Customer.get_member_account(customer)
if member_info["status"] == true
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
current_balance = SaleAudit.paymal_search(sale_id)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
end
#orders print out
if type == "quick_service"
booking = Booking.find_by_sale_id(sale_id)
if booking.dining_facility_id.to_i>0
table_id = booking.dining_facility_id
else
table_id = 0
end
latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
if !latest_order.nil?
latest_order_no = latest_order.order_id
end
booking.booking_orders.each do |order|
# Order.pay_process_order_queue(order.order_id, table_id)
oqs = OrderQueueStation.new
oqs.pay_process_order_queue(order.order_id, table_id)
assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
end
end
#for card sale data
card_data = Array.new
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
if !card_sale_trans_ref_no.nil?
card_sale_trans_ref_no.each do |cash_sale_trans|
card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
card_no = cash_sale_trans.pan.last(4)
card_no = card_no.rjust(19,"**** **** **** ")
card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
end
end
#for card sale data
card_data = Array.new
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
if !card_sale_trans_ref_no.nil?
card_sale_trans_ref_no.each do |cash_sale_trans|
card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
card_no = cash_sale_trans.pan.last(4)
card_no = card_no.rjust(19,"**** **** **** ")
card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
end
end
#card_balance amount for Paymal payment
card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
#card_balance amount for Paymal payment
card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id)
# get printer info
print_settings = PrintSetting.find_by_unique_code(unique_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)
# get printer info
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, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref)
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)
#end
end
logger.debug 'saleObj++++++++++++++++++++++++++'
logger.debug saleObj.to_json
if !saleObj.nil?
# InventoryJob.perform_now(self.id)
# InventoryDefinition.calculate_product_count(saleObj)
@@ -330,7 +242,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
if path.include? ("credit_payment")
@sale_payment = SalePayment.get_credit_amount_due_left(sale_id)
@sale_payment = SalePayment.where(sale_id: sale_id, payment_method: 'creditnote').select("SUM(payment_amount) as payment_amount")
end
@member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code)
@@ -381,7 +293,7 @@ class Origami::PaymentsController < BaseOrigamiController
# @shop = shop_detail #show shop info
@customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'")
@customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"])
saleObj = Sale.find(sale_id)
@@ -636,11 +548,14 @@ class Origami::PaymentsController < BaseOrigamiController
current_balance = nil
order_source = params[:type]
if(Sale.exists?(sale_id))
if Sale.exists?(sale_id)
saleObj = Sale.find(sale_id)
#calculate cash acmount
cash = saleObj.total_amount
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
if saleObj.discount_type == "member_discount"
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
saleObj.compute_by_sale_items(0, nil, order_source)
@@ -648,9 +563,6 @@ class Origami::PaymentsController < BaseOrigamiController
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
bookings = Booking.where("sale_id='#{sale_id}'")
if bookings[0].dining_facility_id.to_i > 0
table = DiningFacility.find(bookings[0].dining_facility_id)
@@ -659,8 +571,6 @@ class Origami::PaymentsController < BaseOrigamiController
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
@@ -795,7 +705,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
end
# 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(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)
@@ -817,8 +727,10 @@ class Origami::PaymentsController < BaseOrigamiController
sale_id = params[:sale_id]
order_source = params[:cashier_type]
tax_type = params[:tax_type]
remark = "Change tax to #{tax_type.upcase} for Sale ID #{sale_id} By #{current_login_employee.name}"
sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.total_discount, nil, order_source, tax_type)
SaleAudit.record_audit_change_tax(sale_id,remark,current_login_employee.name)
render json: JSON.generate({:status => true})
end

View File

@@ -14,7 +14,7 @@ class Origami::PendingOrderController < BaseOrigamiController
def show
id = params[:sale_id]
if id.start_with?("SAL")
if id.include? "SAL"
@sale = Sale.find(id)
if @sale.sale_status == "new"
@bookings = @sale.bookings.first
@@ -22,7 +22,7 @@ class Origami::PendingOrderController < BaseOrigamiController
else
redirect_to "/origami/#{params[:type]}" and return
end
elsif (id.start_with?("BKI") || id.start_with?("CBKI"))
elsif id.include? "BKI"
@bookings = Booking.find(id)
@order = @bookings.orders.where(status: "new").first
@order_items = @bookings.order_items

View File

@@ -10,24 +10,27 @@ class Origami::QuickServiceController < ApplicationController
def index
today = DateTime.now
day = Date.today.wday
# if params[:menu] == "true"
@menus = []
@menu = []
@zone = Zone.all
@customer = Customer.all
@tables = Table.all.active.order('status desc')
@rooms = Room.all.active.order('status desc')
@tables = Table.active.order('status desc')
@rooms = Room.active.order('status desc')
@cashier_type = "quick_service"
display_type = Lookup.find_by_lookup_type("display_type")
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
else
@display_type = nil
end
#checked quick_service only
@quick_service_only = false
lookup_dine_in = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quickservice_add_order')
@quick_service_only = Lookup.collection_of('quickservice_add_order').any? { |x| x == ["quickserviceaddorder", "1"] }
lookup_dine_in = Lookup.collection_of('quickservice_add_order')
# puts 'lookup_dine_in!!!!'
# puts lookup_dine_in
if !lookup_dine_in.empty?
lookup_dine_in.each do |dine_in|
if dine_in[0].downcase == "quickserviceaddorder"
@@ -37,7 +40,23 @@ class Origami::QuickServiceController < ApplicationController
end
end
end
divided_value =0
exclusive =0
tax_profiles = TaxProfile.where(group_type: "quick_service")
if !tax_profiles.empty?
tax_profiles.each do |tax|
#include or execulive
if tax.inclusive
tax_incl_exec = "inclusive"
rate = tax.rate
divided_value += (100 + rate)/rate
else
exclusive +=tax.rate / 100
end
end
end
@inclusive_tax =divided_value
@exclusive_tax =exclusive
render "origami/addorders/detail"
end
@@ -52,7 +71,7 @@ class Origami::QuickServiceController < ApplicationController
# @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end
if(params[:id][0,3] == "BKI")
if params[:id].include? "BKI"
@table_id = nil
@table = nil
@booking = Booking.find(params[:id])
@@ -109,7 +128,7 @@ class Origami::QuickServiceController < ApplicationController
order = Order.new
order.source = params[:order_source]
order.order_type = params[:order_type]
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
order.items = items_arr
order.guest = params[:guest_info]
order.table_id = params[:table_id] # this is dining facilities's id

View File

@@ -18,96 +18,78 @@ class Origami::RequestBillsController < ApplicationController
else
table = DiningFacility.find_by(id: booking.dining_facility_id)
if sale_data = booking.sale
@status = true
elsif sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
@status = true
# in-duty update
in_duties = InDuty.where("booking_id=?", booking.id)
if !in_duties.empty?
in_duties.each do |in_duty|
induty = InDuty.find(in_duty.id)
induty.sale_id = sale_data.sale_id
induty.out_time = Time.now.utc
induty.save
end
end
end
# Bind shift sale id to sale
# @sale_data.shift_sale_id = shift.id
# @sale_data.save
action_by = current_user.name
type = "REQUEST_BILL"
remark = "Request bill Receipt No #{sale_data.receipt_no}"
sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type )
# Promotion Activation
Promotion.promo_activate(sale_data)
#bill channel
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
if order.source == "cashier" || order.source == "quick_service"
ActionCable.server.broadcast "bill_channel",table: table, from: from
end
if order.source == "quick_service" || order.source == "food_court"
result = {:status=> @status, :data => sale_data.sale_id }
render :json => result.to_json
else
#check checkInOut pdf print
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_and_shop_code(unique_code,@shop.shop_code)
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil?
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, table)
if booking.sale_id.nil?
if sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
# in-duty update
in_duties = InDuty.where("booking_id=?", booking.id)
if !in_duties.empty?
in_duties.each do |in_duty|
induty = InDuty.find(in_duty.id)
induty.sale_id = sale_data.sale_id
induty.out_time = Time.now.utc
induty.save
end
end
action_by = current_user.name
type = "REQUEST_BILL"
remark = "Request bill Receipt No #{sale_data.receipt_no}"
sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type )
# Promotion Activation
Promotion.promo_activate(sale_data)
#bill channel
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
if ["quick_service", "cashier"].include? order.source
ActionCable.server.broadcast "bill_channel", table: table, from: from
end
unless ["quick_service", "food_court"].include? order.source
#check checkInOut pdf print
checkout_time = Lookup.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)
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil?
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, table)
end
end
end
end
@status = true
sale_id = sale_data.sale_id
else
@status = false
sale_id = nil
end
else
@status = true
sale_id = booking.sale_id
end
end
@status = true
else
@status = false
@error_message = "No Current Open Shift for This Employee"
end
# Not Use for these printed bill cannot give customer
# unique_code = "ReceiptBillPdf"
# #shop detail
# shop_details = @shop
# # customer= Customer.where('customer_id=' +.customer_id)
# customer= Customer.find(@sale_data.customer_id)
# # get member information
# member_info = Customer.get_member_account(customer)
# # get printer info
# print_settings=PrintSetting.find_by_unique_code(unique_code)
# # find order id by sale id
# # sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# # Calculate price_by_accounts
# item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
# printer = Printer::ReceiptPrinter.new(print_settings)
# printer.print_receipt_bill(print_settings, false, nil,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details)
if ["quick_service", "food_court"].include? order.source
result = {:status=> @status, :data => sale_data.sale_id }
render :json => result.to_json
end
end
end

View File

@@ -27,52 +27,33 @@ class Origami::SalesController < BaseOrigamiController
dining = params[:dining_id]
sale_id = params[:sale_id]
tax_type = params[:tax_type]
sale_data = []
table = DiningFacility.find(dining)
existing_booking = Booking.find_by_sale_id(sale_id)
table.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}' ").each do |booking|
if booking.sale_id.nil?
order_array = []
booking.booking_orders.each do |booking_order|
booking.booking_status = 'moved'
order = Order.find(booking_order.order_id)
order.status = 'billed'
order.order_items.each do |item|
item.order_item_status = 'billed'
end
# create sale item
saleobj = Sale.find(sale_id)
order.order_items.each do |orer_item|
saleobj.add_item (orer_item)
if !orer_item.set_menu_items.nil?
saleobj.add_sub_item(orer_item.set_menu_items)
end
sale_data.push(orer_item)
end
Sale.transaction do
table = DiningFacility.find(dining)
booking = table.current_checkin_booking
# Re-compute for add
saleobj.compute(order.source,tax_type)
saleobj.save
order.save
booking.save
sale = Sale.find(sale_id)
existing = sale.booking
order_array.push(order.order_id)
end
sale.sale_items << booking.order_items.to_sale_items
sale.orders << booking.orders
receipt_no = Sale.find(sale_id).receipt_no
action_by = current_user.name
type = "ADD_TO_EXISTING"
sale.compute(booking.orders[0].source, tax_type)
remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no} in #{table.name}"
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
type = "ADD_TO_EXISTING"
receipt_no = sale.receipt_no
action_by = current_user.name
order_ids = booking.orders.map(&:order_id)
booking_order = BookingOrder.where('booking_id=?',booking)
booking_order.each do |bo|
bo.booking_id = existing_booking.booking_id
bo.save
end
end
remark = "#{action_by} add to existing order #{order_ids.to_s} to Receipt No=>#{receipt_no} in #{table.name}"
sale_audit = SaleAudit.record_audit_sale(sale_id, remark, action_by, type)
booking.orders.update_all(status: "billed")
booking.order_items.update_all(order_item_status: "billed")
BookingOrder.where(booking_id: booking.booking_id).update_all(booking_id: existing)
booking.booking_status = "moved"
booking.save
end
end

View File

@@ -16,377 +16,118 @@ class Origami::SplitBillController < BaseOrigamiController
@sale_data = Array.new
@current_user = current_user
table_bookings = Booking.where("dining_facility_id = #{dining_id} and sale_id IS NOT NULL")
if !table_bookings.nil?
table_bookings.each do |table_booking|
if table_booking.sale.sale_status != 'waste' && table_booking.sale.sale_status != 'spoile'
@sale_data.push(table_booking.sale)
end
end
end
@sale_data = @table.current_sales
if @booking
@booking.booking_orders.each do |booking_order|
arr_order_items = Array.new
@order = Order.find(booking_order.order_id)
if (@order.status == "new")
@orders.push(@order)
@orders = @booking.orders
@order = @orders[0]
@order_items = []
order_items = []
@order.order_items.each do |item|
if !item.set_menu_items.nil?
instance_item_sets = JSON.parse(item.set_menu_items)
arr_instance_item_sets = Array.new
instance_item_sets.each do |instance_item|
item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name
item.price = item.price.to_f + instance_item["price"].to_f
arr_instance_item_sets.push(item_instance_name)
end
item.set_menu_items = arr_instance_item_sets
end
@booking.order_items.each do |item|
if item.set_menu_items.present?
set_menu_items = JSON.parse(item.set_menu_items)
item.set_menu_items = set_menu_items.map { |x| x["item_instance_name"] }
item.price = item.price + set_menu_items.inject(0.0) { |sum, x| sum + x["item_instance_name"].to_f }
end
arr_item = Hash.new
if item.qty.to_i > 1
i = 1
while i <= item.qty.to_i do
arr_item = {'order_items_id' => item.order_items_id,
'order_id' => item.order_id,
'order_item_status' => item.order_item_status,
'item_order_by' => item.item_order_by,
'item_code' => item.item_code,
'item_instance_code' => item.item_instance_code,
'item_name' => item.item_name,
'alt_name' => item.alt_name,
'account_id' => item.account_id,
'qty' => '1.0',
'price' => item.price,
'remark' => item.remark,
'options' => item.options,
'set_menu_items' => item.set_menu_items,
'taxable' => item.taxable,
'completed_by' => item.completed_by,
'created_at' => item.created_at,
'updated_at' => item.updated_at}
i += 1
@order_items.push({@order.order_id => arr_item})
arr_order_items.push(arr_item)
end
else
arr_order_items.push(item)
@order_items.push({@order.order_id => item})
end
end
@order_items.push({'all_order' => arr_order_items})
end
end
else
@booking = nil
end
@order_items += item.qty.to_i.times.map { i = item.as_json; i["qty"] = 1; order_items << i; { item.order_id => i } }
end
@order_items << { 'all_order' => order_items }
else
@booking = nil
end
end
def create
cashier_type = params[:cashier_type]
dining_id = params[:dining_id]
order_ids = params[:order_ids]
arr_order_ids = nil
if !params[:arr_order_ids].nil?
arr_order_ids = JSON.parse(params[:arr_order_ids])
end
orders = nil
if !params[:orders].empty?
orders = JSON.parse(params[:orders])
end
order_items = nil
if !params[:order_items].empty?
order_items = JSON.parse(params[:order_items])
end
arr_order_ids = JSON.parse(params[:arr_order_ids]) if params[:arr_order_ids].present?
orders = JSON.parse(params[:orders]) if params[:orders].present?
order_items = JSON.parse(params[:order_items]) if params[:order_items].present?
status = false
if !ShiftSale.current_shift.nil?
#create Bill by Booking ID
table = 0
if !params[:booking_id].empty?
booking = Booking.find(params[:booking_id])
# for Multiple Cashier by Zone
if booking.dining_facility_id.to_i>0
table = DiningFacility.find(booking.dining_facility_id)
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
else
table = nil
cashier_zone = nil
end
#create Bill by Booking ID
table = DiningFacility.find_by(id: params[:dining_id]) if params[:dining_id].present?
# shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
# get_cashier_by_terminal = Employee.find(shift_by_terminal.employee_id)
if sale_data = booking.sale
status = true
elsif sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type,params[:current_checkin_induties_count])
status = true
Booking.transaction do
if params[:booking_id].present?
booking = Booking.find(params[:booking_id])
else
status = false
end
else
if params[:type] == "Table"
type = "TableBooking"
else
type = "RoomBooking"
end
type = "TableBooking" if params[:type] == "Table"
type ||= "RoomBooking"
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type,
:checkin_at => Time.now.utc, :checkin_by => current_user.name,
:booking_status => "assign",
:shop_code =>@shop.shop_code})
split_orders = []
new_order = nil
if !orders.nil?
orders.each do |order|
BookingOrder.find_by_order_id(order["id"]).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order["id"]})
booking = Booking.create({:dining_facility_id => table.id, :type => type, :checkin_at => Time.now.utc, :checkin_by => current_user.name, :booking_status => "assign" })
if orders.present?
split_orders += orders.map { |x| x["id"] }
end
elsif !order_items.nil?
order_item_count = 0
order_id_count = 0
order_id = nil
arr_order_ids.each do |order|
order.each do |odr|
data = Order.find(odr[0])
if data.order_items.count == odr[1]
order_id = odr[0]
order_id_count += 1
if order_items.present?
order_items = order_items.inject([]) do |arr, v|
v["qty"] = v["qty"].to_i
if i = arr.find { |x| x["id"] == v["id"] }
i["qty"] = i["qty"] + v["qty"]
else
order_item_count += 1
arr << v
end
arr
end
Order.includes(:order_items).where(order_id: order_ids).each do |order|
if order.order_items.any? { |x| order_items.none? { |y| x.order_items_id == y["id"] && x.qty == y["qty"] } }
new_order ||= Order.create({ source: "cashier", order_type: order.order_type, customer_id: order.customer_id, item_count: order_items.length, waiters: current_user.name })
order.order_items.each do |order_item|
if split_item = order_items.find { |x| x["id"] == order_item.order_items_id }
if split_item["qty"] == order_item.qty
new_order.order_items << order_item
else
order_item.qty = order_item.qty - split_item["qty"]
order_item.save
order_item_dup = order_item.dup
order_item_dup.qty = split_item["qty"]
new_order.order_items << order_item_dup
end
end
end
else
split_orders << order
end
end
end
if !order_id.nil?
if order_id_count > 1
updated_order_id = Array.new
arr_order_ids.each do |order|
order.each do |odr|
data = Order.find(odr[0])
if data.order_items.count != odr[1]
updated_order_id.push(odr[0])
end
end
end
if !updated_order_id.empty?
order_ids.each do |odr_id|
unless updated_order_id.include?(odr_id)
BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
end
end
order_items.each do |order_item|
if updated_order_id.include?(order_item["order_id"])
update_order_item(order_id, order_item)
end
end
else
order_ids.each do |odr_id|
new_order_status = true
order_items.each do |order_item|
orderItem = OrderItem.find_by_order_id(odr_id)
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
new_order_status = false
end
end
end
end
if new_order_status
BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end
end
else
new_order_status = true
order_items.each do |order_item|
orderItem = OrderItem.find(order_item["id"])
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
new_order_status = false
end
end
end
end
if new_order_status
BookingOrder.find_by_order_id(order_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id})
order_items.each do |order_item|
update_order_item(order_id, order_item)
end
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end
else
if order_ids.count == 1 && order_item_count == 1
if order_id_count == 0
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
else
BookingOrder.find_by_order_id(order_ids[0]).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
order_items.each do |order_item|
update_order_item(order_ids[0], order_item)
end
end
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
if new_order.present?
booking.orders << new_order
end
end
if sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type ,params[:current_checkin_induties_count])
status = true
end
end
Promotion.promo_activate(sale_data)
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
ActionCable.server.broadcast "bill_channel",table: table,from:from
render :json => { status: status }
else
render :json => { status: false, error_message: 'No Current Open Shift!'}
end
end
def create_order(params,order_type,items_count,current_user)
order = Order.new
order.source = "cashier"
order.order_type = order_type
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.item_count = items_count
order.status = "new"
order.table_id = params[:dining_id] # this is dining facilities's id
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
end
def update_order_item(order_id, order_item)
orderItem = OrderItem.find(order_item["id"])
if orderItem.qty.to_f != order_item['qty'].to_f
set_menu_items_obj = Array.new
if !orderItem.set_menu_items.nil?
instance_item_sets = JSON.parse(orderItem.set_menu_items)
instance_item_sets.each_with_index do |instance_item, instance_index|
instance_item_sets[instance_index]["quantity"] = (instance_item["quantity"].to_i - order_item['qty'].to_i).to_s
set_menu_items_obj.push({'item_instance_code' => instance_item["item_instance_code"], 'quantity' => order_item['qty'].to_i, 'price' => instance_item["price"]})
end
orderItem.set_menu_items = instance_item_sets.to_json
if split_orders.present?
BookingOrder.where(order_id: split_orders).update_all(booking_id: booking.booking_id)
end
end
same_order = OrderItem.find_by_order_id(order_id)
if same_order.nil?
OrderItem.processs_item(orderItem.item_code,
orderItem.item_instance_code,
orderItem.item_name,
orderItem.alt_name,
orderItem.account_id,
order_item['qty'],
orderItem.price,
orderItem.options,
set_menu_items_obj.to_json,
order_id,
orderItem.item_order_by,
orderItem.taxable)
else
same_order.qty = same_order.qty.to_f + order_item['qty'].to_f
same_order.set_menu_items = set_menu_items_obj.to_json
same_order.save
end
orderItem.qty = orderItem.qty.to_f - order_item['qty'].to_f
else
orderItem.order_id = order_id
end
orderItem.save!
if booking.sale.nil?
sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type, params[:current_checkin_induties_count])
Promotion.promo_activate(sale_data)
end
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
ActionCable.server.broadcast "bill_channel", table: table, from:from
render :json => { status: true }
end
else
render :json => { status: false, error_message: 'No Current Open Shift!'}
end
end
def update_sale

View File

@@ -9,7 +9,7 @@ class Origami::SurveysController < BaseOrigamiController
@id = params[:id]
@cashier_type = params[:type]
if(@id[0,3] == "SAL")
if @id.include? "SAL"
@sale = Sale.find(@id)
@receipt_no = @sale.receipt_no
@grand_total = @sale.grand_total
@@ -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_and_shop_code(@dining_facility.name,nil,@shop.shop_code)
@survey_data = Survey.find_by_dining_name_and_receipt_no(@dining_facility.name,nil)
end
end

View File

@@ -1,6 +1,7 @@
class Origami::TableInvoicesController < BaseOrigamiController
def index
@table = DiningFacility.find(params[:table_id])
shop = Shop.current_shop
@sale_array = Array.new
@table.bookings.each do |booking|
@@ -31,29 +32,7 @@ class Origami::TableInvoicesController < BaseOrigamiController
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all
@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
a = sale.grand_total % 25 # Modulus
b = sale.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
#calculate rounding if modulus is zero or not zero and division are not even
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
new_total = Sale.get_rounding_adjustment(sale.grand_total)
sale.rounding_adjustment = new_total-sale.grand_total
sale.update_attributes(grand_total: new_total,old_grand_total: sale.grand_total,rounding_adjustment:sale.rounding_adjustment)
end
end
#end rounding adjustment
if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != "waste" && sale.sale_status != "spoile"
@sale_array.push(sale)
end
end
end
@sale_array = @table.current_sales
@sale = Sale.find(params[:invoice_id])
@date = @sale.created_at

View File

@@ -4,6 +4,9 @@ class Reports::HourlySaleitemController < BaseReportController
@account = Account.where("shop_code='#{@shop.shop_code}'")
from, to = get_date_range_from_params
@start_time = params[:start_time]
@end_time = params[:end_time]
shift_sale_range = ''
shift = ''
@@ -23,9 +26,10 @@ class Reports::HourlySaleitemController < BaseReportController
end
end
filter = params[:filter]
account_type = params[:account_type]
@type = params[:sale_type]
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,@shop.shop_code)
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,filter,@start_time,@end_time)
@sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil).where("sales.shop_code='#{@shop.shop_code}'")