Example usage for org.joda.time LocalDate LocalDate

List of usage examples for org.joda.time LocalDate LocalDate

Introduction

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

Prototype

public LocalDate(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:cherry.foundation.type.querydsl.LocalDateType.java

License:Apache License

@Override
public LocalDate getValue(ResultSet rs, int startIndex) throws SQLException {
    Date date = rs.getDate(startIndex);
    if (date == null) {
        return null;
    }/*from  w  w w. j a  v a  2s.  c  om*/
    return new LocalDate(date.getTime());
}

From source file:com.actimem.blog.jaxb.adapters.LocalDateAdapter.java

License:Apache License

@Override
public LocalDate unmarshal(String v) throws Exception {
    return new LocalDate(v);
}

From source file:com.ajah.user.data.UserInfoDaoImpl.java

License:Apache License

@Override
public MapMap<LocalDate, String, Integer> getSourceCounts() {
    final String sql = "SELECT FROM_UNIXTIME(created_date/1000,'%Y-%m-%d') as date,source,count(*) as total FROM user_info GROUP BY FROM_UNIXTIME(created_date/1000,'%Y-%m-%d'),source";
    sqlLog.finest(sql);/*from  w  ww  .  java 2s  .  c  om*/
    return super.jdbcTemplate.query(sql, new ResultSetExtractor<MapMap<LocalDate, String, Integer>>() {

        @Override
        public MapMap<LocalDate, String, Integer> extractData(final ResultSet rs)
                throws SQLException, DataAccessException {
            final MapMap<LocalDate, String, Integer> mapMap = new MapMap<LocalDate, String, Integer>();
            while (rs.next()) {
                final String source = rs.getString("source") == null ? "mg" : rs.getString("source");
                mapMap.put(new LocalDate(rs.getString("date")), source, rs.getInt("total"));
            }
            return mapMap;
        }

    });
}

From source file:com.axelor.apps.account.service.move.MoveTemplateService.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public List<Long> generateMove(MoveTemplate moveTemplate, List<HashMap<String, Object>> dataList) {
    try {/*  www .j a  v  a2s  .c  om*/
        List<Long> moveList = new ArrayList<Long>();
        BigDecimal hundred = new BigDecimal(100);
        for (HashMap<String, Object> data : dataList) {
            LocalDate moveDate = new LocalDate(data.get("date").toString());
            Partner debitPartner = null;
            Partner creditPartner = null;
            BigDecimal moveBalance = new BigDecimal(data.get("moveBalance").toString());
            Partner partner = null;
            if (data.get("debitPartner") != null) {
                debitPartner = partnerRepo.find(Long
                        .parseLong(((HashMap<String, Object>) data.get("debitPartner")).get("id").toString()));
                partner = debitPartner;
            }
            if (data.get("creditPartner") != null) {
                creditPartner = partnerRepo.find(Long
                        .parseLong(((HashMap<String, Object>) data.get("creditPartner")).get("id").toString()));
                partner = creditPartner;
            }
            Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(),
                    moveTemplate.getJournal().getCompany(), null, partner, moveDate, null);
            int counter = 1;
            for (MoveTemplateLine line : moveTemplate.getMoveTemplateLineList()) {
                partner = null;
                if (line.getDebitCreditSelect().equals("0")) {
                    if (line.getHasPartnerToDebit())
                        partner = debitPartner;
                    MoveLine moveLine = moveLineService.createMoveLine(move, partner, line.getAccount(),
                            moveBalance.multiply(line.getPercentage()).divide(hundred), true, moveDate,
                            moveDate, counter, line.getName());
                    move.getMoveLineList().add(moveLine);
                } else {
                    if (line.getHasPartnerToCredit())
                        partner = creditPartner;
                    MoveLine moveLine = moveLineService.createMoveLine(move, partner, line.getAccount(),
                            moveBalance.multiply(line.getPercentage()).divide(hundred), false, moveDate,
                            moveDate, counter, line.getName());
                    move.getMoveLineList().add(moveLine);
                }
                counter++;
            }
            moveRepo.save(move);
            moveList.add(move.getId());
        }
        return moveList;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.axelor.apps.account.service.MoveTemplateService.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional//from   w ww  .  j  ava  2  s.c  om
public List<Long> generateMove(MoveTemplate moveTemplate, List<HashMap<String, Object>> dataList) {
    try {
        List<Long> moveList = new ArrayList<Long>();
        BigDecimal hundred = new BigDecimal(100);
        for (HashMap<String, Object> data : dataList) {
            LocalDate moveDate = new LocalDate(data.get("date").toString());
            Partner debitPartner = null;
            Partner creditPartner = null;
            BigDecimal moveBalance = new BigDecimal(data.get("moveBalance").toString());
            Partner partner = null;
            if (data.get("debitPartner") != null) {
                debitPartner = partnerService.find(Long
                        .parseLong(((HashMap<String, Object>) data.get("debitPartner")).get("id").toString()));
                partner = debitPartner;
            }
            if (data.get("creditPartner") != null) {
                creditPartner = partnerService.find(Long
                        .parseLong(((HashMap<String, Object>) data.get("creditPartner")).get("id").toString()));
                partner = creditPartner;
            }
            Move move = moveService.createMove(moveTemplate.getJournal(),
                    moveTemplate.getJournal().getCompany(), null, partner, moveDate, null);
            for (MoveTemplateLine line : moveTemplate.getMoveTemplateLineList()) {
                partner = null;
                if (line.getDebitCreditSelect().equals("0")) {
                    if (line.getHasPartnerToDebit())
                        partner = debitPartner;
                    MoveLine moveLine = moveLineService.createMoveLine(move, partner, line.getAccount(),
                            moveBalance.multiply(line.getPercentage()).divide(hundred), true, false, moveDate,
                            moveDate, 0, line.getName());
                    move.getMoveLineList().add(moveLine);
                } else {
                    if (line.getHasPartnerToDebit())
                        partner = creditPartner;
                    MoveLine moveLine = moveLineService.createMoveLine(move, partner, line.getAccount(),
                            moveBalance.multiply(line.getPercentage()).divide(hundred), false, false, moveDate,
                            moveDate, 0, line.getName());
                    move.getMoveLineList().add(moveLine);
                }
            }
            moveService.save(move);
            moveList.add(move.getId());
        }
        return moveList;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.axelor.apps.cash.management.service.ForecastRecapService.java

License:Open Source License

public void populateWithSalaries(ForecastRecap forecastRecap) {
    List<Employee> employeeList = new ArrayList<Employee>();
    if (forecastRecap.getBankDetails() != null) {
        employeeList = Beans.get(EmployeeRepository.class).all()
                .filter("self.user.activeCompany = ?1 AND self.bankDetails = ?2", forecastRecap.getCompany(),
                        forecastRecap.getBankDetails())
                .fetch();/*  www .  j  a  va 2 s  .  c  om*/
    } else {
        employeeList = Beans.get(EmployeeRepository.class).all()
                .filter("self.user.activeCompany = ?1", forecastRecap.getCompany()).fetch();
    }
    LocalDate itDate = new LocalDate(forecastRecap.getFromDate());
    while (!itDate.isAfter(forecastRecap.getToDate())) {
        if (itDate.isEqual(new LocalDate(itDate.getYear(), itDate.getMonthOfYear(),
                itDate.dayOfMonth().getMaximumValue()))) {
            for (Employee employee : employeeList) {
                forecastRecap.setCurrentBalance(forecastRecap.getCurrentBalance().subtract(employee
                        .getHourlyRate().multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4)))));
                forecastRecap.addForecastRecapLineListItem(this.createForecastRecapLine(itDate, 2, null,
                        employee.getHourlyRate()
                                .multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4))),
                        forecastRecap.getCurrentBalance()));
            }
            itDate = itDate.plusMonths(1);
        } else {
            itDate = new LocalDate(itDate.getYear(), itDate.getMonthOfYear(),
                    itDate.dayOfMonth().getMaximumValue());
        }
    }
}

