-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScriptReceiptFunction.js
More file actions
58 lines (46 loc) · 1.86 KB
/
JavaScriptReceiptFunction.js
File metadata and controls
58 lines (46 loc) · 1.86 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
var arr = [];
if (window.openDatabase) {
//Create the database the parameters are 1. the database name 2.version number 3. a description 4. the size of the database (in bytes) 1024 x 1024 = 1MB
var db = openDatabase("mydb", "1.0", "my first database", 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS receiptVFINAL (type, value)");
});
}
function myReceiptFunction() {
var rowWhole = document.querySelectorAll(".row-whole");
var arrayValue = [];
for (var i = 0; i < rowWhole.length; i++) {
var objValue = {};
var tranDVal = document.getElementById("selectable_" + i).value;
var tranTVal = document.getElementById("tType" + i).value;
var isDuplicateTT = arrayValue
.map(function (e) {
return e.tTVal;
})
.indexOf(tranTVal);
var quantityVal = Number(document.getElementById("quanValue" + i).value);
if (isNaN(quantityVal) || quantityVal == 0) {
alert("Please Enter Number(s)");
break;
} else if (isDuplicateTT == -1) {
var quantityVal = Number(document.getElementById("quanValue" + i).value);
objValue.tDVal = tranDVal;
objValue.tTVal = tranTVal;
objValue.qVal = quantityVal;
arrayValue.push(objValue);
let res = document.URL.replace("UserInput", "Table1");
window.open(res, "_self");
} else {
var quantityVal = Number(document.getElementById("quanValue" + i).value);
var x = arrayValue[isDuplicateTT].qVal;
var newDupQVal = Number(x + quantityVal);
arrayValue[isDuplicateTT].qVal = newDupQVal;
let res = document.URL.replace("UserInput", "Table1");
window.open(res, "_self");
}
}
var startToEnd = document.getElementById(startEndDate);
console.log(startToEnd);
sessionStorage.dateVal = JSON.stringify(startToEnd);
sessionStorage.arrayValue = JSON.stringify(arrayValue);
}