<commit_before>class Entry < ActiveRecord::Base
  has_many :attachments, dependent: :destroy
  
  validates :number, presence: true
  validates :appliance_id, presence: true
  validates :brand, presence: true
  validates :typenum, presence: true
  validates :serialnum, presence: true
  validates :company, presence: true

  before_save :format_input
  after_save :update_status

  def format_input
    self.brand = self.brand.titleize #stupid missing bang
    self.typenum.upcase!
    self.serialnum.upcase!
  end

  def update_status
    new_status = get_status
    unless new_status == self.status
      self.update_attribute(:status, new_status)
    end
  end

  def get_status
    status = 'New'

    if self.test == 1 or (!self.defect.nil? and self.defect.length != 0)
      status = 'Tested'
    end

    if self.repaired == 1
      status = 'Repaired'
    end

    if self.scrap == 1
      status = 'Scrap'
    end

    if self.accessoires == 1
      status = 'Waiting for accessoires'
    end

    if self.ready == 1
      status = 'Ready'
    end

    if self.sent == 1
      status = 'Sent ' + Invoice.where(id: self.invoice_id).first.created_at.to_date.to_s
    end

    # return status
    status
  end

  def get_status_translated
    if I18n.locale == :en
      status = self.status
    else
      status = I18n.t('entry.status.new')

      if self.test == 1 or (!self.defect.nil? and self.defect.length != 0)
        status = I18n.t('entry.status.tested')
      end

      if self.repaired == 1
        status = I18n.t('entry.status.repaired')
      end

      if self.scrap == 1
        status = I18n.t('entry.status.scrap')
      end

      if self.accessoires == 1
        status = I18n.t('entry.status.accessoires')
      end

      if self.ready == 1
        status = I18n.t('entry.status.ready')
      end

      if self.sent == 1
        status = I18n.t('entry.status.sent') + Invoice.where(id: self.invoice_id).first.created_at.to_date.to_s
      end

      # return status
      status
    end
  end

  def get_barcode(number)
    require 'barby'
    require 'barby/barcode/code_39'
    require 'barby/outputter/svg_outputter'

    barcode = Barby::Code39.new("#{number}")
    barcode.to_svg(height: 60, xdim: 2.5)
  end<commit_msg>and back to 3<commit_after>class Entry < ActiveRecord::Base
  has_many :attachments, dependent: :destroy
  
  validates :number, presence: true
  validates :appliance_id, presence: true
  validates :brand, presence: true
  validates :typenum, presence: true
  validates :serialnum, presence: true
  validates :company, presence: true

  before_save :format_input
  after_save :update_status

  def format_input
    self.brand = self.brand.titleize #stupid missing bang
    self.typenum.upcase!
    self.serialnum.upcase!
  end

  def update_status
    new_status = get_status
    unless new_status == self.status
      self.update_attribute(:status, new_status)
    end
  end

  def get_status
    status = 'New'

    if self.test == 1 or (!self.defect.nil? and self.defect.length != 0)
      status = 'Tested'
    end

    if self.repaired == 1
      status = 'Repaired'
    end

    if self.scrap == 1
      status = 'Scrap'
    end

    if self.accessoires == 1
      status = 'Waiting for accessoires'
    end

    if self.ready == 1
      status = 'Ready'
    end

    if self.sent == 1
      status = 'Sent ' + Invoice.where(id: self.invoice_id).first.created_at.to_date.to_s
    end

    # return status
    status
  end

  def get_status_translated
    if I18n.locale == :en
      status = self.status
    else
      status = I18n.t('entry.status.new')

      if self.test == 1 or (!self.defect.nil? and self.defect.length != 0)
        status = I18n.t('entry.status.tested')
      end

      if self.repaired == 1
        status = I18n.t('entry.status.repaired')
      end

      if self.scrap == 1
        status = I18n.t('entry.status.scrap')
      end

      if self.accessoires == 1
        status = I18n.t('entry.status.accessoires')
      end

      if self.ready == 1
        status = I18n.t('entry.status.ready')
      end

      if self.sent == 1
        status = I18n.t('entry.status.sent') + Invoice.where(id: self.invoice_id).first.created_at.to_date.to_s
      end

      # return status
      status
    end
  end

  def get_barcode(number)
    require 'barby'
    require 'barby/barcode/code_39'
    require 'barby/outputter/svg_outputter'

    barcode = Barby::Code39.new("#{number}")
    barcode.to_svg(height: 60, xdim: 3)
  end
{'fraction_non_alphanumeric': 0.10660460992907801, 'fraction_numerical': 0.016843971631205674, 'mean_word_length': 2.431939163498099, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5404177', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1511, 'n_words': 366}