Module: NameEntity::Quality

Instance Method Summary collapse

Instance Method Details

#billable_status_is_validObject



40
41
42
43
44
45
46
# File 'lib/quickbooks/util/name_entity.rb', line 40

def billable_status_is_valid
  if billable_status
    unless %w(Billable NotBillable HasBeenBilled).include?(billable_status)
      errors.add(:posting_type, "Posting Type must be either 'Debit' or 'Credit'")
    end
  end
end

#email_addressObject



8
9
10
# File 'lib/quickbooks/util/name_entity.rb', line 8

def email_address
  primary_email_address
end

#email_address=(email_address) ⇒ Object



4
5
6
# File 'lib/quickbooks/util/name_entity.rb', line 4

def email_address=(email_address)
  self.primary_email_address = Quickbooks::Model::EmailAddress.new(email_address)
end

#email_address_is_validObject



22
23
24
25
26
27
28
29
30
# File 'lib/quickbooks/util/name_entity.rb', line 22

def email_address_is_valid
  if primary_email_address
    address = primary_email_address.address.to_s
    return false if address.length == 0
    unless address.index('@') && address.index('.')
      errors.add(:primary_email_address, "Email address must contain @ and . (dot)")
    end
  end
end

#entity_type_is_validObject



48
49
50
51
52
53
54
# File 'lib/quickbooks/util/name_entity.rb', line 48

def entity_type_is_valid
  if entity_type
    unless %w(Customer Vendor).include?(entity_type)
      errors.add(:entity_type, "Entity Type must be either 'Customer' or 'Vendor'")
    end
  end
end

#journal_line_entry_taxObject



56
57
58
59
60
61
62
# File 'lib/quickbooks/util/name_entity.rb', line 56

def journal_line_entry_tax
  if tax_code_ref
    # tax_applicable_on must be set
    errors.add(:tax_applicable_on, "TaxApplicableOn must be set when TaxCodeRef is set") if tax_applicable_on.nil?
    errors.add(:tax_amount, "TaxAmount must be set when TaxCodeRef is set") if tax_amount.nil?
  end
end

#names_cannot_contain_invalid_charactersObject



12
13
14
15
16
17
18
19
20
# File 'lib/quickbooks/util/name_entity.rb', line 12

def names_cannot_contain_invalid_characters
  [:name, :display_name, :given_name, :middle_name, :family_name, :print_on_check_name].each do |property|
    next unless respond_to? property
    value = send(property).to_s
    if value.index(':')
      errors.add(property, ":#{property} cannot contain a colon (:).")
    end
  end
end

#posting_type_is_validObject



32
33
34
35
36
37
38
# File 'lib/quickbooks/util/name_entity.rb', line 32

def posting_type_is_valid
  if posting_type
    unless %w(Debit Credit).include?(posting_type)
      errors.add(:posting_type, "Posting Type must be either 'Debit' or 'Credit'")
    end
  end
end