fix foodcourt sales transaction

This commit is contained in:
Thein Lin Kyaw
2023-08-24 10:40:31 +06:30
parent 5503852217
commit a97b6bff3f
22 changed files with 361 additions and 453 deletions

View File

@@ -42,6 +42,8 @@ gem 'material_icons'
gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.2' gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.2'
gem 'rack-cors' gem 'rack-cors'
gem 'sidekiq'
# Multi-tenancy for shops # Multi-tenancy for shops
gem 'acts_as_tenant' gem 'acts_as_tenant'
@@ -51,7 +53,6 @@ gem 'mini_magick'
gem 'jquery-fileupload-rails', '~> 0.4.7' gem 'jquery-fileupload-rails', '~> 0.4.7'
#Report and Printing gems #Report and Printing gems
gem 'cups', '~> 0.0.7' gem 'cups', '~> 0.0.7'
gem 'prawn' gem 'prawn'
@@ -82,7 +83,6 @@ gem 'jbuilder', '~> 2.5'
gem 'bcrypt', '~> 3.1.7' gem 'bcrypt', '~> 3.1.7'
gem 'aescrypt' gem 'aescrypt'
gem 'sidekiq'
gem 'whenever', :require => false gem 'whenever', :require => false
# XML parser # XML parser
@@ -145,4 +145,4 @@ gem 'momentjs-rails' # for date-range selector
# gem 'select2-rails' # for multi-select and auto-complete select box # gem 'select2-rails' # for multi-select and auto-complete select box
gem "chartkick" #chart lib gem "chartkick" #chart lib
gem 'myanmar-tools' gem 'myanmar-tools'
gem 'rabbit-mm' gem 'rabbit-mm'

View File

