Example usage for org.joda.time LocalDate isBefore

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

Introduction

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

Prototype

public boolean isBefore(ReadablePartial partial) 

Source Link

Document

Is this partial earlier than the specified partial.

Usage

From source file:ru.codemine.ccms.router.SalesRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/sales-pass/data")
public @ResponseBody List<Map<String, Object>> getSalesPassReportData(
        @RequestParam(required = false) String dateStartStr, @RequestParam(required = false) String dateEndStr,
        ModelMap model) {/*  w  w  w  .ja v  a  2 s. c  o  m*/
    List<Map<String, Object>> recordsList = new ArrayList<>();

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart.dayOfMonth().withMaximumValue();

    List<Shop> shopList = shopService.getAllOpen();

    for (Shop shop : shopList) {
        Map<String, Object> record = new HashMap();

        record.put("shopname", shop.getName());
        record.put("passability", salesService.getPassabilityValueByPeriod(shop, dateStart, dateEnd));
        record.put("cheque", salesService.getCqcountValueByPeriod(shop, dateStart, dateEnd));
        record.put("value", salesService.getValueByPeriod(shop, dateStart, dateEnd));
        record.put("cashback", salesService.getCashbackValueByPeriod(shop, dateStart, dateEnd));
        record.put("periodtotal", salesService.getSalesValueByPeriod(shop, dateStart, dateEnd));
        record.put("midPrice", salesService.getMidPriceValueByPeriod(shop, dateStart, dateEnd));
        record.put("plan", salesService.getPlan(shop, dateStart, dateEnd));
        record.put("plancoverage", salesService.getPlanCoverage(shop, dateStart, dateEnd));

        recordsList.add(record);
    }

    return recordsList;
}

From source file:ru.codemine.ccms.router.SalesRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/sales-pass/details")
public @ResponseBody List<Map<String, Object>> getSalesPassReportDetails(@RequestParam String dateStartStr,
        @RequestParam String dateEndStr, @RequestParam String shopname, ModelMap model) {
    List<Map<String, Object>> recordsList = new ArrayList<>();

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart.dayOfMonth().withMaximumValue();

    Integer daysCount = dateEnd.getDayOfMonth();
    Integer counterTotals = 0;//from   ww  w.  java 2  s.c om

    List<String> recordNames = new ArrayList<>();
    recordNames.add("?");
    recordNames.add("- ");
    recordNames.add(" ");
    recordNames.add("");
    recordNames.add("");
    recordNames.add(" ");

    Shop shop = shopService.getByName(shopname);

    if (dateStart.getMonthOfYear() == dateEnd.getMonthOfYear()) {
        SalesMeta salesMeta = salesService.getByShopAndDate(shop, dateStart, dateEnd);

        for (int row = 1; row <= recordNames.size(); row++) {
            Map<String, Object> record = new HashMap();
            record.put("info", recordNames.get(row - 1));

            for (int cell = 1; cell <= daysCount; cell++) {
                String cellname = "c" + String.valueOf(cell);
                Sales sale = salesMeta.getByDate(dateStart.withDayOfMonth(cell));
                switch (row) {
                case 1: //?
                    if (shop.isCountersEnabled()) {
                        Counter counter = counterService.getByShopAndDate(shop,
                                dateStart.withDayOfMonth(cell).toDateTime(LocalTime.MIDNIGHT));
                        Integer counterValue = counter == null ? 0 : counter.getIn();
                        record.put(cellname, counterValue);
                        counterTotals += counterValue;
                        if (cell == daysCount)
                            record.put("totals", counterTotals);
                    } else {
                        record.put(cellname, sale.getPassability());
                        counterTotals += sale.getPassability();
                        if (cell == daysCount)
                            record.put("totals", counterTotals);
                    }
                    break;
                case 2: //- 
                    record.put(cellname, sale.getChequeCount());
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getChequeCountTotal());
                    break;
                case 3: // 
                    record.put(cellname, sale.getValue());
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getValueTotal());
                    break;
                case 4: //
                    record.put(cellname, sale.getCashback());
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getCashbackTotal());
                    break;
                case 5: //
                    record.put(cellname, sale.getDayTotal());
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getSalesTotal());
                    break;
                case 6: // 
                    Integer chequeCount = sale.getChequeCount();
                    Double midPrice = chequeCount == 0 ? 0 : sale.getMidPrice();
                    record.put(cellname, midPrice);
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getPeriodMidPrice());
                    break;
                }
            }

            recordsList.add(record);
        }
    } else //    ??
    {
        List<SalesMeta> smList = new ArrayList<>();

        LocalDate tempStartDate = dateStart;
        while (tempStartDate.isBefore(dateEnd)) {
            smList.add(salesService.getByShopAndDate(shop, tempStartDate,
                    tempStartDate.dayOfMonth().withMaximumValue()));
            tempStartDate = tempStartDate.plusMonths(1);
        }

        for (int row = 1; row <= recordNames.size(); row++) {
            Map<String, Object> record = new HashMap();
            record.put("info", recordNames.get(row - 1));

            for (int cell = 1; cell <= smList.size(); cell++) {
                String cellname = "c" + String.valueOf(cell);
                SalesMeta sm = smList.get(cell - 1);
                switch (row) {
                case 1: //?
                    if (shop.isCountersEnabled()) {
                        record.put(cellname, counterService.getPassabilityValueByPeriod(shop, sm.getStartDate(),
                                sm.getEndDate()));
                        if (cell == smList.size())
                            record.put("totals",
                                    counterService.getPassabilityValueByPeriod(shop, dateStart, dateEnd));
                    } else {
                        record.put(cellname, sm.getPassabilityTotal());
                        if (cell == smList.size())
                            record.put("totals",
                                    salesService.getPassabilityValueByPeriod(shop, dateStart, dateEnd));
                    }
                    break;
                case 2: //- 
                    record.put(cellname, sm.getChequeCountTotal());
                    if (cell == smList.size())
                        record.put("totals", salesService.getCqcountValueByPeriod(shop, dateStart, dateEnd));
                    break;
                case 3: // 
                    record.put(cellname, sm.getValueTotal());
                    if (cell == smList.size())
                        record.put("totals", salesService.getValueByPeriod(shop, dateStart, dateEnd));
                    break;
                case 4: //
                    record.put(cellname, sm.getCashbackTotal());
                    if (cell == smList.size())
                        record.put("totals", salesService.getCashbackValueByPeriod(shop, dateStart, dateEnd));
                    break;
                case 5: //
                    record.put(cellname, sm.getSalesTotal());
                    if (cell == smList.size())
                        record.put("totals", salesService.getSalesValueByPeriod(shop, dateStart, dateEnd));
                    break;
                case 6: // 
                    record.put(cellname, sm.getPeriodMidPrice());
                    if (cell == smList.size())
                        record.put("totals", salesService.getMidPriceValueByPeriod(shop, dateStart, dateEnd));
                    break;
                }
            }

            recordsList.add(record);
        }
    }

    return recordsList;
}

