add print action cable

This commit is contained in:
NyanLinHtut
2020-07-28 13:54:08 +06:30
parent 8f0950f5a1
commit 366f98e51b
11 changed files with 118 additions and 25 deletions

View File

@@ -0,0 +1,10 @@
class PrintChannel < ApplicationCable::Channel
def subscribed
stream_from "print_channel"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
stop_all_streams
end
end

View File

@@ -111,6 +111,7 @@ class Origami::ShiftsController < BaseOrigamiController
@total_dinein = ShiftSale.get_total_dinein(@shift).total_dinein_amount
@total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount
@total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount
@other_charges = ShiftSale.get_other_charges(@shift)
@total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments
@payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method")
# get printer info
@@ -128,6 +129,31 @@ class Origami::ShiftsController < BaseOrigamiController
printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments,@payment_methods)
end
end
p "close cashier print<==============================="
p @other_charges
p @total_amount_by_account
ActionCable.server.broadcast("print_channel",
queue: "Cashier",
unique_code: print_settings.unique_code,
print_copies: print_settings.print_copies,
data: {
shop_details: shop_details.as_json,
shift_sale: @shift,
cashier_terminal: cashier_terminal,
shift_employee: @shift.employee,
sale_items: @sale_items,
sale_taxes: @sale_taxes,
other_payment: @other_payment,
total_amount_by_account: @total_amount_by_account,
total_discount_by_account: @total_discount_by_account,
total_member_discount: @total_member_discount,
total_waste: @total_waste,
total_spoile: @total_spoile,
other_charges: @other_charges,
total_other_charges: @total_other_charges,
total_credit_payments: @total_credit_payments
}
)
end
Employee.logout(session[:session_token])
session[:session_token] = nil

View File

@@ -171,6 +171,15 @@ class Booking < ApplicationRecord
return @orders, @order_items, @sales, @sale_items, @sale_taxes, @sale_payments, @sale_orders, @sale_audits, @bookings, @assigned_order_items, @shift_sales
end
def self.get_booking_id(order_no)
booking = Booking.joins(" JOIN booking_orders bo ON bo.booking_id = bookings.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
private
def generate_custom_id
if self.booking_id.nil?

View File

@@ -85,6 +85,18 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
booking_id = Booking.get_booking_id(order_id) #order[0].order_id
ActionCable.server.broadcast("print_channel",
queue: oqs.station_name,
unique_code: print_settings.unique_code,
print_copies: print_settings.print_copies,
data: {
order_item: order_items,
order: order.as_json(methods: :type),
print_status: "",
booking_id: booking_id,
precision: print_settings.precision}
)
#For print copy
# pdf.render_file filename.gsub(".","-copy.")
# self.print(filename.gsub(".","-copy."), oqs.printer_name)

View File

@@ -42,17 +42,17 @@ class Printer::PrinterWorker
end
def print(file_path, printer_destination = nil )
if printer_destination.nil?
printer_destination = self.printer_destination
end
copy = self.print_copies
#Print only when printer information is not null
if !self.printer_destination.nil?
(1..copy).each do
page = Cups::PrintJob.new(file_path, printer_destination)
page.print
end
end
# if printer_destination.nil?
# printer_destination = self.printer_destination
# end
#
# copy = self.print_copies
# #Print only when printer information is not null
# if !self.printer_destination.nil?
# (1..copy).each do
# page = Cups::PrintJob.new(file_path, printer_destination)
# page.print
# end
# end
end
end

View File

@@ -106,6 +106,34 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
pdf = ReceiptBillOrderPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation)
end
ActionCable.server.broadcast("print_channel",
queue: "Cashier",
unique_code: print_settings.unique_code,
print_copies: print_settings.print_copies,
data: {
shop_details: shop_details.as_json,
body: { sale_data: sale_data,
booking: sale_data.bookings,
dining_facility: sale_data.bookings[0].dining_facility.as_json(methods: :type),
sale_taxes: sale_data.sale_taxes,
latest_order_no: latest_order_no,
sale_items: sale_items,
precision: print_settings.precision,
delimiter: print_settings.delimiter,
member_info: member_info,
customer_name: customer_name,
rebate_amount: rebate_amount,
current_balance: balance,
card_data: card_data,
card_balance_amount: card_balance_amount,
discount_price_by_accounts: discount_price_by_accounts,
item_price_by_accounts: item_price_by_accounts,
sale_payments: sale_data.sale_payments,
},
footer: { printed_status: printed_status, footer_text: "Thank You! See you Again" }
}
)
# print as print copies in printer setting
count = printer_settings.print_copies

View File

@@ -961,7 +961,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
sale_cash = select(Sale.column_names).select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
@@ -984,7 +984,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
sale_cash = select(Sale.column_names).select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
@@ -1008,7 +1008,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
sale_cash = select(Sale.column_names).select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
@@ -1067,7 +1067,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
sale_cash = select(Sale.column_names).select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
@@ -1090,7 +1090,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
sale_cash = select(Sale.column_names).select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
@@ -1114,7 +1114,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
sale_cash = select(Sale.column_names).select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.empty? ? '""' : payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")

View File

@@ -211,6 +211,11 @@ class ShiftSale < ApplicationRecord
.first()
end
def self.get_other_charges(shift)
query = SaleItem.joins("JOIN sales as s ON s.sale_id = sale_items.sale_id")
.where('shift_sale_id =? and s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null',shift.id)
end
def self.search(filter,from,to)
if filter.blank?
keyword = ''

View File

@@ -597,7 +597,8 @@ class CloseCashierPdf < Prawn::Document
def other_charges_detail(total_other_charges)
total_charges = 0
total_charges_items = 0
p "total other charges<========================="
p total_other_charges
unless total_other_charges.nil?
y_position = cursor
bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do
@@ -611,6 +612,7 @@ class CloseCashierPdf < Prawn::Document
total_other_charges.each do |charges|
move_down 3
p charges['product_name']
add_item_line(charges['product_name'], charges['unit_price'].to_i, charges['total_item'].to_i, charges['grand_total'].to_i)
total_charges_items += charges['total_item'].to_i

View File

@@ -54,6 +54,7 @@ Rails.application.configure do
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.action_cable.disable_request_forgery_protection = true
# Set Cable URL
# config.action_cable.url = "ws://192.168.1.196:3002/cable"
end