@@ -563,7 +563,7 @@ $(function() {
$(document).on('click', '.add_icon', function(event){ $(document).on('click', '.add_icon', function(event){
if (window.location.pathname.includes('out_of_stock') == false) { if (window.location.pathname.includes('out_of_stock') == false) {
if($(this).hasClass('product_item')) { if($(this).hasClass('product_item')) {
$('.sx_item_detailModal').modal('hide'); $('.sx_item_detailModal').modal('hide');
@@ -1168,10 +1168,12 @@ $(function() {
data: params, data: params,
dataType: "json", dataType: "json",
success: function(result){ success: function(result){
if (type == "quick_service" || type=="food_court") { booking_id = result.booking_id;
module_name = window.location.href.includes('foodcourt') ? 'foodcourt' : 'origami' if (type == "quick_service") {
window.location.href = "/"+module_name+"/"+type; window.location.href = "/origami/quick_service";
}else{ } else if (type=="food_court") {
window.location.href = "/foodcourt/app_orders?pending_id=" + booking_id;
} else {
if(table_type == "Table"){ if(table_type == "Table"){
window.location.href = "/origami/table/" + table_id; window.location.href = "/origami/table/" + table_id;
} }
@@ -1195,7 +1197,7 @@ $(function() {
// Pay Discount for Payment // Pay Discount for Payment
// $("#create_pay_order").on('click', function(e){ // $("#create_pay_order").on('click', function(e){
// $(this).prop("disabled", true); // $(this).prop("disabled", true);
// $("#create_order").prop("disabled", true); // $("#create_order").prop("disabled", true);
// $("#read_modal").attr('data-for', 'member'); // $("#read_modal").attr('data-for', 'member');
@@ -1716,7 +1718,7 @@ $(function() {
menu_insta = ''; menu_insta = '';
$(instances).each(function(i){ $(instances).each(function(i){
if (!instances[i].out_of_stock) { //instances[i].is_default === true && if (!instances[i].out_of_stock) { //instances[i].is_default === true &&
code = instances[i].code; code = instances[i].code;
name = instances[i].name; name = instances[i].name;
price = parseFloat(instances[i].price).toFixed(2); price = parseFloat(instances[i].price).toFixed(2);

View File

@@ -63,7 +63,8 @@ function member_card(cardNo) {
var params = {'order_source': type, 'order_type': "dine_in", var params = {'order_source': type, 'order_type': "dine_in",
'customer_id': customer_id, 'guest_info': "", 'customer_id': customer_id, 'guest_info': "",
'table_id': table_id, 'table_id': table_id,
'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" }; 'order_items': order_items, 'sale_id': sale_id, 'create_type': "create_pay" };
if (booking_id.length > 0) { if (booking_id.length > 0) {
params.booking_id = booking_id; params.booking_id = booking_id;
} }
@@ -72,20 +73,17 @@ function member_card(cardNo) {
url: ajax_url, url: ajax_url,
data: params, data: params,
dataType: "json", dataType: "json",
success:function(result){ success:function(result) {
if (result.data == 'OK'){ if (result.sale_id) {
request_bill(g_membership_id, g_customer_id, g_customer_name); sale_id = result.sale_id;
}else{ window.location.href = '/foodcourt/sale/'+sale_id+'/food_court/payment/';
if (result.data["sale_id"]){
update_sale(g_membership_id, g_customer_id, g_customer_name,result.data["sale_id"]);
}
} }
} }
}); });
}else if($('.btn').is('#pay')){ } else if($('.btn').is('#pay')){
update_sale(g_membership_id, g_customer_id, g_customer_name,$('#sale_id').text()); sale_id = $('#sale_id').text();
} window.location.href = '/foodcourt/sale/'+sale_id+'/food_court/payment/';
else{ } else {
request_bill(g_membership_id, g_customer_id, g_customer_name); request_bill(g_membership_id, g_customer_id, g_customer_name);
} }
} }
@@ -93,18 +91,20 @@ function member_card(cardNo) {
}); });
} }
} }
function request_bill(membership_id,customer_id,customer_name){ function request_bill(membership_id,customer_id,customer_name){
if (window.location.pathname.includes('foodcourt')) { if (window.location.pathname.includes('foodcourt')) {
order_id = $('#order_id').val() || $('#save_order_id').val() order_id = $('#order_id').val() || $('#save_order_id').val()
data = { 'customer_id': customer_id }
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/foodcourt/food_court/"+order_id+"/request_bill" , url: "/foodcourt/food_court/"+order_id+"/request_bill" ,
data: {}, data: data,
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
if(data.status == true) if(data.status == true)
{ {
update_sale(membership_id, customer_id, customer_name, data.sale_id); window.location.href = '/foodcourt/sale/'+data.sale_id+'/food_court/payment/';
}else{ }else{
swal("Alert!", "Error!", "error"); swal("Alert!", "Error!", "error");
location.reload(); location.reload();
@@ -113,6 +113,7 @@ function request_bill(membership_id,customer_id,customer_name){
}); });
} }
} }
function update_sale(membership_id, customer_id, customer_name, sale_id) { function update_sale(membership_id, customer_id, customer_name, sale_id) {
$("#oqs_loading_wrapper").css("display", "none"); $("#oqs_loading_wrapper").css("display", "none");
var customer=""; var customer="";

View File

@@ -87,8 +87,6 @@ class Foodcourt::AddordersController < BaseFoodcourtController
end end
def create def create
new_booking =true
booking_id =nil
if params[:booking_id].present? if params[:booking_id].present?
booking = Booking.find(params[:booking_id]) booking = Booking.find(params[:booking_id])
end end
@@ -105,82 +103,64 @@ class Foodcourt::AddordersController < BaseFoodcourtController
items_arr = [] items_arr = []
JSON.parse(params[:order_items]).each { |i| JSON.parse(params[:order_items]).each { |i|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s i["item_instance_code"] = i["item_instance_code"].downcase.to_s
if i["item_instance_code"].include? "ext" if i["parent_order_item_id"];
is_extra_time = true 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"])}
arr_exts = i["item_instance_code"].split("_") else
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
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])} items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
end end
items_arr.push(items) items_arr.push(items)
} }
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0 customer_id = params[:customer_id].present? ? params[:customer_id] : Customer.walkin.customer_id
customer_id = takeaway.customer_id # for no customer id from mobile
else
customer_id = params[:customer_id].present? ? params[:customer_id] : Customer.walkin.customer_id # for no customer id from mobile
end
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
new_booking = true
else
new_booking = false
booking_id = booking.booking_id
end
@order =Order.create(source: params[:order_source],
order_type: params[:order_type],
customer_id: customer_id,
items: items_arr,
guest: params[:guest_info],
table_id: params[:table_id],
new_booking: new_booking,
waiters: current_login_employee.name,
employee_name: current_login_employee.name,
is_extra_time: is_extra_time,
extra_time: extra_time,
booking_id: booking_id
)
@status, @booking = @order.generate
if @status && @booking Order.transaction do
#send order broadcast to order_channel @order = Order.new
if @order.table_id.to_i > 0 @order.source = params[:order_source]
table = DiningFacility.find(@booking.dining_facility_id) @order.order_type = params[:order_type]
type = 'order' @order.customer_id = customer_id
from = getCloudDomain #get sub domain in cloud mode @order.items = items_arr
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from @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.new_booking = true
else
@order.new_booking = false
@order.booking_id = booking.booking_id
end end
if params[:order_source] != "quick_service" && params[:order_source] != "food_court" @status, @booking = @order.generate
process_order_queue(@order.order_id,@order.table_id,@order.source)
end
end
if current_user.role != "waiter" && params[:create_type] == "create_pay" if @status && @booking
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') #send order broadcast to order_channel
if @order.table_id.to_i > 0
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee) table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'
# for second display
if @order.source == 'quick_service'
from = getCloudDomain #get sub domain in cloud mode 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
#end
result = {:status=> @status, :data => @sale ,:current_user_role =>current_user.role}
render :json => result.to_json
end end
else
result = {:status=> @status, :data => 0 }
render :json => result.to_json
end
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
end
end
end
end end
# render json for http status code # render json for http status code

View File

@@ -9,51 +9,49 @@ class Foodcourt::FoodCourtController < ApplicationController
def index def index
if !ShiftSale.current_shift.nil? if !ShiftSale.current_shift.nil?
if params[:sale_id].present? if params[:sale_id].present?
sale =Sale.find(params[:sale_id]) sale =Sale.find(params[:sale_id])
if sale if sale
@sale_id =sale.sale_id @sale_id =sale.sale_id
@booking_id =sale.bookings[0].booking_id @booking_id =sale.bookings[0].booking_id
end
end end
end
@zone = Zone.all @zone = Zone.all.includes(:tables, :rooms).where("is_active= true")
@tables = Table.active.order('status desc')
@rooms = Room.active.order('status desc')
today = Time.current today = Time.current
day = Date.today.wday day = Date.today.wday
@menus = [] @menus = []
@menu = [] @menu = []
@cashier_type = "food_court" @cashier_type = "food_court"
#checked quick_service only #checked quick_service only
display_type = Lookup.find_by_lookup_type("display_type") 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 @display_type = display_type.value
else else
@display_type = nil @display_type = nil
end end
@quick_service_only = true @quick_service_only = true
lookup_dine_in = Lookup.collection_of('dinein_cashier') lookup_dine_in = Lookup.collection_of('dinein_cashier')
if !lookup_dine_in.empty? if !lookup_dine_in.empty?
lookup_dine_in.each do |dine_in| lookup_dine_in.each do |dine_in|
if dine_in[0].downcase == "dineincashier" if dine_in[0].downcase == "dineincashier"
if dine_in[1] == '1' if dine_in[1] == '1'
@quick_service_only = false @quick_service_only = false
end
end end
end end
end end
end @app_order_new_count = Booking.select("bookings.*,customers.*")
@app_order_new_count = Booking.select("bookings.*,customers.*")
.joins(" JOIN sales ON bookings.sale_id=sales.sale_id") .joins(" JOIN sales ON bookings.sale_id=sales.sale_id")
.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id") .joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
.joins("JOIN orders ON orders.order_id=booking_orders.order_id") .joins("JOIN orders ON orders.order_id=booking_orders.order_id")
.joins("JOIN order_items ON orders.order_id=order_items.order_id") .joins("JOIN order_items ON orders.order_id=order_items.order_id")
.joins("JOIN customers ON orders.customer_id=customers.customer_id") .joins("JOIN customers ON orders.customer_id=customers.customer_id")
.where("bookings.booking_status !=? and sales.sale_status =? and sales.payment_status =? and orders.source='app' and DATE(bookings.created_at)=?",'completed','completed','paid',Date.today).order("bookings.created_at desc").uniq.length .where("bookings.booking_status !=? and sales.sale_status =? and sales.payment_status =? and orders.source='app' and DATE(bookings.created_at)=?",'completed','completed','paid',Date.today).order("bookings.created_at desc").uniq.length
render "foodcourt/addorders/detail" render "foodcourt/addorders/detail"
else else
if current_user.role == 'administrator' || current_user.role == 'manager' if current_user.role == 'administrator' || current_user.role == 'manager'
redirect_to origami_dashboard_path redirect_to origami_dashboard_path

View File

@@ -64,7 +64,6 @@ class Foodcourt::OrdersController < BaseFoodcourtController
@booking_id =@booking.booking_id @booking_id =@booking.booking_id
@order_id =@booking.order_id @order_id =@booking.order_id
@sale_data = Sale.find_by_sale_id(@booking.sale_id) @sale_data = Sale.find_by_sale_id(@booking.sale_id)
elsif params[:pending_id] elsif params[:pending_id]
id = params[:pending_id] id = params[:pending_id]
if id.include? "SAL" if id.include? "SAL"
@@ -166,40 +165,46 @@ class Foodcourt::OrdersController < BaseFoodcourtController
} }
# begin # begin
order = Order.new Order.transaction do
order.source = params[:order_source] order = Order.new
order.order_type = params[:order_type] order.source = params[:order_source]
# order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile order.order_type = params[:order_type]
order.items = items_arr # order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
order.guest = params[:guest_info] order.items = items_arr
order.table_id = params[:table_id] # this is dining facilities's id order.guest = params[:guest_info]
order.waiters = current_login_employee.name order.table_id = params[:table_id] # this is dining facilities's id
order.employee_name = current_login_employee.name order.waiters = current_login_employee.name
order.employee_name = current_login_employee.name
order.is_extra_time = is_extra_time order.is_extra_time = is_extra_time
order.extra_time = extra_time order.extra_time = extra_time
order.new_booking = false order.new_booking = false
order.booking_id = booking.booking_id order.booking_id = booking.booking_id
if order.generate if order.generate
if sale if sale
Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking) Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking)
render :json => { :status => true, :data => sale } render :json => { :status => true, :data => sale }
else
render :json => { :status => true, :data => 'OK' }
end
else else
render :json => { :status => true, :data => 'OK' } render :json => { :status => false }
end end
else
render :json => { :status => false }
end end
end end
def request_bill def request_bill
sale_data =[] sale_data =[]
customer_id = params[:customer_id]
if !ShiftSale.current_shift.nil? if !ShiftSale.current_shift.nil?
order_id = params[:order_id] # order_id order_id = params[:order_id]
order = Order.find(order_id) order = Order.find(order_id)
booking = order.booking booking = order.booking
if Customer.exists?(customer_id: customer_id)
booking.orders.update_all(customer_id: customer_id)
end
if booking.checkin_at.utc > Time.now.utc && booking.checkout_at.nil? if booking.checkin_at.utc > Time.now.utc && booking.checkout_at.nil?
@status = false @status = false
@error_message = "Operation failed, Could not request bill!" @error_message = "Operation failed, Could not request bill!"
@@ -295,7 +300,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController
def cancel_order def cancel_order
order_id = params[:order_id] order_id = params[:order_id]
if order_id.present? if order_id.present?
order = Order.find(order_id) order = Order.find(order_id)
booking = order.booking booking = order.booking
@@ -321,5 +326,5 @@ class Foodcourt::OrdersController < BaseFoodcourtController
end end
end end
end end
end end

View File

@@ -1,19 +1,37 @@
class Foodcourt::PaymalController < BaseFoodcourtController class Foodcourt::PaymalController < BaseFoodcourtController
def create def create
cash = params[:payment_amount] cash = params[:payment_amount]
sale_id = params[:sale_id] sale_id = params[:sale_id]
transaction_ref = params[:transaction_ref] transaction_ref = params[:transaction_ref]
account_no = params[:account_no] account_no = params[:account_no]
if(Sale.exists?(sale_id)) if(Sale.exists?(sale_id))
Sale.transaction do
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
booking = saleObj.booking
sale_payment = SalePayment.new sale_payment = SalePayment.new
status, @sale, @membership_data = sale_payment.process_payment(saleObj, current_user, cash, "paymal",account_no) status, @sale, @membership_data = sale_payment.process_payment(saleObj, current_user, cash, "paymal", account_no)
if status == true && @membership_data["status"] == true if status == true && @membership_data["status"] == true
PrintOrderQueueJob.perform_later(current_shop.shop_code, booking.booking_id)
PrintReceiptJob.perform_later(current_shop.shop_code, sale_id)
@out = true, "Success!" @out = true, "Success!"
else else
@out = false, @membership_data["message"] @out = false, @membership_data["message"]
end end
end end
end end
end
private
def getCloudDomain
from = ""
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain.to_s + "." + request.domain.to_s
end
return from
end
end end

View File

@@ -9,19 +9,20 @@ class Foodcourt::SecondDisplayController < BaseFoodcourtController
def customer_view def customer_view
display_type = Lookup.find_by_lookup_type("display_type") 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
if params[:status]!= "billed" if params[:status]!= "billed"
tax_profiles = TaxProfile.all.order("order_by asc") tax_profiles = TaxProfile.all.order("order_by asc")
else else
tax_profiles = nil tax_profiles = nil
end end
if ENV["SERVER_MODE"] == 'cloud' if ENV["SERVER_MODE"] == 'cloud'
from = request.host from = request.host
else else
from = "" from = ""
end end
ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from
end end
head :no_content
# end # end
end end
#Shop Name in Navbor #Shop Name in Navbor

View File

@@ -34,6 +34,15 @@ class Foodcourt::VoidController < BaseFoodcourtController
sale.sale_status = 'void' sale.sale_status = 'void'
sale.save sale.save
#call paymal to void
if !sale.sale_payments.nil?
membership_response = sale.paymal_payment_void
Rails.logger.debug "---------Paymal Payment Void response in VoidController"
Rails.logger.debug membership_response.to_json
end
PrintReceiptJob.perform_later(current_shop.shop_code, sale.sale_id)
if table = sale.booking.dining_facility if table = sale.booking.dining_facility
unless table.current_bookings.exists? unless table.current_bookings.exists?
table.update_attributes(status: 'available') table.update_attributes(status: 'available')
@@ -49,73 +58,6 @@ class Foodcourt::VoidController < BaseFoodcourtController
# remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,"SALEVOID" ) sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,"SALEVOID" )
#call paymal to void
if !sale.sale_payments.nil?
membership_response =sale.paymal_payment_void
Rails.logger.debug "---------Paymal Payment Void response in VoidController"
Rails.logger.debug membership_response.to_json
end
# For Print
member_info = nil
rebate_amount = nil
current_balance = nil
if sale.booking.dining_facility_id.to_i > 0
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
else
shift = ShiftSale.find(sale.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
end
customer= Customer.find(sale.customer_id)
#shop detail
shop_details = Shop.current_shop
# get member information
rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
# current_balance = SaleAudit.paymal_search(sale_id)
current_balance = 0
end
printer = PrintSetting.all
unique_code="ReceiptBillPdf"
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'ReceiptBillPdf'
unique_code="ReceiptBillPdf"
elsif printer_setting.unique_code == 'ReceiptBillA5Pdf'
unique_code="ReceiptBillA5Pdf"
elsif printer_setting.unique_code == 'ReceiptBillStarPdf'
unique_code="ReceiptBillStarPdf"
end
end
end
# 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(sale.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil)
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# Mobile Print
render :json => result.to_json
# end
#end print
# update complete order items in oqs # update complete order items in oqs
SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr| SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr|
AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
@@ -124,6 +66,6 @@ class Foodcourt::VoidController < BaseFoodcourtController
end end
end end
end end
head :no_content
end end
end end

View File

@@ -3,8 +3,8 @@ class OrderQueueProcessorJob < ApplicationJob
def perform(order_id, table_id) def perform(order_id, table_id)
# Do something later # Do something later
#Order ID #Order ID
order = Order.find(order_id) order = Order.find(order_id)
#Execute orders and send to order stations #Execute orders and send to order stations
if order if order
@@ -16,11 +16,11 @@ class OrderQueueProcessorJob < ApplicationJob
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end end
# private # private
# def render_order(assign_order) # def render_order(assign_order)
# ApplicationController.renderer.render(partial: 'oqs/oqs_test', # ApplicationController.renderer.render(partial: 'oqs/oqs_test',
# locals: { order: assign_order}) # locals: { order: assign_order})
# end # end
# Read more at https://www.pluralsight.com/guides/ruby-ruby-on-rails/creating-a-chat-using-rails-action-cable#TehYiuqlHDOXaQQk.99 # Read more at https://www.pluralsight.com/guides/ruby-ruby-on-rails/creating-a-chat-using-rails-action-cable#TehYiuqlHDOXaQQk.99

View File

@@ -0,0 +1,14 @@
class PrintOrderQueueJob < ApplicationJob
queue_as :default
def perform(shop_code, booking_id)
current_shop = Shop.find_by(shop_code: shop_code)
ActsAsTenant.with_tenant(current_shop) do
booking = Booking.find(booking_id)
booking.orders.each do |order|
oqs = OrderQueueStation.new
oqs.process_order(order, booking.dining_facility_id)
end
end
end
end

View File

@@ -0,0 +1,49 @@
class PrintReceiptJob < ApplicationJob
queue_as :high_priority
def perform(shop_code, sale_id)
current_shop = Shop.find_by(shop_code: shop_code)
ActsAsTenant.with_tenant(current_shop) do
saleObj = saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id)
booking = saleObj.booking
latest_order_no = booking.booking_orders.last.order_id
cashier_terminal = booking.cashier_terminal_by_dining_facility || saleObj.cashier_terminal_by_shift_sale
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
card_data = Array.new
#card_balance amount for Paymal payment
card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id)
print_settings = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first
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)
if saleObj.sale_status = 'completed'
printer.print_receipt_bill(print_settings, false, nil, cashier_terminal, sale_items, saleObj, customer.paypar_account_no, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, current_shop, 'paid', current_balance, card_data, other_amount, latest_order_no, card_balance_amount, nil, transaction_ref)
elsif saleObj.sale_status = 'void'
printer.print_receipt_bill(print_settings, false, nil,cashier_terminal, sale_items, saleObj, customer.paypar_account_no, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, current_shop, "VOID", current_balance, card_data, other_amount,nil,nil,nil)
end
end
end
end

View File

@@ -173,12 +173,7 @@ class Booking < ApplicationRecord
end end
def self.get_booking_id(order_no) def self.get_booking_id(order_no)
booking = Booking.joins(" JOIN booking_orders bo ON bo.booking_id = bookings.booking_id") return BookingOrder.where(order_id: order_no).first.booking_id
.joins(" JOIN orders o ON o.order_id=bo.order_id")
.where("o.order_id='#{order_no}'")
.first()
return booking.booking_id
end end
private private

View File

@@ -10,11 +10,14 @@ class DiningFacility < ApplicationRecord
has_many :bookings has_many :bookings
has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.unscoped.where(checkout_at: nil).or(Booking.merge(Sale.unscoped.where(sale_status: ['new', nil])))) }, class_name: "Booking" has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.unscoped.where(checkout_at: nil).or(Booking.merge(Sale.unscoped.where(sale_status: ['new', nil])))) }, class_name: "Booking"
has_one :current_checkin_booking, -> { left_joins(:sale).assign.merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking" has_one :current_checkin_booking, -> { left_joins(:sale).assign.where(sale_id: nil) }, class_name: "Booking"
has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.unscoped.where(sale_status: 'new')) }, class_name: "Booking" has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.unscoped.where(sale_status: 'new')) }, class_name: "Booking"
has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking" has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking"
has_many :current_sales, -> { where(sale_status: 'new').merge(Booking.assign) }, through: :bookings, class_name: "Sale", source: "sale" has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.unscoped.where(checkout_at: nil).or(Booking.merge(Sale.unscoped.where(sale_status: ['new', nil])))) }, class_name: "Booking"
has_one :current_checkin_booking, -> { left_joins(:sale).assign.where(sale_id: nil) }, class_name: "Booking"
has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.unscoped.where(sale_status: 'new')) }, class_name: "Booking"
has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking"
TABLE_TYPE = "Table" TABLE_TYPE = "Table"
ROOM_TYPE = "Room" ROOM_TYPE = "Room"

