Selaa lähdekoodia

Excluding header row when showing summary row data.

vtugulan 1 kuukausi sitten
vanhempi
sitoutus
0e14fc1983

+ 24 - 2
app/lib/excel-import/database-excel-reader.ts

@@ -198,8 +198,8 @@ export class DatabaseExcelReaderService {
         }
       }
 
-      // Only add non-empty rows
-      if (Object.keys(rowData).length > 0) {
+      // Only add non-empty, non-header rows
+      if (Object.keys(rowData).length > 0 && !this.isCintasHeaderRow(section.tableName, rowData)) {
         data.push(rowData);
       }
 
@@ -234,6 +234,28 @@ export class DatabaseExcelReaderService {
     return result;
   }
 
+  private isCintasHeaderRow(tableName: string, rowData: Record<string, any>): boolean {
+    if (tableName !== 'cintas_install_calendar') {
+      return false;
+    }
+
+    const values = Object.values(rowData)
+      .map((value) => (typeof value === 'string' ? value.trim().toLowerCase() : ''))
+      .filter(Boolean);
+
+    if (values.length === 0) {
+      return false;
+    }
+
+    if (values.includes('date of install')) {
+      return true;
+    }
+
+    const hasOpportunityHeader = values.includes('opportunity status');
+    const hasTrrHeader = values.includes('trr');
+    return hasOpportunityHeader && hasTrrHeader;
+  }
+
   private parseCellAddress(cellPosition: string, rowNumber: number): { row: number; col: number } {
 
     let match = cellPosition.match(/([A-Z]+)(\d+)/);

+ 24 - 2
app/lib/excel-import/excel-reader.ts

@@ -132,8 +132,8 @@ export class ExcelReaderService {
         }
       }
 
-      // Only add non-empty rows
-      if (Object.keys(rowData).length > 0) {
+      // Only add non-empty, non-header rows
+      if (Object.keys(rowData).length > 0 && !this.isCintasHeaderRow(section.tableName, rowData)) {
         data.push(rowData);
       }
 
@@ -174,6 +174,28 @@ export class ExcelReaderService {
     return result;
   }
 
+  private isCintasHeaderRow(tableName: string, rowData: Record<string, any>): boolean {
+    if (tableName !== 'cintas_install_calendar') {
+      return false;
+    }
+
+    const values = Object.values(rowData)
+      .map((value) => (typeof value === 'string' ? value.trim().toLowerCase() : ''))
+      .filter(Boolean);
+
+    if (values.length === 0) {
+      return false;
+    }
+
+    if (values.includes('date of install')) {
+      return true;
+    }
+
+    const hasOpportunityHeader = values.includes('opportunity status');
+    const hasTrrHeader = values.includes('trr');
+    return hasOpportunityHeader && hasTrrHeader;
+  }
+
   private parseCellAddress(cellPosition: string, rowNumber: number): { row: number; col: number } {
     let match = cellPosition.match(/([A-Z]+)(\d+)/);
     if (!match) {