Esempio n. 1
0
  public StockOpnameHeader save(
      List<StockOpnameDetail> stockOpnameDetails,
      Timestamp performedBeginTimestamp,
      Timestamp performedEndTimestamp,
      Session session) {

    StockOpnameHeader stockOpnameHeader = new StockOpnameHeader();
    stockOpnameHeader.setPerformedBy(Main.getUserLogin());
    stockOpnameHeader.setPerformedBeginTimestamp(performedBeginTimestamp);
    stockOpnameHeader.setPerformedEndTimestamp(performedEndTimestamp);
    stockOpnameHeader.setLastUpdatedBy(Main.getUserLogin().getId());
    stockOpnameHeader.setLastUpdatedTimestamp(CommonUtils.getCurrentTimestamp());

    session.saveOrUpdate(stockOpnameHeader);

    for (StockOpnameDetail stockOpname : stockOpnameDetails) {
      Item item = stockOpname.getItem();
      List<ItemStock> itemStocks = item.getItemStocks();
      for (ItemStock itemStock : itemStocks) {
        session.saveOrUpdate(itemStock);
      }
      session.saveOrUpdate(item);

      stockOpname.setStockOpnameHeader(stockOpnameHeader);
      session.saveOrUpdate(stockOpname);
    }

    return stockOpnameHeader;
  }
Esempio n. 2
0
  private void printBarcode() throws AppException, UserException {
    Session session = HibernateUtils.openSession();
    try {
      int selectedRow = table.getSelectedRow();
      if (selectedRow < 0) {
        return;
      }
      int itemId =
          (int)
              table
                  .getModel()
                  .getValueAt(selectedRow, tableParameters.get(ColumnEnum.ID).getColumnIndex());

      ItemFacade facade = ItemFacade.getInstance();
      Item item = facade.getDetail(itemId, session);

      String barcode = item.getBarcode();
      if (barcode == null || barcode.trim().equals("")) {
        throw new UserException(
            "Barcode untuk barang ["
                + item.getCode()
                + "] "
                + item.getName()
                + " belum diregistrasi");
      }

      File file = BarcodeUtils.generatePdfFile(item.getBarcode());
      BarcodeUtils.print(file);

    } finally {
      session.close();
    }
  }
Esempio n. 3
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;
  }
Esempio n. 4
0
  public StockOpnameDetail createStockOpnameEntity(
      int itemId, int quantityManual, int overCount, int lossCount, Session session)
      throws AppException, UserException {

    Item item = ItemFacade.getInstance().getDetail(itemId, session);
    int quantityInThisStage = ItemFacade.getInstance().calculateStock(item);

    BigDecimal overAmount = calculateOverAmount(item, overCount);
    BigDecimal lossAmount = calculateLossAmount(item, lossCount);

    item.setLastUpdatedBy(Main.getUserLogin().getId());
    item.setLastUpdatedTimestamp(CommonUtils.getCurrentTimestamp());

    StockOpnameDetail stockOpname = new StockOpnameDetail();
    stockOpname.setItem(item);
    stockOpname.setQuantitySystem(quantityInThisStage);
    stockOpname.setQuantityManual(quantityManual);
    stockOpname.setOverCount(overCount);
    stockOpname.setOverAmount(overAmount);
    stockOpname.setLossCount(lossCount);
    stockOpname.setLossAmount(lossAmount);

    return stockOpname;
  }
Esempio n. 5
0
  @Override
  public void loadData() throws AppException {
    Session session = HibernateUtils.openSession();
    try {
      String code = txtKode.getText();
      String barcode = txtBarcode.getText();
      String name = txtNama.getText();
      boolean disabled = rdBarangTidakAktif.isSelected();

      ItemFacade facade = ItemFacade.getInstance();
      List<Item> items = facade.search(code, barcode, name, disabled, session);

      XTableModel tableModel = (XTableModel) table.getModel();
      tableModel.setRowCount(items.size());

      for (int i = 0; i < items.size(); ++i) {
        Item item = items.get(i);

        tableModel.setValueAt(
            item.getCode(), i, tableParameters.get(ColumnEnum.CODE).getColumnIndex());

        tableModel.setValueAt(
            item.getName(), i, tableParameters.get(ColumnEnum.NAME).getColumnIndex());

        tableModel.setValueAt(
            Formatter.formatNumberToString(facade.calculateStock(item)),
            i,
            tableParameters.get(ColumnEnum.STOCK).getColumnIndex());

        tableModel.setValueAt(
            item.getUnit(), i, tableParameters.get(ColumnEnum.UNIT).getColumnIndex());
        tableModel.setValueAt(
            Formatter.formatNumberToString(facade.getLastBuyPrice(item)),
            i,
            tableParameters.get(ColumnEnum.BUY_PRICE).getColumnIndex());

        tableModel.setValueAt(
            Formatter.formatNumberToString(item.getSellPrice()),
            i,
            tableParameters.get(ColumnEnum.SELL_PRICE).getColumnIndex());

        tableModel.setValueAt(item.getId(), i, tableParameters.get(ColumnEnum.ID).getColumnIndex());
      }
    } finally {
      session.close();
    }
  }
Esempio n. 6
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;
  }