Class: Invoice
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Invoice
- Defined in:
- app/models/invoice.rb
Class Method Summary collapse
Instance Method Summary collapse
- #fully_paid? ⇒ Boolean
- #late? ⇒ Boolean
-
#open? ⇒ Boolean
Is this invoice current but not fully paid?.
- #outstanding ⇒ Object
- #textilize ⇒ Object
Class Method Details
.closed ⇒ Object
24 25 26 27 |
# File 'app/models/invoice.rb', line 24 def self.closed invoices = self.find(:all) return invoices.select { |invoice| invoice.fully_paid? } end |
.default ⇒ Object
10 11 12 |
# File 'app/models/invoice.rb', line 10 def self.default return Invoice.new({ :due_date => Date.today + Setting.plugin_chiliproject_invoice['invoice_payment_terms'].to_i.days }) end |
.last_invoice_number ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/models/invoice.rb', line 51 def self.last_invoice_number last_invoice = first(:order => 'id DESC') if last_invoice.present? last_invoice.invoice_number else '-' end end |
.late ⇒ Object
19 20 21 22 |
# File 'app/models/invoice.rb', line 19 def self.late invoices = self.find(:all) return invoices.select { |invoice| invoice.late? } end |
.open ⇒ Object
14 15 16 17 |
# File 'app/models/invoice.rb', line 14 def self.open invoices = self.find(:all) return invoices.select { |invoice| invoice.open? } end |
Instance Method Details
#fully_paid? ⇒ Boolean
38 39 40 |
# File 'app/models/invoice.rb', line 38 def fully_paid? outstanding <= 0 end |
#late? ⇒ Boolean
42 43 44 45 |
# File 'app/models/invoice.rb', line 42 def late? return false if fully_paid? return Time.now > self.due_date end |
#open? ⇒ Boolean
Is this invoice current but not fully paid?
34 35 36 |
# File 'app/models/invoice.rb', line 34 def open? !fully_paid? && !late? end |
#outstanding ⇒ Object
47 48 49 |
# File 'app/models/invoice.rb', line 47 def outstanding (total = amount - payments.sum('amount')) > 0 ? total : 0.0 end |
#textilize ⇒ Object
29 30 31 |
# File 'app/models/invoice.rb', line 29 def textilize self.description_html = RedCloth3.new(self.description).to_html end |