Example usage for org.joda.time DateTime toLocalDate

List of usage examples for org.joda.time DateTime toLocalDate

Introduction

In this page you can find the example usage for org.joda.time DateTime toLocalDate.

Prototype

public LocalDate toLocalDate() 

Source Link

Document

Converts this object to a LocalDate with the same date and chronology.

Usage

From source file:org.mifos.platform.rest.controller.LoanAccountRESTController.java

License:Open Source License

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/disburse", method = RequestMethod.POST)
public @ResponseBody Map<String, String> disburseLoan(@PathVariable String globalAccountNum,
        @RequestParam String disbursalDate, @RequestParam(required = false) Short receiptId,
        @RequestParam(required = false) String receiptDate, @RequestParam Short disbursePaymentTypeId,
        @RequestParam(required = false) Short paymentModeOfPayment) throws Exception {
    String format = "dd-MM-yyyy";
    DateTime trnxDate = validateDateString(disbursalDate, format);
    validateDisbursementDate(trnxDate);//from   ww w .  j a  v  a 2s .c om
    DateTime receiptDateTime = null;
    if (receiptDate != null && !receiptDate.isEmpty()) {
        receiptDateTime = validateDateString(receiptDate, format);
        validateDisbursementDate(receiptDateTime);
    }
    validateDisbursementPaymentTypeId(disbursePaymentTypeId, accountService.getLoanDisbursementTypes());

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);

    String comment = "";
    Short paymentTypeId = Short.valueOf(disbursePaymentTypeId);

    Money outstandingBeforeDisbursement = loan.getLoanSummary().getOutstandingBalance();

    CustomerDto customerDto = null;
    PaymentTypeDto paymentType = null;
    AccountPaymentParametersDto loanDisbursement;
    if (receiptId == null || receiptDateTime == null) {
        loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto((short) user.getUserId()),
                new AccountReferenceDto(loan.getAccountId()), loan.getLoanAmount().getAmount(),
                trnxDate.toLocalDate(), paymentType, comment);
    } else {
        loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto((short) user.getUserId()),
                new AccountReferenceDto(loan.getAccountId()), loan.getLoanAmount().getAmount(),
                trnxDate.toLocalDate(), paymentType, comment, receiptDateTime.toLocalDate(),
                receiptId.toString(), customerDto);
    }

    this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId);

    CustomerBO client = loan.getCustomer();

    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
    map.put("disbursementDate", trnxDate.toLocalDate().toString());
    map.put("disbursementTime", new DateTime().toLocalTime().toString());
    map.put("disbursementAmount", loan.getLastPmnt().getAmount().toString());
    map.put("disbursementMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforeDisbursement", outstandingBeforeDisbursement.toString());
    map.put("outstandingAfterDisbursement", loan.getLoanSummary().getOutstandingBalance().toString());

    return map;
}

From source file:org.mifos.platform.rest.controller.LoanAccountRESTController.java

License:Open Source License

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/adjustment", method = RequestMethod.POST)
public @ResponseBody Map<String, String> applyAdjustment(@PathVariable String globalAccountNum,
        @RequestParam String note) throws Exception {

    validateNote(note);/*from www  . j  a va 2  s. c  o m*/

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
    CustomerBO client = loan.getCustomer();

    String adjustmentAmount = loan.getLastPmnt().getAmount().toString();
    String outstandingBeforeAdjustment = loan.getLoanSummary().getOutstandingBalance().toString();

    try {
        accountServiceFacade.applyAdjustment(globalAccountNum, note, (short) user.getUserId());
    } catch (MifosRuntimeException e) {
        String error = e.getCause().getMessage();
        throw new MifosRuntimeException(error);
    }

    DateTime today = new DateTime();

    loan = loanDao.findByGlobalAccountNum(globalAccountNum);
    client = loan.getCustomer();

    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
    map.put("adjustmentDate", today.toLocalDate().toString());
    map.put("adjustmentTime", today.toLocalTime().toString());
    map.put("adjustmentAmount", adjustmentAmount);
    map.put("adjustmentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforeAdjustment", outstandingBeforeAdjustment);
    map.put("outstandingAfterAdjustment", loan.getLoanSummary().getOutstandingBalance().toString());
    map.put("note", note);

    return map;
}

From source file:org.mifos.platform.rest.controller.LoanAccountRESTController.java

