Class: YDIM::Camt::Entry
- Inherits:
-
Object
- Object
- YDIM::Camt::Entry
- Defined in:
- lib/ydim/camt.rb
Overview
A single booked movement on an account (a camt
Constant Summary collapse
- TOKEN_PATTERN =
Runs of digits found in the remittance information. Whole runs only -- never substrings, or the phone number in a TWINT payment ("+41796723413") would match half the invoices in the database. A run touching a letter is machine noise rather than something a human typed: this drops the hex EndToEndIds that banks generate ("0ebf22116f364fc394da3e2776a05643" would otherwise offer up "22116"), while "RG 13363 VOM 26.6.2026" and "ISO 13368" still yield their invoice number.
/(?<![0-9A-Za-z])\d+(?![0-9A-Za-z])/
Instance Attribute Summary collapse
-
#account_currency ⇒ Object
Returns the value of attribute account_currency.
-
#account_iban ⇒ Object
Returns the value of attribute account_iban.
-
#additional_info ⇒ Object
Returns the value of attribute additional_info.
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#booking_date ⇒ Object
Returns the value of attribute booking_date.
-
#counterparty ⇒ Object
Returns the value of attribute counterparty.
-
#credit ⇒ Object
Returns the value of attribute credit.
-
#creditor_references ⇒ Object
readonly
Returns the value of attribute creditor_references.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#end_to_end_ids ⇒ Object
readonly
Returns the value of attribute end_to_end_ids.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#remittance ⇒ Object
readonly
Returns the value of attribute remittance.
-
#source ⇒ Object
Returns the value of attribute source.
-
#status ⇒ Object
Returns the value of attribute status.
-
#value_date ⇒ Object
Returns the value of attribute value_date.
Instance Method Summary collapse
-
#account?(ibans) ⇒ Boolean
ydim invoices are only ever paid into the ywesee business account -- the private accounts share the same e-banking download, so entries have to be filtered by IBAN before anything is matched.
-
#amount_cents ⇒ Object
Money as an integer so that amounts can be compared without float rounding surprises.
-
#booked? ⇒ Boolean
Only BOOK entries have actually hit the account; PDNG ones can still disappear, so they must never mark an invoice as paid.
- #credit? ⇒ Boolean
-
#dedup_key ⇒ Object
Two statements can deliver the same entry (UBS re-sends a day under a new MsgId), so entries are identified by the bank's own reference.
-
#initialize ⇒ Entry
constructor
A new instance of Entry.
- #numeric_tokens ⇒ Object
-
#texts ⇒ Object
Every string a payer might have put an invoice number into.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Entry
Returns a new instance of Entry.
24 25 26 27 28 29 |
# File 'lib/ydim/camt.rb', line 24 def initialize @remittance = [] @end_to_end_ids = [] @creditor_references = [] @credit = false end |
Instance Attribute Details
#account_currency ⇒ Object
Returns the value of attribute account_currency.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def account_currency @account_currency end |
#account_iban ⇒ Object
Returns the value of attribute account_iban.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def account_iban @account_iban end |
#additional_info ⇒ Object
Returns the value of attribute additional_info.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def additional_info @additional_info end |
#amount ⇒ Object
Returns the value of attribute amount.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def amount @amount end |
#booking_date ⇒ Object
Returns the value of attribute booking_date.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def booking_date @booking_date end |
#counterparty ⇒ Object
Returns the value of attribute counterparty.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def counterparty @counterparty end |
#credit ⇒ Object
Returns the value of attribute credit.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def credit @credit end |
#creditor_references ⇒ Object (readonly)
Returns the value of attribute creditor_references.
23 24 25 |
# File 'lib/ydim/camt.rb', line 23 def creditor_references @creditor_references end |
#currency ⇒ Object
Returns the value of attribute currency.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def currency @currency end |
#end_to_end_ids ⇒ Object (readonly)
Returns the value of attribute end_to_end_ids.
23 24 25 |
# File 'lib/ydim/camt.rb', line 23 def end_to_end_ids @end_to_end_ids end |
#reference ⇒ Object
Returns the value of attribute reference.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def reference @reference end |
#remittance ⇒ Object (readonly)
Returns the value of attribute remittance.
23 24 25 |
# File 'lib/ydim/camt.rb', line 23 def remittance @remittance end |
#source ⇒ Object
Returns the value of attribute source.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def source @source end |
#status ⇒ Object
Returns the value of attribute status.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def status @status end |
#value_date ⇒ Object
Returns the value of attribute value_date.
20 21 22 |
# File 'lib/ydim/camt.rb', line 20 def value_date @value_date end |
Instance Method Details
#account?(ibans) ⇒ Boolean
ydim invoices are only ever paid into the ywesee business account -- the private accounts share the same e-banking download, so entries have to be filtered by IBAN before anything is matched. An empty filter accepts everything here; refusing to run without one is the Reconciler's job, since only it knows the entries are about to be matched against invoices.
39 40 41 42 43 44 |
# File 'lib/ydim/camt.rb', line 39 def account?(ibans) ibans = [ibans].flatten.compact ibans.empty? || ibans.any? { |iban| normalize_iban(iban) == normalize_iban(@account_iban) } end |
#amount_cents ⇒ Object
Money as an integer so that amounts can be compared without float rounding surprises.
52 53 54 |
# File 'lib/ydim/camt.rb', line 52 def amount_cents (@amount.to_f * 100).round end |
#booked? ⇒ Boolean
Only BOOK entries have actually hit the account; PDNG ones can still disappear, so they must never mark an invoice as paid.
47 48 49 |
# File 'lib/ydim/camt.rb', line 47 def booked? @status.nil? || @status == 'BOOK' end |
#credit? ⇒ Boolean
30 31 32 |
# File 'lib/ydim/camt.rb', line 30 def credit? @credit end |
#dedup_key ⇒ Object
Two statements can deliver the same entry (UBS re-sends a day under a new MsgId), so entries are identified by the bank's own reference.
74 75 76 77 |
# File 'lib/ydim/camt.rb', line 74 def dedup_key [@account_iban, @reference || texts.join('|'), amount_cents, @credit, @booking_date] end |
#numeric_tokens ⇒ Object
69 70 71 |
# File 'lib/ydim/camt.rb', line 69 def numeric_tokens texts.flat_map { |text| text.scan(TOKEN_PATTERN) }.uniq end |
#texts ⇒ Object
Every string a payer might have put an invoice number into.
56 57 58 59 |
# File 'lib/ydim/camt.rb', line 56 def texts (@remittance + @end_to_end_ids + @creditor_references \ + [@additional_info]).compact end |
#to_s ⇒ Object
78 79 80 81 |
# File 'lib/ydim/camt.rb', line 78 def to_s sprintf("%s %s %s %s %s", @booking_date, @credit ? 'CRDT' : 'DBIT', @currency, sprintf('%.2f', @amount.to_f), @counterparty) end |