cc7050f6cb
Intl sv-SE formats negatives with U+2212, which the bundled react-pdf Helvetica/Courier fonts cannot render, so a loss printed as a profit. lib/pdf/number-text.ts pdfNumberText maps U+2212 to an ASCII hyphen and prints negative zero unsigned; routed through financial-statement, kassaflodesanalys, reskontra, momsdeklaration, payslip (fmt, the literal Preliminar skatt sign and the calculation formula text) and operational-report templates, with content-stream regression tests. The K2/K3 arsredovisning templates keep main's formatPdfKronor from #2013. Closes #1982
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
||
import { renderToBuffer } from '@react-pdf/renderer'
|
||
import { VatDeclarationPDF } from '../vat-declaration-pdf-template'
|
||
import type { CompanySettings } from '@/types'
|
||
import { pdfTextStrings } from '@/tests/pdf-text'
|
||
|
||
function fakeCompany(): CompanySettings {
|
||
return {
|
||
company_name: 'Testbolaget AB',
|
||
org_number: '5566778899',
|
||
vat_number: 'SE556677889901',
|
||
} as unknown as CompanySettings
|
||
}
|
||
|
||
describe('VatDeclarationPDF sign rendering (issue #1982)', () => {
|
||
it('prints a negative ruta with an ASCII minus the bundled font can draw', async () => {
|
||
const text = pdfTextStrings(
|
||
await renderToBuffer(
|
||
VatDeclarationPDF({
|
||
rows: [
|
||
{ ruta: '05', label: 'Momspliktig försäljning', amount: 100000 },
|
||
{ ruta: '10', label: 'Utgående moms 25 %', amount: 25000 },
|
||
// A credit-note-heavy period can push a ruta below zero.
|
||
{ ruta: '48', label: 'Ingående moms att dra av', amount: -1234 },
|
||
{ ruta: '49', label: 'Moms att betala', amount: 26234, isNet: true },
|
||
],
|
||
period: { start: '2026-04-01', end: '2026-06-30' },
|
||
periodLabel: 'April till juni 2026',
|
||
company: fakeCompany(),
|
||
generatedAt: '2026-08-29T10:00:00Z',
|
||
})
|
||
)
|
||
).join('\n')
|
||
|
||
expect(text).toContain('-1 234')
|
||
expect(text).toContain('26 234')
|
||
expect(text).not.toContain(String.fromCharCode(0x12))
|
||
expect(text).not.toContain('−')
|
||
}, 30_000)
|
||
})
|