@RequestMapping(value = "/backoffice/orders/delete.json", method = RequestMethod.PUT)
  public @ResponseBody List<Long> delete(@RequestBody List<Long> ids) {

    menuService.deleteOrders(ids);
    logger.trace("OrderController.delete called with ID-s: " + ids);
    return Collections.emptyList();
  }
  @RequestMapping(value = "/backoffice/orders/activeByDate.json", method = RequestMethod.GET)
  public @ResponseBody List<OrderDto> findActive() {
    logger.trace("OrderController.findActive called");

    List<Order> orders = menuService.getActiveOrders();
    List<OrderDto> orderDtos = mapOrderList(orders);

    return orderDtos;
  }
  @RequestMapping(value = "/orders", method = RequestMethod.POST)
  public @ResponseBody OrderResultDto createNew(@RequestBody Map<String, Object> data) {
    logger.trace("OrderController.createNew called with data: " + data);

    long articleId = Long.parseLong(data.get("articleId").toString());
    long customerId = Long.parseLong(data.get("customerId").toString());
    long deliveryLocationId = Long.parseLong(data.get("deliveryLocationId").toString());
    boolean setDefaultDeliveryLocation =
        Boolean.parseBoolean(data.get("setDefaultDeliveryLocation").toString());
    String note = data.get("note").toString();

    if (setDefaultDeliveryLocation) {
      menuService.setDefaultDeliveryLocation(customerId, deliveryLocationId);
    }

    OrderResult result = menuService.createOrder(articleId, customerId, deliveryLocationId, note);
    OrderResultDto orderResultDto = mapOrderResult(result);

    return orderResultDto;
  }
  @RequestMapping(
      value = "/backoffice/orders/activeGroupedByArticle.json",
      method = RequestMethod.GET)
  public @ResponseBody List<ArticleWithOrdersDto> getActiveOrdersGroupedByArticle() {

    LinkedHashMap<Long, ArticleWithOrders> articlesWithOrders =
        menuService.getActiveOrdersByArticle();
    List<ArticleWithOrdersDto> articlesWithOrdersDtos = new ArrayList<ArticleWithOrdersDto>();

    for (ArticleWithOrders articleWithOrders : articlesWithOrders.values()) {
      ArticleWithOrdersDto articleWithOrdersDto = new ArticleWithOrdersDto();

      articleWithOrdersDto.entity = beanMapper.map(articleWithOrders.entity, ArticleDto.class);

      for (Order order : articleWithOrders.items.values())
        articleWithOrdersDto.items.add(beanMapper.map(order, OrderDto.class));

      articlesWithOrdersDtos.add(articleWithOrdersDto);
    }
    return articlesWithOrdersDtos;
  }
  @RequestMapping(
      value = "/backoffice/orders/activeGroupedByDeliveryLocation.json",
      method = RequestMethod.GET)
  public @ResponseBody List<DeliveryLocationWithArticlesDto>
      getActiveOrdersGroupedByDeliveryLocation() {

    LinkedHashMap<Long, DeliveryLocationWithArticles> locationsWithArticles =
        menuService.getActiveOrdersByDeliveryLocation();

    List<DeliveryLocationWithArticlesDto> locationsWithArticlesDtos =
        new ArrayList<DeliveryLocationWithArticlesDto>();

    for (DeliveryLocationWithArticles deliveryLocationWithArticles :
        locationsWithArticles.values()) {
      DeliveryLocation deliveryLocation = deliveryLocationWithArticles.entity;
      DeliveryLocationWithArticlesDto deliveryLocationWithArticlesDto =
          new DeliveryLocationWithArticlesDto();
      deliveryLocationWithArticlesDto.entity =
          beanMapper.map(deliveryLocation, DeliveryLocationDto.class);
      deliveryLocationWithArticlesDto.countOrderItems =
          deliveryLocationWithArticles.countOrderItems;

      for (ArticleWithOrders articleWithOrders : deliveryLocationWithArticles.items.values()) {
        Article article = articleWithOrders.entity;

        // Construct complete DTO object before it is added to parent group DTO
        ArticleWithOrdersDto articleWithOrdersDto = new ArticleWithOrdersDto();
        articleWithOrdersDto.entity = beanMapper.map(article, ArticleDto.class);

        for (Order order : articleWithOrders.items.values()) {
          OrderDto orderDto = beanMapper.map(order, OrderDto.class);
          articleWithOrdersDto.items.add(orderDto);
        }
        deliveryLocationWithArticlesDto.items.add(articleWithOrdersDto);
      }
      locationsWithArticlesDtos.add(deliveryLocationWithArticlesDto);
    }
    return locationsWithArticlesDtos;
  }
  @RequestMapping(value = "/backoffice/orders/notifyDelivery.json", method = RequestMethod.PUT)
  public @ResponseBody List<Long> notifyDelivery(@RequestBody List<Long> ids) {

    menuService.notifyDelivery(ids);
    return Collections.emptyList();
  }