This commit is contained in:
NyanLinHtut
2019-12-23 09:48:11 +06:30
76 changed files with 1136 additions and 1531 deletions

View File

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

View File

@@ -9,7 +9,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?
@@ -51,13 +51,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
@@ -147,7 +140,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

@@ -67,15 +67,10 @@ class Api::OrdersController < Api::ApiController
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
@@ -98,7 +93,7 @@ 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
@@ -118,6 +113,7 @@ class Api::OrdersController < Api::ApiController
end
@status, @booking = @order.generate
if @status && @booking
Order.process_order_queue(@order.order_id,@order.table_id,@order.source)
end
@@ -195,7 +191,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

@@ -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,5 +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"

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

@@ -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,7 +42,7 @@ 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

View File

@@ -21,7 +21,7 @@ class Crm::CustomersController < BaseCrmController
# paymal_customer = Customer.search_paypar_account_no(filter)
# search account no from paypar
if type == "card"
response = Customer.search_paypar_account_no(filter)
if !@crm_customers.present?
if response["status"] == true
@@ -70,7 +70,7 @@ class Crm::CustomersController < BaseCrmController
else
flash[:member_error]="Need to press sync button "
end
end
end
end
@@ -82,8 +82,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
@@ -95,7 +96,7 @@ class Crm::CustomersController < BaseCrmController
lookup_customer = Lookup.collection_of('customer_settings')
if !lookup_customer.empty?
lookup_customer.each do |create_setting|
if create_setting[0].downcase == "create"
if create_setting[0].downcase == "create"
if create_setting[1] == '0' && current_login_employee.role == 'cashier'
@create_flag = false
end
@@ -135,7 +136,7 @@ class Crm::CustomersController < BaseCrmController
params[:type] = nil
params[:customer_id] = params[:id]
@credit_sales = SalePayment.get_credit_sales(params)
#get customer amount
@customer = Customer.find(params[:id])
@response = Customer.get_membership_transactions(@customer)
@@ -158,8 +159,9 @@ class Crm::CustomersController < BaseCrmController
def edit
@customer = Customer.find(params[:id])
end
def sync
@customer = Customer.find(params[:id])
@customer = Customer.find(params[:id])
respond_to do |format|
name = @customer.name
phone = @customer.contact_no
@@ -169,17 +171,15 @@ class Crm::CustomersController < BaseCrmController
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?
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,
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
@@ -193,7 +193,6 @@ class Crm::CustomersController < BaseCrmController
member_group_id: member_group_id,
id:id,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
end
begin
response = HTTParty.post(url,
@@ -221,7 +220,7 @@ class Crm::CustomersController < BaseCrmController
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 }
@@ -252,9 +251,9 @@ class Crm::CustomersController < BaseCrmController
end
# POST /crm/customers
# POST /crm/customers.json
def create
# Remove "" default first
params[:customer][:tax_profiles].delete_at(0)
def create
# Remove "" default first
params[:customer][:tax_profiles].delete_at(0)
@checked_contact = Customer.find_by_contact_no(customer_params[:contact_no])
if @checked_contact.nil?
respond_to do |format|
@@ -272,7 +271,7 @@ class Crm::CustomersController < BaseCrmController
nrc = customer_params[:nrc_no]
card_no = customer_params[:card_no]
paypar_account_no = customer_params[:paypar_account_no]
member_group_id = params[:member_group_id]
member_group_id = params[:member_group_id]
if member_group_id.present?
membership = MembershipSetting.find_by_membership_type("paypar_url")
@@ -282,7 +281,7 @@ class Crm::CustomersController < BaseCrmController
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,
dob: dob,address: address,nrc:nrc,card_no:card_no,
member_group_id: member_group_id,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
@@ -333,7 +332,7 @@ class Crm::CustomersController < BaseCrmController
end
# format.json { render :index, status: :created, location: @crm_customers }
else
customer = Customer.find(@crm_customers.customer_id)
customer = Customer.find(@crm_customers.customer_id)
# Check membership id and bind to user
if response["membership_id"] != nil
@@ -399,7 +398,7 @@ class Crm::CustomersController < BaseCrmController
# PATCH/PUT /crm/customers/1
# PATCH/PUT /crm/customers/1.json
def update
# Remove "" default first
# Remove "" default first
params[:customer][:tax_profiles].delete_at(0)
@checked_contact = nil
@existed_contact = Customer.find_by_customer_id_and_contact_no(customer_params[:id], customer_params[:contact_no])
@@ -409,7 +408,7 @@ class Crm::CustomersController < BaseCrmController
if !@existed_contact.nil? || @checked_contact.nil?
respond_to do |format|
if @crm_customer.update(customer_params)
# update tax profile
# update tax profile
@crm_customer.update_attributes(tax_profiles: params[:customer][:tax_profiles])
name = customer_params[:name]
phone = customer_params[:contact_no]
@@ -420,7 +419,7 @@ class Crm::CustomersController < BaseCrmController
card_no = customer_params[:card_no]
paypar_account_no = customer_params[:paypar_account_no]
id = @crm_customer.membership_id
member_group_id = params[:member_group_id]
member_group_id = params[:member_group_id]
if !id.present? && !member_group_id.nil?
membership = MembershipSetting.find_by_membership_type("paypar_url")
@@ -430,7 +429,7 @@ class Crm::CustomersController < BaseCrmController
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,
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
@@ -471,7 +470,7 @@ class Crm::CustomersController < BaseCrmController
Rails.logger.debug "--------Update 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 }
@@ -496,7 +495,7 @@ class Crm::CustomersController < BaseCrmController
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,
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
@@ -601,7 +600,7 @@ class Crm::CustomersController < BaseCrmController
flash[:member_notice]='Membership was successfully updated'
end
end
end
@@ -617,6 +616,5 @@ class Crm::CustomersController < BaseCrmController
params.require(:customer).permit(:id, :name, :company, :contact_no, :email,
:date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type, :image_path)
end
end
end