View File

@@ -49,99 +49,36 @@ class OrderQueueStation < ApplicationRecord
end end
end end
def pay_process_order_queue (order_id, table_id) def pay_process_order_queue (order_id, table_id = nil)
oqs_stations = OrderQueueStation.active
order = Order.find(order_id)
order_items = order.order_items
# Order.pay_process_order_queue(order_id,table_id)
# if order
# oqs = OrderQueueStation.new
# oqs.process_order(order, table_id)
# end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# if ENV["SERVER_MODE"] == 'cloud'
# from = request.subdomain + "." + request.domain
# else
# from = ""
# end
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
if table_id.to_i > 0 if table_id.to_i > 0
# get dining # get dining
dining = DiningFacility.find(table_id) dining = DiningFacility.find(table_id)
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}") oqs_stations = dining.order_queue_stations
booking = Booking.find_by_dining_facility_id(dining.id)
# ToDo per item per printer
oqs_by_zones.each do |oqpbz|
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
is_auto_printed = false
oqs_order_items = []
if oqs.is_active
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
if (pq_item == order_item.item_code)
if (order_item.qty > 0)
oqs_order_items.push(order_item)
end
end
end
end
if oqs.auto_print
if oqs_order_items.length > 0
if oqs.cut_per_item
print_slip_item(oqs, order, oqs_order_items)
else
print_slip(oqs, order, oqs_order_items)
end
is_auto_printed = true
end
end
end
end
else else
oqs_stations.each do |oqs| oqs_stations = OrderQueueStation.active
is_auto_printed = false end
oqs_order_items = []
if oqs.is_active order = Order.find(order_id)
#Get List of items - order_items = order.order_items
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
if (pq_item == order_item.item_code)
if (order_item.qty > 0)
oqs_order_items.push(order_item)
end
end
end
end
if oqs.auto_print assigned_order_items = []
if oqs_order_items.length > 0 oqs_order_items_by_zones = []
if oqs.cut_per_item
print_slip_item(oqs, order, oqs_order_items) oqs_stations.each do |oqs|
else oqs_order_items = order_items.select { |i| JSON.parse(oqs.processing_items).include? i.item_code }
print_slip(oqs, order, oqs_order_items) oqs_order_items_by_zones << { oqs: oqs, oqs_order_items: oqs_order_items }
end
is_auto_printed = true if oqs.auto_print
end if oqs_order_items.length > 0
if oqs.cut_per_item
print_slip_item(oqs, order, oqs_order_items)
else
print_slip(oqs, order, oqs_order_items)
end end
end end
end end
end #end else end
end end
private private

