@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 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); } }
@Override public List<Integer> getPointsOfSale(AbstractProduct product) { List<Integer> pointOfSaleIds = new ArrayList<Integer>(); List<StockItem> stockItems = stockItemCRUD.readStockItems(product); for (StockItem stockItem : stockItems) { pointOfSaleIds.add(stockItem.getPos().getId()); } return pointOfSaleIds; }
@Override public int getTotalUnitsOnStock(AbstractProduct product) { int unitsOnStock = 0; List<StockItem> stockItems = stockItemCRUD.readStockItems(product); for (StockItem stockItem : stockItems) { unitsOnStock += stockItem.getUnits(); } return unitsOnStock; }
@Override public List<AbstractProduct> getAllProductsOnStock() { List<StockItem> stockItems = stockItemCRUD.readAllStockItems(); List<AbstractProduct> productItems = new ArrayList<AbstractProduct>(); for (StockItem stockItem : stockItems) { productItems.add(stockItem.getProduct()); } return productItems; }
@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(); } }
@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; }