-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.html
137 lines (126 loc) · 4.39 KB
/
order.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<link href="assets/img/favicon.png" rel="icon" />
<meta charset="UTF-8" />
<title>Client Sign In</title>
<link rel="stylesheet" href="./assets/css/order.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.8.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.8.0/firebase-firestore.js"></script>
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"
></script>
<script src="assets/js/qrcode.js"></script>
</head>
<body>
<div class="container contact-form">
<div class="contact-image">
<img
src="https://image.ibb.co/kUagtU/rocket_contact.png"
alt="rocket_contact"
/>
</div>
<div id="form">
<h3>Get Your Gas Cylinder</h3>
<div class="d-flex justify-content-center">
<button id="orderBtn" class="btn btn-primary btn-lg px-5">
Order Now
</button>
</div>
</div>
</div>
<div id="snackbar"></div>
<script>
const firebaseConfig = {
apiKey: "AIzaSyD7RKFOV4Mk_O2Nm9Vpv7sEAUc89iKHmeE",
authDomain: "gcylinder-d807a.firebaseapp.com",
projectId: "gcylinder-d807a",
storageBucket: "gcylinder-d807a.appspot.com",
messagingSenderId: "460628927682",
appId: "1:460628927682:web:a5bd53ffb382fd082c475b",
measurementId: "G-PDKWCKS2CF",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const orderDatabase = firebase.firestore().collection("orders");
const username = localStorage.getItem("username");
console.log(username);
function displayAlert(message) {
var x = document.getElementById("snackbar");
x.innerHTML = message;
x.className = "show";
setTimeout(function () {
x.className = x.className.replace("show", "");
}, 3000);
var x = document.getElementById("snackbar");
x.className = "show";
setTimeout(function () {
x.className = x.className.replace("show", "");
}, 3000);
console.log(message);
}
function showQR(title, ID) {
document.getElementById("form").innerHTML =
"<h3>" +
title +
'</h3><div class="d-flex justify-content-center" id="qrcode"></div>';
new QRCode(document.getElementById("qrcode"), ID);
}
document
.getElementById("orderBtn")
.addEventListener("click", function (event) {
event.preventDefault();
orderDatabase
.where("username", "==", username)
.limit(1)
.get()
.then((querySnapshot) => {
const tempDoc = querySnapshot.docs.map((doc) => {
return {
id: doc.id,
sold: doc.data()["sold"],
date: doc.data()["date"],
};
});
const date = new Date();
if (tempDoc.length == 0) {
orderDatabase
.add({
username: username,
sold: false,
date: date,
})
.then((doc) => {
showQR(
"Your order Placed on <br/>" +
date +
"<br/> <br/> Bring this Code to Nearest Retailer to get your Gas Cylinder",
doc.id
);
});
} else {
showQR(
"Your order Placed on <br/>" +
tempDoc[0].date.toDate() +
"<br/> <br/> Bring this Code to Nearest Retailer to get your Gas Cylinder",
tempDoc[0].id
);
}
});
});
window.onload = function () {
if (!username) {
location.replace("./customer/signin.html");
}
};
</script>
</body>
</html>