<!-- 
RSS generated by JIRA (8.13.3#813003-sha1:22ebedbb75c99b147c66f14e031dd8a2d214753a) at Sat Feb 10 07:17:17 CET 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>Jira</title>
    <link>https://jira.astppbilling.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>8.13.3</version>
        <build-number>813003</build-number>
        <build-date>14-01-2021</build-date>
    </build-info>


<item>
            <title>[ASTPPCOM-455] Dashboard call count and pie chart</title>
                <link>https://jira.astppbilling.org/browse/ASTPPCOM-455</link>
                <project id="10608" key="ASTPPCOM">ASTPP Community</project>
                    <description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;I have picked up, what I think is an issue in 3.6 on the dashboard where the call count (Answered, failed) etc is counting the provider calls as well as customers / resellers. This gives an inaccurate count of calls and in a way it is a duplication. The provider and customers / reseller count should be separated.&lt;/p&gt;

&lt;p&gt;I have modified the code in /astpp/application/modules/dashboard/model/dashboard_model.php to exclude provider calls on the call count. See code below:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
function get_call_statistics($table, $parent_id, $start_date = &lt;span class=&quot;code-quote&quot;&gt;&apos;&apos;, $end_date = &apos;&lt;/span&gt;&apos;, $group_flag = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;select ( &quot;count(uniqueid) as sum,
                           count(CASE WHEN billseconds &amp;gt; 0 THEN 1 END) as answered,
                           MAX(billseconds) AS mcd,
                           SUM(billseconds) AS duration,
                           count(CASE WHEN disposition NOT IN (&lt;span class=&quot;code-quote&quot;&gt;&apos;NORMAL_CLEARING&apos;&lt;/span&gt;,&lt;span class=&quot;code-quote&quot;&gt;&apos;SUCCESS&apos;&lt;/span&gt;,&lt;span class=&quot;code-quote&quot;&gt;&apos;NORMAL_CLEARING [16]&apos;&lt;/span&gt;) THEN 1 END) as failed,
                           SUM(CASE WHEN calltype !=&lt;span class=&quot;code-quote&quot;&gt;&apos;free&apos;&lt;/span&gt; THEN billseconds ELSE 0 END) as billable,
                           sum(debit-cost) as profit,
                           sum(debit) as debit,
                           sum(cost) as cost,
                           SUM(CASE WHEN billseconds &amp;gt; 0 THEN 1 ELSE 0 END) as completed,
                           DAY(callstart) as day&quot;, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; );
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;where ( &lt;span class=&quot;code-quote&quot;&gt;&apos;callstart &amp;gt;=&apos;&lt;/span&gt;, $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 00:00:00&quot;&lt;/span&gt; );
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;where ( &lt;span class=&quot;code-quote&quot;&gt;&apos;callstart &amp;lt;=&apos;&lt;/span&gt;, $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 23:59:59&quot;&lt;/span&gt; );
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;where ( &lt;span class=&quot;code-quote&quot;&gt;&apos;reseller_id&apos;&lt;/span&gt;, $parent_id );
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($table == cdrs)
                        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;where ( &lt;span class=&quot;code-quote&quot;&gt;&apos;type !=&apos;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;3&quot;&lt;/span&gt; );
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($group_flag)
                        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;group_by ( &lt;span class=&quot;code-quote&quot;&gt;&quot;DAY(callstart)&quot;&lt;/span&gt; );
                $result = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;get ( $table );
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $result;
        }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I have added the following to exclude providers:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($table == cdrs)
                        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;where ( &lt;span class=&quot;code-quote&quot;&gt;&apos;type !=&apos;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;3&quot;&lt;/span&gt; );
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For the pie chart I add the same in the where clause but not sure how to use it in the parameters. I add &lt;tt&gt;AND type != &apos;3&apos;&lt;/tt&gt; after the $where parameter in the SELECT query.&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
function get_customer_maximum_callminutes($start_date, $end_date) {
                $start_date = $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 00:00:00&quot;&lt;/span&gt;;
                $end_date = $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 23:59:59&quot;&lt;/span&gt;;
                $accountinfo = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;accountinfo&apos;&lt;/span&gt; );
                $parent_id = ($accountinfo [&lt;span class=&quot;code-quote&quot;&gt;&apos;type&apos;&lt;/span&gt;] == 1) ? $accountinfo [&lt;span class=&quot;code-quote&quot;&gt;&apos;id&apos;&lt;/span&gt;] : 0;
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;userlevel_logintype&apos;&lt;/span&gt; ) != 0 &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;userlevel_logintype&apos;&lt;/span&gt; ) != 3) {
                        $where = &lt;span class=&quot;code-quote&quot;&gt;&quot;reseller_id =&lt;span class=&quot;code-quote&quot;&gt;&apos;$parent_id&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                        $where = &lt;span class=&quot;code-quote&quot;&gt;&quot;accountid =&lt;span class=&quot;code-quote&quot;&gt;&apos;$parent_id&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                }
                $where = $where . &lt;span class=&quot;code-quote&quot;&gt;&quot; AND callstart &amp;gt;= &lt;span class=&quot;code-quote&quot;&gt;&apos;&quot;&lt;/span&gt; . $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&lt;/span&gt; AND  callstart &amp;lt;= &lt;span class=&quot;code-quote&quot;&gt;&apos;&quot;&lt;/span&gt; . $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                $select_query = &quot;(SELECT sum( billseconds ) AS billseconds,accountid FROM (cdrs) WHERE $where AND type != &lt;span class=&quot;code-quote&quot;&gt;&apos;3&apos;&lt;/span&gt; group by accountid order$
                        union
                        (SELECT sum( billseconds ) AS billseconds,accountid FROM (reseller_cdrs) WHERE $where 
                        group by accountid order by sum(billseconds) desc limit 10 ) ORDER BY billseconds DESC LIMIT 10 &quot;;
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;query ( $select_query );
        }
        function get_customer_maximum_callcount($start_date, $end_date) {
                $start_date = $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 00:00:00&quot;&lt;/span&gt;;
                $end_date = $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 23:59:59&quot;&lt;/span&gt;;
                $accountinfo = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;accountinfo&apos;&lt;/span&gt; );
                $parent_id = ($accountinfo [&lt;span class=&quot;code-quote&quot;&gt;&apos;type&apos;&lt;/span&gt;] == 1) ? $accountinfo [&lt;span class=&quot;code-quote&quot;&gt;&apos;id&apos;&lt;/span&gt;] : 0;
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;userlevel_logintype&apos;&lt;/span&gt; ) != 0 &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;userlevel_logintype&apos;&lt;/span&gt; ) != 3) {
                        $where = &lt;span class=&quot;code-quote&quot;&gt;&quot;reseller_id =&lt;span class=&quot;code-quote&quot;&gt;&apos;$parent_id&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                        $where = &lt;span class=&quot;code-quote&quot;&gt;&quot;accountid =&lt;span class=&quot;code-quote&quot;&gt;&apos;$parent_id&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                }
                $where = $where . &lt;span class=&quot;code-quote&quot;&gt;&quot; AND callstart &amp;gt;= &lt;span class=&quot;code-quote&quot;&gt;&apos;&quot;&lt;/span&gt; . $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&lt;/span&gt; AND  callstart &amp;lt;= &lt;span class=&quot;code-quote&quot;&gt;&apos;&quot;&lt;/span&gt; . $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                $select_query = &quot;(SELECT count(uniqueid) as call_count, `accountid` FROM (`cdrs`) WHERE $where AND type != &lt;span class=&quot;code-quote&quot;&gt;&apos;3&apos;&lt;/span&gt; GROUP BY `accountid` OR$
          UNION
          (SELECT count(uniqueid) as call_count,accountid FROM (reseller_cdrs) WHERE $where GROUP BY `accountid` ORDER BY `call_count` desc LIMIT 10)
          ORDER BY call_count desc limit 10&quot;;
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;query ( $select_query );
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
        <key id="12275">ASTPPCOM-455</key>
            <summary>Dashboard call count and pie chart</summary>
                <type id="10201" iconUrl="https://jira.astppbilling.org/secure/viewavatar?size=xsmall&amp;avatarId=10700&amp;avatarType=issuetype">New Feature</type>
                                                <status id="10001" iconUrl="https://jira.astppbilling.org/images/icons/status_generic.gif" description="">Done</status>
                    <statusCategory id="3" key="done" colorName="green"/>
                                    <resolution id="10000">Done</resolution>
                                        <assignee username="samir.doshi">Samir Doshi</assignee>
                                    <reporter username="fozzygo4">fozzygo4</reporter>
                        <labels>
                            <label>bug_confirmed</label>
                    </labels>
                <created>Wed, 11 Jul 2018 15:07:42 +0530</created>
                <updated>Sun, 27 Oct 2019 15:49:56 +0530</updated>
                            <resolved>Thu, 18 Oct 2018 13:40:41 +0530</resolved>
                                                                        <due></due>
                            <votes>0</votes>
                                    <watches>0</watches>
                                                                <comments>
                            <comment id="13416" author="smrdoshi" created="Thu, 12 Jul 2018 12:33:03 +0530"  >&lt;p&gt;Hi @FozzyGo4 &lt;/p&gt;

&lt;p&gt;That&apos;s not correct. You will get type = 3 in cdrs table when any provider has tried to make calls or send you calls. &lt;/p&gt;

&lt;p&gt;Basically whoever making calls (Leg A), we capture that account type and insert into cdrs table as we consider they are the originator of the &lt;/p&gt;

&lt;p&gt;If you will put type != 3 then it will start skipping of your interconnect provider cdrs as well DID cdrs, and that will make report inappropriate. &lt;/p&gt;</comment>
                            <comment id="13417" author="fozzygo4" created="Thu, 12 Jul 2018 16:08:08 +0530"  >&lt;p&gt;We are both half right. In the CDR table there are double entries for an inbound call. The same call with the same date time stamp has two records of type = 3. One is a DID and the other is a Local with disposition of STANDARD.&lt;/p&gt;

&lt;p&gt;The dashboard currently counts 2 &lt;tt&gt;count(uniqueid) as sum&lt;/tt&gt; calls but it is actually only 1 call. The query needs to only count the DID record I feel but correct me please if I&apos;m wrong.&lt;/p&gt;</comment>
                            <comment id="13418" author="smrdoshi" created="Mon, 16 Jul 2018 19:17:23 +0530"  >&lt;p&gt;For DID calls, yes we are doing two entries of CDRs. &lt;br/&gt;
1st CDR with Provider ID (STANDARD)&lt;br/&gt;
2nd CDR with Customer ID (DID)&lt;/p&gt;

&lt;p&gt;The reason for not merging both CDRs in dashboard is, both call records are associated with a different account and both records have billable seconds (However for providers you have the option to make chargeable to make it free using INB_FREE) and their charges.&lt;/p&gt;

&lt;p&gt;If we will apply unique constraint while showing in dashboard, then it will start showing incorrect counts as  it may possible someone has charged provider based on allocated tariff plan and it will be skipped. &lt;/p&gt;</comment>
                            <comment id="13419" author="fozzygo4" created="Tue, 17 Jul 2018 00:46:04 +0530"  >&lt;p&gt;Im not saying &quot;do not capture two records&quot;. Im saying the call count is duplicated and is incorrect. Let me try and explain.&lt;br/&gt;
Caller calls via provider and this call is routed to ASTPP. ASTPP received the call and if there is a DID for this call, should route to the customer / reseller etc. Im sure you will agree that this is 1 call for x amount of seconds. Lets say it is for 60 seconds (1 minute). &lt;/p&gt;

&lt;p&gt;Regardless of how many records are in the CDR and if the call is free or charged for, it is still 1 call for 60 seconds.&lt;/p&gt;

&lt;p&gt;The dashboard graph and pie graph is currently counting records so it will see 1st CDR with Provider ID (STANDARD) and 2nd CDR with Customer ID (DID) as 2 calls and the minute count is now 120 seconds (2 minutes).&lt;/p&gt;

&lt;p&gt;This means all inbound calls are counted twice and the dashboard is not accurate. &lt;/p&gt;

&lt;p&gt;It should only count 1 of these CDR records on the dashboard. &lt;/p&gt;
</comment>
                            <comment id="13420" author="smrdoshi" created="Thu, 19 Jul 2018 13:10:08 +0530"  >&lt;p&gt;I agree with your point. Dashboard logic requires a change to display 1&lt;br/&gt;
record for such cases.&lt;/p&gt;

&lt;p&gt;We will work out on that.&lt;/p&gt;


&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;image: Mailtrack&amp;#93;&lt;/span&gt;&lt;br/&gt;
&amp;lt;&lt;a href=&quot;https://mailtrack.io?utm_source=gmail&amp;amp;utm_medium=signature&amp;amp;utm_campaign=signaturevirality6&amp;amp;&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://mailtrack.io?utm_source=gmail&amp;amp;utm_medium=signature&amp;amp;utm_campaign=signaturevirality6&amp;amp;&lt;/a&gt;&amp;gt;&lt;br/&gt;
Sender&lt;br/&gt;
notified by&lt;br/&gt;
Mailtrack&lt;br/&gt;
&amp;lt;&lt;a href=&quot;https://mailtrack.io?utm_source=gmail&amp;amp;utm_medium=signature&amp;amp;utm_campaign=signaturevirality6&amp;amp;&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://mailtrack.io?utm_source=gmail&amp;amp;utm_medium=signature&amp;amp;utm_campaign=signaturevirality6&amp;amp;&lt;/a&gt;&amp;gt;&lt;br/&gt;
07/19/18,&lt;br/&gt;
1:07:07 PM&lt;/p&gt;

&lt;h2&gt;&lt;a name=&quot;BestRegards&quot;&gt;&lt;/a&gt;Best Regards&lt;/h2&gt;
&lt;p&gt;Samir Doshi&lt;br/&gt;
&lt;em&gt;iNextrix Technologie&lt;/em&gt;&lt;em&gt;s Pvt. Ltd&lt;/em&gt;.&lt;br/&gt;
&lt;a href=&quot;http://www.inextrix.com&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.inextrix.com&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;&lt;em&gt;Disclaimer:&lt;/em&gt;&lt;br/&gt;
The information contained in this communication is confidential and may be&lt;br/&gt;
legally privileged. It is intended solely for the use of the individual or&lt;br/&gt;
entity to whom it is addressed and others authorized to receive it. If you&lt;br/&gt;
are not the intended recipient you are hereby notified that any disclosure,&lt;br/&gt;
copying, distribution or taking action in reliance on the contents of this&lt;br/&gt;
information is strictly prohibited and may be unlawful. Please notify the&lt;br/&gt;
sender immediately and destroy all copies of this message and any&lt;br/&gt;
attachments contained in it.&lt;/p&gt;

&lt;p&gt;On Tue, Jul 17, 2018 at 12:46 AM, Stephen Forster &amp;lt;notifications@github.com&amp;gt;&lt;br/&gt;
wrote:&lt;/p&gt;

&lt;p&gt;&amp;gt; Im not saying &quot;do not capture two records&quot;. Im saying the call count is&lt;br/&gt;
&amp;gt; duplicated and is incorrect. Let me try and explain.&lt;br/&gt;
&amp;gt; Caller calls via provider and this call is routed to ASTPP. ASTPP received&lt;br/&gt;
&amp;gt; the call and if there is a DID for this call, should route to the customer&lt;br/&gt;
&amp;gt; / reseller etc. Im sure you will agree that this is 1 call for x amount of&lt;br/&gt;
&amp;gt; seconds. Lets say it is for 60 seconds (1 minute).&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; Regardless of how many records are in the CDR and if the call is free or&lt;br/&gt;
&amp;gt; charged for, it is still 1 call for 60 seconds.&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; The dashboard graph and pie graph is currently counting records so it will&lt;br/&gt;
&amp;gt; see 1st CDR with Provider ID (STANDARD) and 2nd CDR with Customer ID (DID)&lt;br/&gt;
&amp;gt; as 2 calls and the minute count is now 120 seconds (2 minutes).&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; This means all inbound calls are counted twice and the dashboard is not&lt;br/&gt;
&amp;gt; accurate.&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; It should only count 1 of these CDR records on the dashboard.&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; &#8212;&lt;br/&gt;
&amp;gt; You are receiving this because you were assigned.&lt;br/&gt;
&amp;gt; Reply to this email directly, view it on GitHub&lt;br/&gt;
&amp;gt; &amp;lt;&lt;a href=&quot;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-405351051&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-405351051&lt;/a&gt;&amp;gt;, or mute&lt;br/&gt;
&amp;gt; the thread&lt;br/&gt;
&amp;gt; &amp;lt;&lt;a href=&quot;https://github.com/notifications/unsubscribe-auth/AA6gcefT4x3vNJoARpfKNEqmvUPaQibmks5uHOZ1gaJpZM4VKz0O&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/notifications/unsubscribe-auth/AA6gcefT4x3vNJoARpfKNEqmvUPaQibmks5uHOZ1gaJpZM4VKz0O&lt;/a&gt;&amp;gt;&lt;br/&gt;
&amp;gt; .&lt;br/&gt;
&amp;gt;&lt;/p&gt;</comment>
                            <comment id="13421" author="smrdoshi" created="Tue, 24 Jul 2018 11:07:29 +0530"  >&lt;p&gt;Hi @FozzyGo4 &lt;/p&gt;

&lt;p&gt;We changed code to make dashboard graph working. Here is the code, &lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
function get_call_statistics($table, $parent_id, $start_date = &lt;span class=&quot;code-quote&quot;&gt;&apos;&apos;, $end_date = &apos;&lt;/span&gt;&apos;, $group_flag = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;) {
		$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;select ( &quot;count(DISTINCT substr(uniqueid,1,36)) as sum,
                           count(CASE WHEN (billseconds &amp;gt; 0 and substr(uniqueid,37,3)!=&lt;span class=&quot;code-quote&quot;&gt;&apos;DID&apos;&lt;/span&gt;) THEN 1 END) as answered,
                           MAX(billseconds) AS mcd,
                           SUM(CASE WHEN (billseconds &amp;gt; 0 and substr(uniqueid,37,3)!=&lt;span class=&quot;code-quote&quot;&gt;&apos;DID&apos;&lt;/span&gt;) THEN 1 END) AS duration,
                           count(CASE WHEN (disposition NOT IN (&lt;span class=&quot;code-quote&quot;&gt;&apos;NORMAL_CLEARING&apos;&lt;/span&gt;,&lt;span class=&quot;code-quote&quot;&gt;&apos;SUCCESS&apos;&lt;/span&gt;,&lt;span class=&quot;code-quote&quot;&gt;&apos;NORMAL_CLEARING [16]&apos;&lt;/span&gt;) and substr(uniqueid,37,3)!=&lt;span class=&quot;code-quote&quot;&gt;&apos;DID&apos;&lt;/span&gt;) THEN 1 END) as failed,
                           SUM(CASE WHEN (calltype !=&lt;span class=&quot;code-quote&quot;&gt;&apos;free&apos;&lt;/span&gt; and substr(uniqueid,37,3)!=&lt;span class=&quot;code-quote&quot;&gt;&apos;DID&apos;&lt;/span&gt;) THEN billseconds ELSE 0 END) as billable,
                           sum(debit-cost) as profit,
                           sum(debit) as debit,
                           sum(cost) as cost,
                           SUM(CASE WHEN (billseconds &amp;gt; 0 and substr(uniqueid,37,3)!=&lt;span class=&quot;code-quote&quot;&gt;&apos;DID&apos;&lt;/span&gt;) THEN 1 ELSE 0 END) as completed,
                           DAY(callstart) as day&quot;, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; );
		$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;where ( &lt;span class=&quot;code-quote&quot;&gt;&apos;callstart &amp;gt;=&apos;&lt;/span&gt;, $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 00:00:00&quot;&lt;/span&gt; );
		$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;where ( &lt;span class=&quot;code-quote&quot;&gt;&apos;callstart &amp;lt;=&apos;&lt;/span&gt;, $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 23:59:59&quot;&lt;/span&gt; );
		$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;where ( &lt;span class=&quot;code-quote&quot;&gt;&apos;reseller_id&apos;&lt;/span&gt;, $parent_id );
		&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($group_flag)
			$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;group_by ( &lt;span class=&quot;code-quote&quot;&gt;&quot;DAY(callstart)&quot;&lt;/span&gt; );
		$result = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;get ( $table );
		&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $result;
	}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Please replace this code in dashboard_model.php and check. If this works well then we will workout on other related reports. &lt;/p&gt;</comment>
                            <comment id="13422" author="fozzygo4" created="Tue, 24 Jul 2018 11:49:54 +0530"  >&lt;p&gt;I see, so you are excluding all calls with disposition of &quot;DID&quot; so the query is counting the actual calls. Good idea. I will make the changes and check from my side and give feedback.&lt;/p&gt;</comment>
                            <comment id="13423" author="smrdoshi" created="Wed, 25 Jul 2018 10:56:40 +0530"  >&lt;p&gt;Alright. Waiting for your feedback &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.astppbilling.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;


&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;image: Mailtrack&amp;#93;&lt;/span&gt;&lt;br/&gt;
&amp;lt;&lt;a href=&quot;https://mailtrack.io?utm_source=gmail&amp;amp;utm_medium=signature&amp;amp;utm_campaign=signaturevirality6&amp;amp;&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://mailtrack.io?utm_source=gmail&amp;amp;utm_medium=signature&amp;amp;utm_campaign=signaturevirality6&amp;amp;&lt;/a&gt;&amp;gt;&lt;br/&gt;
Sender&lt;br/&gt;
notified by&lt;br/&gt;
Mailtrack&lt;br/&gt;
&amp;lt;&lt;a href=&quot;https://mailtrack.io?utm_source=gmail&amp;amp;utm_medium=signature&amp;amp;utm_campaign=signaturevirality6&amp;amp;&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://mailtrack.io?utm_source=gmail&amp;amp;utm_medium=signature&amp;amp;utm_campaign=signaturevirality6&amp;amp;&lt;/a&gt;&amp;gt;&lt;br/&gt;
07/25/18,&lt;br/&gt;
10:55:26 AM&lt;/p&gt;

&lt;h2&gt;&lt;a name=&quot;BestRegards&quot;&gt;&lt;/a&gt;Best Regards&lt;/h2&gt;
&lt;p&gt;Samir Doshi&lt;br/&gt;
&lt;em&gt;iNextrix Technologie&lt;/em&gt;&lt;em&gt;s Pvt. Ltd&lt;/em&gt;.&lt;br/&gt;
&lt;a href=&quot;http://www.inextrix.com&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.inextrix.com&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;&lt;em&gt;Disclaimer:&lt;/em&gt;&lt;br/&gt;
The information contained in this communication is confidential and may be&lt;br/&gt;
legally privileged. It is intended solely for the use of the individual or&lt;br/&gt;
entity to whom it is addressed and others authorized to receive it. If you&lt;br/&gt;
are not the intended recipient you are hereby notified that any disclosure,&lt;br/&gt;
copying, distribution or taking action in reliance on the contents of this&lt;br/&gt;
information is strictly prohibited and may be unlawful. Please notify the&lt;br/&gt;
sender immediately and destroy all copies of this message and any&lt;br/&gt;
attachments contained in it.&lt;/p&gt;

&lt;p&gt;On Tue, Jul 24, 2018 at 11:49 AM, Stephen Forster &amp;lt;notifications@github.com&amp;gt;&lt;br/&gt;
wrote:&lt;/p&gt;

&lt;p&gt;&amp;gt; I see, so you are excluding all calls with disposition of &quot;DID&quot; so the&lt;br/&gt;
&amp;gt; query is counting the actual calls. Good idea. I will make the changes and&lt;br/&gt;
&amp;gt; check from my side and give feedback.&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; &#8212;&lt;br/&gt;
&amp;gt; You are receiving this because you were assigned.&lt;br/&gt;
&amp;gt; Reply to this email directly, view it on GitHub&lt;br/&gt;
&amp;gt; &amp;lt;&lt;a href=&quot;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-407294180&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-407294180&lt;/a&gt;&amp;gt;, or mute&lt;br/&gt;
&amp;gt; the thread&lt;br/&gt;
&amp;gt; &amp;lt;&lt;a href=&quot;https://github.com/notifications/unsubscribe-auth/AA6gcTiiX5tWxb1W1_rz_6y-9t3Rct7Bks5uJryKgaJpZM4VKz0O&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/notifications/unsubscribe-auth/AA6gcTiiX5tWxb1W1_rz_6y-9t3Rct7Bks5uJryKgaJpZM4VKz0O&lt;/a&gt;&amp;gt;&lt;br/&gt;
&amp;gt; .&lt;br/&gt;
&amp;gt;&lt;/p&gt;</comment>
                            <comment id="13424" author="smrdoshi" created="Sat, 8 Sep 2018 13:01:29 +0530"  >&lt;p&gt;Hi @FozzyGo4 &lt;/p&gt;

&lt;p&gt;Did you check? &lt;/p&gt;</comment>
                            <comment id="13425" author="fozzygo4" created="Sat, 8 Sep 2018 13:52:58 +0530"  >&lt;p&gt;Hi, yes sorry I did check and it works as expected thank you.&lt;/p&gt;

&lt;p&gt;Sent from my iPhone&lt;/p&gt;

&lt;p&gt;On 08 Sep 2018, at 9:31 AM, Samir Doshi &amp;lt;notifications@github.com&amp;lt;&lt;span class=&quot;nobr&quot;&gt;&lt;a href=&quot;mailto:notifications@github.com&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;notifications@github.com&lt;sup&gt;&lt;img class=&quot;rendericon&quot; src=&quot;https://jira.astppbilling.org/images/icons/mail_small.gif&quot; height=&quot;12&quot; width=&quot;13&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/sup&gt;&lt;/a&gt;&lt;/span&gt;&amp;gt;&amp;gt; wrote:&lt;/p&gt;


&lt;p&gt;Hi @FozzyGo4&amp;lt;&lt;a href=&quot;https://github.com/FozzyGo4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/FozzyGo4&lt;/a&gt;&amp;gt;&lt;/p&gt;

&lt;p&gt;Did you check?&lt;/p&gt;

&lt;p&gt;-&lt;br/&gt;
You are receiving this because you were mentioned.&lt;br/&gt;
Reply to this email directly, view it on GitHub&amp;lt;&lt;a href=&quot;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-419620293&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-419620293&lt;/a&gt;&amp;gt;, or mute the thread&amp;lt;&lt;a href=&quot;https://github.com/notifications/unsubscribe-auth/AT8i_6kxeH0rjivcV2iW_v5ITbMCa2irks5uY3JSgaJpZM4VKz0O&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/notifications/unsubscribe-auth/AT8i_6kxeH0rjivcV2iW_v5ITbMCa2irks5uY3JSgaJpZM4VKz0O&lt;/a&gt;&amp;gt;.&lt;/p&gt;</comment>
                            <comment id="13426" author="smrdoshi" created="Sat, 8 Sep 2018 22:58:18 +0530"  >&lt;p&gt;Alright. Thanks for the update.&lt;/p&gt;

&lt;p&gt;On Sat, Sep 8, 2018, 1:52 PM Stephen Forster &amp;lt;notifications@github.com&amp;gt;&lt;br/&gt;
wrote:&lt;/p&gt;

&lt;p&gt;&amp;gt; Hi, yes sorry I did check and it works as expected thank you.&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; Sent from my iPhone&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; On 08 Sep 2018, at 9:31 AM, Samir Doshi &amp;lt;notifications@github.com&amp;lt;mailto:&lt;br/&gt;
&amp;gt; notifications@github.com&amp;gt;&amp;gt; wrote:&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; Hi @FozzyGo4&amp;lt;&lt;a href=&quot;https://github.com/FozzyGo4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/FozzyGo4&lt;/a&gt;&amp;gt;&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; Did you check?&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; -&lt;br/&gt;
&amp;gt; You are receiving this because you were mentioned.&lt;br/&gt;
&amp;gt; Reply to this email directly, view it on GitHub&amp;lt;&lt;br/&gt;
&amp;gt; &lt;a href=&quot;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-419620293&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-419620293&lt;/a&gt;&amp;gt;, or&lt;br/&gt;
&amp;gt; mute the thread&amp;lt;&lt;br/&gt;
&amp;gt; &lt;a href=&quot;https://github.com/notifications/unsubscribe-auth/AT8i_6kxeH0rjivcV2iW_v5ITbMCa2irks5uY3JSgaJpZM4VKz0O&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/notifications/unsubscribe-auth/AT8i_6kxeH0rjivcV2iW_v5ITbMCa2irks5uY3JSgaJpZM4VKz0O&lt;/a&gt;&lt;br/&gt;
&amp;gt; &amp;gt;.&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; &#8212;&lt;br/&gt;
&amp;gt; You are receiving this because you were assigned.&lt;br/&gt;
&amp;gt; Reply to this email directly, view it on GitHub&lt;br/&gt;
&amp;gt; &amp;lt;&lt;a href=&quot;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-419623121&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-419623121&lt;/a&gt;&amp;gt;, or mute&lt;br/&gt;
&amp;gt; the thread&lt;br/&gt;
&amp;gt; &amp;lt;&lt;a href=&quot;https://github.com/notifications/unsubscribe-auth/AA6gcVuUIGkKIZD4HBrmpHE9QbSd1l01ks5uY35jgaJpZM4VKz0O&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/notifications/unsubscribe-auth/AA6gcVuUIGkKIZD4HBrmpHE9QbSd1l01ks5uY35jgaJpZM4VKz0O&lt;/a&gt;&amp;gt;&lt;br/&gt;
&amp;gt; .&lt;br/&gt;
&amp;gt;&lt;/p&gt;</comment>
                            <comment id="13427" author="fozzygo4" created="Sun, 14 Oct 2018 00:45:58 +0530"  >&lt;p&gt;Hi Samir,&lt;/p&gt;

&lt;p&gt;Further to the fixes with the pie charts, I have optimised the speed of the query to MySQL by using temporary tables in the PHP code. I noticed that the query was putting a lot of stress on the MySQL DB. This is mostly because of MySQL and &quot;order by descending&quot; having to work with millions of records. By using a query to get only the records required into a temporary table and then running the charts query on the temp data, the query is much faster and less stress on the recourses of the server.&lt;/p&gt;

&lt;p&gt;Shall I contribute the code here?&lt;/p&gt;</comment>
                            <comment id="13428" author="smrdoshi" created="Tue, 16 Oct 2018 10:37:39 +0530"  >&lt;p&gt;Yes please.&lt;/p&gt;

&lt;p&gt;On Sun, Oct 14, 2018, 12:45 AM Stephen Forster &amp;lt;notifications@github.com&amp;gt;&lt;br/&gt;
wrote:&lt;/p&gt;

&lt;p&gt;&amp;gt; Hi Samir,&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; Further to the fixes with the pie charts, I have optimised the speed of&lt;br/&gt;
&amp;gt; the query to MySQL by using temporary tables in the PHP code. I noticed&lt;br/&gt;
&amp;gt; that the query was putting a lot of stress on the MySQL DB. This is mostly&lt;br/&gt;
&amp;gt; because of MySQL and &quot;order by descending&quot; having to work with millions of&lt;br/&gt;
&amp;gt; records. By using a query to get only the records required into a temporary&lt;br/&gt;
&amp;gt; table and then running the charts query on the temp data, the query is much&lt;br/&gt;
&amp;gt; faster and less stress on the recourses of the server.&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; Shall I contribute the code here?&lt;br/&gt;
&amp;gt;&lt;br/&gt;
&amp;gt; &#8212;&lt;br/&gt;
&amp;gt; You are receiving this because you were assigned.&lt;br/&gt;
&amp;gt; Reply to this email directly, view it on GitHub&lt;br/&gt;
&amp;gt; &amp;lt;&lt;a href=&quot;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-429567963&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/iNextrix/ASTPP/issues/455#issuecomment-429567963&lt;/a&gt;&amp;gt;, or mute&lt;br/&gt;
&amp;gt; the thread&lt;br/&gt;
&amp;gt; &amp;lt;&lt;a href=&quot;https://github.com/notifications/unsubscribe-auth/AA6gcdWV7gKsNK1oDM_5spPsLzb-M7w7ks5ukjvvgaJpZM4VKz0O&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/notifications/unsubscribe-auth/AA6gcdWV7gKsNK1oDM_5spPsLzb-M7w7ks5ukjvvgaJpZM4VKz0O&lt;/a&gt;&amp;gt;&lt;br/&gt;
&amp;gt; .&lt;br/&gt;
&amp;gt;&lt;/p&gt;</comment>
                            <comment id="13429" author="fozzygo4" created="Thu, 18 Oct 2018 13:40:41 +0530"  >&lt;p&gt;Herewith the modified code.&lt;/p&gt;

&lt;p&gt;Top 10 customer minutes function&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
function get_customer_maximum_callminutes($start_date, $end_date) {
                $start_date = $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 00:00:00&quot;&lt;/span&gt;;
                $end_date = $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 23:59:59&quot;&lt;/span&gt;;
                $accountinfo = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;accountinfo&apos;&lt;/span&gt; );
                $parent_id = ($accountinfo [&lt;span class=&quot;code-quote&quot;&gt;&apos;type&apos;&lt;/span&gt;] == 1) ? $accountinfo [&lt;span class=&quot;code-quote&quot;&gt;&apos;id&apos;&lt;/span&gt;] : 0;
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;userlevel_logintype&apos;&lt;/span&gt; ) != 0 &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;userlevel_logintype&apos;&lt;/span&gt; ) != 3) {
                        $where = &lt;span class=&quot;code-quote&quot;&gt;&quot;reseller_id =&lt;span class=&quot;code-quote&quot;&gt;&apos;$parent_id&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                        $where = &lt;span class=&quot;code-quote&quot;&gt;&quot;accountid =&lt;span class=&quot;code-quote&quot;&gt;&apos;$parent_id&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                }
                $where = $where . &lt;span class=&quot;code-quote&quot;&gt;&quot; AND callstart &amp;gt;= &lt;span class=&quot;code-quote&quot;&gt;&apos;&quot;&lt;/span&gt; . $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&lt;/span&gt; AND  callstart &amp;lt;= &lt;span class=&quot;code-quote&quot;&gt;&apos;&quot;&lt;/span&gt; . $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&lt;/span&gt;&quot;&lt;/span&gt;;

                $billingsectemp_query = &quot;CREATE TEMPORARY TABLE IF NOT EXISTS totalbillingsec AS (SELECT billseconds,accountid FROM (cdrs) WHERE $where and type != &lt;span class=&quot;code-quote&quot;&gt;&apos;3&apos;&lt;/span&gt;)
                UNION
                (SELECT billseconds,accountid FROM (cdrs) WHERE $where and type = &lt;span class=&quot;code-quote&quot;&gt;&apos;3&apos;&lt;/span&gt; AND disposition = &lt;span class=&quot;code-quote&quot;&gt;&apos;DID&apos;&lt;/span&gt;)
                UNION
                (SELECT billseconds,accountid FROM (reseller_cdrs) WHERE $where ) &quot;;
                $select_query = &lt;span class=&quot;code-quote&quot;&gt;&quot;SELECT sum( billseconds ) as billseconds, accountid from totalbillingsec group by accountid order by billseconds DESC LIMIT 10&quot;&lt;/span&gt;;
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;query ( $billingsectemp_query );
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;query ( $select_query );
        }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Top 10 customer call count function&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
