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) . '.'); } } }