License:Open Source License

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/charge", method = RequestMethod.POST)
public @ResponseBody Map<String, String> applyCharge(@PathVariable String globalAccountNum,
        @RequestParam BigDecimal amount, @RequestParam Short feeId) throws Exception {

    validateAmount(amount);//from w  ww . jav  a 2 s. c om

    List<String> applicableFees = new ArrayList<String>();
    for (Map<String, String> feeMap : this.getApplicableFees(globalAccountNum).values()) {
        applicableFees.add(feeMap.get("feeId"));
    }
    validateFeeId(feeId, applicableFees);

    Map<String, String> map = new HashMap<String, String>();
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
    Integer accountId = loan.getAccountId();
    CustomerBO client = loan.getCustomer();

    String outstandingBeforeCharge = loan.getLoanSummary().getOutstandingBalance().toString();

    this.accountServiceFacade.applyCharge(accountId, feeId, amount.doubleValue(), false);

    DateTime today = new DateTime();

    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
    map.put("chargeDate", today.toLocalDate().toString());
    map.put("chargeTime", today.toLocalTime().toString());
    map.put("chargeAmount", Double.valueOf(amount.doubleValue()).toString());
    map.put("chargeMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforeCharge", outstandingBeforeCharge);
    map.put("outstandingAfterCharge", loan.getLoanSummary().getOutstandingBalance().toString());

    return map;
}

From source file:org.mifos.platform.rest.controller.SavingsAccountRESTController.java

License:Open Source License

