Skip to content

feat(bank-payments): manually assign payments and learn payers - #509

Merged
Panelica merged 1 commit into
Panelica:mainfrom
hedon77:feat/bank-payments-manual-learning
Nov 28, 2026
Merged

Panelica merged 1 commit into
Panelica:mainfrom
hedon77:feat/bank-payments-manual-learning

Conversation

@hedon77

@hedon77 hedon77 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • show match confidence as a percentage and lower the candidate threshold to 50 points
  • let an operator search open invoices and assign an unmatched transfer in two steps
  • remember a payer to client mapping after a successful manual booking
  • add a learned-payers page where a mapping can be removed
  • add a per-transaction rematch action and pnlcs:bank-payments:rematch
  • count unmatched transfers on the addon dashboard

Verification

  • vendor/bin/pest --configuration=phpunit.testing.xml tests/Feature/BankPayments
  • 36 tests / 166 assertions pass
  • new migration: bank_payer_profiles
  • no production deployment performed

Show match confidence as a percentage, lower the candidate threshold so an amount and payer match reaches review, and add a two-step manual assignment flow. Successful manual bookings remember the payer for future matching; learned mappings can be removed. Add rematch controls and a command for existing transactions.
@Panelica
Panelica merged commit 9f639d4 into Panelica:main Nov 28, 2026
1 check passed
@Panelica

Copy link
Copy Markdown
Owner

Merged as 9f639d4f. The design decision that makes this safe is yours and worth naming: assigning does not book. It writes a proposed match and sets the transaction to review, so the money still goes through the approve path that was already reviewed, with its lock, its duplicate check and its expected_balance.

Measured on main, your tests, nothing else changed β€” five red: the four in BankAssignmentTest (RouteNotFoundException Γ—3, CommandNotFoundException for pnlcs:bank-payments:rematch) and "shows an amount and payer match as a 56 percent review candidate", which needs the threshold at 50.

What I read line by line, since this is money:

  • Lowering the candidate threshold cannot cause an automatic booking. AUTO_SCORE is untouched and the $source === 'auto' block in BankPaymentImporter tests its own literal 90 plus rank 1, auto_ready, the booking window, mode auto, all three criteria and abs($amount - $balance) <= 0.01. 50 only widens what an operator is offered for review.
  • A learned payer cannot move a booking to the wrong client. It grants the client point without a name match, so the most it can do is complete 70 to 90 β€” and 70 already means the reference carries that invoice's number and the amount equals its balance. With a different client the mapping does not apply and the name comparison decides as before.
  • Skipping the score re-check for source === 'manual' is right: a hand-assigned transfer can legitimately score 0, and the guards that matter at that point β€” balance, currency, status, the lock, require_payable, expected_balance β€” all still run.
  • remember() only fires on a manual booking, inside a try/catch that logs, so a payer name too long for the normalized column cannot fail the booking it came from.
  • The module's own translations are complete. All 203 bank-payments:: keys the addon now asks for exist in lang/en and lang/pl, including the eleven matches.status_* that rematched interpolates. Worth saying explicitly: TranslationKeyCoverageTest does not cover namespaced module keys β€” its group list comes from lang/en/*.php β€” so nothing would have told you.

One defect I found and fixed on top, cbedb107: the booked amount was never compared with the transfer. The approval hint says the amount may be changed "for a partial payment or overpayment", and against the invoice that is deliberate β€” it leaves the customer a credit. Against the transfer it is money that never arrived, and nothing checked it: the amount was tested against zero, and on your assignment screen against the invoice balance. Measured before the fix, both through PaymentService:

  • 2,000.00 approved against a 1,234.87 transfer β€” booked in full;
  • two bookings of 1,000.00 from the same 1,234.87 transfer β€” both went through, because a transfer whose other candidates are still open returns to review instead of being closed.

The limit is what is left of the transfer, so splitting still works: the importer sums the imports already booked from that transaction, excluding this match, and refuses when the total would pass the transfer's own amount; the refusal is recorded as a blocked import like every other guard. Your assignment screen says the same while the amount is being chosen, so the operator is not told only after approving. imports.amount_exceeds_transfer, en and pl. Tests: the 2,000 attempt is refused, and one transfer splits into 1,000.00 + 234.87 with the 1,000.00 + 1,000.00 attempt blocked in between.

And one thing your migration exposed in my own code, fixed in 8ebbd575. ensureBankPaymentsTables() β€” the helper I added yesterday, which you correctly extended with bank_payer_profiles β€” runs migrate inside the test's transaction, and CREATE TABLE ends that transaction implicitly. The first addon test on a database without the new table therefore had its own rows committed for good: one row left in each of ten tables, and a later run's BankMailbox::firstOrFail() picked up the leftover mailbox, failing a test about an encrypted password on data it never wrote. 26 addon tests went red that way here. It now hands the transaction back cleanly β€” roll back, migrate, begin again β€” proved by dropping the table, running one addon test and counting: zero rows left.

Noted, not changed: the assignment screen caps the amount at the invoice balance, so the overpayment the approval form allows is not available there. That reads like a deliberate "how much of this transfer goes to this invoice", and the capability still exists at approval, so I left it.

Full suite on the merge result: 5,646 parallel, 112 serial, no failures. Migration checked up, down and up again on its own path. Thank you β€” the rematch command and the payers page with a remove button are the parts an operator will actually live in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants