colonymech / docs / www / colonyscout / internal / inventory_view.php @ f59acf11
History | View | Annotate | Download (5.09 KB)
1 |
<?php
|
---|---|
2 |
$pageNum = (isset($_GET['page'])) ? $_GET['page'] : 1; // if $_GET['page'] defined, use it as page number |
3 |
$rowsPerPage = 30; // how many rows to show per page |
4 |
$offset = ($pageNum - 1) * $rowsPerPage; // counting the offset |
5 |
$sortBy = ""; //default |
6 |
|
7 |
$sortColumn="VendorID"; $sortOrder="DESC"; |
8 |
if(isset($_GET["sortby"])) { |
9 |
$sortBy=$_GET["sortby"]; |
10 |
switch ($sortBy) { |
11 |
case "valinc": |
12 |
$sortColumn = "Description"; $sortOrder="ASC"; |
13 |
break;
|
14 |
case "valdec": |
15 |
$sortColumn = "Description"; $sortOrder="DESC"; |
16 |
break;
|
17 |
case "manfinc": |
18 |
$sortColumn = "ManufacturerName"; $sortOrder="ASC"; |
19 |
break;
|
20 |
case "manfdec": |
21 |
$sortColumn = "ManufacturerName"; $sortOrder="DESC"; |
22 |
break;
|
23 |
case "veninc": |
24 |
$sortColumn = "vendorname"; $sortOrder="ASC"; |
25 |
break;
|
26 |
case "vendec": |
27 |
$sortColumn = "vendorname"; $sortOrder="DESC"; |
28 |
break;
|
29 |
case "qtyinc": |
30 |
$sortColumn = "qty"; $sortOrder="ASC"; |
31 |
break;
|
32 |
case "qtydec": |
33 |
$sortColumn = "qty"; $sortOrder="DESC"; |
34 |
break;
|
35 |
case "priceinc": |
36 |
$sortColumn = "cost_1"; $sortOrder="ASC"; |
37 |
break;
|
38 |
case "pricedec": |
39 |
$sortColumn = "cost_1"; $sortOrder="DESC"; |
40 |
break;
|
41 |
} |
42 |
} |
43 |
|
44 |
//gather the inventory based on search term or all
|
45 |
$get_inventory_sql = "SELECT ID,name,manufacturername,manufacturerpartno,VendorPartNo,description,qty,cost_1, (select name from vendors WHERE vendors.id=inventory.vendorid) as vendorname FROM inventory ORDER BY $sortColumn $sortOrder LIMIT $offset, $rowsPerPage"; |
46 |
$get_inventory_res = mysqli_query($mysqli, $get_inventory_sql) or die(mysqli_error($mysqli)); |
47 |
|
48 |
if (mysqli_num_rows($get_inventory_res) < 1) { |
49 |
$display_block = "</table><br/><h1>No inventory matched those search terms.</h1>"; |
50 |
} else {
|
51 |
//create the display string
|
52 |
$display_block = ""; |
53 |
|
54 |
while ($inv = mysqli_fetch_array($get_inventory_res)) { |
55 |
$display_block .=
|
56 |
"<tr>
|
57 |
<td><a href=\"inventory.php?tab=viewpart&q=".$inv["VendorPartNo"]."\">".$inv["name"]."</a></td> |
58 |
<td>".$inv["description"]."</td><td>".$inv["manufacturername"]."</td> |
59 |
<td><a target=\"_blank\" href=\"".getURL($inv["VendorPartNo"],$inv["vendorname"])."\">".$inv["manufacturerpartno"]."</a></td> |
60 |
<td>".$inv["vendorname"]."</td> |
61 |
<td>".$inv["qty"]."</td> |
62 |
<td>\$".$inv["cost_1"]."</td></tr>"; |
63 |
} |
64 |
$display_block .= "</table><br/><br/>"; |
65 |
|
66 |
// how many rows we have in database
|
67 |
$get_num_inventory_sql = "SELECT COUNT(*) AS inventory_count FROM inventory"; |
68 |
$get_num_inventory_res = mysqli_query($mysqli, $get_num_inventory_sql) or die(mysqli_error($mysqli)); |
69 |
|
70 |
while ($inventory_info = mysqli_fetch_array($get_num_inventory_res)) { |
71 |
$numrows = $inventory_info['inventory_count']; |
72 |
} |
73 |
|
74 |
// how many pages we have when using paging?
|
75 |
$maxPage = ceil($numrows/$rowsPerPage); |
76 |
|
77 |
// print the link to access each page
|
78 |
$nav = ''; |
79 |
for($page = 1; $page <= $maxPage; $page++) { |
80 |
$nav.= ($page == $pageNum) // no need to create a link to current page |
81 |
? "<li class=\"currentpage\">$page</li>\n"
|
82 |
: "<li><a href=\"?tab=".$tab."&page=".$page."&sortby=".$sortBy."\">$page</a></li>\n"; |
83 |
} |
84 |
|
85 |
// creating previous and next link
|
86 |
// plus the link to go straight to
|
87 |
// the first and last page
|
88 |
if ($pageNum > 1) { |
89 |
$page = $pageNum - 1; |
90 |
$prev = "<li><a href=\"?tab=".$tab."&page=".$page."&sortby=".$sortBy."\">prev</a></li>\n"; |
91 |
} else {
|
92 |
$prev = ' '; // we're on page one, don't print previous link |
93 |
} |
94 |
|
95 |
if ($pageNum < $maxPage) { |
96 |
$page = $pageNum + 1; |
97 |
$next = "<li><a href=\"?tab=".$tab."&page=".$page."&sortby=".$sortBy."\">next</a></li>\n"; |
98 |
} else {
|
99 |
$next = ' '; // we're on the last page, don't print next link |
100 |
} |
101 |
|
102 |
// print the navigation link
|
103 |
$navString = "<div id=\"navcontainer\"><ul>".$prev.$nav.$next."</ul>\n</div>"; |
104 |
|
105 |
//free results
|
106 |
mysqli_free_result($get_inventory_res);
|
107 |
|
108 |
} |
109 |
|
110 |
$address = '?tab='.$tab.'&page='.$pageNum."&"; |
111 |
?>
|
112 |
<table style="background-color:#fff;width:920px;"> |
113 |
<tr>
|
114 |
<th width="210px">Part Name<br/> |
115 |
</th>
|
116 |
<th width="70px">Value<br/> |
117 |
<a href="<?php echo $address;?>sortby=valinc"><div class="sort-up"></div></a> |
118 |
<a href="<?php echo $address;?>sortby=valdec"><div class="sort-down"></div></a> |
119 |
</th>
|
120 |
<th width="200px">Manufacturer<br/> |
121 |
<a href="<?php echo $address;?>sortby=manfinc"><div class="sort-up"></div></a> |
122 |
<a href="<?php echo $address;?>sortby=manfdec"><div class="sort-down"></div></a> |
123 |
</th>
|
124 |
<th width="220px">Manufacturer Part No<br/> |
125 |
</th>
|
126 |
<th width="60px">Vendor<br/> |
127 |
<a href="<?php echo $address;?>sortby=veninc"><div class="sort-up"></div></a> |
128 |
<a href="<?php echo $address;?>sortby=vendec"><div class="sort-down"></div></a> |
129 |
</th>
|
130 |
<th width="70px">Qty<br/> |
131 |
<a href="<?php echo $address;?>sortby=qtyinc"><div class="sort-up"></div></a> |
132 |
<a href="<?php echo $address;?>sortby=qtydec"><div class="sort-down"></div></a> |
133 |
</th>
|
134 |
<th width="70px">$/each<br/> |
135 |
<a href="<?php echo $address;?>sortby=priceinc"><div class="sort-up"></div></a> |
136 |
<a href="<?php echo $address;?>sortby=pricedec"><div class="sort-down"></div></a> |
137 |
</th>
|
138 |
</tr>
|
139 |
<?php echo $display_block; echo $navString;?> |
140 |
|
141 |
</div>
|
142 |
</div>
|