From c8b04717941a10629accb253296dcd631a3d7e38 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 24 Aug 2020 11:42:44 +0630 Subject: [PATCH] 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