Class: YDIM::Reconciler
- Inherits:
-
Object
- Object
- YDIM::Reconciler
- Defined in:
- lib/ydim/reconciler.rb
Overview
Matches booked bank credits (YDIM::Camt::Entry) against invoices. Works on Invoice::Info structs rather than Invoice objects so that the result can travel over DRb, and so that it can be unit-tested without a database.
Defined Under Namespace
Classes: InvoiceRef, Match, Result
Constant Summary collapse
- NOISE =
Words that say nothing about who paid, and would otherwise make two unrelated companies look like the same debitor.
%w{ag gmbh sa sarl srl inc ltd co kg the und and dr med prof}
- APPLICABLE =
Only these are safe to book without a human looking at them: the payer named the invoice and the money adds up to the cent.
[:exact, :split]
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
Instance Method Summary collapse
-
#initialize(infos, accounts = nil, resolver = nil) ⇒ Reconciler
constructor
infos - Invoice::Info structs of the invoices still awaiting payment; these are the candidates for matching on amount alone.
- #reconcile(entries) ⇒ Object
Constructor Details
#initialize(infos, accounts = nil, resolver = nil) ⇒ Reconciler
infos - Invoice::Info structs of the invoices still awaiting payment; these are the candidates for matching on amount alone. accounts - IBANs ydim owns; entries on any other account are ignored. ydim only ever sees the ywesee business account, but the e-banking download also carries the private ones. resolver - optional callable turning an invoice number into an Info, so that a payment naming an invoice that is already settled can be reported as such without loading the whole invoice book.
102 103 104 105 106 107 108 |
# File 'lib/ydim/reconciler.rb', line 102 def initialize(infos, accounts = nil, resolver = nil) @invoices = infos.collect { |info| InvoiceRef.new(info) } @accounts = [accounts].flatten.compact @resolver = resolver @by_id = {} @invoices.each { |ref| @by_id[ref.unique_id.to_s] = ref } end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
93 94 95 |
# File 'lib/ydim/reconciler.rb', line 93 def accounts @accounts end |
Instance Method Details
#reconcile(entries) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ydim/reconciler.rb', line 109 def reconcile(entries) if @accounts.empty? raise ArgumentError, "no account given -- set camt_accounts to the IBAN of the ywesee " \ "business account, or the private accounts in the same download " \ "would be matched against invoices too" end result = Result.new unique = YDIM::Camt.dedup(entries) result.skipped[:duplicate] = entries.size - unique.size unique.each { |entry| if !entry.account?(@accounts) result.skipped[:other_account] += 1 elsif !entry.credit? result.skipped[:debit] += 1 elsif !entry.booked? result.skipped[:not_booked] += 1 else result.matches.push(match(entry)) end } result end |