Index: src/sections/invoice/invoice-details.tsx
===================================================================
--- src/sections/invoice/invoice-details.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-details.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -18,5 +18,5 @@
 import { fCurrency } from 'src/utils/format-number';
 // types
-import { Invoice } from 'src/schemas';
+import { Invoice } from 'mvpmasters-shared';
 // components
 import Label from 'src/components/label';
@@ -28,5 +28,4 @@
 import { getQuantityType } from 'src/utils/get-invoice-quantity-type';
 import InvoiceToolbar from './invoice-toolbar';
-import { updateInvoice } from 'src/api/invoice';
 
 // ----------------------------------------------------------------------
@@ -60,8 +59,5 @@
   const handleChangeStatus = useCallback(
     async (event: React.ChangeEvent<HTMLInputElement>) => {
-      // await updateDocument(collections.invoice, invoice.id, { status: event.target.value });
-      await updateInvoice(invoice.id, {
-        status: event.target.value as 'draft' | 'processing' | 'pending' | 'overdue' | 'paid',
-      });
+      await updateDocument(collections.invoice, invoice.id, { status: event.target.value });
       mutate([collections.invoice, invoice.id]);
     },
@@ -244,7 +240,7 @@
             {invoice.invoiceTo.name}
             <br />
-            {!!invoice.invoiceTo.companyNumber && (
+            {!!invoice.invoiceTo.companyId && (
               <>
-                Company ID: {invoice.invoiceTo.companyNumber}
+                Company ID: {invoice.invoiceTo.companyId}
                 <br />
               </>
@@ -261,5 +257,5 @@
               Date Issued
             </Typography>
-            {fDate(invoice.issueDate)}
+            {fDate(invoice.createDate.toDate())}
           </Stack>
 
@@ -268,5 +264,5 @@
               Due Date
             </Typography>
-            {fDate(invoice.dueDate)}
+            {fDate(invoice.dueDate.toDate())}
           </Stack>
         </Box>
Index: src/sections/invoice/invoice-ee-pdf.tsx
===================================================================
--- src/sections/invoice/invoice-ee-pdf.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-ee-pdf.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -5,5 +5,5 @@
 import { fCurrency } from 'src/utils/format-number';
 // types
-import { Invoice } from 'src/schemas';
+import { Invoice } from 'mvpmasters-shared';
 import { createFullAddress } from 'src/utils/create-full-address';
 import { getQuantityType } from 'src/utils/get-invoice-quantity-type';
@@ -129,5 +129,5 @@
     discount,
     invoiceTo,
-    issueDate,
+    createDate,
     totalAmount,
     invoiceFrom,
@@ -229,9 +229,9 @@
           <View style={styles.col6}>
             <Text style={[styles.subtitle1, styles.mb4]}>Date Issued</Text>
-            <Text style={styles.body2}>{fDate(issueDate)}</Text>
+            <Text style={styles.body2}>{fDate(createDate.toDate())}</Text>
           </View>
           <View style={styles.col6}>
             <Text style={[styles.subtitle1, styles.mb4]}>Due date</Text>
-            <Text style={styles.body2}>{fDate(dueDate)}</Text>
+            <Text style={styles.body2}>{fDate(dueDate.toDate())}</Text>
           </View>
         </View>
Index: src/sections/invoice/invoice-mk-pdf.tsx
===================================================================
--- src/sections/invoice/invoice-mk-pdf.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-mk-pdf.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -5,5 +5,5 @@
 import { fCurrency } from 'src/utils/format-number';
 // types
-import { Invoice } from 'src/schemas';
+import { Invoice } from 'mvpmasters-shared';
 import { createFullAddress } from 'src/utils/create-full-address';
 import { getQuantityType } from 'src/utils/get-invoice-quantity-type';
@@ -113,5 +113,5 @@
     discount,
     invoiceTo,
-    issueDate,
+    createDate,
     totalAmount,
     invoiceFrom,
@@ -179,9 +179,9 @@
           <View style={styles.col6}>
             <Text style={[styles.subtitle1, styles.mb4]}>Date Issued</Text>
-            <Text style={styles.body2}>{fDate(issueDate)}</Text>
+            <Text style={styles.body2}>{fDate(createDate.toDate())}</Text>
           </View>
           <View style={styles.col6}>
             <Text style={[styles.subtitle1, styles.mb4]}>Due date</Text>
-            <Text style={styles.body2}>{fDate(dueDate)}</Text>
+            <Text style={styles.body2}>{fDate(dueDate.toDate())}</Text>
           </View>
         </View>
Index: src/sections/invoice/invoice-new-edit-address.tsx
===================================================================
--- src/sections/invoice/invoice-new-edit-address.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-new-edit-address.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -7,5 +7,5 @@
 import Typography from '@mui/material/Typography';
 // hooks
-import { useGetTenant } from 'src/api/tenant';
+import { useGetSettings } from 'src/api/settings';
 import { useBoolean } from 'src/hooks/use-boolean';
 import { useResponsive } from 'src/hooks/use-responsive';
@@ -32,5 +32,5 @@
   const { invoiceFrom, invoiceTo } = values;
 
-  const { settings: tenant } = useGetTenant();
+  const { settings } = useGetSettings();
   const { customers } = useGetCustomers();
 
@@ -100,5 +100,5 @@
       </Stack>
 
-      {tenant && (
+      {settings && (
         <CompanyListDialog
           title="Companies"
@@ -106,6 +106,6 @@
           onClose={from.onFalse}
           selected={(selectedId: string) => invoiceFrom?.id === selectedId}
-          onSelect={(tenant) => setValue('invoiceFrom', tenant)}
-          tenant={tenant}
+          onSelect={(company) => setValue('invoiceFrom', company)}
+          list={[settings?.company, settings?.['company-ee']]}
           action={
             <Button
Index: src/sections/invoice/invoice-new-edit-details.tsx
===================================================================
--- src/sections/invoice/invoice-new-edit-details.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-new-edit-details.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -14,5 +14,5 @@
 import { fCurrency } from 'src/utils/format-number';
 // types
-import { InvoiceItem } from 'src/schemas';
+import { InvoiceItem } from 'mvpmasters-shared';
 // components
 import Iconify from 'src/components/iconify';
@@ -75,26 +75,14 @@
   const handleSelectService = useCallback(
     (index: number, option: string) => {
-      const service = invoiceServices.find((service) => service.id === option);
-      if (!service) return;
-
-      const quantityType = values.quantityType?.toLowerCase();
-      let price = 0;
-
-      switch (quantityType) {
-        case 'sprint':
-          price = service.sprint;
-          break;
-        case 'hour':
-          price = service.hour;
-          break;
-        case 'month':
-          price = service.month;
-          break;
-        default:
-          price = 0;
-      }
-
-      setValue(`items[${index}].price`, price);
-      setValue(`items[${index}].total`, values.items[index].quantity * price);
+      setValue(
+        `items[${index}].price`,
+        invoiceServices.find((service) => service.id === option)?.price?.[
+          values.quantityType?.toLowerCase() as 'sprint' | 'hour' | 'month'
+        ]
+      );
+      setValue(
+        `items[${index}].total`,
+        values.items.map((item: InvoiceItem) => item.quantity * item.price)[index]
+      );
     },
     [setValue, values.items, values.quantityType, invoiceServices]
Index: src/sections/invoice/invoice-new-edit-form.tsx
===================================================================
--- src/sections/invoice/invoice-new-edit-form.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-new-edit-form.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -11,5 +11,5 @@
 import { useRouter } from 'src/routes/hooks';
 // types
-import { CreateInvoice, Invoice } from 'src/schemas';
+import { Invoice } from 'mvpmasters-shared';
 // hooks
 import { useBoolean } from 'src/hooks/use-boolean';
@@ -20,13 +20,19 @@
 import uploadToFirebaseStorage from 'src/utils/upload-to-firebase-storage';
 import { pdf } from '@react-pdf/renderer';
-import { useGetTenant } from 'src/api/tenant';
-import { collections, generateId, updateDocument } from 'src/lib/firestore';
+import { useGetSettings } from 'src/api/settings';
+import {
+  collections,
+  documents,
+  firestoreBatch,
+  generateId,
+  updateDocument,
+} from 'src/lib/firestore';
 import { useGetServices } from 'src/api/service';
 import { mutate } from 'swr';
+import { Timestamp } from 'firebase/firestore';
 import InvoiceNewEditStatusDate from './invoice-new-edit-status-date';
 import InvoiceNewEditAddress from './invoice-new-edit-address';
 import InvoiceNewEditDetails from './invoice-new-edit-details';
 import InvoicePDF from './invoice-pdf';
-import { createInvoice, updateInvoice } from 'src/api/invoice';
 
 // ----------------------------------------------------------------------
@@ -52,13 +58,4 @@
 ];
 
-interface InvoiceItem {
-  service: string | null;
-  title: string;
-  price: number;
-  total: number;
-  quantity: number;
-  description: string;
-}
-
 export default function InvoiceNewEditForm({ isCopy, currentInvoice }: Props) {
   const router = useRouter();
@@ -72,7 +69,5 @@
     description: Yup.string().required('Description is required'),
     service: Yup.string().nullable(),
-    quantity: Yup.number()
-      .required('Quantity is required')
-      .min(0.5, 'Quantity must be at least 0.5'),
+    quantity: Yup.number().required('Quantity is required').min(0.5, 'Quantity must be at least 1'),
     price: Yup.number().required('Price is required').min(0, 'Price must be at least 0'),
     total: Yup.number().required('Total is required').min(0, 'Total must be at least 0'),
@@ -81,5 +76,5 @@
   const NewInvoiceSchema = Yup.object().shape({
     invoiceNumber: Yup.string().nullable().required('Invoice number is required'),
-    issueDate: Yup.mixed<any>().nullable().required('Create date is required'),
+    createDate: Yup.mixed<any>().nullable().required('Create date is required'),
     dueDate: Yup.mixed<any>()
       .required('Due date is required')
@@ -87,5 +82,5 @@
         'date-min',
         'Due date must be later than create date',
-        (value, { parent }) => value.getTime() > parent.issueDate.getTime()
+        (value, { parent }) => value.getTime() > parent.createDate.getTime()
       ),
     invoiceFrom: Yup.mixed<any>().nullable().required('Invoice from is required'),
@@ -96,5 +91,5 @@
       .required('Quantity type is required'),
     month: Yup.string().oneOf(monthNames).required('Month is required'),
-    status: Yup.string().oneOf(['draft', 'processing', 'pending', 'overdue', 'paid']).required(),
+    status: Yup.string().required(),
     totalAmount: Yup.number().required(),
     // not required
@@ -108,6 +103,5 @@
 
   const { services: invoiceServices } = useGetServices();
-  console.log('invoiceServices', invoiceServices);
-  const { settings: tenant, settingsEmpty, settingsLoading } = useGetTenant();
+  const { settings, settingsEmpty, settingsLoading } = useGetSettings();
 
   const defaultValues = useMemo(
@@ -116,9 +110,7 @@
         !isCopy && currentInvoice?.invoiceNumber
           ? currentInvoice?.invoiceNumber
-          : incrementInvoiceNumber(tenant?.lastInvoiceNumber),
-      issueDate: currentInvoice?.issueDate ? new Date(currentInvoice.issueDate) : new Date(),
-      dueDate: currentInvoice?.dueDate
-        ? new Date(currentInvoice.dueDate)
-        : new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
+          : incrementInvoiceNumber(settings?.invoice?.lastInvoiceNumber),
+      createDate: currentInvoice?.createDate?.toDate() || new Date(),
+      dueDate: currentInvoice?.dueDate?.toDate() || null,
       invoiceFrom: currentInvoice?.invoiceFrom || null,
       invoiceTo: currentInvoice?.invoiceTo || null,
@@ -146,5 +138,5 @@
       totalAmount: currentInvoice?.totalAmount || 0,
     }),
-    [currentInvoice, isCopy, tenant]
+    [currentInvoice, isCopy, settings]
   );
 
@@ -172,16 +164,6 @@
 
     try {
+      // generate collection id
       const id = generateId(collections.invoice);
-
-      // Ensure dates are valid Date objects
-      const issueDate = data.issueDate instanceof Date ? data.issueDate : new Date(data.issueDate);
-      const dueDate = data.dueDate instanceof Date ? data.dueDate : new Date(data.dueDate);
-
-      const currentTime = new Date();
-      issueDate.setHours(
-        currentTime.getHours(),
-        currentTime.getMinutes(),
-        currentTime.getSeconds()
-      );
 
       // attach serivce details
@@ -191,16 +173,21 @@
       }));
 
+      const currentTime = new Date();
+      const createDateWithCurrentTime = new Date(data.createDate); // This creates a date object using the date from data.createDate
+      // Set the time of createDateWithCurrentTime to the current hour, minutes, and seconds
+      createDateWithCurrentTime.setHours(
+        currentTime.getHours(),
+        currentTime.getMinutes(),
+        currentTime.getSeconds()
+      );
+
       // transform data
-      const writeData: CreateInvoice = {
+      const writeData = {
         ...data,
-        invoiceNumber: incrementInvoiceNumber(tenant?.lastInvoiceNumber),
+        invoiceNumber: incrementInvoiceNumber(settings?.invoice.lastInvoiceNumber),
         status: 'draft',
-        issueDate,
-        dueDate,
-        items: items.filter((item) => item.service !== null) as CreateInvoice['items'],
-        subTotal: data.totalAmount - (data.taxes || 0) - (data.discount || 0),
-        month: data.month as Invoice['month'],
-        invoiceFrom: data.invoiceFrom!,
-        invoiceTo: data.invoiceTo!,
+        createDate: Timestamp.fromDate(createDateWithCurrentTime),
+        dueDate: Timestamp.fromDate(new Date(data.dueDate)),
+        items,
       };
 
@@ -208,25 +195,23 @@
       const invoicePdf = <InvoicePDF invoice={writeData as Invoice} currentStatus="pending" />;
       const blob: Blob = await pdf(invoicePdf).toBlob();
-      const storagePath: string = `invoices/${writeData.invoiceTo.name}-${writeData.invoiceNumber}.pdf`;
+      const storagePath: string = `invoices/${writeData.invoiceTo.name}/${id}-${writeData.invoiceNumber}.pdf`;
       await uploadToFirebaseStorage(blob, storagePath);
 
       // write to DB
-      // await firestoreBatch([
-      //   {
-      //     docPath: `${collections.invoice}/${id}`,
-      //     type: 'set',
-      //     data: {
-      //       ...writeData,
-      //       pdfRef: storagePath,
-      //     },
-      //   },
-      //   {
-      //     docPath: `${collections.settings}/${documents.settingsInvoice}`,
-      //     type: 'set',
-      //     data: { lastInvoiceNumber: writeData.invoiceNumber },
-      //   },
-      // ]);
-
-      await createInvoice({ ...writeData, pdfRef: storagePath });
+      await firestoreBatch([
+        {
+          docPath: `${collections.invoice}/${id}`,
+          type: 'set',
+          data: {
+            ...writeData,
+            pdfRef: storagePath,
+          },
+        },
+        {
+          docPath: `${collections.settings}/${documents.settingsInvoice}`,
+          type: 'set',
+          data: { lastInvoiceNumber: writeData.invoiceNumber },
+        },
+      ]);
 
       loadingSave.onFalse();
@@ -244,9 +229,4 @@
     try {
       if (currentInvoice) {
-        // Ensure dates are valid Date objects
-        const issueDate =
-          data.issueDate instanceof Date ? data.issueDate : new Date(data.issueDate);
-        const dueDate = data.dueDate instanceof Date ? data.dueDate : new Date(data.dueDate);
-
         // attach serivce details
         const items = data.items.map((item) => ({
@@ -258,9 +238,7 @@
         const writeData = {
           ...data,
-          issueDate,
-          dueDate,
+          createDate: Timestamp.fromDate(new Date(data.createDate)),
+          dueDate: Timestamp.fromDate(new Date(data.dueDate)),
           items,
-          invoiceFrom: data.invoiceFrom!,
-          invoiceTo: data.invoiceTo!,
         };
 
@@ -268,50 +246,18 @@
         const invoicePdf = <InvoicePDF invoice={writeData as Invoice} currentStatus="pending" />;
         const blob: Blob = await pdf(invoicePdf).toBlob();
-        const storagePath: string = `invoices/${data.invoiceTo.name}-${data.invoiceNumber}.pdf`;
+        const storagePath: string = `invoices/${data.invoiceTo.name}/${currentInvoice.id}-${data.invoiceNumber}.pdf`;
         await uploadToFirebaseStorage(blob, storagePath);
 
         // update DB
-        // await updateDocument(collections.invoice, currentInvoice.id, {
-        //   ...writeData,
-        //   pdfRef: storagePath,
-        // });
-
-        await updateInvoice(currentInvoice.id, {
+        await updateDocument(collections.invoice, currentInvoice.id, {
           ...writeData,
           pdfRef: storagePath,
-          status: data.status as 'draft' | 'processing' | 'pending' | 'overdue' | 'paid',
-          month: data.month as
-            | 'January'
-            | 'February'
-            | 'March'
-            | 'April'
-            | 'May'
-            | 'June'
-            | 'July'
-            | 'August'
-            | 'September'
-            | 'October'
-            | 'November'
-            | 'December',
-          items: items.filter((item) => item.service !== null) as {
-            service: { id: string; month: number; name: string; sprint: number; hour: number };
-            title: string;
-            price: number;
-            total: number;
-            quantity: number;
-            description: string;
-          }[],
         });
 
         // mutate current data
-        // mutate([collections.invoice, currentInvoice.id]);
+        mutate([collections.invoice, currentInvoice.id]);
       } else {
         // generate collection id
         const id = generateId(collections.invoice);
-
-        // Ensure dates are valid Date objects
-        const issueDate =
-          data.issueDate instanceof Date ? data.issueDate : new Date(data.issueDate);
-        const dueDate = data.dueDate instanceof Date ? data.dueDate : new Date(data.dueDate);
 
         // attach serivce details
@@ -324,9 +270,7 @@
         const writeData = {
           ...data,
-          issueDate,
-          dueDate,
+          createDate: Timestamp.fromDate(new Date(data.createDate)),
+          dueDate: Timestamp.fromDate(new Date(data.dueDate)),
           items,
-          invoiceFrom: data.invoiceFrom!,
-          invoiceTo: data.invoiceTo!,
         };
 
@@ -334,24 +278,23 @@
         const invoicePdf = <InvoicePDF invoice={writeData as Invoice} currentStatus="pending" />;
         const blob: Blob = await pdf(invoicePdf).toBlob();
-        const storagePath: string = `invoices/${data.invoiceTo.name}-${data.invoiceNumber}.pdf`;
+        const storagePath: string = `invoices/${data.invoiceTo.name}/${id}-${data.invoiceNumber}.pdf`;
         await uploadToFirebaseStorage(blob, storagePath);
 
         // write to DB
-        // await firestoreBatch([
-        //   {
-        //     docPath: `${collections.invoice}/${id}`,
-        //     type: 'set',
-        //     data: {
-        //       ...writeData,
-        //       pdfRef: storagePath,
-        //     },
-        //   },
-        //   {
-        //     docPath: `${collections.settings}/${documents.settingsInvoice}`,
-        //     type: 'set',
-        //     data: { lastInvoiceNumber: writeData.invoiceNumber },
-        //   },
-        // ]);
-        await createInvoice({ ...writeData, pdfRef: storagePath });
+        await firestoreBatch([
+          {
+            docPath: `${collections.invoice}/${id}`,
+            type: 'set',
+            data: {
+              ...writeData,
+              pdfRef: storagePath,
+            },
+          },
+          {
+            docPath: `${collections.settings}/${documents.settingsInvoice}`,
+            type: 'set',
+            data: { lastInvoiceNumber: writeData.invoiceNumber },
+          },
+        ]);
 
         reset();
@@ -371,5 +314,5 @@
     <FormProvider methods={methods}>
       <Card>
-        {!!tenant && <InvoiceNewEditAddress />}
+        {settings?.company && <InvoiceNewEditAddress />}
 
         <InvoiceNewEditStatusDate isCopy={isCopy} />
Index: src/sections/invoice/invoice-new-edit-status-date.tsx
===================================================================
--- src/sections/invoice/invoice-new-edit-status-date.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-new-edit-status-date.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -7,5 +7,5 @@
 import { RHFSelect, RHFTextField } from 'src/components/hook-form';
 // api
-// import { useGetTenant } from 'src/api/settings';
+import { useGetSettings } from 'src/api/settings';
 // utils
 import { incrementInvoiceNumber } from 'src/utils/increment-invoice-number';
@@ -33,5 +33,5 @@
   const values = watch();
 
-  // const { settings } = useGetTenant();
+  const { settings } = useGetSettings();
 
   return (
@@ -109,5 +109,5 @@
 
       <Controller
-        name="issueDate"
+        name="createDate"
         control={control}
         render={({ field, fieldState: { error } }) => (
Index: src/sections/invoice/invoice-pdf.tsx
===================================================================
--- src/sections/invoice/invoice-pdf.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-pdf.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -1,3 +1,3 @@
-import { Invoice } from 'src/schemas';
+import { Invoice } from 'mvpmasters-shared';
 import InvoiceEEPDF from './invoice-ee-pdf';
 import InvoiceMKPDF from './invoice-mk-pdf';
Index: src/sections/invoice/invoice-table-filters-result.tsx
===================================================================
--- src/sections/invoice/invoice-table-filters-result.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-table-filters-result.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -6,5 +6,5 @@
 import Stack, { StackProps } from '@mui/material/Stack';
 // types
-import { InvoiceTableFilters, InvoiceTableFilterValue } from 'src/schemas';
+import { InvoiceTableFilters, InvoiceTableFilterValue } from 'mvpmasters-shared';
 // components
 import Iconify from 'src/components/iconify';
Index: src/sections/invoice/invoice-table-row.tsx
===================================================================
--- src/sections/invoice/invoice-table-row.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-table-row.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -16,5 +16,5 @@
 import { fNumber } from 'src/utils/format-number';
 // types
-import { Invoice } from 'src/schemas';
+import { Invoice } from 'mvpmasters-shared';
 // components
 import Label from 'src/components/label';
@@ -51,5 +51,5 @@
     sent,
     invoiceNumber,
-    issueDate,
+    createDate,
     dueDate,
     status,
@@ -59,6 +59,4 @@
     month,
   } = row;
-
-  console.log(issueDate);
 
   const confirmSend = useBoolean();
@@ -107,6 +105,6 @@
         <TableCell>
           <ListItemText
-            primary={format(new Date(issueDate), 'dd MMM yyyy')}
-            secondary={format(new Date(issueDate), 'p')}
+            primary={format(createDate.toDate(), 'dd MMM yyyy')}
+            secondary={format(createDate.toDate(), 'p')}
             primaryTypographyProps={{ typography: 'body2', noWrap: true }}
             secondaryTypographyProps={{
@@ -120,6 +118,6 @@
         <TableCell>
           <ListItemText
-            primary={format(new Date(dueDate), 'dd MMM yyyy')}
-            secondary={format(new Date(dueDate), 'p')}
+            primary={format(dueDate.toDate(), 'dd MMM yyyy')}
+            secondary={format(dueDate.toDate(), 'p')}
             primaryTypographyProps={{ typography: 'body2', noWrap: true }}
             secondaryTypographyProps={{
Index: src/sections/invoice/invoice-table-toolbar.tsx
===================================================================
--- src/sections/invoice/invoice-table-toolbar.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-table-toolbar.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -7,5 +7,5 @@
 import InputAdornment from '@mui/material/InputAdornment';
 // types
-import { InvoiceTableFilters, InvoiceTableFilterValue } from 'src/schemas';
+import { InvoiceTableFilters, InvoiceTableFilterValue } from 'mvpmasters-shared';
 // components
 import Iconify from 'src/components/iconify';
Index: src/sections/invoice/invoice-toolbar.tsx
===================================================================
--- src/sections/invoice/invoice-toolbar.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/invoice-toolbar.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -18,5 +18,5 @@
 import { useBoolean } from 'src/hooks/use-boolean';
 // types
-import { Invoice } from 'src/schemas';
+import { Invoice } from 'mvpmasters-shared';
 // components
 import Iconify from 'src/components/iconify';
Index: src/sections/invoice/mail-compose.tsx
===================================================================
--- src/sections/invoice/mail-compose.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/mail-compose.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -13,5 +13,5 @@
 import Iconify from 'src/components/iconify';
 import Editor from 'src/components/editor';
-import { Invoice } from 'src/schemas';
+import { Invoice } from 'mvpmasters-shared';
 import FormProvider from 'src/components/hook-form/form-provider';
 import { RHFTextField } from 'src/components/hook-form';
Index: src/sections/invoice/view/invoice-edit-view.tsx
===================================================================
--- src/sections/invoice/view/invoice-edit-view.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/view/invoice-edit-view.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -23,5 +23,4 @@
 
   const { currentInvoice } = useGetInvoice({ id });
-  console.log('currentInvoice', currentInvoice);
 
   return (
Index: src/sections/invoice/view/invoice-list-view.tsx
===================================================================
--- src/sections/invoice/view/invoice-list-view.tsx	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/sections/invoice/view/invoice-list-view.tsx	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -36,9 +36,14 @@
 } from 'src/components/table';
 // types
-import { Invoice, InvoiceStatus, InvoiceTableFilters, InvoiceTableFilterValue } from 'src/schemas';
+import {
+  Invoice,
+  InvoiceStatus,
+  InvoiceTableFilters,
+  InvoiceTableFilterValue,
+} from 'mvpmasters-shared';
 //
 import deleteFromFirebaseStorage from 'src/utils/delete-from-firebase-storage';
 // fetch
-import { useDeleteInvoice, useGetInvoices } from 'src/api/invoice';
+import { useGetInvoices } from 'src/api/invoice';
 import { collections, removeDocument } from 'src/lib/firestore';
 import { mutate } from 'swr';
@@ -49,6 +54,4 @@
 import InvoiceTableToolbar from '../invoice-table-toolbar';
 import MailCompose from '../mail-compose';
-import { useFetchAnalytics } from 'src/api/invoice/use-fetch-analytics';
-import { endpoints } from 'src/utils/axios';
 
 // ----------------------------------------------------------------------
@@ -59,5 +62,5 @@
   { id: 'currency', label: 'Currency' },
   { id: 'invoicePeriod', label: 'Invoice Period' },
-  { id: 'issueDate', label: 'Create' },
+  { id: 'createDate', label: 'Create' },
   { id: 'dueDate', label: 'Due' },
   { id: 'sent', label: 'Sent', align: 'center' },
@@ -152,5 +155,5 @@
 
   const table = useTable({
-    defaultOrderBy: 'issueDate',
+    defaultOrderBy: 'createDate',
     defaultOrder: 'desc',
     defaultDense: true,
@@ -160,5 +163,9 @@
   const [filters, setFilters] = useState(defaultFilters);
 
-  const { invoices: tableData } = useGetInvoices({ startDate: filters.startDate?.toISOString() });
+  const { invoices: tableData } = useGetInvoices({
+    where: [['createDate', '>=', filters.startDate]],
+    orderBy: 'createDate',
+    direction: 'desc',
+  });
 
   const invoiceMutationKey = useMemo(
@@ -166,6 +173,6 @@
       collections.invoice,
       JSON.stringify({
-        where: [['issueDate', '>=', filters.startDate]],
-        orderBy: 'issueDate',
+        where: [['createDate', '>=', filters.startDate]],
+        orderBy: 'createDate',
         direction: 'desc',
       }),
@@ -210,21 +217,13 @@
   //   );
 
-  const {
-    analytics: analyticsData,
-    isAnalyticsLoading,
-    analyticsError,
-  } = useFetchAnalytics(filters.startDate);
-
   useEffect(() => {
-    if (analyticsData) {
-      setAnalytics(analyticsData);
+    if (tableData) {
+      const getAnalytics = async () => {
+        const analyticsStats = await getTotalAmountForAllStatuses(tableData);
+        setAnalytics(analyticsStats);
+      };
+      getAnalytics();
     }
-  }, [analyticsData]);
-
-  useEffect(() => {
-    if (analyticsError) {
-      console.error('Failed to load analytics:', analyticsError);
-    }
-  }, [analyticsError]);
+  }, [tableData]);
 
   const getPercentByStatus = (status: string) =>
@@ -270,20 +269,26 @@
   );
 
-  const { deleteInvoiceMutation } = useDeleteInvoice();
-
   const handleDeleteRow = useCallback(
     async (invoice: Invoice) => {
       const serializedParams = JSON.stringify({
-        where: [['issueDate', '>=', filters.startDate]],
-        orderBy: 'issueDate',
+        where: [['createDate', '>=', filters.startDate]],
+        orderBy: 'createDate',
         direction: 'desc',
-      });
-
-      await deleteInvoiceMutation(invoice.id);
+      }); // Get the same params as used in useGetInvoices
+
+      // Optimistically update the cache before the deletion
+      // mutate(
+      //   [collections.invoice, serializedParams],
+      //   (invoices: Invoice[] = []) => invoices.filter((row) => row.id !== invoice.id),
+      //   false
+      // );
+
+      await removeDocument(collections.invoice, invoice.id);
       await deleteFromFirebaseStorage(
-        `invoices/${invoice.invoiceTo.name}-${invoice.invoiceNumber}.pdf`
+        `invoices/${invoice.invoiceTo.name}/${invoice.id}-${invoice.invoiceNumber}.pdf`
       );
 
-      mutate(endpoints.invoice);
+      // Optionally, rollback optimistic update or refetch data
+      mutate(invoiceMutationKey);
     },
     [filters.startDate, invoiceMutationKey]
@@ -342,8 +347,4 @@
     setFilters(defaultFilters);
   }, []);
-
-  if (isAnalyticsLoading) {
-    // Show loading state
-  }
 
   return (
@@ -671,6 +672,6 @@
       inputData = inputData.filter(
         (invoice) =>
-          fTimestamp(invoice.issueDate.getTime()) >= fTimestamp(startDate.getTime()) &&
-          fTimestamp(invoice.issueDate.getTime()) <= fTimestamp(endDate.getTime())
+          fTimestamp(invoice.createDate.toMillis()) >= fTimestamp(startDate) &&
+          fTimestamp(invoice.createDate.toMillis()) <= fTimestamp(endDate)
       );
     }
