13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/double_entry/validation/line_check.rb', line 13
def perform
log = ''
current_line_id = nil
active_accounts = Set.new
incorrect_accounts = Set.new
new_lines_since_last_run.find_each do |line|
incorrect_accounts << line.account unless running_balance_correct?(line, log)
active_accounts << line.account
current_line_id = line.id
end
active_accounts.each do |account|
incorrect_accounts << account unless cached_balance_correct?(account)
end
incorrect_accounts.each { |account| recalculate_account(account) }
unless active_accounts.empty?
LineCheck.create!(
:errors_found => incorrect_accounts.any?,
:last_line_id => current_line_id,
:log => log,
)
end
end
|