Fix/supp ag fb (#1023)
* fix: prevent credit notes from entering payment flow * fix: persist and display customer personal numbers * feat: configure automatic invoice reminder days * fix: issue credit notes through send flow * chore: add repository agent guidance * feat(mcp): route tools across user companies * fix(articles): delete unused register entries * feat(invoices): improve issued invoice actions * feat(supplier-invoices): retain uploaded source documents * docs: record implementation decisions * feat: enhance customer personal number handling and validation - Updated CustomerForm to allow personal numbers in the format of "********-1234" for individual customers. - Added validation to ensure personal numbers are only accepted for individual customers in CreateCustomerSchema. - Implemented masking and encryption for personal numbers to enhance data protection. - Introduced new utility functions for masking and encrypting personal numbers. - Added database migration to enforce unique constraints on credit note relationships and prevent duplicate entries. - Enhanced error handling and logging for credit note issuance and invoice processing. - Updated tests to cover new credit note creation guards and personal number handling. * test: enhance list companies test with supabase query mocks
This commit is contained in:
@@ -453,6 +453,45 @@ describe('createCreditNoteJournalEntry: per-line VAT', () => {
|
||||
const totalCredit = input.lines.reduce((sum, l) => sum + l.credit_amount, 0)
|
||||
expect(totalDebit).toBe(totalCredit)
|
||||
})
|
||||
|
||||
it.each([
|
||||
['rot' as const, 3000, 9500],
|
||||
['rut' as const, 5000, 7500],
|
||||
])('reverses the %s receivable split across 1510 and 1513', async (deductionType, taxCredit, customerCredit) => {
|
||||
const creditNote = makeInvoice({
|
||||
invoice_number: 'KR-1002',
|
||||
subtotal: -10000,
|
||||
vat_amount: -2500,
|
||||
total: -12500,
|
||||
vat_treatment: 'standard_25',
|
||||
items: [
|
||||
makeItem({
|
||||
quantity: -1,
|
||||
unit_price: 10000,
|
||||
line_total: -10000,
|
||||
vat_rate: 25,
|
||||
vat_amount: -2500,
|
||||
deduction_type: deductionType,
|
||||
dimensions: { '6': 'P001' },
|
||||
}),
|
||||
],
|
||||
default_dimensions: { '1': 'KS01' },
|
||||
})
|
||||
|
||||
await createCreditNoteJournalEntry(null as never, 'company-1', 'user-1', creditNote)
|
||||
const input = mockedCreateEntry.mock.calls[0][3]
|
||||
|
||||
expect(input.lines.find((line) => line.account_number === '1510')?.credit_amount)
|
||||
.toBe(customerCredit)
|
||||
const line1513 = input.lines.find((line) => line.account_number === '1513')
|
||||
expect(line1513?.credit_amount).toBe(taxCredit)
|
||||
expect(line1513?.debit_amount).toBe(0)
|
||||
expect(line1513?.dimensions).toEqual({ '1': 'KS01', '6': 'P001' })
|
||||
|
||||
const totalDebit = input.lines.reduce((sum, line) => sum + line.debit_amount, 0)
|
||||
const totalCredit = input.lines.reduce((sum, line) => sum + line.credit_amount, 0)
|
||||
expect(totalDebit).toBe(totalCredit)
|
||||
})
|
||||
})
|
||||
|
||||
describe('createInvoiceCashEntry: per-line VAT', () => {
|
||||
|
||||
@@ -30,6 +30,7 @@ function makeInvoiceInput(overrides: Partial<{
|
||||
currency: string
|
||||
exchange_rate: number | null
|
||||
vat_treatment: VatTreatment
|
||||
credited_invoice_id: string | null
|
||||
items: InvoiceItem[]
|
||||
default_dimensions: Record<string, string> | null
|
||||
}> = {}) {
|
||||
@@ -77,6 +78,71 @@ describe('proposeSendLines', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('credit note uses positive amounts on the reversed sides', () => {
|
||||
const lines = proposeSendLines({
|
||||
invoice: makeInvoiceInput({
|
||||
invoice_number: 'KR-2025-001',
|
||||
credited_invoice_id: 'invoice-1',
|
||||
total: -12500,
|
||||
subtotal: -10000,
|
||||
vat_amount: -2500,
|
||||
items: [
|
||||
makeItem({ quantity: -1, line_total: -10000, vat_amount: -2500 }),
|
||||
],
|
||||
}),
|
||||
entityType: 'enskild_firma',
|
||||
})
|
||||
|
||||
expect(lines).toEqual([
|
||||
{
|
||||
account_number: '1510',
|
||||
debit_amount: '',
|
||||
credit_amount: '12500',
|
||||
line_description: 'Kreditfaktura KR-2025-001',
|
||||
},
|
||||
{
|
||||
account_number: '3001',
|
||||
debit_amount: '10000',
|
||||
credit_amount: '',
|
||||
line_description: 'Kreditfaktura KR-2025-001',
|
||||
},
|
||||
{
|
||||
account_number: '2611',
|
||||
debit_amount: '2500',
|
||||
credit_amount: '',
|
||||
line_description: 'Moms kreditfaktura 25%',
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('credit-note preview reverses the ROT receivable split', () => {
|
||||
const lines = proposeSendLines({
|
||||
invoice: makeInvoiceInput({
|
||||
invoice_number: 'KR-2025-002',
|
||||
credited_invoice_id: 'invoice-2',
|
||||
total: -12500,
|
||||
subtotal: -10000,
|
||||
vat_amount: -2500,
|
||||
items: [
|
||||
makeItem({
|
||||
quantity: -1,
|
||||
line_total: -10000,
|
||||
vat_amount: -2500,
|
||||
deduction_type: 'rot',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
entityType: 'enskild_firma',
|
||||
})
|
||||
|
||||
expect(lines.find((line) => line.account_number === '1510')?.credit_amount).toBe('9500')
|
||||
expect(lines.find((line) => line.account_number === '1513')?.credit_amount).toBe('3000')
|
||||
expect(lines.reduce((sum, line) => sum + (parseFloat(line.debit_amount) || 0), 0))
|
||||
.toBe(12500)
|
||||
expect(lines.reduce((sum, line) => sum + (parseFloat(line.credit_amount) || 0), 0))
|
||||
.toBe(12500)
|
||||
})
|
||||
|
||||
describe('dimensions propagation (PR7)', () => {
|
||||
const bag = { '1': 'KS01', '6': 'P001' }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user