* refactor: optimize page loading and data fetching * fix: resolve recurring production runtime errors * feat: add MCP company and customer updates * fix: handle year-end tax adjustments * feat: harden annual report compliance * fix: expand invoice logo and font support * fix: sanitize API route error responses * fix: sanitize user-facing error messages * feat: persist onboarding and tax assessment notices * fix: reduce cloud backup audit churn * feat: refine invoice editor layout * fix: show saved tax adjustments in INK2 * fix: complete annual report API mappings * docs: record operational safeguards and decisions * fix: harden annual report review findings * fix: adjust column span for description based on VAT registration * New css class name
58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
import {
|
|
emptyAnnualReportProfile,
|
|
type AnnualReportProfile,
|
|
} from './compliance-types'
|
|
|
|
const PROFILE_COLUMNS =
|
|
'id, company_id, fiscal_period_id, is_public_limited_company, is_in_liquidation, securities_traded_on_regulated_market, is_parent_company, parent_group_size, prepares_consolidated_accounts, has_foreign_branch, has_crypto_assets, has_share_based_payments, has_convertible_debt, building_revenue_share_pct, has_material_deferred_tax, reporting_currency, auditor_report_required, auditor_report_included, dividend_prudence_confirmed, narrative_confirmed_at, k2_assessment_confirmed_at, signer_roster_confirmed_at, updated_at'
|
|
|
|
export type AnnualReportProfileUpdate = Partial<
|
|
Omit<AnnualReportProfile, 'id' | 'company_id' | 'fiscal_period_id' | 'updated_at'>
|
|
>
|
|
|
|
export async function getAnnualReportProfile(
|
|
supabase: SupabaseClient,
|
|
companyId: string,
|
|
fiscalPeriodId: string,
|
|
): Promise<AnnualReportProfile> {
|
|
const { data, error } = await supabase
|
|
.from('annual_report_profiles')
|
|
.select(PROFILE_COLUMNS)
|
|
.eq('company_id', companyId)
|
|
.eq('fiscal_period_id', fiscalPeriodId)
|
|
.maybeSingle()
|
|
if (error) throw new Error(`Failed to load annual report profile: ${error.message}`)
|
|
return data
|
|
? (data as AnnualReportProfile)
|
|
: emptyAnnualReportProfile(companyId, fiscalPeriodId)
|
|
}
|
|
|
|
export async function upsertAnnualReportProfile(
|
|
supabase: SupabaseClient,
|
|
companyId: string,
|
|
userId: string,
|
|
fiscalPeriodId: string,
|
|
input: AnnualReportProfileUpdate,
|
|
): Promise<AnnualReportProfile> {
|
|
const payload: Record<string, unknown> = {
|
|
company_id: companyId,
|
|
fiscal_period_id: fiscalPeriodId,
|
|
user_id: userId,
|
|
...input,
|
|
}
|
|
if (input.is_parent_company === false) {
|
|
payload.parent_group_size = null
|
|
payload.prepares_consolidated_accounts = null
|
|
}
|
|
const { data, error } = await supabase
|
|
.from('annual_report_profiles')
|
|
.upsert(payload, { onConflict: 'company_id,fiscal_period_id' })
|
|
.select(PROFILE_COLUMNS)
|
|
.single()
|
|
if (error || !data) {
|
|
throw new Error(`Failed to save annual report profile: ${error?.message ?? 'unknown'}`)
|
|
}
|
|
return data as AnnualReportProfile
|
|
}
|