From 08cfc7165d3a8a36bc30e782261e9d777e62eb6e Mon Sep 17 00:00:00 2001 From: Jiri Barous Date: Fri, 3 Jul 2015 15:07:29 +0200 Subject: [PATCH] improves dashboard statistics Fixes missing czech translation for statistics header. Improves clarity of displayed information. Removes useless registration count. Adds data for any paid orders. --- .../Doctrine/ORM/OrderRepository.php | 8 +++--- .../Backend/DashboardController.php | 23 ++++++++++------ .../Resources/translations/messages.cs.yml | 3 +++ .../Resources/translations/messages.en.yml | 4 ++- .../views/Backend/Dashboard/main.html.twig | 26 +++++++++---------- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php index 6ba3ac05f9f..14802a321ee 100644 --- a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php +++ b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php @@ -347,10 +347,10 @@ protected function getCollectionQueryBuilderBetweenDates(\DateTime $from, \DateT { $queryBuilder = $this->getCollectionQueryBuilder(); if (null !== $state) { - $queryBuilder - ->andWhere('o.state = :state') - ->setParameter('state', $state) - ; + $queryBuilder + ->andWhere('o.state in (:state)') + ->setParameter('state', (array) $state) + ; } return $queryBuilder diff --git a/src/Sylius/Bundle/WebBundle/Controller/Backend/DashboardController.php b/src/Sylius/Bundle/WebBundle/Controller/Backend/DashboardController.php index bcc35fcb525..82838190d38 100644 --- a/src/Sylius/Bundle/WebBundle/Controller/Backend/DashboardController.php +++ b/src/Sylius/Bundle/WebBundle/Controller/Backend/DashboardController.php @@ -28,16 +28,23 @@ public function mainAction() { $orderRepository = $this->get('sylius.repository.order'); $userRepository = $this->get('sylius.repository.user'); - $productRepository = $this->get('sylius.repository.product'); + + $date_from = new \DateTime('30 days ago'); + $date_to = new \DateTime(); return $this->render('SyliusWebBundle:Backend/Dashboard:main.html.twig', array( - 'orders_count' => $orderRepository->countBetweenDates(new \DateTime('1 month ago'), new \DateTime()), - 'orders' => $orderRepository->findBy(array(), array('updatedAt' => 'desc'), 5), - 'users' => $userRepository->findBy(array(), array('id' => 'desc'), 5), - 'registrations_count' => $userRepository->countBetweenDates(new \DateTime('1 month ago'), new \DateTime()), - 'sales' => $orderRepository->revenueBetweenDates(new \DateTime('1 month ago'), new \DateTime()), - 'sales_confirmed' => $orderRepository->revenueBetweenDates(new \DateTime('1 month ago'), new \DateTime(), OrderInterface::STATE_CONFIRMED), - 'products' => $productRepository->findUpcomingEvents(), + 'orders' => $orderRepository->findBy(array(), array('updatedAt' => 'desc'), 5), + 'orders_count' => $orderRepository->countBetweenDates($date_from, $date_to), + 'orders_count_confirmed' => $orderRepository->countBetweenDates($date_from, $date_to, array( + OrderInterface::STATE_CONFIRMED, + OrderInterface::STATE_SHIPPED, + )), + 'sales' => $orderRepository->revenueBetweenDates($date_from, $date_to), + 'sales_confirmed' => $orderRepository->revenueBetweenDates($date_from, $date_to, array( + OrderInterface::STATE_CONFIRMED, + OrderInterface::STATE_SHIPPED, + )), + 'users' => $userRepository->findBy(array(), array('id' => 'desc'), 5), )); } } diff --git a/src/Sylius/Bundle/WebBundle/Resources/translations/messages.cs.yml b/src/Sylius/Bundle/WebBundle/Resources/translations/messages.cs.yml index afef7b34c10..65316e142c4 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/translations/messages.cs.yml +++ b/src/Sylius/Bundle/WebBundle/Resources/translations/messages.cs.yml @@ -73,8 +73,11 @@ sylius: products: Produkty users: Uživatelé statistics: + header: Statistiky za posledních 30 dní + orders_confirmed_this_month: Objednávek zaplaceno orders_this_month: Celkem objednávek registrations_this_month: Celkem registrací + sales_confirmed_this_month: Z toho zaplaceno sales_this_month: Prodeje block: body: Tělo diff --git a/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml index 9ae373de155..897ed03c4fb 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/WebBundle/Resources/translations/messages.en.yml @@ -84,9 +84,11 @@ sylius: products: Your products users: Users statistics: - header: This month's statistics + header: Statistics for the past 30 days + orders_confirmed_this_month: Orders paid orders_this_month: Total orders registrations_this_month: Total registrations + sales_confirmed_this_month: Confirmed sales sales_this_month: Sales backend_welcome: Hello %name%! block: diff --git a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Dashboard/main.html.twig b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Dashboard/main.html.twig index 1b6491faf46..c9579e99282 100644 --- a/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Dashboard/main.html.twig +++ b/src/Sylius/Bundle/WebBundle/Resources/views/Backend/Dashboard/main.html.twig @@ -25,22 +25,22 @@ - + - - - - - - - - - - - - + + + + + + + + + + + +
{{ 'sylius.backend.statistics.header'|trans }}{{ 'sylius.backend.statistics.header'|trans }}
{{ 'sylius.backend.statistics.sales_this_month'|trans }}{{ sales|sylius_price }} ({{ sales_confirmed|sylius_price }})
{{ 'sylius.backend.statistics.orders_this_month'|trans }}{{ orders_count }}
{{ 'sylius.backend.statistics.registrations_this_month'|trans }}{{ registrations_count }}
{{ 'sylius.backend.statistics.sales_this_month'|trans }}{{ sales|sylius_price }}{{ 'sylius.backend.statistics.sales_confirmed_this_month'|trans }}{{ sales_confirmed|sylius_price }}
{{ 'sylius.backend.statistics.orders_this_month'|trans }}{{ orders_count }}{{ 'sylius.backend.statistics.orders_confirmed_this_month'|trans }}{{ orders_count_confirmed }}