Ejemplo n.º 1
0
  private BigDecimal calculateOverAmount(Item item, int overStock) throws UserException {
    BigDecimal amount = BigDecimal.valueOf(0);

    int excess = overStock;
    List<ItemStock> itemStocks = item.getItemStocks();
    for (int i = itemStocks.size() - 1; i >= 0 && excess > 0; --i) {
      ItemStock itemStock = itemStocks.get(i);
      int maxStock = itemStock.getPurchaseDetail().getQuantity();
      int stock = itemStock.getQuantity();
      int taken;
      if ((excess + stock) > maxStock) {
        taken = maxStock - stock;
      } else {
        taken = excess;
      }
      int remain = excess - taken;
      int newStock = stock + taken;

      itemStock.setQuantity(newStock);
      excess = remain;
      amount =
          amount.add(
              BigDecimal.valueOf(taken).multiply(itemStock.getPurchaseDetail().getPricePerUnit()));
    }

    if (excess > 0) {
      int maxStockLimit = ItemFacade.getInstance().calculateMaxStock(item);
      throw new UserException(
          "Batas penyesuaian stock untuk item "
              + item.getCode()
              + " "
              + item.getName()
              + " hanya bisa disesuaikan hingga "
              + maxStockLimit
              + " "
              + item.getUnit()
              + ".<br/><br/>"
              + "Kelebihan "
              + excess
              + " "
              + item.getUnit()
              + " harus dilakukan melalui menu Transaksi Pembelian.");
    }

    return amount;
  }
Ejemplo n.º 2
0
  private BigDecimal calculateLossAmount(Item item, int lossStock) {
    BigDecimal amount = BigDecimal.valueOf(0);

    int requirement = lossStock;
    List<ItemStock> itemStocks = item.getItemStocks();
    for (int i = 0; i < itemStocks.size() && requirement > 0; ++i) {
      ItemStock itemStock = itemStocks.get(i);
      int stock = itemStock.getQuantity();
      int taken;
      if (requirement > stock) {
        taken = stock;
        requirement -= stock;
      } else {
        taken = requirement;
        requirement = 0;
      }
      int remain = stock - taken;
      itemStock.setQuantity(remain);
      amount =
          amount.add(
              BigDecimal.valueOf(taken).multiply(itemStock.getPurchaseDetail().getPricePerUnit()));
    }
    return amount;
  }