Skip to content

Commit a5b6172

Browse files
Customer Info Tab V9 added real data loading
1 parent c62cf36 commit a5b6172

File tree

5 files changed

+78
-44
lines changed

5 files changed

+78
-44
lines changed

app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ document.addEventListener('DOMContentLoaded', async function () {
2121
const cachedPricing = await idbUtil.getDataset("PricingData");
2222
const cachedEquivs = await idbUtil.getDataset("EquivalentsData");
2323
const cachedPriceRaise = await idbUtil.getDataset("PriceRaiseData");
24+
const cachedContacts = await idbUtil.getDataset("CustomerContactsData");
2425

2526
if (cachedDB && cachedSales && cachedPricing && cachedPriceRaise) {
2627
// ✅ cached path: load datasets into the dataStore
@@ -35,6 +36,12 @@ document.addEventListener('DOMContentLoaded', async function () {
3536
PriceRaise: window.dataStore["PriceRaise"]
3637
});
3738

39+
if (cachedContacts) {
40+
window.dataStore["CustomerContacts"] = cachedContacts.dataframe;
41+
console.log("[DOMContentLoaded] Customer contacts loaded from cache.",
42+
Object.keys(window.dataStore["CustomerContacts"]).length);
43+
}
44+
3845
// --- rebuild the three hrefs from what we just loaded ---
3946
const links = window.dataStore.fileLinks ||= {};
4047

codeConsole.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ document.getElementById('codeModal').addEventListener('shown.bs.modal', () => {
1818
lineNumbers:true,
1919
value:`// Example: list inventory SKUs with <10 on hand\n
2020
const lowStock = dataStore.DB.dataframe.filter(r => r.QtyOnHand - r.QtyCommited < 10);\n
21-
console.table(lowStock.slice(0,20));`
21+
console.table(lowStock.slice(0,20));\n\n// Console output will appear in the development console ('F12' or 'Ctrl+Shift+I')\n\n// You can access the dataStore, idbUtil, and dataLoader objects directly\n// For example: console.log(dataStore.DB.dataframe.head(5));`
2222
});
2323
}
2424
cm.refresh(); // fix sizing quirk inside Bootstrap modal

config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,20 @@
6868
"skipRows": 1,
6969
"sheetName": "COO",
7070
"dataKey": "PriceRaise"
71+
},
72+
{
73+
"directory": "Brandywine Collaborate Team Site Folder/Customers, Orders",
74+
"filenamePrefix": "Customer Contacts 2025",
75+
"columns": [
76+
"Company", "2019 Sales", "2020 Sales", "2021 Sales", "2022 Sales",
77+
"2023 Sales", "2024 Sales", "2025 Sales",
78+
"Location", "Business", "Type", "Remarks", "Website", "N", "O", "P",
79+
"Contact Name 1", "Contact Title 1", "Email 1",
80+
"Contact Name 2", "Contact Title 2", "Email 2",
81+
"Contact Name 3", "Contact Title 3", "Email 3"
82+
],
83+
"skipRows": 1,
84+
"sheetName": "Companies (Ranked)",
85+
"dataKey": "CustomerContacts"
7186
}
7287
]

dataLoader.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ async function processFiles() {
253253
continue;
254254
}
255255

