Skip to content

A local-first personal finance app

🔒 reconciliation on mobile (#8384)

Matt Fiddaman566ee382906a
diff --git a/packages/desktop-client/e2e/accounts.mobile.test.ts b/packages/desktop-client/e2e/accounts.mobile.test.ts
index 2cb15af140..6ea430fdf3 100644
--- a/packages/desktop-client/e2e/accounts.mobile.test.ts
+++ b/packages/desktop-client/e2e/accounts.mobile.test.ts
@@ -62,4 +62,29 @@ test.describe('Mobile Accounts', () => {
await expect(accountPage.transactions).not.toHaveCount(0);
await expect(page).toMatchThemeScreenshots();
});
+
+ test('reconciles an account', async () => {
+ const accountsPage = await navigation.goToAccountsPage();
+ await accountsPage.waitFor();
+
+ const accountPage = await accountsPage.openNthAccount(0);
+ await accountPage.waitFor();
+
+ await accountPage.startReconciliation('200.00');
+ await expect(accountPage.reconcilingBannerDifference).toBeVisible();
+ await expect(page).toMatchThemeScreenshots();
+
+ await accountPage.createReconciliationTransaction();
+ await expect(accountPage.reconcilingBannerAllReconciled).toBeVisible();
+ await expect(page).toMatchThemeScreenshots();
+
+ await accountPage.unclearFirstTransaction();
+ await expect(accountPage.reconcilingBannerDifference).toBeVisible();
+
+ await accountPage.clearFirstTransaction();
+ await expect(accountPage.reconcilingBannerAllReconciled).toBeVisible();
+
+ await accountPage.lockTransactions();
+ await expect(accountPage.reconcilingBanner).not.toBeVisible();
+ });
});
diff --git a/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-1-chromium-linux.png b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-1-chromium-linux.png
new file mode 100644
index 0000000000..86a431db41
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-2-chromium-linux.png b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-2-chromium-linux.png
new file mode 100644
index 0000000000..327b9a46bc
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-3-chromium-linux.png b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-3-chromium-linux.png
new file mode 100644
index 0000000000..8acf41ccd2
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-4-chromium-linux.png b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-4-chromium-linux.png
new file mode 100644
index 0000000000..fb98661f07
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-4-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-5-chromium-linux.png b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-5-chromium-linux.png
new file mode 100644
index 0000000000..069abe6385
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-5-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-6-chromium-linux.png b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-6-chromium-linux.png
new file mode 100644
index 0000000000..fdcbf52e1d
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.mobile.test.ts-snapshots/Mobile-Accounts-reconciles-an-account-6-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/page-models/mobile-account-page.ts b/packages/desktop-client/e2e/page-models/mobile-account-page.ts
index 702ed67876..c28fae8d60 100644
--- a/packages/desktop-client/e2e/page-models/mobile-account-page.ts
+++ b/packages/desktop-client/e2e/page-models/mobile-account-page.ts
@@ -11,6 +11,10 @@ export class MobileAccountPage {
readonly transactionList: Locator;
readonly transactions: Locator;
readonly createTransactionButton: Locator;
+ readonly accountMenuButton: Locator;
+ readonly reconcilingBanner: Locator;
+ readonly reconcilingBannerAllReconciled: Locator;
+ readonly reconcilingBannerDifference: Locator;
constructor(page: Page) {
this.page = page;
@@ -24,6 +28,12 @@ export class MobileAccountPage {
this.createTransactionButton = page.getByRole('button', {
name: 'Add Transaction',
});
+ this.accountMenuButton = this.heading.getByRole('button');
+ this.reconcilingBanner = page.getByTestId('reconciling-banner');
+ this.reconcilingBannerAllReconciled =
+ this.reconcilingBanner.getByText('All reconciled!');
+ this.reconcilingBannerDifference =
+ this.reconcilingBanner.getByText('needs');
}
async waitFor(...options: Parameters<Locator['waitFor']>) {
@@ -59,4 +69,59 @@ export class MobileAccountPage {
await this.createTransactionButton.click();
return new MobileTransactionEntryPage(this.page);
}
+
+ /**
+ * Start reconciling the account
+ */
+ async startReconciliation(amount?: string) {
+ await this.accountMenuButton.click();
+ await this.page
+ .getByTestId('account-menu-modal')
+ .getByRole('button', { name: 'Reconcile' })
+ .click();
+ const reconcileModal = this.page.getByTestId('account-reconcile-modal');
+ const amountInput = reconcileModal.getByTestId('amount-input');
+ await amountInput.waitFor();
+ if (amount != null) {
+ await amountInput.fill(amount);
+ }
+ await reconcileModal.getByRole('button', { name: 'Reconcile' }).click();
+ await this.reconcilingBanner.waitFor();
+ }
+
+ /**
+ * Create a reconciliation balance adjustment transaction
+ */
+ async createReconciliationTransaction() {
+ await this.page
+ .getByRole('button', { name: 'Create reconciliation transaction' })
+ .click();
+ }
+
+ /**
+ * Lock all cleared transactions as reconciled
+ */
+ async lockTransactions() {
+ await this.page.getByRole('button', { name: 'Lock transactions' }).click();
+ }
+
+ /**
+ * Unclear the first cleared transaction in the list
+ */
+ async unclearFirstTransaction() {
+ await this.page
+ .getByRole('button', { name: 'Unclear transaction' })
+ .first()
+ .click();
+ }
+
+ /**
+ * Clear the first uncleared transaction in the list
+ */
+ async clearFirstTransaction() {
+ await this.page
+ .getByRole('button', { name: 'Clear transaction' })
+ .first()
+ .click();
+ }
}
diff --git a/packages/desktop-client/src/accounts/reconciliation.ts b/packages/desktop-client/src/accounts/reconciliation.ts
new file mode 100644
index 0000000000..692e2a6214
--- /dev/null
+++ b/packages/desktop-client/src/accounts/reconciliation.ts
@@ -0,0 +1,124 @@
+import { send } from '@actual-app/core/platform/client/connection';
+import { currentDay } from '@actual-app/core/shared/months';
+import { q } from '@actual-app/core/shared/query';
+import {
+ realizeTempTransactions,
+ ungroupTransactions,
+ updateTransaction,
+} from '@actual-app/core/shared/transactions';
+import { applyChanges } from '@actual-app/core/shared/util';
+import type {
+ AccountEntity,
+ TransactionEntity,
+} from '@actual-app/core/types/models';
+import { t } from 'i18next';
+
+import { aqlQuery } from '#queries/aqlQuery';
+
+export async function lockTransactions(accountId: AccountEntity['id']) {
+ const { data } = await aqlQuery(
+ q('transactions')
+ .filter({ cleared: true, reconciled: false, account: accountId })
+ .select('*')
+ .options({ splits: 'grouped' }),
+ );
+ let transactions = ungroupTransactions(data);
+
+ const changes: { updated: Array<Partial<TransactionEntity>> } = {
+ updated: [],
+ };
+
+ transactions.forEach(trans => {
+ const { diff } = updateTransaction(transactions, {
+ ...trans,
+ reconciled: true,
+ });
+
+ transactions = applyChanges(diff, transactions);
+
+ changes.updated = changes.updated
+ ? changes.updated.concat(diff.updated)
+ : diff.updated;
+ });
+
+ await send('transactions-batch-update', changes);
+}
+
+export async function unlockTransaction(
+ transactionId: TransactionEntity['id'],
+) {
+ const { data } = await aqlQuery(
+ q('transactions')
+ .filter({ id: transactionId })
+ .select('*')
+ .options({ splits: 'grouped' }),
+ );
+ const transactions = ungroupTransactions(data);
+
+ const transaction = transactions.find(trans => trans.id === transactionId);
+ if (!transaction) {
+ return;
+ }
+
+ const { diff } = updateTransaction(transactions, {
+ ...transaction,
+ reconciled: false,
+ });
+
+ await send('transactions-batch-update', { updated: diff.updated });
+}
+
+export async function getClearedBalance(accountId: AccountEntity['id']) {
+ const { data } = await aqlQuery(
+ q('transactions')
+ .filter({ cleared: true, account: accountId })
+ .options({ splits: 'none' })
+ .calculate({ $sum: '$amount' }),
+ );
+
+ return data ?? 0;
+}
+
+export async function finishReconciliation(
+ accountId: AccountEntity['id'],
+ reconcileAmount: number | null,
+ lock: () => Promise<void> = () => lockTransactions(accountId),
+) {
+ const cleared = await getClearedBalance(accountId);
+ const targetDiff = (reconcileAmount ?? 0) - cleared;
+
+ if (targetDiff === 0) {
+ await lock();
+ }
+}
+
+export async function createReconciliationTransaction(
+ accountId: AccountEntity['id'],
+ diff: number,
+ onRealized?: (transactions: TransactionEntity[]) => void,
+) {
+ const reconciliationTransactions = realizeTempTransactions([
+ {
+ id: 'temp',
+ account: accountId,
+ cleared: true,
+ reconciled: false,
+ amount: diff,
+ date: currentDay(),
+ notes: t('Reconciliation balance adjustment'),
+ },
+ ]);
+
+ onRealized?.(reconciliationTransactions);
+
+ const ruledTransactions = await Promise.all(
+ reconciliationTransactions.map(transaction =>
+ send('rules-run', { transaction }),
+ ),
+ );
+
+ await send('transactions-batch-update', {
+ added: ruledTransactions.filter(trans => !trans.tombstone),
+ deleted: ruledTransactions.filter(trans => trans.tombstone),
+ });
+}
diff --git a/packages/desktop-client/src/components/Modals.tsx b/packages/desktop-client/src/components/Modals.tsx
index 5badb78f99..4a325ce1f8 100644
--- a/packages/desktop-client/src/components/Modals.tsx
+++ b/packages/desktop-client/src/components/Modals.tsx
@@ -14,6 +14,7 @@ import { useDispatch } from '#redux';
import { EditSyncAccount } from './banksync/EditSyncAccount';
import { AccountAutocompleteModal } from './modals/AccountAutocompleteModal';
import { AccountMenuModal } from './modals/AccountMenuModal';
+import { AccountReconcileModal } from './modals/AccountReconcileModal';
import { AkahuInitialiseModal } from './modals/AkahuInitialiseModal';
import { BudgetAutomationsModal } from './modals/BudgetAutomationsModal';
import { BudgetPageMenuModal } from './modals/BudgetPageMenuModal';
@@ -277,6 +278,9 @@ export function Modals() {
case 'account-menu':
return <AccountMenuModal key={key} {...modal.options} />;
+ case 'account-reconcile':
+ return <AccountReconcileModal key={key} {...modal.options} />;
+
case 'category-menu':
return <CategoryMenuModal key={key} {...modal.options} />;
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx
index a6a2d504e5..eab85d55ed 100644
--- a/packages/desktop-client/src/components/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/accounts/Account.tsx
@@ -16,18 +16,14 @@ import { View } from '@actual-app/components/view';
import { listen, send } from '@actual-app/core/platform/client/connection';
import * as undo from '@actual-app/core/platform/client/undo';
import type { UndoState } from '@actual-app/core/server/undo';
-import { currentDay } from '@actual-app/core/shared/months';
import { q } from '@actual-app/core/shared/query';
import type { Query } from '@actual-app/core/shared/query';
import {
makeAsNonChildTransactions,
makeChild,
- realizeTempTransactions,
ungroupTransaction,
ungroupTransactions,
- updateTransaction,
} from '@actual-app/core/shared/transactions';
-import { applyChanges } from '@actual-app/core/shared/util';
import type { IntegerAmount } from '@actual-app/core/shared/util';
import type {
AccountEntity,
@@ -50,6 +46,7 @@ import {
useUpdateAccountMutation,
} from '#accounts';
import { markAccountRead } from '#accounts/accountsSlice';
+import * as reconciliation from '#accounts/reconciliation';
import { FeatureErrorFallback } from '#components/FeatureErrorFallback';
import type { SavedFilter } from '#components/filters/SavedFilterMenuButton';
import { TransactionList } from '#components/transactions/TransactionList';
@@ -978,36 +975,14 @@ class AccountInternal extends PureComponent<
};
lockTransactions = async () => {
- this.setState({ workingHard: true });
-
const { accountId } = this.props;
+ if (!accountId) {
+ return;
+ }
- const { data } = await aqlQuery(
- q('transactions')
- .filter({ cleared: true, reconciled: false, account: accountId })
- .select('*')
- .options({ splits: 'grouped' }),
- );
- let transactions = ungroupTransactions(data);
-
- const changes: { updated: Array<Partial<TransactionEntity>> } = {
- updated: [],
- };
-
- transactions.forEach(trans => {
- const { diff } = updateTransaction(transactions, {
- ...trans,
- reconciled: true,
- });
-
- transactions = applyChanges(diff, transactions);
-
- changes.updated = changes.updated
- ? changes.updated.concat(diff.updated)
- : diff.updated;
- });
+ this.setState({ workingHard: true });
- await send('transactions-batch-update', changes);
+ await reconciliation.lockTransactions(accountId);
await this.refetchTransactions();
};
@@ -1030,27 +1005,9 @@ class AccountInternal extends PureComponent<
const { reconcileAmount } = this.state;
- const { data } = await aqlQuery(
- q('transactions')
- .filter({ cleared: true, account: accountId })
- .select('*')
- .options({ splits: 'grouped' }),
+ await reconciliation.finishReconciliation(account.id, reconcileAmount, () =>
+ this.lockTransactions(),
);
- const transactions = ungroupTransactions(data);
-
- let cleared = 0;
-
- transactions.forEach(trans => {
- if (!trans.is_parent) {
- cleared += trans.amount;
- }
- });
-
- const targetDiff = (reconcileAmount || 0) - cleared;
-
- if (targetDiff === 0) {
- await this.lockTransactions();
- }
const lastReconciled = new Date().getTime().toString();
this.props.onUpdateAccount({ ...account, last_reconciled: lastReconciled });
@@ -1062,36 +1019,20 @@ class AccountInternal extends PureComponent<
};
onCreateReconciliationTransaction = async (diff: number) => {
- // Create a new reconciliation transaction
- const reconciliationTransactions = realizeTempTransactions([
- {
- id: 'temp',
- account: this.props.accountId!,
- cleared: true,
- reconciled: false,
- amount: diff,
- date: currentDay(),
- notes: t('Reconciliation balance adjustment'),
- },
- ]);
-
- // Optimistic UI: update the transaction list before sending the data to the database
- this.setState(state => ({
- transactions: [...reconciliationTransactions, ...state.transactions],
- }));
+ const { accountId } = this.props;
+ if (!accountId) {
+ return;
+ }
- // run rules on the reconciliation transaction
- const ruledTransactions = await Promise.all(
- reconciliationTransactions.map(transaction =>
- send('rules-run', { transaction }),
- ),
+ await reconciliation.createReconciliationTransaction(
+ accountId,
+ diff,
+ // Optimistic UI: update the transaction list before sending the data to the database
+ reconciliationTransactions =>
+ this.setState(state => ({
+ transactions: [...reconciliationTransactions, ...state.transactions],
+ })),
);
-
- // sync the reconciliation transaction
- await send('transactions-batch-update', {
- added: ruledTransactions.filter(trans => !trans.tombstone),
- deleted: ruledTransactions.filter(trans => trans.tombstone),
- });
await this.refetchTransactions();
};
diff --git a/packages/desktop-client/src/components/mobile/accounts/AccountPage.tsx b/packages/desktop-client/src/components/mobile/accounts/AccountPage.tsx
index 04941b8bc4..ebcfb540f6 100644
--- a/packages/desktop-client/src/components/mobile/accounts/AccountPage.tsx
+++ b/packages/desktop-client/src/components/mobile/accounts/AccountPage.tsx
@@ -1,6 +1,6 @@
import React, { Fragment, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
-import { useParams } from 'react-router';
+import { useParams, useSearchParams } from 'react-router';
import { Button } from '@actual-app/components/button';
import { styles } from '@actual-app/components/styles';
@@ -139,6 +139,32 @@ function AccountHeader({ account }: { readonly account: AccountEntity }) {
reopenAccount({ id: account.id });
}, [account.id, reopenAccount]);
+ const [, setSearchParams] = useSearchParams();
+
+ const onReconcile = useCallback(() => {
+ dispatch(
+ pushModal({
+ modal: {
+ name: 'account-reconcile',
+ options: {
+ accountId: account.id,
+ onReconcile: (amount: number) => {
+ setSearchParams(prev => {
+ prev.set('reconcile', String(amount));
+ return prev;
+ });
+ dispatch(
+ collapseModals({
+ rootModalName: 'account-menu',
+ }),
+ );
+ },
+ },
+ },
+ }),
+ );
+ }, [account.id, dispatch, setSearchParams]);
+
const [showRunningBalances, setShowRunningBalances] = useSyncedPref(
`show-balances-${account.id}`,
);
@@ -175,6 +201,7 @@ function AccountHeader({ account }: { readonly account: AccountEntity }) {
onEditNotes,
onCloseAccount,
onReopenAccount,
+ onReconcile,
onToggleRunningBalance,
onToggleReconciled,
},
@@ -186,6 +213,7 @@ function AccountHeader({ account }: { readonly account: AccountEntity }) {
dispatch,
onCloseAccount,
onEditNotes,
+ onReconcile,
onReopenAccount,
onSave,
onToggleRunningBalance,
diff --git a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx
index 63e13cda7c..445faa81c7 100644
--- a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx
+++ b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx
@@ -1,5 +1,12 @@
-import React, { useCallback, useEffect, useMemo, useState } from 'react';
+import React, {
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from 'react';
import { useTranslation } from 'react-i18next';
+import { useSearchParams } from 'react-router';
import { send } from '@actual-app/core/platform/client/connection';
import type { Query } from '@actual-app/core/shared/query';
@@ -10,8 +17,13 @@ import type {
TransactionEntity,
} from '@actual-app/core/types/models';
-import { useSyncAndDownloadMutation } from '#accounts';
+import {
+ useSyncAndDownloadMutation,
+ useUpdateAccountMutation,
+} from '#accounts';
import { markAccountRead } from '#accounts/accountsSlice';
+import * as reconciliation from '#accounts/reconciliation';
+import { ReconcilingBanner } from '#components/mobile/accounts/ReconcilingBanner';
import { TransactionListWithBalances } from '#components/mobile/transactions/TransactionListWithBalances';
import { useAccountPreviewTransactions } from '#hooks/useAccountPreviewTransactions';
import { SchedulesProvider } from '#hooks/useCachedSchedules';
@@ -20,6 +32,7 @@ import { useNavigate } from '#hooks/useNavigate';
import { getSchedulesQuery } from '#hooks/useSchedules';
import { useSheetValue } from '#hooks/useSheetValue';
import { useSyncedPref } from '#hooks/useSyncedPref';
+import { useTransactionBatchActions } from '#hooks/useTransactionBatchActions';
import {
calculateRunningBalancesTopDown,
useTransactions,
@@ -60,30 +73,53 @@ function TransactionListWithPreviews({
const [showRunningBalances] = useSyncedPref(`show-balances-${account.id}`);
const [hideReconciled] = useSyncedPref(`hide-reconciled-${account.id}`);
+ const [searchParams, setSearchParams] = useSearchParams();
+ const parsedReconcileAmount = parseInt(
+ searchParams.get('reconcile') ?? '',
+ 10,
+ );
+ const reconcileAmount = Number.isNaN(parsedReconcileAmount)
+ ? null
+ : parsedReconcileAmount;
+ const isReconciling = reconcileAmount != null;
+
const baseTransactionsQuery = useCallback(() => {
let query = queries
.transactions(account.id)
.options({ splits: 'all' })
.select('*');
- if (hideReconciled === 'true') {
+ if (hideReconciled === 'true' && !isReconciling) {
query = query.filter({ reconciled: { $eq: false } });
}
return query;
- }, [account.id, hideReconciled]);
+ }, [account.id, hideReconciled, isReconciling]);
const [transactionsQuery, setTransactionsQuery] = useState<Query>(
baseTransactionsQuery(),
);
- useEffect(() => {
- setTransactionsQuery(baseTransactionsQuery());
- }, [baseTransactionsQuery]);
-
- const { isSearching, search: onSearch } = useTransactionsSearch({
+ const { isSearching, search } = useTransactionsSearch({
updateQuery: setTransactionsQuery,
resetQuery: () => setTransactionsQuery(baseTransactionsQuery()),
dateFormat,
});
+ const searchTextRef = useRef('');
+
+ const onSearch = useCallback(
+ (searchText: string) => {
+ searchTextRef.current = searchText;
+ search(searchText);
+ },
+ [search],
+ );
+
+ useEffect(() => {
+ setTransactionsQuery(baseTransactionsQuery());
+ if (searchTextRef.current !== '') {
+ search(searchTextRef.current);
+ }
+ }, [baseTransactionsQuery, search]);
+
const shouldCalculateRunningBalances =
showRunningBalances === 'true' && !!account?.id && !isSearching;
@@ -194,6 +230,65 @@ function TransactionListWithPreviews({
[dispatch, navigate],
);
+ const { mutate: updateAccount } = useUpdateAccountMutation();
+ const { onBatchEdit } = useTransactionBatchActions();
+
+ const onDoneReconciling = useCallback(async () => {
+ await reconciliation.finishReconciliation(account.id, reconcileAmount);
+
+ updateAccount({
+ account: {
+ ...account,
+ last_reconciled: new Date().getTime().toString(),
+ },
+ });
+
+ setSearchParams(
+ prev => {
+ prev.delete('reconcile');
+ return prev;
+ },
+ { replace: true },
+ );
+ }, [account, reconcileAmount, setSearchParams, updateAccount]);
+
+ const onCreateReconciliationTransaction = useCallback(
+ async (targetDiff: number) => {
+ await reconciliation.createReconciliationTransaction(
+ account.id,
+ targetDiff,
+ );
+ },
+ [account.id],
+ );
+
+ const onToggleTransactionCleared = useCallback(
+ (transaction: TransactionEntity) => {
+ if (isPreviewId(transaction.id)) {
+ return;
+ }
+
+ if (transaction.reconciled) {
+ dispatch(
+ pushModal({
+ modal: {
+ name: 'confirm-transaction-edit',
+ options: {
+ confirmReason: 'unlockReconciled',
+ onConfirm: () => {
+ void reconciliation.unlockTransaction(transaction.id);
+ },
+ },
+ },
+ }),
+ );
+ } else {
+ void onBatchEdit({ name: 'cleared', ids: [transaction.id] });
+ }
+ },
+ [dispatch, onBatchEdit],
+ );
+
const balanceBindings = useMemo(
() => ({
balance: bindings.accountBalance(account.id),
@@ -203,32 +298,46 @@ function TransactionListWithPreviews({
[account],
);
+ const previewTransactionsToDisplay = isReconciling ? [] : previewTransactions;
+
const transactionsToDisplay = !isSearching
? // Do not render child transactions in the list, unless searching
- previewTransactions.concat(transactions.filter(t => !t.is_child))
+ previewTransactionsToDisplay.concat(transactions.filter(t => !t.is_child))
: transactions;
return (
- <TransactionListWithBalances
- isLoading={
- isSearching
- ? isTransactionsLoading
- : isTransactionsLoading || isPreviewTransactionsLoading
- }
- transactions={transactionsToDisplay}
- balance={balanceBindings.balance}
- balanceCleared={balanceBindings.cleared}
- balanceUncleared={balanceBindings.uncleared}
- runningBalances={allBalances}
- showRunningBalances={shouldCalculateRunningBalances}
- isLoadingMore={isLoadingMoreTransactions}
- onLoadMore={fetchMoreTransactions}
- searchPlaceholder={t('Search {{accountName}}', {
- accountName: account.name,
- })}
- onSearch={onSearch}
- onOpenTransaction={onOpenTransaction}
- onRefresh={onRefresh}
- />
+ <>
+ {isReconciling && (
+ <ReconcilingBanner
+ account={account}
+ targetBalance={reconcileAmount}
+ onDone={onDoneReconciling}
+ onCreateTransaction={onCreateReconciliationTransaction}
+ />
+ )}
+ <TransactionListWithBalances
+ isLoading={
+ isSearching || isReconciling
+ ? isTransactionsLoading
+ : isTransactionsLoading || isPreviewTransactionsLoading
+ }
+ transactions={transactionsToDisplay}
+ balance={balanceBindings.balance}
+ balanceCleared={balanceBindings.cleared}
+ balanceUncleared={balanceBindings.uncleared}
+ runningBalances={allBalances}
+ showRunningBalances={shouldCalculateRunningBalances}
+ isLoadingMore={isLoadingMoreTransactions}
+ onLoadMore={fetchMoreTransactions}
+ searchPlaceholder={t('Search {{accountName}}', {
+ accountName: account.name,
+ })}
+ onSearch={onSearch}
+ onOpenTransaction={onOpenTransaction}
+ onRefresh={onRefresh}
+ isReconciling={isReconciling}
+ onToggleTransactionCleared={onToggleTransactionCleared}
+ />
+ </>
);
}
diff --git a/packages/desktop-client/src/components/mobile/accounts/ReconcilingBanner.tsx b/packages/desktop-client/src/components/mobile/accounts/ReconcilingBanner.tsx
new file mode 100644
index 0000000000..29156611ef
--- /dev/null
+++ b/packages/desktop-client/src/components/mobile/accounts/ReconcilingBanner.tsx
@@ -0,0 +1,158 @@
+import React, { useState } from 'react';
+import { Trans } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { SvgCheckCircle1 } from '@actual-app/components/icons/v2';
+import { styles } from '@actual-app/components/styles';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+import type { AccountEntity } from '@actual-app/core/types/models';
+import type { TransObjectLiteral } from '@actual-app/core/types/util';
+
+import { useFormat } from '#hooks/useFormat';
+import { useSheetValue } from '#hooks/useSheetValue';
+import * as bindings from '#spreadsheet/bindings';
+
+type ReconcilingBannerProps = {
+ account: AccountEntity;
+ targetBalance: number;
+ onDone: () => Promise<void>;
+ onCreateTransaction: (targetDiff: number) => Promise<void>;
+};
+
+export function ReconcilingBanner({
+ account,
+ targetBalance,
+ onDone,
+ onCreateTransaction,
+}: ReconcilingBannerProps) {
+ const format = useFormat();
+ const cleared = useSheetValue<'account', 'balanceCleared'>(
+ bindings.accountBalanceCleared(account.id),
+ );
+ const [isUpdating, setIsUpdating] = useState(false);
+
+ if (cleared == null) {
+ return null;
+ }
+
+ const runAction = async (action: () => Promise<void>) => {
+ setIsUpdating(true);
+ try {
+ await action();
+ } finally {
+ setIsUpdating(false);
+ }
+ };
+
+ const targetDiff = targetBalance - cleared;
+
+ const clearedBalance = format(cleared, 'financial');
+ const bankBalance = format(targetBalance, 'financial');
+ const difference =
+ (targetDiff > 0 ? '+' : '') + format(targetDiff, 'financial');
+
+ const isBalanced = targetDiff === 0;
+
+ // both states stay rendered so the banner keeps the height of the taller one
+ return (
+ <View
+ data-testid="reconciling-banner"
+ style={{
+ flexShrink: 0,
+ display: 'grid',
+ backgroundColor: theme.tableBackground,
+ ...styles.shadow,
+ borderRadius: 4,
+ margin: '10px 10px 0 10px',
+ padding: 10,
+ }}
+ >
+ <View
+ style={{
+ gridArea: '1 / 1',
+ justifyContent: 'center',
+ gap: 10,
+ ...(!isBalanced && { visibility: 'hidden' }),
+ }}
+ >
+ <View
+ style={{
+ color: theme.noticeTextLight,
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}
+ >
+ <SvgCheckCircle1
+ style={{
+ width: 13,
+ height: 13,
+ color: 'inherit',
+ marginRight: 3,
+ }}
+ />
+ <Trans>All reconciled!</Trans>
+ </View>
+ <Button
+ variant="primary"
+ isDisabled={isUpdating}
+ style={{ height: styles.mobileMinHeight }}
+ onPress={() => runAction(onDone)}
+ >
+ <Trans>Lock transactions</Trans>
+ </Button>
+ </View>
+ <View
+ style={{
+ gridArea: '1 / 1',
+ justifyContent: 'center',
+ gap: 10,
+ ...(isBalanced && { visibility: 'hidden' }),
+ }}
+ >
+ <Text
+ style={{
+ color: theme.tableText,
+ fontStyle: 'italic',
+ textAlign: 'center',
+ }}
+ >
+ <Trans>
+ Your cleared balance{' '}
+ <strong>{{ clearedBalance } as TransObjectLiteral}</strong> needs{' '}
+ <strong>{{ difference } as TransObjectLiteral}</strong> to match
+ your bank&apos;s balance of{' '}
+ <Text style={{ fontWeight: 700 }}>
+ {{ bankBalance } as TransObjectLiteral}
+ </Text>
+ </Trans>
+ </Text>
+ <View
+ style={{
+ flexDirection: 'row',
+ justifyContent: 'center',
+ gap: 10,
+ }}
+ >
+ <Button
+ isDisabled={isUpdating}
+ style={{ flex: 1, minHeight: styles.mobileMinHeight }}
+ onPress={() => runAction(() => onCreateTransaction(targetDiff))}
+ >
+ <Trans>Create reconciliation transaction</Trans>
+ </Button>
+ <Button
+ variant="primary"
+ isDisabled={isUpdating}
+ style={{ flex: 1, minHeight: styles.mobileMinHeight }}
+ onPress={() => runAction(onDone)}
+ >
+ <Trans>Exit reconciliation</Trans>
+ </Button>
+ </View>
+ </View>
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx
index 00e2919f94..471ae99fc3 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx
@@ -88,6 +88,8 @@ type TransactionListProps = {
isLoadingMore: boolean;
onLoadMore: () => void;
showMakeTransfer?: boolean;
+ isReconciling?: boolean;
+ onToggleTransactionCleared?: (transaction: TransactionEntity) => void;
};
export function TransactionList({
@@ -99,6 +101,8 @@ export function TransactionList({
isLoadingMore,
onLoadMore,
showMakeTransfer = false,
+ isReconciling = false,
+ onToggleTransactionCleared,
}: TransactionListProps) {
const locale = useLocale();
const { t } = useTranslation();
@@ -184,6 +188,8 @@ export function TransactionList({
onTransactionPress,
runningBalances,
showRunningBalances,
+ isReconciling,
+ onToggleTransactionCleared,
t,
]}
renderEmptyState={() =>
@@ -235,8 +241,10 @@ export function TransactionList({
showRunningBalance={showRunningBalances}
runningBalance={runningBalances?.get(transaction.id)}
transaction={transaction}
+ isReconciling={isReconciling}
onPress={trans => onTransactionPress(trans)}
onLongPress={trans => onTransactionPress(trans, true)}
+ onToggleCleared={onToggleTransactionCleared}
/>
)}
</ListBoxItem>
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
index ba842599a8..b46b63a913 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
@@ -73,15 +73,19 @@ type TransactionListItemProps = ListBoxItemRenderProps & {
transaction?: TransactionEntity;
showRunningBalance?: boolean;
runningBalance?: IntegerAmount;
+ isReconciling?: boolean;
onPress: (transaction: TransactionEntity) => void;
onLongPress: (transaction: TransactionEntity) => void;
+ onToggleCleared?: (transaction: TransactionEntity) => void;
};
export function TransactionListItem({
showRunningBalance,
runningBalance,
+ isReconciling = false,
onPress,
onLongPress,
+ onToggleCleared,
transaction,
...itemProps
}: TransactionListItemProps) {
@@ -148,170 +152,260 @@ export function TransactionListItem({
const textStyle = getTextStyle({ isPreview });
return (
- <PressResponder {...mergeProps(pressProps, longPressProps)}>
- <Button
- {...itemProps}
- style={{
- userSelect: 'none',
- height: ROW_HEIGHT,
- width: '100%',
- borderRadius: 0,
- ...(itemProps.isSelected
- ? {
- borderWidth: '0 0 0 4px',
- borderColor: theme.mobileTransactionSelected,
- borderStyle: 'solid',
- }
- : {
- borderWidth: '0 0 1px 0',
- borderColor: theme.tableBorder,
- borderStyle: 'solid',
- }),
- ...(isPreview
- ? {
- backgroundColor: theme.tableRowHeaderBackground,
- }
- : {
- backgroundColor: theme.tableBackground,
- }),
- }}
- >
- <View
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'stretch',
+ width: '100%',
+ height: ROW_HEIGHT,
+ overflow: 'hidden',
+ ...(itemProps.isSelected
+ ? {
+ borderWidth: '0 0 0 4px',
+ borderColor: theme.mobileTransactionSelected,
+ borderStyle: 'solid',
+ }
+ : {
+ borderWidth: '0 0 1px 0',
+ borderColor: theme.tableBorder,
+ borderStyle: 'solid',
+ }),
+ ...(isPreview
+ ? {
+ backgroundColor: theme.tableRowHeaderBackground,
+ }
+ : {
+ backgroundColor: theme.tableBackground,
+ }),
+ }}
+ >
+ <PressResponder {...mergeProps(pressProps, longPressProps)}>
+ <Button
+ {...itemProps}
style={{
- flexDirection: 'row',
+ userSelect: 'none',
+ height: '100%',
flex: 1,
- alignItems: 'center',
- justifyContent: 'space-between',
- padding: '0 4px',
+ borderRadius: 0,
+ borderWidth: 0,
+ ...(isReconciling && { paddingRight: 0 }),
+ ...(isPreview
+ ? {
+ backgroundColor: theme.tableRowHeaderBackground,
+ }
+ : {
+ backgroundColor: theme.tableBackground,
+ }),
}}
>
- <View style={{ flex: 1 }}>
- <View style={{ flexDirection: 'row', alignItems: 'center' }}>
- <PayeeIcons
- transaction={transaction}
- transferAccount={transferAccount}
- />
- <TextOneLine
- style={{
- ...textStyle,
- fontWeight: isAdded ? '600' : '400',
- ...(!displayPayee && !isPreview
- ? {
- color: theme.pageTextLight,
- fontStyle: 'italic',
- }
- : {}),
- }}
- >
- {displayPayee || t('(No payee)')}
- </TextOneLine>
- </View>
- {isPreview ? (
- <Status status={previewStatus} isSplit={isParent || isChild} />
- ) : (
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- marginTop: 3,
- }}
- >
- {isReconciled ? (
- <SvgLockClosed
- style={{
- width: 11,
- height: 11,
- color: theme.noticeTextLight,
- marginRight: 5,
- }}
- />
- ) : (
- <SvgCheckCircle1
- style={{
- width: 11,
- height: 11,
- color: isCleared
- ? theme.noticeTextLight
- : theme.pageTextSubdued,
- marginRight: 5,
- }}
- />
- )}
- {(isParent || isChild) && (
- <SvgSplit
+ <View
+ style={{
+ flexDirection: 'row',
+ flex: 1,
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ padding: isReconciling ? '0 0 0 4px' : '0 4px',
+ }}
+ >
+ <View style={{ flex: 1 }}>
+ <View style={{ flexDirection: 'row', alignItems: 'center' }}>
+ <PayeeIcons
+ transaction={transaction}
+ transferAccount={transferAccount}
+ />
+ <TextOneLine
+ style={{
+ ...textStyle,
+ fontWeight: isAdded ? '600' : '400',
+ ...(!displayPayee && !isPreview
+ ? {
+ color: theme.pageTextLight,
+ fontStyle: 'italic',
+ }
+ : {}),
+ }}
+ >
+ {displayPayee || t('(No payee)')}
+ </TextOneLine>
+ </View>
+ {isPreview ? (
+ <Status status={previewStatus} isSplit={isParent || isChild} />
+ ) : (
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ marginTop: 3,
+ }}
+ >
+ {!isReconciling &&
+ (isReconciled ? (
+ <SvgLockClosed
+ style={{
+ width: 11,
+ height: 11,
+ color: theme.noticeTextLight,
+ marginRight: 5,
+ }}
+ />
+ ) : (
+ <SvgCheckCircle1
+ style={{
+ width: 11,
+ height: 11,
+ color: isCleared
+ ? theme.noticeTextLight
+ : theme.pageTextSubdued,
+ marginRight: 5,
+ }}
+ />
+ ))}
+ {(isParent || isChild) && (
+ <SvgSplit
+ style={{
+ width: 12,
+ height: 12,
+ marginRight: 5,
+ }}
+ />
+ )}
+ <TextOneLine
style={{
- width: 12,
- height: 12,
- marginRight: 5,
+ fontSize: 11,
+ marginTop: 1,
+ fontWeight: '400',
+ color: prettyCategory
+ ? theme.tableText
+ : theme.menuItemTextSelected,
+ fontStyle:
+ specialCategory || !prettyCategory
+ ? 'italic'
+ : undefined,
+ textAlign: 'left',
}}
- />
- )}
+ >
+ {prettyCategory || t('Uncategorized')}
+ </TextOneLine>
+ </View>
+ )}
+ {notes && (
<TextOneLine
style={{
fontSize: 11,
- marginTop: 1,
+ marginTop: 4,
fontWeight: '400',
- color: prettyCategory
- ? theme.tableText
- : theme.menuItemTextSelected,
- fontStyle:
- specialCategory || !prettyCategory ? 'italic' : undefined,
+ color: theme.tableText,
textAlign: 'left',
+ opacity: 0.85,
}}
>
- {prettyCategory || t('Uncategorized')}
+ <NotesTagFormatter notes={notes} />
</TextOneLine>
- </View>
- )}
- {notes && (
- <TextOneLine
- style={{
- fontSize: 11,
- marginTop: 4,
- fontWeight: '400',
- color: theme.tableText,
- textAlign: 'left',
- opacity: 0.85,
- }}
- >
- <NotesTagFormatter notes={notes} />
- </TextOneLine>
- )}
- </View>
- <View style={{ justifyContent: 'center', alignItems: 'flex-end' }}>
- <Text
- style={{
- ...styles.tnum,
- ...makeAmountFullStyle(amount, {
- positiveColor: theme.tableText,
- negativeColor: theme.tableText,
- zeroColor: theme.numberNeutral,
- }),
- ...textStyle,
- }}
- >
- {integerToCurrency(amount)}
- </Text>
- {showRunningBalance && runningBalance !== undefined && (
+ )}
+ </View>
+ <View style={{ justifyContent: 'center', alignItems: 'flex-end' }}>
<Text
style={{
- fontSize: 11,
- fontWeight: '400',
...styles.tnum,
- ...makeAmountFullStyle(runningBalance, {
- positiveColor: theme.numberPositive,
- negativeColor: theme.numberNegative,
+ ...makeAmountFullStyle(amount, {
+ positiveColor: theme.tableText,
+ negativeColor: theme.tableText,
zeroColor: theme.numberNeutral,
}),
+ ...textStyle,
}}
>
- {integerToCurrency(runningBalance)}
+ {integerToCurrency(amount)}
</Text>
- )}
+ {showRunningBalance && runningBalance !== undefined && (
+ <Text
+ style={{
+ fontSize: 11,
+ fontWeight: '400',
+ ...styles.tnum,
+ ...makeAmountFullStyle(runningBalance, {
+ positiveColor: theme.numberPositive,
+ negativeColor: theme.numberNegative,
+ zeroColor: theme.numberNeutral,
+ }),
+ }}
+ >
+ {integerToCurrency(runningBalance)}
+ </Text>
+ )}
+ </View>
</View>
- </View>
- </Button>
- </PressResponder>
+ </Button>
+ </PressResponder>
+ {isReconciling &&
+ !isPreview &&
+ (isChild ? (
+ <View
+ style={{
+ width: 32,
+ flexShrink: 0,
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <ClearedStatusIcon
+ isReconciled={isReconciled}
+ isCleared={isCleared}
+ />
+ </View>
+ ) : (
+ <Button
+ variant="bare"
+ aria-label={
+ isReconciled
+ ? t('Unlock reconciled transaction')
+ : isCleared
+ ? t('Unclear transaction')
+ : t('Clear transaction')
+ }
+ style={{
+ width: 32,
+ height: '100%',
+ flexShrink: 0,
+ borderRadius: 0,
+ }}
+ onPress={() => onToggleCleared?.(transaction)}
+ >
+ <ClearedStatusIcon
+ isReconciled={isReconciled}
+ isCleared={isCleared}
+ />
+ </Button>
+ ))}
+ </View>
+ );
+}
+
+type ClearedStatusIconProps = {
+ isReconciled?: boolean;
+ isCleared?: boolean;
+};
+
+function ClearedStatusIcon({
+ isReconciled,
+ isCleared,
+}: ClearedStatusIconProps) {
+ return isReconciled ? (
+ <SvgLockClosed
+ style={{
+ width: 13,
+ height: 13,
+ color: theme.noticeTextLight,
+ }}
+ />
+ ) : (
+ <SvgCheckCircle1
+ style={{
+ width: 13,
+ height: 13,
+ color: isCleared ? theme.noticeTextLight : theme.pageTextSubdued,
+ }}
+ />
);
}
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx
index a3ba5bfb86..a01a45c51d 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx
@@ -84,6 +84,8 @@ type TransactionListWithBalancesProps = {
onOpenTransaction: (transaction: TransactionEntity) => void;
onRefresh?: () => void;
showMakeTransfer?: boolean;
+ isReconciling?: boolean;
+ onToggleTransactionCleared?: (transaction: TransactionEntity) => void;
};
export function TransactionListWithBalances({
@@ -101,6 +103,8 @@ export function TransactionListWithBalances({
onOpenTransaction,
onRefresh,
showMakeTransfer = false,
+ isReconciling = false,
+ onToggleTransactionCleared,
}: TransactionListWithBalancesProps) {
const selectedInst = useSelected('transactions', [...transactions], []);
@@ -124,6 +128,7 @@ export function TransactionListWithBalances({
balance={balance}
balanceCleared={balanceCleared}
balanceUncleared={balanceUncleared}
+ alwaysShowCleared={isReconciling}
/>
) : (
<Balance balance={balance} />
@@ -152,6 +157,8 @@ export function TransactionListWithBalances({
onLoadMore={onLoadMore}
onOpenTransaction={onOpenTransaction}
showMakeTransfer={showMakeTransfer}
+ isReconciling={isReconciling}
+ onToggleTransactionCleared={onToggleTransactionCleared}
/>
</PullToRefresh>
</SelectedProvider>
@@ -180,24 +187,27 @@ type BalanceWithClearedProps = {
TransactionListWithBalancesProps['balanceCleared']
>;
balance: TransactionListWithBalancesProps['balance'];
+ alwaysShowCleared?: boolean;
};
function BalanceWithCleared({
balanceUncleared,
balanceCleared,
balance,
+ alwaysShowCleared = false,
}: BalanceWithClearedProps) {
const { t } = useTranslation();
const unclearedAmount = useSheetValue<
'account' | 'category',
'balanceUncleared'
>(balanceUncleared);
+ const showCleared = !!unclearedAmount || alwaysShowCleared;
return (
<>
<View
style={{
- display: !unclearedAmount ? 'none' : undefined,
+ display: !showCleared ? 'none' : undefined,
flexBasis: '33%',
}}
>
@@ -225,7 +235,7 @@ function BalanceWithCleared({
<Balance balance={balance} />
<View
style={{
- display: !unclearedAmount ? 'none' : undefined,
+ display: !showCleared ? 'none' : undefined,
flexBasis: '33%',
}}
>
diff --git a/packages/desktop-client/src/components/modals/AccountMenuModal.tsx b/packages/desktop-client/src/components/modals/AccountMenuModal.tsx
index dc20610e55..6a107f0828 100644
--- a/packages/desktop-client/src/components/modals/AccountMenuModal.tsx
+++ b/packages/desktop-client/src/components/modals/AccountMenuModal.tsx
@@ -8,7 +8,7 @@ import {
SvgDotsHorizontalTriple,
SvgLockOpen,
} from '@actual-app/components/icons/v1';
-import { SvgNotesPaper } from '@actual-app/components/icons/v2';
+import { SvgLockClosed, SvgNotesPaper } from '@actual-app/components/icons/v2';
import { Menu } from '@actual-app/components/menu';
import { Popover } from '@actual-app/components/popover';
import { styles } from '@actual-app/components/styles';
@@ -42,6 +42,7 @@ export function AccountMenuModal({
onReopenAccount,
onEditNotes,
onClose,
+ onReconcile,
onToggleRunningBalance,
onToggleReconciled,
}: AccountMenuModalProps) {
@@ -91,12 +92,14 @@ export function AccountMenuModal({
onEditNotes?.(account.id);
};
+ const canReconcile = !!onReconcile;
+
const buttonStyle: CSSProperties = {
...styles.mediumText,
height: styles.mobileMinHeight,
color: theme.formLabelText,
// Adjust based on desired number of buttons per row.
- flexBasis: '100%',
+ flexBasis: canReconcile ? '48%' : '100%',
};
if (!account) {
@@ -188,6 +191,16 @@ export function AccountMenuModal({
/>
<Trans>Edit notes</Trans>
</Button>
+ {canReconcile && (
+ <Button style={buttonStyle} onPress={() => onReconcile?.()}>
+ <SvgLockClosed
+ width={20}
+ height={20}
+ style={{ paddingRight: 5 }}
+ />
+ <Trans>Reconcile</Trans>
+ </Button>
+ )}
</View>
</View>
</>
diff --git a/packages/desktop-client/src/components/modals/AccountReconcileModal.tsx b/packages/desktop-client/src/components/modals/AccountReconcileModal.tsx
new file mode 100644
index 0000000000..79a72e5f90
--- /dev/null
+++ b/packages/desktop-client/src/components/modals/AccountReconcileModal.tsx
@@ -0,0 +1,184 @@
+import React, { useEffect, useState } from 'react';
+import { Trans, useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { styles } from '@actual-app/components/styles';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+import {
+ amountToInteger,
+ integerToAmount,
+ tsToRelativeTime,
+} from '@actual-app/core/shared/util';
+import { format as formatDate } from 'date-fns';
+
+import { Modal, ModalCloseButton, ModalHeader } from '#components/common/Modal';
+import { FinancialText } from '#components/FinancialText';
+import { FieldLabel } from '#components/mobile/MobileForms';
+import { AmountInput } from '#components/mobile/transactions/AmountInput';
+import { useAccount } from '#hooks/useAccount';
+import { useDateFormat } from '#hooks/useDateFormat';
+import { useFeatureFlag } from '#hooks/useFeatureFlag';
+import { useFormat } from '#hooks/useFormat';
+import { useLocale } from '#hooks/useLocale';
+import { useSheetValue } from '#hooks/useSheetValue';
+import type { Modal as ModalType } from '#modals/modalsSlice';
+import * as bindings from '#spreadsheet/bindings';
+
+type AccountReconcileModalProps = Extract<
+ ModalType,
+ { name: 'account-reconcile' }
+>['options'];
+
+export function AccountReconcileModal({
+ accountId,
+ onReconcile,
+}: AccountReconcileModalProps) {
+ const { t } = useTranslation();
+ const account = useAccount(accountId);
+ const mobileCalculatorEnabled = useFeatureFlag('mobileCalculator');
+ const clearedBalance = useSheetValue<'account', 'balanceCleared'>(
+ bindings.accountBalanceCleared(accountId),
+ );
+ const format = useFormat();
+ const dateFormat = useDateFormat() || 'MM/dd/yyyy';
+ const locale = useLocale();
+
+ const [amount, setAmount] = useState<number | null>(null);
+ const [amountInputKey, setAmountInputKey] = useState(0);
+
+ useEffect(() => {
+ if (amount == null && clearedBalance != null) {
+ setAmount(clearedBalance);
+ }
+ }, [amount, clearedBalance]);
+
+ const lastSyncedBalance = account?.balance_current;
+
+ if (!account) {
+ return null;
+ }
+
+ const onSubmit = (newAmount: number | null) => {
+ if (newAmount == null) {
+ return;
+ }
+ onReconcile(newAmount);
+ };
+
+ return (
+ <Modal
+ name="account-reconcile"
+ wrapperProps={{
+ style: mobileCalculatorEnabled ? { paddingBottom: '30vh' } : undefined,
+ }}
+ >
+ {({ state }) => (
+ <>
+ <ModalHeader
+ title={t('Reconcile')}
+ rightContent={<ModalCloseButton onPress={() => state.close()} />}
+ />
+ <View>
+ <FieldLabel
+ title={t(
+ 'Enter the current balance of your bank account that you want to reconcile with:',
+ )}
+ />
+ {amount != null && (
+ <View
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <AmountInput
+ key={amountInputKey}
+ value={integerToAmount(amount)}
+ onChange={newAmount => setAmount(amountToInteger(newAmount))}
+ autoFocus
+ autoFocusDelay={150}
+ variant="large"
+ />
+ </View>
+ )}
+ </View>
+ {lastSyncedBalance != null && (
+ <View
+ style={{
+ alignItems: 'center',
+ paddingTop: 10,
+ }}
+ >
+ <Text>
+ <Trans>Last Balance from Bank: </Trans>
+ <FinancialText>
+ {format(lastSyncedBalance, 'financial')}
+ </FinancialText>
+ </Text>
+ <Button
+ style={{
+ height: styles.mobileMinHeight,
+ marginTop: 5,
+ marginLeft: styles.mobileEditingPadding,
+ marginRight: styles.mobileEditingPadding,
+ }}
+ onPress={() => {
+ setAmount(lastSyncedBalance);
+ setAmountInputKey(key => key + 1);
+ }}
+ >
+ <Trans>Use last synced total</Trans>
+ </Button>
+ </View>
+ )}
+ <View
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ paddingTop: 10,
+ }}
+ >
+ <Button
+ variant="primary"
+ isDisabled={amount == null}
+ style={{
+ height: styles.mobileMinHeight,
+ marginLeft: styles.mobileEditingPadding,
+ marginRight: styles.mobileEditingPadding,
+ }}
+ onPress={() => {
+ onSubmit(amount);
+ state.close();
+ }}
+ >
+ <Trans>Reconcile</Trans>
+ </Button>
+ </View>
+ <Text
+ style={{
+ color: theme.pageTextLight,
+ marginTop: 8,
+ textAlign: 'center',
+ }}
+ >
+ {account.last_reconciled
+ ? t('Reconciled {{ relativeTimeAgo }} ({{ absoluteDate }})', {
+ relativeTimeAgo: tsToRelativeTime(
+ account.last_reconciled,
+ locale,
+ ),
+ absoluteDate: formatDate(
+ new Date(parseInt(account.last_reconciled, 10)),
+ dateFormat,
+ { locale },
+ ),
+ })
+ : t('Not yet reconciled')}
+ </Text>
+ </>
+ )}
+ </Modal>
+ );
+}
diff --git a/packages/desktop-client/src/modals/modalsSlice.ts b/packages/desktop-client/src/modals/modalsSlice.ts
index 844c103d7f..6eee7146a9 100644
--- a/packages/desktop-client/src/modals/modalsSlice.ts
+++ b/packages/desktop-client/src/modals/modalsSlice.ts
@@ -353,10 +353,18 @@ export type Modal =
onReopenAccount: (accountId: AccountEntity['id']) => void;
onEditNotes: (id: NoteEntity['id']) => void;
onClose?: () => void;
+ onReconcile?: () => void;
onToggleRunningBalance?: () => void;
onToggleReconciled?: () => void;
};
}
+ | {
+ name: 'account-reconcile';
+ options: {
+ accountId: AccountEntity['id'];
+ onReconcile: (amount: number) => void;
+ };
+ }
| {
name: 'category-menu';
options: {
diff --git a/upcoming-release-notes/add-mobile-reconciliation.md b/upcoming-release-notes/add-mobile-reconciliation.md
new file mode 100644
index 0000000000..76fa484ecf
--- /dev/null
+++ b/upcoming-release-notes/add-mobile-reconciliation.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [matt-fidd]
+---
+
+Add ability to reconcile accounts on mobile