View File

@@ -7,10 +7,10 @@ class Origami::AddordersController < BaseOrigamiController
@webview = true
end
@tables = Table.all.active.order('zone_id asc').group("zone_id")
@rooms = Room.all.active.order('zone_id asc').group("zone_id")
@all_table = Table.all.active.order('status desc')
@all_room = Room.all.active.order('status desc')
@tables = Table.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
@@ -126,67 +126,68 @@ class Origami::AddordersController < BaseOrigamiController
}
# 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.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
@order.is_extra_time = is_extra_time
@order.extra_time = extra_time
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
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
# 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')
@status, @booking = @order.generate
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
# for second display
if @order.source == 'quick_service'
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 "second_display_channel",data: @sale,status:"sale",from:from
ActionCable.server.broadcast "order_channel", table: table,type:type,from:from
end
#end
result = {:status=> @status, :data => @sale }
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')
@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
end
#end
result = {:status=> @status, :data => @sale }
render :json => result.to_json
end
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
@@ -235,15 +236,9 @@ class Origami::AddordersController < BaseOrigamiController
sidekiq = Lookup.find_by_lookup_type("sidekiq")
if ENV["SERVER_MODE"] != 'cloud'
cup_status = `#{"sudo service cups status"}`
if !check_cup_status(cup_status)
cup_start = `#{"sudo service cups start"}`
cup_status = `#{"sudo service cups status"}`
if !check_cup_status(cup_status)
from = ''
msg = 'Print Error ! Please contact to service'
ActionCable.server.broadcast "call_waiter_channel", table: msg, time:'print_error', from: from
end
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

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

@@ -56,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])
@@ -113,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,8 +4,8 @@ class Origami::HomeController < BaseOrigamiController
def index
@webview = check_mobile
@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')
@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')

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,38 +10,18 @@ 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.id)
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)
end
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
#shop detail
## shop_detail = Shop.current_shop
# customer= Customer.where('customer_id=' +.customer_id)
customer = Customer.find(sale_data.customer_id)
# rounding adjustment
if shop_detail.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
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"
@@ -110,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.current_shop
# rounding adjustment
if !path.include? ("credit_payment")
if shop_detail.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
@@ -138,129 +102,107 @@ 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.id)
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.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(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
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 = 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(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)
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)
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
@@ -353,7 +295,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)
@@ -767,7 +709,7 @@ class Origami::PaymentsController < BaseOrigamiController
end
end
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)

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,30 +10,27 @@ class Origami::QuickServiceController < ApplicationController
def index
today = DateTime.now
day = Date.today.wday
# if params[:menu] == "true"
@menus = []
@menu = []
# else
# @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end
@zone = Zone.all
@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
@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
# 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"
@@ -43,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
@@ -58,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])
@@ -115,13 +128,13 @@ 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
order.waiters = current_login_employee.name
order.employee_name = current_login_employee.name
order.is_extra_time = is_extra_time
order.extra_time = extra_time

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.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)
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.current_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

@@ -1,7 +1,6 @@
class Origami::RoomInvoicesController < BaseOrigamiController
def index
@room = DiningFacility.find(params[:room_id])
puts "room bookig lenght"
@sale_array = Array.new
@room.bookings.each do |booking|
puts booking.sale_id

View File

@@ -26,52 +26,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,390 +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" })
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
# puts order_id
# puts order_ids.count
# puts order_id_count
# puts order_items.count
# puts order_item_count
if !order_id.nil?
if order_id_count > 1
puts "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
# puts "updated_order_id"
# puts updated_order_id
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
# puts new_order_status
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
# puts "order_id_count < 1"
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
# puts new_order_status
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.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

@@ -2,14 +2,14 @@ class Origami::SurveysController < BaseOrigamiController
def new
@webview = false
if check_mobile
@webview = true
@webview = true
end
@survey = Survey.new
@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
@@ -27,14 +27,14 @@ class Origami::SurveysController < BaseOrigamiController
@dining_facility = nil
@table_type = nil
end
else
@dining_facility = DiningFacility.find(@id)
@table_type = @dining_facility.type
@receipt_no = nil
@grand_total = nil
@survey_data = Survey.find_by_dining_name_and_receipt_no(@dining_facility.name,nil)
end
end
end
def create
@@ -63,13 +63,13 @@ class Origami::SurveysController < BaseOrigamiController
shift = ShiftSale.find(sale.shift_sale_id)
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil)
end
if @type == "quick_service" || @type == "food_court"
@url = "/origami/sale/"+@sale_id+"/"+@type+"/payment"
else
@url = "/origami/"+@dining_facility.type.downcase+"/"+params[:table_id]
end
if params[:survey_id].nil? || params[:survey_id] == ""
@survey = Survey.new(survey_params)
@@ -106,5 +106,5 @@ class Origami::SurveysController < BaseOrigamiController
def survey_params
params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount,:survey_id)
end
end

View File

@@ -1,8 +1,7 @@
class Origami::TableInvoicesController < BaseOrigamiController
def index
@table = DiningFacility.find(params[:table_id])
shop = Shop.current_shop
puts "table bookig lenght"
shop = Shop.current_shop
@sale_array = Array.new
@table.bookings.each do |booking|
puts booking.sale_id
@@ -34,30 +33,7 @@ class Origami::TableInvoicesController < BaseOrigamiController
@table = DiningFacility.find(params[:table_id])
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all
shop = Shop.current_shop
@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