Index: src/app/api/invoices/[id]/route.ts
===================================================================
--- src/app/api/invoices/[id]/route.ts	(revision 057453cdc828f504e8bcd813422d99221b3b5732)
+++ src/app/api/invoices/[id]/route.ts	(revision 299af01b89703f010e0519c717f8e1c8bb9bb299)
@@ -90,5 +90,5 @@
       // Conditionally delete and recreate items only if they are provided
       if (validation.data.items) {
-        await tx.invoiceItem.deleteMany({
+        await tx.lineItem.deleteMany({
           where: { invoiceId: params.id },
         });
@@ -174,5 +174,5 @@
     await prisma.$transaction(async (tx) => {
       // Delete related items first
-      await tx.invoiceItem.deleteMany({
+      await tx.lineItem.deleteMany({
         where: { invoiceId: params.id },
       });
Index: src/app/api/invoices/route.ts
===================================================================
--- src/app/api/invoices/route.ts	(revision 057453cdc828f504e8bcd813422d99221b3b5732)
+++ src/app/api/invoices/route.ts	(revision 299af01b89703f010e0519c717f8e1c8bb9bb299)
@@ -24,7 +24,7 @@
   try {
     const userId = await getUserId(request);
-    if (!userId) {
-      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
-    }
+    // if (!userId) {
+    //   return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
+    // }
 
     const searchParams = request.nextUrl.searchParams;
@@ -74,7 +74,7 @@
   try {
     const userId = await getUserId(request);
-    if (!userId) {
-      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
-    }
+    // if (!userId) {
+    //   return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
+    // }
 
     const body = await request.json();
Index: src/app/api/invoices/totals/route.ts
===================================================================
--- src/app/api/invoices/totals/route.ts	(revision 299af01b89703f010e0519c717f8e1c8bb9bb299)
+++ src/app/api/invoices/totals/route.ts	(revision 299af01b89703f010e0519c717f8e1c8bb9bb299)
@@ -0,0 +1,71 @@
+import { NextRequest, NextResponse } from 'next/server';
+import prisma from 'src/lib/prisma';
+import { authenticateRequest } from 'src/lib/auth-middleware';
+
+type InvoiceStatus = 'processing' | 'paid' | 'pending' | 'overdue' | 'draft';
+type CurrencyTotals = { EUR: number; USD: number };
+type Results = Record<InvoiceStatus | 'total', CurrencyTotals>;
+
+export async function GET(request: NextRequest) {
+  try {
+    // Authenticate the request
+    const authResult = await authenticateRequest(request);
+
+    if (!authResult || authResult instanceof NextResponse) {
+      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
+    }
+
+    const { userId, tenantId } = authResult;
+
+    const searchParams = request.nextUrl.searchParams;
+    const startDate = searchParams.get('startDate')
+      ? new Date(searchParams.get('startDate')!)
+      : null;
+
+    if (!startDate) {
+      return NextResponse.json({ error: 'Start date is required' }, { status: 400 });
+    }
+
+    // Calculate totals using raw SQL
+    const totals = await prisma.$queryRaw`
+      SELECT 
+        status,
+        currency,
+        SUM("totalAmount") as total
+      FROM "Invoice"
+      WHERE "createDate" >= ${startDate}
+        AND "invoiceFromId" = ${tenantId}
+      GROUP BY status, currency
+    `;
+
+    // Format the response
+    const results: Results = {
+      total: { EUR: 0, USD: 0 },
+      processing: { EUR: 0, USD: 0 },
+      paid: { EUR: 0, USD: 0 },
+      pending: { EUR: 0, USD: 0 },
+      overdue: { EUR: 0, USD: 0 },
+      draft: { EUR: 0, USD: 0 },
+    };
+
+    // Process the results - adjusted for raw SQL response format
+    for (const row of totals as {
+      status: string;
+      currency: 'EUR' | 'USD';
+      total: string | number;
+    }[]) {
+      const { status, currency, total } = row;
+      const statusKey = status.toLowerCase() as InvoiceStatus;
+      if (statusKey in results && (currency === 'EUR' || currency === 'USD')) {
+        const amount = Number(total) || 0;
+        results[statusKey][currency] = amount;
+        results.total[currency] += amount;
+      }
+    }
+
+    return NextResponse.json(results);
+  } catch (error) {
+    console.error('Error calculating totals:', error);
+    return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
+  }
+}
