New Base func

This commit is contained in:
Jakob Wennberg
2026-02-19 09:48:02 +01:00
parent afc9f69def
commit cdf1dcc4c8
73 changed files with 11036 additions and 51 deletions
+9
View File
@@ -1,5 +1,7 @@
import { createClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'
import { eventBus } from '@/lib/events'
import { ensureInitialized } from '@/lib/init'
import { renderToBuffer } from '@react-pdf/renderer'
import { InvoicePDF } from '@/lib/invoice/pdf-template'
import { sendEmail, isResendConfigured } from '@/lib/email/resend'
@@ -10,6 +12,8 @@ import {
} from '@/lib/email/invoice-templates'
import type { Invoice, InvoiceItem, Customer, CompanySettings } from '@/types'
ensureInitialized()
export async function POST(
request: Request,
{ params }: { params: Promise<{ id: string }> }
@@ -154,6 +158,11 @@ export async function POST(
// Don't fail the request - the email was sent successfully
}
await eventBus.emit({
type: 'invoice.sent',
payload: { invoice: invoice as Invoice, userId: user.id },
})
return NextResponse.json({
success: true,
message: `Fakturan har skickats till ${customer.email}`,
+15 -1
View File
@@ -1,6 +1,8 @@
import { createClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'
import type { CreateInvoiceInput, Invoice } from '@/types'
import { eventBus } from '@/lib/events'
import { ensureInitialized } from '@/lib/init'
import type { CreateInvoiceInput, Invoice, CreditNote } from '@/types'
import { getVatRules, calculateVat, calculateTotal } from '@/lib/invoice/vat-rules'
import { fetchExchangeRate, convertToSEK } from '@/lib/currency/riksbanken'
import {
@@ -8,6 +10,8 @@ import {
createCreditNoteJournalEntry,
} from '@/lib/bookkeeping/invoice-entries'
ensureInitialized()
interface CreateCreditNoteInput {
credited_invoice_id: string
reason?: string
@@ -189,6 +193,11 @@ export async function POST(request: Request) {
console.error('Failed to create invoice journal entry:', err)
// Don't fail the invoice creation
}
await eventBus.emit({
type: 'invoice.created',
payload: { invoice: completeInvoice as Invoice, userId: user.id },
})
}
return NextResponse.json({ data: completeInvoice })
@@ -316,6 +325,11 @@ async function createCreditNote(
} catch (err) {
console.error('Failed to create credit note journal entry:', err)
}
await eventBus.emit({
type: 'credit_note.created',
payload: { creditNote: completeCreditNote as CreditNote, userId },
})
}
return NextResponse.json({ data: completeCreditNote })