-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
96 lines (74 loc) · 3.28 KB
/
app.js
File metadata and controls
96 lines (74 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// app.js
function processCSV() {
const fileInput = document.getElementById("csv-file");
const resultTable = document.getElementById("result-table");
if (fileInput.files.length > 0) {
const file = fileInput.files[0];
Papa.parse(file, {
header: true,
complete: function(results) {
const data = results.data;
const categoryCounts = {};
const staticValues = {
"Category I": 120,
"Category II": 150,
"Category III": 150,
"Category IV": 150,
"Category V": 148
};
// Assuming the specific column header is 'webhookLog.data.object.description'
const categoryColumn = 'webhookLog.data.object.description';
data.forEach(row => {
// Ignore rows with the value 'STRIPE PAYOUT'
if (row[categoryColumn] && row[categoryColumn] !== 'STRIPE PAYOUT') {
const match = row[categoryColumn].match(/(.+?) x (\d+)/);
if (match) {
const category = match[1].trim();
const count = parseInt(match[2]);
categoryCounts[category] = (categoryCounts[category] || 0) + count;
}
}
});
displayResultTable(categoryCounts, staticValues);
}
});
} else {
resultTable.innerHTML = "<p>Please choose a CSV file.</p>";
}
}
function displayResultTable(data, staticValues) {
const resultTable = document.getElementById("result-table");
resultTable.innerHTML = "";
const categories = ["Category I", "Category II", "Category III", "Category IV", "Category V"];
const table = document.createElement("table");
const headerRow = table.insertRow(0);
const categoryHeader = document.createElement("th");
categoryHeader.textContent = "Product/Service Description";
headerRow.appendChild(categoryHeader);
const purchasedHeader = document.createElement("th");
purchasedHeader.textContent = "Quantity Purchased";
headerRow.appendChild(purchasedHeader);
const availableHeader = document.createElement("th");
availableHeader.textContent = "Quantity Available";
headerRow.appendChild(availableHeader);
const leftHeader = document.createElement("th");
leftHeader.textContent = "Quantity Left";
headerRow.appendChild(leftHeader);
categories.forEach(category => {
const row = table.insertRow(-1);
const categoryCell = row.insertCell(0);
categoryCell.textContent = category;
const purchasedCell = row.insertCell(1);
purchasedCell.textContent = data[category] || 0;
const availableCell = row.insertCell(2);
availableCell.textContent = staticValues[category] || 0;
const leftCell = row.insertCell(3);
const leftValue = (staticValues[category] || 0) - (data[category] || 0);
leftCell.textContent = leftValue;
// Highlight cell in red if the left quantity is 5 or less
if (leftValue <= 5) {
leftCell.style.color = "red";
}
});
resultTable.appendChild(table);
}