@RequestMapping(value = "account/savings/num-{globalAccountNum}/adjustment", method = RequestMethod.POST)
public @ResponseBody Map<String, String> applyAdjustment(@PathVariable String globalAccountNum,
        @RequestParam BigDecimal amount, @RequestParam String note,
        @RequestParam(required = false) Integer paymentId) throws Exception {

    validateAmount(amount);//  w  ww . j  a  v  a  2  s . c  om

    validateNote(note);

    SavingsBO savingsBO = savingsDao.findBySystemId(globalAccountNum);
    new SavingsPersistence().initialize(savingsBO);
    Integer accountId = savingsBO.getAccountId();
    Long savingsId = Long.valueOf(accountId.toString());

    SavingsAdjustmentDto savingsAdjustment = new SavingsAdjustmentDto(savingsId, amount.doubleValue(), note,
            (paymentId == null) ? savingsBO.getLastPmnt().getPaymentId() : paymentId,
            new LocalDate(savingsBO.getLastPmnt().getPaymentDate()));
    Money balanceBeforePayment = savingsBO.getSavingsBalance();

    this.savingsServiceFacade.adjustTransaction(savingsAdjustment);

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    DateTime today = new DateTime();
    CustomerBO client = savingsBO.getCustomer();

    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("savingsDisplayName", savingsBO.getSavingsOffering().getPrdOfferingName());
    map.put("adjustmentDate", today.toLocalDate().toString());
    map.put("adjustmentTime", today.toLocalTime().toString());
    map.put("adjustmentAmount", savingsBO.getLastPmnt().getAmount().toString());
    map.put("adjustmentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("balanceBeforeAdjustment", balanceBeforePayment.toString());
    map.put("balanceAfterAdjustment", savingsBO.getSavingsBalance().toString());
    map.put("note", note);

    return map;
}

From source file:org.mifos.platform.rest.controller.SavingsAccountRESTController.java

License:Open Source License

private Map<String, String> doSavingsTrxn(String globalAccountNum, BigDecimal amount, String trxnDate,
        Short receiptId, String receiptDate, Short paymentTypeId, TrxnTypes trxnType) throws Exception {

    validateAmount(amount);/*from   w  w  w  .  j  a v  a  2s  .co m*/

    String format = "dd-MM-yyyy";
    DateTime trnxDate = validateDateString(trxnDate, format);
    validateSavingsDate(trnxDate);
    DateTime receiptDateTime = null;
    if (receiptDate != null && !receiptDate.isEmpty()) {
        receiptDateTime = validateDateString(receiptDate, format);
        validateSavingsDate(receiptDateTime);
    } else {
        receiptDateTime = new DateTime(trnxDate);
    }

    SavingsBO savingsBO = savingsDao.findBySystemId(globalAccountNum);

    validateAccountState(savingsBO);

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    Integer accountId = savingsBO.getAccountId();

    DateTime today = new DateTime();
    String receiptIdString;
    if (receiptId == null) {
        receiptIdString = "";
    } else {
        receiptIdString = receiptId.toString();
    }

    CustomerBO client = savingsBO.getCustomer();
    CustomerDto customer = new CustomerDto();
    customer.setCustomerId(client.getCustomerId());

    Money balanceBeforePayment = savingsBO.getSavingsBalance();
    if (trxnType.equals(TrxnTypes.savings_deposit)) {
        validateSavingsPaymentTypeId(paymentTypeId, accountService.getSavingsPaymentTypes());
        SavingsDepositDto savingsDeposit = new SavingsDepositDto(accountId.longValue(),
                savingsBO.getCustomer().getCustomerId().longValue(), trnxDate.toLocalDate(),
                amount.doubleValue(), paymentTypeId.intValue(), receiptIdString, receiptDateTime.toLocalDate(),
                Locale.UK);
        this.savingsServiceFacade.deposit(savingsDeposit);
    } else {
        validateSavingsPaymentTypeId(paymentTypeId, accountService.getSavingsWithdrawalTypes());
        SavingsWithdrawalDto savingsWithdrawal = new SavingsWithdrawalDto(accountId.longValue(),
                savingsBO.getCustomer().getCustomerId().longValue(), trnxDate.toLocalDate(),
                amount.doubleValue(), paymentTypeId.intValue(), receiptIdString, receiptDateTime.toLocalDate(),
                Locale.UK);
        this.savingsServiceFacade.withdraw(savingsWithdrawal);
    }

    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("savingsDisplayName", savingsBO.getSavingsOffering().getPrdOfferingName());
    map.put("paymentDate", today.toLocalDate().toString());
    map.put("paymentTime", today.toLocalTime().toString());
    map.put("paymentAmount", savingsBO.getLastPmnt().getAmount().toString());
    map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("balanceBeforePayment", balanceBeforePayment.toString());
    map.put("balanceAfterPayment", savingsBO.getSavingsBalance().toString());
    return map;
}

From source file:org.mifosplatform.infrastructure.reportmailingjob.service.ReportMailingJobWritePlatformServiceImpl.java

License:Mozilla Public License

/**
 * create the next recurring DateTime from recurrence pattern, start DateTime and current DateTime
 * //from   w w w  .  ja v  a 2 s.  c  o m
 * @param recurrencePattern
 * @param startDateTime
 * @return DateTime object
 */
private DateTime createNextRecurringDateTime(final ReportMailingJob reportMailingJob) {
    DateTime nextRecurringDateTime = null;
    final String recurrencePattern = reportMailingJob.getRecurrence();
    final DateTime nextRunDateTime = reportMailingJob.getNextRunDateTime();

    // the recurrence pattern/rule cannot be empty
    if (StringUtils.isNotBlank(recurrencePattern) && nextRunDateTime != null) {
        final LocalDate currentDate = DateUtils.getLocalDateOfTenant();
        final LocalDate nextRunDate = nextRunDateTime.toLocalDate();

        LocalDate nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, nextRunDate,
                nextRunDate);

        if (nextRecurringLocalDate.isBefore(currentDate)) {
            nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, nextRunDate,
                    currentDate);
        }

        // get the date fields
        final int currentYearIntValue = nextRecurringLocalDate.get(DateTimeFieldType.year());
        final int currentMonthIntValue = nextRecurringLocalDate.get(DateTimeFieldType.monthOfYear());
        final int currentDayIntValue = nextRecurringLocalDate.get(DateTimeFieldType.dayOfMonth());

        // append the time of the previous next run date time
        nextRecurringDateTime = nextRunDateTime.withDate(currentYearIntValue, currentMonthIntValue,
                currentDayIntValue);
    }

    return nextRecurringDateTime;
}

From source file:org.nekorp.workflow.desktop.servicio.imp.CobranzaMetadataCalculatorImp.java

License:Apache License

private void calculaWanrLevel(String status, MonedaVB saldo, CobranzaMetadata cobranzaMetadata,
        DatosCobranzaVB cobranza) {//from   w w w . j a v  a  2s  .  com
    CobranzaWarningLevel warningLevel = CobranzaWarningLevel.info;
    if (saldo.doubleValue() <= 0 || status.compareTo("Terminado") == 0) {
        cobranzaMetadata.setWarningLevel(warningLevel);
        cobranzaMetadata.setDiasUltimoPago(0);
        return;
    }
    DateTime ultimoPago = new DateTime(cobranza.getInicio());
    for (PagoCobranzaVB pago : cobranza.getPagos()) {
        DateTime fechaPago = new DateTime(pago.getFecha());
        if (ultimoPago.isBefore(fechaPago)) {
            ultimoPago = fechaPago;
        }
    }
    if (ultimoPago.plusDays(diasWarn).isBeforeNow()) {
        warningLevel = CobranzaWarningLevel.warn;
    }
    if (ultimoPago.plusDays(diasUrgent).isBeforeNow()) {
        warningLevel = CobranzaWarningLevel.urgent;
    }
    int dias = Days.daysBetween(ultimoPago.toLocalDate(), DateTime.now().toLocalDate()).getDays();
    cobranzaMetadata.setDiasUltimoPago(dias);
    cobranzaMetadata.setWarningLevel(warningLevel);
}

