Update index.html
Browse files- index.html +32 -41
index.html
CHANGED
|
@@ -593,8 +593,7 @@
|
|
| 593 |
setTimeout(() => { progressBar.style.display = 'none'; }, 3000);
|
| 594 |
}
|
| 595 |
}
|
| 596 |
-
|
| 597 |
-
// --- WEEKLY PERFORMANCE REPORT GENERATOR FUNCTION ---
|
| 598 |
async function generateWeeklyReport() {
|
| 599 |
const genBtn = document.getElementById('weeklyGenBtn');
|
| 600 |
const rawFileInput = document.getElementById('weeklyRawDataFile');
|
|
@@ -638,24 +637,29 @@
|
|
| 638 |
let skippedCount = 0;
|
| 639 |
const totalRaw = rawMatrix.length;
|
| 640 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 641 |
// Filter starts at Row 9 (Index 8)
|
| 642 |
for (let i = 8; i < totalRaw; i++) {
|
| 643 |
const row = rawMatrix[i];
|
| 644 |
if (!row || row.length === 0) continue;
|
| 645 |
|
| 646 |
-
const rawSiteCodeInput = row[0] !== undefined && row[0] !== null ? row[0].toString().trim() : '';
|
| 647 |
|
| 648 |
-
// Gagamit ng Regex para kunin LAMANG ang Site Code na nasa format na ELRN-XX-XXXX
|
| 649 |
-
// Halimbawa: "ELRN-L1-2329 Ubo IS" -> magiging "ELRN-L1-2329" na lang
|
| 650 |
const elrnMatch = rawSiteCodeInput.match(/ELRN-[A-Z0-9]+-[A-Z0-9]+/i);
|
| 651 |
|
| 652 |
-
// SKIP kapag walang nahanap na valid na ELRN format
|
| 653 |
if (!elrnMatch) {
|
| 654 |
skippedCount++;
|
| 655 |
continue;
|
| 656 |
}
|
| 657 |
|
| 658 |
-
// Kukunin lamang ang mismong Site Code (hihiwalay ang " Ubo IS")
|
| 659 |
const rawSiteCode = elrnMatch[0].toUpperCase();
|
| 660 |
const cleanSiteCode = rawSiteCode;
|
| 661 |
|
|
@@ -664,16 +668,17 @@ const rawSiteCodeInput = row[0] !== undefined && row[0] !== null ? row[0].toStri
|
|
| 664 |
dbSiteName = loadedSiteDatabase[cleanSiteCode].siteName || "";
|
| 665 |
}
|
| 666 |
|
| 667 |
-
|
| 668 |
-
const
|
| 669 |
-
const
|
|
|
|
| 670 |
|
| 671 |
cleanDataRows.push([
|
| 672 |
rawSiteCode, // Column A
|
| 673 |
dbSiteName, // Column B
|
| 674 |
-
rawColC, // Column C
|
| 675 |
-
rawColD, // Column D
|
| 676 |
-
rawColE // Column E
|
| 677 |
]);
|
| 678 |
|
| 679 |
if (i % 200000 === 0) {
|
|
@@ -686,28 +691,7 @@ const rawSiteCodeInput = row[0] !== undefined && row[0] !== null ? row[0].toStri
|
|
| 686 |
showStatus('weeklyStatusMessage', `Pasting ${cleanDataRows.length.toLocaleString()} clean rows into template preserving exact logo...`, 'info');
|
| 687 |
await sleep(50);
|
| 688 |
|
| 689 |
-
|
| 690 |
-
// STEP 3A: Isulat muna ang lahat ng data values simula Row 11 (Cell A11)
|
| 691 |
-
let startRow = 11;
|
| 692 |
-
for (let r = 0; r < cleanDataRows.length; r++) {
|
| 693 |
-
const rowData = cleanDataRows[r];
|
| 694 |
-
const row = worksheet.getRow(startRow + r);
|
| 695 |
-
|
| 696 |
-
row.getCell(1).value = rowData[0]; // Col A (Site Code)
|
| 697 |
-
row.getCell(2).value = rowData[1]; // Col B (Site Name)
|
| 698 |
-
row.getCell(3).value = rowData[2]; // Col C (Total Client Sessions)
|
| 699 |
-
row.getCell(4).value = rowData[3]; // Col D (Total Unique Clients)
|
| 700 |
-
row.getCell(5).value = rowData[4]; // Col E (Utilized BW)
|
| 701 |
-
|
| 702 |
-
row.commit();
|
| 703 |
-
|
| 704 |
-
if (r % 50000 === 0) {
|
| 705 |
-
progressFill.style.width = `${70 + Math.floor((r / cleanDataRows.length) * 15)}%`;
|
| 706 |
-
await sleep(10);
|
| 707 |
-
}
|
| 708 |
-
}
|
| 709 |
-
|
| 710 |
-
// STEP 3B: I-apply ang formatting & borders mula Row 11 pababa hanggang sa huling row
|
| 711 |
const templateRow = worksheet.getRow(11);
|
| 712 |
const templateStyles = [];
|
| 713 |
for (let c = 1; c <= 8; c++) {
|
|
@@ -726,13 +710,21 @@ const rawSiteCodeInput = row[0] !== undefined && row[0] !== null ? row[0].toStri
|
|
| 726 |
right: { style: 'thin', color: { argb: 'FF000000' } }
|
| 727 |
};
|
| 728 |
|
|
|
|
|
|
|
| 729 |
for (let r = 0; r < cleanDataRows.length; r++) {
|
|
|
|
| 730 |
const row = worksheet.getRow(startRow + r);
|
| 731 |
|
| 732 |
for (let c = 1; c <= 8; c++) {
|
| 733 |
const cell = row.getCell(c);
|
| 734 |
|
| 735 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 736 |
const style = templateStyles[c];
|
| 737 |
if (style) {
|
| 738 |
if (style.font) cell.font = style.font;
|
|
@@ -740,19 +732,19 @@ const rawSiteCodeInput = row[0] !== undefined && row[0] !== null ? row[0].toStri
|
|
| 740 |
if (style.numFmt) cell.numFmt = style.numFmt;
|
| 741 |
}
|
| 742 |
|
| 743 |
-
// Apply grid borders sa Columns A hanggang H
|
| 744 |
cell.border = gridBorder;
|
| 745 |
}
|
| 746 |
|
| 747 |
row.commit();
|
| 748 |
|
| 749 |
if (r % 50000 === 0) {
|
| 750 |
-
progressFill.style.width = `${
|
| 751 |
await sleep(10);
|
| 752 |
}
|
| 753 |
}
|
| 754 |
|
| 755 |
-
// STEP 3C:
|
| 756 |
for (let r = 1; r <= 9; r++) {
|
| 757 |
const headerRow = worksheet.getRow(r);
|
| 758 |
for (let c = 1; c <= 8; c++) {
|
|
@@ -761,14 +753,13 @@ const rawSiteCodeInput = row[0] !== undefined && row[0] !== null ? row[0].toStri
|
|
| 761 |
headerRow.commit();
|
| 762 |
}
|
| 763 |
|
| 764 |
-
|
| 765 |
cleanDataRows = null;
|
| 766 |
|
| 767 |
progressFill.style.width = '90%';
|
| 768 |
showStatus('weeklyStatusMessage', 'Exporting final report with exact template layout...', 'info');
|
| 769 |
await sleep(50);
|
| 770 |
|
| 771 |
-
// Step
|
| 772 |
const buffer = await workbook.xlsx.writeBuffer();
|
| 773 |
const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
| 774 |
const url = window.URL.createObjectURL(blob);
|
|
|
|
| 593 |
setTimeout(() => { progressBar.style.display = 'none'; }, 3000);
|
| 594 |
}
|
| 595 |
}
|
| 596 |
+
// --- WEEKLY PERFORMANCE REPORT GENERATOR FUNCTION ---
|
|
|
|
| 597 |
async function generateWeeklyReport() {
|
| 598 |
const genBtn = document.getElementById('weeklyGenBtn');
|
| 599 |
const rawFileInput = document.getElementById('weeklyRawDataFile');
|
|
|
|
| 637 |
let skippedCount = 0;
|
| 638 |
const totalRaw = rawMatrix.length;
|
| 639 |
|
| 640 |
+
// Helper function para gawing Tunay na Number ang Column C, D, at E
|
| 641 |
+
const parseToNumber = (val) => {
|
| 642 |
+
if (val === undefined || val === null || val === '') return '';
|
| 643 |
+
const cleanStr = val.toString().replace(/,/g, '').trim();
|
| 644 |
+
const num = Number(cleanStr);
|
| 645 |
+
return !isNaN(num) && cleanStr !== '' ? num : val;
|
| 646 |
+
};
|
| 647 |
+
|
| 648 |
// Filter starts at Row 9 (Index 8)
|
| 649 |
for (let i = 8; i < totalRaw; i++) {
|
| 650 |
const row = rawMatrix[i];
|
| 651 |
if (!row || row.length === 0) continue;
|
| 652 |
|
| 653 |
+
const rawSiteCodeInput = row[0] !== undefined && row[0] !== null ? row[0].toString().trim() : '';
|
| 654 |
|
| 655 |
+
// Gagamit ng Regex para kunin LAMANG ang Site Code na nasa format na ELRN-XX-XXXX (hal. "ELRN-L1-2329")
|
|
|
|
| 656 |
const elrnMatch = rawSiteCodeInput.match(/ELRN-[A-Z0-9]+-[A-Z0-9]+/i);
|
| 657 |
|
|
|
|
| 658 |
if (!elrnMatch) {
|
| 659 |
skippedCount++;
|
| 660 |
continue;
|
| 661 |
}
|
| 662 |
|
|
|
|
| 663 |
const rawSiteCode = elrnMatch[0].toUpperCase();
|
| 664 |
const cleanSiteCode = rawSiteCode;
|
| 665 |
|
|
|
|
| 668 |
dbSiteName = loadedSiteDatabase[cleanSiteCode].siteName || "";
|
| 669 |
}
|
| 670 |
|
| 671 |
+
// Convert Columns C, D, at E to numbers
|
| 672 |
+
const rawColC = parseToNumber(row[2]); // Total Client Sessions
|
| 673 |
+
const rawColD = parseToNumber(row[3]); // Total Unique Clients
|
| 674 |
+
const rawColE = parseToNumber(row[4]); // Utilized BW
|
| 675 |
|
| 676 |
cleanDataRows.push([
|
| 677 |
rawSiteCode, // Column A
|
| 678 |
dbSiteName, // Column B
|
| 679 |
+
rawColC, // Column C (Number)
|
| 680 |
+
rawColD, // Column D (Number)
|
| 681 |
+
rawColE // Column E (Number)
|
| 682 |
]);
|
| 683 |
|
| 684 |
if (i % 200000 === 0) {
|
|
|
|
| 691 |
showStatus('weeklyStatusMessage', `Pasting ${cleanDataRows.length.toLocaleString()} clean rows into template preserving exact logo...`, 'info');
|
| 692 |
await sleep(50);
|
| 693 |
|
| 694 |
+
// STEP 3A: Extract template styles mula sa Row 11
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 695 |
const templateRow = worksheet.getRow(11);
|
| 696 |
const templateStyles = [];
|
| 697 |
for (let c = 1; c <= 8; c++) {
|
|
|
|
| 710 |
right: { style: 'thin', color: { argb: 'FF000000' } }
|
| 711 |
};
|
| 712 |
|
| 713 |
+
// STEP 3B: Isulat ang values AT ilapat ang formatting & grid borders simula Row 11 pababa sa dulo
|
| 714 |
+
let startRow = 11;
|
| 715 |
for (let r = 0; r < cleanDataRows.length; r++) {
|
| 716 |
+
const rowData = cleanDataRows[r];
|
| 717 |
const row = worksheet.getRow(startRow + r);
|
| 718 |
|
| 719 |
for (let c = 1; c <= 8; c++) {
|
| 720 |
const cell = row.getCell(c);
|
| 721 |
|
| 722 |
+
// Value Assignment para sa Columns A hanggang E
|
| 723 |
+
if (c <= 5) {
|
| 724 |
+
cell.value = rowData[c - 1];
|
| 725 |
+
}
|
| 726 |
+
|
| 727 |
+
// Apply font, alignment, at number formats mula Row 11
|
| 728 |
const style = templateStyles[c];
|
| 729 |
if (style) {
|
| 730 |
if (style.font) cell.font = style.font;
|
|
|
|
| 732 |
if (style.numFmt) cell.numFmt = style.numFmt;
|
| 733 |
}
|
| 734 |
|
| 735 |
+
// Apply grid borders sa Columns A hanggang H para sa LAHAT ng rows
|
| 736 |
cell.border = gridBorder;
|
| 737 |
}
|
| 738 |
|
| 739 |
row.commit();
|
| 740 |
|
| 741 |
if (r % 50000 === 0) {
|
| 742 |
+
progressFill.style.width = `${70 + Math.floor((r / cleanDataRows.length) * 20)}%`;
|
| 743 |
await sleep(10);
|
| 744 |
}
|
| 745 |
}
|
| 746 |
|
| 747 |
+
// STEP 3C: Linisin ang borders sa Header Rows 1 hanggang 9 para maging 100% exact sa template design
|
| 748 |
for (let r = 1; r <= 9; r++) {
|
| 749 |
const headerRow = worksheet.getRow(r);
|
| 750 |
for (let c = 1; c <= 8; c++) {
|
|
|
|
| 753 |
headerRow.commit();
|
| 754 |
}
|
| 755 |
|
|
|
|
| 756 |
cleanDataRows = null;
|
| 757 |
|
| 758 |
progressFill.style.width = '90%';
|
| 759 |
showStatus('weeklyStatusMessage', 'Exporting final report with exact template layout...', 'info');
|
| 760 |
await sleep(50);
|
| 761 |
|
| 762 |
+
// Step 4: Export File
|
| 763 |
const buffer = await workbook.xlsx.writeBuffer();
|
| 764 |
const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
| 765 |
const url = window.URL.createObjectURL(blob);
|