コード例 #1
0
ファイル: GuaranteesHelper.java プロジェクト: TouK/cyclos
 public static BigDecimal calculateFee(
     final Period period, final BigDecimal amount, final GuaranteeFeeVO guaranteeFee) {
   Amount result = null;
   switch (guaranteeFee.getType()) {
     case FIXED:
       result = Amount.fixed(guaranteeFee.getFee());
       // fall down!
     case PERCENTAGE:
       result = result != null ? result : Amount.percentage(guaranteeFee.getFee());
       return result.apply(amount);
     case VARIABLE_ACCORDING_TO_TIME: // it's a compound interest calculation
       if (period.getBegin().after(period.getEnd())) {
         throw new IllegalArgumentException(
             "Can't calculate the guarantee fee. Invalid period time: the begin date must be less than the end date");
       } else if (amount.doubleValue() == 0d || guaranteeFee.getFee().doubleValue() == 0d) {
         return BigDecimal.ZERO;
       }
       final double periodInDays = DateHelper.daysBetween(period.getBegin(), period.getEnd());
       final double pow = periodInDays / 365D;
       final double value =
           (Math.pow(1 + guaranteeFee.getFee().doubleValue() / 100D, pow) - 1)
               * amount.doubleValue();
       return new BigDecimal(value);
     default:
       throw new IllegalArgumentException(
           "Can't calculate the guarantee fee: unknown fee type: " + guaranteeFee.getType());
   }
 }
コード例 #2
0
 /** Ensure the payment can be performed */
 private void validatePayment(final DoPaymentDTO payment) {
   String key = null;
   String arg = null;
   try {
     paymentService.simulatePayment(payment);
   } catch (final NotEnoughCreditsException e) {
     key = "mobile.payment.error.notEnoughCredits";
   } catch (final MaxAmountPerDayExceededException e) {
     final Calendar date = e.getDate();
     if (date == null || DateHelper.sameDay(date, Calendar.getInstance())) {
       key = "mobile.payment.error.maxAmountPerDay";
     } else {
       key = "mobile.payment.error.maxAmountPerDay.at";
       arg = settingsService.getLocalSettings().getRawDateConverter().toString(date);
     }
   } catch (final UnexpectedEntityException e) {
     key = "mobile.payment.error.noTransferType";
   }
   if (key != null) {
     throw new MobileException(key, arg);
   }
 }