function insert_item($PO_num) { if ($PO_num <= 0) { return $PO_num; } include 'php/dbconnect.php'; if ($link->connect_error) { die("Connection failed: " . $link->connect_error); } $Insert_OK = TRUE; $sql = "SELECT SKU, Count FROM purchase_order_log WHERE PONumber = '{$PO_num}'"; $result = $link->query($sql); if ($result->num_rows > 0) { // use the first row $row = $result->fetch_assoc(); $SKU = $row["SKU"]; $Count = get_stock_count($SKU); $PO_Count = $row["Count"]; if (is_consumable($SKU)) { //Is consumable $sql = "UPDATE item SET Stock_Count=Stock_Count+{$PO_Count} WHERE item.SKU={$SKU}"; $result = $link->query($sql); $sql = "SELECT Description, Manufacturer FROM item WHERE SKU = {$SKU}"; $result = $link->query($sql); if ($result->num_rows > 0) { // use the first row $row = $result->fetch_assoc(); $Description = $row["Description"]; $Manufacturer = $row["Manufacturer"]; echo "<h3>Consumable Item Updated</h3>"; echo "<br>"; echo "Description: "; echo $Description; echo "<br>"; echo "Manufacturer: "; echo get_manufacturer($Manufacturer); echo "<br>"; echo "SKU: "; echo $SKU; echo "<br>"; echo "Stock Count: "; echo $Count; echo "<br>"; } else { //Database error $Insert_OK = FALSE; } } else { //Not consumable for ($i = 1; $i <= $PO_Count; $i++) { $Serial_Number = get_serial_number(); $sql = "SELECT Description, Manufacturer FROM item WHERE SKU = {$SKU}"; $result = $link->query($sql); if ($result->num_rows > 0) { // use the first row $row = $result->fetch_assoc(); $Description = $row["Description"]; $Manufacturer = $row["Manufacturer"]; $sql = "INSERT INTO item (Description, Manufacturer, Serial_Number, SKU, Stock_Count) VALUES ('{$Description}', '{$Manufacturer}', '{$Serial_Number}', '{$SKU}', 1)"; if ($link->query($sql) === TRUE) { echo "<h3>Equipment Entered</h3>"; echo "<br>"; echo "Description: "; echo $Description; echo "<br>"; echo "Manufacturer: "; echo get_manufacturer($Manufacturer); echo "<br>"; echo "Serial Number: "; echo $Serial_Number; echo "<br>"; echo "SKU: "; echo $SKU; echo "<br>"; echo "Stock Count: "; echo $Count; echo "<br>"; } else { $Insert_OK = FALSE; echo "Error: " . $sql . "<br>" . $link->error; } } else { //Database error $Insert_OK = FALSE; } } } } else { //error PO number not found $Insert_OK = FALSE; } if ($Insert_OK == TRUE) { close_PO($PO_num); } return $PO_num; }
<?php if (isset($_POST['Submit'])) { echo "<h3>Purchase Order Submitted</h3>"; echo "<br>"; echo "Requestor: "; echo $_SESSION['username']; echo "<br>"; echo "SKU: "; echo $SKU; echo "<br>"; echo "Description: "; echo $description[$SKU]; echo "<br>"; echo "Manufacturer: "; echo get_manufacturer($manufacturer[$SKU]); echo "<br>"; echo "Count: "; echo $count; echo "<br>"; create_purchase_order($SKU, $count, $_SESSION['username']); } ?> </div> <?php include 'php/footer.php'; ?> </body> </html>