Skip to content

Add bank account fields to businesses for transaction matching#4027

Open
gilgardosh wants to merge 1 commit into
mainfrom
claude/business-bank-data-setup-h4u85f
Open

Add bank account fields to businesses for transaction matching#4027
gilgardosh wants to merge 1 commit into
mainfrom
claude/business-bank-data-setup-h4u85f

Conversation

@gilgardosh

Copy link
Copy Markdown
Collaborator

Summary

This PR adds support for storing bank account details (bank number, branch number, account number) on business entities, enabling automatic matching of incoming bank transactions to local businesses by their counterparty (contra) account information.

Key Changes

Database Schema

  • Added three new nullable integer columns to the businesses table:
    • bank_account_bank_number
    • bank_account_branch_number
    • bank_account_account_number
  • Created a composite index on these columns (scoped by owner_id) to optimize contra account lookups

Transaction Processing

  • Created match_business_by_bank_account() SQL function to look up a business by its bank account details within an owner's scope
  • Updated three transaction handler triggers to use this function:
    • insert_poalim_ils_transaction_handler()
    • insert_poalim_foreign_transaction_handler()
    • insert_otsar_hahayal_ils_transaction_handler()
  • All handlers now populate the business_id field on created transactions when a matching business is found

GraphQL API

  • Added BusinessBankAccount type with bankNumber, branchNumber, and accountNumber fields
  • Added BusinessBankAccountInput for mutations
  • Updated Business type and UpdateBusinessInput/CreateBusinessInput to include bankAccount field
  • Updated resolver to map database columns to the new GraphQL type

Client UI

  • Added three new NumberInput fields to the business contact info form:
    • Bank Number
    • Bank Branch Number
    • Bank Account Number
  • Updated form schema validation and data conversion logic to handle the new fields

Implementation Details

  • The match_business_by_bank_account() function returns a single business ID or NULL, enforcing one-to-one matching semantics per owner
  • Transaction handlers check for NULL account numbers (value of 0) to avoid matching invalid/placeholder accounts
  • The index includes a WHERE clause to exclude NULL account numbers, optimizing for the common case of businesses without bank account data

https://claude.ai/code/session_01Wy7Xya5fazLb7ctUpY9LX5

…ss by contra account

Store each business' bank account (bank number, branch, account) and use it to set
the counterparty business on incoming bank transactions at insertion time.

- migrations: add bank_account_{bank,branch,account}_number columns to businesses
  (+ owner-scoped lookup index); add match_business_by_bank_account() helper and
  wire it into the Poalim ILS, Poalim foreign and Otsar Hahayal ILS insert-trigger
  handlers so an exact contra/correspondent-account match sets transactions.business_id.
- server: expose/accept the bank account via the Business GraphQL type and the
  update/insert business inputs; persist it through the businesses provider.
- client: add Bank Number / Branch / Account fields to the business contact section.

Closes #3967

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wy7Xya5fazLb7ctUpY9LX5
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds bank-account details to businesses and wires them through DB → GraphQL → client UI so incoming bank transactions can be auto-matched to a local business using contra/counterparty account information.

Changes:

  • Adds bank_account_* columns to accounter_schema.businesses and introduces an index intended to speed up contra-account matching.
  • Adds match_business_by_bank_account() and updates multiple bank-transaction insert handlers to populate transactions.business_id when a matching business exists.
  • Extends the GraphQL Business model + client business contact form to view/edit the bank account fields.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/server/src/modules/onboarding/providers/shaam-import.provider.ts Initializes new business bank-account fields to null during SHAAM import.
packages/server/src/modules/financial-entities/typeDefs/businesses.graphql.ts Adds BusinessBankAccount types and exposes bankAccount on Business + inputs.
packages/server/src/modules/financial-entities/resolvers/businesses.resolver.ts Maps GraphQL bankAccount input/output to DB columns.
packages/server/src/modules/financial-entities/providers/businesses.provider.ts Extends business SELECT/INSERT/UPDATE SQL to include new bank-account columns.
packages/server/src/modules/financial-entities/helpers/update-business.helper.ts Passes bank-account fields through the update helper.
packages/migrations/src/run-pg-migrations.ts Registers the two new migrations.
packages/migrations/src/actions/2026-07-22T10-00-00.add-business-bank-account-fields.ts Adds the three columns + an index for matching lookups.
packages/migrations/src/actions/2026-07-22T10-30-00.match-business-by-contra-account.ts Adds match function and updates bank transaction handlers to set business_id.
packages/client/src/components/business/contact-info-section.tsx Adds bank-account inputs and sends bankAccount in update mutation payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +23
-- Index to speed up (and enforce lookup semantics of) matching a contra account
-- to a business within a given owner scope.
CREATE INDEX IF NOT EXISTS businesses_bank_account_idx
ON accounter_schema.businesses (
owner_id,
bank_account_bank_number,
bank_account_branch_number,
bank_account_account_number
)
WHERE bank_account_account_number IS NOT NULL;
Comment on lines +18 to +27
SELECT b.id
FROM accounter_schema.businesses b
WHERE p_owner_id IS NOT NULL
AND p_account_number IS NOT NULL
AND p_account_number <> 0
AND b.owner_id = p_owner_id
AND b.bank_account_bank_number = p_bank_number
AND b.bank_account_branch_number = p_branch_number
AND b.bank_account_account_number = p_account_number
LIMIT 1;
Comment on lines +83 to +85
bankNumber: z.number().int().nonnegative().optional().nullable(),
bankBranchNumber: z.number().int().nonnegative().optional().nullable(),
bankAccountNumber: z.number().int().nonnegative().optional().nullable(),
Comment on lines +65 to 69
bankAccountBankNumber: fields.bankAccount?.bankNumber ?? null,
bankAccountBranchNumber: fields.bankAccount?.branchNumber ?? null,
bankAccountAccountNumber: fields.bankAccount?.accountNumber ?? null,
};

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.

3 participants