From 366f98e51b52e7e4a51948af5f9259b87ed9c899 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Tue, 28 Jul 2020 13:54:08 +0630 Subject: [PATCH 01/11] add print action cable --- app/channels/print_channel.rb | 10 +++++++ app/controllers/origami/shifts_controller.rb | 26 +++++++++++++++++ app/models/booking.rb | 9 ++++++ app/models/printer/order_queue_printer.rb | 12 ++++++++ app/models/printer/printer_worker.rb | 24 ++++++++-------- app/models/printer/receipt_printer.rb | 30 +++++++++++++++++++- app/models/sale.rb | 12 ++++---- app/models/shift_sale.rb | 7 ++++- app/pdf/close_cashier_pdf.rb | 4 ++- app/pdf/receipt_bill_pdf.rb | 8 +++--- config/environments/development.rb | 1 + 11 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 app/channels/print_channel.rb diff --git a/app/channels/print_channel.rb b/app/channels/print_channel.rb new file mode 100644 index 00000000..565622cd --- /dev/null +++ b/app/channels/print_channel.rb @@ -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 diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index be13f2d0..4045eef3 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -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 diff --git a/app/models/booking.rb b/app/models/booking.rb index 3add744b..276ef53e 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -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? diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 20da8fcd..951783cb 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -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) diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index d30af42d..4dc057b9 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -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 diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index ac3e6f3f..b9828dec 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -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 @@ -126,7 +154,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end elsif printed_status == 'credit_payment' filename = directory_name + "/receipt_bill_credit_#{sale_data.receipt_no}.pdf" - pdf.render_file filename + pdf.render_file filename self.print(directory_name + "/receipt_bill_credit_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) end else diff --git a/app/models/sale.rb b/app/models/sale.rb index 69398753..2dd3a522 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -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") diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index a3545863..8ded4de2 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -132,7 +132,7 @@ class ShiftSale < ApplicationRecord self.commercial_taxes = self.commercial_taxes.to_f - tax.to_f self.total_rounding = self.total_rounding - saleobj.rounding_adjustment self.total_void = self.total_void + saleobj.grand_total - + if saleobj.customer.customer_type == "Dinein" self.dining_count = self.dining_count - 1 else @@ -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 = '' diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 11cb139b..1afc13e4 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -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 diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 198c0a12..374e014b 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -96,7 +96,7 @@ class ReceiptBillPdf < Prawn::Document if kbz_pay_status if printed_status == 'credit_payment' printed_status = 'Paid' - end + end kbzpay_qr_generator(printed_status, qr_code) end @@ -444,7 +444,7 @@ class ReceiptBillPdf < Prawn::Document # sql = "SELECT SUM(payment_amount) # FROM sale_payments where payment_method='creditnote' # and sale_id='#{sale_data.sale_id}'" - + if printed_status == 'credit_payment' sale_payments = SalePayment.select(:payment_amount, :payment_method, :updated_at) .where("sale_id = '#{sale_data.sale_id}' AND payment_method != 'creditnote'") @@ -467,7 +467,7 @@ class ReceiptBillPdf < Prawn::Document THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id) .group("payment_method") end - + sale_payments.each do |payment| y_position = cursor if payment.payment_method == "paypar" @@ -677,7 +677,7 @@ class ReceiptBillPdf < Prawn::Document query = sale_data.sale_payments .merge(SalePayment.where.not(payment_method: 'creditnote') .or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount))))) - + query.each do |payment| if payment.payment_method == "creditnote" diff --git a/config/environments/development.rb b/config/environments/development.rb index d1fddff2..71e117c4 100755 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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 From b74ef4bff1f1780b0d1bfb2bf0634016c3a6ed65 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Wed, 29 Jul 2020 11:36:43 +0630 Subject: [PATCH 02/11] move table & order item actioncable added --- app/models/printer/order_queue_printer.rb | 12 ++++++++++++ app/models/printer/receipt_printer.rb | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 951783cb..14cc3c67 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -13,7 +13,19 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # check for item not to show # if order_item[0].price != 0 pdf = print_settings.unique_code.constantize.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) + booking_id = Booking.get_booking_id(order_id) # end + 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_item[0].as_json(methods: :type), + print_status: print_status.gsub(/[()]/, ""), + booking_id: booking_id, + precision: print_settings.precision + } + ) shop = Shop.current_shop directory_name = 'public/orders_'+shop.shop_code diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index b9828dec..ff6cc8e6 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -211,6 +211,21 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #no print in cloud server self.print("tmp/print_move_table.pdf", oqs.printer_name) end + ActionCable.server.broadcast("print_channel", + queue: oqs.station_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + type: type, + body: { + to: to, + from: from, + date: date, + moved_by: moved_by, + order_items: order_items.as_json, + }, + } + ) end #Bill Receipt Print From 4a2dd294abf453b74b056b9d4fb15beb7aa165f5 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Wed, 29 Jul 2020 15:24:46 +0630 Subject: [PATCH 03/11] sale item report print action cable added --- app/models/printer/cashier_station_printer.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 63ffc53e..8bb46542 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -86,6 +86,25 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker if print_settings.unique_code == "SaleItemsPdf" pdf = SaleItemsPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) + + ActionCable.server.broadcast("print_channel", + queue: 'Cashier', + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + sale_items: sale_items.as_json, + total_other_charges: total_other_charges, + shop_details:shop_details.as_json, + sale_details: { + period: period_name, + type: type, + account: account, + from_date: from_date, + to_date: to_date, + shift: shift_name, + }, + } + ) puts 'Printing!!!!' end if print_settings.unique_code == "SaleItemsStarPdf" From 61a1189083d85c016a09136855f2a9c5ce2905d2 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Thu, 6 Aug 2020 14:05:20 +0630 Subject: [PATCH 04/11] print_channel with shop_code --- app/channels/print_channel.rb | 2 +- app/controllers/origami/shifts_controller.rb | 2 +- app/models/printer/cashier_station_printer.rb | 2 +- app/models/printer/order_queue_printer.rb | 7 +++++-- app/models/printer/receipt_printer.rb | 4 ++-- app/models/shop.rb | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/channels/print_channel.rb b/app/channels/print_channel.rb index 565622cd..b27223e1 100644 --- a/app/channels/print_channel.rb +++ b/app/channels/print_channel.rb @@ -1,6 +1,6 @@ class PrintChannel < ApplicationCable::Channel def subscribed - stream_from "print_channel" + stream_from "print_channel_#{params[:shop_code]}" end def unsubscribed diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 4045eef3..cdc2950a 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -132,7 +132,7 @@ class Origami::ShiftsController < BaseOrigamiController p "close cashier print<===============================" p @other_charges p @total_amount_by_account - ActionCable.server.broadcast("print_channel", + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: "Cashier", unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 8bb46542..7f290133 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -87,7 +87,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker if print_settings.unique_code == "SaleItemsPdf" pdf = SaleItemsPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) - ActionCable.server.broadcast("print_channel", + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: 'Cashier', unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 14cc3c67..5b1231b6 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -15,7 +15,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf = print_settings.unique_code.constantize.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) booking_id = Booking.get_booking_id(order_id) # end - ActionCable.server.broadcast("print_channel", + puts "print_channel_#{Shop.current_shop.shop_code}" + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: oqs.station_name, unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, @@ -98,7 +99,9 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker self.print(filename, oqs.printer_name) end booking_id = Booking.get_booking_id(order_id) #order[0].order_id - ActionCable.server.broadcast("print_channel", + puts "printing>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + puts "print_channel_#{Shop.current_shop.shop_code}" + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: oqs.station_name, unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index ff6cc8e6..6adcca25 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -106,7 +106,7 @@ 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", + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: "Cashier", unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, @@ -211,7 +211,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #no print in cloud server self.print("tmp/print_move_table.pdf", oqs.printer_name) end - ActionCable.server.broadcast("print_channel", + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: oqs.station_name, unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, diff --git a/app/models/shop.rb b/app/models/shop.rb index 41110515..dbe6c58b 100755 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -8,7 +8,7 @@ class Shop < ApplicationRecord accepts_nested_attributes_for :display_images def file_data=(input_data) - self.data = input_data.read + self.data = input_data.read end def self.current_shop From 583d7ee473d76a63658dd1d2f25586ba0da1e16c Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Wed, 12 Aug 2020 15:37:38 +0630 Subject: [PATCH 05/11] fixed print serviceaction cable --- app/controllers/origami/shifts_controller.rb | 35 ++----------- app/models/order_queue_station.rb | 4 +- app/models/printer/cashier_station_printer.rb | 49 ++++++++++++----- app/models/printer/order_queue_printer.rb | 52 +++++++++---------- app/models/printer/receipt_printer.rb | 20 ++++--- app/models/sale.rb | 4 +- app/models/seed_generator.rb | 8 +-- app/models/shift_sale.rb | 4 +- config/secrets.yml | 2 +- 9 files changed, 89 insertions(+), 89 deletions(-) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index cdc2950a..eb894d58 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -67,10 +67,7 @@ class Origami::ShiftsController < BaseOrigamiController end end - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server - - - + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server # if !close_cashier_print[0].nil? # @close_cashier_print = close_cashier_print[0][1] # end @@ -126,34 +123,10 @@ class Origami::ShiftsController < BaseOrigamiController end find_close_cashier_print = Lookup.collection_of('close_cashier_print') if find_close_cashier_print[0][1].to_i > 0 - 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) + 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,@other_charges) end - end - p "close cashier print<===============================" - p @other_charges - p @total_amount_by_account - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - 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 + end Employee.logout(session[:session_token]) session[:session_token] = nil diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index f650b807..b86734a7 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -176,7 +176,7 @@ class OrderQueueStation < ApplicationRecord end def move_print_pdf(change_to,current_user,change_from,order_items,oqs) - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server # get printer info @from = (DiningFacility.find(change_from)).name @to = (DiningFacility.find(change_to)).name @@ -197,6 +197,6 @@ class OrderQueueStation < ApplicationRecord printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by,order_items,oqs) # end # end - end + # end end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 7f290133..01bfd3c9 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -38,7 +38,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # self.print(filename, cashier_terminal.printer_name) # end - def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods) + def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods,other_charges) if !sale_items.blank? or !sale_items.nil? @account_cate_count = Hash.new {|hash, key| hash[key] = 0} @@ -74,10 +74,32 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker end end pdf.render_file filename - #no print in cloud server if ENV["SERVER_MODE"] != "cloud" self.print(filename, cashier_terminal.printer_name) + else + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: "Cashier", + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + shop_details: shop_details.as_json, + shift_sale: shift_sale, + cashier_terminal: cashier_terminal, + shift_employee: shift_sale.employee, + sale_items: sale_items, + sale_taxes: sale_taxes, + other_payment: other_payment, + total_amount_by_account: amount, + total_discount_by_account: discount, + total_member_discount: 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 end @@ -86,7 +108,18 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker if print_settings.unique_code == "SaleItemsPdf" pdf = SaleItemsPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) + end + if print_settings.unique_code == "SaleItemsStarPdf" + pdf = SaleItemsStarPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) + end + + pdf.render_file filename + + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, print_settings.printer_name) + else ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: 'Cashier', unique_code: print_settings.unique_code, @@ -105,18 +138,6 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker }, } ) - puts 'Printing!!!!' - end - if print_settings.unique_code == "SaleItemsStarPdf" - pdf = SaleItemsStarPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) - puts 'PrintingStar!!!!' - end - - pdf.render_file filename - - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, print_settings.printer_name) end end #sqa diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 5b1231b6..b7315765 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -15,18 +15,6 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf = print_settings.unique_code.constantize.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) booking_id = Booking.get_booking_id(order_id) # end - puts "print_channel_#{Shop.current_shop.shop_code}" - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: oqs.station_name, - unique_code: print_settings.unique_code, - print_copies: print_settings.print_copies, - data: { - order_item: order_item[0].as_json(methods: :type), - print_status: print_status.gsub(/[()]/, ""), - booking_id: booking_id, - precision: print_settings.precision - } - ) shop = Shop.current_shop directory_name = 'public/orders_'+shop.shop_code @@ -38,6 +26,18 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker if ENV["SERVER_MODE"] != "cloud" self.print(filename, oqs.printer_name) + else + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: oqs.station_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + order_item: order_item[0].as_json(methods: :type), + print_status: print_status.gsub(/[()]/, ""), + booking_id: booking_id, + precision: print_settings.precision + } + ) end #For print copy # pdf.render_file filename.gsub(".","-copy.") @@ -87,6 +87,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # For Print Order Summary else + booking_id = Booking.get_booking_id(order_id) #order[0].order_id order = print_query('order_summary', order_id) filename = directory_name + "/order_summary_#{order_id}.pdf" @@ -97,21 +98,20 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker #no print in cloud server if ENV["SERVER_MODE"] != "cloud" self.print(filename, oqs.printer_name) + else + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + 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} + ) end - booking_id = Booking.get_booking_id(order_id) #order[0].order_id - puts "printing>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" - puts "print_channel_#{Shop.current_shop.shop_code}" - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - 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) diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 6adcca25..d130c96e 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -106,6 +106,7 @@ 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 + if ENV["SERVER_MODE"] == "cloud" ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: "Cashier", unique_code: print_settings.unique_code, @@ -133,6 +134,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker footer: { printed_status: printed_status, footer_text: "Thank You! See you Again" } } ) + end # print as print copies in printer setting count = printer_settings.print_copies @@ -199,18 +201,19 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print - pdf = MoveTablePdf.new(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) pdf.render_file "tmp/print_move_table.pdf" - if oqs.print_copy - self.print("tmp/print_move_table.pdf",oqs.printer_name) + if ENV["SERVER_MODE"] != "cloud" + if oqs.print_copy + self.print("tmp/print_move_table.pdf",oqs.printer_name) + else + print_settings.print_copies = 1 + print_settings.save! + #no print in cloud server + self.print("tmp/print_move_table.pdf", oqs.printer_name) + end else - print_settings.print_copies = 1 - print_settings.save! - #no print in cloud server - self.print("tmp/print_move_table.pdf", oqs.printer_name) - end ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: oqs.station_name, unique_code: print_settings.unique_code, @@ -226,6 +229,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker }, } ) + end end #Bill Receipt Print diff --git a/app/models/sale.rb b/app/models/sale.rb index 2dd3a522..d2f94cd8 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -755,7 +755,7 @@ class Sale < ApplicationRecord payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) sales = select(Sale.column_names) - .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.push('').join(', ')} + .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as `#{method == 'paypar' ? 'redeem' : method}`"}.push('').join(', ')} 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) - SUM(case when (sale_payments.payment_method not in('creditnote') and sale_audits.sale_audit_id IS NOT NULL) then sale_payments.payment_amount else 0 end) as credit_amount, @@ -776,7 +776,7 @@ class Sale < ApplicationRecord (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale, (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale, CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, - #{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(#{pm}) as #{pm}"}.push('').join(', ')} + #{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(`#{pm}`) as `#{pm}`"}.push('').join(', ')} SUM(cash_amount) as cash_amount, SUM(credit_amount) as credit_amount, SUM(foc_amount) as foc_amount diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index 482a65a1..8118b272 100755 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -1,14 +1,15 @@ class SeedGenerator < ApplicationRecord # Generate ID for Tables def self.generate_id(model, prefix) - model_name = self.get_model_name(model) + # model_name = self.get_model_name(model) + model_name = model prefix ||= '' prefix << '-' if prefix.present? if ENV["SERVER_MODE"] == 'cloud' prefix << 'C' - else + # else prefix << 'L' end @@ -22,7 +23,8 @@ class SeedGenerator < ApplicationRecord end def self.generate_ids(model, prefix, count = 1) - model_name = self.get_model_name(model) + # model_name = self.get_model_name(model) + model_name = model prefix ||= '' prefix << '-' if prefix.present? diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 8ded4de2..2b6129dc 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -152,9 +152,9 @@ class ShiftSale < ApplicationRecord def self.get_by_shift_other_payment(shift) payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) - shift_other_payments = Sale.select("sales.sale_id,sale_payments.payment_method as name") + # shift_other_payments = Sale.select("sales.sale_id,sale_payments.payment_method as name") if payment_methods.present? - shift_other_payments = shift_other_payments.select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.join(', ')}") + shift_other_payments = Sale.select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as `#{method == 'paypar' ? 'redeem' : method}`"}.join(', ')}") end shift_other_payments.select("SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") diff --git a/config/secrets.yml b/config/secrets.yml index 069b1403..9eabc5ac 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -13,7 +13,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 sx_provision_url: connect.smartsales.asia/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api - server_mode: application + server_mode: cloud cipher_type: AES-256-CBC sx_key: Wh@t1$C2L From 5dfdc7353e2aa7a8b0b76d770b753d206485983b Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 18 Aug 2020 16:11:17 +0630 Subject: [PATCH 06/11] print settings ActionCable --- Gemfile | 2 +- Gemfile.lock | 2 + README.md | 3 + app/assets/javascripts/OQS.js | 34 +-- app/assets/javascripts/application.js | 13 +- app/assets/javascripts/order_reservation.js | 100 +++---- app/assets/stylesheets/application.scss | 2 + app/assets/stylesheets/select2-material.css | 231 +++++++++++++++ app/controllers/oqs/print_controller.rb | 2 - app/helpers/print_settings_helper.rb | 3 + app/models/printer/cashier_station_printer.rb | 129 ++++----- app/models/printer/order_queue_printer.rb | 136 ++++----- app/models/printer/receipt_printer.rb | 166 +++++------ app/views/oqs/home/index.html.erb | 52 ++-- app/views/origami/home/show.html.erb | 266 +++++++++--------- .../origami/order_reservation/index.html.erb | 58 ++-- app/views/origami/payments/show.html.erb | 95 ++++--- .../pending_order/completed_sale.html.erb | 60 ++-- app/views/origami/rooms/show.html.erb | 157 ++++++----- app/views/origami/sales/show.html.erb | 56 ++-- .../origami/table_invoices/show.html.erb | 127 ++++----- app/views/print_settings/_form.html.erb | 54 ++-- .../settings/cashier_terminals/_form.html.erb | 39 +-- .../order_queue_stations/_form.html.erb | 53 ++-- app/views/transactions/sales/show.html.erb | 12 +- 25 files changed, 1050 insertions(+), 802 deletions(-) create mode 100644 app/assets/stylesheets/select2-material.css diff --git a/Gemfile b/Gemfile index 92b133de..6d6a2397 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ gem 'pg' gem 'mysql2', '~> 0.5.2' #Use PosgreSQL - +gem "select2-rails" # redis server for cable gem 'redis', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 578d79d3..eff1b2cb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -264,6 +264,7 @@ GEM tilt (>= 1.1, < 3) schema_to_scaffold (0.8.0) activesupport (>= 3.2.1) + select2-rails (4.0.13) shoulda-matchers (3.1.3) activesupport (>= 4.0.0) sidekiq (5.2.7) @@ -367,6 +368,7 @@ DEPENDENCIES rubyzip (= 1.0.0) sass-rails (~> 5.0) schema_to_scaffold + select2-rails shoulda-matchers (~> 3.1) sidekiq simple_form diff --git a/README.md b/README.md index 63ba995a..6c749590 100755 --- a/README.md +++ b/README.md @@ -77,6 +77,9 @@ For Using Star Printer **_ Need to change these print settings 1) settings/print_settings/unique_code => OrderItemStarPdf 2) settings/print_settings/unique_code => ReceiptBillStarPdf 3) settings/print_settings/unique_code => SaleItemsStarPdf _** Other print settings aren't need to change. +For Cloud ActionCable Print +settings/lookups => { type: print_settings, name: ActionCable, value: 1 } + For Show Sale Items Summary at CloseCashierPrint 1) settings/print_settings a) Check => Shift Sale Items diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 68cf44d7..76413675 100755 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -402,17 +402,17 @@ $(document).on('turbolinks:load', function() { url: '/oqs/print/print/'+assigned_item_id, data: params, success: function(result){ - // For Server Print - from jade - if ($("#server_mode").val() == "cloud") { - if(typeof code2lab != 'undefined'){ - code2lab.printFile(result.filepath.substr(6), result.printer_url); - } - } - location.reload(); - + if (!$('#print_settings').data('action-cable')) { + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + if(typeof code2lab != 'undefined'){ + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } + } + } + location.reload(); } }); - }); // Print Order Summary @@ -428,13 +428,15 @@ $(document).on('turbolinks:load', function() { url: '/oqs/print/print_order_summary/'+assigned_item_id, data: params, success: function(result){ - // For Server Print - from jade - if ($("#server_mode").val() == "cloud") { - if(typeof code2lab != 'undefined'){ - code2lab.printFile(result.filepath.substr(6), result.printer_url); - } - } - location.reload(); + if (!$('#print_settings').data('action-cable')) { + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + if(typeof code2lab != 'undefined'){ + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } + } + } + location.reload(); } }); }); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index bd9018fb..7317b338 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -36,6 +36,7 @@ //= require custom.js //= require jquery-fileupload/basic //= require induties/induties.js +//= require select2 $(document).ready(function() { $('.count-to').countTo(); @@ -65,7 +66,7 @@ $(document).ready(function() { clearButton: true, date: false }); - + // Image Upload $("#simple_menu_item_image_path").fileinput({ previewFileType: "image", @@ -148,7 +149,7 @@ $(document).ready(function() { '\n', } }); - + $("#commissioner_image_path").fileinput({ previewFileType: "image", allowedFileExtensions: ["jpg", "gif", "png"], @@ -167,7 +168,7 @@ $(document).ready(function() { ' {caption}\n' + '\n', } - }); + }); $("#employee_image_path").fileinput({ previewFileType: "image", @@ -187,7 +188,7 @@ $(document).ready(function() { ' {caption}\n' + '\n', } - }); + }); $("#shop_image").fileinput({ previewFileType: "image", @@ -227,7 +228,7 @@ $(document).ready(function() { ' {caption}\n' + '\n', } - }); + }); // first input focus for all form $('form:first *input[data-behaviour!=datepicker]:input[type!=hidden]:first').focus(); @@ -252,4 +253,4 @@ Chart.scaleService.updateScaleDefaults('linear', { } } }); -/* chartkick js YAxis value override */ \ No newline at end of file +/* chartkick js YAxis value override */ diff --git a/app/assets/javascripts/order_reservation.js b/app/assets/javascripts/order_reservation.js index f74f1fa9..6c141ddc 100644 --- a/app/assets/javascripts/order_reservation.js +++ b/app/assets/javascripts/order_reservation.js @@ -1,6 +1,6 @@ //= require custom.js -$(function() { +$(function() { $("#discount").hide(); $(".expected_time").hide(); $('#accepted').hide(); @@ -11,7 +11,7 @@ $(function() { $(".accepted_time").hide(); $(".kitchen_time").hide(); $(".ready_time").hide(); - $(function() { + $(function() { $('.first-1').click(); }); @@ -213,8 +213,8 @@ $(function() { function warnBeforeRedirect(linkURL) { swal({ - title: "Alert!", - text: "Are you sure you want to close cashier?", + title: "Alert!", + text: "Are you sure you want to close cashier?", type: "warning", showCancelButton: true }, function() { @@ -278,13 +278,13 @@ function refreshDetailData(){ $("#payment_type").text(""); } -//show order list -function show_order_detail(url,sr_no){ +//show order list +function show_order_detail(url,sr_no){ // $('.summary-items').html(""); //Start Ajax - $.ajax({ - type: "GET", - url: url, + $.ajax({ + type: "GET", + url: url, data: {}, dataType: "json", success: function(data) { @@ -334,12 +334,12 @@ function show_order_detail(url,sr_no){ $("#ready_delivery_time").html(ready_time); } } - + var newDate = new Date(data.requested_time); var time = timeFormat(newDate); // var requested_date = newDate.getFullYear() + '-' + (newDate.getMonth() >= 10? newDate.getMonth() : '0' + (newDate.getMonth() + 1)) +'-'+ (newDate.getDate() >= 10? newDate.getDate() : '0' + newDate.getDate()) +' '+time; var requested_date = getOrderMonth(newDate.getMonth()) +' '+ (newDate.getDate() >= 10? newDate.getDate() : '0' + newDate.getDate()) +', '+newDate.getFullYear()+'('+getOrderDay(newDate.getDay())+')'+' '+time; - + if((data.expected_waiting_time!=undefined) && (data.expected_waiting_time!=null)){ // var expDate = new Date(data.expected_waiting_time); // var exptime = timeFormat(expDate); @@ -367,7 +367,7 @@ function show_order_detail(url,sr_no){ if(items!=undefined && items!=""){ if(items.length > 0){ - for(var i in items) { + for(var i in items) { var item_price = 0; if(items[i].price > 0){ item_price = items[i].price; @@ -378,7 +378,7 @@ function show_order_detail(url,sr_no){ var check_mobile =document.getElementsByName("summary_items_mobile")[0].value; if (check_mobile == "true"){ if(items[i].options!='[]' && items[i].options!="" && items[i].options!=null){ - row = + row = '' +''+items[i].item_name +'
' @@ -417,8 +417,8 @@ function show_order_detail(url,sr_no){ } } - - + + $('.summary-items').append(row); } @@ -452,7 +452,7 @@ function show_order_detail(url,sr_no){ }else if(data.payment_type == "dinga"){ $("#payment_type").text("DINGA"); } - + $('#ref_no').text(data.transaction_ref); $('#callback_url').text(data.callback_url); $('#order_id').text(data.order_reservation_id); @@ -494,16 +494,16 @@ function show_order_detail(url,sr_no){ }else{ $("#invoice_no").text(data["order_reservation_id"]); } - + } } } }); - //end Ajax + //end Ajax } -function callback_url(callback,ref_no,order_id,status,min_type,time,exptime,reason,approved_code){ +function callback_url(callback,ref_no,order_id,status,min_type,time,exptime,reason,approved_code){ var url = 'order_reservation/update'; var post_url = "order_reservation/send_status"; var waiting_time = ""; @@ -527,16 +527,16 @@ function callback_url(callback,ref_no,order_id,status,min_type,time,exptime,reas access_code = approved_code; } - // $.ajax({ - // type: "POST", - // url: post_url, + // $.ajax({ + // type: "POST", + // url: post_url, // data: {url: callback, ref_no: ref_no, status: status, waiting_time: waiting_time, min_type: type, reason: reject_reason}, // dataType: "json", // success: function(data) { // if(data.status){ - $.ajax({ - type: "POST", - url: url, + $.ajax({ + type: "POST", + url: url, data: {order_id: order_id, ref_no: ref_no, status: status, min_type: min_type, expected_time: waiting_time, remark: reason, access_code: access_code}, dataType: "json", success: function(data) { @@ -711,7 +711,7 @@ function getOrderDay(day){ function timeFormat(date){ var isPM = date.getHours() >= 12; var isMidday = date.getHours() == 12; - var time = [(date.getHours()>10? date.getHours() : '0'+date.getHours()) - (isPM && !isMidday ? 12 : 0), + var time = [(date.getHours()>10? date.getHours() : '0'+date.getHours()) - (isPM && !isMidday ? 12 : 0), (date.getMinutes()>10? date.getMinutes() : '0'+date.getMinutes()) || '00'].join(':') + (isPM ? ' PM' : ' AM'); return time; @@ -722,8 +722,8 @@ function timeFormat(date){ function getOnlineOrderCount(){ var count = 0; //Start Ajax - $.ajax({ - async: false, + $.ajax({ + async: false, type: "GET", url: "/origami/get_order_info", dataType: "json", @@ -733,7 +733,7 @@ function getOnlineOrderCount(){ } } }); - //end Ajax + //end Ajax // alert(count); return count; } @@ -748,31 +748,33 @@ function print_receipt(){ var params = { 'filename':filename, 'receipt_no':receipt_no, 'printer_name':printer_name }; console.log(params); $.ajax({ - type: "POST", + type: "POST", url: "/origami/sale/"+sale_id+"/doemal_order/payment/print", data: params, success:function(result){ - // For Server Print - from jade - if ($("#server_mode").val() == "cloud") { - if(typeof code2lab != 'undefined'){ - code2lab.printFile(result.filepath.substr(6), result.printer_url); + if (!$('#print_settings').data('action-cable')) { + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + if(typeof code2lab != 'undefined'){ + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } + window.location.href = '/origami/order_reservation'; + } + else{ + swal({ + title: "Print Success", + text: "Complete Order", + type: 'success', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/order_reservation'; + }); } - window.location.href = '/origami/order_reservation'; - } - else{ - swal({ - title: "Print Success", - text: "Complete Order", - type: 'success', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/order_reservation'; - }); } } }); } -/* pdf print out */ \ No newline at end of file +/* pdf print out */ diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index ee797cf8..3c3de041 100755 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -12,6 +12,8 @@ @import "BSBMaterial/themes/all-themes"; @import "reset"; @import "induties/assign_in_duties"; +@import "select2"; +@import "select2-material"; /*@import "bootstrap-select/css/bootstrap-select.min";*/ diff --git a/app/assets/stylesheets/select2-material.css b/app/assets/stylesheets/select2-material.css new file mode 100644 index 00000000..a52e1654 --- /dev/null +++ b/app/assets/stylesheets/select2-material.css @@ -0,0 +1,231 @@ +.select2-container--material { + width: 100% !important; } + .select2-container--material .select2-selection--single { + background-color: transparent; + border: none; + border-bottom: 1px solid rgba(0,0,0,0.26); + border-radius: 0; + box-shadow: none; + box-sizing: content-box; + height: auto; + margin: 0; + outline: none; + padding: 0.46875rem 0 0.40625rem 0; + transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; } + .select2-container--material .select2-selection--single .select2-selection__rendered { + color: #444; + font-size: 1rem; + line-height: 18px; + padding-left: 0; } + .select2-container--material .select2-selection--single .select2-selection__clear { + cursor: pointer; + float: right; + font-weight: bold; } + .select2-container--material .select2-selection--single .select2-selection__placeholder { + color: #999; } + .select2-container--material .select2-selection--single .select2-selection__arrow { + height: 20px; + margin: 0.5rem 0 0.2rem 0; + position: absolute; + line-height: 1rem; + top: 1px; + right: 1px; + width: 20px; } + .select2-container--material .select2-selection--single .select2-selection__arrow b { + border-color: #888 transparent transparent transparent; + border-style: solid; + border-width: 5px 4px 0 4px; + height: 0; + left: 50%; + margin-left: -4px; + margin-top: -2px; + position: absolute; + top: 50%; + width: 0; } + .select2-container--material[dir="rtl"] .select2-selection--single .select2-selection__clear { + float: left; } + .select2-container--material[dir="rtl"] .select2-selection--single .select2-selection__arrow { + left: 1px; + right: auto; } + .select2-container--material.select2-container--disabled .select2-selection--single { + background-color: #eee; + cursor: default; } + .select2-container--material.select2-container--disabled .select2-selection--single .select2-selection__clear { + display: none; } + .select2-container--material.select2-container--open .select2-selection--single .select2-selection__arrow b { + border-color: transparent transparent #888 transparent; + border-width: 0 4px 5px 4px; } + .select2-container--material .select2-selection--multiple { + background-color: transparent; + border: none; + border-bottom: 1px solid #ced4da; + border-radius: 0; + box-shadow: none; + box-sizing: content-box; + cursor: text; + height: auto; + margin: 0; + outline: none; + padding: 5px 0 0 0; + transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; } + .select2-container--material .select2-selection--multiple .select2-selection__rendered { + box-sizing: border-box; + list-style: none; + margin: 0; + padding: 0 5px; + width: 100%; } + .select2-container--material .select2-selection--multiple .select2-selection__rendered li { + list-style: none; } + .select2-container--material .select2-selection--multiple .select2-selection__placeholder { + color: #999; + margin-top: 5px; + float: left; } + .select2-container--material .select2-selection--multiple .select2-selection__clear { + cursor: pointer; + float: right; + font-weight: bold; + margin-top: 5px; + margin-right: 10px; } + .select2-container--material .select2-selection--multiple .select2-selection__choice { + background-color: #ffca28; + border-radius: 16px; + color: rgba(0, 0, 0, 0.6); + cursor: default; + float: left; + margin-right: 5px; + margin-top: 6px; + padding: 0 12px; } + .select2-container--material .select2-selection--multiple .select2-selection__choice__remove { + cursor: pointer; + display: inline-block; + font-weight: bold; + float: right; + margin-left: 5px; } + .select2-container--material .select2-selection--multiple .select2-selection__choice__remove:hover { + color: #333; } + .select2-container--material[dir="rtl"] .select2-selection--multiple .select2-selection__choice, .select2-container--material[dir="rtl"] .select2-selection--multiple .select2-selection__placeholder, .select2-container--material[dir="rtl"] .select2-selection--multiple .select2-search--inline { + float: right; } + .select2-container--material[dir="rtl"] .select2-selection--multiple .select2-selection__choice { + margin-left: 5px; + margin-right: auto; } + .select2-container--material[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove { + margin-left: 2px; + margin-right: auto; } + .select2-container--material.select2-container--disabled .select2-selection--multiple { + background-color: #eee; + cursor: default; } + .select2-container--material.select2-container--disabled .select2-selection__choice__remove { + display: none; } + .select2-container--material.select2-container--open.select2-container--above .select2-selection--single, .select2-container--material.select2-container--open.select2-container--above .select2-selection--multiple { + border-top-left-radius: 0; + border-top-right-radius: 0; } + .select2-container--material.select2-container--open.select2-container--below .select2-selection--single, .select2-container--material.select2-container--open.select2-container--below .select2-selection--multiple { + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; } + .select2-container--material.select2-container--focus .select2-selection--single { + transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; + outline: 0; } + .select2-container--material.select2-container--focus .select2-selection--multiple { + transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; + outline: 0; } + .select2-container--material .select2-search--dropdown .select2-search__field { + border: none; + border-bottom: 1px solid #ced4da; + border-radius: 0; + outline: none; } + .select2-container--material .select2-search--dropdown .select2-search__field:focus:not([readonly]) { + box-shadow: 0 1px 0 0 #ced4da; + border-bottom: 1px solid #ced4da; } + .select2-container--material .select2-search--inline .select2-search__field { + background: transparent; + border: none !important; + outline: 0; + box-shadow: none !important; + -webkit-appearance: textfield; } + .select2-container--material .select2-results > .select2-results__options { + overflow-y: auto; } + .select2-container--material .select2-results__option[role=group] { + padding: 0; } + .select2-container--material .select2-results__option[aria-disabled=true] { + color: #999; } + .select2-container--material .select2-results__option[aria-selected=true] { + background-color: #ddd; } + .select2-container--material .select2-results__option .select2-results__option { + padding-left: 1em; } + .select2-container--material .select2-results__option .select2-results__option .select2-results__group { + padding-left: 0; } + .select2-container--material .select2-results__option .select2-results__option .select2-results__option { + margin-left: -1em; + padding-left: 2em; } + .select2-container--material .select2-results__option .select2-results__option .select2-results__option .select2-results__option { + margin-left: -2em; + padding-left: 3em; } + .select2-container--material .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option { + margin-left: -3em; + padding-left: 4em; } + .select2-container--material .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option { + margin-left: -4em; + padding-left: 5em; } + .select2-container--material .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option { + margin-left: -5em; + padding-left: 6em; } + .select2-container--material .select2-results__option--highlighted[aria-selected] { + background-color: #3f729b; + color: white; } + .select2-container--material .select2-results__group { + cursor: default; + display: block; + padding: 6px; } + +.select2-dropdown { + background-color: white; + border: 1px solid #ced4da; + border-radius: 4px; + box-sizing: border-box; + box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12); + display: block; + position: absolute; + left: -100000px; + width: 100%; + z-index: 1051; + -webkit-box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12); } + +.select2-results { + display: block; } + +.select2-results__options { + list-style: none; + margin: 0; + padding: 0; } + +.select2-results__option { + padding: 6px; + user-select: none; + -webkit-user-select: none; } + .select2-results__option[aria-selected] { + cursor: pointer; } + +.select2-container--open .select2-dropdown { + left: 0; } + +.select2-container--open .select2-dropdown--above { + border-bottom: none; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; } + +.select2-container--open .select2-dropdown--below { + border-top: none; + border-top-left-radius: 0; + border-top-right-radius: 0; } + +.select2-search--dropdown { + display: block; + padding: 4px; } + .select2-search--dropdown .select2-search__field { + padding: 4px; + width: 100%; + box-sizing: border-box; } + .select2-search--dropdown .select2-search__field::-webkit-search-cancel-button { + -webkit-appearance: none; } + .select2-search--dropdown.select2-search--hide { + display: none; } diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index 751e1c01..a5eca433 100755 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -51,7 +51,6 @@ class Oqs::PrintController < ApplicationController ai.save end - # filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount) if ENV["SERVER_MODE"] == "cloud" result = { :filepath => filename, @@ -119,7 +118,6 @@ class Oqs::PrintController < ApplicationController ai.save end - # filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount) if ENV["SERVER_MODE"] == "cloud" result = { :filepath => filename, diff --git a/app/helpers/print_settings_helper.rb b/app/helpers/print_settings_helper.rb index 3e712d7c..6f14d22e 100755 --- a/app/helpers/print_settings_helper.rb +++ b/app/helpers/print_settings_helper.rb @@ -1,2 +1,5 @@ module PrintSettingsHelper + def print_settings + tag.div id: 'print_settings', class: 'hidden', data: { action_cable: Lookup.collection_of('print_settings').any? { |x| x == ["ActionCable", "1"] } } + end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 01bfd3c9..1c255a42 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -38,90 +38,91 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # self.print(filename, cashier_terminal.printer_name) # end - def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods,other_charges) + def print_close_cashier(printer_settings, cashier_terminal, shift_sale, sale_items, total_other_charges_info, shop_details, sale_taxes, other_payment, amount, discount, member_discount, total_dinein, total_takeway, total_other_charges, total_waste, total_spoile, total_credit_payments, payment_methods, other_charges) + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + if !sale_items.blank? or !sale_items.nil? + @account_cate_count = Hash.new {|hash, key| hash[key] = 0} + sale_items.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} - if !sale_items.blank? or !sale_items.nil? - @account_cate_count = Hash.new {|hash, key| hash[key] = 0} - sale_items.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} + @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} + sale_items.each {|cate| @menu_cate_count[cate.menu_category_id] += 1} + @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + sale_items.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + end - @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} - sale_items.each {|cate| @menu_cate_count[cate.menu_category_id] += 1} + #Use CUPS service + #Generate PDF + #Print + cashier = shift_sale.employee.name + shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" + pdf = CloseCashierPdf.new(printer_settings, shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details, sale_taxes, other_payment, amount, discount, member_discount, total_dinein, total_takeway, total_other_charges, total_waste, total_spoile, total_credit_payments, payment_methods) + close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf - - @totalByAccount = Hash.new {|hash, key| hash[key] = 0} - sale_items.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} - end - - #Use CUPS service - #Generate PDF - #Print - cashier = shift_sale.employee.name - shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") - filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" - pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods) - close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf - - if !close_cashier_pdf.empty? - close_cashier_pdf.each do |close_cashier| - if close_cashier[0] == 'CloseCashierCustomisePdf' - if close_cashier[1] == '1' - pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) - else - pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods) + if !close_cashier_pdf.empty? + close_cashier_pdf.each do |close_cashier| + if close_cashier[0] == 'CloseCashierCustomisePdf' + if close_cashier[1] == '1' + pdf = CloseCashierCustomisePdf.new(printer_settings, shift_sale, shop_details, sale_taxes, other_payment, amount, discount, member_discount, total_dinein, total_takeway, total_other_charges, total_waste, total_spoile, total_credit_payments) + else + pdf = CloseCashierPdf.new(printer_settings, shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details, sale_taxes, other_payment, amount,discount, member_discount, total_dinein, total_takeway, total_other_charges, total_waste, total_spoile, total_credit_payments, payment_methods) + end end end end - end - pdf.render_file filename - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, cashier_terminal.printer_name) + pdf.render_file filename + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, cashier_terminal.printer_name) + end else ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: "Cashier", - unique_code: print_settings.unique_code, - print_copies: print_settings.print_copies, - data: { - shop_details: shop_details.as_json, - shift_sale: shift_sale, - cashier_terminal: cashier_terminal, - shift_employee: shift_sale.employee, - sale_items: sale_items, - sale_taxes: sale_taxes, - other_payment: other_payment, - total_amount_by_account: amount, - total_discount_by_account: discount, - total_member_discount: 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 - } + queue: cashier_terminal.printer_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + shop_details: shop_details.as_json, + shift_sale: shift_sale, + cashier_terminal: cashier_terminal, + shift_employee: shift_sale.employee, + sale_items: sale_items, + sale_taxes: sale_taxes, + other_payment: other_payment, + total_amount_by_account: amount, + total_discount_by_account: discount, + total_member_discount: 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 end def print_sale_items_report(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) - filename = "tmp/reports_sale_items.pdf" + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + filename = "tmp/reports_sale_items.pdf" - if print_settings.unique_code == "SaleItemsPdf" - pdf = SaleItemsPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) - end + if print_settings.unique_code == "SaleItemsPdf" + pdf = SaleItemsPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) + end - if print_settings.unique_code == "SaleItemsStarPdf" - pdf = SaleItemsStarPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) - end + if print_settings.unique_code == "SaleItemsStarPdf" + pdf = SaleItemsStarPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges) + end - pdf.render_file filename + pdf.render_file filename - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, print_settings.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, print_settings.printer_name) + end else ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: 'Cashier', + queue: print_settings.printer_name, unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, data: { diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index b7315765..5a145efc 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -1,94 +1,66 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker def print_order_item(print_settings, oqs, order_id, order_item_id, print_status, before_updated_qty="", options="") - # Must be one print - if print_settings.print_copies == 0 - print_settings.print_copies = 1 - print_settings.save! - end - - order_item = print_query('order_item', order_item_id) #OrderItem.find_by_item_code(item_code) - options = order_item[0].options - - # check for item not to show - # if order_item[0].price != 0 - pdf = print_settings.unique_code.constantize.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) booking_id = Booking.get_booking_id(order_id) - # end + order_item = print_query('order_item', order_item_id).first #OrderItem.find_by_item_code(item_code) - shop = Shop.current_shop - directory_name = 'public/orders_'+shop.shop_code - Dir.mkdir(directory_name) unless File.exists?(directory_name) + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + # Must be one print + if print_settings.print_copies == 0 + print_settings.print_copies = 1 + print_settings.save! + end - filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf" + options = order_item.options + # check for item not to show + pdf = print_settings.unique_code.constantize.new(print_settings, order_item, print_status, options, oqs.use_alternate_name, before_updated_qty) - pdf.render_file filename + shop = Shop.current_shop + directory_name = "public/orders_#{shop.shop_code}" + Dir.mkdir(directory_name) unless File.exists?(directory_name) - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, oqs.printer_name) + filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf" + + pdf.render_file filename + + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end + + return filename, order_id, oqs.printer_name else ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: oqs.station_name, unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, data: { - order_item: order_item[0].as_json(methods: :type), + order_item: order_item.as_json(methods: :type), print_status: print_status.gsub(/[()]/, ""), booking_id: booking_id, precision: print_settings.precision } - ) + ) 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="") - #Use CUPS service - #Generate PDF - #Print - # Must be one print - if print_settings.print_copies == 0 - print_settings.print_copies = 1 - print_settings.save! - end + booking_id = Booking.get_booking_id(order_id) #order[0].order_id + order = print_query('order_summary', order_id) - shop = Shop.current_shop - directory_name = "public/orders_#{shop.shop_code}" - Dir.mkdir(directory_name) unless File.exists?(directory_name) - - # For Print Per Item - if oqs.cut_per_item - - order_items.each do |odi| - odi_item = print_query('order_item', odi.order_items_id) - - filename = directory_name + "/order_item_#{order_id}.pdf" - # filename = "tmp/order_item_#{order_id}" + ".pdf" - # For Item Options - options = odi.options == "[]" ? "" : odi.options - - # check for item not to show - #if odi.price != 0 - pdf = print_settings.unique_code.constantize.new(print_settings, odi_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) - - # pdf.render_file "tmp/order_item.pdf" - pdf.render_file filename - #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 + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + #Use CUPS service + #Generate PDF + #Print + # Must be one print + if print_settings.print_copies == 0 + print_settings.print_copies = 1 + print_settings.save! end - # For Print Order Summary - else - booking_id = Booking.get_booking_id(order_id) #order[0].order_id - order = print_query('order_summary', order_id) + + shop = Shop.current_shop + directory_name = "public/orders_#{shop.shop_code}" + Dir.mkdir(directory_name) unless File.exists?(directory_name) filename = directory_name + "/order_summary_#{order_id}.pdf" # filename = "tmp/order_summary_#{order_id}" + ".pdf" @@ -98,29 +70,27 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker #no print in cloud server if ENV["SERVER_MODE"] != "cloud" self.print(filename, oqs.printer_name) - else - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - 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} - ) 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 + else + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + 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 + } + ) 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 diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index d130c96e..360ca85c 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -91,61 +91,29 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Bill Receipt Print def print_receipt_bill(printer_settings, kbz_pay_status, qr_code, cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation) - #Use CUPS service - #Generate PDF - #Print - if printer_settings - if !printer_settings.unique_code.match?(/receiptbillorder/i) - if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf - pdf = ReceiptBillA5Pdf.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) + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + #Use CUPS service + #Generate PDF + #Print + if printer_settings + if !printer_settings.unique_code.match?(/receiptbillorder/i) + if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf + pdf = ReceiptBillA5Pdf.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) + else + pdf = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code.constantize.new(printer_settings, kbz_pay_status, qr_code, 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) + end else - pdf = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code.constantize.new(printer_settings, kbz_pay_status, qr_code, 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) + #doemal online order pdf template + 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 - else - #doemal online order pdf template - 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) + + # print as print copies in printer setting + count = printer_settings.print_copies end - if ENV["SERVER_MODE"] == "cloud" - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - 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" } - } - ) - end - - # print as print copies in printer setting - count = printer_settings.print_copies - - # override print copies for print worker loop - # print_settings.print_copies = 1 - # print_settings.save! - end - directory_name = 'public/receipts' - Dir.mkdir(directory_name) unless File.exists?(directory_name) - Rails.logger.debug "############## dir::" + directory_name + directory_name = 'public/receipts' + Dir.mkdir(directory_name) unless File.exists?(directory_name) + Rails.logger.debug "############## dir::" + directory_name if count == 1 filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf" pdf.render_file filename @@ -169,12 +137,44 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end end end - Rails.logger.debug "############## filename::" + filename - return filename, sale_data.receipt_no, cashier_terminal.printer_name + + Rails.logger.debug "############## filename::" + filename + return filename, sale_data.receipt_no, cashier_terminal.printer_name + else + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: cashier_terminal.printer_name, + 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" + } + } + ) + end end # stock check - def print_stock_check_result(print_settings,stockcheck, stockcheck_items,checker_name, shop_details) + def print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker_name, shop_details) pdf = StockResultPdf.new(print_settings,stockcheck, stockcheck_items,checker_name, shop_details) pdf.render_file "tmp/print_stock_check_result.pdf" #no print in cloud server @@ -197,37 +197,39 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Move Table Print - def print_move_table(printer_settings,to,from,shop_detail,date,type,moved_by,order_items,oqs) - #Use CUPS service - #Generate PDF - #Print - pdf = MoveTablePdf.new(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) - pdf.render_file "tmp/print_move_table.pdf" + def print_move_table(printer_settings, to, from, shop_detail, date, type, moved_by, order_items, oqs) + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + #Use CUPS service + #Generate PDF + #Print + pdf = MoveTablePdf.new(printer_settings, to, from, shop_detail, date, type, moved_by, order_items) + pdf.render_file "tmp/print_move_table.pdf" - if ENV["SERVER_MODE"] != "cloud" - if oqs.print_copy - self.print("tmp/print_move_table.pdf",oqs.printer_name) - else - print_settings.print_copies = 1 - print_settings.save! - #no print in cloud server - self.print("tmp/print_move_table.pdf", oqs.printer_name) + if ENV["SERVER_MODE"] != "cloud" + if oqs.print_copy + self.print("tmp/print_move_table.pdf",oqs.printer_name) + else + print_settings.print_copies = 1 + print_settings.save! + #no print in cloud server + self.print("tmp/print_move_table.pdf", oqs.printer_name) + end end else - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: oqs.station_name, - unique_code: print_settings.unique_code, - print_copies: print_settings.print_copies, - data: { - type: type, - body: { - to: to, - from: from, - date: date, - moved_by: moved_by, - order_items: order_items.as_json, - }, - } + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: oqs.station_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + type: type, + body: { + to: to, + from: from, + date: date, + moved_by: moved_by, + order_items: order_items.as_json, + }, + } ) end end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index c7b52bb8..0b5e9d93 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,6 +1,6 @@
-
+
@@ -20,7 +20,7 @@ <% end %> - <% end %> + <% end %>
@@ -38,8 +38,8 @@
- <% - @queue_completed_item.each do |qid| + <% + @queue_completed_item.each do |qid| %>
@@ -52,38 +52,38 @@ <%= qid.order_id %> -
+

