Class: ODDB::Company

Inherits:
Object show all
Includes:
AddressObserver, OddbYaml, Persistence, RegistrationObserver, UserObserver
Defined in:
src/model/company.rb,
test/test_model/company.rb,
ext/export/src/oddb_yaml.rb,
src/custom/lookandfeelbase.rb

Constant Summary

ODBA_SERIALIZABLE =
['@addresses', '@invoice_dates', '@disabled_invoices', 
'@prices', '@users']
EXPORT_PROPERTIES =
[
  '@oid',
  '@ean13',
  '@name',
  '@business_area',
  '@generic_type',
  '@registrations',
  '@url',
  '@email',
  '@addresses',
  '@contact',
  '@contact_email',
]

Constants included from OddbYaml

EXPORT_PROPERTIES, YAML_URI

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from OddbYaml

#to_yaml_properties, #to_yaml_type

Methods included from AddressObserver

#address, #address_item, #create_address, #ydim_address_lines, #ydim_location

Methods included from UserObserver

#add_user, #contact_email, #has_user?, #remove_user, #users

Methods included from RegistrationObserver

#add_registration, #article_codes, #empty?, #iksnrs, #registration_count, #remove_registration

Methods included from PersistenceMethods

#checkout, #data_origin, #data_origins, #diff, #nil_if_empty, #parent, #structural_ancestors, #undiffable?, #update_values

Constructor Details

- (Company) initialize

A new instance of Company



30
31
32
33
34
35
36
37
# File 'src/model/company.rb', line 30

def initialize
  @addresses = [Address2.new]
  @cl_status = false
  @invoice_dates = {}
  @disabled_invoices = {}
  @prices = {}
  super
end

Instance Attribute Details

- (Object) address_email Also known as: email

Returns the value of attribute address_email



18
19
20
# File 'src/model/company.rb', line 18

def address_email
  @address_email
end

- (Object) business_area

Returns the value of attribute business_area



18
19
20
# File 'src/model/company.rb', line 18

def business_area
  @business_area
end

- (Object) business_unit

Returns the value of attribute business_unit



18
19
20
# File 'src/model/company.rb', line 18

def business_unit
  @business_unit
end

- (Object) cl_status

Returns the value of attribute cl_status



18
19
20
# File 'src/model/company.rb', line 18

def cl_status
  @cl_status
end

- (Object) competition_email

Returns the value of attribute competition_email



18
19
20
# File 'src/model/company.rb', line 18

def competition_email
  @competition_email
end

- (Object) complementary_type

Returns the value of attribute complementary_type



18
19
20
# File 'src/model/company.rb', line 18

def complementary_type
  @complementary_type
end

- (Object) contact

Returns the value of attribute contact



18
19
20
# File 'src/model/company.rb', line 18

def contact
  @contact
end

- (Object) deductible_display

Returns the value of attribute deductible_display



18
19
20
# File 'src/model/company.rb', line 18

def deductible_display
  @deductible_display
end

- (Object) disable_patinfo

Returns the value of attribute disable_patinfo



18
19
20
# File 'src/model/company.rb', line 18

def disable_patinfo
  @disable_patinfo
end

- (Object) disabled_invoices (readonly)

Returns the value of attribute disabled_invoices



24
25
26
# File 'src/model/company.rb', line 24

def disabled_invoices
  @disabled_invoices
end

- (Object) ean13

Returns the value of attribute ean13



18
19
20
# File 'src/model/company.rb', line 18

def ean13
  @ean13
end

- (Object) force_new_ydim_debitor

Returns the value of attribute force_new_ydim_debitor



18
19
20
# File 'src/model/company.rb', line 18

def force_new_ydim_debitor
  @force_new_ydim_debitor
end

- (Object) generic_type

Returns the value of attribute generic_type



18
19
20
# File 'src/model/company.rb', line 18

def generic_type
  @generic_type
end

- (Object) invoice_dates (readonly)

Returns the value of attribute invoice_dates



24
25
26
# File 'src/model/company.rb', line 24

def invoice_dates
  @invoice_dates
end

- (Object) invoice_htmlinfos

Returns the value of attribute invoice_htmlinfos



18
19
20
# File 'src/model/company.rb', line 18

def invoice_htmlinfos
  @invoice_htmlinfos
end

- (Object) limit_invoice_duration

Returns the value of attribute limit_invoice_duration



18
19
20
# File 'src/model/company.rb', line 18

def limit_invoice_duration
  @limit_invoice_duration
end

- (Object) logo_filename

Returns the value of attribute logo_filename



18
19
20
# File 'src/model/company.rb', line 18

def logo_filename
  @logo_filename
end

