Example usage for org.joda.time LocalDate withDayOfMonth

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

Introduction

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

Prototype

public LocalDate withDayOfMonth(int dayOfMonth) 

Source Link

Document

Returns a copy of this date with the day of month field updated.

Usage

From source file:org.zkoss.ganttz.timetracker.zoom.DetailThreeTimeTrackerState.java

License:Open Source License

@Override
protected LocalDate round(LocalDate date, boolean down) {
    if ((date.getMonthOfYear() == 1 || date.getMonthOfYear() == 7) && date.getDayOfMonth() == 1) {
        return date;
    }/*from w ww.  jav a  2  s.c o  m*/

    date = date.withDayOfMonth(1);

    if (date.getMonthOfYear() < 7) {
        return down ? date.withMonthOfYear(1) : date.withMonthOfYear(7);
    } else {
        return down ? date.withMonthOfYear(7) : date.plusYears(1).withMonthOfYear(1);
    }
}

From source file:ru.codemine.ccms.entity.SalesMeta.java

License:Open Source License

public SalesMeta(Shop shop, LocalDate startDate, LocalDate endDate) {
    this.shop = shop;
    this.description = "";
    this.startDate = startDate;
    this.endDate = endDate;
    this.plan = 0.0;
    this.passabilityTotal = 0;
    this.chequeCountTotal = 0;
    this.valueTotal = 0.0;
    this.cashbackTotal = 0.0;
    this.salesTotal = 0.0;
    this.expencesTotal = 0.0;

    this.expences = new TreeMap<>();
    this.sales = new TreeSet<>();
    for (int i = 1; i <= startDate.dayOfMonth().getMaximumValue(); i++) {
        this.sales.add(new Sales(shop, startDate.withDayOfMonth(i)));
    }//from  w  w w.  j  av a2s  .c  o m
}

From source file:ru.codemine.ccms.router.api.ApiRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/api/passability", method = RequestMethod.GET)
public @ResponseBody List<PassabilityJson> getPassabilityJson(@RequestParam(required = false) Integer shopid,
        @RequestParam(required = false) String shopname, @RequestParam("startDate") String startDateStr,
        @RequestParam("endDate") String endDateStr, @RequestParam(required = false) String detail) {
    if (shopid == null && shopname == null)
        throw new InvalidParametersException();
    if (shopid != null && shopname != null)
        throw new InvalidParametersException();

    try {//  w  w  w.  j  a  v  a  2 s .  c  om
        Shop shop = shopid == null ? shopService.getByName(shopname) : shopService.getById(shopid);

        DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
        List<PassabilityJson> resulList = new ArrayList<>();

        LocalDate startDate = formatter.parseLocalDate(startDateStr);
        LocalDate endDate = formatter.parseLocalDate(endDateStr);

        if (detail == null || "none".equals(detail)) {
            PassabilityJson record = new PassabilityJson();

            record.setStartDate(startDate.toString("dd.MM.YYYY"));
            record.setEndDate(endDate.toString("dd.MM.YYYY"));
            if (shop.isCountersEnabled()) {
                record.setIn(counterService.getInValueByPeriod(shop, startDate, endDate));
                record.setOut(counterService.getOutValueByPeriod(shop, startDate, endDate));
            } else {
                record.setIn(salesService.getPassabilityValueByPeriod(shop, startDate, endDate));
                record.setOut(record.getIn());
            }
            resulList.add(record);
        } else if ("day".equals(detail)) {
            // ? ,  ? 
            List<SalesMeta> smList = salesService.getByPeriod(shop, startDate.withDayOfMonth(1),
                    endDate.dayOfMonth().withMaximumValue());
            List<Sales> allSales = salesService.getAllSalesFromMetaList(smList, startDate, endDate);

            for (Sales s : allSales) {
                PassabilityJson record = new PassabilityJson();

                record.setStartDate(s.getDate().toString("dd.MM.YYYY"));
                record.setEndDate(s.getDate().toString("dd.MM.YYYY"));
                record.setIn(shop.isCountersEnabled()
                        ? counterService.getInValueByPeriod(shop, s.getDate(), s.getDate())
                        : s.getPassability());
                record.setOut(shop.isCountersEnabled()
                        ? counterService.getOutValueByPeriod(shop, s.getDate(), s.getDate())
                        : s.getPassability());

                resulList.add(record);
            }
        } else if ("month".equals(detail)) {
            startDate = startDate.withDayOfMonth(1);
            endDate = endDate.dayOfMonth().withMaximumValue();

            List<SalesMeta> smList = salesService.getByPeriod(shop, startDate, endDate);
            for (SalesMeta sm : smList) {
                PassabilityJson record = new PassabilityJson();

                record.setStartDate(sm.getStartDate().toString("dd.MM.YYYY"));
                record.setEndDate(sm.getEndDate().toString("dd.MM.YYYY"));
                record.setIn(shop.isCountersEnabled()
                        ? counterService.getInValueByPeriod(shop, sm.getStartDate(), sm.getEndDate())
                        : sm.getPassabilityTotal());
                record.setOut(shop.isCountersEnabled()
                        ? counterService.getOutValueByPeriod(shop, sm.getStartDate(), sm.getEndDate())
                        : sm.getPassabilityTotal());

                resulList.add(record);
            }
        }

        return resulList;
    } catch (Exception e) {
        log.warn(" ?  API (?) - "
                + e.getLocalizedMessage());
        return new ArrayList<>();
    }
}

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;//  www  . java2 s.c o  m

    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.sales.domino.DominoSalesLoader.java

License:Open Source License

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

    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 Double getMidExpences(Shop shop, int months) {
    if (months <= 0)
        return -1.0;

    LocalDate endDate = LocalDate.now().minusMonths(1).dayOfMonth().withMaximumValue();
    LocalDate startDate = endDate.withDayOfMonth(1).minusMonths(months - 1);

    Double expTotal = getTotalExpenceValueForPeriod(shop, startDate, endDate);

    Double result = Math.round(expTotal / months * 100.0) / 100.0;

    return result;
}

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

License:Open Source License

public Double getMidCleanSales(Shop shop, int months) {
    if (months <= 0)
        return -1.0;

    LocalDate endDate = LocalDate.now().minusMonths(1).dayOfMonth().withMaximumValue();
    LocalDate startDate = endDate.withDayOfMonth(1).minusMonths(months - 1);

    Double cleanSales = getSalesValueByPeriod(shop, startDate, endDate)
            - getTotalExpenceValueForPeriod(shop, startDate, endDate);

    Double result = Math.round(cleanSales / months * 100.0) / 100.0;

    return result;
}