public void createBackOrder(String inventoryID, int amountToOrder, int maximumItems)
{
try
{
Util.debug("BackOrderStockBean.createBackOrder() - Entered");
BackOrder backOrder = null;
try
{
// See if there is already an existing backorder and increase the order quantity
// but only if it has not been sent to the supplier.
// backOrder = getBackOrderLocalHome().findByInventoryIDUpdate(inventoryID);
// TODO: query need updating based on relation?
Query q = em.createNamedQuery("findByInventoryID");
q.setParameter("id", inventoryID);
backOrder = (BackOrder) q.getSingleResult();
if (!(backOrder.getStatus().equals(Util.STATUS_ORDERSTOCK)))
{
Util.debug("BackOrderStockBean.createBackOrder() - Backorders found but have already been ordered from the supplier");
// throw new FinderException();
}
// Increase the BackOrder quantity for an existing Back Order.
backOrder.setQuantity(backOrder.getQuantity() + amountToOrder);
}
catch (NoResultException e)
{
Util.debug("BackOrderStockBean.createBackOrder() - BackOrder doesn't exist." + e);
Util.debug("BackOrderStockBean.createBackOrder() - Creating BackOrder for InventoryID: " + inventoryID);
// Order enough stock from the supplier to reach the maximum threshold and to
// satisfy the back order.
amountToOrder = maximumItems + amountToOrder;
// backOrder = getBackOrderLocalHome().create(inventoryID, amountToOrder);
Inventory inv = em.find(Inventory.class, inventoryID);
BackOrder b = new BackOrder(inv, amountToOrder);
em.persist(b);
}
}
catch (Exception e)
{