Skip to content

A local-first personal finance app

Formulas code clean up (#8369)

lelemmf00bde7a17d7
diff --git a/packages/desktop-client/src/components/formula/codeMirror-excelLanguage.tsx b/packages/desktop-client/src/components/formula/codeMirror-excelLanguage.tsx
index 16b91360bc..ad32f3d5f7 100644
--- a/packages/desktop-client/src/components/formula/codeMirror-excelLanguage.tsx
+++ b/packages/desktop-client/src/components/formula/codeMirror-excelLanguage.tsx
@@ -5,7 +5,7 @@ import { Trans } from 'react-i18next';
import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { autocompletion } from '@codemirror/autocomplete';
-import type { Completion, CompletionContext } from '@codemirror/autocomplete';
+import type { CompletionContext } from '@codemirror/autocomplete';
import {
HighlightStyle,
StreamLanguage,
@@ -21,11 +21,18 @@ import {
} from '@codemirror/view';
import type { Tooltip } from '@codemirror/view';
import { tags } from '@lezer/highlight';
-import { t } from 'i18next';
-import { queryModeFunctions } from './queryModeFunctions';
-import type { FunctionDef } from './queryModeFunctions';
-import { transactionModeFunctions } from './transactionModeFunctions';
+import {
+ getDynamicReportQueryCompletions,
+ getFormulaCategoryForName,
+ getFormulaFunctionByName,
+ getFormulaFunctionCategoryConfig,
+ getFunctionCompletions,
+ getNamedVariableCompletions,
+ getRuleFieldCompletions,
+ sortFormulaCompletions,
+} from './formulaCatalog';
+import type { FormulaMode } from './formulaCatalog';
// Tooltip components using the same styles as Tooltip.tsx
function FunctionTooltip({
@@ -73,121 +80,6 @@ function FieldTooltip({ label, info }: { label: string; info: string }) {
);
}
-type FormulaMode = 'query' | 'transaction';
-
-const MATH_FUNCTIONS = new Set([
- 'SUM',
- 'AVERAGE',
- 'MAX',
- 'MIN',
- 'ABS',
- 'ROUND',
- 'ROUNDUP',
- 'ROUNDDOWN',
- 'CEILING',
- 'FLOOR',
- 'MOD',
- 'POWER',
- 'SQRT',
- 'INT',
- 'TRUNC',
- 'SIGN',
- 'PI',
- 'SIN',
- 'COS',
- 'TAN',
- 'LN',
- 'LOG',
- 'LOG10',
- 'EXP',
- 'PRODUCT',
- 'PMT',
- 'FV',
- 'PV',
- 'NPV',
- 'IRR',
- 'RATE',
-]);
-
-const LOGICAL_FUNCTIONS = new Set([
- 'IF',
- 'IFS',
- 'AND',
- 'OR',
- 'XOR',
- 'NOT',
- 'TRUE',
- 'FALSE',
- 'IFERROR',
- 'IFNA',
- 'SWITCH',
-]);
-
-const TEXT_FUNCTIONS = new Set([
- 'TEXT',
- 'FIXED',
- 'FORMATNUMBER',
- 'FORMATCURRENCY',
- 'CONCATENATE',
- 'LEFT',
- 'RIGHT',
- 'MID',
- 'LEN',
- 'UPPER',
- 'LOWER',
- 'TRIM',
- 'PROPER',
- 'SUBSTITUTE',
- 'REPLACE',
- 'FIND',
- 'SEARCH',
- 'REPT',
- 'CHAR',
- 'CODE',
- 'EXACT',
- 'CLEAN',
- 'SPLIT',
- 'VALUE',
- 'T',
- 'N',
-]);
-
-const DATE_FUNCTIONS = new Set([
- 'DATE',
- 'YEAR',
- 'MONTH',
- 'DAY',
- 'TODAY',
- 'NOW',
- 'WEEKDAY',
- 'EDATE',
- 'EOMONTH',
- 'DAYS',
- 'DATEDIF',
- 'DATEVALUE',
- 'NETWORKDAYS',
- 'WEEKNUM',
- 'ISOWEEKNUM',
-]);
-
-const QUERY_FUNCTIONS = new Set([
- 'QUERY',
- 'QUERY_COUNT',
- 'BUDGET_QUERY',
- 'QUERY_EXTRACT_CATEGORIES',
- 'QUERY_EXTRACT_TIMEFRAME_START',
- 'QUERY_EXTRACT_TIMEFRAME_END',
- 'CHOOSE',
- 'ISBLANK',
- 'ISERROR',
- 'ISNA',
- 'ISNUMBER',
- 'ISTEXT',
- 'ISLOGICAL',
- 'ISEVEN',
- 'ISODD',
-]);
-
// Excel formula syntax parser for CodeMirror
const excelFormulaParser: StreamParser<{ inString: boolean }> = {
startState() {
@@ -230,23 +122,9 @@ const excelFormulaParser: StreamParser<{ inString: boolean }> = {
if (stream.peek() === '(') {
stream.pos = pos; // Reset position
- // Categorize the function using different token types
- if (MATH_FUNCTIONS.has(word)) {
- return 'keyword';
- }
- if (LOGICAL_FUNCTIONS.has(word)) {
- return 'className';
- }
- if (TEXT_FUNCTIONS.has(word)) {
- return 'namespace';
- }
- if (DATE_FUNCTIONS.has(word)) {
- return 'typeName';
- }
- if (QUERY_FUNCTIONS.has(word)) {
- return 'propertyName';
- }
- return 'function';
+ return getFormulaFunctionCategoryConfig()[
+ getFormulaCategoryForName(word) ?? 'other'
+ ].tokenClass;
}
stream.pos = pos; // Reset position
return 'variableName';
@@ -267,275 +145,12 @@ const excelFormulaParser: StreamParser<{ inString: boolean }> = {
},
};
-// Transaction field variables for autocomplete
-const transactionFields: Completion[] = [
- {
- label: 'amount',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Transaction amount in cents. Use for calculations and comparisons.\n\nExample: =amount / 100 to get dollar value',
- ),
- },
- {
- label: 'date',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Transaction date in YYYY-MM-DD format. Use with date functions.\n\nExample: =TEXT(date, "MMMM") to get month name',
- ),
- },
- {
- label: 'notes',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Transaction notes/memo text. Use for string operations.\n\nExample: =UPPER(notes) to convert to uppercase',
- ),
- },
- {
- label: 'imported_payee',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Original imported payee name from bank import. Contains the raw text before matching.\n\nExample: =LEFT(imported_payee, 10) to get first 10 characters',
- ),
- },
- {
- label: 'payee',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Payee ID (string). The ID of the payee.\n\nExample: =CONCATENATE("Payment to ", payee)',
- ),
- },
- {
- label: 'payee_name',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Payee name (string). The human-readable name of the payee.\n\nExample: =UPPER(payee_name) or =CONCATENATE("Payment to ", payee_name)',
- ),
- },
- {
- label: 'account',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Account ID (string). The ID of the account.\n\nExample: =CONCATENATE("Paid from ", account)',
- ),
- },
- {
- label: 'account_name',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Account name (string). The human-readable name of the account.\n\nExample: =CONCATENATE("Paid from ", account_name)',
- ),
- },
- {
- label: 'category',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Category ID (string). The ID of the category.\n\nExample: =IF(category="Groceries", "Food", "Other")',
- ),
- },
- {
- label: 'category_name',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Category Name (string). The human-readable name of the category.\n\nExample: =IF(category_name="Groceries", "Food", "Other")',
- ),
- },
- {
- label: 'cleared',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Boolean cleared status. TRUE if transaction is cleared, FALSE otherwise.\n\nExample: =IF(cleared, "Cleared", "Pending")',
- ),
- },
- {
- label: 'reconciled',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Boolean reconciled status. TRUE if transaction is reconciled, FALSE otherwise.',
- ),
- },
- {
- label: 'balance',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'Account balance as of the date of the transaction, excluding the transaction amount. Use for calculations and comparisons.\n\nExample: =IF(balance < 0, "Negative Balance", "Positive Balance")',
- ),
- },
- {
- label: 'parent_amount',
- type: 'variable',
- section: 'πŸ’° Transaction Fields',
- boost: 5,
- info: t(
- 'The amount of the parent transaction in cents in split transactions.\n\nExample: =(parent_amount / 100) * .05',
- ),
- },
-];
-
-// Convert function definitions to completions with grouping
-function getFunctionCompletions(mode: FormulaMode): Completion[] {
- const functions =
- mode === 'query' ? queryModeFunctions : transactionModeFunctions;
-
- // Helper to create completion with section info
- const createCompletion = (
- name: string,
- func: FunctionDef,
- section: string,
- ): Completion => ({
- label: name,
- type: 'function',
- section,
- info: [
- func.description,
- '',
- `${t('Parameters:')} ${func.parameters.map(p => p.name).join(', ')}`,
- '',
- func.parameters.map(p => `- ${p.name}: ${p.description}`).join('\n'),
- ].join('\n'),
- apply: `${name}()`,
- boost: 10, // Boost functions to appear higher
- });
-
- const completions: Completion[] = [];
-
- // Group functions by category
- for (const [name, func] of Object.entries(functions)) {
- if (MATH_FUNCTIONS.has(name)) {
- completions.push(createCompletion(name, func, 'πŸ“Š Math Functions'));
- } else if (LOGICAL_FUNCTIONS.has(name)) {
- completions.push(createCompletion(name, func, 'πŸ”€ Logical Functions'));
- } else if (TEXT_FUNCTIONS.has(name)) {
- completions.push(createCompletion(name, func, 'πŸ“ Text Functions'));
- } else if (DATE_FUNCTIONS.has(name)) {
- completions.push(createCompletion(name, func, 'πŸ“… Date Functions'));
- } else if (QUERY_FUNCTIONS.has(name)) {
- completions.push(createCompletion(name, func, 'πŸ” Query Functions'));
- } else {
- completions.push(createCompletion(name, func, 'βš™οΈ Other Functions'));
- }
- }
-
- return completions;
-}
-
// Autocomplete extension
export function excelFormulaAutocomplete(
mode: FormulaMode,
queries?: Record<string, unknown>,
variables?: Record<string, number | string>,
): Extension {
- const functionCompletions = getFunctionCompletions(mode);
-
- const queryCompletions: Completion[] = queries
- ? Object.keys(queries).flatMap(queryName => [
- {
- label: `QUERY("${queryName}")`,
- type: 'function',
- section: 'πŸ” Query Functions',
- info: t('Execute the {{queryName}} query and return the result.', {
- queryName,
- }),
- apply: `QUERY("${queryName}")`,
- boost: 15, // Boost query completions to appear at top of Query Functions section
- },
- {
- label: `QUERY_COUNT("${queryName}")`,
- type: 'function',
- section: 'πŸ” Query Functions',
- info: t(
- 'Execute the {{queryName}} query and return the number of matching rows.',
- {
- queryName,
- },
- ),
- apply: `QUERY_COUNT("${queryName}")`,
- boost: 14,
- },
- {
- label: `BUDGET_QUERY("budgeted", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
- type: 'function',
- section: 'πŸ” Query Functions',
- info: t(
- 'Sum of budgeted amounts with extracted parameters from {{queryName}}.',
- { queryName },
- ),
- apply: `BUDGET_QUERY("budgeted", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
- boost: 13,
- },
- {
- label: `BUDGET_QUERY("spent", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
- type: 'function',
- section: 'πŸ” Query Functions',
- info: t(
- 'Sum of spending with extracted parameters from {{queryName}}.',
- { queryName },
- ),
- apply: `BUDGET_QUERY("spent", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
- boost: 13,
- },
- {
- label: `BUDGET_QUERY("balance_start", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
- type: 'function',
- section: 'πŸ” Query Functions',
- info: t(
- 'Opening balance with extracted parameters from {{queryName}}.',
- { queryName },
- ),
- apply: `BUDGET_QUERY("balance_start", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
- boost: 13,
- },
- {
- label: `BUDGET_QUERY("balance_end", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
- type: 'function',
- section: 'πŸ” Query Functions',
- info: t(
- 'Closing balance with extracted parameters from {{queryName}}.',
- { queryName },
- ),
- apply: `BUDGET_QUERY("balance_end", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
- boost: 13,
- },
- ])
- : [];
-
- const variableCompletions: Completion[] = variables
- ? Object.entries(variables).map(([varName, value]) => ({
- label: varName,
- type: 'variable',
- section: 'πŸ”’ Variables',
- info: t('Variable with value: {{value}}', {
- value: String(value),
- }),
- boost: 20, // Boost variable completions to appear at top
- }))
- : [];
-
return autocompletion({
override: [
(context: CompletionContext) => {
@@ -544,57 +159,21 @@ export function excelFormulaAutocomplete(
return null;
}
- const suggestions: Completion[] = [
- ...variableCompletions, // Put variable completions first
- ...queryCompletions, // Put query completions first
- ...functionCompletions,
+ const suggestions = [
+ ...getNamedVariableCompletions(variables),
+ ...(mode === 'query'
+ ? getDynamicReportQueryCompletions(queries)
+ : []),
+ ...getFunctionCompletions(mode),
];
if (mode === 'transaction') {
- suggestions.push(...transactionFields);
+ suggestions.push(...getRuleFieldCompletions());
}
- // Sort by section first, then by boost (descending), then by label
- const sortedSuggestions = suggestions.sort((a, b) => {
- // Define section priority order
- const sectionOrder: Record<string, number> = {
- 'πŸ”’ Variables': -1,
- 'πŸ” Query Functions': 0,
- 'πŸ“Š Math Functions': 1,
- 'πŸ”€ Logical Functions': 2,
- 'πŸ“ Text Functions': 3,
- 'πŸ“… Date Functions': 4,
- 'βš™οΈ Other Functions': 5,
- 'πŸ’° Transaction Fields': 6,
- };
-
- // Get section names
- const sectionA =
- typeof a.section === 'string' ? a.section : a.section?.name || '';
- const sectionB =
- typeof b.section === 'string' ? b.section : b.section?.name || '';
-
- // Compare by section priority
- const orderA = sectionOrder[sectionA] ?? 999;
- const orderB = sectionOrder[sectionB] ?? 999;
- if (orderA !== orderB) {
- return orderA - orderB;
- }
-
- // Within same section, sort by boost (higher first)
- const boostA = a.boost || 0;
- const boostB = b.boost || 0;
- if (boostA !== boostB) {
- return boostB - boostA;
- }
-
- // Finally, sort by label alphabetically
- return a.label.localeCompare(b.label);
- });
-
return {
from: word.from,
- options: sortedSuggestions,
+ options: sortFormulaCompletions(suggestions),
};
},
],
@@ -603,15 +182,12 @@ export function excelFormulaAutocomplete(
// Hover tooltip for documentation
export function excelFormulaHover(mode: FormulaMode): Extension {
- const functions =
- mode === 'query' ? queryModeFunctions : transactionModeFunctions;
-
return hoverTooltip((view, pos) => {
const word = view.state.wordAt(pos);
if (!word) return null;
const w = view.state.doc.sliceString(word.from, word.to);
const upper = w.toUpperCase();
- const funcDef = functions[upper];
+ const funcDef = getFormulaFunctionByName(upper, mode);
if (funcDef) {
return {
pos: word.from,
@@ -641,7 +217,7 @@ export function excelFormulaHover(mode: FormulaMode): Extension {
// Transaction fields
if (mode === 'transaction') {
- const field = transactionFields.find(f => f.label === w);
+ const field = getRuleFieldCompletions().find(f => f.label === w);
if (field) {
return {
pos: word.from,
diff --git a/packages/desktop-client/src/components/formula/formulaCatalog.test.ts b/packages/desktop-client/src/components/formula/formulaCatalog.test.ts
new file mode 100644
index 0000000000..dae1b2347e
--- /dev/null
+++ b/packages/desktop-client/src/components/formula/formulaCatalog.test.ts
@@ -0,0 +1,117 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ getDynamicReportQueryCompletions,
+ getFormulaCategoryForName,
+ getFormulaFunctionCatalog,
+ getFormulaFunctionCategoryConfig,
+ getFormulaFunctionsByMode,
+ getFormulaFunctionsForMode,
+ getFunctionCompletions,
+ getNamedVariableCompletions,
+ getRuleFieldCompletions,
+ sortFormulaCompletions,
+} from './formulaCatalog';
+
+function labels(items: Array<{ label: string }>): string[] {
+ return items.map(item => item.label);
+}
+
+describe('formulaCatalog', () => {
+ it('derives mode availability for every catalog function', () => {
+ const catalog = getFormulaFunctionCatalog();
+ const functionsByMode = getFormulaFunctionsByMode();
+ const availableFunctionNames = new Set([
+ ...functionsByMode.query,
+ ...functionsByMode.transaction,
+ ]);
+
+ for (const [functionName, func] of Object.entries(catalog)) {
+ expect(func.modes.length).toBeGreaterThan(0);
+ expect(availableFunctionNames.has(functionName)).toBe(true);
+ }
+ });
+
+ it('does not duplicate function names within a mode', () => {
+ for (const functionNames of Object.values(getFormulaFunctionsByMode())) {
+ expect(new Set(functionNames).size).toBe(functionNames.length);
+ }
+ });
+
+ it('keeps report-only query functions out of rule formulas', () => {
+ const reportFunctions = getFormulaFunctionsForMode('query');
+ const ruleFunctions = getFormulaFunctionsForMode('transaction');
+
+ expect(reportFunctions.QUERY).toBeDefined();
+ expect(reportFunctions.QUERY_COUNT).toBeDefined();
+ expect(reportFunctions.BUDGET_QUERY).toBeDefined();
+ expect(reportFunctions.BALANCE_OF).toBeUndefined();
+
+ expect(ruleFunctions.BALANCE_OF).toBeDefined();
+ expect(ruleFunctions.QUERY).toBeUndefined();
+ expect(ruleFunctions.QUERY_COUNT).toBeUndefined();
+ });
+
+ it('keeps shared functions available to reports and rules', () => {
+ const reportFunctions = getFormulaFunctionsForMode('query');
+ const ruleFunctions = getFormulaFunctionsForMode('transaction');
+
+ for (const functionName of [
+ 'SUM',
+ 'FORMATNUMBER',
+ 'FORMATCURRENCY',
+ 'INTEGER_TO_AMOUNT',
+ ]) {
+ expect(reportFunctions[functionName]).toBeDefined();
+ expect(ruleFunctions[functionName]).toBeDefined();
+ }
+ });
+
+ it('has completion and highlighting config for every function category', () => {
+ const categoryConfig = getFormulaFunctionCategoryConfig();
+
+ for (const func of Object.values(getFormulaFunctionCatalog())) {
+ expect(categoryConfig[func.category]).toEqual(
+ expect.objectContaining({
+ section: expect.any(String),
+ order: expect.any(Number),
+ tokenClass: expect.any(String),
+ }),
+ );
+ expect(getFormulaCategoryForName(func.name)).toBe(func.category);
+ }
+ });
+
+ it('builds rule field completions', () => {
+ expect(labels(getRuleFieldCompletions())).toEqual(
+ expect.arrayContaining(['amount', 'date', 'notes', 'balance']),
+ );
+ });
+
+ it('builds report query completions from saved query names', () => {
+ const completions = getDynamicReportQueryCompletions({
+ Expenses: {},
+ });
+ const spentBudgetQueryLabel =
+ 'BUDGET_QUERY("spent", QUERY_EXTRACT_CATEGORIES("Expenses"), ' +
+ 'QUERY_EXTRACT_TIMEFRAME_START("Expenses"), ' +
+ 'QUERY_EXTRACT_TIMEFRAME_END("Expenses"))';
+
+ expect(labels(completions)).toEqual(
+ expect.arrayContaining([
+ 'QUERY("Expenses")',
+ 'QUERY_COUNT("Expenses")',
+ spentBudgetQueryLabel,
+ ]),
+ );
+ });
+
+ it('sorts named variables above function completions', () => {
+ const sorted = sortFormulaCompletions([
+ ...getFunctionCompletions('query'),
+ ...getNamedVariableCompletions({ RESULT: 42 }),
+ ]);
+
+ expect(sorted[0].label).toBe('RESULT');
+ });
+});
diff --git a/packages/desktop-client/src/components/formula/formulaCatalog.ts b/packages/desktop-client/src/components/formula/formulaCatalog.ts
new file mode 100644
index 0000000000..cea90ffd66
--- /dev/null
+++ b/packages/desktop-client/src/components/formula/formulaCatalog.ts
@@ -0,0 +1,1430 @@
+import type { Completion } from '@codemirror/autocomplete';
+import { t } from 'i18next';
+
+export type FormulaMode = 'query' | 'transaction';
+
+export type FormulaFunctionCategory =
+ | 'math'
+ | 'logical'
+ | 'text'
+ | 'date'
+ | 'query'
+ | 'other';
+
+export type FormulaFunctionDef = {
+ name: string;
+ category: FormulaFunctionCategory;
+ modes: FormulaMode[];
+ description: string;
+ parameters: Array<{ name: string; description: string }>;
+};
+
+type FormulaFunctionCategoryConfig = {
+ section: string;
+ order: number;
+ tokenClass:
+ | 'keyword'
+ | 'className'
+ | 'namespace'
+ | 'typeName'
+ | 'propertyName'
+ | 'function';
+};
+
+export function getFormulaFunctionCategoryConfig(): Record<
+ FormulaFunctionCategory,
+ FormulaFunctionCategoryConfig
+> {
+ return {
+ query: {
+ section: `πŸ” ${t('Query Functions')}`,
+ order: 0,
+ tokenClass: 'propertyName',
+ },
+ math: {
+ section: `πŸ“Š ${t('Math Functions')}`,
+ order: 1,
+ tokenClass: 'keyword',
+ },
+ logical: {
+ section: `πŸ”€ ${t('Logical Functions')}`,
+ order: 2,
+ tokenClass: 'className',
+ },
+ text: {
+ section: `πŸ“ ${t('Text Functions')}`,
+ order: 3,
+ tokenClass: 'namespace',
+ },
+ date: {
+ section: `πŸ“… ${t('Date Functions')}`,
+ order: 4,
+ tokenClass: 'typeName',
+ },
+ other: {
+ section: `βš™οΈ ${t('Other Functions')}`,
+ order: 5,
+ tokenClass: 'function',
+ },
+ };
+}
+
+function getVariableCompletionSection(): string {
+ return `πŸ”’ ${t('Variables')}`;
+}
+
+function getRuleFieldCompletionSection(): string {
+ return `πŸ’° ${t('Transaction Fields')}`;
+}
+
+function getFormulaCompletionSectionOrder(): Record<string, number> {
+ const categoryConfig = getFormulaFunctionCategoryConfig();
+
+ return {
+ [getVariableCompletionSection()]: -1,
+ [categoryConfig.query.section]: categoryConfig.query.order,
+ [categoryConfig.math.section]: categoryConfig.math.order,
+ [categoryConfig.logical.section]: categoryConfig.logical.order,
+ [categoryConfig.text.section]: categoryConfig.text.order,
+ [categoryConfig.date.section]: categoryConfig.date.order,
+ [categoryConfig.other.section]: categoryConfig.other.order,
+ [getRuleFieldCompletionSection()]: 6,
+ };
+}
+
+export function getFormulaFunctionCatalog(): Record<
+ string,
+ FormulaFunctionDef
+> {
+ return {
+ SUM: {
+ name: 'SUM',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Returns the sum of all numbers in a range.'),
+ parameters: [{ name: 'numbers', description: t('One or more numbers') }],
+ },
+ AVERAGE: {
+ name: 'AVERAGE',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the average of all numbers in a range.'),
+ parameters: [{ name: 'numbers', description: t('One or more numbers') }],
+ },
+ MAX: {
+ name: 'MAX',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the maximum value from numbers.'),
+ parameters: [{ name: 'numbers', description: t('One or more numbers') }],
+ },
+ MIN: {
+ name: 'MIN',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the minimum value from numbers.'),
+ parameters: [{ name: 'numbers', description: t('One or more numbers') }],
+ },
+ ABS: {
+ name: 'ABS',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Returns the absolute value of a number.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ ROUND: {
+ name: 'ROUND',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Rounds a number to specified decimals.'),
+ parameters: [
+ { name: 'number', description: t('Number') },
+ { name: 'decimals', description: t('Decimals') },
+ ],
+ },
+ ROUNDDOWN: {
+ name: 'ROUNDDOWN',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Rounds down to specified decimals.'),
+ parameters: [
+ { name: 'number', description: t('Number') },
+ { name: 'decimals', description: t('Decimals') },
+ ],
+ },
+ ROUNDUP: {
+ name: 'ROUNDUP',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Rounds up to specified decimals.'),
+ parameters: [
+ { name: 'number', description: t('Number') },
+ { name: 'decimals', description: t('Decimals') },
+ ],
+ },
+ BUDGET_QUERY: {
+ name: 'BUDGET_QUERY',
+ category: 'query',
+ modes: ['query'],
+ description: t(
+ 'Evaluate a budget query using extracted parameters. Supply dimension, categories, and timeframe explicitly.',
+ ),
+ parameters: [
+ {
+ name: 'dimension',
+ description: t(
+ 'One of: budgeted, spent, balance_start, balance_end, goal (string)',
+ ),
+ },
+ {
+ name: 'categories',
+ description: t(
+ 'Categories result from QUERY_EXTRACT_CATEGORIES() (array)',
+ ),
+ },
+ {
+ name: 'timeframe_start',
+ description: t(
+ 'Start month from QUERY_EXTRACT_TIMEFRAME_START() (string)',
+ ),
+ },
+ {
+ name: 'timeframe_end',
+ description: t(
+ 'End month from QUERY_EXTRACT_TIMEFRAME_END() (string)',
+ ),
+ },
+ ],
+ },
+ QUERY_EXTRACT_CATEGORIES: {
+ name: 'QUERY_EXTRACT_CATEGORIES',
+ category: 'query',
+ modes: ['query'],
+ description: t('Extract category IDs from a named query.'),
+ parameters: [
+ {
+ name: 'queryName',
+ description: t('Name of the saved query (string)'),
+ },
+ ],
+ },
+ QUERY_EXTRACT_TIMEFRAME_START: {
+ name: 'QUERY_EXTRACT_TIMEFRAME_START',
+ category: 'query',
+ modes: ['query'],
+ description: t('Extract the start month from a named query timeframe.'),
+ parameters: [
+ {
+ name: 'queryName',
+ description: t('Name of the saved query (string)'),
+ },
+ ],
+ },
+ QUERY_EXTRACT_TIMEFRAME_END: {
+ name: 'QUERY_EXTRACT_TIMEFRAME_END',
+ category: 'query',
+ modes: ['query'],
+ description: t('Extract the end month from a named query timeframe.'),
+ parameters: [
+ {
+ name: 'queryName',
+ description: t('Name of the saved query (string)'),
+ },
+ ],
+ },
+ FLOOR: {
+ name: 'FLOOR',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Rounds down to nearest multiple of significance.'),
+ parameters: [
+ { name: 'number', description: t('Number') },
+ { name: 'significance', description: t('Significance') },
+ ],
+ },
+ CEILING: {
+ name: 'CEILING',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Rounds up to nearest multiple of significance.'),
+ parameters: [
+ { name: 'number', description: t('Number') },
+ { name: 'significance', description: t('Significance') },
+ ],
+ },
+ POWER: {
+ name: 'POWER',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Returns base raised to the power of exponent.'),
+ parameters: [
+ { name: 'base', description: t('Base') },
+ { name: 'exponent', description: t('Exponent') },
+ ],
+ },
+ SQRT: {
+ name: 'SQRT',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Returns the square root.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ MOD: {
+ name: 'MOD',
+ category: 'math',
+ modes: ['query', 'transaction'],
+ description: t('Returns the remainder of division.'),
+ parameters: [
+ { name: 'dividend', description: t('Dividend') },
+ { name: 'divisor', description: t('Divisor') },
+ ],
+ },
+ PI: {
+ name: 'PI',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the value of PI.'),
+ parameters: [],
+ },
+ SIN: {
+ name: 'SIN',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the sine of an angle.'),
+ parameters: [{ name: 'angle', description: t('Angle') }],
+ },
+ COS: {
+ name: 'COS',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the cosine of an angle.'),
+ parameters: [{ name: 'angle', description: t('Angle') }],
+ },
+ TAN: {
+ name: 'TAN',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the tangent of an angle.'),
+ parameters: [{ name: 'angle', description: t('Angle') }],
+ },
+ LN: {
+ name: 'LN',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the natural logarithm.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ LOG: {
+ name: 'LOG',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the logarithm to specified base.'),
+ parameters: [
+ { name: 'number', description: t('Number') },
+ { name: 'base', description: t('Base') },
+ ],
+ },
+ LOG10: {
+ name: 'LOG10',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the base-10 logarithm.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ EXP: {
+ name: 'EXP',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns e raised to the power of number.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ PRODUCT: {
+ name: 'PRODUCT',
+ category: 'math',
+ modes: ['query'],
+ description: t('Returns the product of all numbers.'),
+ parameters: [{ name: 'numbers', description: t('One or more numbers') }],
+ },
+ IF: {
+ name: 'IF',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Returns one value if condition is TRUE, another if FALSE.',
+ ),
+ parameters: [
+ { name: 'condition', description: t('Condition') },
+ { name: 'value_if_true', description: t('Value to return when true') },
+ {
+ name: 'value_if_false',
+ description: t('Value to return when false'),
+ },
+ ],
+ },
+ IFS: {
+ name: 'IFS',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Checks multiple conditions and returns corresponding values.',
+ ),
+ parameters: [
+ { name: 'condition1', description: t('First condition') },
+ { name: 'value1', description: t('First value') },
+ ],
+ },
+ AND: {
+ name: 'AND',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if all arguments are TRUE.'),
+ parameters: [
+ {
+ name: 'conditions',
+ description: t('One or more conditions'),
+ },
+ ],
+ },
+ OR: {
+ name: 'OR',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if any argument is TRUE.'),
+ parameters: [
+ {
+ name: 'conditions',
+ description: t('One or more conditions'),
+ },
+ ],
+ },
+ XOR: {
+ name: 'XOR',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if odd number of arguments are TRUE.'),
+ parameters: [
+ {
+ name: 'conditions',
+ description: t('One or more conditions'),
+ },
+ ],
+ },
+ NOT: {
+ name: 'NOT',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t('Reverses the logical value.'),
+ parameters: [{ name: 'condition', description: t('Condition') }],
+ },
+ TRUE: {
+ name: 'TRUE',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t('Returns the logical value TRUE.'),
+ parameters: [],
+ },
+ FALSE: {
+ name: 'FALSE',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t('Returns the logical value FALSE.'),
+ parameters: [],
+ },
+ IFERROR: {
+ name: 'IFERROR',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Returns value if no error, otherwise returns alternative.',
+ ),
+ parameters: [
+ { name: 'value', description: t('Value') },
+ {
+ name: 'value_if_error',
+ description: t('Value to return when there is an error'),
+ },
+ ],
+ },
+ IFNA: {
+ name: 'IFNA',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Returns value if not #N/A error, otherwise returns alternative.',
+ ),
+ parameters: [
+ { name: 'value', description: t('Value') },
+ {
+ name: 'value_if_na',
+ description: t('Value to return for #N/A errors'),
+ },
+ ],
+ },
+ SWITCH: {
+ name: 'SWITCH',
+ category: 'logical',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Matches expression against values and returns corresponding result.',
+ ),
+ parameters: [
+ { name: 'expression', description: t('Expression') },
+ { name: 'value1', description: t('First value') },
+ { name: 'result1', description: t('First result') },
+ ],
+ },
+ CONCATENATE: {
+ name: 'CONCATENATE',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Combines several text strings into one.'),
+ parameters: [
+ { name: 'texts', description: t('One or more text values') },
+ ],
+ },
+ INTEGER_TO_AMOUNT: {
+ name: 'INTEGER_TO_AMOUNT',
+ category: 'other',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Converts integer amount to decimal amount (e.g., 1234 -> 12.34).',
+ ),
+ parameters: [
+ { name: 'integer_amount', description: t('Integer amount in cents') },
+ {
+ name: 'decimal_places',
+ description: t('Number of decimal places (default: 2)'),
+ },
+ ],
+ },
+ UPPER: {
+ name: 'UPPER',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Converts text to uppercase.'),
+ parameters: [{ name: 'text', description: t('Text') }],
+ },
+ LOWER: {
+ name: 'LOWER',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Converts text to lowercase.'),
+ parameters: [{ name: 'text', description: t('Text') }],
+ },
+ PROPER: {
+ name: 'PROPER',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Capitalizes first letter of each word.'),
+ parameters: [{ name: 'text', description: t('Text') }],
+ },
+ LEFT: {
+ name: 'LEFT',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Returns leftmost characters from text.'),
+ parameters: [
+ { name: 'text', description: t('Text') },
+ { name: 'num_chars', description: t('Number of characters') },
+ ],
+ },
+ RIGHT: {
+ name: 'RIGHT',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Returns rightmost characters from text.'),
+ parameters: [
+ { name: 'text', description: t('Text') },
+ { name: 'num_chars', description: t('Number of characters') },
+ ],
+ },
+ MID: {
+ name: 'MID',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Returns substring from specified position.'),
+ parameters: [
+ { name: 'text', description: t('Text') },
+ { name: 'start_pos', description: t('Starting position') },
+ { name: 'length', description: t('Length') },
+ ],
+ },
+ LEN: {
+ name: 'LEN',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Returns length of text.'),
+ parameters: [{ name: 'text', description: t('Text') }],
+ },
+ TRIM: {
+ name: 'TRIM',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Removes extra spaces from text.'),
+ parameters: [{ name: 'text', description: t('Text') }],
+ },
+ SUBSTITUTE: {
+ name: 'SUBSTITUTE',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Replaces occurrences of text.'),
+ parameters: [
+ { name: 'text', description: t('Text') },
+ { name: 'old_text', description: t('Text to replace') },
+ { name: 'new_text', description: t('Replacement text') },
+ ],
+ },
+ REPLACE: {
+ name: 'REPLACE',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Replaces substring at specified position.'),
+ parameters: [
+ { name: 'text', description: t('Text') },
+ { name: 'start_pos', description: t('Starting position') },
+ { name: 'length', description: t('Length') },
+ { name: 'new_text', description: t('Replacement text') },
+ ],
+ },
+ FIND: {
+ name: 'FIND',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Finds text within text (case-sensitive).'),
+ parameters: [
+ { name: 'find_text', description: t('Text to find') },
+ { name: 'within_text', description: t('Text to search within') },
+ ],
+ },
+ SEARCH: {
+ name: 'SEARCH',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Finds text within text (case-insensitive, supports wildcards).',
+ ),
+ parameters: [
+ { name: 'search_text', description: t('Text to search for') },
+ { name: 'text', description: t('Text') },
+ ],
+ },
+ TEXT: {
+ name: 'TEXT',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Converts number to text with format.'),
+ parameters: [
+ { name: 'value', description: t('Number') },
+ { name: 'format', description: t('Format') },
+ ],
+ },
+ FIXED: {
+ name: 'FIXED',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Formats a number to a fixed amount of decimal places.'),
+ parameters: [
+ { name: 'number', description: t('Number') },
+ { name: 'decimals', description: t('Decimals') },
+ ],
+ },
+ FORMATNUMBER: {
+ name: 'FORMATNUMBER',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Formats a number with thousands separators. Uses your app number format settings by default.',
+ ),
+ parameters: [
+ { name: 'value', description: t('Number to format') },
+ {
+ name: 'decimals',
+ description: t('Decimal places (optional, uses app settings)'),
+ },
+ {
+ name: 'thousandsSeparator',
+ description: t('Thousands separator (optional, uses app settings)'),
+ },
+ {
+ name: 'decimalSeparator',
+ description: t('Decimal separator (optional, uses app settings)'),
+ },
+ ],
+ },
+ FORMATCURRENCY: {
+ name: 'FORMATCURRENCY',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t(
+ 'Formats a number as currency. Uses your app currency and number format settings by default.',
+ ),
+ parameters: [
+ { name: 'value', description: t('Number to format') },
+ {
+ name: 'currencySymbol',
+ description: t('Currency symbol (optional, uses app settings)'),
+ },
+ {
+ name: 'decimals',
+ description: t('Decimal places (optional, uses app settings)'),
+ },
+ {
+ name: 'thousandsSeparator',
+ description: t('Thousands separator (optional, uses app settings)'),
+ },
+ {
+ name: 'decimalSeparator',
+ description: t('Decimal separator (optional, uses app settings)'),
+ },
+ {
+ name: 'symbolPosition',
+ description: t('"before" or "after" (optional, uses app settings)'),
+ },
+ {
+ name: 'spaceBetweenAmountAndSymbol',
+ description: t('TRUE or FALSE (optional, uses app settings)'),
+ },
+ ],
+ },
+ REPT: {
+ name: 'REPT',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Repeats text specified number of times.'),
+ parameters: [
+ { name: 'text', description: t('Text') },
+ { name: 'number', description: t('Number') },
+ ],
+ },
+ CHAR: {
+ name: 'CHAR',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Converts number to character.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ CODE: {
+ name: 'CODE',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Returns numeric code for first character.'),
+ parameters: [{ name: 'text', description: t('Text') }],
+ },
+ EXACT: {
+ name: 'EXACT',
+ category: 'text',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if texts are exactly the same.'),
+ parameters: [
+ { name: 'text1', description: t('First text value') },
+ { name: 'text2', description: t('Second text value') },
+ ],
+ },
+ DATE: {
+ name: 'DATE',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns date as number of days since null date.'),
+ parameters: [
+ { name: 'year', description: t('Year') },
+ { name: 'month', description: t('Month') },
+ { name: 'day', description: t('Day') },
+ ],
+ },
+ TODAY: {
+ name: 'TODAY',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns current date.'),
+ parameters: [],
+ },
+ NOW: {
+ name: 'NOW',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns current date and time.'),
+ parameters: [],
+ },
+ YEAR: {
+ name: 'YEAR',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns the year from a date.'),
+ parameters: [{ name: 'date', description: t('Date value') }],
+ },
+ MONTH: {
+ name: 'MONTH',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns the month from a date.'),
+ parameters: [{ name: 'date', description: t('Date value') }],
+ },
+ DAY: {
+ name: 'DAY',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns the day from a date.'),
+ parameters: [{ name: 'date', description: t('Date value') }],
+ },
+ WEEKDAY: {
+ name: 'WEEKDAY',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns day of week (1-7).'),
+ parameters: [
+ { name: 'date', description: t('Date') },
+ { name: 'type', description: t('Return type') },
+ ],
+ },
+ EDATE: {
+ name: 'EDATE',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns date shifted by specified months.'),
+ parameters: [
+ { name: 'start_date', description: t('Start date') },
+ { name: 'months', description: t('Months') },
+ ],
+ },
+ EOMONTH: {
+ name: 'EOMONTH',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns last day of month after specified months.'),
+ parameters: [
+ { name: 'start_date', description: t('Start date') },
+ { name: 'months', description: t('Months') },
+ ],
+ },
+ DAYS: {
+ name: 'DAYS',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Calculates difference between dates in days.'),
+ parameters: [
+ { name: 'end_date', description: t('End date') },
+ { name: 'start_date', description: t('Start date') },
+ ],
+ },
+ DATEDIF: {
+ name: 'DATEDIF',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Calculates distance between dates.'),
+ parameters: [
+ { name: 'start_date', description: t('Start date') },
+ { name: 'end_date', description: t('End date') },
+ { name: 'unit', description: t('Unit') },
+ ],
+ },
+ NETWORKDAYS: {
+ name: 'NETWORKDAYS',
+ category: 'date',
+ modes: ['query'],
+ description: t('Returns number of working days between dates.'),
+ parameters: [
+ { name: 'start_date', description: t('Start date') },
+ { name: 'end_date', description: t('End date') },
+ ],
+ },
+ WEEKNUM: {
+ name: 'WEEKNUM',
+ category: 'date',
+ modes: ['query', 'transaction'],
+ description: t('Returns week number of year.'),
+ parameters: [
+ { name: 'date', description: t('Date') },
+ { name: 'type', description: t('Return type') },
+ ],
+ },
+ CHOOSE: {
+ name: 'CHOOSE',
+ category: 'query',
+ modes: ['query'],
+ description: t('Returns value from list based on index.'),
+ parameters: [
+ { name: 'index', description: t('Index (1-based)') },
+ { name: 'value1', description: t('First value') },
+ { name: 'value2', description: t('Additional values') },
+ ],
+ },
+ ISBLANK: {
+ name: 'ISBLANK',
+ category: 'query',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if value is blank.'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ ISERROR: {
+ name: 'ISERROR',
+ category: 'query',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if value is any error.'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ ISNA: {
+ name: 'ISNA',
+ category: 'query',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if value is #N/A error.'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ ISNUMBER: {
+ name: 'ISNUMBER',
+ category: 'query',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if value is a number.'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ ISTEXT: {
+ name: 'ISTEXT',
+ category: 'query',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if value is text.'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ ISLOGICAL: {
+ name: 'ISLOGICAL',
+ category: 'query',
+ modes: ['query', 'transaction'],
+ description: t('Returns TRUE if value is logical (TRUE/FALSE).'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ ISREF: {
+ name: 'ISREF',
+ category: 'other',
+ modes: ['query'],
+ description: t('Returns TRUE if value is a reference.'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ PMT: {
+ name: 'PMT',
+ category: 'math',
+ modes: ['query'],
+ description: t('Calculates payment for a loan.'),
+ parameters: [
+ { name: 'rate', description: t('Interest rate') },
+ { name: 'nper', description: t('Number of periods') },
+ { name: 'pv', description: t('Present value') },
+ ],
+ },
+ FV: {
+ name: 'FV',
+ category: 'math',
+ modes: ['query'],
+ description: t('Calculates future value of investment.'),
+ parameters: [
+ { name: 'rate', description: t('Interest rate') },
+ { name: 'nper', description: t('Number of periods') },
+ { name: 'pmt', description: t('Payment amount') },
+ ],
+ },
+ PV: {
+ name: 'PV',
+ category: 'math',
+ modes: ['query'],
+ description: t('Calculates present value of investment.'),
+ parameters: [
+ { name: 'rate', description: t('Interest rate') },
+ { name: 'nper', description: t('Number of periods') },
+ { name: 'pmt', description: t('Payment amount') },
+ ],
+ },
+ NPV: {
+ name: 'NPV',
+ category: 'math',
+ modes: ['query'],
+ description: t('Calculates net present value.'),
+ parameters: [
+ { name: 'rate', description: t('Interest rate') },
+ { name: 'value1', description: t('First value') },
+ { name: 'value2', description: t('Second value') },
+ ],
+ },
+ IRR: {
+ name: 'IRR',
+ category: 'math',
+ modes: ['query'],
+ description: t('Calculates internal rate of return.'),
+ parameters: [{ name: 'values', description: t('Values') }],
+ },
+ RATE: {
+ name: 'RATE',
+ category: 'math',
+ modes: ['query'],
+ description: t('Calculates interest rate per period.'),
+ parameters: [
+ { name: 'nper', description: t('Number of periods') },
+ { name: 'pmt', description: t('Payment amount') },
+ { name: 'pv', description: t('Present value') },
+ ],
+ },
+ QUERY: {
+ name: 'QUERY',
+ category: 'query',
+ modes: ['query'],
+ description: t('Execute a query and return the result.'),
+ parameters: [
+ { name: 'queryName', description: t('Name of the query to execute') },
+ ],
+ },
+ QUERY_COUNT: {
+ name: 'QUERY_COUNT',
+ category: 'query',
+ modes: ['query'],
+ description: t('Execute a query and return the number of matching rows.'),
+ parameters: [
+ { name: 'queryName', description: t('Name of the query to execute') },
+ ],
+ },
+ BALANCE_OF: {
+ name: 'BALANCE_OF',
+ category: 'other',
+ modes: ['transaction'],
+ description: t(
+ 'Running balance for another account (cents) at this transaction, same cutoff as balance. Use a quoted account id for a deterministic match, or a quoted account name. Use the balance variable instead for the current account.',
+ ),
+ parameters: [
+ {
+ name: 'account_id_or_name',
+ description: t('Quoted account id or exact account name'),
+ },
+ ],
+ },
+ CLEAN: {
+ name: 'CLEAN',
+ category: 'text',
+ modes: ['transaction'],
+ description: t('Removes non-printable characters from text.'),
+ parameters: [{ name: 'text', description: t('Text') }],
+ },
+ SPLIT: {
+ name: 'SPLIT',
+ category: 'text',
+ modes: ['transaction'],
+ description: t('Splits text by space and returns part at index.'),
+ parameters: [
+ { name: 'text', description: t('Text') },
+ { name: 'index', description: t('Index') },
+ ],
+ },
+ INT: {
+ name: 'INT',
+ category: 'math',
+ modes: ['transaction'],
+ description: t('Rounds down to nearest integer.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ TRUNC: {
+ name: 'TRUNC',
+ category: 'math',
+ modes: ['transaction'],
+ description: t('Truncates number to specified decimals.'),
+ parameters: [
+ { name: 'number', description: t('Number') },
+ { name: 'decimals', description: t('Decimals') },
+ ],
+ },
+ SIGN: {
+ name: 'SIGN',
+ category: 'math',
+ modes: ['transaction'],
+ description: t('Returns -1 for negative, 0 for zero, 1 for positive.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ DATEVALUE: {
+ name: 'DATEVALUE',
+ category: 'date',
+ modes: ['transaction'],
+ description: t('Parses a date string and returns it as a number.'),
+ parameters: [{ name: 'date_string', description: t('Date string') }],
+ },
+ ISOWEEKNUM: {
+ name: 'ISOWEEKNUM',
+ category: 'date',
+ modes: ['transaction'],
+ description: t('Returns ISO week number.'),
+ parameters: [{ name: 'date', description: t('Date') }],
+ },
+ ISEVEN: {
+ name: 'ISEVEN',
+ category: 'query',
+ modes: ['transaction'],
+ description: t('Returns TRUE if number is even.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ ISODD: {
+ name: 'ISODD',
+ category: 'query',
+ modes: ['transaction'],
+ description: t('Returns TRUE if number is odd.'),
+ parameters: [{ name: 'number', description: t('Number') }],
+ },
+ VALUE: {
+ name: 'VALUE',
+ category: 'text',
+ modes: ['transaction'],
+ description: t('Converts text to a number.'),
+ parameters: [{ name: 'text', description: t('Text') }],
+ },
+ T: {
+ name: 'T',
+ category: 'text',
+ modes: ['transaction'],
+ description: t('Returns text if value is text, empty string otherwise.'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ N: {
+ name: 'N',
+ category: 'text',
+ modes: ['transaction'],
+ description: t('Converts value to a number.'),
+ parameters: [{ name: 'value', description: t('Value') }],
+ },
+ };
+}
+
+function getCompletionSectionName(completion: Completion): string {
+ const { section } = completion;
+ return typeof section === 'string' ? section : section?.name || '';
+}
+
+let formulaFunctionCategoryByName: Record<
+ string,
+ FormulaFunctionCategory
+> | null = null;
+
+function getFormulaFunctionCategoryByName(): Record<
+ string,
+ FormulaFunctionCategory
+> {
+ formulaFunctionCategoryByName ??= Object.fromEntries(
+ Object.entries(getFormulaFunctionCatalog()).map(([name, func]) => [
+ name,
+ func.category,
+ ]),
+ );
+
+ return formulaFunctionCategoryByName;
+}
+
+export function getFormulaFunctionsByMode(): Record<FormulaMode, string[]> {
+ const functionsByMode: Record<FormulaMode, string[]> = {
+ query: [],
+ transaction: [],
+ };
+
+ for (const [name, func] of Object.entries(getFormulaFunctionCatalog())) {
+ for (const mode of func.modes) {
+ functionsByMode[mode].push(name);
+ }
+ }
+
+ return functionsByMode;
+}
+
+export function getFormulaFunctionsForMode(
+ mode: FormulaMode,
+): Record<string, FormulaFunctionDef> {
+ const catalog = getFormulaFunctionCatalog();
+
+ return Object.fromEntries(
+ Object.entries(catalog).filter(([, func]) => func.modes.includes(mode)),
+ );
+}
+
+export function getFormulaFunctionByName(
+ name: string,
+ mode?: FormulaMode,
+): FormulaFunctionDef | undefined {
+ const upperName = name.toUpperCase();
+ const func = getFormulaFunctionCatalog()[upperName];
+
+ if (!func || (mode && !func.modes.includes(mode))) {
+ return undefined;
+ }
+
+ return func;
+}
+
+export function getFormulaCategoryForName(
+ name: string,
+): FormulaFunctionCategory | undefined {
+ return getFormulaFunctionCategoryByName()[name.toUpperCase()];
+}
+
+export function getFunctionCompletions(mode: FormulaMode): Completion[] {
+ const categoryConfig = getFormulaFunctionCategoryConfig();
+
+ return Object.entries(getFormulaFunctionsForMode(mode)).map(
+ ([name, func]) => ({
+ label: name,
+ type: 'function',
+ section: categoryConfig[func.category].section,
+ info: [
+ func.description,
+ '',
+ `${t('Parameters:')} ${func.parameters.map(p => p.name).join(', ')}`,
+ '',
+ func.parameters.map(p => `- ${p.name}: ${p.description}`).join('\n'),
+ ].join('\n'),
+ apply: `${name}()`,
+ boost: 10,
+ }),
+ );
+}
+
+export function getRuleFieldCompletions(): Completion[] {
+ const ruleFieldSection = getRuleFieldCompletionSection();
+
+ return [
+ {
+ label: 'amount',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Transaction amount in cents. Use for calculations and comparisons.\n\nExample: =amount / 100 to get dollar value',
+ ),
+ },
+ {
+ label: 'date',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Transaction date in YYYY-MM-DD format. Use with date functions.\n\nExample: =TEXT(date, "MMMM") to get month name',
+ ),
+ },
+ {
+ label: 'notes',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Transaction notes/memo text. Use for string operations.\n\nExample: =UPPER(notes) to convert to uppercase',
+ ),
+ },
+ {
+ label: 'imported_payee',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Original imported payee name from bank import. Contains the raw text before matching.\n\nExample: =LEFT(imported_payee, 10) to get first 10 characters',
+ ),
+ },
+ {
+ label: 'payee',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Payee ID (string). The ID of the payee.\n\nExample: =CONCATENATE("Payment to ", payee)',
+ ),
+ },
+ {
+ label: 'payee_name',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Payee name (string). The human-readable name of the payee.\n\nExample: =UPPER(payee_name) or =CONCATENATE("Payment to ", payee_name)',
+ ),
+ },
+ {
+ label: 'account',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Account ID (string). The ID of the account.\n\nExample: =CONCATENATE("Paid from ", account)',
+ ),
+ },
+ {
+ label: 'account_name',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Account name (string). The human-readable name of the account.\n\nExample: =CONCATENATE("Paid from ", account_name)',
+ ),
+ },
+ {
+ label: 'category',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Category ID (string). The ID of the category.\n\nExample: =IF(category="Groceries", "Food", "Other")',
+ ),
+ },
+ {
+ label: 'category_name',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Category Name (string). The human-readable name of the category.\n\nExample: =IF(category_name="Groceries", "Food", "Other")',
+ ),
+ },
+ {
+ label: 'cleared',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Boolean cleared status. TRUE if transaction is cleared, FALSE otherwise.\n\nExample: =IF(cleared, "Cleared", "Pending")',
+ ),
+ },
+ {
+ label: 'reconciled',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Boolean reconciled status. TRUE if transaction is reconciled, FALSE otherwise.',
+ ),
+ },
+ {
+ label: 'balance',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'Account balance as of the date of the transaction, excluding the transaction amount. Use for calculations and comparisons.\n\nExample: =IF(balance < 0, "Negative Balance", "Positive Balance")',
+ ),
+ },
+ {
+ label: 'parent_amount',
+ type: 'variable',
+ section: ruleFieldSection,
+ boost: 5,
+ info: t(
+ 'The amount of the parent transaction in cents in split transactions.\n\nExample: =(parent_amount / 100) * .05',
+ ),
+ },
+ ];
+}
+
+export function getDynamicReportQueryCompletions(
+ queries?: Record<string, unknown>,
+): Completion[] {
+ if (!queries) {
+ return [];
+ }
+
+ const queryFunctionSection = getFormulaFunctionCategoryConfig().query.section;
+
+ return Object.keys(queries).flatMap(queryName => [
+ {
+ label: `QUERY("${queryName}")`,
+ type: 'function',
+ section: queryFunctionSection,
+ info: t('Execute the {{queryName}} query and return the result.', {
+ queryName,
+ }),
+ apply: `QUERY("${queryName}")`,
+ boost: 15,
+ },
+ {
+ label: `QUERY_COUNT("${queryName}")`,
+ type: 'function',
+ section: queryFunctionSection,
+ info: t(
+ 'Execute the {{queryName}} query and return the number of matching rows.',
+ {
+ queryName,
+ },
+ ),
+ apply: `QUERY_COUNT("${queryName}")`,
+ boost: 14,
+ },
+ {
+ label: `BUDGET_QUERY("budgeted", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
+ type: 'function',
+ section: queryFunctionSection,
+ info: t(
+ 'Sum of budgeted amounts with extracted parameters from {{queryName}}.',
+ { queryName },
+ ),
+ apply: `BUDGET_QUERY("budgeted", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
+ boost: 13,
+ },
+ {
+ label: `BUDGET_QUERY("spent", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
+ type: 'function',
+ section: queryFunctionSection,
+ info: t('Sum of spending with extracted parameters from {{queryName}}.', {
+ queryName,
+ }),
+ apply: `BUDGET_QUERY("spent", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
+ boost: 13,
+ },
+ {
+ label: `BUDGET_QUERY("balance_start", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
+ type: 'function',
+ section: queryFunctionSection,
+ info: t('Opening balance with extracted parameters from {{queryName}}.', {
+ queryName,
+ }),
+ apply: `BUDGET_QUERY("balance_start", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
+ boost: 13,
+ },
+ {
+ label: `BUDGET_QUERY("balance_end", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
+ type: 'function',
+ section: queryFunctionSection,
+ info: t('Closing balance with extracted parameters from {{queryName}}.', {
+ queryName,
+ }),
+ apply: `BUDGET_QUERY("balance_end", QUERY_EXTRACT_CATEGORIES("${queryName}"), QUERY_EXTRACT_TIMEFRAME_START("${queryName}"), QUERY_EXTRACT_TIMEFRAME_END("${queryName}"))`,
+ boost: 13,
+ },
+ ]);
+}
+
+export function getNamedVariableCompletions(
+ variables?: Record<string, number | string>,
+): Completion[] {
+ if (!variables) {
+ return [];
+ }
+
+ const variableSection = getVariableCompletionSection();
+
+ return Object.entries(variables).map(([varName, value]) => ({
+ label: varName,
+ type: 'variable',
+ section: variableSection,
+ info: t('Variable with value: {{value}}', {
+ value: String(value),
+ }),
+ boost: 20,
+ }));
+}
+
+export function sortFormulaCompletions(
+ completions: Completion[],
+): Completion[] {
+ const sectionOrder = getFormulaCompletionSectionOrder();
+
+ return [...completions].sort((a, b) => {
+ const sectionA = getCompletionSectionName(a);
+ const sectionB = getCompletionSectionName(b);
+ const orderA = sectionOrder[sectionA] ?? 999;
+ const orderB = sectionOrder[sectionB] ?? 999;
+
+ if (orderA !== orderB) {
+ return orderA - orderB;
+ }
+
+ const boostA = a.boost || 0;
+ const boostB = b.boost || 0;
+ if (boostA !== boostB) {
+ return boostB - boostA;
+ }
+
+ return a.label.localeCompare(b.label);
+ });
+}
diff --git a/packages/desktop-client/src/components/formula/queryModeFunctions.ts b/packages/desktop-client/src/components/formula/queryModeFunctions.ts
deleted file mode 100644
index 37e5463de8..0000000000
--- a/packages/desktop-client/src/components/formula/queryModeFunctions.ts
+++ /dev/null
@@ -1,708 +0,0 @@
-import { t } from 'i18next';
-
-export type FunctionDef = {
- name: string;
- description: string;
- parameters: Array<{ name: string; description: string }>;
-};
-
-// Excel formula functions for CodeMirror (Query Mode) - Complete set
-export const queryModeFunctions: Record<string, FunctionDef> = {
- // Math and Aggregation Functions
- SUM: {
- name: 'SUM',
- description: t('Returns the sum of all numbers in a range.'),
- parameters: [
- { name: 'numbers', description: 'Number1, Number2, ...NumberN' },
- ],
- },
- AVERAGE: {
- name: 'AVERAGE',
- description: t('Returns the average of all numbers in a range.'),
- parameters: [
- { name: 'numbers', description: 'Number1, Number2, ...NumberN' },
- ],
- },
- MAX: {
- name: 'MAX',
- description: t('Returns the maximum value from numbers.'),
- parameters: [
- { name: 'numbers', description: 'Number1, Number2, ...NumberN' },
- ],
- },
- MIN: {
- name: 'MIN',
- description: t('Returns the minimum value from numbers.'),
- parameters: [
- { name: 'numbers', description: 'Number1, Number2, ...NumberN' },
- ],
- },
- ABS: {
- name: 'ABS',
- description: t('Returns the absolute value of a number.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- ROUND: {
- name: 'ROUND',
- description: t('Rounds a number to specified decimals.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- ROUNDDOWN: {
- name: 'ROUNDDOWN',
- description: t('Rounds down to specified decimals.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- ROUNDUP: {
- name: 'ROUNDUP',
- description: t('Rounds up to specified decimals.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- BUDGET_QUERY: {
- name: 'BUDGET_QUERY',
- description: t(
- 'Evaluate a budget query using extracted parameters. Supply dimension, categories, and timeframe explicitly.',
- ),
- parameters: [
- {
- name: 'dimension',
- description:
- 'One of: budgeted, spent, balance_start, balance_end, goal (string)',
- },
- {
- name: 'categories',
- description:
- 'Categories result from QUERY_EXTRACT_CATEGORIES() (array)',
- },
- {
- name: 'timeframe_start',
- description:
- 'Start month from QUERY_EXTRACT_TIMEFRAME_START() (string)',
- },
- {
- name: 'timeframe_end',
- description: 'End month from QUERY_EXTRACT_TIMEFRAME_END() (string)',
- },
- ],
- },
- QUERY_EXTRACT_CATEGORIES: {
- name: 'QUERY_EXTRACT_CATEGORIES',
- description: t('Extract category IDs from a named query.'),
- parameters: [
- { name: 'queryName', description: 'Name of the saved query (string)' },
- ],
- },
- QUERY_EXTRACT_TIMEFRAME_START: {
- name: 'QUERY_EXTRACT_TIMEFRAME_START',
- description: t('Extract the start month from a named query timeframe.'),
- parameters: [
- { name: 'queryName', description: 'Name of the saved query (string)' },
- ],
- },
- QUERY_EXTRACT_TIMEFRAME_END: {
- name: 'QUERY_EXTRACT_TIMEFRAME_END',
- description: t('Extract the end month from a named query timeframe.'),
- parameters: [
- { name: 'queryName', description: 'Name of the saved query (string)' },
- ],
- },
- FLOOR: {
- name: 'FLOOR',
- description: t('Rounds down to nearest multiple of significance.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'significance', description: 'Significance' },
- ],
- },
- CEILING: {
- name: 'CEILING',
- description: t('Rounds up to nearest multiple of significance.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'significance', description: 'Significance' },
- ],
- },
- POWER: {
- name: 'POWER',
- description: t('Returns base raised to the power of exponent.'),
- parameters: [
- { name: 'base', description: 'Base' },
- { name: 'exponent', description: 'Exponent' },
- ],
- },
- SQRT: {
- name: 'SQRT',
- description: t('Returns the square root.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- MOD: {
- name: 'MOD',
- description: t('Returns the remainder of division.'),
- parameters: [
- { name: 'dividend', description: 'Dividend' },
- { name: 'divisor', description: 'Divisor' },
- ],
- },
- PI: {
- name: 'PI',
- description: t('Returns the value of PI.'),
- parameters: [],
- },
- SIN: {
- name: 'SIN',
- description: t('Returns the sine of an angle.'),
- parameters: [{ name: 'angle', description: 'Angle' }],
- },
- COS: {
- name: 'COS',
- description: t('Returns the cosine of an angle.'),
- parameters: [{ name: 'angle', description: 'Angle' }],
- },
- TAN: {
- name: 'TAN',
- description: t('Returns the tangent of an angle.'),
- parameters: [{ name: 'angle', description: 'Angle' }],
- },
- LN: {
- name: 'LN',
- description: t('Returns the natural logarithm.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- LOG: {
- name: 'LOG',
- description: t('Returns the logarithm to specified base.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'base', description: 'Base' },
- ],
- },
- LOG10: {
- name: 'LOG10',
- description: t('Returns the base-10 logarithm.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- EXP: {
- name: 'EXP',
- description: t('Returns e raised to the power of number.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- PRODUCT: {
- name: 'PRODUCT',
- description: t('Returns the product of all numbers.'),
- parameters: [
- { name: 'numbers', description: 'Number1, Number2, ...NumberN' },
- ],
- },
- // Logical Functions
- IF: {
- name: 'IF',
- description: t('Returns one value if condition is TRUE, another if FALSE.'),
- parameters: [
- { name: 'condition', description: 'Condition' },
- { name: 'value_if_true', description: 'ValueIfTrue' },
- { name: 'value_if_false', description: 'ValueIfFalse' },
- ],
- },
- IFS: {
- name: 'IFS',
- description: t(
- 'Checks multiple conditions and returns corresponding values.',
- ),
- parameters: [
- { name: 'condition1', description: 'Condition1' },
- { name: 'value1', description: 'Value1' },
- ],
- },
- AND: {
- name: 'AND',
- description: t('Returns TRUE if all arguments are TRUE.'),
- parameters: [
- {
- name: 'conditions',
- description: 'Condition1, Condition2, ...ConditionN',
- },
- ],
- },
- OR: {
- name: 'OR',
- description: t('Returns TRUE if any argument is TRUE.'),
- parameters: [
- {
- name: 'conditions',
- description: 'Condition1, Condition2, ...ConditionN',
- },
- ],
- },
- XOR: {
- name: 'XOR',
- description: t('Returns TRUE if odd number of arguments are TRUE.'),
- parameters: [
- {
- name: 'conditions',
- description: 'Condition1, Condition2, ...ConditionN',
- },
- ],
- },
- NOT: {
- name: 'NOT',
- description: t('Reverses the logical value.'),
- parameters: [{ name: 'condition', description: 'Condition' }],
- },
- TRUE: {
- name: 'TRUE',
- description: t('Returns the logical value TRUE.'),
- parameters: [],
- },
- FALSE: {
- name: 'FALSE',
- description: t('Returns the logical value FALSE.'),
- parameters: [],
- },
- IFERROR: {
- name: 'IFERROR',
- description: t('Returns value if no error, otherwise returns alternative.'),
- parameters: [
- { name: 'value', description: 'Value' },
- { name: 'value_if_error', description: 'ValueIfError' },
- ],
- },
- IFNA: {
- name: 'IFNA',
- description: t(
- 'Returns value if not #N/A error, otherwise returns alternative.',
- ),
- parameters: [
- { name: 'value', description: 'Value' },
- { name: 'value_if_na', description: 'ValueIfNA' },
- ],
- },
- SWITCH: {
- name: 'SWITCH',
- description: t(
- 'Matches expression against values and returns corresponding result.',
- ),
- parameters: [
- { name: 'expression', description: 'Expression' },
- { name: 'value1', description: 'Value1' },
- { name: 'result1', description: 'Result1' },
- ],
- },
-
- // Text Functions
- CONCATENATE: {
- name: 'CONCATENATE',
- description: t('Combines several text strings into one.'),
- parameters: [{ name: 'texts', description: 'Text1, Text2, ...TextN' }],
- },
- INTEGER_TO_AMOUNT: {
- name: 'INTEGER_TO_AMOUNT',
- description: t(
- 'Converts integer amount to decimal amount (e.g., 1234 -> 12.34).',
- ),
- parameters: [
- { name: 'integer_amount', description: 'Integer amount in cents' },
- {
- name: 'decimal_places',
- description: 'Number of decimal places (default: 2)',
- },
- ],
- },
- UPPER: {
- name: 'UPPER',
- description: t('Converts text to uppercase.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- LOWER: {
- name: 'LOWER',
- description: t('Converts text to lowercase.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- PROPER: {
- name: 'PROPER',
- description: t('Capitalizes first letter of each word.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- LEFT: {
- name: 'LEFT',
- description: t('Returns leftmost characters from text.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'num_chars', description: 'Number' },
- ],
- },
- RIGHT: {
- name: 'RIGHT',
- description: t('Returns rightmost characters from text.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'num_chars', description: 'Number' },
- ],
- },
- MID: {
- name: 'MID',
- description: t('Returns substring from specified position.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'start_pos', description: 'Start_position' },
- { name: 'length', description: 'Length' },
- ],
- },
- LEN: {
- name: 'LEN',
- description: t('Returns length of text.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- TRIM: {
- name: 'TRIM',
- description: t('Removes extra spaces from text.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- SUBSTITUTE: {
- name: 'SUBSTITUTE',
- description: t('Replaces occurrences of text.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'old_text', description: 'Old_text' },
- { name: 'new_text', description: 'New_text' },
- ],
- },
- REPLACE: {
- name: 'REPLACE',
- description: t('Replaces substring at specified position.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'start_pos', description: 'Start_position' },
- { name: 'length', description: 'Length' },
- { name: 'new_text', description: 'New_text' },
- ],
- },
- FIND: {
- name: 'FIND',
- description: t('Finds text within text (case-sensitive).'),
- parameters: [
- { name: 'find_text', description: 'Text1' },
- { name: 'within_text', description: 'Text2' },
- ],
- },
- SEARCH: {
- name: 'SEARCH',
- description: t(
- 'Finds text within text (case-insensitive, supports wildcards).',
- ),
- parameters: [
- { name: 'search_text', description: 'Search_string' },
- { name: 'text', description: 'Text' },
- ],
- },
- TEXT: {
- name: 'TEXT',
- description: t('Converts number to text with format.'),
- parameters: [
- { name: 'value', description: 'Number' },
- { name: 'format', description: 'Format' },
- ],
- },
- FIXED: {
- name: 'FIXED',
- description: t('Formats a number to a fixed amount of decimal places.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- FORMATNUMBER: {
- name: 'FORMATNUMBER',
- description: t(
- 'Formats a number with thousands separators. Uses your app number format settings by default.',
- ),
- parameters: [
- { name: 'value', description: 'Number to format' },
- {
- name: 'decimals',
- description: 'Decimal places (optional, uses app settings)',
- },
- {
- name: 'thousandsSeparator',
- description: 'Thousands separator (optional, uses app settings)',
- },
- {
- name: 'decimalSeparator',
- description: 'Decimal separator (optional, uses app settings)',
- },
- ],
- },
- FORMATCURRENCY: {
- name: 'FORMATCURRENCY',
- description: t(
- 'Formats a number as currency. Uses your app currency and number format settings by default.',
- ),
- parameters: [
- { name: 'value', description: 'Number to format' },
- {
- name: 'currencySymbol',
- description: 'Currency symbol (optional, uses app settings)',
- },
- {
- name: 'decimals',
- description: 'Decimal places (optional, uses app settings)',
- },
- {
- name: 'thousandsSeparator',
- description: 'Thousands separator (optional, uses app settings)',
- },
- {
- name: 'decimalSeparator',
- description: 'Decimal separator (optional, uses app settings)',
- },
- {
- name: 'symbolPosition',
- description: '"before" or "after" (optional, uses app settings)',
- },
- {
- name: 'spaceBetweenAmountAndSymbol',
- description: 'TRUE or FALSE (optional, uses app settings)',
- },
- ],
- },
- REPT: {
- name: 'REPT',
- description: t('Repeats text specified number of times.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'number', description: 'Number' },
- ],
- },
- CHAR: {
- name: 'CHAR',
- description: t('Converts number to character.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- CODE: {
- name: 'CODE',
- description: t('Returns numeric code for first character.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- EXACT: {
- name: 'EXACT',
- description: t('Returns TRUE if texts are exactly the same.'),
- parameters: [
- { name: 'text1', description: 'Text' },
- { name: 'text2', description: 'Text' },
- ],
- },
-
- // Date and Time Functions
- DATE: {
- name: 'DATE',
- description: t('Returns date as number of days since null date.'),
- parameters: [
- { name: 'year', description: 'Year' },
- { name: 'month', description: 'Month' },
- { name: 'day', description: 'Day' },
- ],
- },
- TODAY: {
- name: 'TODAY',
- description: t('Returns current date.'),
- parameters: [],
- },
- NOW: {
- name: 'NOW',
- description: t('Returns current date and time.'),
- parameters: [],
- },
- YEAR: {
- name: 'YEAR',
- description: t('Returns the year from a date.'),
- parameters: [{ name: 'date', description: 'Number' }],
- },
- MONTH: {
- name: 'MONTH',
- description: t('Returns the month from a date.'),
- parameters: [{ name: 'date', description: 'Number' }],
- },
- DAY: {
- name: 'DAY',
- description: t('Returns the day from a date.'),
- parameters: [{ name: 'date', description: 'Number' }],
- },
- WEEKDAY: {
- name: 'WEEKDAY',
- description: t('Returns day of week (1-7).'),
- parameters: [
- { name: 'date', description: 'Date' },
- { name: 'type', description: 'Type' },
- ],
- },
- EDATE: {
- name: 'EDATE',
- description: t('Returns date shifted by specified months.'),
- parameters: [
- { name: 'start_date', description: 'Startdate' },
- { name: 'months', description: 'Months' },
- ],
- },
- EOMONTH: {
- name: 'EOMONTH',
- description: t('Returns last day of month after specified months.'),
- parameters: [
- { name: 'start_date', description: 'Startdate' },
- { name: 'months', description: 'Months' },
- ],
- },
- DAYS: {
- name: 'DAYS',
- description: t('Calculates difference between dates in days.'),
- parameters: [
- { name: 'end_date', description: 'Date2' },
- { name: 'start_date', description: 'Date1' },
- ],
- },
- DATEDIF: {
- name: 'DATEDIF',
- description: t('Calculates distance between dates.'),
- parameters: [
- { name: 'start_date', description: 'Date1' },
- { name: 'end_date', description: 'Date2' },
- { name: 'unit', description: 'Unit' },
- ],
- },
- NETWORKDAYS: {
- name: 'NETWORKDAYS',
- description: t('Returns number of working days between dates.'),
- parameters: [
- { name: 'start_date', description: 'Date1' },
- { name: 'end_date', description: 'Date2' },
- ],
- },
- WEEKNUM: {
- name: 'WEEKNUM',
- description: t('Returns week number of year.'),
- parameters: [
- { name: 'date', description: 'Date' },
- { name: 'type', description: 'Type' },
- ],
- },
- CHOOSE: {
- name: 'CHOOSE',
- description: t('Returns value from list based on index.'),
- parameters: [
- { name: 'index', description: 'Index (1-based)' },
- { name: 'value1', description: 'Value1' },
- { name: 'value2', description: 'Value2, ...ValueN' },
- ],
- },
-
- // Information Functions
- ISBLANK: {
- name: 'ISBLANK',
- description: t('Returns TRUE if value is blank.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISERROR: {
- name: 'ISERROR',
- description: t('Returns TRUE if value is any error.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISNA: {
- name: 'ISNA',
- description: t('Returns TRUE if value is #N/A error.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISNUMBER: {
- name: 'ISNUMBER',
- description: t('Returns TRUE if value is a number.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISTEXT: {
- name: 'ISTEXT',
- description: t('Returns TRUE if value is text.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISLOGICAL: {
- name: 'ISLOGICAL',
- description: t('Returns TRUE if value is logical (TRUE/FALSE).'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISREF: {
- name: 'ISREF',
- description: t('Returns TRUE if value is a reference.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
-
- // Financial Functions
- PMT: {
- name: 'PMT',
- description: t('Calculates payment for a loan.'),
- parameters: [
- { name: 'rate', description: 'Rate' },
- { name: 'nper', description: 'Nper' },
- { name: 'pv', description: 'PV' },
- ],
- },
- FV: {
- name: 'FV',
- description: t('Calculates future value of investment.'),
- parameters: [
- { name: 'rate', description: 'Rate' },
- { name: 'nper', description: 'Nper' },
- { name: 'pmt', description: 'PMT' },
- ],
- },
- PV: {
- name: 'PV',
- description: t('Calculates present value of investment.'),
- parameters: [
- { name: 'rate', description: 'Rate' },
- { name: 'nper', description: 'Nper' },
- { name: 'pmt', description: 'PMT' },
- ],
- },
- NPV: {
- name: 'NPV',
- description: t('Calculates net present value.'),
- parameters: [
- { name: 'rate', description: 'Rate' },
- { name: 'value1', description: 'Value1' },
- { name: 'value2', description: 'Value2' },
- ],
- },
- IRR: {
- name: 'IRR',
- description: t('Calculates internal rate of return.'),
- parameters: [{ name: 'values', description: 'Values' }],
- },
- RATE: {
- name: 'RATE',
- description: t('Calculates interest rate per period.'),
- parameters: [
- { name: 'nper', description: 'Nper' },
- { name: 'pmt', description: 'PMT' },
- { name: 'pv', description: 'PV' },
- ],
- },
-
- // Query-specific
- QUERY: {
- name: 'QUERY',
- description: t('Execute a query and return the result.'),
- parameters: [
- { name: 'queryName', description: 'Name of the query to execute' },
- ],
- },
- QUERY_COUNT: {
- name: 'QUERY_COUNT',
- description: t('Execute a query and return the number of matching rows.'),
- parameters: [
- { name: 'queryName', description: 'Name of the query to execute' },
- ],
- },
-};
diff --git a/packages/desktop-client/src/components/formula/transactionModeFunctions.ts b/packages/desktop-client/src/components/formula/transactionModeFunctions.ts
deleted file mode 100644
index a094e14a22..0000000000
--- a/packages/desktop-client/src/components/formula/transactionModeFunctions.ts
+++ /dev/null
@@ -1,580 +0,0 @@
-import { t } from 'i18next';
-
-export type FunctionDef = {
- name: string;
- description: string;
- parameters: Array<{ name: string; description: string }>;
-};
-
-// Excel formula functions for CodeMirror (Transaction Mode) - Complete set
-export const transactionModeFunctions: Record<string, FunctionDef> = {
- // Text Functions (most useful for transaction fields)
- CONCATENATE: {
- name: 'CONCATENATE',
- description: t('Combines several text strings into one.'),
- parameters: [{ name: 'texts', description: 'Text1, Text2, ...TextN' }],
- },
- UPPER: {
- name: 'UPPER',
- description: t('Converts text to uppercase.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- LOWER: {
- name: 'LOWER',
- description: t('Converts text to lowercase.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- PROPER: {
- name: 'PROPER',
- description: t('Capitalizes first letter of each word.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- LEFT: {
- name: 'LEFT',
- description: t('Returns leftmost characters from text.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'num_chars', description: 'Number' },
- ],
- },
- RIGHT: {
- name: 'RIGHT',
- description: t('Returns rightmost characters from text.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'num_chars', description: 'Number' },
- ],
- },
- INTEGER_TO_AMOUNT: {
- name: 'INTEGER_TO_AMOUNT',
- description: t(
- 'Converts integer amount to decimal amount (e.g., 1234 -> 12.34).',
- ),
- parameters: [
- { name: 'integer_amount', description: 'Integer amount in cents' },
- {
- name: 'decimal_places',
- description: 'Number of decimal places (default: 2)',
- },
- ],
- },
- BALANCE_OF: {
- name: 'BALANCE_OF',
- description: t(
- 'Running balance for another account (cents) at this transaction, same cutoff as balance. Use a quoted account id for a deterministic match, or a quoted account name. Use the balance variable instead for the current account.',
- ),
- parameters: [
- {
- name: 'account_id_or_name',
- description: t('Quoted account id or exact account name'),
- },
- ],
- },
- MID: {
- name: 'MID',
- description: t('Returns substring from specified position.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'start_pos', description: 'Start_position' },
- { name: 'length', description: 'Length' },
- ],
- },
- LEN: {
- name: 'LEN',
- description: t('Returns length of text.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- TRIM: {
- name: 'TRIM',
- description: t('Removes extra spaces from text.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- SUBSTITUTE: {
- name: 'SUBSTITUTE',
- description: t('Replaces occurrences of text.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'old_text', description: 'Old_text' },
- { name: 'new_text', description: 'New_text' },
- ],
- },
- REPLACE: {
- name: 'REPLACE',
- description: t('Replaces substring at specified position.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'start_pos', description: 'Start_position' },
- { name: 'length', description: 'Length' },
- { name: 'new_text', description: 'New_text' },
- ],
- },
- FIND: {
- name: 'FIND',
- description: t('Finds text within text (case-sensitive).'),
- parameters: [
- { name: 'find_text', description: 'Text1' },
- { name: 'within_text', description: 'Text2' },
- ],
- },
- SEARCH: {
- name: 'SEARCH',
- description: t(
- 'Finds text within text (case-insensitive, supports wildcards).',
- ),
- parameters: [
- { name: 'search_text', description: 'Search_string' },
- { name: 'text', description: 'Text' },
- ],
- },
- TEXT: {
- name: 'TEXT',
- description: t('Converts number to text with format.'),
- parameters: [
- { name: 'value', description: 'Number' },
- { name: 'format', description: 'Format' },
- ],
- },
- FIXED: {
- name: 'FIXED',
- description: t('Formats a number to a fixed amount of decimal places.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- FORMATNUMBER: {
- name: 'FORMATNUMBER',
- description: t(
- 'Formats a number with thousands separators. Uses your app number format settings by default.',
- ),
- parameters: [
- { name: 'value', description: 'Number to format' },
- {
- name: 'decimals',
- description: 'Decimal places (optional, uses app settings)',
- },
- {
- name: 'thousandsSeparator',
- description: 'Thousands separator (optional, uses app settings)',
- },
- {
- name: 'decimalSeparator',
- description: 'Decimal separator (optional, uses app settings)',
- },
- ],
- },
- FORMATCURRENCY: {
- name: 'FORMATCURRENCY',
- description: t(
- 'Formats a number as currency. Uses your app currency and number format settings by default.',
- ),
- parameters: [
- { name: 'value', description: 'Number to format' },
- {
- name: 'currencySymbol',
- description: 'Currency symbol (optional, uses app settings)',
- },
- {
- name: 'decimals',
- description: 'Decimal places (optional, uses app settings)',
- },
- {
- name: 'thousandsSeparator',
- description: 'Thousands separator (optional, uses app settings)',
- },
- {
- name: 'decimalSeparator',
- description: 'Decimal separator (optional, uses app settings)',
- },
- {
- name: 'symbolPosition',
- description: '"before" or "after" (optional, uses app settings)',
- },
- {
- name: 'spaceBetweenAmountAndSymbol',
- description: 'TRUE or FALSE (optional, uses app settings)',
- },
- ],
- },
- REPT: {
- name: 'REPT',
- description: t('Repeats text specified number of times.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'number', description: 'Number' },
- ],
- },
- CHAR: {
- name: 'CHAR',
- description: t('Converts number to character.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- CODE: {
- name: 'CODE',
- description: t('Returns numeric code for first character.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- EXACT: {
- name: 'EXACT',
- description: t('Returns TRUE if texts are exactly the same.'),
- parameters: [
- { name: 'text1', description: 'Text' },
- { name: 'text2', description: 'Text' },
- ],
- },
- CLEAN: {
- name: 'CLEAN',
- description: t('Removes non-printable characters from text.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- SPLIT: {
- name: 'SPLIT',
- description: t('Splits text by space and returns part at index.'),
- parameters: [
- { name: 'text', description: 'Text' },
- { name: 'index', description: 'Index' },
- ],
- },
-
- // Math Functions (for amount calculations)
- SUM: {
- name: 'SUM',
- description: t('Returns the sum of all numbers.'),
- parameters: [
- { name: 'numbers', description: 'Number1, Number2, ...NumberN' },
- ],
- },
- ABS: {
- name: 'ABS',
- description: t('Returns the absolute value of a number.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- ROUND: {
- name: 'ROUND',
- description: t('Rounds a number to specified decimals.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- ROUNDDOWN: {
- name: 'ROUNDDOWN',
- description: t('Rounds down to specified decimals.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- ROUNDUP: {
- name: 'ROUNDUP',
- description: t('Rounds up to specified decimals.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- FLOOR: {
- name: 'FLOOR',
- description: t('Rounds down to nearest multiple of significance.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'significance', description: 'Significance' },
- ],
- },
- CEILING: {
- name: 'CEILING',
- description: t('Rounds up to nearest multiple of significance.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'significance', description: 'Significance' },
- ],
- },
- INT: {
- name: 'INT',
- description: t('Rounds down to nearest integer.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- TRUNC: {
- name: 'TRUNC',
- description: t('Truncates number to specified decimals.'),
- parameters: [
- { name: 'number', description: 'Number' },
- { name: 'decimals', description: 'Decimals' },
- ],
- },
- MOD: {
- name: 'MOD',
- description: t('Returns the remainder of division.'),
- parameters: [
- { name: 'dividend', description: 'Dividend' },
- { name: 'divisor', description: 'Divisor' },
- ],
- },
- POWER: {
- name: 'POWER',
- description: t('Returns base raised to the power of exponent.'),
- parameters: [
- { name: 'base', description: 'Base' },
- { name: 'exponent', description: 'Exponent' },
- ],
- },
- SQRT: {
- name: 'SQRT',
- description: t('Returns the square root.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- SIGN: {
- name: 'SIGN',
- description: t('Returns -1 for negative, 0 for zero, 1 for positive.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
-
- // Date and Time Functions
- DATE: {
- name: 'DATE',
- description: t('Returns date as number of days since null date.'),
- parameters: [
- { name: 'year', description: 'Year' },
- { name: 'month', description: 'Month' },
- { name: 'day', description: 'Day' },
- ],
- },
- TODAY: {
- name: 'TODAY',
- description: t('Returns current date.'),
- parameters: [],
- },
- NOW: {
- name: 'NOW',
- description: t('Returns current date and time.'),
- parameters: [],
- },
- YEAR: {
- name: 'YEAR',
- description: t('Returns the year from a date.'),
- parameters: [{ name: 'date', description: 'Number' }],
- },
- MONTH: {
- name: 'MONTH',
- description: t('Returns the month from a date.'),
- parameters: [{ name: 'date', description: 'Number' }],
- },
- DAY: {
- name: 'DAY',
- description: t('Returns the day from a date.'),
- parameters: [{ name: 'date', description: 'Number' }],
- },
- WEEKDAY: {
- name: 'WEEKDAY',
- description: t('Returns day of week (1-7).'),
- parameters: [
- { name: 'date', description: 'Date' },
- { name: 'type', description: 'Type' },
- ],
- },
- EDATE: {
- name: 'EDATE',
- description: t('Returns date shifted by specified months.'),
- parameters: [
- { name: 'start_date', description: 'Startdate' },
- { name: 'months', description: 'Months' },
- ],
- },
- EOMONTH: {
- name: 'EOMONTH',
- description: t('Returns last day of month after specified months.'),
- parameters: [
- { name: 'start_date', description: 'Startdate' },
- { name: 'months', description: 'Months' },
- ],
- },
- DAYS: {
- name: 'DAYS',
- description: t('Calculates difference between dates in days.'),
- parameters: [
- { name: 'end_date', description: 'Date2' },
- { name: 'start_date', description: 'Date1' },
- ],
- },
- DATEDIF: {
- name: 'DATEDIF',
- description: t('Calculates distance between dates.'),
- parameters: [
- { name: 'start_date', description: 'Date1' },
- { name: 'end_date', description: 'Date2' },
- { name: 'unit', description: 'Unit' },
- ],
- },
- DATEVALUE: {
- name: 'DATEVALUE',
- description: t('Parses a date string and returns it as a number.'),
- parameters: [{ name: 'date_string', description: 'Datestring' }],
- },
- WEEKNUM: {
- name: 'WEEKNUM',
- description: t('Returns week number of year.'),
- parameters: [
- { name: 'date', description: 'Date' },
- { name: 'type', description: 'Type' },
- ],
- },
- ISOWEEKNUM: {
- name: 'ISOWEEKNUM',
- description: t('Returns ISO week number.'),
- parameters: [{ name: 'date', description: 'Date' }],
- },
-
- // Logical Functions
- IF: {
- name: 'IF',
- description: t('Returns one value if condition is TRUE, another if FALSE.'),
- parameters: [
- { name: 'condition', description: 'Condition' },
- { name: 'value_if_true', description: 'ValueIfTrue' },
- { name: 'value_if_false', description: 'ValueIfFalse' },
- ],
- },
- IFS: {
- name: 'IFS',
- description: t(
- 'Checks multiple conditions and returns corresponding values.',
- ),
- parameters: [
- { name: 'condition1', description: 'Condition1' },
- { name: 'value1', description: 'Value1' },
- ],
- },
- AND: {
- name: 'AND',
- description: t('Returns TRUE if all arguments are TRUE.'),
- parameters: [
- {
- name: 'conditions',
- description: 'Condition1, Condition2, ...ConditionN',
- },
- ],
- },
- OR: {
- name: 'OR',
- description: t('Returns TRUE if any argument is TRUE.'),
- parameters: [
- {
- name: 'conditions',
- description: 'Condition1, Condition2, ...ConditionN',
- },
- ],
- },
- XOR: {
- name: 'XOR',
- description: t('Returns TRUE if odd number of arguments are TRUE.'),
- parameters: [
- {
- name: 'conditions',
- description: 'Condition1, Condition2, ...ConditionN',
- },
- ],
- },
- NOT: {
- name: 'NOT',
- description: t('Reverses the logical value.'),
- parameters: [{ name: 'condition', description: 'Condition' }],
- },
- TRUE: {
- name: 'TRUE',
- description: t('Returns the logical value TRUE.'),
- parameters: [],
- },
- FALSE: {
- name: 'FALSE',
- description: t('Returns the logical value FALSE.'),
- parameters: [],
- },
- IFERROR: {
- name: 'IFERROR',
- description: t('Returns value if no error, otherwise returns alternative.'),
- parameters: [
- { name: 'value', description: 'Value' },
- { name: 'value_if_error', description: 'ValueIfError' },
- ],
- },
- IFNA: {
- name: 'IFNA',
- description: t(
- 'Returns value if not #N/A error, otherwise returns alternative.',
- ),
- parameters: [
- { name: 'value', description: 'Value' },
- { name: 'value_if_na', description: 'ValueIfNA' },
- ],
- },
- SWITCH: {
- name: 'SWITCH',
- description: t(
- 'Matches expression against values and returns corresponding result.',
- ),
- parameters: [
- { name: 'expression', description: 'Expression' },
- { name: 'value1', description: 'Value1' },
- { name: 'result1', description: 'Result1' },
- ],
- },
-
- // Information Functions
- ISBLANK: {
- name: 'ISBLANK',
- description: t('Returns TRUE if value is blank.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISERROR: {
- name: 'ISERROR',
- description: t('Returns TRUE if value is any error.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISNA: {
- name: 'ISNA',
- description: t('Returns TRUE if value is #N/A error.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISNUMBER: {
- name: 'ISNUMBER',
- description: t('Returns TRUE if value is a number.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISTEXT: {
- name: 'ISTEXT',
- description: t('Returns TRUE if value is text.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISLOGICAL: {
- name: 'ISLOGICAL',
- description: t('Returns TRUE if value is logical (TRUE/FALSE).'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- ISEVEN: {
- name: 'ISEVEN',
- description: t('Returns TRUE if number is even.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
- ISODD: {
- name: 'ISODD',
- description: t('Returns TRUE if number is odd.'),
- parameters: [{ name: 'number', description: 'Number' }],
- },
-
- // Conversion Functions
- VALUE: {
- name: 'VALUE',
- description: t('Converts text to a number.'),
- parameters: [{ name: 'text', description: 'Text' }],
- },
- T: {
- name: 'T',
- description: t('Returns text if value is text, empty string otherwise.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
- N: {
- name: 'N',
- description: t('Converts value to a number.'),
- parameters: [{ name: 'value', description: 'Value' }],
- },
-};
diff --git a/packages/docs/docs/experimental/formulas.md b/packages/docs/docs/experimental/formulas.md
index 6094ddd0fe..c2806502fb 100644
--- a/packages/docs/docs/experimental/formulas.md
+++ b/packages/docs/docs/experimental/formulas.md
@@ -39,9 +39,9 @@ Click the card to open the editor (where you can save the widget).
- **Start with `=`** (example: `=SUM(1, 2, 3)`)
- You can use typical Excel-style functions (autocomplete and hover help are built into the editor).
-## Function reference (autocomplete)
+## Function reference
-This list documents the functions that appear in the in-app **autocomplete/hover popover** for formulas.
+This list documents formula functions that are useful in Actual. The in-app **autocomplete/hover popover** provides a curated subset of these functions.
:::tip
If a function isn’t listed here, it still might work. Actual uses HyperFormula under the hood, so you can also refer to [HyperFormula’s built-in functions list](https://hyperformula.handsontable.com/guide/built-in-functions.html).
diff --git a/upcoming-release-notes/8369.md b/upcoming-release-notes/8369.md
new file mode 100644
index 0000000000..ef6f1fb941
--- /dev/null
+++ b/upcoming-release-notes/8369.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [lelemm]
+---
+
+Refactor formula autocomplete metadata to share a single catalog for report and rule formula suggestions.