forked from codepoetIn/POSNIC-1.02
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_purchase.php
548 lines (335 loc) · 13.7 KB
/
view_purchase.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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<?php
include_once("init.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>POSNIC - Stock</title>
<!-- Stylesheets -->
<!--<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet'>-->
<link rel="stylesheet" href="css/style.css">
<!-- Optimize for mobile devices -->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<!-- jQuery & JS files -->
<?php include_once("tpl/common_js.php"); ?>
<script src="js/script.js"></script>
<script LANGUAGE="JavaScript">
<!--
// Nannette Thacker http://www.shiningstar.net
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to Delete this Entry?");
if (agree)
return true ;
else
return false ;
}
function confirmDeleteSubmit()
{
var flag=0;
var field=document.forms.deletefiles;
for (i = 0; i < field.length; i++){
if(field[i].checked ==true){
flag=flag+1;
}
}
if (flag <1) {
alert ("You must check one and only one checkbox!");
return false;
}else{
var agree=confirm("Are you sure you wish to Delete Selected Record?");
if (agree)
document.deletefiles.submit();
else
return false ;
}
}
function confirmLimitSubmit()
{
if(document.getElementById('search_limit').value!=""){
document.limit_go.submit();
}else{
return false;
}
}
function checkAll()
{
var field=document.forms.deletefiles;
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}
function uncheckAll()
{
var field=document.forms.deletefiles;
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
// -->
</script>
<script>
/*$.validator.setDefaults({
submitHandler: function() { alert("submitted!"); }
});*/
$(document).ready(function() {
// validate signup form on keyup and submit
$("#form1").validate({
rules: {
name: {
required: true,
minlength: 3,
maxlength: 200
},
address: {
minlength: 3,
maxlength: 500
},
contact1: {
minlength: 3,
maxlength: 20
},
contact2: {
minlength: 3,
maxlength: 20
}
},
messages: {
name: {
required: "Please enter a supplier Name",
minlength: "supplier must consist of at least 3 characters"
},
address: {
minlength: "supplier Address must be at least 3 characters long",
maxlength: "supplier Address must be at least 3 characters long"
}
}
});
});
</script>
</head>
<body>
<!-- TOP BAR -->
<?php include_once("tpl/top_bar.php"); ?>
<!-- end top-bar -->
<!-- HEADER -->
<div id="header-with-tabs">
<div class="page-full-width cf">
<ul id="tabs" class="fl">
<li><a href="dashboard.php" class="dashboard-tab">Dashboard</a></li>
<li><a href="view_sales.php" class="sales-tab">Sales</a></li>
<li><a href="view_customers.php" class=" customers-tab">Customers</a></li>
<li><a href="view_purchase.php" class="active-tab purchase-tab">Purchase</a></li>
<li><a href="view_supplier.php" class=" supplier-tab">Supplier</a></li>
<li><a href="view_product.php" class=" stock-tab">Stocks / Products</a></li>
<li><a href="view_payments.php" class="payment-tab">Payments / Outstandings</a></li>
<li><a href="view_report.php" class="report-tab">Reports</a></li>
</ul> <!-- end tabs -->
<!-- Change this image to your own company's logo -->
<!-- The logo will automatically be resized to 30px height. -->
<a href="#" id="company-branding-small" class="fr"><img src="<?php if(isset($_SESSION['logo'])) { echo "upload/".$_SESSION['logo'];}else{ echo "upload/posnic.png"; } ?>" alt="Point of Sale" /></a>
</div> <!-- end full-width -->
</div> <!-- end header -->
<!-- MAIN CONTENT -->
<div id="content">
<div class="page-full-width cf">
<div class="side-menu fl">
<h3>Stock Purchase</h3>
<ul>
<li><a href="add_purchase.php">Add Purchase</a></li>
<li><a href="view_purchase.php">View Purchase </a></li>
</ul>
</div> <!-- end side-menu -->
<div class="side-content fr">
<div class="content-module">
<div class="content-module-heading cf">
<h3 class="fl">Purchase</h3>
<span class="fr expand-collapse-text">Click to collapse</span>
<span class="fr expand-collapse-text initial-expand">Click to expand</span>
</div> <!-- end content-module-heading -->
<div class="content-module-main cf">
<table>
<form action="" method="post" name="search" >
<input name="searchtxt" type="text" class="round my_text_box" placeholder="Search" >
<input name="Search" type="submit" class="my_button round blue text-upper" value="Search">
</form>
<form action="" method="get" name="limit_go">
Page per Record<input name="limit" type="text" class="round my_text_box" id="search_limit" style="margin-left:5px;" value="<?php if(isset($_GET['limit'])) echo $_GET['limit']; else echo "10"; ?>" size="3" maxlength="3">
<input name="go" type="button" value="Go" class=" round blue my_button text-upper" onclick="return confirmLimitSubmit()">
</form>
<form name="deletefiles" action="delete.php" method="post">
<input type="hidden" name="table" value="stock_entries">
<input type="hidden" name="return" value="view_purchase.php">
<input type="button" name="selectall" value="SelectAll" class="my_button round blue text-upper" onClick="checkAll()" style="margin-left:5px;"/>
<input type="button" name="unselectall" value="DeSelectAll" class="my_button round blue text-upper" onClick="uncheckAll()" style="margin-left:5px;" />
<input name="dsubmit" type="button" value="Delete Selected" class="my_button round blue text-upper" style="margin-left:5px;" onclick="return confirmDeleteSubmit()"/>
<table>
<?php
$SQL = "SELECT DISTINCT(stock_id) FROM stock_entries where type='entry'";
if(isset($_POST['Search']) AND trim($_POST['searchtxt'])!="")
{
$SQL = "SELECT DISTINCT(stock_id) FROM stock_entries WHERE stock_name LIKE '%".$_POST['searchtxt']."%' OR stock_supplier_name LIKE '%".$_POST['searchtxt']."%' OR stock_id LIKE '%".$_POST['searchtxt']."%' OR date LIKE '%".$_POST['searchtxt']."%' OR type LIKE '%".$_POST['searchtxt']."%' AND type='entry'";
}
$tbl_name="stock_entries"; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = 3;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(DISTINCT stock_id) as num FROM $tbl_name where type='entry'";
if(isset($_POST['Search']) AND trim($_POST['searchtxt'])!="")
{
$query = "SELECT COUNT(DISTINCT stock_id) as num FROM stock_entries WHERE stock_name LIKE '%".$_POST['searchtxt']."%' OR stock_supplier_name LIKE '%".$_POST['searchtxt']."%' OR stock_id LIKE '%".$_POST['searchtxt']."%' OR date LIKE '%".$_POST['searchtxt']."%' OR type LIKE '%".$_POST['searchtxt']."%' and type='entry'";
}
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
/* Setup vars for query. */
$targetpage = "view_stock_entries.php"; //your file name (the name of this file)
$limit = 10; //how many items to show per page
if(isset($_GET['limit']))
$limit=$_GET['limit'];
$page = $_GET['page'];
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
/* Get data. */
$sql = "SELECT DISTINCT(stock_id) FROM stock_entries where type='entry' ORDER BY date desc LIMIT $start, $limit ";
if(isset($_POST['Search']) AND trim($_POST['searchtxt'])!="")
{
$sql = "SELECT DISTINCT(stock_id) FROM stock_entries WHERE stock_name LIKE '%".$_POST['searchtxt']."%' OR stock_supplier_name LIKE '%".$_POST['searchtxt']."%' OR stock_id LIKE '%".$_POST['searchtxt']."%' OR date LIKE '%".$_POST['searchtxt']."%' OR type LIKE '%".$_POST['searchtxt']."%' and type='entry' ORDER BY date desc LIMIT $start, $limit";
}
$result = mysql_query($sql);
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div >";
//previous button
if ($page > 1)
$pagination.= "<a href=\"view_purchase.php?page=$prev&limit=$limit\" class=my_pagination >Previous</a>";
else
$pagination.= "<span class=my_pagination>Previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=my_pagination>$counter</span>";
else
$pagination.= "<a href=\"view_purchase.php?page=$counter&limit=$limit\" class=my_pagination>$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=my_pagination>$counter</span>";
else
$pagination.= "<a href=\"view_purchase.php?page=$counter&limit=$limit\" class=my_pagination>$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"view_purchase.php?page=$lpm1&limit=$limit\" class=my_pagination>$lpm1</a>";
$pagination.= "<a href=\"view_purchase.php?page=$lastpage&limit=$limit\" class=my_pagination>$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"view_purchase.php?page=1&limit=$limit\" class=my_pagination>1</a>";
$pagination.= "<a href=\"view_purchase.php?page=2&limit=$limit\" class=my_pagination>2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=my_pagination>$counter</span>";
else
$pagination.= "<a href=\"view_purchase.php?page=$counter&limit=$limit\" class=my_pagination>$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"view_purchase.php?page=$lpm1&limit=$limit\" class=my_pagination>$lpm1</a>";
$pagination.= "<a href=\"view_purchase.php?page=$lastpage&limit=$limit\" class=my_pagination>$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$view_purchase.php?page=1&limit=$limit\" class=my_pagination>1</a>";
$pagination.= "<a href=\"$view_purchase.php?page=2&limit=$limit\" class=my_pagination>2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=my_pagination >$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter&limit=$limit\" class=my_pagination>$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"view_purchase.php?page=$next&limit=$limit\" class=my_pagination>Next</a>";
else
$pagination.= "<span class= my_pagination >Next</span>";
$pagination.= "</div>\n";
}
?>
<tr>
<th>No</th>
<th>Stock Id</th>
<th>Stock Name</th>
<th>Date</th>
<th>Supplier</th>
<th>Amount</th>
<th>Edit /Delete</th>
<th>Select</th>
<td></td>
</tr>
<?php $i=1; $no=$page-1; $no=$no*$limit;
while($row = mysql_fetch_array($result))
{
$entryid=$row['stock_id'];
$line = $db->queryUniqueObject("SELECT * FROM stock_entries WHERE stock_id='$entryid' ");
$mysqldate=$line->date;
$phpdate = strtotime( $mysqldate );
$phpdate = date("d/m/Y",$phpdate);
?>
<tr>
<td></td>
<td width="100"><?php echo $line->stock_id; ?></td>
<td width="100"><?php echo $line->stock_name; ?></td>
<td width="100"><?php echo $phpdate; ?></td>
<td width="100"><?php echo $line->stock_supplier_name ; ?></td>
<td width="100"><?php echo $line->subtotal; ?></td>
<td> <a href="update_purchase.php?sid=<?php echo $entryid;?>&table=stock_entries&return=view_purchase.php" class="table-actions-button ic-table-edit">
</a>
<a onclick="return confirmSubmit()" href="delete.php?id=<?php echo $row['id'];?>&table=stock_entries&return=view_purchase.php" class="table-actions-button ic-table-delete"></a>
</td>
<td><input type="checkbox" value="<?php echo $row['id']; ?>" name="checklist[]" id="check_box" /></td>
<td></td>
</tr>
<?php $i++; } ?>
<tr>
<td align="center"><div style="margin-left:20px;"><?php echo $pagination; ?></div></td>
</tr>
</table>
</form>
</div>
</div>
<div id="footer">
<p>Any Queries email to <a href="mailto:[email protected]?subject=Stock%20Management%20System">[email protected]</a>.</p>
</div> <!-- end footer -->
</body>
</html>