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;
  }
Beispiel #2
0
  public User addNewUser(
      String login,
      String name,
      String password,
      List<Role> roles,
      boolean disabled,
      boolean deleted,
      Session session)
      throws UserException, AppException {

    if (DBUtils.getInstance().isExists("login", login, User.class, session)) {
      throw new UserException("User dengan Login ID " + login + " sudah pernah didaftarkan");
    }

    User user = new User();
    user.setLogin(login);
    user.setName(name);
    user.setPassword(SecurityUtils.hash(password));
    user.setDisabled(disabled);
    user.setDeleted(deleted);
    user.setLastUpdatedBy(Main.getUserLogin().getId());
    user.setLastUpdatedTimestamp(CommonUtils.getCurrentTimestamp());

    session.saveOrUpdate(user);

    updateUserRoleLink(user.getId(), roles, session);

    return user;
  }
Beispiel #3
0
  public User updateExistingUser(
      String login,
      String name,
      String password,
      List<Role> roles,
      boolean disabled,
      boolean deleted,
      Session session)
      throws UserException, AppException {

    User user = getDetail(login, session);
    user.setName(name);
    if (password != null && !password.trim().equals("")) {
      user.setPassword(SecurityUtils.hash(password));
    }
    if (deleted) {
      if (!disabled) {
        throw new UserException("Tidak dapat menghapus User yang masih dalam kondisi aktif");
      }
    }
    user.setDisabled(disabled);
    user.setDeleted(deleted);
    user.setLastUpdatedBy(Main.getUserLogin().getId());
    user.setLastUpdatedTimestamp(CommonUtils.getCurrentTimestamp());

    session.saveOrUpdate(user);

    updateUserRoleLink(user.getId(), roles, session);

    return user;
  }
  public JasperPrint prepareJasper(
      List<StockOpnameDetail> stockOpnameDetails, Timestamp beginTimestamp, Timestamp endTimestamp)
      throws AppException {

    Map<String, Object> paramReport = new HashMap<String, Object>();
    paramReport.put("reportName", REPORT_NAME);
    paramReport.put("companyName", Main.getCompany().getName());
    paramReport.put("performedByUserName", Main.getUserLogin().getName());
    paramReport.put("performedBeginTimestamp", beginTimestamp);
    paramReport.put("performedEndTimestamp", endTimestamp);

    InputStream inputStream = null;
    try {
      inputStream = this.getClass().getClassLoader().getResourceAsStream(REPORT_FILE);

      JasperDesign jasperDesign = JRXmlLoader.load(inputStream);

      JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

      JasperPrint jasperPrint =
          JasperFillManager.fillReport(
              jasperReport, paramReport, new JRBeanCollectionDataSource(stockOpnameDetails));

      return jasperPrint;
    } catch (JRException e) {
      throw new AppException(e);
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          throw new AppException(e);
        }
      }
    }
  }
Beispiel #5
0
  public User changePassword(int userId, String oldPassword, String newPassword, Session session)
      throws AppException, UserException {

    User user = getDetail(userId, session);
    boolean oldPasswordValid =
        LoginFacade.getInstance().validatePassword(oldPassword, user.getPassword());

    if (!oldPasswordValid) {
      throw new UserException("Password Lama tidak sesuai");
    }

    String hashedPassword = SecurityUtils.hash(newPassword);
    user.setPassword(hashedPassword);
    user.setLastUpdatedBy(Main.getUserLogin().getId());
    user.setLastUpdatedTimestamp(CommonUtils.getCurrentTimestamp());

    session.saveOrUpdate(user);
    return user;
  }
  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;
  }