From source file:com.axelor.apps.cash.management.service.ForecastService.java

License:Open Source License

public void generate(ForecastGenerator forecastGenerator) {
    LocalDate fromDate = forecastGenerator.getFromDate();
    LocalDate toDate = forecastGenerator.getToDate();
    LocalDate itDate = new LocalDate(fromDate);
    LocalDate todayDate = generalService.getTodayDate();

    if (forecastGenerator.getForecastList() != null && !forecastGenerator.getForecastList().isEmpty()) {
        List<Forecast> forecastList = forecastGenerator.getForecastList();
        for (Forecast forecast : forecastList) {
            if (forecast.getRealizedSelect() == ForecastRepository.REALISED_SELECT_NO) {
                forecastList.remove(forecast);
            } else if (forecast.getRealizedSelect() == ForecastRepository.REALISED_SELECT_AUTO
                    && forecast.getEstimatedDate().isAfter(todayDate)) {
                forecastList.remove(forecast);
            }// w  w w .  j ava  2 s  .co m
        }
    }

    while (!itDate.isAfter(toDate)) {
        Forecast forecast = this.createForecast(forecastGenerator.getCompany(),
                forecastGenerator.getBankDetails(), forecastGenerator.getTypeSelect(),
                forecastGenerator.getAmount(), itDate, forecastGenerator.getForecastReason(),
                forecastGenerator.getComments(), forecastGenerator.getRealizedSelect());
        forecastGenerator.addForecastListItem(forecast);
        itDate.plusMonths(forecastGenerator.getPeriodicitySelect());
    }
}

