-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
82 lines (67 loc) · 2.53 KB
/
script.js
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
var mode = 0;
function btn() {
var item = document.getElementById("item").value;
var qty = document.getElementById("qty").value;
var rate = document.getElementById("rate").value;
var discount = document.getElementById("dis").value;
var netAmt = document.getElementById("netAmt").value;
var netAmt = (qty * rate) - (qty * rate * discount / 100);
document.getElementById("netAmt").innerHTML = "net Amt " + netAmt;
}
function update(index) {
mode = index;
var row = document.getElementsByClassName("mid-col")[0].rows[index];
document.getElementById("bttn").innerHTML = "Update";
var form = document.forms[0];
var item = form.item;
var qty = form.qty;
var rate = form.rate;
var discount = form.discount;
var row = document.getElementsByClassName("mid-col")[0].rows[index];
item.value = row.cells[1].innerHTML;
qty.value = row.cells[2].innerHTML;
rate.value = row.cells[3].innerHTML;
discount.value = row.cells[4].innerHTML;
}
function btn1() {
var tbl = document.getElementsByClassName("mid-col")[0];
var r;
var row;
if (mode > 0) {
row = tbl.rows[mode];
r = mode;
mode = 0;
document.getElementById("bttn").innerHTML = "Add";
}
else {
r = tbl.rows.length;
row = tbl.insertRow(r);
}
var form = document.forms[0];
var item = form.item.value;
var qty = form.qty.value;
var rate = form.rate.value;
var discount = form.dis.value;
var netAmount = (qty * rate) - (qty * rate * discount / 100);
var data = "<td onclick='update(" + r + ")'>" + r + "</td>"
+ "<td onclick='update(" + r + ")'>" + item + "</td>"
+ "<td onclick='update(" + r + ")'>" + qty + "</td>"
+ "<td onclick='update(" + r + ")'>" + rate + "</td>"
+ "<td onclick='update(" + r + ")'>" + discount + "</td>"
+ "<td onclick='update(" + r + ")'>" + netAmount + "</td>"
row.innerHTML = data;
var amount = 0;
var discount1 = 0;
var netamount1 = 0;
for (i = 1; i < tbl.rows.length; i++) {
var amountP = tbl.rows[i].cells[2].innerHTML * tbl.rows[i].cells[3].innerHTML;
var discountP = (amountP / 100) * tbl.rows[i].cells[4].innerHTML;
var netAmtP = (amountP - discountP);
amount += amountP;
discount1 += discountP;
netamount1 += netAmtP;
}
document.getElementById("amount").innerHTML = amount;
document.getElementById("discount1").innerHTML = discount1;
document.getElementById("netamount1").innerHTML = netamount1;
}