Class: YDIM::Camt::Entry

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeEntry

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_currencyObject

Returns the value of attribute account_currency.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def 
  @account_currency
end

#account_ibanObject

Returns the value of attribute account_iban.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def 
  @account_iban
end

#additional_infoObject

Returns the value of attribute additional_info.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def additional_info
  @additional_info
end

#amountObject

Returns the value of attribute amount.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def amount
  @amount
end

#booking_dateObject

Returns the value of attribute booking_date.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def booking_date
  @booking_date
end

#counterpartyObject

Returns the value of attribute counterparty.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def counterparty
  @counterparty
end

#creditObject

Returns the value of attribute credit.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def credit
  @credit
end

#creditor_referencesObject (readonly)

Returns the value of attribute creditor_references.



23
24
25
# File 'lib/ydim/camt.rb', line 23

def creditor_references
  @creditor_references
end

#currencyObject

Returns the value of attribute currency.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def currency
  @currency
end

#end_to_end_idsObject (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

#referenceObject

Returns the value of attribute reference.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def reference
  @reference
end

#remittanceObject (readonly)

Returns the value of attribute remittance.



23
24
25
# File 'lib/ydim/camt.rb', line 23

def remittance
  @remittance
end

#sourceObject

Returns the value of attribute source.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def source
  @source
end

#statusObject

Returns the value of attribute status.



20
21
22
# File 'lib/ydim/camt.rb', line 20

def status
  @status
end

#value_dateObject

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.

Returns:

  • (Boolean)


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_centsObject

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.

Returns:

  • (Boolean)


47
48
49
# File 'lib/ydim/camt.rb', line 47

def booked?
  @status.nil? || @status == 'BOOK'
end

#credit?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ydim/camt.rb', line 30

def credit?
  @credit
end

#dedup_keyObject

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_tokensObject



69
70
71
# File 'lib/ydim/camt.rb', line 69

def numeric_tokens
  texts.flat_map { |text| text.scan(TOKEN_PATTERN) }.uniq
end

#textsObject

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_sObject



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