-
Notifications
You must be signed in to change notification settings - Fork 0
/
newUsed_Line.php
196 lines (171 loc) · 6.91 KB
/
newUsed_Line.php
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
<?php
require_once('header2.html');
?>
<body>
<div id="carbonForm1">
<h1>New Usage Line</h1>
<div class = "fieldContainer">
<div class = "formRow">
<div class = "label">
<label for = "ulorder">Used OrderID</label>
</div>
<div class = "field">
<input type = "text" id = "ulorder" value = <?php echo $_GET['Used_OrderID']; ?> readonly >
</div>
</div>
<div class = "formRow">
<div class = "label">
<label for = "ulcomponent">ComponentID</label>
</div>
<div class = "field">
<input type = "text" onclick = showComponentTable(); id = "ulcomponent" readonly>
</div>
</div>
<span id="ulctable" hidden>
<h4>Select Component</h4>
<table id = "table_id" class = "display">
<thead>
<tr align="left">
<th>Reference</th>
<th>Value</th>
<th>Part Number</th>
<th>Manufacturer</th>
<th>Foot Print</th>
<th>Price</th>
<th>Data Sheet</th>
<th>Description</th>
</tr>
</thead>
<div>
<tbody>
<?php
require_once('connect.php');
$query = "select * from Component";
$stmt = $conn->prepare($query);
if ($stmt->execute()) {
$stmt->setFetchMode(PDO::FETCH_ASSOC);
}
while ( $result = $stmt->fetch() ) {
echo '<tr class = "clickable-row" data-href = '. $result['ComponentID'] .'>
<td>' . $result['ComponentReference'] . '</td>
<td>' . $result['ComponentValue'] . '</td>
<td>' . $result['ComponentPartNumber'] . '</td>
<td>' . $result['ComponentManufacturer'] . '</td>
<td>' . $result['ComponentFootPrint'] . '</td>
<td>' . $result['ComponentPrice'] . '</td>
<td>' . $result['ComponentDataSheet'] . '</td>
<td>' . $result['ComponentDescription'] . '</td>
</tr>';
}
?>
</tbody>
</div>
</table>
</span>
<div class = "formRow">
<div class = "label">
<label for = "ulquantity">Used Quantity</label>
</div>
<div class = "field">
<input type = "text" onchange = calcSubtotal(); id = "ulquantity">
</div>
</div>
<div class = "formRow">
<div class = "label">
<label for = "ulcost">Used Cost</label>
</div>
<div class = "field">
<input type = "text" onchange = calcSubtotal(); id = "ulcost">
</div>
</div>
<div class = "formRow">
<div class = "label">
<label for = "ulstatus">Used Status</label>
</div>
<div class = "field">
<select id = "ulstatus">
<option value = ""></option>
<option value = "Used" >Used</option>
<option value = "Defective" >Defective</option>
<option value = "Salvaged" >Salvaged</option>
<option value = "Cancelled" >Cancelled</option>
</select>
</div>
</div>
<div class = "formRow">
<div class = "label">
<label for = "datepicker">Date Used</label>
</div>
<div class = "field">
<input type="text" id="datepicker" readonly>
</div>
</div>
<div class = "formRow">
<div class = "label">
<label for = "ulsubtotal">Subtotal</label>
</div>
<div class = "field">
<input type = "text" id = "ulsubtotal" readonly>
</div>
</div>
</div>
<div class = "signupButton">
<button type = "button" id = "submit" onclick = insertUsedLine()>Add New Usage Line</button>
</div>
</div>
<h2 id="footer"><a href="./Used_Line.php?Used_OrderID=<?php echo $_GET['Used_OrderID']; ?>">Go Back To Usage Details »</a></h2>
</body>
<script>
function insertUsedLine() {
var ulorder = document.getElementById('ulorder').value;
var ulcomponent = document.getElementById('ulcomponent').value;
var ulquantity = document.getElementById('ulquantity').value;
var ulcost = document.getElementById('ulcost').value;
var ulstatus = document.getElementById('ulstatus').value;
var datepicker = document.getElementById('datepicker').value;
var ulsubtotal = document.getElementById('ulsubtotal').value;
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200)
{
req.responseText;
}
}
req.open("GET", "insertUsed_Line.php?ulorder=" + ulorder
+ "&ulcomponent=" + ulcomponent
+ "&ulquantity=" + ulquantity
+ "&ulcost=" + ulcost
+ "&ulstatus=" + ulstatus
+ "&datepicker=" + datepicker
+ "&ulsubtotal=" + ulsubtotal
);
req.send();
alert("Added New Usage Line Successfully");
location.replace("./Used_Line.php?Used_OrderID=<?php echo $_GET['Used_OrderID']; ?>");
}
function showComponentTable() {
$("#ulctable").toggle();
};
$(document).ready(function($) {
$(".clickable-row").click(function() {
document.getElementById("ulcomponent").value = $(this).data("href");
$("#ulctable").hide();
});
});
function calcSubtotal() {
var ulquantity = document.getElementById('ulquantity').value;
var ulcost = document.getElementById('ulcost').value;
var ulsubtotal;
if(ulquantity == "" || ulcost == "") {
ulsubtotal = "";
document.getElementById('ulsubtotal').value = ulsubtotal;
}
else {
ulsubtotal = ulquantity * ulcost;
document.getElementById('ulsubtotal').value = ulsubtotal.toFixed(2);
}
}
</script>
<?php $conn = null; ?>
</body>
</html>