From source file:com.axelor.apps.hr.service.expense.ExpenseService.java

License:Open Source License

@Transactional
public void insertExpenseLine(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();//w ww .  j  a va 2  s  .c  o m
    ProjectTask projectTask = Beans.get(ProjectTaskRepository.class)
            .find(new Long(request.getData().get("project").toString()));
    Product product = Beans.get(ProductRepository.class)
            .find(new Long(request.getData().get("expenseType").toString()));
    if (user != null) {
        Expense expense = Beans.get(ExpenseRepository.class).all()
                .filter("self.statusSelect = 1 AND self.user.id = ?1", user.getId()).order("-id").fetchOne();
        if (expense == null) {
            expense = new Expense();
            expense.setUser(user);
            expense.setCompany(user.getActiveCompany());
            expense.setStatusSelect(TimesheetRepository.STATUS_DRAFT);
        }
        ExpenseLine expenseLine = new ExpenseLine();
        expenseLine.setExpenseDate(new LocalDate(request.getData().get("date").toString()));
        expenseLine.setComments(request.getData().get("comments").toString());
        expenseLine.setExpenseType(product);
        expenseLine.setToInvoice(new Boolean(request.getData().get("toInvoice").toString()));
        expenseLine.setProjectTask(projectTask);
        expenseLine.setUser(user);
        expenseLine.setUntaxedAmount(new BigDecimal(request.getData().get("amountWithoutVat").toString()));
        expenseLine.setTotalTax(new BigDecimal(request.getData().get("vatAmount").toString()));
        expenseLine.setTotalAmount(expenseLine.getUntaxedAmount().add(expenseLine.getTotalTax()));
        expenseLine.setJustification((byte[]) request.getData().get("justification"));
        expense.addExpenseLineListItem(expenseLine);

        Beans.get(ExpenseRepository.class).save(expense);
    }
}

From source file:com.axelor.apps.hr.service.expense.ExpenseService.java

License:Open Source License

