-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice-edit.php
383 lines (355 loc) · 16.7 KB
/
invoice-edit.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?php
include('header.php');
include('functions.php');
$getID = $_GET['id'];
// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
// output any connection error
if ($mysqli->connect_error) {
die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}
// the query
$query = "SELECT p.*, i.*, c.*
FROM invoice_items p
JOIN invoices i ON i.invoice = p.invoice
JOIN customers c ON c.invoice = i.invoice
WHERE p.invoice = '" . $mysqli->real_escape_string($getID) . "'";
$result = mysqli_query($mysqli, $query);
// mysqli select query
if($result) {
while ($row = mysqli_fetch_assoc($result)) {
$customer_name = $row['name']; // customer name
$customer_email = $row['email']; // customer email
$customer_address_1 = $row['address_1']; // customer address
$customer_address_2 = $row['address_2']; // customer address
$customer_town = $row['town']; // customer town
$customer_county = $row['county']; // customer county
$customer_postcode = $row['postcode']; // customer postcode
$customer_phone = $row['phone']; // customer phone number
//shipping
$customer_name_ship = $row['name_ship']; // customer name (shipping)
$customer_address_1_ship = $row['address_1_ship']; // customer address (shipping)
$customer_address_2_ship = $row['address_2_ship']; // customer address (shipping)
$customer_town_ship = $row['town_ship']; // customer town (shipping)
$customer_county_ship = $row['county_ship']; // customer county (shipping)
$customer_postcode_ship = $row['postcode_ship']; // customer postcode (shipping)
// invoice details
$invoice_number = $row['invoice']; // invoice number
$custom_email = $row['custom_email']; // invoice custom email body
$invoice_date = $row['invoice_date']; // invoice date
$invoice_due_date = $row['invoice_due_date']; // invoice due date
$invoice_subtotal = $row['subtotal']; // invoice sub-total
$invoice_shipping = $row['shipping']; // invoice shipping amount
$invoice_discount = $row['discount']; // invoice discount
$invoice_vat = $row['vat']; // invoice vat
$invoice_total = $row['total']; // invoice total
$invoice_notes = $row['notes']; // Invoice notes
$invoice_type = $row['invoice_type']; // Invoice type
$invoice_status = $row['status']; // Invoice status
}
}
/* close connection */
$mysqli->close();
?>
<h1>Edit Invoice (<?php echo $getID; ?>)</h1>
<hr>
<div id="response" class="alert alert-success" style="display:none;">
<a href="#" class="close" data-dismiss="alert">×</a>
<div class="message"></div>
</div>
<form method="post" id="update_invoice">
<input type="hidden" name="action" value="update_invoice">
<input type="hidden" name="update_id" value="<?php echo $getID; ?>">
<div class="row">
<div class="col-xs-12">
<textarea name="custom_email" id="custom_email" class="custom_email_textarea" placeholder="Enter a custom email message here if you wish to override the default invoice type email message."><?php echo $custom_email; ?></textarea>
</div>
</div>
<div class="row">
<div class="col-xs-5">
<h1>
<img src="<?php echo COMPANY_LOGO ?>" class="img-responsive">
</h1>
</div>
<div class="col-xs-7 text-right">
<div class="row">
<div class="col-xs-6">
<h1>INVOICE</h1>
</div>
<div class="col-xs-3">
<select name="invoice_type" id="invoice_type" class="form-control">
<option value="invoice" <?php if($invoice_type === 'invoice'){?>selected<?php } ?>>Invoice</option>
<option value="quote" <?php if($invoice_type === 'quote'){?>selected<?php } ?>>Quote</option>
<option value="receipt" <?php if($invoice_type === 'receipt'){?>selected<?php } ?>>Receipt</option>
</select>
</div>
<div class="col-xs-3">
<select name="invoice_status" id="invoice_status" class="form-control">
<option value="open" <?php if($invoice_status === 'open'){?>selected<?php } ?>>Open</option>
<option value="paid" <?php if($invoice_status === 'paid'){?>selected<?php } ?>>Paid</option>
</select>
</div>
</div>
<div class="col-xs-4 no-padding-right">
<div class="form-group">
<div class="input-group date" id="invoice_date">
<input type="text" class="form-control required" name="invoice_date" placeholder="Select invoice date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<div class="input-group date" id="invoice_due_date">
<input type="text" class="form-control required" name="invoice_due_date" placeholder="Select due date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_due_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="input-group col-xs-4 float-right">
<span class="input-group-addon">#<?php echo INVOICE_PREFIX ?></span>
<input type="text" name="invoice_id" id="invoice_id" class="form-control required" placeholder="Invoice Number" aria-describedby="sizing-addon1" value="<?php echo $getID; ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Customer Information</h4>
<div class="clear"></div>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_name" id="customer_name" placeholder="Enter name" tabindex="1" value="<?php echo $customer_name; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_address_1" id="customer_address_1" placeholder="Address 1" tabindex="3" value="<?php echo $customer_address_1; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_town" id="customer_town" placeholder="Town" tabindex="5" value="<?php echo $customer_town; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control copy-input required" name="customer_postcode" id="customer_postcode" placeholder="Postcode" tabindex="7" value="<?php echo $customer_postcode; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="input-group float-right margin-bottom">
<span class="input-group-addon">@</span>
<input type="email" class="form-control copy-input required" name="customer_email" id="customer_email" placeholder="E-mail address" aria-describedby="sizing-addon1" tabindex="2" value="<?php echo $customer_email; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input" name="customer_address_2" id="customer_address_2" placeholder="Address 2" tabindex="4" value="<?php echo $customer_address_2; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_county" id="customer_county" placeholder="County" tabindex="6" value="<?php echo $customer_county; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_phone" id="invoice_phone" placeholder="Phone number" tabindex="8" value="<?php echo $customer_phone; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 text-right">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Shipping Information</h4>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_name_ship" id="customer_name_ship" placeholder="Enter name" tabindex="9" value="<?php echo $customer_name_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom" name="customer_address_2_ship" id="customer_address_2_ship" placeholder="Address 2" tabindex="11" value="<?php echo $customer_address_2_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_county_ship" id="customer_county_ship" placeholder="County" tabindex="13" value="<?php echo $customer_county_ship; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_address_1_ship" id="customer_address_1_ship" placeholder="Address 1" tabindex="10" value="<?php echo $customer_address_1_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_town_ship" id="customer_town_ship" placeholder="Town" tabindex="12" value="<?php echo $customer_town_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_postcode_ship" id="customer_postcode_ship" placeholder="Postcode" tabindex="14" value="<?php echo $customer_postcode_ship; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / end client details section -->
<table class="table table-bordered" id="invoice_table">
<thead>
<tr>
<th width="500">
<h4><a href="#" class="btn btn-success btn-xs add-row"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a> Item</h4>
</th>
<th>
<h4>Qty</h4>
</th>
<th>
<h4>Price</h4>
</th>
<th width="300">
<h4>Discount</h4>
</th>
<th>
<h4>Sub Total</h4>
</th>
</tr>
</thead>
<tbody>
<?php
// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
// output any connection error
if ($mysqli->connect_error) {
die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}
// the query
$query2 = "SELECT * FROM invoice_items WHERE invoice = '" . $mysqli->real_escape_string($getID) . "'";
$result2 = mysqli_query($mysqli, $query2);
//var_dump($result2);
// mysqli select query
if($result2) {
while ($rows = mysqli_fetch_assoc($result2)) {
//var_dump($rows);
$item_product = $rows['product'];
$item_qty = $rows['qty'];
$item_price = $rows['price'];
$item_discount = $rows['discount'];
$item_subtotal = $rows['subtotal'];
?>
<tr>
<td>
<div class="form-group form-group-sm no-margin-bottom">
<a href="#" class="btn btn-danger btn-xs delete-row"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
<input type="text" class="form-control form-group-sm item-input invoice_product" name="invoice_product[]" placeholder="Enter item title and / or description" value="<?php echo $item_product; ?>">
<p class="item-select">or <a href="#">select an item</a></p>
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control invoice_product_qty calculate" name="invoice_product_qty[]" value="<?php echo $item_qty; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm no-margin-bottom">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate invoice_product_price required" name="invoice_product_price[]" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $item_price; ?>">
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_discount[]" placeholder="Enter % or value (ex: 10% or 10.50)" value="<?php echo $item_discount; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate-sub" name="invoice_product_sub[]" id="invoice_product_sub" aria-describedby="sizing-addon1" value="<?php echo $item_subtotal; ?>" disabled>
</div>
</td>
</tr>
<?php } } ?>
</tbody>
</table>
<div id="invoice_totals" class="padding-right row text-right">
<div class="col-xs-6">
<div class="input-group form-group-sm textarea no-margin-bottom">
<textarea class-"form-control" name="invoice_notes" placeholder="Please enter any order notes here."><?php echo $invoice_notes; ?></textarea>
</div>
</div>
<div class="col-xs-6 no-padding-right">
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Sub Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-sub-total"> <?php echo $invoice_subtotal; ?></span>
<input type="hidden" name="invoice_subtotal" id="invoice_subtotal" value="<?php echo $invoice_subtotal; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Discount:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-discount"> <?php echo $invoice_discount; ?></span>
<input type="hidden" name="invoice_discount" id="invoice_discount" value="<?php echo $invoice_discount; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong class="shipping">Shipping:</strong>
</div>
<div class="col-xs-3">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate shipping" name="invoice_shipping" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $invoice_shipping; ?>">
</div>
</div>
</div>
<?php if (ENABLE_VAT == true) { ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>TAX/VAT:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-vat" data-enable-vat="<?php echo ENABLE_VAT ?>" data-vat-rate="<?php echo VAT_RATE ?>" data-vat-method="<?php echo VAT_INCLUDED ?>"><?php echo $invoice_vat; ?></span>
<input type="hidden" name="invoice_vat" id="invoice_vat" value="<?php echo $invoice_vat; ?>">
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-total"> <?php echo $invoice_total; ?></span>
<input type="hidden" name="invoice_total" id="invoice_total" value="<?php echo $invoice_total; ?>">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 margin-top btn-group">
<input type="submit" id="action_edit_invoice" class="btn btn-success float-right" value="Update Invoice" data-loading-text="Updating...">
</div>
</div>
</form>
<div id="insert" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Select an item</h4>
</div>
<div class="modal-body">
<?php popProductsList(); ?>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary" id="selected">Add</button>
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
include('footer.php');
?>