This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
neworder.php
196 lines (173 loc) · 8.06 KB
/
neworder.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 'dbconfig.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$products = array();
$id = 0;
foreach ($_POST['product'] as &$value) {
//$value = $value * 2;
$date = $_POST['date'];
$attribes = $_POST['attribute'];
$qty = $_POST['qty'];
$price = $_POST['price'];
$shipping = $_POST['shipping'];
$total = $_POST['total'];
$link = $_POST['link'];
$products['products'][$id]['name'] = $value;
$products['products'][$id]['status'] = 'Ordered';
$products['products'][$id]['attributes'] = $attribes[$id];
$products['products'][$id]['quantity'] = $quantity[$id];
$products['products'][$id]['price'] = $price[$id];
$products['products'][$id]['shipping'] = $shipping[$id];
$products['products'][$id]['total'] = $total[$id];
$products['products'][$id]['link'] = $link[$id];
$id = $id + 1;
}
$products['address'] = $_POST['address'];
$products['total'] = $_POST['total_amount'];
$products['shipping method'] = $_POST['shippingmethod'];
$products = json_encode($products);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO orders (date, info, status)
VALUES ('$date', '$products', 'Started')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
die();
}
$conn->close();
}
?>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<form method="post">
<div class="container">
<div class="row clearfix">
<div class="col-md-12">
<label>Address:</label><input required type="text" name='address' placeholder='Enter Address' class="form-control" /><br>
<label>Shipping Method:</label><input required type="text" name='shippingmethod' placeholder='Shipping Method' class="form-control" /><br>
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr>
<th class="text-center"> # </th>
<th class="text-center"> Product </th>
<th class="text-center"> Attributes </th>
<th class="text-center"> Qty </th>
<th class="text-center"> Price </th>
<th class="text-center"> Shipping </th>
<th class="text-center"> Total </th>
<th class="text-center"> Link </th>
</tr>
</thead>
<tbody>
<tr id='addr0'>
<td>1</td>
<td><input required type="text" name='product[]' placeholder='Enter Product Name' class="form-control" /></td>
<td><input required type="text" name='attribute[]' placeholder='Enter Attribute' class="form-control" /></td>
<td><input required type="number" name='qty[]' placeholder='Enter Qty' class="form-control qty" step="0" min="0" /></td>
<td><input required type="number" name='price[]' placeholder='Enter Unit Price' class="form-control price" step="0.00" min="0" /></td>
<td><input required type="number" name='shipping[]' placeholder='Enter Shipping Price' class="form-control shipping" step="0.00" min="0" /></td>
<td><input required type="number" name='total[]' placeholder='0.00' class="form-control total" readonly /></td>
<td><input required type="text" name='link[]' placeholder='Enter Link' class="form-control" /></td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12">
<button id="add_row" class="btn btn-default pull-left">Add Row</button>
<button id='delete_row' class="pull-right btn btn-default">Delete Row</button>
</div>
</div>
<div class="row clearfix" style="margin-top:20px">
<div class="pull-right col-md-4">
<table class="table table-bordered table-hover" id="tab_logic_total">
<tbody>
<tr>
<th class="text-center">Date</th>
<td class="text-center"><input type="date" name='date' id="date" class="form-control" required/></td>
</tr>
<tr>
<th class="text-center">Sub Total</th>
<td class="text-center"><input type="number" name='sub_total' placeholder='0.00' class="form-control" id="sub_total" readonly /></td>
</tr>
<tr>
<th class="text-center">Tax</th>
<td class="text-center">
<div class="input-group mb-2 mb-sm-0">
<input type="number" class="form-control" id="tax" placeholder="0">
<div class="input-group-addon">%</div>
</div>
</td>
</tr>
<tr>
<th class="text-center">Tax Amount</th>
<td class="text-center"><input type="number" name='tax_amount' id="tax_amount" placeholder='0.00' class="form-control" readonly /></td>
</tr>
<tr>
<th class="text-center">Grand Total</th>
<td class="text-center"><input type="number" name='total_amount' id="total_amount" placeholder='0.00' class="form-control" readonly /></td>
</tr>
</tbody>
</table>
</div>
</div>
<button type="submit">Submit</button>
</div>
</form>
<script>
$(document).ready(function() {
var i = 1;
$("#add_row").click(function() {
b = i - 1;
$('#addr' + i).html($('#addr' + b).html()).find('td:first-child').html(i + 1);
$('#tab_logic').append('<tr id="addr' + (i + 1) + '"></tr>');
i++;
});
$("#delete_row").click(function() {
if (i > 1) {
$("#addr" + (i - 1)).html('');
i--;
}
calc();
});
$('#tab_logic tbody').on('keyup change', function() {
calc();
});
$('#tax').on('keyup change', function() {
calc_total();
});
});
function calc() {
$('#tab_logic tbody tr').each(function(i, element) {
var html = $(this).html();
if (html != '') {
var qty = $(this).find('.qty').val();
var price = $(this).find('.price').val();
var shipping = $(this).find('.shipping').val();
var simple = (qty * price)
var quick = (Number(simple) + Number(shipping));
$(this).find('.total').val(quick);
calc_total();
}
});
}
function calc_total() {
total = 0;
$('.total').each(function() {
total += parseInt($(this).val());
});
$('#sub_total').val(total.toFixed(2));
tax_sum = total / 100 * $('#tax').val();
$('#tax_amount').val(tax_sum.toFixed(2));
$('#total_amount').val((tax_sum + total).toFixed(2));
}
</script>