Ejemplo n.º 1
0
  public void update(CurrencyDTO dto, Integer entityId) {
    if (currency != null) {
      currency.setSymbol(dto.getSymbol());
      currency.setCode(dto.getCode());
      currency.setCountryCode(dto.getCountryCode());

      // set system rate
      if (dto.getSysRate() != null) {
        final CurrencyExchangeDTO systemExchangeRate =
            findExchange(SYSTEM_RATE_ENTITY_ID, currency.getId(), new Date());
        systemExchangeRate.setRate(dto.getSysRate());
      }

      // add active currencies to the company map
      CompanyDTO company = new CompanyDAS().find(entityId);
      if (dto.getInUse()) {
        company.getCurrencies().add(currency);
      } else {
        company.getCurrencies().remove(currency);
      }

      invalidateCache();
      ;

    } else {
      LOG.error("Cannot update, CurrencyDTO not found or not set!");
    }
  }
Ejemplo n.º 2
0
  public Integer create(CurrencyDTO dto, Integer entityId) {
    if (dto != null) {
      /*
         Simplify currency creation; Set exchange rates from transient CurrencyDTO#getRate() and
         CurrencyDTO#getSysRate() if no currency exchanges have been mapped.
      */
      if (dto.getCurrencyExchanges().isEmpty()) {
        // set system rate
        CurrencyExchangeDTO sysRate = new CurrencyExchangeDTO();
        sysRate.setEntityId(SYSTEM_RATE_ENTITY_ID);
        sysRate.setRate(dto.getSysRate() != null ? dto.getSysRate() : BigDecimal.ONE);
        sysRate.setValidSince(
            com.sapienter.jbilling.common.Util.truncateDate(CommonConstants.EPOCH_DATE));
        sysRate.setCurrency(dto);

        dto.getCurrencyExchanges().add(sysRate);
      }

      this.currency = currencyDas.save(dto);

      // add active currencies to the company map
      if (dto.getInUse()) {
        CompanyDTO company = new CompanyDAS().find(entityId);
        company.getCurrencies().add(this.currency);
      }

      invalidateCache();

      return this.currency.getId();
    }

    LOG.error("Cannot save a null CurrencyDTO!");
    return null;
  }
Ejemplo n.º 3
0
  public void sendReminders(Date today) throws SQLException, SessionInternalError {
    GregorianCalendar cal = new GregorianCalendar();

    for (Iterator it = new CompanyDAS().findEntities().iterator(); it.hasNext(); ) {
      CompanyDTO thisEntity = (CompanyDTO) it.next();
      Integer entityId = thisEntity.getId();
      PreferenceBL pref = new PreferenceBL();
      try {
        pref.set(entityId, Constants.PREFERENCE_USE_INVOICE_REMINDERS);
      } catch (EmptyResultDataAccessException e1) {
        // let it use the defaults
      }
      if (pref.getInt() == 1) {
        prepareStatement(InvoiceSQL.toRemind);

        cachedResults.setDate(1, new java.sql.Date(today.getTime()));
        cal.setTime(today);
        pref.set(entityId, Constants.PREFERENCE_FIRST_REMINDER);
        cal.add(GregorianCalendar.DAY_OF_MONTH, -pref.getInt());
        cachedResults.setDate(2, new java.sql.Date(cal.getTimeInMillis()));
        cal.setTime(today);
        pref.set(entityId, Constants.PREFERENCE_NEXT_REMINDER);
        cal.add(GregorianCalendar.DAY_OF_MONTH, -pref.getInt());
        cachedResults.setDate(3, new java.sql.Date(cal.getTimeInMillis()));

        cachedResults.setInt(4, entityId.intValue());

        execute();
        while (cachedResults.next()) {
          int invoiceId = cachedResults.getInt(1);
          set(Integer.valueOf(invoiceId));
          NotificationBL notif = new NotificationBL();
          long mils = invoice.getDueDate().getTime() - today.getTime();
          int days = Math.round(mils / 1000 / 60 / 60 / 24);

          try {
            MessageDTO message =
                notif.getInvoiceReminderMessage(
                    entityId,
                    invoice.getBaseUser().getUserId(),
                    Integer.valueOf(days),
                    invoice.getDueDate(),
                    invoice.getPublicNumber(),
                    invoice.getTotal(),
                    invoice.getCreateDatetime(),
                    invoice.getCurrency().getId());

            INotificationSessionBean notificationSess =
                (INotificationSessionBean) Context.getBean(Context.Name.NOTIFICATION_SESSION);

            notificationSess.notify(invoice.getBaseUser(), message);

            invoice.setLastReminder(today);
          } catch (NotificationNotFoundException e) {
            LOG.warn(
                "There are invoice to send reminders, but "
                    + "the notification message is missing for "
                    + "entity "
                    + entityId);
          }
        }
      }
    }

    if (conn != null) { // only if somthing run
      conn.close();
    }
  }
Ejemplo n.º 4
0
 public static void setEntityCurrency(Integer entityId, Integer currencyId) {
   CompanyDTO entity = new CompanyDAS().find(entityId);
   entity.setCurrency(new CurrencyDAS().find(currencyId));
 }
Ejemplo n.º 5
0
 public static Integer getEntityCurrency(Integer entityId) {
   CompanyDTO entity = new CompanyDAS().find(entityId);
   return entity.getCurrencyId();
 }