function get_customer_maximum_callcount($start_date, $end_date) {
                $start_date = $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 00:00:00&quot;&lt;/span&gt;;
                $end_date = $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot; 23:59:59&quot;&lt;/span&gt;;
                $accountinfo = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;accountinfo&apos;&lt;/span&gt; );
                $parent_id = ($accountinfo [&lt;span class=&quot;code-quote&quot;&gt;&apos;type&apos;&lt;/span&gt;] == 1) ? $accountinfo [&lt;span class=&quot;code-quote&quot;&gt;&apos;id&apos;&lt;/span&gt;] : 0;
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;userlevel_logintype&apos;&lt;/span&gt; ) != 0 &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;session-&amp;gt;userdata ( &lt;span class=&quot;code-quote&quot;&gt;&apos;userlevel_logintype&apos;&lt;/span&gt; ) != 3) {
                        $where = &lt;span class=&quot;code-quote&quot;&gt;&quot;reseller_id =&lt;span class=&quot;code-quote&quot;&gt;&apos;$parent_id&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                        $where = &lt;span class=&quot;code-quote&quot;&gt;&quot;accountid =&lt;span class=&quot;code-quote&quot;&gt;&apos;$parent_id&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                }
                $where = $where . &lt;span class=&quot;code-quote&quot;&gt;&quot; AND callstart &amp;gt;= &lt;span class=&quot;code-quote&quot;&gt;&apos;&quot;&lt;/span&gt; . $start_date . &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&lt;/span&gt; AND  callstart &amp;lt;= &lt;span class=&quot;code-quote&quot;&gt;&apos;&quot;&lt;/span&gt; . $end_date . &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&lt;/span&gt;&quot;&lt;/span&gt;;
                $callcounttemp_query = &quot;CREATE TEMPORARY TABLE IF NOT EXISTS totalcalls AS (SELECT uniqueid,accountid FROM cdrs WHERE $where)
                UNION
                (SELECT uniqueid, accountid FROM reseller_cdrs WHERE $where) &quot;;
                $select_query = &lt;span class=&quot;code-quote&quot;&gt;&quot;SELECT count(DISTINCT substr(uniqueid,1,36)) as call_count, accountid FROM totalcalls GROUP BY accountid ORDER BY call_count desc LIMIT 10&quot;&lt;/span&gt;;
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;query ( $callcounttemp_query );
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;db-&amp;gt;query ( $select_query );
        }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The changes are to first get the data based on where clause into a temporary table and then run the order by, group by and and calculations on the temporary data. Shaves of many seconds and resources on my system.&lt;/p&gt;

&lt;p&gt;Im sure you could probably optimise this even further and perhaps use the same principle on other modules like reports.&lt;/p&gt;

&lt;p&gt;Regards&lt;br/&gt;
Stephen&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10000" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10703" key="com.atlassian.jira.plugin.system.customfieldtypes:textfield">
                        <customfieldname>External issue ID</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>455</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10006" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0|i00bfz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        </customfields>
    </item>
</channel>
</rss>