Class: DebitInvoice

Inherits:
Invoice
  • Object
show all
Defined in:
app/models/debit_invoice.rb

Constant Summary

Constants inherited from Invoice

Invoice::STATES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Invoice

#active, #amount, #build_booking, #open, #overdue?, #state_adverb, #state_noun, #to_s, #update_code

Methods included from ApplicationHelper

#currency_fmt, #current_tenant, #engine_stylesheet_link_tag, #icon_delete_link_to, #icon_edit_link_to, #list_item_actions_for, #show_new_form

Class Method Details

.direct_accountObject

Accounts



4
5
6
# File 'app/models/debit_invoice.rb', line 4

def self.
  Account.find_by_code("1100")
end

Instance Method Details

#balance_accountObject



8
9
10
# File 'app/models/debit_invoice.rb', line 8

def 
  bookings.first.try(:credit_account)
end

#booking_saved(booking) ⇒ Object

Callback hook



17
18
19
20
21
22
23
# File 'app/models/debit_invoice.rb', line 17

def booking_saved(booking)
  if (self.state != 'canceled') and (self.state != 'reactivated') and (self.amount <= 0.0)
    update_attribute(:state, 'paid')
  elsif !self.overdue? and (self.amount > 0.0)
    update_attribute(:state, 'booked')
  end
end

#profit_accountObject



12
13
14
# File 'app/models/debit_invoice.rb', line 12

def 
  bookings.first.try(:debit_account)
end