Class StockMovementUtils
java.lang.Object
ch.tocco.nice2.optional.order.api.StockMovementUtils
-
Method Summary
Modifier and TypeMethodDescriptiongetValidRetailPrice
(Entity priceCategory, Entity article, org.joda.time.LocalDate movementDate, QueryBuilderFactory queryBuilderFactory, Context ctx) Determines the retail price for stock movment from affected article according to selected price category and stock movement date.static boolean
haveInStock
(Entity article, @Nullable Integer amount) Checks if enough articles are in stock for outward stock movement.static void
recalculateAverageCostPrice
(Entity stockMovement, Entity article) Recalucates actual inventory amount on inward stock movements for affected article.static void
setRetailPriceForPricecategory
(Entity stockMovement, Entity article, QueryBuilderFactory queryBuilderFactory, Context ctx) Determines and sets the retail price for stock movment from affected article according to selected price category and stock movement date.static void
updateStock
(Entity article, @Nullable Integer amount, Entity stockMovement, boolean isInward) Updates the actual inventory stock on affected article.
-
Method Details
-
recalculateAverageCostPrice
Recalucates actual inventory amount on inward stock movements for affected article. Calculation formula: `new_average_cost_price = ((old_stock_amount * old_average_cost_price) + (inward_stock_movement_amount * inward_stock_movement_cost_price)) / new_stock_amount`- Parameters:
stockMovement
- the new created outward stock movment entityarticle
- the affected article entity
-
setRetailPriceForPricecategory
public static void setRetailPriceForPricecategory(Entity stockMovement, Entity article, QueryBuilderFactory queryBuilderFactory, Context ctx) Determines and sets the retail price for stock movment from affected article according to selected price category and stock movement date. Price is set to zero when no valid price can be found.- Parameters:
stockMovement
- the new created outward stock movment entityarticle
- the affected article entityqueryBuilderFactory
- QueryBuilderFactory instancectx
- current Context
-
getValidRetailPrice
public static Optional<Entity> getValidRetailPrice(Entity priceCategory, Entity article, org.joda.time.LocalDate movementDate, QueryBuilderFactory queryBuilderFactory, Context ctx) Determines the retail price for stock movment from affected article according to selected price category and stock movement date.- Parameters:
priceCategory
- the price category entityarticle
- the affected article entitymovementDate
- the stock movement datequeryBuilderFactory
- QueryBuilderFactory instancectx
- current Context- Returns:
- the entity list with valid retail prices. May be empty when no valid prices are found
-
updateStock
public static void updateStock(Entity article, @Nullable @Nullable Integer amount, Entity stockMovement, boolean isInward) Updates the actual inventory stock on affected article. Add amount to stock on inward stock movements or subtract amount otherwise- Parameters:
article
- the affected article entityamount
- inward or outward amountstockMovement
- the stock movement entityisInward
- flag to define if its an inward stock movement @throws PersistException
-
haveInStock
Checks if enough articles are in stock for outward stock movement.- Parameters:
article
- the affected article entityamount
- the outward amount- Returns:
- true if enough articles are in stock, otherwise false
-