Class: Invoice
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Invoice
show all
- Includes:
- ApplicationHelper, HasAccounts::Model
- Defined in:
- app/models/invoice.rb
Constant Summary
collapse
- STATES =
['booked', 'canceled', 'paid', 'reactivated', 'reminded', '2xreminded', '3xreminded', 'encashment', 'written_off']
Instance Method Summary
collapse
#currency_fmt, #current_tenant, #engine_stylesheet_link_tag, #icon_delete_link_to, #icon_edit_link_to, #list_item_actions_for, #show_new_form
Instance Method Details
#active ⇒ Object
83
84
85
|
# File 'app/models/invoice.rb', line 83
def active
!(state == 'canceled' or state == 'reactivated' or state == 'written_off')
end
|
#amount ⇒ Object
133
134
135
|
# File 'app/models/invoice.rb', line 133
def amount
self[:amount] || line_items.sum('times * price').to_f
end
|
#build_booking(params = {}, template_code = nil) ⇒ Object
Build booking
We pass the value_date to the booking
119
120
121
122
123
124
125
126
|
# File 'app/models/invoice.rb', line 119
def build_booking(params = {}, template_code = nil)
invoice_params = {:value_date => self.value_date}
template_code ||= self.class.to_s.underscore + ':invoice'
invoice_params.merge!(params)
super(invoice_params, template_code)
end
|
#open ⇒ Object
87
88
89
|
# File 'app/models/invoice.rb', line 87
def open
active and !(state == 'paid')
end
|
#overdue? ⇒ Boolean
99
100
101
102
103
104
105
106
|
# File 'app/models/invoice.rb', line 99
def overdue?
return true if state == 'booked' and due_date < Date.today
return true if state == 'reminded' and (reminder_due_date.nil? or reminder_due_date < Date.today)
return true if state == '2xreminded' and (second_reminder_due_date.nil? or second_reminder_due_date < Date.today)
return true if state == '3xreminded' and (third_reminder_due_date.nil? or third_reminder_due_date < Date.today)
return false
end
|
#state_adverb ⇒ Object
91
92
93
|
# File 'app/models/invoice.rb', line 91
def state_adverb
I18n.t state, :scope => 'invoice.state'
end
|
#state_noun ⇒ Object
95
96
97
|
# File 'app/models/invoice.rb', line 95
def state_noun
I18n.t state, :scope => 'invoice.state_noun'
end
|
#to_s(format = :default) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/models/invoice.rb', line 18
def to_s(format = :default)
return "" if amount.nil?
identifier = title
identifier += " / #{code}" if code.present?
case format
when :reference
return identifier + " (#{customer.to_s})"
when :long
return "%s: %s für %s à %s" % [I18n::localize(value_date), ident, customer, currency_fmt(amount)]
else
return identifier
end
end
|
#update_code ⇒ Object
35
36
37
38
39
40
|
# File 'app/models/invoice.rb', line 35
def update_code
code = value_date.strftime("%y%m")
code += "%04i" % id
self.code = code
end
|