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