-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodulus.js
More file actions
59 lines (45 loc) · 1.66 KB
/
modulus.js
File metadata and controls
59 lines (45 loc) · 1.66 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
// // // // // SINGLE ITEM// // // // //
var HEADER_NAME = "item header name";
var ITEM_COST = 5;
var DISPLAY_NAME = "item display name";
var exists = formData[HEADER_NAME];
if (exists || exxists == "Yes") {
totalPrice += ITEM_COST;
placeholderMap["{{" + curIndex + "}}"] = DISPLAY_NAME;
curIndex++;
}
// // // // // QUANTITY ITEM // // // // //
var HEADER_QUANTITY_NAME = "item quantity header name";
var ITEM_COST = 5;
var DISPLAY_NAME = "item display name";
var quantity = formData[HEADER_QUANTITY_NAME];
if (exists && Number.isInteger(quantity) && quantity > 0) {
totalPrice += ITEM_COST * quantity;
placeholderMap["{{" + curIndex + "}}"] = DISPLAY_NAME + " × " + quantity;
curIndex++;
}
// // // // // MULTIPLE ITEMS (CURRENCY) // // // // //
var START_HEADER = "Addon Start";
var END_HEADER = "Addon End";
// Supports: RM1200 | RM 1,200 | RM 1,200.00
// change corresponded for other currencies: $, CNY,
var CURRENCY_REGEX = /RM\s?([\d,]+(?:\.\d{1,2})?)/;
var startIndex = headers.indexOf(START_HEADER);
var endIndex = headers.indexOf(END_HEADER);
if (startIndex !== -1 && endIndex !== -1 && startIndex <= endIndex) {
for (var col = startIndex; col <= endIndex; col++) {
var cellValue = lastRowData[col];
if (!cellValue || typeof cellValue !== "string") continue;
var items = cellValue.split(",").map(function (i) {
return i.trim();
});
items.forEach(function (item) {
var match = item.match(CURRENCY_REGEX);
if (!match) return;
var price = Number(match[1].replace(/,/g, ""));
totalPrice += price;
placeholderMap["{{" + curIndex + "}}"] = item;
curIndex++;
});
}
}