update for addorder and printer
This commit is contained in:
@@ -131,60 +131,62 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[: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
|
||||
|
||||
@@ -234,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
|
||||
|
||||
|
||||
@@ -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)
|
||||
booking = sale_data.booking
|
||||
|
||||
if current_user.role == 'cashier'
|
||||
cashier_terminal = shift.cashier_terminal
|
||||
elsif booking.dining_facility_id
|
||||
cashier_terminal = booking.dining_facility.cashier_terminal
|
||||
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
|
||||
cashier_terminal = sale_data.shift_sale.cashier_terminal
|
||||
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
|
||||
customer = sale_data.customer
|
||||
|
||||
#record for sale audit
|
||||
action_by = current_user.name
|
||||
type = "FIRST_BILL"
|
||||
@@ -113,21 +93,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
if(Sale.exists?(sale_id))
|
||||
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 #################'
|
||||
@@ -141,14 +107,12 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
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]
|
||||
bookings = saleObj.booking
|
||||
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if !shift.nil?
|
||||
@@ -170,97 +134,78 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
|
||||
# For Print
|
||||
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
||||
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
||||
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"
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
@@ -4,6 +4,8 @@ class DiningFacility < ApplicationRecord
|
||||
has_one :dining_charge
|
||||
has_one :cashier_terminal_by_zone, foreign_key: "zone_id", primary_key: "zone_id"
|
||||
has_one :cashier_terminal, through: :cashier_terminal_by_zone
|
||||
has_many :order_queue_process_by_zones, foreign_key: "zone_id", primary_key: "zone_id"
|
||||
has_many :order_queue_stations, -> { where(is_active: true) }, through: :order_queue_process_by_zones
|
||||
|
||||
has_many :bookings
|
||||
|
||||
|
||||
@@ -132,7 +132,6 @@ class Order < ApplicationRecord
|
||||
menu_items = MenuItem.search_by_item_code(item_instance_codes)
|
||||
menu_items += Product.search_by_product_code(item_instance_codes) if menu_items.length < item_instance_codes.length
|
||||
|
||||
new_order_items = []
|
||||
items.each do |order_item|
|
||||
menu_item = menu_items.find { |i| i[:item_instance_code].downcase == order_item[:item_instance_code].downcase }
|
||||
sub_order_items = []
|
||||
@@ -144,7 +143,7 @@ class Order < ApplicationRecord
|
||||
end
|
||||
end
|
||||
sub_order_items = sub_order_items.to_json
|
||||
new_order_items << OrderItem.new({
|
||||
self.order_items.build({
|
||||
item_code: menu_item[:item_code],
|
||||
item_instance_code: order_item[:item_instance_code],
|
||||
item_name: menu_item[:name],
|
||||
@@ -159,7 +158,6 @@ class Order < ApplicationRecord
|
||||
})
|
||||
end
|
||||
|
||||
self.order_items << new_order_items
|
||||
self.item_count = self.order_items.count
|
||||
self.save!
|
||||
|
||||
@@ -408,62 +406,28 @@ class Order < ApplicationRecord
|
||||
print_status = nil
|
||||
cup_status = nil
|
||||
|
||||
#Send to background job for processing
|
||||
order = Order.find(order_id)
|
||||
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||
#Send to background job for processing
|
||||
order = Order.find(order_id)
|
||||
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
cup_status = `#{"sudo service cups status"}`
|
||||
print_status = check_cup_status(cup_status)
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
if Printer::PrinterWorker.printers.blank?
|
||||
msg = 'Print Error ! Please contact to service'
|
||||
ActionCable.server.broadcast "call_waiter_channel", table: msg, time:'print_error', from: ''
|
||||
end
|
||||
end
|
||||
|
||||
if print_status
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, source)
|
||||
end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
else
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
cup_start = `#{"sudo service cups start"}`
|
||||
cup_status = `#{"sudo service cups status"}`
|
||||
print_status = check_cup_status(cup_status)
|
||||
end
|
||||
|
||||
if print_status
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, source)
|
||||
end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
else
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
|
||||
msg = ' Print Error ! Please contact to service'
|
||||
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error'
|
||||
end
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, source)
|
||||
end
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
end
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, order_source)
|
||||
end
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
ActionCable.server.broadcast "order_queue_station_channel", order: assign_order, from: from
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_cup_status(status)
|
||||
|
||||
@@ -15,14 +15,14 @@ class OrderQueueStation < ApplicationRecord
|
||||
validates_presence_of :station_name, :printer_name
|
||||
|
||||
def process_order(order, table_id, order_source = nil, pdf_status = nil ,change_to=nil, current_user=nil)
|
||||
oqs_stations = OrderQueueStation.active
|
||||
order_items = order.order_items
|
||||
|
||||
if table_id.to_i > 0
|
||||
# get dining
|
||||
dining = DiningFacility.find(table_id)
|
||||
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}").pluck(:order_queue_station_id)
|
||||
oqs_stations = oqs_stations.select { |s| oqs_by_zones.include? s.id }
|
||||
oqs_stations = dining.order_queue_stations
|
||||
else
|
||||
oqs_stations = OrderQueueStation.active
|
||||
end
|
||||
|
||||
assigned_order_items = []
|
||||
@@ -30,12 +30,12 @@ class OrderQueueStation < ApplicationRecord
|
||||
|
||||
# ToDo per item per printer
|
||||
oqs_stations.each do |oqs|
|
||||
oqs_order_items = nil
|
||||
oqs_order_items = order_items.select { |i| JSON.parse(oqs.processing_items).include? i.item_code }
|
||||
assigned_order_items += oqs_order_items.map { |i| AssignedOrderItem.new({ order: order, item_code: i.item_code, instance_code: i.item_instance_code, order_queue_station: oqs, print_status: false, delivery_status: false }) }
|
||||
oqs_order_items_by_zones << { oqs: oqs, oqs_order_items: oqs_order_items }
|
||||
|
||||
print_status = false
|
||||
if oqs.auto_print && order_source != "quick_service"
|
||||
print_status = true
|
||||
if oqs_order_items.length > 0
|
||||
if oqs.cut_per_item
|
||||
print_slip_item(oqs, order, oqs_order_items, pdf_status, change_to, current_user, table_id)
|
||||
@@ -44,9 +44,9 @@ class OrderQueueStation < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assigned_order_items.each(&:save)
|
||||
oqs_order_items.each { |i| AssignedOrderItem.create({ order: order, item_code: i.item_code, instance_code: i.item_instance_code, order_queue_station: oqs, print_status: print_status, delivery_status: false }) }
|
||||
end
|
||||
end
|
||||
|
||||
def pay_process_order_queue (order_id, table_id)
|
||||
@@ -155,13 +155,10 @@ class OrderQueueStation < ApplicationRecord
|
||||
else
|
||||
move_print_pdf(change_to,current_user,table_id,order_items,oqs)
|
||||
end
|
||||
|
||||
AssignedOrderItem.where("order_id = ?", order.order_id).update_all(print_status: true)
|
||||
end
|
||||
|
||||
#Print order_item in 1 slip per item
|
||||
def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
|
||||
|
||||
if pdf_status.nil?
|
||||
# order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first()
|
||||
# print when complete click
|
||||
@@ -176,8 +173,6 @@ class OrderQueueStation < ApplicationRecord
|
||||
else
|
||||
move_print_pdf(change_to,current_user,table_id,assigned_items,oqs)
|
||||
end
|
||||
|
||||
AssignedOrderItem.where("order_id = ?", order.order_id).update_all(print_status: true)
|
||||
end
|
||||
|
||||
def move_print_pdf(change_to,current_user,change_from,order_items,oqs)
|
||||
|
||||
@@ -23,28 +23,18 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
pdf.render_file filename
|
||||
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
|
||||
return filename, order_id, oqs.printer_name
|
||||
end
|
||||
|
||||
# Query for per order
|
||||
def print_order_summary(print_settings,oqs, order_id, order_items, print_status, before_updated_qty="", options="")
|
||||
def print_order_summary(print_settings, oqs, order_id, order_items, print_status, before_updated_qty="", options="")
|
||||
#Use CUPS service
|
||||
#Generate PDF
|
||||
#Print
|
||||
@@ -55,7 +45,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
end
|
||||
|
||||
shop = Shop.current_shop
|
||||
directory_name = 'public/orders_'+shop.shop_code
|
||||
directory_name = "public/orders_#{shop.shop_code}"
|
||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||
|
||||
# For Print Per Item
|
||||
@@ -64,10 +54,10 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
order_items.each do |odi|
|
||||
odi_item = print_query('order_item', odi.order_items_id)
|
||||
|
||||
filename = directory_name + "/order_item_#{order_id}" + ".pdf"
|
||||
filename = directory_name + "/order_item_#{order_id}.pdf"
|
||||
# filename = "tmp/order_item_#{order_id}" + ".pdf"
|
||||
# For Item Options
|
||||
options = odi.options == "[]"? "" : odi.options
|
||||
options = odi.options == "[]" ? "" : odi.options
|
||||
|
||||
# check for item not to show
|
||||
#if odi.price != 0
|
||||
@@ -75,19 +65,10 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
# pdf.render_file "tmp/order_item.pdf"
|
||||
pdf.render_file filename
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
end
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
end
|
||||
#end
|
||||
end
|
||||
@@ -95,33 +76,24 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
else
|
||||
order = print_query('order_summary', order_id)
|
||||
|
||||
filename = directory_name + "/order_summary_#{order_id}" + ".pdf"
|
||||
filename = directory_name + "/order_summary_#{order_id}.pdf"
|
||||
# filename = "tmp/order_summary_#{order_id}" + ".pdf"
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings, order, print_status, order_items, oqs.use_alternate_name, before_updated_qty)
|
||||
|
||||
pdf.render_file filename
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
end
|
||||
return filename, order_id, oqs.printer_name
|
||||
end
|
||||
|
||||
# Print for orders in booking
|
||||
def print_booking_summary(print_settings,oqs, booking_id, print_status,before_updated_qty="")
|
||||
def print_booking_summary(print_settings, oqs, booking_id, print_status,before_updated_qty="")
|
||||
# Must be one print
|
||||
if print_settings.print_copies == 0
|
||||
print_settings.print_copies = 1
|
||||
@@ -146,36 +118,10 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
# check for item not to show
|
||||
#if odi.price != 0
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings, odi, print_status, options, oqs.use_alternate_name, before_updated_qty)
|
||||
|
||||
pdf.render_file filename
|
||||
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
end
|
||||
#end
|
||||
end
|
||||
# For Print Order Summary
|
||||
else
|
||||
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
|
||||
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
||||
|
||||
pdf.render_file filename
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
@@ -183,14 +129,22 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#end
|
||||
end
|
||||
# For Print Order Summary
|
||||
else
|
||||
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
|
||||
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings, order, print_status, oqs.use_alternate_name, before_updated_qty)
|
||||
|
||||
pdf.render_file filename
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
end
|
||||
return filename, booking_id, oqs.printer_name
|
||||
end
|
||||
@@ -206,14 +160,14 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
.joins("left join menu_items as item ON item.item_code = order_items.item_code")
|
||||
|
||||
if type == "order_item"
|
||||
query.where("order_items.order_items_id = '#{ id }'")
|
||||
query.where("order_items.order_items_id = ?", id)
|
||||
.group("order_items.item_code")
|
||||
elsif type == "order_summary"
|
||||
query.where("orders.order_id = '#{ id }'")
|
||||
query.where("orders.order_id = ?", id)
|
||||
.group("order_items.order_items_id")
|
||||
else
|
||||
# order summary for booking
|
||||
query.where("b.booking_id = '#{ id }'")
|
||||
query.where("b.booking_id = ?", id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -37,14 +37,15 @@ class Printer::PrinterWorker
|
||||
Cups.default_printer
|
||||
end
|
||||
|
||||
def print(file_path,printer_destination = nil )
|
||||
def self.printer_exists?(printer)
|
||||
Cups.show_destinations.include? printer
|
||||
end
|
||||
|
||||
def print(file_path, printer_destination = nil )
|
||||
if printer_destination.nil?
|
||||
printer_destination = self.printer_destination
|
||||
end
|
||||
|
||||
puts printer_destination
|
||||
puts '........Printer Destination..........'
|
||||
|
||||
copy = self.print_copies
|
||||
#Print only when printer information is not null
|
||||
if !self.printer_destination.nil?
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class OrderSummaryPdf < Prawn::Document
|
||||
include NumberFormattable
|
||||
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
|
||||
def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty)
|
||||
def initialize(print_settings, order, print_status, order_items = nil, alt_name, before_updated_qty)
|
||||
self.page_width = print_settings.page_width
|
||||
self.page_height = print_settings.page_height
|
||||
self.header_font_size = print_settings.header_font_size.to_i
|
||||
|
||||
Reference in New Issue
Block a user