From 583d7ee473d76a63658dd1d2f25586ba0da1e16c Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Wed, 12 Aug 2020 15:37:38 +0630 Subject: [PATCH] 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