<?php require_once 'inc/init.php'; require_once 'inc/class.wine.php'; echo 'Hello Wine Enthusiasts.<br>'; $dbh->query("DELETE FROM wine"); $dbh->query("DELETE FROM inventory"); $newWine = new Wine($dbh); $newWine->setUPC('1541948561658'); $newWine->setName('Pinot Grigio'); $newWine->setVintage('1954'); $newWine->setSellPrice('150.00'); $id = $newWine->writeWineToTable(); echo $id . '<br>'; $newWine->setID($id); $id = $newWine->addInventory(10, 15.5, 'Bought From Bob'); echo $id . '<br>'; $id = $newWine->removeInventory(5, 45.5, 'Sold To James'); echo $id;
function transferInventory($arr, $dbh) { $wine = new Wine($dbh); if (!is_null($arr['wine_id']) && $arr['wine_id'] != '') { $wine->fetchWineById($arr['wine_id']); } else { die('Wine Not Found'); } if (!is_null($arr['wine_id']) && !is_null($arr['quantity'])) { $args = array('location' => $arr['location']); if ($arr['quantity'] <= $wine->getCurrentInventory($args)) { $args = array('quantity' => $arr['quantity'], 'sell_price' => 0, 'notes' => 'Inventory Transfer To ' . getLocationName($arr['location-to'], $dbh) . ' :::: ' . $arr['notes'], 'location' => $arr['location']); $fromid = $wine->removeInventory($args); $args = array('quantity' => $arr['quantity'], 'cost' => 0, 'notes' => 'Inventory Transfer From ' . getLocationName($arr['location'], $dbh) . ' :::: ' . $arr['notes'], 'location' => $arr['location-to']); $toid = $wine->addInventory($args); if ($fromid != 0 && $toid != 0) { die('Inventory Transferred'); } else { die('Database Error'); } } else { die('You cannot remove more inventory than you have in stock. Current inventory for this item in this location is ' . $wine->getCurrentInventory($args) . '.'); } } }