View File

@@ -118,7 +118,6 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
if printed_status != 'Paid' || !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1') if printed_status != 'Paid' || !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1')
#no print in cloud server #no print in cloud server
puts "SERVER_MODE #{ENV["SERVER_MODE"]}"
if ENV["SERVER_MODE"] != "cloud" if ENV["SERVER_MODE"] != "cloud"
self.print(filename, cashier_terminal.printer_name) self.print(filename, cashier_terminal.printer_name)
end end

View File

@@ -1,10 +1,13 @@
if @status == true if @status == true
json.status :success json.status :success
json.id @order.id
json.booking_id @booking.id json.booking_id @booking.id
json.order_id @order.id
json.order_items do json.order_items do
json.array! @order.order_items, :item_code, :item_name, :qty, :options, :remark json.array! @order.order_items, :item_code, :item_name, :qty, :options, :remark
end end
if @sale
json.sale_id @sale.sale_id
end
else else
json.status :error json.status :error
if @error_messages if @error_messages

View File

@@ -167,7 +167,7 @@
Orders Orders
</button> </button>
<button class="btn btn-lg bg-blue waves-effect select_table col-md-3" data-toggle="modal" data-target="#TableModal">Select</button> <button class="btn btn-lg bg-blue waves-effect select_table col-md-3" data-toggle="modal" data-target="#TableModal">Select</button>
<div class="row "> <div class="row ">
<div class="col-md-9 col-lg-9 col-sm-9 "> <div class="col-md-9 col-lg-9 col-sm-9 ">
<strong id="order-title" class="font-14 p-l-10">ORDER DETAILS </strong> <strong id="order-title" class="font-14 p-l-10">ORDER DETAILS </strong>
@@ -432,80 +432,53 @@
</div> </div>
</div> </div>
<div class="modal fade" id="TableModal" tabindex="-1" role="dialog"> <div class="modal fade" id="TableModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header" style="margin-top: -1rem;"> <div class="modal-header" style="margin-top: -1rem;">
<!-- <h4 class="modal-title" id="TableModalLabel">Select Table</h4> --> <!-- <h4 class="modal-title" id="TableModalLabel">Select Table</h4> -->
<button type="button" class="close" id="close" data-dismiss="modal" aria-hidden="true" style="font-size: 20px;">&times;</button> <button type="button" class="close" id="close" data-dismiss="modal" aria-hidden="true" style="font-size: 20px;">&times;</button>
</div> </div>
<div class="modal-body" style="margin-top: -0.75rem;padding-top:5px"> <div class="modal-body" style="margin-top: -0.75rem;padding-top:5px">
<%@zone.each do |zone| %> <%@zone.each do |zone| %>
<h5>Zone : <%=zone.name%></h5> <h5>Zone : <%=zone.name%></h5>
<div class="card-columns" style="column-count: 7;"> <div class="card-columns" style="column-count: 7;">
<%zone.tables.each do |table| %> <%zone.tables.each do |table| %>
<% if table.status == 'occupied' %> <% if table.status == 'occupied' %>
<% if table.get_booking.nil? %> <% color="red"%>
<% if table.get_checkout_booking.nil? %> <% else %>
<% color="red"%> <% color="green"%>
<% else %> <% end %>
<% color="orange"%> <div class="card tables <%=color%> text-white table_<%= table.id %>" data-id="<%= table.id %>" data-type="<%= table.type %>" data-name="<%= table.name %>">
<% end %> <div class="card-block">
<%= table.name %>
<% else %>
<% if table.get_checkout_booking.nil? %>
<% color="blue"%>
<% else %>
<% color="orange"%>
<% end %>
<% end %>
<% else %>
<% color="green"%>
<% end %>
<div class="card tables <%=color%> text-white table_<%= table.id %>" data-id="<%= table.id %>" data-type="<%= table.type %>" data-name="<%= table.name %>">
<div class="card-block">
<%= table.name %>
</div>
</div>
<%end%>
<%zone.rooms.each do |table| %>
<% if table.status == 'occupied' %>
<% if table.get_booking.nil? %>
<% if table.get_checkout_booking.nil? %>
<% color="red"%>
<% else %>
<% color="orange"%>
<% end %>
<% else %>
<% if table.get_checkout_booking.nil? %>
<% color="blue"%>
<% else %>
<% color="orange"%>
<% end %>
<% end %>
<% else %>
<% color="green"%>
<% end %>
<div class="card tables <%=color%> text-white table_<%= table.id %>" data-id="<%= table.id %>" data-type="<%= table.type %>" data-name="<%= table.name %>">
<div class="card-block">
<%= table.name %>
</div>
</div>
<%end%>
</div>
<%end%>
<div class="modal-footer p-r-30">
<button type="button" class="btn btn-link btn-danger waves-effect" data-dismiss="modal">CLOSE</button>
&nbsp; &nbsp;
<button type="button" class="btn btn-link bg-blue waves-effect confirm_table" data-dismiss="modal">Confirm</button>
</div>
</div>
</div> </div>
</div> </div>
</div> <%end%>
<%zone.rooms.each do |table| %>
<% if table.status == 'occupied' %>
<% color="red"%>
<% else %>
<% color="green"%>
<% end %>
<div class="card tables <%=color%> text-white table_<%= table.id %>" data-id="<%= table.id %>" data-type="<%= table.type %>" data-name="<%= table.name %>">
<div class="card-block">
<%= table.name %>
</div>
</div>
<%end%>
</div>
<%end%>
<div class="modal-footer p-r-30">
<button type="button" class="btn btn-link btn-danger waves-effect" data-dismiss="modal">CLOSE</button>
&nbsp; &nbsp;
<button type="button" class="btn btn-link bg-blue waves-effect confirm_table" data-dismiss="modal">Confirm</button>
</div>
</div>
</div>
</div>
</div>
<input type="hidden" name="server_mode" value="<%=ENV["SERVER_MODE"]%>" id="server_mode"> <input type="hidden" name="server_mode" value="<%=ENV["SERVER_MODE"]%>" id="server_mode">
</div> </div>
@@ -555,7 +528,7 @@ $(document).ready(function () {
$('#table_type').text(type); $('#table_type').text(type);
$('.select_table').text(name); $('.select_table').text(name);
}); });
$('#app_order').on('click', function () { $('#app_order').on('click', function () {
window.location.href = '/en/foodcourt/app_orders'; window.location.href = '/en/foodcourt/app_orders';
}); });
@@ -574,7 +547,7 @@ $(document).ready(function () {
show_menu_cat_list(name, url); show_menu_cat_list(name, url);
} }
}); });
//End menu category Click //End menu category Click
function getAllMenu(){ function getAllMenu(){
$.ajax({ $.ajax({

View File

@@ -201,7 +201,7 @@
<div class="card-block h-100 d-flex flex-column"> <div class="card-block h-100 d-flex flex-column">
<div> <div>
<span class="font-14 float-left d-inline"><b>Booking</b> - <%=@booking.booking_id%></span> <span class="font-14 float-left d-inline"><b>Booking</b> - <%=@booking.booking_id%></span>
<span class="font-14 float-right d-inline"><b>Order No</b> - <%=@booking.order_id%></span> <span class="font-14 float-right d-inline"><b>Order No</b> - <%=@booking.order_id%></span>
</div> </div>
<div class="card-text h-100" id="foodcourt-table-slimscroll" style="overflow-y: auto"> <div class="card-text h-100" id="foodcourt-table-slimscroll" style="overflow-y: auto">
<table class="table table-striped summary-items fixed-header"> <table class="table table-striped summary-items fixed-header">
@@ -271,12 +271,17 @@
<div class="card" style="height: 100%; margin-bottom: 10px;"> <div class="card" style="height: 100%; margin-bottom: 10px;">
<div class="card-header"> <div class="card-header">
<div> <div>
<strong id="order-title">INVOICE DETAILS </strong>| Table - <%= @pending.dining_facility.name rescue "" %> <% if @status == 'sale' %>
<% table_name = @pending.try(:booking).try(:dining_facility).try(:name) %>
<% elsif @status == 'order' %>
<% table_name = @pending.try(:dining_facility).try(:name) %>
<% end %>
<strong id="order-title">INVOICE DETAILS </strong>| Table - <%= table_name %>
</div> </div>
<div class="row p-l-5 p-r-5"> <div class="row p-l-5 p-r-5">
<% if @status == 'sale' || @pending.try(:sale_status) == 'completed' || @pending.try(:sale_status) == 'void' %> <% if @status == 'sale' || @pending.try(:sale_status) == 'completed' || @pending.try(:sale_status) == 'void' %>
<div class="col-lg-6 col-md-6 col-sm-6"> <div class="col-lg-6 col-md-6 col-sm-6">
&nbsp; Receipt No: &nbsp; Receipt No:
<span id="receipt_no"> <span id="receipt_no">
<%= @pending.receipt_no rescue '' %> <%= @pending.receipt_no rescue '' %>
</span> </span>
@@ -380,7 +385,7 @@
</table> </table>
</div> </div>
</div> </div>
</div> </div>
<% end %> <% end %>
@@ -440,7 +445,7 @@
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
</div> </div>
<div class="modal fade" id="voidModal" tabindex="-1" role="dialog"> <div class="modal fade" id="voidModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">

View File

@@ -757,53 +757,32 @@ $(document).ready(function(){
var sale_id = $('#sale_id').text(); var sale_id = $('#sale_id').text();
// var item_row = $('.is_card'); // var item_row = $('.is_card');
// payment if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){
var cash = $('#cash').text(); var receipt_no = ($("#receipt_no").html()).trim();
var credit = $('#credit').text(); deleteReceiptNoInFirstBillData(receipt_no);
var card = $('#card').text(); }
var kbz_amt = "<%= @kbz_pay_amount %>";
var is_kbz = false;
if (kbz_amt > 0) {
is_kbz = true
}
var tax_type = localStorage.getItem("tax_type") ? localStorage.getItem("tax_type") : 'all'; $("#loading_wrapper").hide();
// calculate_member_discount(sale_id,tax_type);
/* check credit payment or not*/
var url = "<%= foodcourt_payment_cash_path %>";
$.ajax({type: "POST",
url: url,
data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type + "&is_kbz=" + is_kbz+"&account_no="+customer_mamber_card_no,
success:function(result) {
/* start delete receipt no in first bill*/
if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){
var receipt_no = ($("#receipt_no").html()).trim();
deleteReceiptNoInFirstBillData(receipt_no);
}
/* end delete receipt no in first bill*/
localStorage.removeItem("cash");
swal({
title: "Payment Successful!",
text: "Thank You !",
type: 'success',
html: true,
closeOnConfirm: true,
closeOnCancel: false,
allowOutsideClick: false
},
function (isConfirm) {
$("#loading_wrapper").show();
$('.confirm').attr("disabled","disabled");
window.location.href = "<%= foodcourt_food_court_path %>";
});
$("#loading_wrapper").hide();
}
});
var second_display_lookup = $("#display_type").val(); var second_display_lookup = $("#display_type").val();
if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){ if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){
customer_display_view(null,"reload"); customer_display_view(null,"reload");
} }
swal({
title: "Payment Successful!",
text: "Thank You !",
type: 'success',
html: true,
closeOnConfirm: true,
closeOnCancel: false,
allowOutsideClick: false
},
function (isConfirm) {
$("#loading_wrapper").show();
$('.confirm').attr("disabled","disabled");
window.location.href = "<%= foodcourt_food_court_path %>";
});
} else { } else {
var insufficient_message = result.message + '<br> Card balance : ' + customer_card_balance var insufficient_message = result.message + '<br> Card balance : ' + customer_card_balance
swal({ swal({
@@ -815,7 +794,7 @@ $(document).ready(function(){
closeOnCancel: false, closeOnCancel: false,
allowOutsideClick: false allowOutsideClick: false
}, function () { }, function () {
location.reload(); window.location.href = '/foodcourt/food_court';
}); });
$("#loading_wrapper").hide(); $("#loading_wrapper").hide();
} }

View File

@@ -14,4 +14,3 @@
- default - default
- [high_priority, 2] - [high_priority, 2]
:demon: true :demon: true

View File

@@ -0,0 +1,5 @@
class AddIndexSaleIdOnBookings < ActiveRecord::Migration[5.1]
def change
add_index :bookings, [:shop_code, :sale_id]
end
end