From source file:ru.codemine.ccms.router.SalesRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/graph/sales-pass", method = RequestMethod.GET)
public String getSalesPassGraph(@RequestParam(required = false) String dateStartStr,
        @RequestParam(required = false) String dateEndStr, @RequestParam(required = false) Integer shopid,
        ModelMap model) {/* w  w w . j  a v a2  s  . c o m*/
    model.addAllAttributes(utils.prepareModel());

    List<Shop> shopList = shopService.getAllOpen();
    List<String> graphDataDayTotal = new ArrayList<>();
    List<String> graphDataPassability = new ArrayList<>();

    Shop shop = shopid == null ? shopList.get(0) : shopService.getById(shopid);

    model.addAttribute("shop", shop);
    model.addAttribute("shopList", shopList);

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart.dayOfMonth().withMaximumValue();

    model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY"));
    model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY"));

    List<SalesMeta> smList = salesService.getByPeriod(shop, dateStart, dateEnd);

    for (Sales sales : salesService.getAllSalesFromMetaList(smList)) {
        if (shop.isCountersEnabled()) {
            Counter counter = counterService.getByShopAndDate(shop,
                    sales.getDate().toDateTime(LocalTime.MIDNIGHT));
            if (sales.getPassability() == 0)
                sales.setPassability(counter == null ? 0 : counter.getIn());
        }

        graphDataDayTotal.add(sales.getGraphDataDayTotal());
        graphDataPassability.add(sales.getGraphDataPassability());
    }

    model.addAttribute("graphDataDayTotal", graphDataDayTotal);
    model.addAttribute("graphDataPassability", graphDataPassability);

    return "reports/sales-pass-graph";
}

From source file:ru.codemine.ccms.router.TaskRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/tasks", method = RequestMethod.GET)
public String tasksReport(ModelMap model, @RequestParam(required = false) String dateStartStr,
        @RequestParam(required = false) String dateEndStr) {
    model.addAllAttributes(utils.prepareModel());

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr);

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart;/*  w  w w .  ja v  a  2 s.  c o  m*/

    model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY"));
    model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY"));

    return "reports/tasks-byuser";
}

From source file:uk.ac.ox.oucs.vle.CourseDAOImpl.java

License:Educational Community License

public static LocalDate getPreviousYearBeginning(LocalDate currentDate) {
    int currentCivilYear = currentDate.getYear();
    int previousAcademicYear;

    // If we've started a new civil year and haven't changed the academic year yet, go back one more year.
    if (currentDate.isBefore(FIRST_DAY_OF_ACADEMIC_YEAR.toLocalDate(currentCivilYear))) {
        previousAcademicYear = currentCivilYear - 2;
    } else {/*from w ww  .jav  a 2  s.c o  m*/
        previousAcademicYear = currentCivilYear - 1;
    }

    return FIRST_DAY_OF_ACADEMIC_YEAR.toLocalDate(previousAcademicYear);
}