<%= qid.item_name %> [x <%= qid.qty %> - ] + ] <% if !qid.set_menu_items.nil? %> <% qid.set_menu_items.each do |item_instance|%>
<%= item_instance %> <% end %> - <% end %> -

+ <% end %> +

-

<%= qid.options == "[]"? "" : qid.options %>

+

<%= qid.options == "[]"? "" : qid.options %>

- Order at - + Order at - <%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %> -
+

Order By - <%= qid.item_order_by %> - +
- +
<% if !qid.delivery_status %> <%end%> -
- <% end %> +
+ <% end %>
-
+
@@ -127,7 +127,7 @@ --> <% if current_user.role != "kitchen" %> - + reply Back - <%end%> + <%end%>
+ @@ -179,7 +179,7 @@ - +
@@ -232,7 +232,7 @@
- +
@@ -285,7 +285,7 @@
- +
@@ -338,7 +338,7 @@
- + @@ -350,7 +350,7 @@ - --> + -->
- + @@ -378,7 +378,7 @@
2 X700
1400.00
@@ -388,7 +388,7 @@ - SUB TOTAL + SUB TOTAL 0.00 @@ -419,19 +419,19 @@ - + <% if request.user_agent.include? "Mobile" %>
<% else %>
<% end %> - +
-
CUSTOMER & DELIVERY INFORMATION + CUSTOMER & DELIVERY INFORMATION
@@ -541,7 +541,7 @@ - + <% if current_user.role != "waiter" %> @@ -559,12 +559,16 @@
- + +<%= print_settings %> + +"> + +
+ +<%= print_settings %> +
@@ -653,7 +655,7 @@ - -
+ - + @@ -440,9 +442,11 @@ $('#reprint').on('click', function () { type: "GET", url: ajax_url, success: function (result) { - if ($("#server_mode").val() == "cloud") { - if(typeof code2lab != 'undefined'){ - code2lab.printFile(result.filepath.substr(6), result.printer_url); + if (!$('#print_settings').data('action-cable')) { + if ($("#server_mode").val() == "cloud") { + if(typeof code2lab != 'undefined'){ + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } } } location.reload(); @@ -542,15 +546,17 @@ $(document).on('click', '.access_modal', function(event){ type: "GET", url: ajax_url, success: function (result) { - // For Server Print - from jade - if ($("#server_mode").val() == "cloud") { - if(typeof code2lab != 'undefined'){ - code2lab.printFile(result.filepath.substr(6), result.printer_url); + if (!$('#print_settings').data('action-cable')) { + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + if(typeof code2lab != 'undefined'){ + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } } } location.reload(); } - }); + }); }else if(type == "foc"){ $('#AccessCodeModal').modal('hide'); $('#focModal').modal('show'); diff --git a/app/views/origami/table_invoices/show.html.erb b/app/views/origami/table_invoices/show.html.erb index 76c65057..7f0acdce 100644 --- a/app/views/origami/table_invoices/show.html.erb +++ b/app/views/origami/table_invoices/show.html.erb @@ -164,6 +164,8 @@ +<%= print_settings %> + "> @@ -243,7 +245,6 @@ - "> \ No newline at end of file + diff --git a/app/views/settings/cashier_terminals/_form.html.erb b/app/views/settings/cashier_terminals/_form.html.erb index 3ba13d97..707ef348 100755 --- a/app/views/settings/cashier_terminals/_form.html.erb +++ b/app/views/settings/cashier_terminals/_form.html.erb @@ -12,11 +12,9 @@ <%= f.input :auto_print_receipt %> <%= f.label "Select Zones", :class => 'control-label' %> <%= f.collection_check_boxes :zone_ids , Zone.all, :id, :name , :class => 'checkbox form-group'%> - <% if(@server_mode != 'cloud') %> - <%= f.input :printer_name, :as => :select, :collection => Printer::PrinterWorker.printers, include_blank: false %> - <% else %> - <%= f.input :printer_name, :as => :select, :collection => [], include_blank: false %> - <% end %> + + <%= f.input :printer_name, :as => :select, :collection => Printer::PrinterWorker.printers, include_blank: "Please Select", class: "mdb-select md-form" %> + <%= f.input :font %> <%= f.input :font_size %> <%= f.input :show_tax %> @@ -24,7 +22,7 @@ <%= f.input :show_guest_info %> -
+
<%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %>
<% end %> @@ -58,24 +56,31 @@ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.cashier_terminal_txt") %>

- + \ No newline at end of file + diff --git a/app/views/settings/order_queue_stations/_form.html.erb b/app/views/settings/order_queue_stations/_form.html.erb index 908e2844..fb4cc989 100755 --- a/app/views/settings/order_queue_stations/_form.html.erb +++ b/app/views/settings/order_queue_stations/_form.html.erb @@ -1,10 +1,3 @@ - - -
@@ -12,22 +5,11 @@ div.form-inputs span{ <%= simple_form_for([:settings,@settings_order_queue_station]) do |f| %> <%= f.error_notification %> -
+
<%= f.input :station_name %> <%= f.input :is_active %> - <% if(@server_mode != 'cloud') %> -
- - -
- <% else %> - <%= f.input :printer_name, :as => :select, :collection => [], include_blank: false %> - <% end %> - + <%= f.input :printer_name, :as => :select, :collection => Printer::PrinterWorker.printers, include_blank: "Please Select", class: "mdb-select md-form" %> + <%= f.input :print_copy %> <%= f.hidden_field :processing_items %> <%= f.label "Select Zones", :class => 'control-label' %> @@ -38,7 +20,7 @@ div.form-inputs span{ <%= f.input :auto_print %>
-
+
<%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %>
<% end %> @@ -69,24 +51,31 @@ div.form-inputs span{ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.order_queue_stations_txt") %>

-
+
diff --git a/app/views/transactions/sales/show.html.erb b/app/views/transactions/sales/show.html.erb index 07ca05b0..dab994c4 100755 --- a/app/views/transactions/sales/show.html.erb +++ b/app/views/transactions/sales/show.html.erb @@ -280,7 +280,7 @@ - +<%= print_settings %> "> @@ -405,10 +405,12 @@ url: ajax_url, data: "remark="+ remark + "&sale_id=" + sale_id+ "&access_code=" + access_code, success: function (result) { - // For Server Print - from jade - if ($("#server_mode").val() == "cloud") { - if(typeof code2lab != 'undefined'){ - code2lab.printFile(result.filepath.substr(6), result.printer_url); + if (!$('#print_settings').data('action-cable')) { + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + if(typeof code2lab != 'undefined'){ + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } } } window.location.href = '/transactions/sales/'; From b3ab99996210fbee83680614ab915e505d010f4f Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Fri, 21 Aug 2020 11:24:10 +0630 Subject: [PATCH 07/11] fixed receipt bill pdf with action cable --- .../origami/payments_controller.rb | 53 ++----- app/models/printer/order_queue_printer.rb | 8 +- app/models/printer/printer_worker.rb | 24 ++-- app/models/printer/receipt_printer.rb | 136 ++++++++---------- app/views/origami/payments/show.html.erb | 42 +++--- 5 files changed, 112 insertions(+), 151 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 8b5416cf..22c25e85 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -132,14 +132,6 @@ class Origami::PaymentsController < BaseOrigamiController ) end - # For Print - # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server - 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 @@ -197,12 +189,17 @@ class Origami::PaymentsController < BaseOrigamiController card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) # get printer info - print_settings = PrintSetting.find_by_unique_code(unique_code) + if type.strip.downcase == 'doemal_order' + print_settings = PrintSetting.where(unique_code: 'ReceiptBillOrderPdf').first + else + print_settings = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first + end # 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) credit_pdf = Lookup.find_by_lookup_type("credit_pdf") + if (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1 printed_status = 'credit_payment' else @@ -211,13 +208,10 @@ class Origami::PaymentsController < BaseOrigamiController 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, printed_status,current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) - - #end - - if !saleObj.nil? - # InventoryJob.perform_now(self.id) - # InventoryDefinition.calculate_product_count(saleObj) - end + # if !saleObj.nil? + # InventoryJob.perform_now(self.id) + # InventoryDefinition.calculate_product_count(saleObj) + # end end # status, filename, sale_receipt_no, printer_name = Payment.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, shop_detail, current_user, nil, nil) @@ -610,32 +604,11 @@ class Origami::PaymentsController < BaseOrigamiController cashier_type = params[:type] if cashier_type.strip.downcase == "doemal_order" - unique_code = "ReceiptBillOrderPdf" + print_settings = PrintSetting.where(unique_code: 'ReceiptBillOrderPdf').first else - 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 - 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 - # unique_code = "ReceiptBillPdf" - end - end - end - end + print_settings = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first end + # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::ReceiptPrinter.new(print_settings) diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 5a145efc..53f29479 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -26,8 +26,6 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker if ENV["SERVER_MODE"] != "cloud" self.print(filename, oqs.printer_name) end - - return filename, order_id, oqs.printer_name else ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: oqs.station_name, @@ -41,6 +39,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker } ) end + + return filename, order_id, oqs.printer_name end # Query for per order @@ -71,8 +71,6 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker if ENV["SERVER_MODE"] != "cloud" self.print(filename, oqs.printer_name) end - - return filename, order_id, oqs.printer_name else ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: oqs.station_name, @@ -87,6 +85,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker } ) end + + return filename, order_id, oqs.printer_name end # Print for orders in booking diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index 4dc057b9..d30af42d 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -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 diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 360ca85c..356ba825 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -95,82 +95,70 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print - if printer_settings - if !printer_settings.unique_code.match?(/receiptbillorder/i) - if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf - pdf = ReceiptBillA5Pdf.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) - else - pdf = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code.constantize.new(printer_settings, kbz_pay_status, qr_code, 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) - end + if !printer_settings.unique_code.match?(/receiptbillorder/i) + if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf + pdf = ReceiptBillA5Pdf.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) else - #doemal online order pdf template - 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) + pdf = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code.constantize.new(printer_settings, kbz_pay_status, qr_code, 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) end - - # print as print copies in printer setting - count = printer_settings.print_copies + else + #doemal online order pdf template + 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 + # print as print copies in printer setting + count = printer_settings.print_copies + directory_name = 'public/receipts' Dir.mkdir(directory_name) unless File.exists?(directory_name) Rails.logger.debug "############## dir::" + directory_name - if count == 1 - filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf" - pdf.render_file filename - if printed_status != 'Paid' && printed_status != 'credit_payment' - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) - end - elsif printed_status == 'credit_payment' - filename = directory_name + "/receipt_bill_credit_#{sale_data.receipt_no}.pdf" - pdf.render_file filename - self.print(directory_name + "/receipt_bill_credit_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) - end - else - filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" - pdf.render_file filename - if printed_status != 'Paid' - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name) - end + + filename = "#{directory_name}/receipt_bill_#{sale_data.receipt_no}#{count != 1 ? "_#{count}" : ''}.pdf" + pdf.render_file filename + if !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1') + #no print in cloud server + puts "SERVER_MODE #{ENV["SERVER_MODE"]}" + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, cashier_terminal.printer_name) end end Rails.logger.debug "############## filename::" + filename - return filename, sale_data.receipt_no, cashier_terminal.printer_name else - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: cashier_terminal.printer_name, - 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" + if !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1') + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: cashier_terminal.printer_name, + 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.booking.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" + } } - } - ) + ) + end end + + return filename || '', sale_data.receipt_no, cashier_terminal.printer_name end # stock check @@ -266,18 +254,18 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker # if count == 0 # self.print(filename, printer_name) # else - if count == 1 - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, printer_name) - end - else - filename = "public/receipts/receipt_bill_#{receipt_no}_#{count}.pdf" - # no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, printer_name) - end - end + if count == 1 + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, printer_name) + end + else + filename = "public/receipts/receipt_bill_#{receipt_no}_#{count}.pdf" + # no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, printer_name) + end + end # end end diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 39f4fa49..20bf09e2 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -726,6 +726,7 @@ $(document).ready(function(){ data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type + "&is_kbz=" + is_kbz, success:function(result){ /* start delete receipt no in first bill*/ + console.log(result); if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ var receipt_no = ($("#receipt_no").html()).trim(); deleteReceiptNoInFirstBillData(receipt_no); @@ -740,33 +741,29 @@ $(document).ready(function(){ var msg = ''; } - $("#loading_wrapper" ).hide(); - if(location.pathname.includes("credit_payment")){ + $("#changed_amount").text(""); + if($('#balance').text() < 0){ + <% if precision.to_i > 0 %> + $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>)); + <% else %> + $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); + <% end %> + } + + if(location.pathname.includes("credit_payment") || pdf_view != 1){ payment_success_alert(); - }else{ - //PDF lightbox data - var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6); + } else { + //PDF lightbox data; + var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6) $("#sale_receipt_no").val(result.receipt_no); $("#filename").val(result.filename); $("#printer_name").val(result.printer_name); $("#receipt_pdf").attr("src", pdfPath); - $("#changed_amount").text(""); - if($('#balance').text() < 0){ - <% if precision.to_i > 0 %> - $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>)); - <% else %> - $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); - <% end %> - } - - if (pdf_view == 1) { - $("#pdfModal").modal({show : true, backdrop : false, keyboard : false}); - $("#pdfModalLabel").text("Sale Completed"); - }else{ - //PDF lightbox data - print_receipt(); - } + $("#pdfModal").modal({show : true, backdrop : false, keyboard : false}); + $("#pdfModalLabel").text("Sale Completed"); } + + $("#loading_wrapper").hide(); } }); } @@ -1010,6 +1007,7 @@ $(document).ready(function(){ if($('#pay').is(":visible")) { $('#pay').prop("disabled",true); } + $("#loading_wrapper" ).show(); var sale_id = $('#sale_id').text(); var filename = $("#filename").val(); @@ -1048,6 +1046,8 @@ $(document).ready(function(){ }else{ payment_success_alert(); } + + $("#loading_wrapper" ).hide(); } }); } From c8b04717941a10629accb253296dcd631a3d7e38 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 24 Aug 2020 11:42:44 +0630 Subject: [PATCH 08/11] receipt bill sale payments action cable --- app/models/printer/receipt_printer.rb | 6 ++- app/pdf/receipt_bill_pdf.rb | 70 +++++++++++++-------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 356ba825..3a3a905d 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -126,6 +126,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker Rails.logger.debug "############## filename::" + filename else if !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1') + sale_payments = SalePayment + .select(:payment_method, 'SUM(`sale_payments`.`payment_amount`) AS `payment_amount`') + .where(sale_id: sale_data.sale_id).group(:payment_method) + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", queue: cashier_terminal.printer_name, unique_code: print_settings.unique_code, @@ -148,7 +152,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker 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 + sale_payments: sale_payments.as_json }, footer: { printed_status: printed_status, footer_text: "Thank You! See you Again" diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 374e014b..bc69ce78 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -439,16 +439,16 @@ class ReceiptBillPdf < Prawn::Document end def sale_payment(sale_data,precision,delimiter,printed_status) - stroke_horizontal_rule - #move_down line_move - # sql = "SELECT SUM(payment_amount) - # FROM sale_payments where payment_method='creditnote' - # and sale_id='#{sale_data.sale_id}'" + stroke_horizontal_rule + #move_down line_move + # sql = "SELECT SUM(payment_amount) + # FROM sale_payments where payment_method='creditnote' + # and sale_id='#{sale_data.sale_id}'" - if printed_status == 'credit_payment' + if printed_status == 'credit_payment' sale_payments = SalePayment.select(:payment_amount, :payment_method, :updated_at) .where("sale_id = '#{sale_data.sale_id}' AND payment_method != 'creditnote'") - else + else sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote' and sale_id='#{sale_data.sale_id}'").to_sql # sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) # FROM sale_payments where payment_method='creditnote' @@ -466,38 +466,38 @@ class ReceiptBillPdf < Prawn::Document where sa.sale_id='#{sale_data.sale_id}')) = 0 THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id) .group("payment_method") - end + end - sale_payments.each do |payment| - y_position = cursor - if payment.payment_method == "paypar" - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Redeem Payment", :size => self.item_font_size,:align => :left - end - elsif printed_status == 'credit_payment' - text "#{payment.payment_method.capitalize} Payment on #{payment.updated_at.strftime('%d-%m-%Y')}", :left_margin => -10, :size => self.item_font_size,:align => :left - else - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left - end - end + sale_payments.each do |payment| + y_position = cursor + if payment.payment_method == "paypar" + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Redeem Payment", :size => self.item_font_size,:align => :left + end + elsif printed_status == 'credit_payment' + text "#{payment.payment_method.capitalize} Payment on #{payment.updated_at.strftime('%d-%m-%Y')}", :left_margin => -10, :size => self.item_font_size,:align => :left + else + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left + end + end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end - move_down line_move + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - if sale_data.amount_received > 0 - y_position = cursor - move_down line_move - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Change Amount", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end - # move_down line_move + move_down line_move + end + if sale_data.amount_received > 0 + y_position = cursor + move_down line_move + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Change Amount", :size => self.item_font_size,:align => :left end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + # move_down line_move + end end # show member information From bd65edcba3fa872e27e71a86b16989ad09de4611 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 24 Aug 2020 16:07:25 +0630 Subject: [PATCH 09/11] update close cashier pdf --- app/controllers/origami/shifts_controller.rb | 21 +- .../reports/shiftsale_controller.rb | 37 ++- app/models/printer/cashier_station_printer.rb | 5 +- app/pdf/receipt_bill_pdf.rb | 222 +++++++++--------- 4 files changed, 137 insertions(+), 148 deletions(-) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index eb894d58..a4c282d0 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -87,13 +87,11 @@ class Origami::ShiftsController < BaseOrigamiController end shop_details = shop_detail #get tax - shift_obj = ShiftSale.where('id =?',@shift.id) - sale_items = '' + shift_obj = ShiftSale.where('id = ?', @shift.id) @lookup = Lookup.shift_sale_items_lookup_value if @lookup.to_i == 1 - @sale_items = Sale.get_shift_sale_items(@shift.id) - other_charges = Sale.get_other_charges() - @total_other_charges_info = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",@shift) + @sale_items = Sale.get_shift_sale_items(@shift.id) + @total_other_charges_info = ShiftSale.get_other_charges(@shift) end @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') @total_waste = Sale.get_total_waste(shift_id).sum(:grand_total) @@ -108,7 +106,6 @@ 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 @@ -116,15 +113,9 @@ class Origami::ShiftsController < BaseOrigamiController printer = Printer::CashierStationPrinter.new(print_settings) # print close cashier setting - close_cashier_print = Lookup.collection_of('close_cashier_print') - if close_cashier_print.empty? - @settings_lookup = Lookup.new(lookup_type: "close_cashier_print", name: "CloseCashierPrint", value: "1") - @settings_lookup.save - end - find_close_cashier_print = Lookup.collection_of('close_cashier_print') - if find_close_cashier_print[0][1].to_i > 0 - 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,@other_charges) - end + if Lookup.collection_of('close_cashier_print').any? { |l| l == ['CloseCashierPrint', '1'] } + 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 end diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index ce927f8e..1434b93c 100755 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -53,28 +53,31 @@ class Reports::ShiftsaleController < BaseReportController @shift = ShiftSale.find_by_id(shift_id) shift_obj = ShiftSale.where('id =?',shift_id) + close_cashier_pdf = Lookup.collection_of("print_settings") - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + unique_code = "CloseCashierPdf" - close_cashier_pdf = Lookup.collection_of("print_settings") - - unique_code = "CloseCashierPdf" - - if !close_cashier_pdf.empty? - close_cashier_pdf.each do |close_cashier| - if close_cashier[0] == 'CloseCashierCustomisePdf' - if close_cashier[1] == '1' - unique_code="CloseCashierCustomisePdf" - else - unique_code="CloseCashierPdf" - end + if !close_cashier_pdf.empty? + close_cashier_pdf.each do |close_cashier| + if close_cashier[0] == 'CloseCashierCustomisePdf' + if close_cashier[1] == '1' + unique_code="CloseCashierCustomisePdf" + else + unique_code="CloseCashierPdf" end end end - + end shop_details = shop_detail cashier_terminal = @shift.cashier_terminal + + @lookup = Lookup.shift_sale_items_lookup_value + if @lookup.to_i == 1 + @sale_items = Sale.get_shift_sale_items(@shift.id) + @total_other_charges_info = ShiftSale.get_other_charges(@shift) + end + @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') @total_waste = Sale.get_total_waste(shift_id).sum(:grand_total) @total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total) @@ -96,14 +99,10 @@ class Reports::ShiftsaleController < BaseReportController printer = Printer::CashierStationPrinter.new(print_settings) # printer.print_close_cashier(print_settings,cashier_terminal,@shift, nil, 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) - 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) + 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) respond_to do |format| format.html { redirect_to '/en/reports/shiftsale/', notice: 'Printing Completed.'} - format - end end end - - end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 1c255a42..ceff5022 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -38,7 +38,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # self.print(filename, cashier_terminal.printer_name) # end - def print_close_cashier(printer_settings, cashier_terminal, shift_sale, sale_items, total_other_charges_info, shop_details, sale_taxes, other_payment, amount, discount, member_discount, total_dinein, total_takeway, total_other_charges, total_waste, total_spoile, total_credit_payments, payment_methods, other_charges) + def print_close_cashier(printer_settings, cashier_terminal, shift_sale, sale_items, total_other_charges_info, shop_details, sale_taxes, other_payment, amount, discount, member_discount, total_dinein, total_takeway, total_other_charges, total_waste, total_spoile, total_credit_payments, payment_methods) if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } if !sale_items.blank? or !sale_items.nil? @account_cate_count = Hash.new {|hash, key| hash[key] = 0} @@ -71,6 +71,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker end end end + pdf.render_file filename #no print in cloud server if ENV["SERVER_MODE"] != "cloud" @@ -87,6 +88,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker cashier_terminal: cashier_terminal, shift_employee: shift_sale.employee, sale_items: sale_items, + other_charges: total_other_charges_info, sale_taxes: sale_taxes, other_payment: other_payment, total_amount_by_account: amount, @@ -94,7 +96,6 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker total_member_discount: 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 } diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index bc69ce78..8defeb30 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -309,133 +309,131 @@ class ReceiptBillPdf < Prawn::Document end def all_total(sale_data,precision,delimiter,printed_status) - move_down line_move - item_name_width = self.item_width - y_position = cursor - if sale_data.discount_type == 'member_discount' - dis_type = "Member Discount:" + move_down line_move + item_name_width = self.item_width + y_position = cursor + if sale_data.discount_type == 'member_discount' + dis_type = "Member Discount:" + else + dis_type = "Overall Discount:" + end + + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ dis_type }", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + end + + service_tax_desc = "" + service_tax_amount = 0 + service_tax_rate = 0 + com_tax_desc = "" + com_tax_amount = 0 + com_tax_rate = 0 + if sale_data.sale_taxes.length > 0 + incl_tax = "" + if sale_data.tax_type == "inclusive" + incl_tax = "Incl." + end + + find_lookup = Lookup.find_by_lookup_type('show_total_before_tax') + if find_lookup.nil? || find_lookup == nil + lookup = Lookup.new(lookup_type: 'show_total_before_tax', name: 'Show Total Before Tax', value: '0') + lookup.save + end + check_lookup_type = Lookup.find_by_lookup_type('show_total_before_tax') + if check_lookup_type.value == '1' + sale_data.sale_taxes.each do |st| + if (st.tax_name.include? "Service") + service_tax_desc = st.tax_name + service_tax_amount = st.tax_payable_amount + if incl_tax + service_tax_rate = st.tax_rate.to_i + end + end + if (st.tax_name.include? "Commercial") + com_tax_desc = st.tax_name + com_tax_amount = st.tax_payable_amount + if incl_tax + com_tax_rate = st.tax_rate.to_i + end + end + end + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + move_down line_move + y_position = cursor + stroke_horizontal_rule + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Total Before Tax", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{service_tax_amount.to_i + @sub_total.to_i}" , :size => self.item_font_size,:align => :right + end + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end else - dis_type = "Overall Discount:" - end - - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ dis_type }", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right - end - - service_tax_desc = "" - service_tax_amount = 0 - service_tax_rate = 0 - com_tax_desc = "" - com_tax_amount = 0 - com_tax_rate = 0 - if sale_data.sale_taxes.length > 0 - incl_tax = "" - if sale_data.tax_type == "inclusive" - incl_tax = "Incl." - end - - find_lookup = Lookup.find_by_lookup_type('show_total_before_tax') - if find_lookup.nil? || find_lookup == nil - lookup = Lookup.new(lookup_type: 'show_total_before_tax', name: 'Show Total Before Tax', value: '0') - lookup.save - end - check_lookup_type = Lookup.find_by_lookup_type('show_total_before_tax') - if check_lookup_type.value == '1' - sale_data.sale_taxes.each do |st| - if (st.tax_name.include? "Service") - service_tax_desc = st.tax_name - service_tax_amount = st.tax_payable_amount - if incl_tax - service_tax_rate = st.tax_rate.to_i - end - end - if (st.tax_name.include? "Commercial") - com_tax_desc = st.tax_name - com_tax_amount = st.tax_payable_amount - if incl_tax - com_tax_rate = st.tax_rate.to_i - end - end - end - move_down line_move - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end - move_down line_move - y_position = cursor - stroke_horizontal_rule - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Total Before Tax", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{service_tax_amount.to_i + @sub_total.to_i}" , :size => self.item_font_size,:align => :right - end - move_down line_move - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end - else - sale_data.sale_taxes.each do |st| - move_down line_move - y_position = cursor - - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end - end - end - else - - end - - # move_down 5 - # y_position = cursor - - # bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - # text "Total Tax", :size => self.item_font_size,:align => :left - # end - # bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - # text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right - # end - - if sale_data.rounding_adjustment != 0.0 - move_down line_move + sale_data.sale_taxes.each do |st| + move_down line_move y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Rounding Adjustment", :size => self.item_font_size,:align => :left + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end + end end + end + # move_down 5 + # y_position = cursor + + # bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + # text "Total Tax", :size => self.item_font_size,:align => :left + # end + # bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + # text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right + # end + + if sale_data.rounding_adjustment != 0.0 move_down line_move y_position = cursor - move_down line_move - bounding_box([0,y_position], :width =>self.item_description_width) do - text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left + + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rounding Adjustment", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right end - move_down line_move + end - sale_payment(sale_data,precision,delimiter,printed_status) + move_down line_move + y_position = cursor + move_down line_move + bounding_box([0,y_position], :width =>self.item_description_width) do + text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + end + move_down line_move + + sale_payment(sale_data,precision,delimiter,printed_status) end def sale_payment(sale_data,precision,delimiter,printed_status) From c7cd353ba201c3fbd85703580a564a74413a04bc Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Tue, 25 Aug 2020 14:18:51 +0630 Subject: [PATCH 10/11] add action cable for call waiter,stock check & check in out --- .../api/call_waiters_controller.rb | 2 +- app/models/printer/order_queue_printer.rb | 10 ++++++ app/models/printer/receipt_printer.rb | 34 ++++++++++++++++++- ...stock_result_pdf.rb => stock_check_pdf.rb} | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) rename app/pdf/{stock_result_pdf.rb => stock_check_pdf.rb} (99%) diff --git a/app/controllers/api/call_waiters_controller.rb b/app/controllers/api/call_waiters_controller.rb index 5beba9a6..c29f5128 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -1,4 +1,4 @@ -class Api::CallWaitersController < ActionController::API +class Api::CallWaitersController < Api::ApiController #List all active customers by name def index diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 53f29479..c7068d65 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -177,6 +177,16 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker filename = "tmp/check_in_out_#{sale_id}" + ".pdf" pdf = CheckInOutPdf.new(print_settings,booking, table) + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: cashier_terminal.printer_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + booking: booking, + table: table, + table_type: table.type, + } + ) print_setting = PrintSetting.all # if order_item[0].price != 0 diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 3a3a905d..3b02256c 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -167,7 +167,28 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker # stock check def print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker_name, shop_details) - pdf = StockResultPdf.new(print_settings,stockcheck, stockcheck_items,checker_name, shop_details) + pdf = StockCheckPdf.new(print_settings,stockcheck, stockcheck_items,checker_name, shop_details) + stock_items= [] + if stockcheck_items.length > 0 + stockcheck_items.each do |sc| + stock_item= { + count: sc.stock_count.to_s, + item_name: MenuItemInstance.get_item_name(sc.item_code) + } + stock_items.push(stock_item) + end + end + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: print_settings.printer_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + stockcheck: stockcheck, + stockcheck_items: stock_items, + checker_name: checker_name, + shop_details: shop_details, + } + ) pdf.render_file "tmp/print_stock_check_result.pdf" #no print in cloud server if ENV["SERVER_MODE"] != "cloud" @@ -245,6 +266,17 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Generate PDF #Print pdf = CallWaiterPdf.new(printer_settings,table,time,shop_detail) + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: print_settings.printer_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + shop_name: shop_detail.name, + name: print_settings.name, + table: table.name, + time: time, + } + ) pdf.render_file "tmp/print_call_waiter.pdf" #no print in cloud server if ENV["SERVER_MODE"] != "cloud" diff --git a/app/pdf/stock_result_pdf.rb b/app/pdf/stock_check_pdf.rb similarity index 99% rename from app/pdf/stock_result_pdf.rb rename to app/pdf/stock_check_pdf.rb index 1da06dd2..d04cd82e 100755 --- a/app/pdf/stock_result_pdf.rb +++ b/app/pdf/stock_check_pdf.rb @@ -1,4 +1,4 @@ -class StockResultPdf < Prawn::Document +class StockCheckPdf < Prawn::Document 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, :text_width def initialize(printer_settings, stockcheck, stockcheck_items, checker_name, shop_details) From 63abafdbccab1be45911e99d96d1776709bb2a50 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Wed, 26 Aug 2020 10:25:02 +0630 Subject: [PATCH 11/11] use print_settings ActionCable fro call waiter, stock check, check in out --- app/models/printer/order_queue_printer.rb | 74 +++++++++--------- app/models/printer/receipt_printer.rb | 93 +++++++++++++---------- app/views/origami/home/show.html.erb | 2 +- 3 files changed, 91 insertions(+), 78 deletions(-) diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index c7068d65..84ef703c 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -39,7 +39,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker } ) end - + return filename, order_id, oqs.printer_name end @@ -170,47 +170,51 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # Check in-out time def print_check_in_out(print_settings, cashier_terminal, booking, table) - #Use CUPS service - #Generate PDF - #Print - sale_id = booking.sale_id - filename = "tmp/check_in_out_#{sale_id}" + ".pdf" + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + #Use CUPS service + #Generate PDF + #Print + sale_id = booking.sale_id + filename = "tmp/check_in_out_#{sale_id}" + ".pdf" - pdf = CheckInOutPdf.new(print_settings,booking, table) - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: cashier_terminal.printer_name, - unique_code: print_settings.unique_code, - print_copies: print_settings.print_copies, - data: { - booking: booking, - table: table, - table_type: table.type, - } - ) - print_setting = PrintSetting.all + pdf = CheckInOutPdf.new(print_settings,booking, table) - # if order_item[0].price != 0 - if !print_setting.empty? - print_setting.each do |print_settings| - if print_settings.unique_code == 'CheckInOutPdf' - pdf = CheckInOutPdf.new(print_settings,booking, table) + print_setting = PrintSetting.all + + # if order_item[0].price != 0 + if !print_setting.empty? + print_setting.each do |print_settings| + if print_settings.unique_code == 'CheckInOutPdf' + pdf = CheckInOutPdf.new(print_settings,booking, table) + end end end - end - pdf.render_file filename + pdf.render_file filename - # Must be one print - if print_settings.print_copies == 0 - print_settings.print_copies = 1 - print_settings.save! - end - # print_settings.print_copies = 1 - # print_settings.save! + # Must be one print + if print_settings.print_copies == 0 + print_settings.print_copies = 1 + print_settings.save! + end + # print_settings.print_copies = 1 + # print_settings.save! - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, print_settings.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, print_settings.printer_name) + end + else + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: cashier_terminal.printer_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + booking: booking, + table: table, + table_type: table.type, + } + ) end end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 3b02256c..81a5ea62 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -167,33 +167,38 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker # stock check def print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker_name, shop_details) - pdf = StockCheckPdf.new(print_settings,stockcheck, stockcheck_items,checker_name, shop_details) stock_items= [] if stockcheck_items.length > 0 - stockcheck_items.each do |sc| - stock_item= { - count: sc.stock_count.to_s, - item_name: MenuItemInstance.get_item_name(sc.item_code) + stockcheck_items.each do |sc| + stock_item= { + count: sc.stock_count.to_s, + item_name: MenuItemInstance.get_item_name(sc.item_code) + } + stock_items.push(stock_item) + end + end + + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + pdf = StockCheckPdf.new(print_settings,stockcheck, stockcheck_items,checker_name, shop_details) + + pdf.render_file "tmp/print_stock_check_result.pdf" + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print("tmp/print_stock_check_result.pdf") + end + else + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: print_settings.printer_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + stockcheck: stockcheck, + stockcheck_items: stock_items, + checker_name: checker_name, + shop_details: shop_details, } - stock_items.push(stock_item) - end + ) end - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: print_settings.printer_name, - unique_code: print_settings.unique_code, - print_copies: print_settings.print_copies, - data: { - stockcheck: stockcheck, - stockcheck_items: stock_items, - checker_name: checker_name, - shop_details: shop_details, - } - ) - pdf.render_file "tmp/print_stock_check_result.pdf" - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print("tmp/print_stock_check_result.pdf") - end end #Queue No Print @@ -262,25 +267,29 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Queue No Print def print_call_waiter(printer_settings,table,time,shop_detail) - #Use CUPS service - #Generate PDF - #Print - pdf = CallWaiterPdf.new(printer_settings,table,time,shop_detail) - ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: print_settings.printer_name, - unique_code: print_settings.unique_code, - print_copies: print_settings.print_copies, - data: { - shop_name: shop_detail.name, - name: print_settings.name, - table: table.name, - time: time, - } - ) - pdf.render_file "tmp/print_call_waiter.pdf" - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print("tmp/print_call_waiter.pdf") + if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] } + #Use CUPS service + #Generate PDF + #Print + pdf = CallWaiterPdf.new(printer_settings,table,time,shop_detail) + + pdf.render_file "tmp/print_call_waiter.pdf" + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print("tmp/print_call_waiter.pdf") + end + else + ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", + queue: print_settings.printer_name, + unique_code: print_settings.unique_code, + print_copies: print_settings.print_copies, + data: { + shop_name: shop_detail.name, + name: print_settings.name, + table: table.name, + time: time, + } + ) end end diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index a6fc62a7..29a644af 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -1274,7 +1274,7 @@ data: "remark="+ remark + "&sale_id=" + sale_id+ "&access_code=" + access_code, success: function (result) { if (!$('#print_settings').data('action-cable')) { - // For Server Print - from jade + // For Server Print - from jade if ($("#server_mode").val() == "cloud") { if(typeof code2lab != 'undefined'){ code2lab.printFile(result.filepath.substr(6), result.printer_url);