Example usage for org.joda.time LocalDate toString

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

Introduction

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

Prototype

public String toString(String pattern) 

Source Link

Document

Output the date using the specified format pattern.

Usage

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

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/sales-pass", method = RequestMethod.GET)
public String getSalesPassReport(@RequestParam(required = false) String dateStartStr,
        @RequestParam(required = false) String dateEndStr, @RequestParam(required = false) String mode,
        ModelMap model) {//from  w  w w. ja v a  2 s. c o  m

    model.addAllAttributes(utils.prepareModel());

    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<String> subgridColNames = new ArrayList<>();
    subgridColNames.add("?");

    if (dateStart.getMonthOfYear() == dateEnd.getMonthOfYear()) {
        for (int i = 1; i <= dateEnd.getDayOfMonth(); i++) {
            subgridColNames.add(String.valueOf(i) + dateStart.toString(".MM.YY"));
        }
    } else {
        LocalDate printDate = dateStart;
        while (printDate.isBefore(dateEnd)) {
            subgridColNames.add(printDate.toString("MMM YYYY"));
            printDate = printDate.plusMonths(1);
        }
    }

    subgridColNames.add("");

    model.addAttribute("subgridColNames", subgridColNames);

    return "print".equals(mode) ? "printforms/reports/salesAllFrm" : "reports/sales-pass";
}

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) {/*from  w w w. jav  a 2  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;/* www .  jav  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:ru.codemine.ccms.sales.domino.DominoSalesLoader.java

License:Open Source License

@Override
public void processSales(List<Shop> shops) {
    emailExtractor.saveAllAttachment();//from ww  w.j a v a  2s.  c  o  m

    Map<LocalDate, Map<String, Sales>> processMap = getSalesMap();

    if (!processMap.isEmpty()) {
        for (Entry<LocalDate, Map<String, Sales>> entry : processMap.entrySet()) {
            LocalDate date = entry.getKey();
            Map<String, Sales> valuesMap = entry.getValue();

            for (Shop shop : shops) {
                Sales saleFromMap = valuesMap.get(shop.getDominoName());
                if (saleFromMap != null) {
                    SalesMeta sm = salesService.getByShopAndDate(shop, date.withDayOfMonth(1),
                            date.dayOfMonth().withMaximumValue());
                    Sales sales = sm.getByDate(date);
                    sales.setValue(saleFromMap.getValue());
                    sales.setCashback(saleFromMap.getCashback());
                    sales.setChequeCount(saleFromMap.getChequeCount());
                    salesService.update(sm);
                } else {
                    log.warn("?  ?    "
                            + shop.getName() + ",    " + date.toString("dd.MM.YYYY"));
                    //log.warn("? : " + shop.getDominoName());
                }
            }
        }

        log.info("??   ");
    } else {
        log.info("?   ? ");
    }

}

From source file:ru.codemine.ccms.service.SalesService.java

License:Open Source License

public SalesMeta getByShopAndDate(Shop shop, LocalDate startDate, LocalDate endDate) {
    SalesMeta sm = salesDAO.getByShopAndDate(shop, startDate, endDate);
    if (sm == null) {
        sm = new SalesMeta(shop, startDate, endDate);
        sm.setDescription(" : " + shop.getName() + " ("
                + startDate.toString("MMMM YYYY") + ")");
    }/*  w  w w  . jav  a2 s. c  o m*/

    return sm;
}

From source file:ru.codemine.pos.reports.SalesByPtypeReport.java

License:Open Source License

@Override
public void setPeriod(LocalDate startDate, LocalDate endDate) {
    List<SalesByPtypeReportRecord> records = new ArrayList<>();
    for (Map.Entry<Cheque.PaymentType, String> paymentEntry : Cheque.getAvaiblePaymentTypes().entrySet()) {
        List<Cheque> chequesByPtype = chequeService.getByPeriod(startDate, endDate, paymentEntry.getKey());
        Double sales = 0.0;// w w  w.ja v a2  s.  c  o  m
        for (Cheque c : chequesByPtype)
            sales += c.getChequeTotal();
        records.add(new SalesByPtypeReportRecord(paymentEntry.getValue(), chequesByPtype.size(), sales));
    }

    Map<String, Object> parameters = new HashMap<>();
    parameters.put("startDate", startDate.toString("dd.MM.YY"));
    parameters.put("endDate", endDate.toString("dd.MM.YY"));

    try {
        JasperReport report = (JasperReport) JRLoader.loadObjectFromFile("reports/SalesByPtypeReport.jasper");
        JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(records);
        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);
        WebFrame reportFrame = new WebFrame("     ");
        reportFrame.getContentPane().add(new JRViewer(jasperPrint));
        reportFrame.pack();
        reportFrame.setExtendedState(WebFrame.MAXIMIZED_BOTH);
        reportFrame.setVisible(true);
    } catch (JRException ex) {
        WebOptionPane.showMessageDialog(null, ex.getLocalizedMessage(),
                " ?? ", WebOptionPane.ERROR_MESSAGE);
    }

}

From source file:se.inera.certificate.schema.adapter.LocalDateAdapter.java

License:Open Source License

/**
 * Print a Date in ISO format.//w w w  .  j  av  a  2 s.  c o m
 */
public static String printIsoDate(LocalDate date) {
    return date.toString(ISO_DATE_PATTERN);
}

From source file:ua.mycompany.agedaysmonths.AgeDaysMonths.java

public static void main(String[] args) {
    LocalDate birthdate = new LocalDate(2015, 11, 12);
    LocalDate now = new LocalDate();

    System.out.printf("My age in month: %d\n", Months.monthsBetween(birthdate, now).getMonths());
    System.out.printf("My age in days: %d\n", Days.daysBetween(birthdate, now).getDays());
    System.out.printf("Day of week my birtday: %s, %s\n", birthdate.getDayOfWeek(),
            birthdate.toString(DateTimeFormat.forPattern("E").withLocale(Locale.forLanguageTag("en"))));

}