From source file:org.netxilia.api.utils.DateUtils.java

License:Open Source License

/**
 * //from   w w w. ja  v  a  2s.  c  o  m
 * @param formatter
 * @param text
 * @return the ReadablePartial corresponding to the given formatter and text
 */
public static ReadablePartial parsePartial(DateTimeFormatter formatter, String text) {
    PartialDateTimeParserBucket bucket = new PartialDateTimeParserBucket();
    int newPos = formatter.getParser().parseInto(bucket, text, 0);

    if (newPos >= 0 && newPos >= text.length()) {
        long millis = bucket.computeMillis(true, text);
        DateTime dt = new DateTime(millis, (Chronology) null);
        if (bucket.isHasDate() && bucket.isHasTime()) {
            return dt.toLocalDateTime();
        }
        if (bucket.isHasDate()) {
            return dt.toLocalDate();
        }
        return dt.toLocalTime();
    }
    throw new IllegalArgumentException("Cannot parse date:" + text);
}

From source file:org.netxilia.functions.Main.java

License:Open Source License

public DateTime WORKDAY(DateTime startDate, int days, Iterator<DateTime> holidays) {
    Set<LocalDate> holidaySet = new HashSet<LocalDate>();
    while (holidays.hasNext())
        holidaySet.add(holidays.next().toLocalDate());

    HolidayCalendar<LocalDate> holidayCalendar = new DefaultHolidayCalendar<LocalDate>(holidaySet);

    DateCalculator<LocalDate> calc = new LocalDateCalculator("", startDate.toLocalDate(), holidayCalendar,
            null);// w ww  .j a  va 2 s. c  o m
    calc = calc.moveByBusinessDays(days);
    return calc.getCurrentBusinessDate().toDateTimeAtStartOfDay();
}

From source file:org.netxilia.impexp.impl.ExcelImportService.java

License:Open Source License

private ICellCommand copyCell(Cell poiCell, CellReference cellReference, HSSFPalette palette,
        NetxiliaStyleResolver styleResolver) throws FormulaParsingException {

    CellStyle poiStyle = poiCell.getCellStyle();
    Styles styles = PoiUtils.poiStyle2Netxilia(poiStyle,
            poiCell.getSheet().getWorkbook().getFontAt(poiStyle.getFontIndex()), palette, styleResolver);

    IGenericValue value = null;//www . j  a v a 2  s.c o m
    Formula formula = null;

    // log.info("CELL TYPE:" + cellReference + " type:" + poiCell.getCellType() + " "
    // + (poiCell.getCellType() == Cell.CELL_TYPE_FORMULA ? poiCell.getCellFormula() : "no"));
    switch (poiCell.getCellType()) {
    // TODO translate errors

    case Cell.CELL_TYPE_STRING:
        value = new StringValue(poiCell.getStringCellValue());
        break;
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(poiCell)) {
            DateTime dt = new DateTime(poiCell.getDateCellValue());
            // TODO decide whether is date or time
            if (dt.isBefore(EXCEL_START)) {
                value = new DateValue(dt.toLocalTime());
            } else if (dt.getMillisOfDay() == 0) {
                value = new DateValue(dt.toLocalDate());
            } else {
                value = new DateValue(dt.toLocalDateTime());
            }
        } else {
            value = new NumberValue(poiCell.getNumericCellValue());
        }
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        value = new BooleanValue(poiCell.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_FORMULA:
        if (poiCell.getCellFormula() != null) {
            formula = formulaParser.parseFormula(new Formula("=" + poiCell.getCellFormula()));
        }
        break;
    }

    if ((styles == null || styles.getItems().isEmpty()) && formula == null
            && (value == null || value.equals(GenericValueUtils.EMTPY_STRING))) {
        return null;
    }
    return CellCommands.cell(new AreaReference(cellReference), value, formula, styles);
}