Class: ODDB::Business::Invoice
- Defined in:
- lib/oddb/business/invoice.rb,
lib/oddb/persistence/odba/business/invoice.rb
Defined Under Namespace
Classes: Item
Constant Summary
Constants included from OddbUri
Instance Attribute Summary collapse
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#ipn ⇒ Object
Returns the value of attribute ipn.
-
#status ⇒ Object
Returns the value of attribute status.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#ydim_id ⇒ Object
Returns the value of attribute ydim_id.
-
#yus_name ⇒ Object
Returns the value of attribute yus_name.
Instance Method Summary collapse
- #add(*args) ⇒ Object
- #id ⇒ Object
-
#initialize ⇒ Invoice
constructor
A new instance of Invoice.
- #paid_for?(text) ⇒ Boolean
- #total_brutto ⇒ Object
- #types ⇒ Object
Methods inherited from Model
#__odba_delete__, #__odba_save__, _serializables, belongs_to, connections, connector, connectors, #data_origin, #data_origins, delegates, #delete, find_by_uid, has_many, is_coded, m10l_document, multilingual, #odba_serializables, #oid, on_delete, on_save, predicates, #save, #saved?, serializables, serialize, singular
Methods included from ODBA::Persistable
Methods included from Yaml
append_features, #to_yaml_properties
Methods included from OddbUri
#to_yaml, #to_yaml_map, #to_yaml_type
Constructor Details
#initialize ⇒ Invoice
Returns a new instance of Invoice.
43 44 45 46 47 48 49 |
# File 'lib/oddb/business/invoice.rb', line 43 def initialize @items = [] @salt = generate_salt @time = Time.now @yus_name = '' @currency = 'EUR' end |
Instance Attribute Details
#currency ⇒ Object
Returns the value of attribute currency.
10 11 12 |
# File 'lib/oddb/business/invoice.rb', line 10 def currency @currency end |
#ipn ⇒ Object
Returns the value of attribute ipn.
10 11 12 |
# File 'lib/oddb/business/invoice.rb', line 10 def ipn @ipn end |
#status ⇒ Object
Returns the value of attribute status.
10 11 12 |
# File 'lib/oddb/business/invoice.rb', line 10 def status @status end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
11 12 13 |
# File 'lib/oddb/business/invoice.rb', line 11 def time @time end |
#ydim_id ⇒ Object
Returns the value of attribute ydim_id.
10 11 12 |
# File 'lib/oddb/business/invoice.rb', line 10 def ydim_id @ydim_id end |
#yus_name ⇒ Object
Returns the value of attribute yus_name.
10 11 12 |
# File 'lib/oddb/business/invoice.rb', line 10 def yus_name @yus_name end |
Instance Method Details
#add(*args) ⇒ Object
50 51 52 |
# File 'lib/oddb/business/invoice.rb', line 50 def add(*args) add_item Item.new(*args) end |
#id ⇒ Object
53 54 55 |
# File 'lib/oddb/business/invoice.rb', line 53 def id @id ||= Digest::MD5.hexdigest @time.strftime("%c") << @salt << @yus_name end |
#paid_for?(text) ⇒ Boolean
56 57 58 |
# File 'lib/oddb/business/invoice.rb', line 56 def paid_for?(text) @status == 'completed' && @items.any? { |item| item.text == text } end |
#total_brutto ⇒ Object
59 60 61 62 63 |
# File 'lib/oddb/business/invoice.rb', line 59 def total_brutto @items.inject(Util::Money.new(0)) { |memo, item| memo + item.total_brutto } end |
#types ⇒ Object
64 65 66 |
# File 'lib/oddb/business/invoice.rb', line 64 def types @items.collect { |item| item.type }.compact.uniq end |