Class StockMovementUtils

java.lang.Object
ch.tocco.nice2.optional.order.api.StockMovementUtils

public class StockMovementUtils extends Object
  • Method Details

    • recalculateAverageCostPrice

      public static void recalculateAverageCostPrice(Entity stockMovement, Entity article)
      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 entity
      article - 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 entity
      article - the affected article entity
      queryBuilderFactory - QueryBuilderFactory instance
      ctx - 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 entity
      article - the affected article entity
      movementDate - the stock movement date
      queryBuilderFactory - QueryBuilderFactory instance
      ctx - 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 entity
      amount - inward or outward amount
      stockMovement - the stock movement entity
      isInward - flag to define if its an inward stock movement @throws PersistException
    • haveInStock

      public static boolean haveInStock(Entity article, @Nullable @Nullable Integer amount)
      Checks if enough articles are in stock for outward stock movement.
      Parameters:
      article - the affected article entity
      amount - the outward amount
      Returns:
      true if enough articles are in stock, otherwise false