Example #1
0
  /** Add new StockItem to table. */
  public void addItem(final SoldItem soldItem) throws SalesSystemException {

    StockItem stockItem = soldItem.getStockItem();
    long stockItemId = stockItem.getId();
    SoldItem existingItem = getForStockItem(stockItemId);

    if (existingItem != null) {
      int totalQuantity = existingItem.getQuantity() + soldItem.getQuantity();
      validateQuantityInStock(stockItem, totalQuantity);
      existingItem.setQuantity(totalQuantity);

      log.debug(
          "Found existing item "
              + soldItem.getName()
              + " increased quantity by "
              + soldItem.getQuantity());

    } else {
      validateQuantityInStock(soldItem.getStockItem(), soldItem.getQuantity());
      getRows().add(soldItem);
      log.debug("Added " + soldItem.getName() + " quantity of " + soldItem.getQuantity());
    }

    fireTableDataChanged();
  }
Example #2
0
 public SoldItem getForStockItem(long stockItemId) {
   for (SoldItem item : getRows()) {
     if (item.getStockItem().getId().equals(stockItemId)) {
       return item;
     }
   }
   return null;
 }