From c982da42648c3eabb144fdfd5ae524e20658b51f Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 15 Mar 2018 18:56:29 +0630 Subject: [PATCH] add printer brand and api and type --- app/controllers/origami/payments_controller.rb | 11 ++++++++++- app/controllers/print_settings_controller.rb | 13 ++++++++++++- app/models/print_setting.rb | 2 +- app/models/printer/printer_worker.rb | 5 +++++ app/models/printer/receipt_printer.rb | 10 +++++----- app/pdf/receipt_bill_pdf.rb | 15 ++++----------- app/views/origami/home/show.html.erb | 4 +++- app/views/print_settings/_form.html.erb | 18 ++++++++++++++++++ .../_print_setting.json.jbuilder | 2 +- app/views/print_settings/show.html.erb | 8 ++++++++ config/routes.rb | 2 ++ .../20170628103624_create_print_settings.rb | 2 +- 12 files changed, 70 insertions(+), 22 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index c764b92f..fc07f966 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -79,7 +79,16 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil) + + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json end end diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb index 710e6ea4..f12778af 100755 --- a/app/controllers/print_settings_controller.rb +++ b/app/controllers/print_settings_controller.rb @@ -64,6 +64,17 @@ class PrintSettingsController < ApplicationController end end + def get_printer_options + printer_name = params[:printer_name] + printer_options = Printer::PrinterWorker.printer_options(printer_name) + options = { + :url => printer_options['device-uri'], + :model => printer_options['printer-info'], + } + + render :json => options.to_json + end + private # Use callbacks to share common setup or constraints between actions. def set_print_setting @@ -72,7 +83,7 @@ class PrintSettingsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def print_setting_params - params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :font, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space) + params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :brand_name, :printer_type, :font, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space) end #Shop Name in Navbor diff --git a/app/models/print_setting.rb b/app/models/print_setting.rb index d28b852b..a3cfc597 100755 --- a/app/models/print_setting.rb +++ b/app/models/print_setting.rb @@ -1,6 +1,6 @@ class PrintSetting < ApplicationRecord # validations - validates_presence_of :name, :unique_code, :printer_name, :page_width, :page_height, :print_copies + validates_presence_of :name, :unique_code, :printer_name, :brand_name, :api_settings, :page_width, :page_height, :print_copies def self.get_precision_delimiter PrintSetting.find_by_unique_code("ReceiptBillPdf") diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index c0485187..2924853e 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -24,6 +24,11 @@ class Printer::PrinterWorker end end + # Options from printer name + def self.printer_options(printer_name) + Cups.options_for(printer_name) + end + def self.printers() Cups.show_destinations end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index d544c908..597f264a 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -176,7 +176,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker def print_receipt_bill(printer_settings,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) #Use CUPS service #Generate PDF - #Print + #Print pdf = ReceiptBillPdf.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) receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if !receipt_bill_a5_pdf.empty? @@ -202,14 +202,14 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker begin if count == 1 - filename = "/receipts/receipt_bill_#{sale_data.receipt_no}.pdf" - pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf" + filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf" + pdf.render_file filename if printed_status != 'Paid' self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) end else - filename = "/receipts/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" - pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" + filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" + pdf.render_file filename if printed_status != 'Paid' self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name) end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 9926e423..c0299033 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -23,7 +23,7 @@ class ReceiptBillPdf < Prawn::Document # @double = @qty_width * 1.3 # @half_qty = @qty_width / 2 #setting page margin and width - super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin]) + super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) #precision checked if printer_settings.precision.to_i > 2 @@ -121,15 +121,8 @@ class ReceiptBillPdf < Prawn::Document end move_down line_move - y_position = cursor - if sale_data.bookings[0].dining_facility_id.to_i > 0 - bounding_box([0,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :left - end - end - - bounding_box([self.label_width, y_position], :width =>self.label_width, :height => self.item_height) do + bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do @@ -493,8 +486,8 @@ class ReceiptBillPdf < Prawn::Document end #individual payment per person - def individual_payment(sale_data, precision, delimiter) - per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i + def individual_payment(sale_data, survey, precision, delimiter) + per_person = sale_data.grand_total.to_f / survey.total_customer.to_i stroke_horizontal_rule move_down line_move y_position = cursor diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 8c2e58bc..5f0245a9 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -689,7 +689,9 @@ receipt_no = ($("#receipt_no").html()).trim(); if((receipt_no!=undefined) && (receipt_no!="")) createReceiptNoInFirstBillData(receipt_no,""); - + + // console.log(result); + code2lab.printBill(result.filepath, result.printer_model, result.printer_url); location.reload(); } }); diff --git a/app/views/print_settings/_form.html.erb b/app/views/print_settings/_form.html.erb index b8804dcc..bec1b931 100755 --- a/app/views/print_settings/_form.html.erb +++ b/app/views/print_settings/_form.html.erb @@ -12,6 +12,8 @@ <%= f.input :template %> <%= f.input :font %> <%= f.input :printer_name, :as => :select, :collection => Printer::PrinterWorker.printers, include_blank: false %> + <%= f.input :brand_name %> + <%= f.input :printer_type %> <%= f.input :api_settings %> <%= f.input :page_width %> <%= f.input :page_height %> @@ -61,6 +63,22 @@