-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory.js
122 lines (116 loc) · 3.82 KB
/
inventory.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var cur_exp=null;
function showInput(){
var section=document.getElementById("input");
section.style.display="block";
}
function addItem(){
var iname=document.getElementById("iname");
var iquantity=document.getElementById("iquantity");
var iprice=document.getElementById("iprice");
var table=document.getElementById("results");
var row=table.insertRow(-1);
var name_cell=row.insertCell(-1);
var quantity_cell=row.insertCell(-1);
var price_cell=row.insertCell(-1);
var amount_cell=row.insertCell(-1);
name_cell.innerHTML=iname.value;
quantity_cell.innerHTML=iquantity.value;
price_cell.innerHTML=iprice.value;
var amount=parseFloat(iquantity.value)*parseFloat(iprice.value);
window.console.log("Name is "+iname.value);
amount_cell.innerHTML=amount;
iname.value="";
iquantity.value=null;
iprice.value=null;
}
function storeRecord(rno,name,quantity,price,amount)
{
var record=[name,quantity,price,amount];
localStorage.setItem(rno,record);
}
function stringFromTable(tableid)
{
var table=document.getElementById(tableid);
var row_list=table.getElementsByTagName("tr");
var str="";
for(var i=1;i<row_list.length;i++)
{
var row=row_list[i].getElementsByTagName("td");
for(var j=0;j<row.length;j++)
{
str=str+row[j].innerHTML;
if(j!=row.length-1)
str=str+",";
}
if(i!=row_list.length-1)
str=str+"<br>";
console.log(str);
}
return str;
}
function createBill()
{
var cur_bill=parseInt(localStorage.getItem("cur_bill"));
console.log("Current Bill ID="+cur_bill);
var tabledata=stringFromTable("results");
localStorage.setItem(cur_bill,tabledata);
localStorage.setItem("cur_bill",cur_bill+1);
var table=document.getElementById("results");
table.innerHTML="<tr><th>Item</th><th>Quantity</th><th>Price</th><th>Amount</th></tr>";
// localStorage.setItem("cur_bill",1001);
}
function displayBills()
{
console.log("In displayBills");
var article=document.getElementById("bills");
var cur_no_of_bills=parseInt(localStorage.getItem("cur_bill"));
console.log("Current no. of bills:"+cur_no_of_bills);
for(var i=1001;i<cur_no_of_bills;i++)
{
var table=document.createElement("table");
table.classList.add("table");
table.classList.add("table-bordered");
table.style.width="25%";
var bill_no=i;
var tabledata=localStorage.getItem(bill_no);
var rows=tabledata.split("<br>");
var hrow=table.insertRow(-1);
var hname_cell=hrow.insertCell(-1);
var hquantity_cell=hrow.insertCell(-1);
var hprice_cell=hrow.insertCell(-1);
var hamount_cell=hrow.insertCell(-1);
hname_cell.innerHTML="Name";
hquantity_cell.innerHTML="Quantity";
hprice_cell.innerHTML="Price";
hamount_cell.innerHTML="Amount";
hrow.style.fontWeight="bolder";
for(var j=0;j<rows.length;j++)
{
var row=table.insertRow(-1);
var name_cell=row.insertCell(-1);
var quantity_cell=row.insertCell(-1);
var price_cell=row.insertCell(-1);
var amount_cell=row.insertCell(-1);
fields=rows[j].split(",");
name_cell.innerHTML=fields[0];
quantity_cell.innerHTML=fields[1];
price_cell.innerHTML=fields[2];
amount_cell.innerHTML=fields[3];
}
article.appendChild(table);
table.addEventListener("click",zoom,true);
}
}
function showPrevious(){
window.location.href="Bills.html";
}
function zoom(e){
if(cur_exp!=null)
cur_exp.style.height="25%";
e.stopPropagation();
e.preventDefault();
var table=this;
cur_exp=this;
table.style.height="100%";
table.style.width="100%";
}