Skip to content
Newer
Older
100644 73 lines (59 sloc) 3.46 KB
983db8a fixed loads of applicable fee issues
Siddharth authored
1 class AccountPaymentObserver
021e81c Rule book & payment observer is added
ravi authored
2 include DataMapper::Observer
fbb8928 cleaned up repayment styles
Siddharth authored
3 observe BranchDiary
4
1593436 Rule book added
ravi authored
5 def self.make_posting_entries(obj)
ce1f61c @Gazal24 observer for Payment updated
Gazal24 authored
6 # This function will make entries to the posting database when save, update or delete envent triggers
c1b5024 @piyushranjan Rules engine to have journal type
piyushranjan authored
7 credit_accounts, debit_accounts, rules = RuleBook.get_accounts(obj)
de3d67a @Gazal24 changes in observer, added journal resource, manual entry for transac…
Gazal24 authored
8 # do not do accounting if no matching accounts
8b842b5 @piyushranjan Multi account support and split of amount support added
piyushranjan authored
9 return unless (credit_accounts and debit_accounts)
10 return unless (credit_accounts.length>=0 and debit_accounts.length>=0)
de3d67a @Gazal24 changes in observer, added journal resource, manual entry for transac…
Gazal24 authored
11
12 journal = {:date => obj.received_on, :transaction_id => obj.id.to_s, :currency => Currency.first, :amount => obj.amount}
13 journal[:comment] = "Payment: #{obj.type} - #{obj.amount}"
920299a @ravishankar ohff..finally reverse entry bug is removed
ravishankar authored
14
f83b7c8 @piyushranjan Fixed reconcillation
piyushranjan authored
15 journal[:journal_type_id]= 2
920299a @ravishankar ohff..finally reverse entry bug is removed
ravishankar authored
16
bf5a7c9 @Gazal24 now :fee_id and :action are recorded in postings level in case of Sin…
Gazal24 authored
17 status, @journal = Journal.create_transaction(journal, debit_accounts, credit_accounts, rules)
b39a92e Rule book & payment observer is added
ravi authored
18 end
6f746c7 @Gazal24 Journals with multiple credit and debit posting entries, single vouch…
Gazal24 authored
19
20 def self.single_voucher_entry(payments)
35951b7 @piyushranjan Loan repayment now does accounting entries
piyushranjan authored
21 obj = payments.first
6f746c7 @Gazal24 Journals with multiple credit and debit posting entries, single vouch…
Gazal24 authored
22 # This function will make entries to the posting database when save, update or delete envent triggers
c1b5024 @piyushranjan Rules engine to have journal type
piyushranjan authored
23 credit_accounts, debit_accounts, rules = RuleBook.get_accounts(payments)
6f746c7 @Gazal24 Journals with multiple credit and debit posting entries, single vouch…
Gazal24 authored
24 # do not do accounting if no matching accounts
b43ad75 @piyushranjan Added accounting disabler
piyushranjan authored
25 return unless (credit_accounts and debit_accounts)
6f746c7 @Gazal24 Journals with multiple credit and debit posting entries, single vouch…
Gazal24 authored
26 return unless (credit_accounts.length>=0 and debit_accounts.length>=0)
27
28 journal = {:date => obj.received_on, :transaction_id => obj.id.to_s, :currency => Currency.first}
29 amount = payments.map{|x| x.amount}.inject(0){|s,x| s+=x}
30 client = obj.client || obj.loan.client
31 if client
32 journal[:comment] = "Payment: #{client.name}"
33 else
34 journal[:comment] = "Payments: #{payments.map{|x| x.id}.join(',')}"
35 end
c1b5024 @piyushranjan Rules engine to have journal type
piyushranjan authored
36 journal[:journal_type_id]= rules.first.journal_type.id
bf5a7c9 @Gazal24 now :fee_id and :action are recorded in postings level in case of Sin…
Gazal24 authored
37 status, @journal = Journal.create_transaction(journal, debit_accounts, credit_accounts, rules)
6f746c7 @Gazal24 Journals with multiple credit and debit posting entries, single vouch…
Gazal24 authored
38 end
de3d67a @Gazal24 changes in observer, added journal resource, manual entry for transac…
Gazal24 authored
39
1593436 Rule book added
ravi authored
40 def self.reverse_posting_entries(obj)
4633bc0 fixed payment deletion bug
Siddharth authored
41 credit_accounts, debit_accounts, rule = RuleBook.get_accounts(obj)
42 # j = Journal.first(:transaction_id => obj.id, :journal_type_id => 1, :order => [:created_at.desc]) if obj.type == :principal
43 # j = Journal.first(:transaction_id => obj.id, :journal_type_id => 2, :order => [:created_at.desc]) if obj.type == :interest or obj.type == :fees
44 # credit_accounts, debit_accounts = {}, {}
45 # j.postings.each{|p|
46 # credit_accounts[p.account] = p.amount if p.amount >= 0
47 # debit_accounts[p.account] = p.amount * -1 if p.amount < 0 #we keep every amount positive here, similar to forward entry. Rest is taken care off later.
48 # }
290cf78 @Gazal24 resolves bug #824. Do not use rule_book to make reverse journal entries.
Gazal24 authored
49
de3d67a @Gazal24 changes in observer, added journal resource, manual entry for transac…
Gazal24 authored
50 # do not do accounting if no matching accounts
8b842b5 @piyushranjan Multi account support and split of amount support added
piyushranjan authored
51 return unless (credit_accounts and debit_accounts)
52 return unless (credit_accounts.length>=0 and debit_accounts.length>=0)
de3d67a @Gazal24 changes in observer, added journal resource, manual entry for transac…
Gazal24 authored
53 journal = {:date => obj.received_on, :transaction_id => obj.id.to_s, :currency => Currency.first, :amount => obj.amount * -1}
920299a @ravishankar ohff..finally reverse entry bug is removed
ravishankar authored
54 journal[:comment] = "Payment: #{obj.type} - #{obj.amount} - Reverse entry"
8b842b5 @piyushranjan Multi account support and split of amount support added
piyushranjan authored
55
56 #reverse the signs
ffc15dd cherry-pick commit 6457727 from intellecash to fix accounting issues
Siddharth authored
57 debit_accounts.each{|r, val| val.each{|account, amount| val[account] = amount * -1}} if debit_accounts.is_a?(Hash)
58 credit_accounts.each{|r, val| val.each{|account, amount| val[account] = amount * -1}} if credit_accounts.is_a?(Hash)
110219d @ravishankar payment & loan observer is updated
ravishankar authored
59
f2e4eaf @piyushranjan Fixed posting specs
piyushranjan authored
60 journal[:journal_type_id]= rule.journal_type.id
8b842b5 @piyushranjan Multi account support and split of amount support added
piyushranjan authored
61 status, @journal = Journal.create_transaction(journal, debit_accounts, credit_accounts)
de3d67a @Gazal24 changes in observer, added journal resource, manual entry for transac…
Gazal24 authored
62 end
63
64
6f746c7 @Gazal24 Journals with multiple credit and debit posting entries, single vouch…
Gazal24 authored
65 after :create do
66 AccountPaymentObserver.make_posting_entries(self) unless self.override_create_observer
021e81c Rule book & payment observer is added
ravi authored
67 end
60fa552 @Gazal24 minor improvements in accounting
Gazal24 authored
68
69 before :save do
70 AccountPaymentObserver.reverse_posting_entries(self) unless deleted_at.nil?
021e81c Rule book & payment observer is added
ravi authored
71 end
72 end
Something went wrong with that request. Please try again.