Class: Journal::Bill

Inherits:
Journal
  • Object
show all
Defined in:
lib/bookkeeper/journal/bill.rb

Instance Method Summary collapse

Methods inherited from Journal

#destroy, #transactable_type=

Instance Method Details

#amountObject



5
6
7
# File 'lib/bookkeeper/journal/bill.rb', line 5

def amount
  postings.find(:first, :conditions => {:account_id => Account.accounts_payable}).amount
end

#amount_paidObject



9
10
11
# File 'lib/bookkeeper/journal/bill.rb', line 9

def amount_paid
  payments.inject(0) { |sum, payment| sum - payment.postings.find(:first, :conditions => {:account_id => Account.accounts_payable}).amount }
end

#overpaid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/bookkeeper/journal/bill.rb', line 17

def overpaid?
  amount_paid > amount
end

Returns:

  • (Boolean)


13
14
15
# File 'lib/bookkeeper/journal/bill.rb', line 13

def paid_in_full?
  amount_paid >= amount
end

#pay(payment_transaction) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bookkeeper/journal/bill.rb', line 21

def pay(payment_transaction)
  gross = payment_transaction.notification.amount.cents.to_f / 100
  
  journal = Journal::Disbursement.new(:transactable => payment_transaction)
  
  journal.postings |= payment_transaction.to_postings
  journal.postings << Account.accounts_payable.debit(gross)
  
  payments << journal
  save!
end