int change = itemChange.getInt("change");
int denomination = itemChange.getInt("denomination");
Inventory inventory = findInventory(itemID, denomination);
if (inventory == null) { throw new ServiceException("Invalid sale request item:" + itemID + " denomination:" + denomination); }
if (change > 0) {
runningTotalCash -= change * inventory.getPrice();
}
else {
runningTotalCash += change * inventory.getPurchaseprice();
// The player does not have enough of that item to sell
if (player.item(itemID).amount() >= -change) { throw new ServiceException("Insufficent quantity item : " + player.item(itemID).name()); }
}
}
if (!(runningTotalCash >= 0)) { throw new ServiceException("Not enough cash to complete order"); }
for (int index = 0; index < itemChanges.length(); index++) {
JSONObject itemChange = itemChanges.getJSONObject(index);
int itemID = itemChange.getInt("item");