Class: ODDB::Invoice

Inherits:
Object show all
Includes:
Persistence
Defined in:
src/model/invoice.rb

Constant Summary

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from PersistenceMethods

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

Constructor Details

- (Invoice) initialize

A new instance of Invoice



12
13
14
15
16
17
# File 'src/model/invoice.rb', line 12

def initialize
  super
  @items = {}
  @payment_received = false
  @unexpirable = false
end

Instance Attribute Details

- (Object) currency

Returns the value of attribute currency



11
12
13
# File 'src/model/invoice.rb', line 11

def currency
  @currency
end

- (Object) items (readonly)

Returns the value of attribute items



10
11
12
# File 'src/model/invoice.rb', line 10

def items
  @items
end

- (Object) keep_if_unpaid

Returns the value of attribute keep_if_unpaid



11
12
13
# File 'src/model/invoice.rb', line 11

def keep_if_unpaid
  @keep_if_unpaid
end

- (Object) user_pointer

Returns the value of attribute user_pointer



11
12
13
# File 'src/model/invoice.rb', line 11

def user_pointer
  @user_pointer
end

- (Object) ydim_id

Returns the value of attribute ydim_id



11
12
13
# File 'src/model/invoice.rb', line 11

def ydim_id
  @ydim_id
end

- (Object) yus_name

Returns the value of attribute yus_name



11
12
13
# File 'src/model/invoice.rb', line 11

def yus_name
  @yus_name
end

Instance Method Details

- (Object) create_item



26
27
28
29
# File 'src/model/invoice.rb', line 26

def create_item
  item = InvoiceItem.new
  @items.store(item.oid, item)
end

- (Boolean) deletable?

Returns:

  • (Boolean)


30
31
32
# File 'src/model/invoice.rb', line 30

def deletable?
  !(@payment_received || @keep_if_unpaid) && expired?
end

- (Boolean) expired?(time = nil)

Returns:

  • (Boolean)


33
34
35
# File 'src/model/invoice.rb', line 33

def expired?(time=nil)
  @items.values.all? { |item| item.expired?(time) }
end

- (Object) init(app)



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

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

- (Object) item(oid)



36
37
38
# File 'src/model/invoice.rb', line 36

def item(oid)
  @items[oid]
end

- (Object) item_by_text(text)



21
22
23
24
25
# File 'src/model/invoice.rb', line 21

def item_by_text(text)
  @items.values.find { |item|
    item.text == text
  }
end

- (Object) max_duration



39
40
41
# File 'src/model/invoice.rb', line 39

def max_duration
  @items.values.collect { |item| item.duration }.compact.max
end

- (Object) payment_received!



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

def payment_received!
  @payment_received = true
end

- (Boolean) payment_received?

Returns:

  • (Boolean)


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

def payment_received?
  @payment_received
end

- (Object) total_brutto



42
43
44
# File 'src/model/invoice.rb', line 42

def total_brutto
  @items.values.inject(0) { |inj, item| inj + item.total_brutto }
end

- (Object) total_netto



45
46
47
# File 'src/model/invoice.rb', line 45

def total_netto
  @items.values.inject(0) { |inj, item| inj + item.total_netto }
end

- (Object) types



48
49
50
# File 'src/model/invoice.rb', line 48

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

- (Object) vat



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

def vat
  @items.values.inject(0) { |inj, item| inj + item.vat }
end