2021-07-23 19:52:28 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class LabelPrinter < ApplicationRecord
|
2021-08-02 17:11:11 +08:00
|
|
|
FLUICS_STATUS_MAP = Hash.new(:error).merge(
|
|
|
|
{
|
|
|
|
'00' => :ready,
|
|
|
|
'50' => :busy,
|
|
|
|
'60' => :busy,
|
|
|
|
'01' => :out_of_labels,
|
|
|
|
'02' => :out_of_labels
|
|
|
|
}
|
|
|
|
).freeze
|
|
|
|
|
2022-08-26 16:53:55 +08:00
|
|
|
enum type_of: { fluics: 0, zebra: 1 }
|
2021-07-23 19:52:28 +08:00
|
|
|
enum language_type: { zpl: 0 }
|
2021-08-02 17:11:11 +08:00
|
|
|
enum status: { ready: 0, busy: 1, out_of_labels: 2, unreachable: 3, error: 4 }
|
2021-07-23 19:52:28 +08:00
|
|
|
|
|
|
|
validates :name, presence: true
|
|
|
|
validates :type_of, presence: true
|
|
|
|
validates :language_type, presence: true
|
|
|
|
|
2022-09-05 18:37:03 +08:00
|
|
|
def self.available_printers
|
|
|
|
printers = all
|
|
|
|
printers = printers.where.not(type_of: :zebra) unless Rails.configuration.x.zebra_print_enabled
|
|
|
|
printers
|
|
|
|
end
|
|
|
|
|
2021-08-02 17:11:11 +08:00
|
|
|
def display_name
|
|
|
|
"#{name} • #{description}"
|
2021-07-23 19:52:28 +08:00
|
|
|
end
|
2021-08-02 21:33:51 +08:00
|
|
|
|
|
|
|
def done?
|
|
|
|
current_print_job_ids.blank? && ready?
|
|
|
|
end
|
|
|
|
|
|
|
|
def printing?
|
|
|
|
current_print_job_ids.any? && ready?
|
|
|
|
end
|
|
|
|
|
|
|
|
def printing_status
|
|
|
|
return 'printing' if printing?
|
|
|
|
|
|
|
|
return 'done' if done?
|
|
|
|
|
|
|
|
status
|
|
|
|
end
|
2021-07-23 19:52:28 +08:00
|
|
|
end
|