Ejemplo n.º 1
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();
    }
  }
Ejemplo n.º 2
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();
    }
  }
Ejemplo 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;
  }