lib/sapos/print/printer.rb in sapos-print-1.0.7 vs lib/sapos/print/printer.rb in sapos-print-1.0.8
- old
+ new
@@ -8,11 +8,11 @@
end
def print(args = {})
raw_message = args[:document]
- log_text = "Print #{args[:document_number]},#{args[:print_control]}"
+ log_text = "id=#{args[:id]},doc=#{args[:document_number]},control=#{args[:print_control] ? "SI" : "NO"}\t"
filename = "#{args[:document_number]}.print" if args[:document_number]
filename = SecureRandom.hex if filename.nil?
result = false
raw = raw_message.force_encoding("UTF-8")
begin
@@ -25,10 +25,13 @@
printable = data(raw_message)
File.open(filename, 'w'){|f| f.write(printable)}
result = send_to_printer({file: filename})
#puts "Result: #{result}"
log_text += " => OK"
+ else
+ result = true
+ log_text += " => DUPLICADO"
end
else
printable = data(raw_message)
File.open(filename, 'w'){|f| f.write(printable)}
result = send_to_printer({file: filename})
@@ -47,11 +50,10 @@
end
end
def data(raw_message)
- puts "data: #{@config.interface}"
case @config.interface
when 'text'
return raw_message
when 'escp'
esc = "\x1B" #ESC byte in hex notation
@@ -69,20 +71,20 @@
end
def send_to_printer(opts = {})
case @config.adapter
when 'console'
- puts "=> CONSOLE: file: #{opts[:file]}<="
+ puts "=> CONSOLE: file: #{opts[:file]}<=\n\n"
puts File.read(opts[:file])
- puts "=> END CONSOLE =<"
+ puts "\n=> END CONSOLE =<"
return true
when 'cups'
file = opts.delete(:file)
command_options = []
command_options << "-d #{@printer_name}"
command_options << "-o raw" if opts[:raw].present?
command = "lp #{command_options.join(" ")} #{file}"
- puts "CMD => #{command}"
+ puts "CMD => #{command}" if @config.verbose
if !system(command)
puts "Not executed"
return false
end
return true
\ No newline at end of file