Custom Reports

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bandtank
    Active Community Member
    • Mar 2017
    • 379

    Custom Reports

    I'm trying to make a custom internal report and I'm not sure where to put it.I found this thread, but it doesn't say where the report should go in the file system. I tried putting it here:

    Code:
    custom/Espo/Custom/Modules/Advanced/Reports/test.php
    but that doesn't work:

    Code:
    [2018-07-22 15:52:21] Espo.ERROR: Uncaught Exception Error: "Class '\Espo\Modules\Advanced\Reports\test.php' not found" ...
    Is there an example of an internal list report? I haven't been able to get the report to show data yet even though I've tried to copy the response to a non-internal report from Chrome's network debugger.
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    Hi,
    try
    custom/Espo/Custom/Reports/Test.php

    Comment

    • bandtank
      Active Community Member
      • Mar 2017
      • 379

      #3
      That was part of the issue. The other part of the issue was the internal_class_name setting, which needs to be Custom:className instead of Advanced:className. Is there documentation to explain how to build internal reports? I can't find anything and I still can't get it to work.

      This is my report:

      Code:
        1 <?php
        2
        3 namespace Espo\Custom\Reports;
        4
        5 use \Espo\ORM\Entity;
        6 use \Espo\Core\Exceptions\Error;
        7 use \Espo\Core\Exceptions\NotFound;
        8
        9 class test extends Base
       10 {
       11   public function run($where = null, array $params = null)
       12   {
       13     return array('list' => [], 'total' => 0, 'columns' => ['name']);
       14   }
       15 }
      EspoCRM reports an Error 500 and no response is shown in the Chrome debugger or the EspoCRM log. I have tried returning an empty array, an array with data, and both of the previous values wrapped in json_encode, but the 500 error code is returned each time.

      Comment

      • bandtank
        Active Community Member
        • Mar 2017
        • 379

        #4
        I copied the return format of the 'LeadsByLastActivity' report:

        Code:
          1 <?php
          2
          3 namespace Espo\Custom\Reports;
          4
          5 use \Espo\ORM\Entity;
          6 use \Espo\Core\Exceptions\Error;
          7 use \Espo\Core\Exceptions\NotFound;
          8
          9 class test extends Base
         10 {
         11   public function run($where = null, array $params = null)
         12   {
         13     return array(
         14         'type'            => 'Grid',
         15         'groupBy'         => array(),
         16         'columns'         => array('name'),
         17         'sums'            => array(),
         18         'groupNameMap'    => array(),
         19         'columnNameMap'   => array('name' => 'name'),
         20         'depth'           => 2,
         21         'grouping'        => array(),
         22         'reportData'      => array(),
         23         'entityType'      => 'Jobpse',
         24     );
         25   }
         26 }
        I'm still seeing an Error 500 in EspoCRM when I try to run the report. I have no idea what's wrong because the log has nothing in it. I would like to use a List instead of a Grid, but neither option works and I don't know the list of required parameters.

        Comment

        • bandtank
          Active Community Member
          • Mar 2017
          • 379

          #5
          It was this:

          Code:
          class test extends \Espo\Modules\Advanced\Reports\Base
          I found it by looking in /var/log/apache2/crm-error.log:

          Code:
          ... PHP Fatal error:  Class 'Espo\\Custom\\Reports\\Base' not found ...

          Comment

          • bandtank
            Active Community Member
            • Mar 2017
            • 379

            #6
            I've made some more progress. The report will display correctly in EspoCRM, but a few things don't seem right still.

            Here's my report:

            Code:
              1 <?php
              2
              3 namespace Espo\Custom\Reports;
              4
              5 use \Espo\ORM\Entity;
              6 use \Espo\Core\Exceptions\Error;
              7 use \Espo\Core\Exceptions\NotFound;
              8
              9 class test extends \Espo\Modules\Advanced\Reports\Base
             10 {
             11   public function run($where = null, array $params = null)
             12   {
             13     $jobs = $this->getEntityManager()->getRepository('Jobpse')->where(array(
             14       'name' => '18-0089'
             15     ))->find(['select' => ['id', 'name','deleted']]);
             16
             17     return array(
             18         'collection'      => $jobs,
             19         'total'           => $jobs->count(),
             20         'columns'         => ['name', 'id'],
             21         'columnsData'     => json_decode(json_encode([
             22           'name' => ['link' => true, 'width' => null, 'notSortable' => false, 'align' => 'left'],
             23           'id'   => ['link' => true, 'width' => null, 'notSortable' => false, 'align' => 'left']
             24         ]))
             25     );
             26   }
             27 }
            The 'columns' and 'columnsData' entries in the returned object do not work unless the values shown in the test are entered into the database. Trying to set 'columns' and 'columnsData' as shown above results in the following report:

            Click image for larger version  Name:	1.png Views:	1 Size:	18.9 KB ID:	40691

            As you can see, there are no rows or columns even though there should be:


            Click image for larger version  Name:	2.png Views:	1 Size:	35.1 KB ID:	40686

            Now, if I add ["name", "id"] to the 'columns' field in the database:

            Click image for larger version  Name:	5.png Views:	1 Size:	4.7 KB ID:	40688

            The report looks like this:

            Click image for larger version  Name:	4.png Views:	1 Size:	23.4 KB ID:	40689


            However, the links are still not present.

            Finally, if I add the 'columnsData' value to the database, the report has links in each field as expected:

            Click image for larger version  Name:	6.png Views:	1 Size:	25.0 KB ID:	40690


            This is a little confusing. Do 'columns' and 'columnsData' need to be set in the report class or database entry? Why does the Base class look for 'columns' and 'columnsData' if it isn't useful?
            Last edited by bandtank; 07-23-2018, 04:49 AM.

            Comment

            • tanya
              Senior Member
              • Jun 2014
              • 4308

              #7
              the logic were changed, but for old logic has to work as well. That's why you see these fields...

              Comment

              • bandtank
                Active Community Member
                • Mar 2017
                • 379

                #8
                Originally posted by tanya
                the logic were changed, but for old logic has to work as well. That's why you see these fields...
                Ok, thanks. So, just to be clear, the database should be used to define the 'columns' and 'columnsData' values, right?

                Comment

                • tanya
                  Senior Member
                  • Jun 2014
                  • 4308

                  #9
                  columns is an array, which contains list of fields only
                  columnsData is json, where you set the definition of this columns
                  Code:
                  {
                    "field1Name": {
                       "link":true,
                      "width":null,
                      "notSortable":false,
                      "align":"left"
                   },
                  "field2Name": {
                       ...
                   }
                  }

                  Comment

                  Working...