From 1a1edf1195490490e198fb3327ed84e0e7118cd1 Mon Sep 17 00:00:00 2001 From: demonspork Date: Thu, 18 Feb 2021 07:51:48 -0600 Subject: [PATCH 1/9] Improved Missed Call accuracy, cdr statistics, and hide duplicated CDRs from Enterprise Ring Groups Changes -------- - Improve CDR Import Logic so that missed_call column is more accurate to the "missed" status. It would previously mark unanswered outbound calls as "missed". These are their own category of call. - Don't mark the CDRs of the "legs" of an Enterprise Ring Group call as missed, only the originating_leg will be marked (one missed call per call) - We could also just "skip" importing these call legs. Simultaneous ring groups don't have these duplicated CDRs for every ringing phone. The "Skip" approach might make most of the rest of this work irrelevant. - Create `originating_leg_uuid` column in v_xml_cdr and import it into the database during CDR imports so it is available for filtering Enterprise Ring Group calls out of CDRs and reports. - Move logic that hides the agent leg of CC calls, LOSE_RACE calls, and the Enterprise Leg hiding code from xml_cdr.php into xml_cdr_inc.php into the SQL query WHERE clause so the CDR page looks more consistent. The logic is the same, but these calls are now excluded from the query result entirely instead of having to "skip" rendering them in the list on the xml_cdr.php page. - Improved CDR statistics page to use the missed_call variable instead of relying upon billsec and answer_stamp/answer_epoch. Added the same logic as the xml_cdr pages to the query so it excludes enterprise ring group call legs. - Laid the query groundwork in xml_cdr_statistics to report on Average TTA (No UI changes yet to include that statistic) Retroactive Changes --------------------- There are a few changes going back in time to bring everything in line with this better reporting accuracy: - If you want the populated the `originating_leg_uuid column` in `v_xml_cdr`, it will rely upon having the `json` column and not having deleted the data from it like I know some people do for space saving. - If you don't have the json column, you are mostly out of luck for hiding the duplicate legs of Enterprise ring group calls. It might be possible, but it isn't going to be easy. - On Newer Versions of postgres, this works: ``` UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid WHERE json->'variables'->>'originating_leg_uuid' IS NOT NULL; ``` - For some reason on postgres 9.4, I had to UPDATE every single record because I couldn't get it to allow the json syntax properly after the WHERE. This is fine, it doesn't change the end result it just means it has to run the UPDATE on every record, which will take a while ``` UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid; ``` - To remove the `missed_call = true` on all your previous outbound records so that they don't show up when you filter on missed (outbound unanswered calls can be accurately listed with TTA max 0 and direction outbound) ``` UPDATE v_xml_cdr SET missed_call = false WHERE direction = 'outbound' AND missed_call = true; ``` --- app/xml_cdr/app_config.php | 9 +++++++++ app/xml_cdr/resources/classes/xml_cdr.php | 10 +++++++--- app/xml_cdr/v_xml_cdr_import.php | 5 ++++- app/xml_cdr/xml_cdr.php | 7 ------- app/xml_cdr/xml_cdr_inc.php | 13 ++++++++++++- app/xml_cdr/xml_cdr_statistics_inc.php | 16 ++++++++++++---- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/app/xml_cdr/app_config.php b/app/xml_cdr/app_config.php index b130e477ef..29a1acb1eb 100644 --- a/app/xml_cdr/app_config.php +++ b/app/xml_cdr/app_config.php @@ -197,6 +197,9 @@ $apps[$x]['permissions'][$y]['name'] = "xml_cdr_lose_race"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $y++; + $apps[$x]['permissions'][$y]['name'] = "xml_cdr_enterprise_leg"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $y++; $apps[$x]['permissions'][$y]['name'] = "xml_cdr_cc_agent_leg"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $y++; @@ -537,6 +540,12 @@ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(1)"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "The leg of the call a or b."; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "originating_leg_uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Originating Leg UUID. Used to identify legs of an enterprise ring group - and exclude them "; + $z++; $apps[$x]['db'][$y]['fields'][$z]['name'] = "pdd_ms"; $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "numeric"; $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "numeric"; diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index 904f920290..20a6d6fa25 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -145,6 +145,7 @@ if (!class_exists('xml_cdr')) { $this->fields[] = "record_path"; $this->fields[] = "record_name"; $this->fields[] = "leg"; + $this->fields[] = "originating_leg_uuid"; $this->fields[] = "pdd_ms"; $this->fields[] = "rtp_audio_in_mos"; $this->fields[] = "last_app"; @@ -316,7 +317,7 @@ if (!class_exists('xml_cdr')) { //set missed calls $missed_call = 'false'; - if (strlen($xml->variables->answer_stamp) == 0) { + if (strlen($xml->variables->originating_leg_uuid) == 0 && $xml->variables->call_direction != 'outbound' && strlen($xml->variables->answer_stamp) == 0) { $missed_call = 'true'; } if ($xml->variables->missed_call == 'true') { @@ -404,6 +405,9 @@ if (!class_exists('xml_cdr')) { //store the call leg $this->array[$key]['leg'] = $leg; + //store the originating leg uuid + $this->array[$key]['originating_leg_uuid'] = urldecode($xml->variables->originating_leg_uuid); + //store post dial delay, in milliseconds $this->array[$key]['pdd_ms'] = urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec); @@ -430,7 +434,7 @@ if (!class_exists('xml_cdr')) { if (strlen($domain_name) == 0) { $presence_id = urldecode($xml->variables->presence_id); if (strlen($presence_id) > 0) { - $presence_array = explode($presence_id); + $presence_array = explode($presence_id, '%40'); $domain_name = $presence_array[1]; } } @@ -1210,7 +1214,7 @@ if (!class_exists('xml_cdr')) { // If the range starts with an '-' we start from the beginning // If not, we forward the file pointer // And make sure to get the end byte if spesified - if ($range0 == '-') { + if ($range == '-') { // The n-number of the last bytes is requested $c_start = $size - substr($range, 1); } diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index d8a3198aef..bfbd1026c7 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -265,6 +265,9 @@ //store the call leg $database->fields['leg'] = $leg; + + //store the originating leg + $database->fields['originating_leg_uuid'] = urldecode($xml->variables->originating_leg_uuid); //store post dial delay, in milliseconds $database->fields['pdd_ms'] = urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec); @@ -292,7 +295,7 @@ if (strlen($domain_name) == 0) { $presence_id = urldecode($xml->variables->presence_id); if (strlen($presence_id) > 0) { - $presence_array = explode($presence_id); + $presence_array = explode($presence_id, '%40'); $domain_name = $presence_array[1]; } } diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index 5cd4e71c94..8288e5b3d0 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -824,13 +824,6 @@ $content .= "\n"; - if (!permission_exists('xml_cdr_lose_race') && $row['hangup_cause'] == 'LOSE_RACE') { - $content = ''; - } - //show agent originated legs only to those with the permission - if (!permission_exists('xml_cdr_cc_agent_leg') && $row['cc_side'] == "agent") { - $content = ''; - } //show the leg b only to those with the permission if ($row['leg'] == 'a') { echo $content; diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index df1653fbb1..01b5a42f34 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -413,10 +413,13 @@ $sql .= "and billsec like :billsec "; $parameters['billsec'] = '%'.$billsec.'%'; } - if (strlen($hangup_cause) > 0) { + if (strlen($hangup_cause) > 0 && $hangup_cause != 'LOSE_RACE') { $sql .= "and hangup_cause like :hangup_cause "; $parameters['hangup_cause'] = '%'.$hangup_cause.'%'; } + elseif (!permission_exists('xml_cdr_lose_race')) { + $sql .= "and hangup_cause != 'LOSE_RACE' "; + } if (strlen($call_result) > 0) { switch ($call_result) { case 'answered': @@ -491,6 +494,10 @@ $sql .= "and leg = :leg "; $parameters['leg'] = $leg; } + //exclude enterprise ring group legs + if (!permission_exists('xml_cdr_enterprise_leg')) { + $sql .= "and originating_leg_uuid IS NULL "; + } if (is_numeric($tta_min)) { $sql .= "and (c.answer_epoch - c.start_epoch) >= :tta_min "; $parameters['tta_min'] = $tta_min; @@ -507,6 +514,10 @@ $sql .= "and (c.record_path is null or c.record_name is null) "; } } + //show agent originated legs only to those with the permission + if (!permission_exists('xml_cdr_cc_agent_leg')) { + $sql .= "and cc_side != 'agent' "; + } //end where if (strlen($order_by) > 0) { $sql .= order_by($order_by, $order); diff --git a/app/xml_cdr/xml_cdr_statistics_inc.php b/app/xml_cdr/xml_cdr_statistics_inc.php index 574440d413..4b1c9d9b04 100644 --- a/app/xml_cdr/xml_cdr_statistics_inc.php +++ b/app/xml_cdr/xml_cdr_statistics_inc.php @@ -153,7 +153,7 @@ $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } if ($missed == true) { - $sql_where_ands[] = "billsec = '0'"; + $sql_where_ands[] = "missed_call = true "; } if (strlen($start_epoch) > 0 && strlen($stop_epoch) > 0) { $sql_where_ands[] = "start_epoch between :start_epoch and :stop_epoch"; @@ -284,6 +284,11 @@ if (!permission_exists('xml_cdr_lose_race')) { $sql_where_ands[] = "hangup_cause != 'LOSE_RACE'"; } + //Exclude enterprise ring group legs + if (!permission_exists('xml_cdr_enterprise_leg')) { + $sql_where_ands[] .= "originating_leg_uuid IS NULL"; + } + //if not admin or superadmin, only show own calls if (!permission_exists('xml_cdr_domain')) { @@ -349,7 +354,7 @@ //get the call volume between a start end end time in seconds function get_call_volume_between($start, $end, $where, $parameters) { - $sql = "select count(*) as count, sum(billsec) as seconds from v_xml_cdr "; + $sql = "select count(*) as count, sum(billsec) as seconds, sum(answer_stamp - start_stamp) as tta from v_xml_cdr "; $sql .= $where." "; $sql .= "start_epoch between :start and :end "; $parameters['start'] = $start; @@ -360,6 +365,7 @@ return array( 'volume' => $row['count'], 'seconds' => $row['seconds'], + 'tta' => $row['tta'], ); } return false; @@ -379,14 +385,13 @@ $stats[$i]['volume'] = $stat_range ? $stat_range['volume'] : 0; $stats[$i]['seconds'] = $stat_range ? $stat_range['seconds'] : 0; $stats[$i]['minutes'] = $stats[$i]['seconds'] / 60; - $stats[$i]['avg_sec'] = $stats[$i]['volume'] == 0 ? 0 : $stats[$i]['seconds'] / $stats[$i]['volume']; if ($missed) { //we select only missed calls at first place - no reasons to select it again $stats[$i]['missed'] = $stats[$i]['volume']; } else { - $where = $sql_where."billsec = '0' and "; + $where = $sql_where."missed_call = true and "; $stat_range = get_call_volume_between($stats[$i]['start_epoch'], $stats[$i]['stop_epoch'], $where, $parameters); $stats[$i]['missed'] = $stat_range ? $stat_range['volume'] : 0; } @@ -403,6 +408,9 @@ //answer / seizure ratio $stats[$i]['asr'] = $stats[$i]['volume'] == 0 ? 0 : ($success_volume / $stats[$i]['volume'] * 100); + //average time to answer + $stats[$i]['avg_tta'] = $stats[$i]['volume'] == 0 ? 0 : round($stat_range['tta'] / $success_volume); + //average length of call $stats[$i]['aloc'] = $success_volume == 0 ? 0 : $stats[$i]['minutes'] / $success_volume; } From ef38b15cdc9a1e4bfa5a0462c7d304a94f28f720 Mon Sep 17 00:00:00 2001 From: demonspork Date: Fri, 19 Feb 2021 23:27:24 -0600 Subject: [PATCH 2/9] Add new missed call rules to HTTP CDR Imports Add new missed call rules to HTTP CDR Imports. They had only been added to the xml_cdr class used by the file import. --- app/xml_cdr/v_xml_cdr_import.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index bfbd1026c7..0902b4c271 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -211,7 +211,7 @@ //set missed calls $database->fields['missed_call'] = 'false'; - if (strlen($xml->variables->answer_stamp) == 0) { + if (strlen($xml->variables->originating_leg_uuid) == 0 && $xml->variables->call_direction != 'outbound' && strlen($xml->variables->answer_stamp) == 0) { $database->fields['missed_call'] = 'true'; } if ($xml->variables->missed_call == 'true') { @@ -265,9 +265,6 @@ //store the call leg $database->fields['leg'] = $leg; - - //store the originating leg - $database->fields['originating_leg_uuid'] = urldecode($xml->variables->originating_leg_uuid); //store post dial delay, in milliseconds $database->fields['pdd_ms'] = urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec); From 56a318b2f0bebee69ba48c27ecd42e73fac6953b Mon Sep 17 00:00:00 2001 From: demonspork Date: Fri, 19 Feb 2021 23:30:34 -0600 Subject: [PATCH 3/9] Fix TTA display bug If the TTA is 0 because the call was answered in less than a second (so that the answer_epoch and start_epoch are in the same second), it would not display the TTA at all. This is safe to include 0 because "unanswered" calls are going to have a TTA that is is the negative value of the start time, significantly lower than 0. --- app/xml_cdr/xml_cdr.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index 8288e5b3d0..fb139285fd 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -796,7 +796,7 @@ } //tta (time to answer) if (permission_exists('xml_cdr_tta')) { - $content .= " ".(($row['tta'] > 0) ? $row['tta']."s" : " ")."\n"; + $content .= " ".(($row['tta'] >= 0) ? $row['tta']."s" : " ")."\n"; } //duration if (permission_exists('xml_cdr_duration')) { From d150f16b9d408b6239ad1fa232201b1ba65911a6 Mon Sep 17 00:00:00 2001 From: demonspork Date: Sat, 20 Feb 2021 00:17:01 -0600 Subject: [PATCH 4/9] Fixed "Failed" call status in CDR Re-implemented the commented out "Failed" call status SQL filter. It was no different than leaving the "Call status" search box empty. Removed the send_refuse restriction. --- app/xml_cdr/xml_cdr_inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index 01b5a42f34..619a7455e4 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -453,7 +453,8 @@ ))"; } break; - default: //failed + default: + $sql .= "and (answer_stamp is null and bridge_uuid is null and duration = 0) "; //$sql .= "and (answer_stamp is null and bridge_uuid is null and billsec = 0 and sip_hangup_disposition = 'send_refuse') "; } } From 92dc62a7b43eef626ddf367de894fb94391da52d Mon Sep 17 00:00:00 2001 From: demonspork Date: Sat, 20 Feb 2021 01:02:03 -0600 Subject: [PATCH 5/9] Fix TTA display bug in Export CDR PDF Same thing as in the xml_cdr.php page display. If the call is answered instantly, less than a second, then the difference is 0s, and the 0s is a visual indicator that the call was answered, it just took less than a second. Calls that didn't get answered have a large negative number stored in the TTA field, 0 is an answered call. --- app/xml_cdr/xml_cdr_export.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/xml_cdr/xml_cdr_export.php b/app/xml_cdr/xml_cdr_export.php index b39ce53d03..96a12d26f7 100644 --- a/app/xml_cdr/xml_cdr_export.php +++ b/app/xml_cdr/xml_cdr_export.php @@ -192,7 +192,7 @@ $data_body[$p] .= ''.format_phone($fields['destination_number']).''; $data_body[$p] .= ''.$fields['start_stamp'].''; $total['tta'] += ($fields['tta'] > 0) ? $fields['tta'] : 0; - $data_body[$p] .= ''.(($fields['tta'] > 0) ? $fields['tta'].'s' : null).''; + $data_body[$p] .= ''.(($fields['tta'] >= 0) ? $fields['tta'].'s' : null).''; $seconds = ($fields['hangup_cause'] == "ORIGINATOR_CANCEL") ? $fields['duration'] : round(($fields['billmsec'] / 1000), 0, PHP_ROUND_HALF_UP); $total['duration'] += $seconds; $data_body[$p] .= ''.gmdate("G:i:s", $seconds).''; From 77974b71dc9cb1dee9edfafeaa92242c81ea1773 Mon Sep 17 00:00:00 2001 From: demonspork Date: Sat, 20 Feb 2021 02:57:08 -0600 Subject: [PATCH 6/9] Fix Query performance for cc_side agent For some unexplained reason, including the `"and cc_side != 'agent'` in the WHERE tanks the query performance from seconds to minutes on Postgres 9.4. It runs great on Postgresql 13. Reverting to the "blank content while writing the page content" approach for this value unless I can find the source of the problem. - Oh, also removed an unnecessary condition that prevents you from filtering by LOSE_RACE. --- app/xml_cdr/xml_cdr.php | 5 ++++- app/xml_cdr/xml_cdr_inc.php | 6 +----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index fb139285fd..d4a1512645 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -823,7 +823,10 @@ } $content .= "\n"; - + //show agent originated legs only to those with the permission + if (!permission_exists('xml_cdr_cc_agent_leg') && $row['cc_side'] == "agent") { + $content = ''; + } //show the leg b only to those with the permission if ($row['leg'] == 'a') { echo $content; diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index 619a7455e4..9e34896f7d 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -413,7 +413,7 @@ $sql .= "and billsec like :billsec "; $parameters['billsec'] = '%'.$billsec.'%'; } - if (strlen($hangup_cause) > 0 && $hangup_cause != 'LOSE_RACE') { + if (strlen($hangup_cause) > 0) { $sql .= "and hangup_cause like :hangup_cause "; $parameters['hangup_cause'] = '%'.$hangup_cause.'%'; } @@ -515,10 +515,6 @@ $sql .= "and (c.record_path is null or c.record_name is null) "; } } - //show agent originated legs only to those with the permission - if (!permission_exists('xml_cdr_cc_agent_leg')) { - $sql .= "and cc_side != 'agent' "; - } //end where if (strlen($order_by) > 0) { $sql .= order_by($order_by, $order); From b5272984d1bce21497f5b27b982b521a2312c79c Mon Sep 17 00:00:00 2001 From: demonspork Date: Sat, 20 Feb 2021 11:14:47 -0600 Subject: [PATCH 7/9] Don't filter LOSE_RACE of already filtering originating_leg_uuid It is redundant to filter out LOSE_RACE when originating_leg_uuid is also filtered, there is an overlap where every call with LOSE_RACE also has an originating_leg. --- app/xml_cdr/resources/classes/xml_cdr.php | 10 ++++++++-- app/xml_cdr/xml_cdr_inc.php | 10 +++++----- app/xml_cdr/xml_cdr_statistics_inc.php | 8 ++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index 20a6d6fa25..a8675eb507 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -973,7 +973,10 @@ if (!class_exists('xml_cdr')) { $sql .= "filter ( \n"; $sql .= " where c.extension_uuid = e.extension_uuid \n"; $sql .= " and missed_call = true \n"; - if (!permission_exists('xml_cdr_lose_race')) { + if (!permission_exists('xml_cdr_enterprise_leg')) { + $sql .= " and originating_leg_uuid is null \n"; + } + elseif (!permission_exists('xml_cdr_lose_race')) { $sql .= " and hangup_cause <> 'LOSE_RACE' \n"; } if ($this->include_internal) { @@ -1029,7 +1032,10 @@ if (!class_exists('xml_cdr')) { $sql .= "count(*) \n"; $sql .= "filter ( \n"; $sql .= " where c.extension_uuid = e.extension_uuid \n"; - if (!permission_exists('xml_cdr_lose_race')) { + if (!permission_exists('xml_cdr_enterprise_leg')) { + $sql .= " and originating_leg_uuid is null \n"; + } + elseif (!permission_exists('xml_cdr_lose_race')) { $sql .= " and hangup_cause <> 'LOSE_RACE' \n"; } if ($this->include_internal) { diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index 9e34896f7d..c1151d0f07 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -417,9 +417,13 @@ $sql .= "and hangup_cause like :hangup_cause "; $parameters['hangup_cause'] = '%'.$hangup_cause.'%'; } - elseif (!permission_exists('xml_cdr_lose_race')) { + elseif (!permission_exists('xml_cdr_lose_race') && permission_exists('xml_cdr_enterprise_leg')) { $sql .= "and hangup_cause != 'LOSE_RACE' "; } + //exclude enterprise ring group legs + if (!permission_exists('xml_cdr_enterprise_leg')) { + $sql .= "and originating_leg_uuid IS NULL "; + } if (strlen($call_result) > 0) { switch ($call_result) { case 'answered': @@ -495,10 +499,6 @@ $sql .= "and leg = :leg "; $parameters['leg'] = $leg; } - //exclude enterprise ring group legs - if (!permission_exists('xml_cdr_enterprise_leg')) { - $sql .= "and originating_leg_uuid IS NULL "; - } if (is_numeric($tta_min)) { $sql .= "and (c.answer_epoch - c.start_epoch) >= :tta_min "; $parameters['tta_min'] = $tta_min; diff --git a/app/xml_cdr/xml_cdr_statistics_inc.php b/app/xml_cdr/xml_cdr_statistics_inc.php index 4b1c9d9b04..e695b8e67c 100644 --- a/app/xml_cdr/xml_cdr_statistics_inc.php +++ b/app/xml_cdr/xml_cdr_statistics_inc.php @@ -280,14 +280,14 @@ $sql_where_ands[] = "leg = :leg"; $parameters['leg'] = $leg; } - //If you can't see lose_race, don't run stats on it - if (!permission_exists('xml_cdr_lose_race')) { - $sql_where_ands[] = "hangup_cause != 'LOSE_RACE'"; - } //Exclude enterprise ring group legs if (!permission_exists('xml_cdr_enterprise_leg')) { $sql_where_ands[] .= "originating_leg_uuid IS NULL"; } + //If you can't see lose_race, don't run stats on it + elseif (!permission_exists('xml_cdr_lose_race')) { + $sql_where_ands[] = "hangup_cause != 'LOSE_RACE'"; + } //if not admin or superadmin, only show own calls From 0ef2551698754ed7a5348ef82a9d15328b02aa6e Mon Sep 17 00:00:00 2001 From: demonspork Date: Sun, 21 Feb 2021 18:26:24 -0600 Subject: [PATCH 8/9] Exclude cc_side agent legs from missed_call Excluded cc_side = agent calls from being marked as missed_call = true Fixed the previous performance issue with adding the cc_side != 'agent' to the SQL and removed its filter from the rendering loop for the xml_cdr. --- app/xml_cdr/resources/classes/xml_cdr.php | 2 +- app/xml_cdr/v_xml_cdr_import.php | 2 +- app/xml_cdr/xml_cdr.php | 4 ---- app/xml_cdr/xml_cdr_inc.php | 4 ++++ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index a8675eb507..eac992c12d 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -317,7 +317,7 @@ if (!class_exists('xml_cdr')) { //set missed calls $missed_call = 'false'; - if (strlen($xml->variables->originating_leg_uuid) == 0 && $xml->variables->call_direction != 'outbound' && strlen($xml->variables->answer_stamp) == 0) { + if ($xml->variables->cc_side != "agent" && strlen($xml->variables->originating_leg_uuid) == 0 && $xml->variables->call_direction != 'outbound' && strlen($xml->variables->answer_stamp) == 0) { $missed_call = 'true'; } if ($xml->variables->missed_call == 'true') { diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index 0902b4c271..a38985e228 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -211,7 +211,7 @@ //set missed calls $database->fields['missed_call'] = 'false'; - if (strlen($xml->variables->originating_leg_uuid) == 0 && $xml->variables->call_direction != 'outbound' && strlen($xml->variables->answer_stamp) == 0) { + if ($xml->variables->cc_side != "agent" && strlen($xml->variables->originating_leg_uuid) == 0 && $xml->variables->call_direction != 'outbound' && strlen($xml->variables->answer_stamp) == 0) { $database->fields['missed_call'] = 'true'; } if ($xml->variables->missed_call == 'true') { diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index d4a1512645..05d889091b 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -823,10 +823,6 @@ } $content .= "\n"; - //show agent originated legs only to those with the permission - if (!permission_exists('xml_cdr_cc_agent_leg') && $row['cc_side'] == "agent") { - $content = ''; - } //show the leg b only to those with the permission if ($row['leg'] == 'a') { echo $content; diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index c1151d0f07..3d12d71339 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -515,6 +515,10 @@ $sql .= "and (c.record_path is null or c.record_name is null) "; } } + //show agent originated legs only to those with the permission + if (!permission_exists('xml_cdr_cc_agent_leg')) { + $sql .= "and (cc_side is null or cc_side != 'agent') "; + } //end where if (strlen($order_by) > 0) { $sql .= order_by($order_by, $order); From c11589b1c38dcb22371192333fd848ee6b0fe79a Mon Sep 17 00:00:00 2001 From: demonspork Date: Sun, 21 Feb 2021 21:09:37 -0600 Subject: [PATCH 9/9] Track Voicemail Message Success/Failure in CDR Track whether or not a message was actually left in the voicemail box. Previously we only knew that voicemail answered, now we know whether the caller left a message. Callers who didn't leave a message now show up in the "Cancelled" call filter in xml_cdr.php Bonus: Fixed a bug with the originating_leg_uuid that was breaking extension summary from a previous commit and some other minor bugs/typos. --- .../resources/functions/record_message.lua | 2 +- app/xml_cdr/app_config.php | 6 ++++ app/xml_cdr/resources/classes/xml_cdr.php | 28 +++++++++++++------ app/xml_cdr/v_xml_cdr_import.php | 8 ++++++ app/xml_cdr/xml_cdr_inc.php | 22 +++++++++++++-- 5 files changed, 53 insertions(+), 13 deletions(-) diff --git a/app/scripts/resources/scripts/app/voicemail/resources/functions/record_message.lua b/app/scripts/resources/scripts/app/voicemail/resources/functions/record_message.lua index a459da7b8a..93a61d9c68 100644 --- a/app/scripts/resources/scripts/app/voicemail/resources/functions/record_message.lua +++ b/app/scripts/resources/scripts/app/voicemail/resources/functions/record_message.lua @@ -587,7 +587,7 @@ --if the recording is below the minimal length then re-record the message if (message_length > 2) then - --continue + session:setVariable("voicemail_message_seconds", message_length); else if (session:ready()) then --your recording is below the minimal acceptable length, please try again diff --git a/app/xml_cdr/app_config.php b/app/xml_cdr/app_config.php index 29a1acb1eb..3cd481481d 100644 --- a/app/xml_cdr/app_config.php +++ b/app/xml_cdr/app_config.php @@ -564,6 +564,12 @@ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Save the last application data."; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "voicemail_message"; + $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "boolean"; + $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; $apps[$x]['db'][$y]['fields'][$z]['name'] = "missed_call"; $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "boolean"; $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text"; diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index eac992c12d..4f488c1002 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -150,6 +150,7 @@ if (!class_exists('xml_cdr')) { $this->fields[] = "rtp_audio_in_mos"; $this->fields[] = "last_app"; $this->fields[] = "last_arg"; + $this->fields[] = "voicemail_message"; $this->fields[] = "cc_side"; $this->fields[] = "cc_member_uuid"; $this->fields[] = "cc_queue_joined_epoch"; @@ -391,6 +392,14 @@ if (!class_exists('xml_cdr')) { $this->array[$key]['last_app'] = urldecode($xml->variables->last_app); $this->array[$key]['last_arg'] = urldecode($xml->variables->last_arg); + //voicemail message success + if ($xml->variables->voicemail_action == "save" && $xml->variables->voicemail_message_seconds > 0){ + $this->array[$key]['voicemail_message'] = "true"; + } + else { //if ($xml->variables->voicemail_action == "save") { + $this->array[$key]['voicemail_message'] = "false"; + } + //conference $this->array[$key]['conference_name'] = urldecode($xml->variables->conference_name); $this->array[$key]['conference_uuid'] = urldecode($xml->variables->conference_uuid); @@ -922,13 +931,13 @@ if (!class_exists('xml_cdr')) { if (strlen($this->start_stamp_begin) > 0 || strlen($this->start_stamp_end) > 0) { unset($this->quick_select); if (strlen($this->start_stamp_begin) > 0 && strlen($this->start_stamp_end) > 0) { - $sql_date_range .= " and start_stamp between :start_stamp_begin and :start_stamp_end \n"; + $sql_date_range = " and start_stamp between :start_stamp_begin and :start_stamp_end \n"; $parameters['start_stamp_begin'] = $this->start_stamp_begin.':00.000'; $parameters['start_stamp_end'] = $this->start_stamp_end.':59.999'; } else { if (strlen($this->start_stamp_begin) > 0) { - $sql_date_range .= "and start_stamp >= :start_stamp_begin \n"; + $sql_date_range = "and start_stamp >= :start_stamp_begin \n"; $parameters['start_stamp_begin'] = $this->start_stamp_begin.':00.000'; } if (strlen($this->start_stamp_end) > 0) { @@ -939,13 +948,13 @@ if (!class_exists('xml_cdr')) { } else { switch ($this->quick_select) { - case 1: $sql_date_range .= "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 week"))."' \n"; break; //last 7 days - case 2: $sql_date_range .= "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 hour"))."' \n"; break; //last hour - case 3: $sql_date_range .= "and start_stamp >= '".date('Y-m-d')." "."00:00:00.000' \n"; break; //today - case 4: $sql_date_range .= "and start_stamp between '".date('Y-m-d',strtotime("-1 day"))." "."00:00:00.000' and '".date('Y-m-d',strtotime("-1 day"))." "."23:59:59.999' \n"; break; //yesterday - case 5: $sql_date_range .= "and start_stamp >= '".date('Y-m-d',strtotime("this week"))." "."00:00:00.000' \n"; break; //this week - case 6: $sql_date_range .= "and start_stamp >= '".date('Y-m-')."01 "."00:00:00.000' \n"; break; //this month - case 7: $sql_date_range .= "and start_stamp >= '".date('Y-')."01-01 "."00:00:00.000' \n"; break; //this year + case 1: $sql_date_range = "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 week"))."' \n"; break; //last 7 days + case 2: $sql_date_range = "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 hour"))."' \n"; break; //last hour + case 3: $sql_date_range = "and start_stamp >= '".date('Y-m-d')." "."00:00:00.000' \n"; break; //today + case 4: $sql_date_range = "and start_stamp between '".date('Y-m-d',strtotime("-1 day"))." "."00:00:00.000' and '".date('Y-m-d',strtotime("-1 day"))." "."23:59:59.999' \n"; break; //yesterday + case 5: $sql_date_range = "and start_stamp >= '".date('Y-m-d',strtotime("this week"))." "."00:00:00.000' \n"; break; //this week + case 6: $sql_date_range = "and start_stamp >= '".date('Y-m-')."01 "."00:00:00.000' \n"; break; //this month + case 7: $sql_date_range = "and start_stamp >= '".date('Y-')."01-01 "."00:00:00.000' \n"; break; //this year } } @@ -1086,6 +1095,7 @@ if (!class_exists('xml_cdr')) { $sql .= " direction, \n"; $sql .= " start_stamp, \n"; $sql .= " hangup_cause, \n"; + $sql .= " originating_leg_uuid, \n"; $sql .= " billsec \n"; $sql .= " from v_xml_cdr \n"; if (!($_GET['show'] === 'all' && permission_exists('xml_cdr_all'))) { diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index a38985e228..6230f8c030 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -198,6 +198,14 @@ $database->fields['last_app'] = urldecode($xml->variables->last_app); $database->fields['last_arg'] = urldecode($xml->variables->last_arg); + //voicemail message success + if ($xml->variables->voicemail_action == "save" && $xml->variables->voicemail_message_seconds > 0){ + $database->fields['voicemail_message'] = "true"; + } + elseif ($xml->variables->voicemail_action == "save") { + $database->fields['voicemail_message'] = "false"; + } + //conference $database->fields['conference_name'] = urldecode($xml->variables->conference_name); $database->fields['conference_uuid'] = urldecode($xml->variables->conference_uuid); diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index 3d12d71339..d7255167d8 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -417,7 +417,7 @@ $sql .= "and hangup_cause like :hangup_cause "; $parameters['hangup_cause'] = '%'.$hangup_cause.'%'; } - elseif (!permission_exists('xml_cdr_lose_race') && permission_exists('xml_cdr_enterprise_leg')) { + elseif (!permission_exists('xml_cdr_lose_race') && !permission_exists('xml_cdr_enterprise_leg')) { $sql .= "and hangup_cause != 'LOSE_RACE' "; } //exclude enterprise ring group legs @@ -437,10 +437,20 @@ break; case 'cancelled': if ($direction == 'inbound' || $direction == 'local' || $call_result == 'missed') { - $sql = "and (answer_stamp is null and bridge_uuid is null and sip_hangup_disposition <> 'send_refuse') "; + $sql .= " + and (( + answer_stamp is null + and bridge_uuid is null + and sip_hangup_disposition <> 'send_refuse' + ) + or ( + answer_stamp is not null + and bridge_uuid is null + and voicemail_message = false + ))"; } else if ($direction == 'outbound') { - $sql = "and (answer_stamp is null and bridge_uuid is not null) "; + $sql .= "and (answer_stamp is null and bridge_uuid is not null) "; } else { $sql .= " @@ -454,6 +464,12 @@ direction = 'outbound' and answer_stamp is null and bridge_uuid is not null + ) + or ( + (direction = 'inbound' or direction = 'local') + and answer_stamp is not null + and bridge_uuid is null + and voicemail_message = false ))"; } break;