Bug/vat selection warning (#583)
* refactor: update VAT handling logic for non-registered sellers and improve related comments * chore: gate automated email flows behind 503 responses Disables user-facing access to invoice payment reminders and salary payslip email sending. Underlying lib code (reminder-processor, PDF templates, notification_settings) is preserved for easy re-enable. - Invoice reminders cron route returns 503; settings UI section removed. - Payslip send route returns 503; original implementation kept as _sendPayslipsImpl for future re-enable. - Push notifications were already extension-disabled, no change needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: remove Recapt feedback widget Strips the third-party Recapt SDK and its floating feedback bubble from the app. The in-app contact form keeps working via the existing email channel (/api/support/contact). Drops the Recapt entries from the CSP and the subprocessor list in the privacy policy. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat: reject meaningless rättelser in correctEntry Guard against zero-economic-effect corrections in the storno engine: - Reject when proposed lines net to zero on every account (e.g. 1930 debit 100 / 1930 credit 100), which would erase the original posting without representing any affärshändelse (BFL 5 kap. 5 §). - Reject when proposed lines are an exact multiset match of the original entry — a rättelse must actually change something. New MeaninglessCorrectionError wired through bookkeepingErrorResponse (HTTP 400) and the Swedish error translator. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat: add date-range picker to resultat- and balansrapport Adds optional from/to date filtering to the four operational financial reports (resultatrapport, balansrapport, income-statement, balance-sheet) so users can view a month, quarter, or custom range inside a fiscal year without leaving the report. Defaults to YTD; "Hela året" preserves the prior full-period behaviour (URL-identical, cache-stable). - trial-balance engine accepts optional fromDate/toDate, rolling prior in-period activity into IB and clamping period activity to the window - 12 API routes accept and validate from_date/to_date query params - ReportDateRange chip picker persists preset per company, only renders on the four relevant tabs - FiscalYearSelector now emits the period object so the range picker has bounds without an extra fetch - PDF/XLSX filenames reflect the chosen range - Resultatrapport drops the prior-year column when narrowed (full-year vs partial-year would mislead) - 11 new tests (engine + parser); all existing report tests pass Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat: add support for marking journal entries as "no document required" - Introduced a new sidecar table `journal_entry_no_doc_required` to track entries that do not require separate documentation (e.g., bank fees, interest). - Implemented API routes for creating and deleting exemptions, including validation and authorization checks. - Added a toggle component in the UI to allow users to mark entries as exempt, with an optional reason. - Updated relevant tests to cover the new functionality, including RLS checks and cascading deletes. - Enhanced existing schemas and types to accommodate the new `vat_amount` field for supplier invoice items. * fix: address PR review findings on no-doc-required + VAT changes - pg-real cascade test wraps DELETE in gnubok.allow_delete='true' txn so the immutability trigger bypass fires (mirrors delete_last_voucher RPC). - Clamp supplier-invoice item vat_amount to <= line_total * vat_rate via Zod refinement (with 1-öre rounding tolerance) so the manual override can't inflate the 2641 debit beyond the statutory ceiling. - groupVatByRate falls back to line_total * rate when stored vat_amount is 0 with a positive rate, so legacy/import paths leaving the column at its NOT NULL DEFAULT 0 don't silently understate ruta 48. - ReportDateRange todayIso() and preset endpoints use local date components instead of toISOString() (UTC) — fixes the midnight-to-02:00 off-by-one that truncated a day from YTD / this-month / this-quarter for Swedish users. - NoDocRequiredToggle restores the previous reason on failed POST/DELETE so the rolled-back toggle state stays consistent with the rendered reason. - Document the company-scoped (not user-scoped) DELETE authorization policy on the no-document-required route. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
627109b5bd
commit
a9b43ebeb7
@@ -67,27 +67,14 @@ describe('getAvailableVatRates', () => {
|
||||
expect(rates).toHaveLength(4)
|
||||
})
|
||||
|
||||
it('collapses to 0%/exempt for non-registered sellers regardless of customer type', () => {
|
||||
// ML 1 kap. 1§ — only a skattskyldig may charge output VAT. The picker
|
||||
// must never offer non-zero rates when vat_registered=false; the API
|
||||
// route (route.ts) and preview-pdf route enforce the same gate so a
|
||||
// client bypassing the UI also gets rejected.
|
||||
for (const customerType of ['individual', 'swedish_business', 'eu_business', 'non_eu_business'] as const) {
|
||||
const rates = getAvailableVatRates(customerType, false, false)
|
||||
expect(rates).toHaveLength(1)
|
||||
expect(rates[0]).toEqual({
|
||||
rate: 0,
|
||||
label: '0% (ej momsregistrerad)',
|
||||
treatment: 'exempt',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('defaults vatRegistered to true (legitimate VAT path)', () => {
|
||||
// Explicit default-arg pin so a future signature change doesn't silently
|
||||
// flip the default and strip VAT from invoices for registered sellers.
|
||||
const rates = getAvailableVatRates('swedish_business', false)
|
||||
it('does not gate on seller VAT-registration status', () => {
|
||||
// ML 16 kap. 23 § (faktureringsmoms): the picker offers the full
|
||||
// customer-type-based rate set regardless of whether the seller is
|
||||
// momsregistrerad. The invoice form surfaces a warning at submit time
|
||||
// when a non-registered seller picks a non-zero rate.
|
||||
const rates = getAvailableVatRates('swedish_business')
|
||||
expect(rates).toHaveLength(4)
|
||||
expect(rates.map((r) => r.rate)).toEqual([25, 12, 6, 0])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -179,23 +166,11 @@ describe('getVatRules', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('short-circuits to exempt / rate 0 / empty momsRuta for non-registered sellers', () => {
|
||||
// ML 1 kap. 1§ — non-skattskyldig cannot charge output VAT. momsRuta is
|
||||
// intentionally empty so a downstream momsdeklaration generator never
|
||||
// mis-files a non-registered seller's revenue into ruta 05.
|
||||
for (const customerType of ['individual', 'swedish_business', 'eu_business', 'non_eu_business'] as const) {
|
||||
const rules = getVatRules(customerType, false, false)
|
||||
expect(rules).toEqual({
|
||||
treatment: 'exempt',
|
||||
rate: 0,
|
||||
momsRuta: '',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('defaults vatRegistered to true (legitimate VAT path)', () => {
|
||||
// Explicit default-arg pin (see corresponding getAvailableVatRates test).
|
||||
const rules = getVatRules('swedish_business', false)
|
||||
it('does not gate on seller VAT-registration status', () => {
|
||||
// ML 16 kap. 23 § (faktureringsmoms): a non-registered seller who states
|
||||
// VAT still owes it. The rule output reflects the customer-type rate so
|
||||
// the booking is consistent with what the buyer sees on the invoice.
|
||||
const rules = getVatRules('swedish_business')
|
||||
expect(rules.rate).toBe(25)
|
||||
expect(rules.treatment).toBe('standard_25')
|
||||
expect(rules.momsRuta).toBe('05')
|
||||
|
||||
@@ -868,12 +868,12 @@ export function InvoicePDF({ invoice, customer, items, company, originalInvoiceN
|
||||
</View>
|
||||
))
|
||||
) : (
|
||||
// Suppress the "Moms 0%" row entirely when the seller is not
|
||||
// VAT-registered. ML 1 kap. 1§ — a non-skattskyldig may not
|
||||
// charge output VAT, so a "Moms 0%" line would imply VAT
|
||||
// accounting that doesn't exist. The notice block below the
|
||||
// payment section explains the absence of VAT.
|
||||
company.vat_registered !== false && (
|
||||
// Suppress the "Moms 0%" row only when the seller is not
|
||||
// VAT-registered AND the invoice actually carries no VAT.
|
||||
// A non-registered seller who states VAT (warned at create time
|
||||
// per ML 16 kap. 23 §) still gets the totals row so the printed
|
||||
// invoice matches what the customer is being asked to pay.
|
||||
!(company.vat_registered === false && invoice.vat_amount === 0) && (
|
||||
<View style={styles.totalRow}>
|
||||
<Text style={styles.totalLabel}>{L.vatRow(invoice.vat_rate ?? (vatByRate.size === 1 ? (vatByRate.keys().next().value ?? 0) : 0))}</Text>
|
||||
<Text style={styles.totalValue}>{formatCurrency(invoice.vat_amount, invoice.currency, lang)}</Text>
|
||||
@@ -1063,17 +1063,13 @@ export function InvoicePDF({ invoice, customer, items, company, originalInvoiceN
|
||||
)}
|
||||
|
||||
{/* Reverse charge / export / exempt / not-registered notice.
|
||||
"Not VAT-registered" trumps the others — when the seller is
|
||||
outside the VAT system entirely (vat_registered=false in
|
||||
company_settings), reverse-charge and ML 3 kap. exempt notices
|
||||
don't apply, and a single dedicated notice is clearer for the
|
||||
customer than reusing the exempt notice (which implies the sale
|
||||
specifically is exempt while the seller is otherwise within the
|
||||
VAT system). Server-side enforcement (api/invoices/route.ts +
|
||||
preview-pdf/route.ts) coerces vat_amount to 0 for non-registered
|
||||
sellers, so this branch always lines up with what's in the
|
||||
totals block. */}
|
||||
{company.vat_registered === false ? (
|
||||
"Not VAT-registered" trumps the others ONLY when the invoice
|
||||
actually carries no VAT — a non-registered seller who chose to
|
||||
state VAT on the invoice (warned at create time per ML 16 kap.
|
||||
23 §) gets the normal reverse-charge / exempt notices instead,
|
||||
since the "ej momsregistrerad" line would contradict the VAT
|
||||
shown in the totals block. */}
|
||||
{company.vat_registered === false && invoice.vat_amount === 0 ? (
|
||||
<View style={styles.reverseChargeBox}>
|
||||
<Text style={styles.reverseChargeText}>{L.notVatRegisteredNotice}</Text>
|
||||
</View>
|
||||
|
||||
@@ -12,22 +12,16 @@ export interface VatRateOption {
|
||||
* Swedish/EU-unvalidated customers can choose between 25%, 12%, 6%, and 0% (exempt).
|
||||
* Reverse charge and export customers are locked to 0%.
|
||||
*
|
||||
* When the seller is not VAT-registered (`vatRegistered=false`), every customer
|
||||
* type collapses to a single 0% / exempt option. ML 1 kap. 1§ — only a
|
||||
* skattskyldig person may charge VAT, so the picker must never offer non-zero
|
||||
* rates in that mode. ML 16 kap. 23 § (faktureringsmoms) imposes liability for
|
||||
* VAT erroneously stated on a document, but does NOT grant the right to charge
|
||||
* it — so we block at source rather than allow + warn.
|
||||
* The picker does NOT gate on the seller's VAT registration status. A
|
||||
* non-momsregistrerad seller is shown the same options as a registered one —
|
||||
* the form surfaces a warning at submit time (ML 16 kap. 23 § faktureringsmoms:
|
||||
* stated VAT is owed even by non-registered sellers, but the buyer cannot
|
||||
* deduct it as input VAT).
|
||||
*/
|
||||
export function getAvailableVatRates(
|
||||
customerType: CustomerType,
|
||||
vatNumberValidated: boolean = false,
|
||||
vatRegistered: boolean = true,
|
||||
): VatRateOption[] {
|
||||
if (!vatRegistered) {
|
||||
return [{ rate: 0, label: '0% (ej momsregistrerad)', treatment: 'exempt' }]
|
||||
}
|
||||
|
||||
// EU business with validated VAT → reverse charge, locked to 0%
|
||||
if (customerType === 'eu_business' && vatNumberValidated) {
|
||||
return [{ rate: 0, label: '0% (omvänd skattskyldighet)', treatment: 'reverse_charge' }]
|
||||
@@ -81,25 +75,14 @@ export interface VatRule {
|
||||
* - EU business without validated VAT: 25% VAT, moms ruta 05
|
||||
* - Non-EU business: 0% export, moms ruta 40
|
||||
*
|
||||
* When the seller is not VAT-registered (`vatRegistered=false`), the rules
|
||||
* short-circuit to `{ treatment: 'exempt', rate: 0, momsRuta: '' }` regardless
|
||||
* of customer type — ML 1 kap. 1§ bars a non-skattskyldig from charging output
|
||||
* VAT. `momsRuta` is empty so a downstream momsdeklaration generator never
|
||||
* mis-files a non-registered seller's "sales" into ruta 05.
|
||||
* Independent of the seller's VAT registration status. A non-momsregistrerad
|
||||
* seller who charges VAT still owes it under ML 16 kap. 23 § (faktureringsmoms),
|
||||
* so the rule output must reflect the rate actually charged on the line.
|
||||
*/
|
||||
export function getVatRules(
|
||||
customerType: CustomerType,
|
||||
vatNumberValidated: boolean = false,
|
||||
vatRegistered: boolean = true,
|
||||
): VatRule {
|
||||
if (!vatRegistered) {
|
||||
return {
|
||||
treatment: 'exempt',
|
||||
rate: 0,
|
||||
momsRuta: '',
|
||||
}
|
||||
}
|
||||
|
||||
switch (customerType) {
|
||||
case 'individual':
|
||||
case 'swedish_business':
|
||||
|
||||
Reference in New Issue
Block a user