Skip to content

Developer notes

All tables are InnoDB and are dropped on uninstall. Prefix ?:kv_bnkrec_.

Table Holds
statements One row per imported statement: format, file name and SHA-1, source (U upload, F folder), account IBAN, period, entry counters, mapping
entries One row per bank entry: booking and value date, direction (C credit, D debit), amount, currency, payer name and IBAN, end-to-end id, structured reference, payment text, bank reference, status, matched order, suggestion, score, rule, reason. UNIQUE (company_id, entry_hash) is the idempotency guard
payments Payments booked on orders: entry, order, kind (F full, P partial, O more than due), amount and currency, amount in the primary currency, status A active / U voided, order status before and after
refs Payment reference of a top-level order (UNIQUE reference)
mappings Saved CSV mappings (JSON)
log Imports, matches, undo, ignore

Entry status: N new / unmatched, S suggestion, M matched, I ignored, X not a credit (debit or reversal).

Parser::entryHash() = SHA-1 of account IBAN, bank reference (AcctSvcrRef / NtryRef / MT940 reference of the account servicer), booking date, amount, direction and currency; when the bank gives no reference also value date, end-to-end id, payer name and text (lower case). Identical lines of one file get a running number. An entry exists once per bank account: the check ignores the storefront scope and whether the file came by upload or cron. A second, fuzzy key (dup_key: account, direction, amount, currency, booking date and the end-to-end id, else the normalised text and the payer IBAN) finds the same transfer in a different report (camt.052 / camt.054 first, camt.053 later, other bank references); such an entry is stored as I with reason duplicate and dup_of, never booked automatically. Identical lines inside one file are not treated as duplicates of each other. An automatic booking is also refused when the order already carries an active payment with the same amount, booking date and payer name.

Matcher::match() is pure PHP (no database): reference 100, order number next to a keyword 80, bare order number 65 (45 below 100), amount and payer name 70, amount alone 40; +10 amount fits, -20 amount does not fit, +5 name. Reconciler::run() books automatically when mode is automatic, the add-on is licensed, the top score is unique and at least the threshold, the order waits for payment (an “open” order), the currency fits, and a partial or over-payment came with an exact reference and auto_partial is on. Otherwise it stores the best candidate as a suggestion (S) with a reason (low_score, ambiguous, currency, order_not_open, partial, over, review_mode) or leaves the entry N.

Reconciler::apply() takes a database lock per top-level order, claims the entry with UPDATE ... WHERE status IN ('N','S') (one row or nothing), writes the payment row, changes the order status through fn_change_order_status() (notification rules from the setting) and writes the order note and the log. Reconciler::undo() voids the payment rows and puts the status back only when the order is still in the status this match set.

Order totals are stored in the primary currency. The currency a customer saw the order in is read from ?:order_data (type R). An entry may be in the primary or that secondary currency; the secondary amount is the total at the current rate, payments in the secondary currency are subtracted in that currency.

References and payments belong to the top-level order (parent_order_id = 0): the parent order of a multi-vendor cart, or a single order. Orders::topId() turns a child order into its parent; a child shows the parent’s reference. The paid status reaches the children through the core fn_change_order_status() child handling.

Fired after the add-on’s own work (handlers get references, as with every core hook):

fn_set_hook('kv_bank_reconcile_booked', $order_id, $entry, $payment_id, $kind, $new_status);
// $order_id top-level order, $entry the ?:kv_bnkrec_entries row, $payment_id row of ?:kv_bnkrec_payments,
// $kind F|P|O, $new_status the order status this booking set ('' when unchanged)
fn_set_hook('kv_bank_reconcile_undone', $order_id, $entry, $voided_payments, $reverted_status);

An accounting connector can book the payment on its side from kv_bank_reconcile_booked.

$order_info.kv_bnkrec is added by the get_order_info hook for bank transfer orders: reference, reference_txt, due_text, total_text, paid_text, is_paid, bank_name, bank_iban, bank_bic, qr_url, show_order, show_email, show_qr. The order documents have a variable kv_bnkrec (show, reference, account_holder, iban, bic, amount_due, qr_url) and a snippet kv_bank_transfer; install adds {{ snippet("kv_bank_transfer") }} after the payment paragraph of the invoice and the order summary, uninstall removes it.

The QR image is served by index.php?dispatch=kv_bank_reconcile.qr&order_id=<id>&token=<hmac> (signed; the image shows what is still open).

index.php?dispatch=kv_bank_reconcile.cron&key=<key> imports the files of the configured folder and answers JSON (ok, files). It does nothing while the add-on is switched off or unlicensed.

