Class: YDIM::Debitor

Inherits:
Object
  • Object
show all
Includes:
ODBA::Persistable, ItemId
Defined in:
lib/ydim/odba.rb,
lib/ydim/debitor.rb

Constant Summary collapse

ODBA_SERIALIZABLE =
['@address_lines', '@emails_cc', '@hosting_items']

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ItemId

#next_item_id

Constructor Details

#initialize(unique_id) ⇒ Debitor

Returns a new instance of Debitor.



12
13
14
15
16
17
# File 'lib/ydim/debitor.rb', line 12

def initialize(unique_id)
	@unique_id = unique_id
	@address_lines = []
	@invoices = []
    @autoinvoices = []
end

Instance Attribute Details

#address_linesObject

Returns the value of attribute address_lines.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def address_lines
  @address_lines
end

#autoinvoicesObject (readonly)

Returns the value of attribute autoinvoices.



8
9
10
# File 'lib/ydim/debitor.rb', line 8

def autoinvoices
  @autoinvoices
end

#contactObject

Returns the value of attribute contact.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def contact
  @contact
end

#contact_firstnameObject

Returns the value of attribute contact_firstname.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def contact_firstname
  @contact_firstname
end

#contact_titleObject

Returns the value of attribute contact_title.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def contact_title
  @contact_title
end

#countryObject

Returns the value of attribute country.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def country
  @country
end

#debitor_typeObject

Returns the value of attribute debitor_type.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def debitor_type
  @debitor_type
end

#emailObject

Returns the value of attribute email.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def email
  @email
end

#invoicesObject (readonly)

Returns the value of attribute invoices.



8
9
10
# File 'lib/ydim/debitor.rb', line 8

def invoices
  @invoices
end

#locationObject

Returns the value of attribute location.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def location
  @location
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def phone
  @phone
end

#salutationObject

Returns the value of attribute salutation.



9
10
11
# File 'lib/ydim/debitor.rb', line 9

def salutation
  @salutation
end

#unique_idObject (readonly)

Returns the value of attribute unique_id.



8
9
10
# File 'lib/ydim/debitor.rb', line 8

def unique_id
  @unique_id
end

Instance Method Details

#add_autoinvoice(invoice) ⇒ Object



24
25
26
27
# File 'lib/ydim/debitor.rb', line 24

def add_autoinvoice(invoice)
  @autoinvoices.push(invoice)
  invoice
end

#add_invoice(invoice) ⇒ Object



28
29
30
31
# File 'lib/ydim/debitor.rb', line 28

def add_invoice(invoice)
	@invoices.push(invoice)
	invoice
end

#addressObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ydim/debitor.rb', line 32

def address
	lns = [@name]
	lns.push(["z.H.", @salutation, 
					 @contact_firstname, @contact].compact.join(' '))
	lns.push(@contact_title)
	lns.concat(@address_lines)
	lns.push(@location, @country)
    if @email
      lns.push "To: #@email"
      unless emails_cc.empty?
        lns.push "Cc: #{emails_cc.join(', ')}"
      end
    end
	lns.compact!
	lns
end

#autoinvoice(unique_id) ⇒ Object



18
19
20
# File 'lib/ydim/debitor.rb', line 18

def autoinvoice(unique_id)
  @autoinvoices.find { |invoice| invoice.unique_id == unique_id }
end

#autoinvoice_infosObject



21
22
23
# File 'lib/ydim/debitor.rb', line 21

def autoinvoice_infos
  @autoinvoices.collect { |inv| inv.info }
end

#delete_autoinvoice(invoice) ⇒ Object



48
49
50
# File 'lib/ydim/debitor.rb', line 48

def delete_autoinvoice(invoice)
  @autoinvoices.delete(invoice)
end

#delete_invoice(invoice) ⇒ Object



51
52
53
# File 'lib/ydim/debitor.rb', line 51

def delete_invoice(invoice)
	@invoices.delete(invoice)
end

#emailsObject



60
61
62
# File 'lib/ydim/debitor.rb', line 60

def emails
  [ @email ].concat(emails_cc).compact
end

#emails=(emails) ⇒ Object



63
64
65
66
67
# File 'lib/ydim/debitor.rb', line 63

def emails=(emails)
  @email = emails.shift
  @emails_cc = emails
  emails
end

#emails_ccObject



54
55
56
# File 'lib/ydim/debitor.rb', line 54

def emails_cc
  @emails_cc ||= []
end

#emails_cc=(emails) ⇒ Object



57
58
59
# File 'lib/ydim/debitor.rb', line 57

def emails_cc=(emails)
  @emails_cc = emails
end

#foreign?Boolean

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/ydim/debitor.rb', line 68

def foreign?
  @country && !@country.to_s.strip.empty? \
    && @country != Server.config.home_country
end

#invoice(unique_id) ⇒ Object



72
73
74
# File 'lib/ydim/debitor.rb', line 72

def invoice(unique_id)
	@invoices.find { |invoice| invoice.unique_id == unique_id }
end

#invoice_infos(status) ⇒ Object



75
76
77
78
79
# File 'lib/ydim/debitor.rb', line 75

def invoice_infos(status)
	@invoices.select { |inv| 
		inv.status == status 
	}.collect { |inv| inv.info }
end

#next_invoice_dateObject



80
81
82
# File 'lib/ydim/debitor.rb', line 80

def next_invoice_date
	@autoinvoices.collect { |inv| inv.date }.compact.min
end