Skip over navigation
Documentation
You are currently viewing documentation for a previously released version of OroCommerce. See the latest long-term support version.

How to Create a Report

In the user interface, users can configure their own reports through an intuitive graphical report builder. However, you can also define your own static reports through YAML configuration and make them available to your users. You may, for example, want to display the number of tasks per priority.

The solution to this problem involves two simple steps:

  1. Firstly, you have to define which data need to be fetched and how they should be presented to the user in a data grid configuration.
  2. To make the created report accessible to your users, you have to create an entry in the application menu.

Configuring the Data Grid

Defining the report basically is the same as configuring any other data grid:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# src/AppBundle/Resources/config/oro/datagrids.yml
datagrids:
    orocrm_report-tasks-by_priority:
        source:
            type: orm
            query:
                select:
                    - priority.label AS taskPriority
                    - COUNT(task) AS tasksCount
                from:
                    - { table: AppBundle:TaskPriority, alias: priority }
                join:
                    left:
                        - join: AppBundle:Task
                          alias: task
                          conditionType: WITH
                          condition: priority = task.priority
        columns:
            taskPriority:
                label: Priority
            tasksCount:
                label: '# Tasks'
        sorters:
            columns:
                taskPriority:
                    data_name: priority.label
                tasksCount:
                    data_name: tasksCount
            default:
                taskPriority: ASC
        filters:
            columns:
                taskPriority:
                    data_name: priority.label
                tasksCount:
                    data_name: tasksCount
                    filter_by_having: true

Adding an Entry to the Navigation

If you followed the naming schema explained above, you do not have to create your own controller, but you can create a navigation item whose route config option refers to orocrm_report_index route which comes with the OroCRMReportBundle and is able to render any static report:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# src/AppBundle/Resources/config/oro/navigation.yml
menu_config:
    items:
        app_tasks_reports_tab:
            label: Tasks
            uri: '#'
        app_tasks_by_priority_report:
            label: By Priority
            route: orocrm_report_index
            routeParameters:
                reportGroupName: tasks
                reportName: by_priority
    tree:
        application_menu:
            children:
                reports_tab:
                    children:
                        app_tasks_reports_tab:
                            children:
                                app_tasks_by_priority_report: ~
ForumsForums
Back to top