* feat(invoicing): artikelregister (product/article catalog) with per-article revenue account Add a lean, non-inventory article catalog (artikelregister) so users can define reusable invoice-line presets (name, unit, price excl VAT, VAT rate) with an optional per-article BAS class-3 revenue-account override. - DB: articles table (RLS via user_company_ids(), audit + updated_at triggers, unique-per-company article_number), generate_article_number RPC (atomic + idempotent), company_settings counter, nullable invoice_items.revenue_account + article_id, pending_operations CHECK expansion. - Engine: generatePerRateLines groups revenue by (vat_rate, account) — byte-identical with no override, balance-safe when split (last account absorbs the rounding remainder), reverse_charge/export still force 3308/3305. - API: /api/articles CRUD (soft-deactivate); override validated against chart_of_accounts (active class-3) and frozen onto invoice lines at create. - Propagation: override carried through send/mark-sent/credit/convert/cash and the staged commit paths (recurring deferred — documented inline). - MCP: gnubok_list/create/update_article (staged, scoped, risk-tiered). - UI: articles register (list/detail/form) + nav + bilingual i18n + invoice-line article picker & "Spara som artikel" quick-create. - Tests: engine regression, route, and pg-real (RPC/RLS/triggers). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(mcp): strip ILIKE _ wildcard from gnubok_list_articles search Underscore is a single-character ILIKE wildcard; stripping it (alongside the existing %,()\* set) keeps a stray char in the article search from matching every row. Read-only + RLS-scoped, so no security impact — addresses PR #703 reviewer + compliance-swarm CC6.3 notes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29 lines
953 B
TypeScript
29 lines
953 B
TypeScript
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
|
|
/**
|
|
* True when `account` exists in the company's chart of accounts as an ACTIVE
|
|
* class-3 (revenue/intäkt) account. Used to guard the optional per-article
|
|
* revenue-account override so a typo or a non-revenue account can never be
|
|
* pinned to an article (and later booked). Never trust the client.
|
|
*
|
|
* Throws on an unexpected DB error so the route wrapper maps it to the canonical
|
|
* envelope; a simple "account not found" resolves to `false`, not an error.
|
|
*/
|
|
export async function isValidRevenueAccount(
|
|
supabase: SupabaseClient,
|
|
companyId: string,
|
|
account: string,
|
|
): Promise<boolean> {
|
|
const { data, error } = await supabase
|
|
.from('chart_of_accounts')
|
|
.select('account_number')
|
|
.eq('company_id', companyId)
|
|
.eq('account_class', 3)
|
|
.eq('is_active', true)
|
|
.eq('account_number', account)
|
|
.maybeSingle()
|
|
|
|
if (error) throw error
|
|
return !!data
|
|
}
|