The readers follow the published definitions; fixtures are constructed from them (see tests/fixtures/README.md: no official sample file could be downloaded, so none is claimed).

  • ISO 20022 camt.052 / camt.053 / camt.054: message definitions camt.053.001.02 (BankToCustomerStatementV02), camt.053.001.08 (BankToCustomerStatementV08), camt.054.001.02 / .08, camt.052.001.02 / .08, ISO 20022 Message Definitions, Bank-To-Customer Cash Management (iso20022.org, Catalogue of messages). The reader uses local element names, so every .001.NN version with the same element paths works; version differences it handles: Sts text vs Sts/Cd, Dbtr/Nm vs Dbtr/Pty/Nm, BIC vs BICFI, Dt vs DtTm. Only booked entries (BOOK or no status) are imported; CdtDbtInd is always the direction of the entry itself and RvslInd only flags that it is the result of a reversal (ISO 20022 usage rule, change request CR0023; the direction is never swapped; MT940 differs: RC / RD mark the entry); a batch entry with several TxDtls that each carry AmtDtls/TxAmt/Amt becomes one entry per detail, and a detail with its own CdtDbtInd / RvslInd (camt.053.001.04 and later) uses it, so a batch can hold a credit and a debit. A UTF-16 file is converted and checked for a DOCTYPE like any other. Files with a DOCTYPE are refused (no external entities).
  • SWIFT MT940 (Customer Statement Message): fields :20:, :25:, :28C:, :60F:/:60M:, :61: (value date YYMMDD, entry date MMDD, D/C mark with R reversal, funds code, amount with decimal comma, transaction type N/F/S + 3 characters, customer reference, // bank reference), :86:, :62F:/:62M: as in the SWIFT MT 940 field specification. The :86: layouts: the German “GVC” structure of the Deutsche Kreditwirtschaft MT940 specification (?00 booking text, ?20-?29 purpose, ?30 BIC, ?31 account, ?32/?33 name; SEPA keys EREF+, SVWZ+, KREF+, IBAN+, BIC+), the slash-key structure (/EREF/, /REMI/, /NAME/, /IBAN/, /CREF/), and free text.
  • CSV: no standard; driven by the saved mapping.
  • ISO 11649 (Financial services - Core banking - Structured creditor reference to remittance information): RF + two check digits + up to 21 alphanumeric characters; check digits by ISO 7064 MOD 97-10 over the reference followed by RF00. Example RF18 5390 0754 7034.
  • IBAN: ISO 13616 (MOD 97 = 1). Luhn check digit: ISO/IEC 7812-1 Annex B.
  • EPC QR code: European Payments Council, EPC069-12 “Quick Response Code: Guidelines to Enable the Data Capture for the Initiation of a SEPA Credit Transfer”: service tag BCD, version 002, character set UTF-8, identification SCT, BIC, name (70), IBAN, EUR amount, purpose, structured reference (35) or unstructured text (140); maximum 331 bytes; error correction level M. The QR symbol is encoded with ISO/IEC 18004 (byte mode, versions 1-25). The generated codes are decoded again in the build checks with an independent reader.

Known limits: amounts are stored with two decimals (currencies with three decimals such as KWD lose the last digit); a transfer in a third currency is never booked; bank charges (Chrgs) are not read, so a transfer with a deducted fee arrives as a partial payment (use the tolerance, or book the rest by hand). Returned transfers: a debit marked as reversal (MT940 RC) is stored with reversal = Y, linked to the booked credit with the same account, amount, currency and end-to-end id, reference or text (reverses_entry), and waits in the queue (Reversals filter) with an “Undo the booking” action, or undoes the booking at once when the setting “Returned transfers” is Automatic and exactly one booking fits. A credit marked as reversal is never booked automatically.

app/addons/kv_bank_reconcile/
addon.xml settings, six tables, install / uninstall functions, snippet templates
init.php func.php hooks (get_order_info, delete_order, delete_company), install, settings variants
controllers/backend/ kv_bank_reconcile.php (pages and actions), orders.post.php (order tab)
controllers/frontend/ kv_bank_reconcile.php (qr, cron)
schemas/ menu, permissions (admin, vendor closed), documents/order.post.php (kv_bnkrec variable)
resources/snippet_templates.xml
Tygh/Addons/KvBankReconcile/
Parser.php Parser/{Camt,Mt940,Csv}.php readers, format detection, entry hash
Matcher.php Reconciler.php Importer.php scoring, booking / undo, import and folder pickup
Reference.php EpcQr.php Qr.php Money.php references, EPC payload, QR encoder, currencies
Orders.php Store.php Config.php Documents/ order data, queries, settings and gate, invoice variable
License/ Upgrade/ license client and self-healing upgrades (generated)
design/backend/templates/addons/kv_bank_reconcile/ admin pages, order tab, license card
var/themes_repository/responsive/templates/addons/kv_bank_reconcile/ transfer box on the order pages
tests/ unit.php (pure logic), fixtures/, php/ (store_test, lifecycle, seed), e2e/ (HTTP), qa-gate.mjs
  • php81 tests/unit.php and php83 tests/unit.php: parsers, references, EPC payload, QR structure, matcher, idempotency hashes. No store needed.
  • tests/php/store_test.php, tests/php/lifecycle.php, tests/e2e/e2e.mjs run on a dev store (see tests/test-plan.md). Mail stays in the process; no bank or provider is contacted.

The add-on checks its license once a day (domain name only) and gates new work with Config::active(). See the license card on the add-on page.