- (Object) lookandfeel_member_count

Returns the value of attribute lookandfeel_member_count



18
19
20
# File 'src/model/company.rb', line 18

def lookandfeel_member_count
  @lookandfeel_member_count
end

- (Object) name Also known as: to_s, fullname

Returns the value of attribute name



18
19
20
# File 'src/model/company.rb', line 18

def name
  @name
end

Returns the value of attribute powerlink



18
19
20
# File 'src/model/company.rb', line 18

def powerlink
  @powerlink
end

- (Object) registrations

Returns the value of attribute registrations



14
15
16
# File 'test/test_model/company.rb', line 14

def registrations
  @registrations
end

- (Object) regulatory_email

Returns the value of attribute regulatory_email



18
19
20
# File 'src/model/company.rb', line 18

def regulatory_email
  @regulatory_email
end

- (Object) swissmedic_email

Returns the value of attribute swissmedic_email



18
19
20
# File 'src/model/company.rb', line 18

def swissmedic_email
  @swissmedic_email
end

- (Object) swissmedic_salutation

Returns the value of attribute swissmedic_salutation



18
19
20
# File 'src/model/company.rb', line 18

def swissmedic_salutation
  @swissmedic_salutation
end

- (Object) url

Returns the value of attribute url



18
19
20
# File 'src/model/company.rb', line 18

def url
  @url
end

- (Object) ydim_id

Returns the value of attribute ydim_id



18
19
20
# File 'src/model/company.rb', line 18

def ydim_id
  @ydim_id
end

Instance Method Details

- (Object) active_package_count



41
42
43
44
45
# File 'src/model/company.rb', line 41

def active_package_count
  @registrations.inject(0) { |sum, reg|
    sum + reg.active_package_count
  }
end

- (Object) adjust_types(input, app = nil)



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'src/model/company.rb', line 177

def adjust_types(input, app=nil)
  input.each { |key, val|
    case key
    when :powerlink
      if(val.to_s.empty?)
        input[key] = nil
      end
    when :generic_type, :complementary_type
      if(val.is_a? String)
        input[key] = val.intern
      end
    when :price_lookandfeel, :price_lookandfeel_member, 
      :price_index, :price_index_package
      input[key] = (val.to_f * 100) unless(val.nil?)
    end
  }
  input
end

- (Object) atc_classes



46
47
48
49
50
# File 'src/model/company.rb', line 46

def atc_classes
  @registrations.inject([]) do |memo, registration|
    memo.concat registration.atc_classes        
  end.compact.uniq
end

- (Object) disable_invoice_fachinfo



51
52
53
# File 'src/model/company.rb', line 51

def disable_invoice_fachinfo
  invoice_disabled?(:fachinfo)
end

- (Object) disable_invoice_fachinfo=(status)



54
55
56
# File 'src/model/company.rb', line 54

def disable_invoice_fachinfo=(status)
  @disabled_invoices[:fachinfo] = status
end

- (Object) disable_invoice_patinfo



57
58
59
# File 'src/model/company.rb', line 57

def disable_invoice_patinfo
  invoice_disabled?(:patinfo)
end

- (Object) disable_invoice_patinfo=(status)



60
61
62
# File 'src/model/company.rb', line 60

def disable_invoice_patinfo=(status)
  @disabled_invoices[:patinfo] = status
end

- (Object) inactive_packages



63
64
65
66
67
# File 'src/model/company.rb', line 63

def inactive_packages
  packages.select { |pac|
    (date = pac.market_date) && date > @@today
  }
end

- (Object) inactive_registrations



68
69
70
71
72
# File 'src/model/company.rb', line 68

def inactive_registrations
  @registrations.reject { |registration|
    registration.public_package_count > 0
  }
end

- (Object) init(app)



38
39
40
# File 'src/model/company.rb', line 38

def init(app)
  @pointer.append(@oid)
end

- (Object) invoice_date(key)



79
80
81
# File 'src/model/company.rb', line 79

def invoice_date(key)
  @invoice_dates[key] = _yearly_repetition(@invoice_dates[key])
end

- (Object) invoice_date_fachinfo



82
83
84
# File 'src/model/company.rb', line 82

def invoice_date_fachinfo
  invoice_date(:fachinfo)
end

- (Object) invoice_date_fachinfo=(date)



85
86
87
# File 'src/model/company.rb', line 85

def invoice_date_fachinfo=(date)
  @invoice_dates[:fachinfo] = date
end

- (Object) invoice_date_index



88
89
90
# File 'src/model/company.rb', line 88

def invoice_date_index
  invoice_date(:index)
end

- (Object) invoice_date_index=(date)



