public boolean process(PaymentDTOEx paymentInfo) throws PluggableTaskException {
    FormatLogger log = new FormatLogger(Logger.getLogger(PaymentEmailAuthorizeNetTask.class));
    boolean retValue = super.process(paymentInfo);
    String address = (String) parameters.get(PARAMETER_EMAIL_ADDRESS.getName());
    try {
      UserBL user = new UserBL(paymentInfo.getUserId());
      String message;
      if (new Integer(paymentInfo.getPaymentResult().getId()).equals(Constants.RESULT_OK)) {
        message = "payment.success";
      } else {
        message = "payment.fail";
      }
      String params[] = new String[6];
      params[0] = paymentInfo.getUserId().toString();
      params[1] = user.getEntity().getUserName();
      params[2] = paymentInfo.getId() + "";
      params[3] = paymentInfo.getAmount().toString();
      if (paymentInfo.getAuthorization() != null) {
        params[4] = paymentInfo.getAuthorization().getTransactionId();
        params[5] = paymentInfo.getAuthorization().getApprovalCode();
      } else {
        params[4] = "Not available";
        params[5] = "Not available";
      }
      log.debug(
          "Bkp 6 " + params[0] + " " + params[1] + " " + params[2] + " " + params[3] + " "
              + params[4] + " " + params[5] + " ");
      NotificationBL.sendSapienterEmail(
          address, user.getEntity().getEntity().getId(), message, null, params);
    } catch (Exception e) {

      log.warn("Cant send receit email");
    }

    return retValue;
  }
Exemple #2
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();
    }
  }