38b658205d
* fix: include reversed entries in all reports (general ledger, trial balance, VAT, SIE, NE, INK2) Reversed entries (storno) must appear alongside their original posted entries in reports for a complete audit trail. Previously, filtering by status='posted' excluded them, causing discrepancies when corrections had been made. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: semi-manual invoice payment booking with editable journal lines When marking an invoice as paid, users now see a dialog where they can: - Choose which bank/cash account the payment goes to (1910, 1920, 1930, etc.) - Review and edit the proposed journal entry lines before committing - The happy path remains fast — lines are pre-filled correctly Implementation: - Pure proposePaymentLines() function for line computation (accrual + cash) - PaymentBookingDialog with AccountCombobox, balance validation, date picker - API accepts optional custom lines, falls back to auto-generation without them - 18 tests (8 unit + 10 API) all passing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address Greptile review — validation fallback, balance check, error handling - P1: Return 400 on invalid body instead of silently falling back to auto-generated lines (split JSON parse from schema validation) - P1: Add server-side balance check for custom lines before committing (debit must equal credit, totalDebit > 0) - P2: Wrap PaymentBookingDialog init() in try/catch with toast on failure and auto-close instead of silent empty state - Add 2 new tests: unbalanced lines → 400, invalid schema → 400 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: OAuth callback redirect for local dev and timeout resilience - Pass redirectUri dynamically from NEXT_PUBLIC_APP_URL so OAuth callbacks work on localhost (not just production) - Encode consentId/provider in OAuth state (base64url JSON) so the callback doesn't depend on session storage - Add skipAuth flag to extension API routes for OAuth callbacks (external provider redirects have no user session cookie) - Wrap AbortError in descriptive timeout messages in arcim-client - Make preview endpoint resilient to partial failures (company info and SIE fetch are individually non-blocking) - Simplify login page (remove unused magic link auth mode) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: create journal entry before marking invoice as paid Move journal entry creation before the invoice status update so that if accounting fails, the invoice is not permanently marked paid without a corresponding entry. Previously the error was silently swallowed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: update mark-paid tests for journal-first ordering Reorder mock queue to match new flow (settings before update), update failure test to expect 500 instead of silent success, add try-catch with proper error response in route handler. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add reverse charge VAT (ruta 20-32) and improve mobile UX across dashboard Add full reverse charge (omvänd skattskyldighet) support to the VAT declaration: - Map accounts 2614/2624/2634 to ruta 30/31/32 for self-assessed output VAT - Calculate purchase bases (ruta 20-24) from supplier invoices by supplier type - Include ruta 30-32 in ruta 49 formula and totalOutputVat summary - Display reverse charge section in reports UI and composition chart - Add comprehensive test coverage for all reverse charge scenarios Improve mobile UX across the app: - Convert nav drawer to bottom sheet with drag handle and safe area padding - Add mobile card layout for PaymentBookingDialog journal lines - Replace settings tab pills with dropdown selector on mobile - Make wizard step indicators responsive (collapsed on mobile) - Ensure all dialog footers stack buttons full-width on mobile - Add 44px minimum touch targets throughout - Make onboarding buttons full-width on mobile Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address Greptile review — indentation, query efficiency, tab dedup - Fix misleading try-block indentation in mark-paid route - Filter reversed entries at DB level (.eq('status', 'posted')) instead of fetching then discarding in memory - Extract shared settingsTabs array so mobile Select and desktop TabsList stay in sync automatically Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add resilience fallbacks, Arcim retry logic, and client tests Add FallbackPrompt component and integrate it across banking and migration error states so users always have a manual import escape hatch. Add retry with exponential backoff to Arcim API client for transient failures (429, 502, 503, 504) and timeouts. Expand import page deep-linking with ?mode= parameter. Add persistent error banner on settings page for bank connection failures. Include 18 new tests for the Arcim client covering retry, backoff, pagination, timeout, env validation, and singleton resource unwrapping. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address Greptile review — setActiveTab, test cleanup, redundant clearTimeout - Add missing setActiveTab('banking') when handling bank_error query param so the error banner is actually visible (P1) - Guard env-var cleanup with try/finally in arcim-client tests to prevent state leakage on assertion failure (P2) - Only mock retry-range setTimeout delays in backoff test, letting AbortController timers pass through real setTimeout (P2) - Remove redundant clearTimeout in catch block — finally handles it (P2) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add BFL-compliant counterparty names to journal descriptions and cancelled entry status Journal descriptions now include customer/supplier names for traceability (e.g. "Kundfaktura 1001, Foretag AB"). Failed draft entries are marked as 'cancelled' instead of deleted, respecting immutability constraints. Includes DB migration for the new journal_entries status value. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address Greptile review — Swedish typos, missing source type, trigger and reversal cleanup - Fix Swedish spelling: leverantor → leverantör in all supplier description prefixes - Add supplier_credit_note to supplierSourceTypes in VAT declaration so credit notes correctly reduce reverse-charge bases (ruta 20–24) - Mark orphaned concurrent reversals as cancelled instead of attempting deletion that the immutability trigger blocks - Allow posted → cancelled transition in trigger for orphaned reversal cleanup - Restrict cancelled entry line trigger to DELETE-only (block INSERT/UPDATE) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: use main's Step3TaxRegistration (onboarding restructured in PR #54) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: retrigger Greptile review Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add TIC company lookup extension, extension nav items, and legacy toggle fallback Introduces the TIC (Bolagsuppgifter) extension for automatic company data lookup via org number during onboarding. Adds dynamic extension nav items in the sidebar, legacy general extension fallback for toggle checks, and company lookup type definitions in core. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address Greptile review — restore push-notifications, filter nav by toggles, fix timeout error name - Restore push-notifications to LEGACY_GENERAL_EXTENSIONS (was silently dropped when extracting the shared constant) - Remove tic and arcim-migration from legacy defaults (new extensions should not default to enabled for all users) - Filter getExtensionNavItems() against user's enabled extensions so disabled extensions don't appear in the sidebar - Fix AbortSignal.timeout() error name check — Node.js throws TimeoutError, not AbortError Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: add all bundled extensions to legacy defaults (email, arcim-migration, tic) Bundled extensions configured in extensions.config.json should default to enabled. Adds email, arcim-migration, and tic alongside the existing legacy defaults so they are accessible without explicit toggle rows. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: replace welcome checklist with full-page setup gate New users now see a full-page onboarding gate instead of a small dismissible card. The gate enforces a clear two-step sequential flow: (1) migrate bookkeeping from Fortnox/Bokio/Visma or import SIE file, (2) connect bank account. The gate blocks all dashboard content until the user has imported data or explicitly chooses "fresh start". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: clean up journal lines after cancelling failed reversal entries When a reversal fails at the line-insert, post, or CAS stage, the entry is correctly marked as cancelled. Now also delete the attached lines to prevent stale data accumulation — the migration trigger allows DELETE on lines of cancelled entries for this purpose. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
433 lines
13 KiB
TypeScript
433 lines
13 KiB
TypeScript
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
import { eventBus } from '@/lib/events'
|
|
import type {
|
|
CreateJournalEntryInput,
|
|
CreateJournalEntryLineInput,
|
|
JournalEntry,
|
|
JournalEntryLine,
|
|
} from '@/types'
|
|
|
|
/**
|
|
* Validate that a set of journal entry lines is balanced (debits = credits)
|
|
*/
|
|
export function validateBalance(lines: CreateJournalEntryLineInput[]): {
|
|
valid: boolean
|
|
totalDebit: number
|
|
totalCredit: number
|
|
} {
|
|
const totalDebit = lines.reduce((sum, l) => sum + (l.debit_amount || 0), 0)
|
|
const totalCredit = lines.reduce((sum, l) => sum + (l.credit_amount || 0), 0)
|
|
|
|
// Round to avoid floating point issues (2 decimal places for SEK)
|
|
const roundedDebit = Math.round(totalDebit * 100) / 100
|
|
const roundedCredit = Math.round(totalCredit * 100) / 100
|
|
|
|
return {
|
|
valid: roundedDebit === roundedCredit && roundedDebit > 0,
|
|
totalDebit: roundedDebit,
|
|
totalCredit: roundedCredit,
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the next voucher number for a user/period/series
|
|
* Uses the concurrent-safe INSERT ON CONFLICT implementation in the database
|
|
*/
|
|
export async function getNextVoucherNumber(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
fiscalPeriodId: string,
|
|
series: string = 'A'
|
|
): Promise<number> {
|
|
|
|
const { data, error } = await supabase.rpc('next_voucher_number', {
|
|
p_user_id: userId,
|
|
p_fiscal_period_id: fiscalPeriodId,
|
|
p_series: series,
|
|
})
|
|
|
|
if (error) {
|
|
throw new Error(`Failed to get next voucher number: ${error.message}`)
|
|
}
|
|
|
|
return data as number
|
|
}
|
|
|
|
/**
|
|
* Resolve account IDs from account numbers for a user
|
|
*/
|
|
async function resolveAccountIds(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
lines: CreateJournalEntryLineInput[]
|
|
): Promise<Map<string, string>> {
|
|
const accountNumbers = [...new Set(lines.map((l) => l.account_number))]
|
|
|
|
const { data: accounts, error } = await supabase
|
|
.from('chart_of_accounts')
|
|
.select('id, account_number')
|
|
.eq('user_id', userId)
|
|
.in('account_number', accountNumbers)
|
|
|
|
if (error) {
|
|
throw new Error(`Failed to resolve account IDs: ${error.message}`)
|
|
}
|
|
|
|
const map = new Map<string, string>()
|
|
for (const account of accounts || []) {
|
|
map.set(account.account_number, account.id)
|
|
}
|
|
|
|
return map
|
|
}
|
|
|
|
/**
|
|
* Find the fiscal period for a given date
|
|
*/
|
|
export async function findFiscalPeriod(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
date: string
|
|
): Promise<string | null> {
|
|
|
|
// Overlapping periods are prevented by a DB exclusion constraint
|
|
// (migration 042). limit(1) is kept as a defensive measure.
|
|
const { data, error } = await supabase
|
|
.from('fiscal_periods')
|
|
.select('id')
|
|
.eq('user_id', userId)
|
|
.lte('period_start', date)
|
|
.gte('period_end', date)
|
|
.eq('is_closed', false)
|
|
.order('period_start', { ascending: false })
|
|
.limit(1)
|
|
|
|
if (error || !data || data.length === 0) {
|
|
return null
|
|
}
|
|
|
|
return data[0].id
|
|
}
|
|
|
|
/**
|
|
* Build line insert objects from input lines, resolving account IDs and
|
|
* including tax_code, cost_center, project dimensions
|
|
*/
|
|
function buildLineInserts(
|
|
entryId: string,
|
|
lines: CreateJournalEntryLineInput[],
|
|
accountIdMap: Map<string, string>
|
|
) {
|
|
return lines.map((line, index) => ({
|
|
journal_entry_id: entryId,
|
|
account_number: line.account_number,
|
|
account_id: accountIdMap.get(line.account_number) || null,
|
|
debit_amount: Math.round((line.debit_amount || 0) * 100) / 100,
|
|
credit_amount: Math.round((line.credit_amount || 0) * 100) / 100,
|
|
currency: line.currency || 'SEK',
|
|
amount_in_currency: line.amount_in_currency ? Math.round(line.amount_in_currency * 100) / 100 : null,
|
|
exchange_rate: line.exchange_rate || null,
|
|
line_description: line.line_description || null,
|
|
tax_code: line.tax_code || null,
|
|
cost_center: line.cost_center || null,
|
|
project: line.project || null,
|
|
sort_order: index,
|
|
}))
|
|
}
|
|
|
|
/**
|
|
* Create a draft journal entry with lines (no voucher number assigned yet)
|
|
* The entry stays in 'draft' status until commitEntry() is called.
|
|
*/
|
|
export async function createDraftEntry(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
input: CreateJournalEntryInput
|
|
): Promise<JournalEntry> {
|
|
// Validate balance
|
|
const balance = validateBalance(input.lines)
|
|
if (!balance.valid) {
|
|
throw new Error(
|
|
`Journal entry is not balanced: debits (${balance.totalDebit}) != credits (${balance.totalCredit})`
|
|
)
|
|
}
|
|
|
|
// Resolve account IDs
|
|
const accountIdMap = await resolveAccountIds(supabase, userId, input.lines)
|
|
|
|
// Insert journal entry header as draft (voucher_number = 0, will be assigned on commit)
|
|
const { data: entry, error: entryError } = await supabase
|
|
.from('journal_entries')
|
|
.insert({
|
|
user_id: userId,
|
|
fiscal_period_id: input.fiscal_period_id,
|
|
voucher_number: 0,
|
|
voucher_series: input.voucher_series || 'A',
|
|
entry_date: input.entry_date,
|
|
description: input.description,
|
|
source_type: input.source_type,
|
|
source_id: input.source_id || null,
|
|
status: 'draft',
|
|
})
|
|
.select()
|
|
.single()
|
|
|
|
if (entryError || !entry) {
|
|
throw new Error(`Failed to create draft journal entry: ${entryError?.message}`)
|
|
}
|
|
|
|
// Insert journal entry lines with dimensions
|
|
const lineInserts = buildLineInserts(entry.id, input.lines, accountIdMap)
|
|
|
|
const { error: linesError } = await supabase
|
|
.from('journal_entry_lines')
|
|
.insert(lineInserts)
|
|
|
|
if (linesError) {
|
|
await supabase.from('journal_entries').update({ status: 'cancelled' }).eq('id', entry.id)
|
|
throw new Error(`Failed to create journal entry lines: ${linesError.message}`)
|
|
}
|
|
|
|
// Fetch complete entry with lines
|
|
const { data: completeEntry } = await supabase
|
|
.from('journal_entries')
|
|
.select('*, lines:journal_entry_lines(*)')
|
|
.eq('id', entry.id)
|
|
.single()
|
|
|
|
const result = completeEntry as JournalEntry
|
|
|
|
await eventBus.emit({
|
|
type: 'journal_entry.drafted',
|
|
payload: { entry: result, userId },
|
|
})
|
|
|
|
return result
|
|
}
|
|
|
|
/**
|
|
* Commit a draft entry: assigns voucher number and transitions to 'posted'
|
|
* Triggers balance validation and sets committed_at via DB triggers
|
|
*/
|
|
export async function commitEntry(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
entryId: string
|
|
): Promise<JournalEntry> {
|
|
|
|
// Fetch the draft entry
|
|
const { data: entry, error: fetchError } = await supabase
|
|
.from('journal_entries')
|
|
.select('*')
|
|
.eq('id', entryId)
|
|
.eq('user_id', userId)
|
|
.eq('status', 'draft')
|
|
.single()
|
|
|
|
if (fetchError || !entry) {
|
|
throw new Error('Draft journal entry not found')
|
|
}
|
|
|
|
// Assign voucher number
|
|
const voucherNumber = await getNextVoucherNumber(
|
|
supabase,
|
|
userId,
|
|
entry.fiscal_period_id,
|
|
entry.voucher_series || 'A'
|
|
)
|
|
|
|
// Update to posted with voucher number
|
|
// DB triggers will: validate balance, set committed_at, write audit log
|
|
const { error: postError } = await supabase
|
|
.from('journal_entries')
|
|
.update({
|
|
voucher_number: voucherNumber,
|
|
status: 'posted',
|
|
})
|
|
.eq('id', entryId)
|
|
|
|
if (postError) {
|
|
throw new Error(`Failed to commit journal entry: ${postError.message}`)
|
|
}
|
|
|
|
// Fetch complete posted entry with lines
|
|
const { data: completeEntry } = await supabase
|
|
.from('journal_entries')
|
|
.select('*, lines:journal_entry_lines(*)')
|
|
.eq('id', entryId)
|
|
.single()
|
|
|
|
const result = completeEntry as JournalEntry
|
|
|
|
await eventBus.emit({
|
|
type: 'journal_entry.committed',
|
|
payload: { entry: result, userId },
|
|
})
|
|
|
|
return result
|
|
}
|
|
|
|
/**
|
|
* Create a journal entry with lines (verifikation)
|
|
* Convenience wrapper: creates draft + commits in one step.
|
|
* The voucher number is only assigned after lines are successfully inserted,
|
|
* preventing gaps in the voucher sequence (BFL 5 kap. 7§).
|
|
*/
|
|
export async function createJournalEntry(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
input: CreateJournalEntryInput
|
|
): Promise<JournalEntry> {
|
|
const draft = await createDraftEntry(supabase, userId, input)
|
|
return commitEntry(supabase, userId, draft.id)
|
|
}
|
|
|
|
/**
|
|
* Get the current date in Swedish timezone (Europe/Stockholm).
|
|
* Avoids UTC date shift when server runs in a different timezone.
|
|
*/
|
|
export function getSwedishLocalDate(): string {
|
|
return new Intl.DateTimeFormat('sv-SE', { timeZone: 'Europe/Stockholm' }).format(new Date())
|
|
}
|
|
|
|
/**
|
|
* Create a reversal entry for an existing journal entry
|
|
* Sets reversed_by_id/reverses_id links for compliance tracking
|
|
*/
|
|
export async function reverseEntry(
|
|
supabase: SupabaseClient,
|
|
userId: string,
|
|
entryId: string,
|
|
reversalDate?: string
|
|
): Promise<JournalEntry> {
|
|
|
|
// Fetch original entry with lines
|
|
const { data: original, error } = await supabase
|
|
.from('journal_entries')
|
|
.select('*, lines:journal_entry_lines(*)')
|
|
.eq('id', entryId)
|
|
.eq('user_id', userId)
|
|
.single()
|
|
|
|
if (error || !original) {
|
|
throw new Error('Journal entry not found')
|
|
}
|
|
|
|
if (original.status !== 'posted') {
|
|
throw new Error('Can only reverse posted entries')
|
|
}
|
|
|
|
const lines = (original.lines as JournalEntryLine[]) || []
|
|
|
|
// Create reversed lines (swap debit and credit, preserve dimensions)
|
|
const reversedLines: CreateJournalEntryLineInput[] = lines.map((line) => ({
|
|
account_number: line.account_number,
|
|
debit_amount: line.credit_amount,
|
|
credit_amount: line.debit_amount,
|
|
line_description: `Reversal: ${line.line_description || ''}`,
|
|
currency: line.currency,
|
|
amount_in_currency: line.amount_in_currency
|
|
? -line.amount_in_currency
|
|
: undefined,
|
|
exchange_rate: line.exchange_rate || undefined,
|
|
tax_code: line.tax_code || undefined,
|
|
cost_center: line.cost_center || undefined,
|
|
project: line.project || undefined,
|
|
}))
|
|
|
|
const entryDate = reversalDate || getSwedishLocalDate()
|
|
|
|
// Get voucher number for the reversal
|
|
const voucherNumber = await getNextVoucherNumber(
|
|
supabase,
|
|
userId,
|
|
original.fiscal_period_id,
|
|
original.voucher_series || 'A'
|
|
)
|
|
|
|
// Resolve account IDs
|
|
const accountIdMap = await resolveAccountIds(supabase, userId, reversedLines)
|
|
|
|
// Create reversal entry with reverses_id link
|
|
const { data: reversalEntry, error: reversalError } = await supabase
|
|
.from('journal_entries')
|
|
.insert({
|
|
user_id: userId,
|
|
fiscal_period_id: original.fiscal_period_id,
|
|
voucher_number: voucherNumber,
|
|
voucher_series: original.voucher_series || 'A',
|
|
entry_date: entryDate,
|
|
description: `Makulering: ${original.description}`,
|
|
source_type: 'storno',
|
|
source_id: original.source_id || null,
|
|
reverses_id: entryId,
|
|
status: 'draft',
|
|
})
|
|
.select()
|
|
.single()
|
|
|
|
if (reversalError || !reversalEntry) {
|
|
throw new Error(`Failed to create reversal entry: ${reversalError?.message}`)
|
|
}
|
|
|
|
// Insert reversal lines with dimensions
|
|
const lineInserts = buildLineInserts(reversalEntry.id, reversedLines, accountIdMap)
|
|
|
|
const { error: linesError } = await supabase
|
|
.from('journal_entry_lines')
|
|
.insert(lineInserts)
|
|
|
|
if (linesError) {
|
|
await supabase.from('journal_entries').update({ status: 'cancelled' }).eq('id', reversalEntry.id)
|
|
await supabase.from('journal_entry_lines').delete().eq('journal_entry_id', reversalEntry.id)
|
|
throw new Error(`Failed to create reversal lines: ${linesError.message}`)
|
|
}
|
|
|
|
// Post the reversal entry
|
|
const { error: postError } = await supabase
|
|
.from('journal_entries')
|
|
.update({ status: 'posted' })
|
|
.eq('id', reversalEntry.id)
|
|
|
|
if (postError) {
|
|
await supabase.from('journal_entries').update({ status: 'cancelled' }).eq('id', reversalEntry.id)
|
|
await supabase.from('journal_entry_lines').delete().eq('journal_entry_id', reversalEntry.id)
|
|
throw new Error(`Failed to post reversal entry: ${postError.message}`)
|
|
}
|
|
|
|
// Mark original as reversed with reversed_by_id link (CAS guard: only if still 'posted')
|
|
const { data: updatedOriginal, error: casError } = await supabase
|
|
.from('journal_entries')
|
|
.update({
|
|
status: 'reversed',
|
|
reversed_by_id: reversalEntry.id,
|
|
})
|
|
.eq('id', entryId)
|
|
.eq('status', 'posted')
|
|
.select('id')
|
|
|
|
if (casError || !updatedOriginal || updatedOriginal.length === 0) {
|
|
// Another concurrent reversal already changed the status — mark the orphaned
|
|
// reversal as cancelled so it's excluded from reports but remains traceable.
|
|
await supabase.from('journal_entries').update({ status: 'cancelled' }).eq('id', reversalEntry.id)
|
|
await supabase.from('journal_entry_lines').delete().eq('journal_entry_id', reversalEntry.id)
|
|
throw new Error('Entry was already reversed by a concurrent operation')
|
|
}
|
|
|
|
// Fetch complete reversal entry with lines
|
|
const { data: completeEntry } = await supabase
|
|
.from('journal_entries')
|
|
.select('*, lines:journal_entry_lines(*)')
|
|
.eq('id', reversalEntry.id)
|
|
.single()
|
|
|
|
const result = completeEntry as JournalEntry
|
|
|
|
await eventBus.emit({
|
|
type: 'journal_entry.committed',
|
|
payload: { entry: result, userId },
|
|
})
|
|
|
|
return result
|
|
}
|