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

@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,
};

@gilgardosh
gilgardosh force-pushed the claude/business-bank-data-setup-h4u85f branch from a887f71 to e0b926a Compare August 4, 2026 10:21
@gilgardosh
gilgardosh temporarily deployed to accounter-fullstack August 4, 2026 10:21 — with GitHub Actions Inactive
@gilgardosh
gilgardosh temporarily deployed to accounter-fullstack August 4, 2026 10:21 — with GitHub Actions Inactive
@gilgardosh
gilgardosh force-pushed the claude/business-bank-data-setup-h4u85f branch from e0b926a to 2518a35 Compare August 17, 2026 14:17
@gilgardosh
gilgardosh temporarily deployed to accounter-fullstack August 17, 2026 14:17 — with GitHub Actions Inactive
@gilgardosh
gilgardosh temporarily deployed to accounter-fullstack August 17, 2026 14:17 — with GitHub Actions Inactive
@gilgardosh
gilgardosh requested a lite review from Copilot August 17, 2026 14:19

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

…ss by contra account

Store each business' bank accounts (a business may have several) and use them to set
the counterparty business on incoming bank transactions at insertion time.

- migrations (single, consolidated): add businesses_bank_accounts link table with
  RLS tenant isolation, dedup unique index and updated_at trigger; add
  match_business_by_bank_account() helper and wire it into the latest Poalim ILS,
  Poalim foreign and Otsar Hahayal ILS insert-trigger handlers so an exact
  contra/correspondent-account match sets transactions.business_id.
- server: BusinessBankAccountsProvider (DataLoader + replace-set), a zod-validated
  bankAccounts input, a bankAccounts list on the Business GraphQL type, and
  update/insert business wiring.
- client: manage a dynamic list of bank accounts (add/remove) in the business
  contact section.

Closes #3967

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wy7Xya5fazLb7ctUpY9LX5
@gilgardosh
gilgardosh force-pushed the claude/business-bank-data-setup-h4u85f branch from 2518a35 to a08092e Compare August 23, 2026 10:23
@gilgardosh
gilgardosh temporarily deployed to accounter-fullstack August 23, 2026 10:23 — with GitHub Actions Inactive
@gilgardosh
gilgardosh temporarily deployed to accounter-fullstack August 23, 2026 10:23 — with GitHub Actions Inactive
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