fix test failure
Build & Push / Pipeline Tests (push) Successful in 1m54s
Test / Type Check (all packages) (push) Successful in 53s
Build & Push / Build & Push Docker Image (push) Successful in 5m13s
Test / API Unit Tests (push) Successful in 1m18s
Test / Homepage Unit Tests (push) Successful in 48s
Test / Carplace Unit Tests (push) Successful in 41s
Test / Admin Unit Tests (push) Successful in 41s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m8s
Build & Push / Pipeline Tests (push) Successful in 1m54s
Test / Type Check (all packages) (push) Successful in 53s
Build & Push / Build & Push Docker Image (push) Successful in 5m13s
Test / API Unit Tests (push) Successful in 1m18s
Test / Homepage Unit Tests (push) Successful in 48s
Test / Carplace Unit Tests (push) Successful in 41s
Test / Admin Unit Tests (push) Successful in 41s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m8s
This commit is contained in:
@@ -850,7 +850,10 @@ export async function finalizeInvoice(invoiceId: string, adminId: string, ip?: s
|
|||||||
}
|
}
|
||||||
|
|
||||||
const taxBase = Math.max(preTaxBase - autoCreditToApply, 0)
|
const taxBase = Math.max(preTaxBase - autoCreditToApply, 0)
|
||||||
const { taxRate, taxAmount } = calculateTaxAmount(taxBase, account.taxExempt, platformBillingSettings.taxRate)
|
const shouldApplyTax = current.invoiceType !== 'MANUAL'
|
||||||
|
const { taxRate, taxAmount } = shouldApplyTax
|
||||||
|
? calculateTaxAmount(taxBase, account.taxExempt, platformBillingSettings.taxRate)
|
||||||
|
: { taxRate: 0, taxAmount: 0 }
|
||||||
|
|
||||||
if (taxAmount > 0) {
|
if (taxAmount > 0) {
|
||||||
await tx.billingInvoiceLineItem.create({
|
await tx.billingInvoiceLineItem.create({
|
||||||
|
|||||||
@@ -950,16 +950,23 @@ function safeSubmission(submission: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getCanonicalInvoices(companyId: string) {
|
export async function getCanonicalInvoices(companyId: string) {
|
||||||
const invoices = await prisma.billingInvoice.findMany({
|
const [invoices, legacyInvoices] = await Promise.all([
|
||||||
where: { companyId, subscriptionId: { not: null }, status: 'PAID' },
|
prisma.billingInvoice.findMany({
|
||||||
include: {
|
where: { companyId, subscriptionId: { not: null } },
|
||||||
manualPaymentSubmissions: { orderBy: { createdAt: 'desc' }, include: { documents: { orderBy: { uploadedAt: 'asc' } } } },
|
include: {
|
||||||
paymentAttempts: { where: { status: 'SUCCEEDED' }, orderBy: { attemptedAt: 'desc' }, take: 1 },
|
manualPaymentSubmissions: { orderBy: { createdAt: 'desc' }, include: { documents: { orderBy: { uploadedAt: 'asc' } } } },
|
||||||
},
|
paymentAttempts: { where: { status: 'SUCCEEDED' }, orderBy: { attemptedAt: 'desc' }, take: 1 },
|
||||||
orderBy: { createdAt: 'desc' },
|
},
|
||||||
take: 50,
|
orderBy: { createdAt: 'desc' },
|
||||||
})
|
take: 50,
|
||||||
return invoices.map((invoice: any) => ({
|
}),
|
||||||
|
prisma.subscriptionInvoice.findMany({
|
||||||
|
where: { companyId, billingInvoiceId: null },
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
take: 50,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
const canonical = invoices.map((invoice: any) => ({
|
||||||
id: invoice.id,
|
id: invoice.id,
|
||||||
invoiceNumber: invoice.invoiceNumber,
|
invoiceNumber: invoice.invoiceNumber,
|
||||||
amount: invoice.totalAmount,
|
amount: invoice.totalAmount,
|
||||||
@@ -981,6 +988,27 @@ export async function getCanonicalInvoices(companyId: string) {
|
|||||||
? safeSubmission(invoice.manualPaymentSubmissions[0])
|
? safeSubmission(invoice.manualPaymentSubmissions[0])
|
||||||
: null,
|
: null,
|
||||||
}))
|
}))
|
||||||
|
const legacy = legacyInvoices.map((invoice: any) => ({
|
||||||
|
id: invoice.id,
|
||||||
|
invoiceNumber: null,
|
||||||
|
amount: invoice.amount,
|
||||||
|
amountPaid: invoice.status === 'PAID' ? invoice.amount : 0,
|
||||||
|
amountDue: invoice.status === 'PAID' ? 0 : invoice.amount,
|
||||||
|
currency: invoice.currency,
|
||||||
|
status: invoice.status,
|
||||||
|
paymentProvider: invoice.paymentProvider,
|
||||||
|
collectionMethod: invoice.paymentProvider === 'STRIPE' ? 'STRIPE' : 'BANK_TRANSFER',
|
||||||
|
requestedPlan: invoice.requestedPlan,
|
||||||
|
requestedBillingPeriod: invoice.requestedBillingPeriod,
|
||||||
|
dueAt: invoice.dueAt,
|
||||||
|
paidAt: invoice.paidAt,
|
||||||
|
createdAt: invoice.createdAt,
|
||||||
|
confirmedReference: null,
|
||||||
|
manualPaymentSubmission: null,
|
||||||
|
}))
|
||||||
|
return [...canonical, ...legacy]
|
||||||
|
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
|
||||||
|
.slice(0, 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPaidInvoicePdf(companyId: string, invoiceId: string) {
|
export async function getPaidInvoicePdf(companyId: string, invoiceId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user