91
92
93
# File 'src/model/company.rb', line 91

def invoice_date_index=(date)
  @invoice_dates[:index] = date
end

- (Object) invoice_date_lookandfeel



94
95
96
# File 'src/model/company.rb', line 94

def invoice_date_lookandfeel
  invoice_date(:lookandfeel)
end

- (Object) invoice_date_lookandfeel=(date)



97
98
99
# File 'src/model/company.rb', line 97

def invoice_date_lookandfeel=(date)
  @invoice_dates[:lookandfeel] = date
end

- (Object) invoice_date_patinfo



100
101
102
# File 'src/model/company.rb', line 100

def invoice_date_patinfo
  invoice_date(:patinfo)
end

- (Object) invoice_date_patinfo=(date)



103
104
105
# File 'src/model/company.rb', line 103

def invoice_date_patinfo=(date)
  @invoice_dates[:patinfo] = date
end

- (Boolean) invoice_disabled?(key)

Returns:

  • (Boolean)


106
107
108
# File 'src/model/company.rb', line 106

def invoice_disabled?(key)
  @disabled_invoices[key]
end

- (Boolean) invoiceable?

to be invoiceable, the company needs to have a complete address:

Returns:

  • (Boolean)


74
75
76
77
78
# File 'src/model/company.rb', line 74

def invoiceable?
  addr = address(0)
  ![ @name, @contact, addr.address, addr.plz, 
    addr.city, invoice_email, addr.fon ].any? { |datum| datum.nil? }
end

- (Boolean) listed?

Returns:

  • (Boolean)


109
110
111
# File 'src/model/company.rb', line 109

def listed?
  @cl_status
end

- (Object) merge(other)



112
113
114
115
116
117
118
# File 'src/model/company.rb', line 112

def merge(other)
  other.registrations.dup.each { |reg|
    reg.company = self
    reg.odba_isolated_store
  }
  @registrations.odba_isolated_store
end

- (Object) packages



171
172
173
174
175
# File 'src/model/company.rb', line 171

def packages
  @registrations.inject([]) { |memo, reg|
    memo.concat(reg.packages)
  }
end

- (Object) pointer_descr



119
120
121
# File 'src/model/company.rb', line 119

def pointer_descr
  @name
end

- (Object) price(key)



122
123
124
# File 'src/model/company.rb', line 122

def price(key)
  @prices[key]
end

- (Object) price_fachinfo



125
126
127
# File 'src/model/company.rb', line 125

def price_fachinfo
  price(:fachinfo)
end

- (Object) price_fachinfo=(units)



128
129
130
# File 'src/model/company.rb', line 128

def price_fachinfo=(units)
  @prices[:fachinfo] = units
end

- (Object) price_index



131
132
133
# File 'src/model/company.rb', line 131

def price_index
  price(:index)
end

- (Object) price_index=(cents)



134
135
136
# File 'src/model/company.rb', line 134

def price_index=(cents)
  @prices[:index] = cents
end

- (Object) price_index_package



137
138
139
# File 'src/model/company.rb', line 137

def price_index_package
  price(:index_package)
end

- (Object) price_index_package=(cents)



140
141
142
# File 'src/model/company.rb', line 140

def price_index_package=(cents)
  @prices[:index_package] = cents
end

- (Object) price_lookandfeel



143
144
145
# File 'src/model/company.rb', line 143

def price_lookandfeel
  price(:lookandfeel)
end

- (Object) price_lookandfeel=(cents)



146
147
148
# File 'src/model/company.rb', line 146

def price_lookandfeel=(cents)
  @prices[:lookandfeel] = cents
end

- (Object) price_lookandfeel_member



149
150
151
# File 'src/model/company.rb', line 149

def price_lookandfeel_member
  price(:lookandfeel_member)
end

- (Object) price_lookandfeel_member=(cents)



152
153
154
# File 'src/model/company.rb', line 152

def price_lookandfeel_member=(cents)
  @prices[:lookandfeel_member] = cents
end

- (Object) price_patinfo



155
156
157
# File 'src/model/company.rb', line 155

def price_patinfo
  price(:patinfo)
end

- (Object) price_patinfo=(units)



158
159
160
# File 'src/model/company.rb', line 158

def price_patinfo=(units)
  @prices[:patinfo] = units
end

- (Object) search_terms



161
162
163
164
165
166
167
168
169
170
# File 'src/model/company.rb', line 161

def search_terms
  terms = @name.split(/[\s\-()]+/u).select { |str| str.size >= 3 }
  terms += [
    @name, @ean13, 
  ]
  @addresses.each { |addr| 
    terms += addr.search_terms
  }
  ODDB.search_terms(terms)
end