@Transactional
public void insertKMExpenses(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();/*from   ww w  .jav  a 2 s .  c o m*/
    if (user != null) {
        Expense expense = Beans.get(ExpenseRepository.class).all()
                .filter("self.statusSelect = 1 AND self.user.id = ?1", user.getId()).order("-id").fetchOne();
        if (expense == null) {
            expense = new Expense();
            expense.setUser(user);
            expense.setCompany(user.getActiveCompany());
            expense.setStatusSelect(TimesheetRepository.STATUS_DRAFT);
        }
        KilometricAllowance kmAllowance = new KilometricAllowance();
        kmAllowance.setDistance(new BigDecimal(request.getData().get("kmNumber").toString()));
        kmAllowance.setCityFrom(request.getData().get("locationFrom").toString());
        kmAllowance.setCityTo(request.getData().get("locationTo").toString());
        kmAllowance.setTypeSelect(new Integer(request.getData().get("allowanceTypeSelect").toString()));
        kmAllowance.setReason(request.getData().get("comments").toString());
        kmAllowance.setDate(new LocalDate(request.getData().get("date").toString()));
        if (user.getEmployee() != null && user.getEmployee().getKilometricAllowParam() != null) {
            kmAllowance.setKilometricAllowParam(user.getEmployee().getKilometricAllowParam());
            KilometricAllowanceRate kilometricAllowanceRate = Beans.get(KilometricAllowanceRateRepository.class)
                    .findByVehicleKillometricAllowanceParam(user.getEmployee().getKilometricAllowParam());
            if (kilometricAllowanceRate != null) {
                BigDecimal rate = kilometricAllowanceRate.getRate();
                if (rate != null) {
                    kmAllowance.setInTaxTotal(rate.multiply(kmAllowance.getDistance()));
                }
            }
        }

        expense.addKilometricAllowanceListItem(kmAllowance);

        Beans.get(ExpenseRepository.class).save(expense);
    }
}

From source file:com.axelor.apps.hr.service.leave.LeaveService.java

License:Open Source License

public BigDecimal computeDuration(LeaveRequest leave) throws AxelorException {
    if (leave.getDateFrom() != null && leave.getDateTo() != null) {
        Employee employee = leave.getUser().getEmployee();
        if (employee == null) {
            throw new AxelorException(
                    String.format(I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), leave.getUser().getName()),
                    IException.CONFIGURATION_ERROR);
        }//  w  w w. j a  v a  2 s .c  om

        WeeklyPlanning weeklyPlanning = employee.getPlanning();
        if (weeklyPlanning == null) {
            HRConfig conf = leave.getCompany().getHrConfig();
            if (conf != null) {
                weeklyPlanning = conf.getWeeklyPlanning();
            }
        }
        if (weeklyPlanning == null) {
            throw new AxelorException(
                    String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName()),
                    IException.CONFIGURATION_ERROR);
        }
        PublicHolidayPlanning publicHolidayPlanning = employee.getPublicHolidayPlanning();
        if (publicHolidayPlanning == null) {
            HRConfig conf = leave.getCompany().getHrConfig();
            if (conf != null) {
                publicHolidayPlanning = conf.getPublicHolidayPlanning();
            }
        }
        if (publicHolidayPlanning == null) {
            throw new AxelorException(
                    String.format(I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY), employee.getName()),
                    IException.CONFIGURATION_ERROR);
        }

        BigDecimal duration = BigDecimal.ZERO;

        duration = duration.add(new BigDecimal(this.computeStartDateWithSelect(leave.getDateFrom(),
                leave.getStartOnSelect(), weeklyPlanning)));
        LocalDate itDate = new LocalDate(leave.getDateFrom().plusDays(1));

        while (!itDate.isEqual(leave.getDateTo()) && !itDate.isAfter(leave.getDateTo())) {
            duration = duration
                    .add(new BigDecimal(weeklyPlanningService.workingDayValue(weeklyPlanning, itDate)));
            itDate = itDate.plusDays(1);
        }

        if (!leave.getDateFrom().isEqual(leave.getDateTo())) {
            duration = duration.add(new BigDecimal(
                    this.computeEndDateWithSelect(leave.getDateTo(), leave.getEndOnSelect(), weeklyPlanning)));
        }

        duration = duration.subtract(Beans.get(PublicHolidayService.class).computePublicHolidayDays(
                leave.getDateFrom(), leave.getDateTo(), weeklyPlanning, publicHolidayPlanning));
        return duration;
    } else {
        return BigDecimal.ZERO;
    }
}