Class: ODDB::Business::Invoice

Inherits:
Model
  • Object
show all
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

OddbUri::YAML_URI

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#to_yaml_properties

Methods included from Yaml

append_features, #to_yaml_properties

Methods included from OddbUri

#to_yaml, #to_yaml_map, #to_yaml_type

Constructor Details

#initializeInvoice

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

#currencyObject

Returns the value of attribute currency.



10
11
12
# File 'lib/oddb/business/invoice.rb', line 10

def currency
  @currency
end

#ipnObject

Returns the value of attribute ipn.



10
11
12
# File 'lib/oddb/business/invoice.rb', line 10

def ipn
  @ipn
end

#statusObject

Returns the value of attribute status.



10
11
12
# File 'lib/oddb/business/invoice.rb', line 10

def status
  @status
end

#timeObject (readonly)

Returns the value of attribute time.



11
12
13
# File 'lib/oddb/business/invoice.rb', line 11

def time
  @time
end

#ydim_idObject

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_nameObject

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

#idObject



53
54
55
# File 'lib/oddb/business/invoice.rb', line 53

def id
  @id ||= Digest::MD5.hexdigest @time.strftime("%c") << @salt << @yus_name
end

Returns:

  • (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_bruttoObject



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

#typesObject



64
65
66
# File 'lib/oddb/business/invoice.rb', line 64

def types
  @items.collect { |item| item.type }.compact.uniq
end