fix: update RPC calls to use company_id instead of user_id for invoice and arrival number generation (#154)

This commit is contained in:
Mattsson
2026-03-31 17:34:51 +02:00
committed by GitHub
parent 0dd1f5ebc1
commit fad4899cb4
14 changed files with 23 additions and 15 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ export async function POST(
// Generate real invoice number
const { data: invoiceNumber } = await supabase.rpc('generate_invoice_number', {
p_user_id: user.id,
p_company_id: companyId,
})
// Create the real invoice
+2 -2
View File
@@ -166,12 +166,12 @@ export async function POST(request: Request) {
let invoiceNumber: string
if (documentType === 'delivery_note') {
const { data: dnNumber } = await supabase.rpc('generate_delivery_note_number', {
p_user_id: user.id,
p_company_id: companyId,
})
invoiceNumber = dnNumber
} else {
const { data: baseNumber } = await supabase.rpc('generate_invoice_number', {
p_user_id: user.id,
p_company_id: companyId,
})
invoiceNumber = documentType === 'proforma'
? `PF-${baseNumber}`
@@ -340,7 +340,7 @@ async function commitCreateInvoice(
// Generate invoice number
const { data: invoiceNumber } = await supabase.rpc('generate_invoice_number', {
p_user_id: userId,
p_company_id: companyId,
})
// Create invoice
+3 -3
View File
@@ -73,7 +73,7 @@ export async function POST() {
// 3. Seed chart of accounts via RPC
const { error: coaError } = await supabase.rpc('seed_chart_of_accounts', {
p_user_id: userId,
p_company_id: companyId,
p_entity_type: 'enskild_firma',
})
if (coaError) throw coaError
@@ -294,7 +294,7 @@ export async function POST() {
// 9. Create journal entries (inserted directly, not via engine, to avoid event emission)
const { data: voucherNum1 } = await supabase.rpc('next_voucher_number', {
p_user_id: userId,
p_company_id: companyId,
p_fiscal_period_id: fiscalPeriod.id,
p_series: 'A',
})
@@ -320,7 +320,7 @@ export async function POST() {
if (je1Error) throw je1Error
const { data: voucherNum2 } = await supabase.rpc('next_voucher_number', {
p_user_id: userId,
p_company_id: companyId,
p_fiscal_period_id: fiscalPeriod.id,
p_series: 'A',
})
@@ -44,7 +44,7 @@ export async function POST(
// Get next arrival number
const { data: arrivalNum } = await supabase
.rpc('get_next_arrival_number', { p_user_id: user.id })
.rpc('get_next_arrival_number', { p_company_id: companyId })
// Create credit note invoice (negative amounts)
const { data: creditNote, error: creditError } = await supabase
@@ -123,6 +123,8 @@ export async function POST(
const { error: paymentError } = await supabase
.from('supplier_invoice_payments')
.insert({
user_id: user.id,
company_id: companyId,
supplier_invoice_id: id,
payment_date: paymentDate,
amount: paymentAmount,
+1 -1
View File
@@ -75,7 +75,7 @@ export async function POST(request: Request) {
// Get next arrival number
const { data: arrivalNum, error: arrivalError } = await supabase
.rpc('get_next_arrival_number', { p_user_id: user.id })
.rpc('get_next_arrival_number', { p_company_id: companyId })
if (arrivalError) {
return NextResponse.json({ error: 'Failed to get arrival number' }, { status: 500 })