Пример #1
0
  @Override
  public void addToStock(AbstractProduct product, int pointOfSaleId, int units) {

    PointOfSale pos = pointOfSaleCRUD.readPointOfSale(pointOfSaleId);
    // if (pos == null) {
    // pos = new PointOfSale();
    // pos.setId(pointOfSaleId);
    // pos = pointOfSaleCRUD.createPointOfSale(pos);
    // }

    StockItem stockItem = stockItemCRUD.readStockItem(product, pos);
    if (stockItem == null) {
      stockItem = new StockItem(product, pos, units);
      stockItem = stockItemCRUD.createStockItem(stockItem);
    }
    stockItem.setUnits(stockItem.getUnits() + units);

    // logger.info("addToStock: " + product);
    //
    // if (!this.stock.containsKey(product.getName())) {
    // this.stock.put(product.getName(), new HashMap<Integer, StockItem>());
    // }
    //
    // PointOfSale pos = new PointOfSale();
    // pos.setId(pointOfSaleId);
    //
    // StockItem stockItem = new StockItem();
    // stockItem.setProduct(product);
    // stockItem.setUnits(units);
    // stockItem.setPos(pos);
    //
    // this.stock.get(product.getName()).put(pointOfSaleId, stockItem);
  }
Пример #2
0
  @Override
  public int getUnitsOnStock(AbstractProduct product, int pointOfSaleId) {

    PointOfSale pos = pointOfSaleCRUD.readPointOfSale(pointOfSaleId);

    if (pos != null) {
      StockItem stockItem = stockItemCRUD.readStockItem(product, pos);

      if (stockItem == null) {
        return 0;
      }

      return stockItem.getUnits();
    }
    return 0;

    // HashMap<Integer, StockItem> result = (HashMap<Integer, StockItem>)
    // this.stock.get(product.getName());
    //
    // if (result == null) {
    // return 0;
    // } else {
    // return result.get(pointOfSaleId).getUnits();
    // }
  }
Пример #3
0
 @Override
 public void setStockItemPrice(AbstractProduct product, int pointOfSaleId, float price) {
   PointOfSale pos = pointOfSaleCRUD.readPointOfSale(pointOfSaleId);
   StockItem stockItem = stockItemCRUD.readStockItem(product, pos);
   if (stockItem != null) {
     stockItem.setPrice(price);
   }
 }
Пример #4
0
  @Override
  public float getPriceForProductAndPos(IndividualisedProductItem product, int pointOfSaleId) {
    PointOfSale pos = pointOfSaleCRUD.readPointOfSale(pointOfSaleId);
    StockItem stockItem = stockItemCRUD.readStockItem(product, pos);

    if (stockItem.getPrice() > 0) {
      return stockItem.getPrice();
    } else {
      return stockItem.getProduct().getPrice();
    }
  }
Пример #5
0
  @Override
  public List<AbstractProduct> getProductsOnStock(int pointOfSaleId) {

    PointOfSale pos = pointOfSaleCRUD.readPointOfSale(pointOfSaleId);

    List<StockItem> stockItems = stockItemCRUD.readStockItems(pos);
    List<AbstractProduct> productItems = new ArrayList<AbstractProduct>();

    for (StockItem stockItem : stockItems) {
      productItems.add(stockItem.getProduct());
    }

    return productItems;
  }