/** 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();
  }
 @Override
 protected Object getColumnValue(SoldItem item, int columnIndex) {
   switch (columnIndex) {
     case 0:
       return item.getId();
     case 1:
       return item.getName();
     case 2:
       return item.getPrice();
     case 3:
       return item.getQuantity();
     case 4:
       return item.getSum();
   }
   throw new IllegalArgumentException("Column index out of range");
 }
  @Override
  public String toString() {
    final StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < headers.length; i++) buffer.append(headers[i] + "\t");
    buffer.append("\n");

    for (final SoldItem item : getRows()) {
      buffer.append(item.getId() + "\t");
      buffer.append(item.getName() + "\t");
      buffer.append(item.getPrice() + "\t");
      buffer.append(item.getQuantity() + "\t");
      buffer.append(item.getSum() + "\t");
      buffer.append("\n");
    }

    return buffer.toString();
  }