Files
accounted/extensions/general/mcp-server/resources/period-active.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

54 lines
2.0 KiB
TypeScript

import type { McpResource } from './types'
export const periodActiveResource: McpResource = {
uri: 'Accounted://period/active',
name: 'Active Fiscal Period',
description: 'The fiscal period that the current date falls within: lock state, opening-balance status, retention deadline. Use to check whether new entries can be posted.',
mimeType: 'application/json',
read: async ({ supabase, companyId }) => {
const today = new Date().toISOString().slice(0, 10)
const { data: active, error: activeError } = await supabase
.from('fiscal_periods')
.select('id, name, period_start, period_end, is_closed, closed_at, locked_at, opening_balances_set, retention_expires_at, opening_balance_entry_id, closing_entry_id, previous_period_id')
.eq('company_id', companyId)
.lte('period_start', today)
.gte('period_end', today)
.maybeSingle()
if (activeError && activeError.code !== 'PGRST116') {
throw new Error(`Failed to read active period: ${activeError.message}`)
}
const { data: settings } = await supabase
.from('company_settings')
.select('bookkeeping_locked_through, auto_lock_period_days')
.eq('company_id', companyId)
.maybeSingle()
const periodLockedAt = active?.locked_at ?? null
const isClosed = active?.is_closed ?? null
const companyLockDate = settings?.bookkeeping_locked_through ?? null
const canPostEntries = active
? !isClosed && !periodLockedAt
: false
return {
active_period: active ?? null,
company_lock: {
bookkeeping_locked_through: companyLockDate,
auto_lock_period_days: settings?.auto_lock_period_days ?? null,
},
can_post_entries: canPostEntries,
reason_blocked: !active
? 'No fiscal period covers today\'s date'
: isClosed
? 'Active period is closed (status: stängd)'
: periodLockedAt
? 'Active period is locked (status: låst)'
: null,
}
},
}