Class: YDIM::Debitor
- Inherits:
-
Object
- Object
- YDIM::Debitor
- 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
-
#address_lines ⇒ Object
Returns the value of attribute address_lines.
-
#autoinvoices ⇒ Object
readonly
Returns the value of attribute autoinvoices.
-
#contact ⇒ Object
Returns the value of attribute contact.
-
#contact_firstname ⇒ Object
Returns the value of attribute contact_firstname.
-
#contact_title ⇒ Object
Returns the value of attribute contact_title.
-
#country ⇒ Object
Returns the value of attribute country.
-
#debitor_type ⇒ Object
Returns the value of attribute debitor_type.
-
#email ⇒ Object
Returns the value of attribute email.
-
#invoices ⇒ Object
readonly
Returns the value of attribute invoices.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#salutation ⇒ Object
Returns the value of attribute salutation.
-
#unique_id ⇒ Object
readonly
Returns the value of attribute unique_id.
Instance Method Summary collapse
- #add_autoinvoice(invoice) ⇒ Object
- #add_invoice(invoice) ⇒ Object
- #address ⇒ Object
- #autoinvoice(unique_id) ⇒ Object
- #autoinvoice_infos ⇒ Object
- #delete_autoinvoice(invoice) ⇒ Object
- #delete_invoice(invoice) ⇒ Object
- #emails ⇒ Object
- #emails=(emails) ⇒ Object
- #emails_cc ⇒ Object
- #emails_cc=(emails) ⇒ Object
- #foreign? ⇒ Boolean
-
#initialize(unique_id) ⇒ Debitor
constructor
A new instance of Debitor.
- #invoice(unique_id) ⇒ Object
- #invoice_infos(status) ⇒ Object
- #next_invoice_date ⇒ Object
Methods included from ItemId
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_lines ⇒ Object
Returns the value of attribute address_lines.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def address_lines @address_lines end |
#autoinvoices ⇒ Object (readonly)
Returns the value of attribute autoinvoices.
8 9 10 |
# File 'lib/ydim/debitor.rb', line 8 def autoinvoices @autoinvoices end |
#contact ⇒ Object
Returns the value of attribute contact.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def contact @contact end |
#contact_firstname ⇒ Object
Returns the value of attribute contact_firstname.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def contact_firstname @contact_firstname end |
#contact_title ⇒ Object
Returns the value of attribute contact_title.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def contact_title @contact_title end |
#country ⇒ Object
Returns the value of attribute country.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def country @country end |
#debitor_type ⇒ Object
Returns the value of attribute debitor_type.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def debitor_type @debitor_type end |
#email ⇒ Object
Returns the value of attribute email.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def email @email end |
#invoices ⇒ Object (readonly)
Returns the value of attribute invoices.
8 9 10 |
# File 'lib/ydim/debitor.rb', line 8 def invoices @invoices end |
#location ⇒ Object
Returns the value of attribute location.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def name @name end |
#phone ⇒ Object
Returns the value of attribute phone.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def phone @phone end |
#salutation ⇒ Object
Returns the value of attribute salutation.
9 10 11 |
# File 'lib/ydim/debitor.rb', line 9 def salutation @salutation end |
#unique_id ⇒ Object (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 |
#address ⇒ Object
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_infos ⇒ Object
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 |
#emails ⇒ Object
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_cc ⇒ Object
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
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_date ⇒ Object
80 81 82 |
# File 'lib/ydim/debitor.rb', line 80 def next_invoice_date @autoinvoices.collect { |inv| inv.date }.compact.min end |