receipt update
This commit is contained in:
50
app/models/printer/printer_worker.rb
Normal file
50
app/models/printer/printer_worker.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
require 'net/http'
|
||||
require 'cups'
|
||||
|
||||
class Printer::PrinterWorker
|
||||
attr_accessor :print_settings
|
||||
|
||||
def initialize(print_settings)
|
||||
self.print_settings = print_settings
|
||||
end
|
||||
|
||||
def printer_destination()
|
||||
if self.print_settings
|
||||
self.print_settings.printer_name
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def print_copies()
|
||||
if self.print_settings
|
||||
self.print_settings.print_copies.to_i
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
def printers()
|
||||
Cups.show_destinations
|
||||
end
|
||||
|
||||
def default_printer()
|
||||
Cups.default_printer
|
||||
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
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user