@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); }
@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(); // } }
@Override public int getTotalUnitsOnStock(AbstractProduct product) { int unitsOnStock = 0; List<StockItem> stockItems = stockItemCRUD.readStockItems(product); for (StockItem stockItem : stockItems) { unitsOnStock += stockItem.getUnits(); } return unitsOnStock; }