-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
205 lines (168 loc) · 6.59 KB
/
helpers.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
function displaySupplierForm() {
var formEl = document.getElementById("supplierFormContainer");
if (formEl.style.display === 'none' || formEl.style.display === "") {
formEl.style.display = "block";
} else {
formEl.style.display = "none";
}
}
function displayInventoryCountForm() {
var formEl = document.getElementById("inventoryCountFormContainer");
if (formEl.style.display === 'none' || formEl.style.display === "") {
formEl.style.display = "block";
} else {
formEl.style.display = "none";
}
}
function displayOrderTrackingForm() {
var formEl = document.getElementById("trackingOrderFormContainer");
if (formEl.style.display === 'none' || formEl.style.display === "") {
formEl.style.display = "block";
document.getElementById("trackingForm").scrollIntoView();
} else {
formEl.style.display = "none";
}
}
function displayPurchaseOrders(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var response = xmlhttp.responseText;
document.getElementById("purchaseOrders").innerHTML = response;
document.getElementById("purchaseOrders").scrollIntoView();
console.log("Success");
}
};
xmlhttp.open("GET", 'displayPurchaseOrders.php', true);
xmlhttp.send();
}
function displayTotalWeights(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var response = xmlhttp.responseText;
document.getElementById("totalWeights").innerHTML = response;
document.getElementById("totalWeights").scrollIntoView();
console.log("Success");
}
};
xmlhttp.open("GET", 'displayTotalWeights.php', true);
xmlhttp.send();
}
// Function which creates an AJAX request to obtain the supplierID of the row which is clicked on in the suppliers table
function getSupplierID(el){
var supplierID = el.getElementsByTagName('td')[0].innerHTML;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var response = xmlhttp.responseText;
document.getElementById("supplierInventoryContainer").innerHTML = response;
console.log("Success");
}
};
xmlhttp.open("GET", "getSupplierInventory.php?value=" + supplierID, true);
xmlhttp.send();
}
function getTrackingNum(el){
var trackingNum= el.getElementsByTagName('td')[0].innerHTML;
var modal = document.getElementById("myModal");
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var response = xmlhttp.responseText;
document.getElementById("supplierInventoryContainer").innerHTML = response;
modal.style.display = "block";
console.log("Success");
}
};
xmlhttp.open("GET", "displayOrderDetails.php?value=" + trackingNum, true);
xmlhttp.send();
}
window.onload = function(){
var supplierRows = document.querySelectorAll(".supplierRow");
var orderRows = document.querySelectorAll(".orderDetailsRow");
var modal = document.getElementById("myModal");
supplierRows.forEach(function(row){
row.addEventListener("click", function(event){
modal.style.display = "block";
});
});
window.onclick = function(event){
if (event.target == modal) {
modal.style.display = "none";
}
}
var targetForm = document.querySelector('#trackingForm');
if (targetForm){
document.querySelector('#trackingForm').addEventListener('submit', function(event){
event.preventDefault();
})
}
}
// Function to which creates an AJAX request to obtain the supplier Inventory of the supplier which is clicked on in the suppliers selection option
function getSupplierInventory(el){
var supplierOption = document.querySelector("#supplier option:checked");
var supplierName = supplierOption.textContent;
if (supplierName != 'SELECT SUPPLIER'){
console.log(supplierName);
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var response = xmlhttp.responseText;
document.getElementById("items").innerHTML = response;
document.getElementById("items").style.display = "block";
console.log("Success");
}
};
xmlhttp.open("GET", "supplierInventoryOption.php?value=" + supplierName, true);
xmlhttp.send();
}
else{
document.getElementById("items").style.display = "none";
}
}
function getSupplierInventoryCount(el){
var supplierOption = document.querySelector("#supplier option:checked");
var supplierName = supplierOption.textContent;
if (supplierName != 'SELECT SUPPLIER'){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var response = xmlhttp.responseText;
document.getElementById("inventoryCount").innerHTML = response;
document.getElementById("inventoryCount").style.display = "block";
document.getElementById("inventoryCount").scrollIntoView();
console.log("Success");
}
};
xmlhttp.open("GET", "displayInventoryCounts.php?value=" + supplierName, true);
xmlhttp.send();
}
else{
document.getElementById("inventoryCount").style.display = "none";
}
}
function getTrackingHistory(el){
var inputElement = document.getElementById('trackingNumber');
var trackingNumber = document.getElementById('trackingNumber').value;
console.log(trackingNumber);
if (trackingNumber != ''){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var response = xmlhttp.responseText;
document.getElementById("trackingHistory").innerHTML = response;
document.getElementById("trackingHistory").style.display = "block";
document.getElementById("trackingHistory").scrollIntoView();
console.log("Success");
}
};
xmlhttp.open("GET", "displayTrackingHistory.php?value=" + trackingNumber, true);
xmlhttp.send();
}
else{
inputElement.focus();
document.getElementById("trackingHistory").scrollIntoView();
console.log("Failure");
}
}