-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbulk-order.html
191 lines (173 loc) · 5.92 KB
/
bulk-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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bulk Stock Orders</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" />
<style>
body {
background: #f0f2f5;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.container {
max-width: 1200px;
margin-top: 40px;
}
h2 {
font-weight: 700;
text-align: center;
margin-bottom: 30px;
color: #343a40;
}
.order-form {
background: #ffffff;
padding: 30px;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
.order-card {
background: #f8f9fa;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
margin-bottom: 20px;
}
.form-control {
border-radius: 6px;
}
.order-row {
display: flex;
flex-wrap: wrap;
gap: 15px;
}
.order-row .form-group {
flex: 1 1 18%;
}
.btn-section {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
.order-summary {
background: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
margin-top: 30px;
}
.order-summary h5 {
font-weight: bold;
margin-bottom: 15px;
}
.summary-line {
font-size: 1rem;
margin-bottom: 8px;
}
</style>
</head>
<body>
<div class="container">
<h2>Bulk Stock Order Form</h2>
<form id="orderForm" class="order-form">
<div id="orders">
<div class="order-card order-row">
<div class="form-group">
<label>Order ID</label>
<input type="text" name="orderId" class="form-control" required />
</div>
<div class="form-group">
<label>Stock Symbol</label>
<input type="text" name="stockSymbol" class="form-control" required />
</div>
<div class="form-group">
<label>Order Type</label>
<select name="orderType" class="form-control" required>
<option value="BUY">BUY</option>
<option value="SELL">SELL</option>
</select>
</div>
<div class="form-group">
<label>Price</label>
<input type="number" name="price" class="form-control" required />
</div>
<div class="form-group">
<label>Quantity</label>
<input type="number" name="quantity" class="form-control" required />
</div>
</div>
</div>
<div class="btn-section">
<button type="button" class="btn btn-info" onclick="addOrder()">Add Another Order</button>
<button type="submit" class="btn btn-primary">Submit Orders</button>
</div>
</form>
<div class="order-summary">
<h5>Order Summary</h5>
<div id="result">
<p class="summary-line">📭 No orders submitted yet.</p>
</div>
</div>
</div>
<script>
function addOrder() {
const orders = document.getElementById("orders");
const newCard = document.createElement("div");
newCard.className = "order-card order-row";
newCard.innerHTML = `
<div class="form-group">
<label>Order ID</label>
<input type="text" name="orderId" class="form-control" required>
</div>
<div class="form-group">
<label>Stock Symbol</label>
<input type="text" name="stockSymbol" class="form-control" required>
</div>
<div class="form-group">
<label>Order Type</label>
<select name="orderType" class="form-control" required>
<option value="BUY">BUY</option>
<option value="SELL">SELL</option>
</select>
</div>
<div class="form-group">
<label>Price</label>
<input type="number" name="price" class="form-control" required>
</div>
<div class="form-group">
<label>Quantity</label>
<input type="number" name="quantity" class="form-control" required>
</div>`;
orders.appendChild(newCard);
}
document.getElementById("orderForm").onsubmit = function (event) {
event.preventDefault();
const orderElements = document.querySelectorAll(".order-card");
const orders = Array.from(orderElements).map(card => {
const order = {};
card.querySelectorAll("input, select").forEach(input => {
order[input.name] = input.value;
});
return order;
});
fetch("http://localhost:8080/api/stock/bulk-order", {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(orders)
})
.then(response => response.json())
.then(data => {
const resultDiv = document.getElementById("result");
resultDiv.innerHTML = `
<p class="summary-line">✅ <strong>Total Orders:</strong> ${data.totalOrders}</p>
<p class="summary-line">🎯 <strong>Successful Orders:</strong> ${data.successCount}</p>
<p class="summary-line">💰 <strong>Total Amount:</strong> ₹${data.totalAmount.toLocaleString()}</p>
`;
})
.catch(error => {
document.getElementById("result").innerHTML = `<p class="summary-line text-danger">❌ Error: ${error}</p>`;
});
};
</script>
</body>
</html>