Third Party Report Writer Compatibility

Hey @Andrew_C I ended up just using Google Charts to write my own graphs and reports for users to display on the dashboard (with some help from one of @pgr 's posts.

1 Like

Could you please share your code and config for Sankey chart?

@pgr gets credit for this one. I think I had to make a few tweaks but like 99% @pgr.

<html>
  <head>
       <?php
  global $current_user;
  global $db;
  $rows=array();

  $query = "SELECT lead_source, sales_stage as stage, amount as total, user_name as user
            FROM opportunities
            LEFT JOIN users ON users.id = opportunities.assigned_user_id
            WHERE opportunities.deleted=0
            ";
  $result=$db->query($query,true);
  while( $row = $db->fetchByAssoc($result)) {
     $rows[]= $row;
   //  $rows[]= array($row['lead_source'], $row['stage'], $row['total'], $row['user']);
   //echo $row['stage'], ": ", $row['total'], '<br/>';
  }
//  if (count($rows)==0) echo 'Query returned no rows.';
//  var_dump($rows);
//  foreach($rows as $key => $value) {
//     var_dump($key);
//     var_dump($value);
//   }
?>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">

      // Load the Visualization API and the corechart package.
//      google.charts.load('current', {'packages':['corechart']});
      google.charts.load('current', {'packages':['sankey']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.charts.setOnLoadCallback(drawChart);
      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'From');
        data.addColumn('string', 'To');
        data.addColumn('number', 'Amount');
        data.addRows([
            <?php foreach ($rows as $r) {
               echo "['", $r['lead_source'], "', '", $r['user'], "', ", $r['total'], "],", PHP_EOL;
               echo "['", $r['user'], "', '", $r['stage'], "', ", $r['total'], "],", PHP_EOL;
             }
            ?>
        ]);

        // Set chart options
        var colors = ['#a6cee3', '#b2df8a', '#fb9a99', '#fdbf6f',
                  '#cab2d6', '#ffff99', '#1f78b4', '#33a02c'];
        var options = {'title': 'Opportunities', // Source, Employee, Outcome, with Amount shown as Width',
                       'width': 400,
                       'height':400,
        sankey: {
          node: {
      //      colors: colors
          },
          link: {
            colorMode: 'gradient',
      //      colors: colors
          }
        }

        };

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.Sankey(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
   </script>

<body>
<div style="zoom: 1.0; -moz-transform: scale(1.0); transform-origin: 0 0; -moz-transform-origin: 0 0">
    <!--Table and divs that hold the pie charts-->
    <table class="columns">
      <tr>
        <td><div id="chart_div" style="border: 1px solid #ccc;"></div></td>
      </tr>
      <td><div id="barchart_div" style="border: 1px solid #ccc;"></div></td>
      </tr>
    </table>
</div>
  </body>

</html>
1 Like

@rsp the cool one is the line chart where I have a drop down so the user can change from “all users” to “current user” I did that as proof of concept, but you could have the user customize the report and thus modify the query based on what they choose. It’ super versatile!

But, where I have to create this file and paste code? I guess, I need your code for line chart too then.
It is really cool dashlet to have on the home page.

If you want, I could create a separate topic on this forum.

Here’s the complete discussion on Google Charts:

1 Like

I clicked on Add Dashlets and paste my URL. But, I am getting an error.

Incorrect website location is specified

Console error:

MySugar.js?v=6WY0eIRvQx-xSuYs2iwxMg:49 Uncaught ReferenceError: newTop is not defined
    at Object.fillInConfigureDiv (MySugar.js?v=6WY0eIRvQx-xSuYs2iwxMg:49:481)
    at Object.handleTransactionResponse (sugar_grp1_yui.js?v=6WY0eIRvQx-xSuYs2iwxMg:31:4422)
    at sugar_grp1_yui.js?v=6WY0eIRvQx-xSuYs2iwxMg:31:3935

Here is the fix for that problem.

Hello,

I’ve added below code to end of my utils.php file under include/. But when I save custom entry point link to website tab under Add Dashlets. I am getting same error - Incorrect website location is specified.

What I am missing here? Do I have to repair from admin panel or delete something form cache folder?

From line 1620

/**
 * @param $endpoint
 * @return bool
 */
function isSelfRequest($endpoint) : bool {
    $domain = 'localhost';
    if (isset($_SERVER["HTTP_HOST"])) {
        $domain = $_SERVER["HTTP_HOST"];
    }

    $siteUrl = SugarConfig::getInstance()->get('site_url');
    if (empty($siteUrl)){
        $siteUrl = '';
    }
     // Get the list of valid custom entry points
     $customEntryPoints = getCustomEntryPoints();
     // Check if the endpoint matches a URL of the form "$siteURL/?entryPoint={entry_point_name}"
     $entryPointPattern = "/^" . preg_quote($siteUrl, '/') . "\/\?entryPoint=(" . implode('|', $customEntryPoints) . ")$/i";
     if (preg_match($entryPointPattern, $endpoint)) {
         return false; // It matches a valid custom entry point URL
     }
     // Check if the endpoint contains the domain or site URL
    return stripos($endpoint, $domain) !== false || stripos($endpoint, $siteUrl) !== false;
}


function getCustomEntryPoints() {
    $customEntryPoints = [];
    // Specify the path to the entry_point_registry.ext.php file
    $entryPointRegistryPath = 'custom/application/Ext/EntryPointRegistry/entry_point_registry.ext.php';
    if (file_exists($entryPointRegistryPath)) {
        // Include the file
        include($entryPointRegistryPath);
        // Check if $entry_point_registry is an array
        if (isset($entry_point_registry) && is_array($entry_point_registry)) {
            // Iterate through each entry point definition
            foreach ($entry_point_registry as $entryPointName => $entryPointData) {
                // Add the entry point name to the custom entry points list
                $customEntryPoints[] = $entryPointName;
            }
        }
    }
    return $customEntryPoints;
}

Did you do a repair and rebuild? If that does not work try rebuild all the JS stuff. Also check file permissions of the new files you created. It does work, I’ve tested on a few different installations and others have reached out to me saying it worked for them.

I tried it. So, when I click on pencil icon :pencil2: on newly added dashlet. I can see Website Location field is blank.

image

Also, I have below error in the browser’s console:

MySugar.js?v=6WY0eIRvQx-xSuYs2iwxMg:203 Uncaught ReferenceError: newTop is not defined
    at Object.fillInConfigureDiv (MySugar.js?v=6WY0eIRvQx-xSuYs2iwxMg:203:24)
    at Object.handleTransactionResponse (sugar_grp1_yui.js?v=6WY0eIRvQx-xSuYs2iwxMg:31:4422)
    at sugar_grp1_yui.js?v=6WY0eIRvQx-xSuYs2iwxMg:31:3935

I think it is not able to save that web url. What’s missing?

p.s. - I have http local host url for that sankey chart

I think you’re going to want to confirm your hostname in your config. I’m thinking the localhost configuration you have setup is the problem.

Are you talking about the below field:

‘site_url’ => ‘http://example.com/suitecrm’,

yes, it has to match the actual URL you are hosting locally or this won’t work because it checks this hostname against the url of the link you are trying to add.

Maybe I’m not understanding fully, are BOTH your suitecrm install AND the sandkey chart file locally on your PC? Or is suitecrm hosted on the web and you’re trying to use a localhost url to embed?

suitecrm is hosted on the local server and I am trying to use a localhost url to embed

Then they all must match. the hostname must match the URL of the iframe you are trying to insert.

okay, I am trying to make it work. I feel like that I am so close. Just there is tiny mistake.

I am using the below URL on the browser and it is showing me a chart. But this same URL giving error when I added to Dashlet Web tab.

http://IPADDRESS/suitecrm/index.php?entryPoint=SankeyChart

I think it has to be https://

It is not working. I think that I have some another issue. If I find a solution, I’ll post here.