/
required_purchases.php
executable file
·94 lines (76 loc) · 1.96 KB
/
required_purchases.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
<?php
require ("settings.php");
if (isset($_REQUEST["key"])) {
switch ($_REQUEST["key"]) {
case "display":
$OUTPUT = display();
break;
case "purchaseitem":
$OUTPUT = purchaseItem();
break;
case "purchaseall":
$OUTPUT = purchaseAll();
break;
}
} else {
$OUTPUT = display();
}
require ("template.php");
function display()
{
$sql = "SELECT * FROM cubit.stock ORDER BY stkcod ASC";
$stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock.");
$stock_out = "";
while ($stock_data = pg_fetch_array($stock_rslt)) {
// Retrieve units on order
$sql = "SELECT sum(qty) FROM cubit.sorders_items WHERE stkid='$stock_data[stkid]'";
$order_rslt = db_exec($sql) or errDie("Unable to retrieve orders.");
$order_qty = pg_fetch_result($order_rslt, 0);
if (empty($stock_data["minlvl"])) {
continue;
}
if (empty($order_qty)) {
$order_qty = 0;
}
$units = $stock_data["units"] - $order_qty;
$required = abs($units - $stock_data["minlvl"]);
// We're not required to purchase this item
if ($units > $stock_data["minlvl"]) {
continue;
}
$stock_out .= "
<tr class='".bg_class()."'>
<td>$stock_data[stkcod]</td>
<td>$stock_data[stkdes]</td>
<td align='center'>".sprint3($stock_data['units'])."</td>
<td align='center'>".sprint3($order_qty)."</td>
<td align='center'>".sprint3($stock_data['minlvl'])."</td>
<td align='center'><b>".sprint3($required)."</b></td>
<td><a href='purchase-new.php'>Purchase</a></td>
</tr>";
}
if (empty($stock_out)) {
$stock_out = "
<tr class='".bg_class()."'>
<td colspan='7'>No items required for purchase.</td>
</tr>";
}
$OUTPUT = "
<center>
<h3>Required Purchases</h3>
<table ".TMPL_tblDflts.">
<tr>
<th>Stock Code</th>
<th>Stock Description</th>
<th>Current Units</th>
<th>Units on Order</th>
<th>Minimum Level</th>
<th>Minimum Required</th>
<th>Options</th>
</tr>
$stock_out
</table>
</center>";
return $OUTPUT;
}
?>