256+
if (key === "CustomerContacts") {
257+
const map = normaliseCustomerContacts(frame);
258+
const stored = { dataframe: map, metadata: md };
259+
ds[key] = map; // keep mapping only
260+
await idbUtil.setDataset(storageKey, stored);
261+
console.log(`[CustomerContacts] ${Object.keys(map).length} companies loaded.`);
262+
continue;
263+
}
264+
265+
256266
// generic sheet (Sales, DB, …)
257267
const cleaned = key === "Sales"
258268
? filterOutValues(fillDownColumn(frame, "Customer"),
@@ -440,6 +450,47 @@ function toNumber(val) {
440450
return isFinite(num) ? num : null; // null is better than NaN or undefined later
441451
}
442452

453+
// Helper function to normalize customer contacts from the "Customer Contacts" sheet.
454+
function normaliseCustomerContacts(frame) {
455+
const YEARS = ["2019","2020","2021","2022","2023","2024","2025"];
456+
const map = {};
457+
458+
for (const row of frame) {
459+
const company = String(row.Company || "").trim();
460+
if (!company) continue;
461+
462+
/* — sales by year — */
463+
const sales = {};
464+
YEARS.forEach(y => { sales[y] = row[`${y} Sales`] ?? null; });
465+
466+
/* — contacts (1‒3) — */
467+
const contacts = [];
468+
for (let i = 1; i <= 3; i++) {
469+
const name = row[`Contact Name ${i}`] || "";
470+
const title = row[`Contact Title ${i}`] || "";
471+
const email = row[`Email ${i}`] || "";
472+
if (name || title || email) {
473+
contacts.push({ Name: name, Title: title, Email: email });
474+
}
475+
}
476+
477+
map[company] = {
478+
SalesByYear : sales,
479+
Location : row.Location || "",
480+
Business : row.Business || "",
481+
Type : row.Type || "",
482+
Remarks : row.Remarks || "",
483+
Website : row.Website || "",
484+
Contacts : contacts
485+
};
486+
}
487+
return map;
488+
}
489+
490+
// Exports a function to get customer details by company name.
491+
function getCustomerDetails(company) {
492+
return (window.dataStore["CustomerContacts"] || {})[company] || null;
493+
}
443494
// Global storage for parsed data
444495
window.dataStore = {};
445496
window.dataStore.fileLinks = {}; // for sheet links
@@ -449,5 +500,6 @@ window.dataLoader = {
449500
fetchLatestFileMetadata,
450501
downloadExcelFile,
451502
parseExcelData,
452-
processFiles
503+
processFiles,
504+
getCustomerDetails
453505
};

uiRenderer.js

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -532,49 +532,9 @@ document.getElementById('customer-info-tab').addEventListener('click', () => {
532532
});
533533

534534

535-
// Temporary mock function for getCustomerDetails
536-
// YOU WILL NEED TO REPLACE THIS WITH ACTUAL DATA FETCHING LOGIC
537535
async function getCustomerDetails(customerName) {
538-
// Mock data for demonstration
539-
const mockCustomerData = {
540-
"Acme Corp": {
541-
"Sales by Year": "$1,200,000 (2024)",
542-
"Location": "New York, USA",
543-
"Business": "Manufacturing",
544-
"Type": "B2B",
545-
"Remarks": "Key account, high potential for growth.",
546-
"Website": "https://www.acmecorp.com",
547-
"Contacts": [
548-
{ Name: "John Doe", Title: "Purchasing Manager", Email: "[email protected]", Phone: "555-123-4567" },
549-
{ Name: "Jane Smith", Title: "CEO", Email: "[email protected]", Phone: "555-987-6543" }
550-
]
551-
},
552-
"Global Solutions": {
553-
"Sales by Year": "$500,000 (2024)",
554-
"Location": "London, UK",
555-
"Business": "Software Development",
556-
"Type": "B2B",
557-
"Remarks": "New client, growing steadily.",
558-
"Website": "https://www.globalsolutions.co.uk",
559-
"Contacts": [
560-
{ Name: "Alice Brown", Title: "CTO", Email: "[email protected]", Phone: "020-7946-0123" }
561-
]
562-
}
563-
};
564-
565-
// Return specific mock data if found, otherwise return generic data
566-
return mockCustomerData[customerName] || {
567-
"Sales by Year": "N/A (Generic)",
568-
"Location": "Unknown",
569-
"Business": "Various",
570-
"Type": "Mixed",
571-
"Remarks": "Generic customer profile.",
572-
"Website": "N/A",
573-
"Contacts": [
574-
{ Name: "Generic Contact 1", Title: "Manager", Email: "[email protected]", Phone: "555-000-1111" },
575-
{ Name: "Generic Contact 2", Title: "Specialist", Email: "[email protected]", Phone: "555-000-2222" }
576-
]
577-
};
536+
// thin wrapper around dataLoader => keeps rest of code unchanged
537+
return window.dataLoader.getCustomerDetails(customerName);
578538
}
579539

580540

0 commit comments

Comments
 (0)