Class: Invoice

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/invoice.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.closedObject



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

.defaultObject



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_numberObject



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

.lateObject



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

.openObject



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

Returns:

  • (Boolean)


38
39
40
# File 'app/models/invoice.rb', line 38

def fully_paid?
  outstanding <= 0
end

#late?Boolean

Returns:

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

Returns:

  • (Boolean)


34
35
36
# File 'app/models/invoice.rb', line 34

def open?
  !fully_paid? && !late?
end

#outstandingObject



47
48
49
# File 'app/models/invoice.rb', line 47

def outstanding
  (total = amount - payments.sum('amount')) > 0 ? total : 0.0
end

#textilizeObject



29
30
31
# File 'app/models/invoice.rb', line 29

def textilize
  self.description_html = RedCloth3.new(self.description).to_html
end