Fixed Call Flow Summary for outbound calls

This commit is contained in:
FusionPBX 2024-11-14 17:14:33 -07:00 committed by GitHub
parent 6d37675273
commit ffd1bbd4fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 100 additions and 33 deletions

View File

@ -43,10 +43,13 @@ if (!class_exists('xml_cdr')) {
public $domain_uuid;
public $call_details;
public $call_direction;
public $status;
public $billsec;
private $username;
private $password;
private $json;
public $recording_uuid;
public $binary;
/**
* user summary
@ -1138,8 +1141,18 @@ if (!class_exists('xml_cdr')) {
//add new rows when callee_id_number exists
$new_rows = 0;
foreach ($call_flow_array as $key => $row) {
//for outbound calls update the times if the bridged_time to remove the call setup plus the ring time
if ($this->call_direction === 'outbound') {
if (isset($row["times"]["bridged_time"]) and $row["times"]["bridged_time"] > 0) {
//change the end time for the current row
$call_flow_array[$key]["times"]["profile_created_time"] = $row["times"]["bridged_time"];
}
}
//add a new row to the call summary
if (!empty($row["caller_profile"]["destination_number"])
and !empty($row["caller_profile"]["callee_id_number"])
and $this->call_direction !== 'outbound'
and $row["caller_profile"]["destination_number"] !== $row["caller_profile"]["callee_id_number"]) {
//build the base of the new_row array
$new_row["caller_profile"]["destination_number"] = $row["caller_profile"]["callee_id_number"];
@ -1192,6 +1205,7 @@ if (!class_exists('xml_cdr')) {
$x = 0; $skip_row = false;
if (!empty($call_flow_array)) {
foreach ($call_flow_array as $row) {
//skip this row
if ($skip_row) {
$skip_row = false;
@ -1200,7 +1214,12 @@ if (!class_exists('xml_cdr')) {
//get the application array
if (!empty($destination_array) && !empty($row["caller_profile"]["destination_number"])) {
$app = $this->find_app($destination_array, urldecode($row["caller_profile"]["destination_number"]));
if ($this->call_direction == 'outbound') {
$app = $this->find_app($destination_array, urldecode($row["caller_profile"]["username"]));
}
else {
$app = $this->find_app($destination_array, urldecode($row["caller_profile"]["destination_number"]));
}
}
//call centers
@ -1230,11 +1249,11 @@ if (!class_exists('xml_cdr')) {
//extensions
if (!empty($app['application']) && $app['application'] == 'extensions') {
if ($this->billsec == 0) {
$app['status'] = 'missed';
if (!empty($row["times"]["profile_created_time"]) && !empty($row["times"]["profile_end_time"]) && (floor($row["times"]["profile_end_time"] / 1000000) - floor($row["times"]["profile_created_time"] / 1000000)) > 0) {
$app['status'] = 'answered';
}
else {
$app['status'] = 'answered';
$app['status'] = 'missed';
}
}
@ -1245,10 +1264,23 @@ if (!class_exists('xml_cdr')) {
//outbound routes
if ($this->call_direction == 'outbound') {
if (empty($app['application'])) {
$app['application'] = 'dialplans';
$status = 'missed';
if (!empty($row["times"]["answered_time"])) {
$status = 'answered';
}
if (!empty($row["caller_profile"]["username"])) {
//add to the application array
$app['application'] = 'extensions';
$app['source'] = $row["caller_profile"]["username"];
$app['status'] = $status;
$app['name'] = '';
$app['label'] = 'extensions';
}
elseif (empty($app['application'])) {
$app['application'] = 'diaplans';
$app['uuid'] = '';
$app['status'] = '';
$app['status'] = $status;
$app['name'] = 'Outbound';
$app['label'] = 'Outbound';
}
@ -1306,12 +1338,10 @@ if (!class_exists('xml_cdr')) {
}
//debug - add the callee_id_number to the end of the status
if (
isset($_REQUEST['debug']) && $_REQUEST['debug'] == 'true'
if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == 'true'
&& !empty($row["caller_profile"]["destination_number"])
&& !empty($row["caller_profile"]["callee_id_number"])
&& $row["caller_profile"]["destination_number"] !== $row["caller_profile"]["callee_id_number"]
) {
&& $row["caller_profile"]["destination_number"] !== $row["caller_profile"]["callee_id_number"]) {
$app['status'] .= ' ('.$row["caller_profile"]["callee_id_number"].')';
}
@ -1328,26 +1358,48 @@ if (!class_exists('xml_cdr')) {
$text2 = $language2->get($this->setting->get('domain', 'language'), 'app/'.($app['application'] ?? ''));
$call_flow_summary[$x]["application_name"] = ($app['application'] ?? '');
$call_flow_summary[$x]["application_label"] = trim($text2['title-'.($app['application'] ?? '')] ?? '');
$call_flow_summary[$x]["call_direction"] = $this->call_direction;
$call_flow_summary[$x]["application_url"] = $application_url;
$call_flow_summary[$x]["destination_uuid"] = ($app["uuid"] ?? '');
$call_flow_summary[$x]["destination_name"] = ($app['name'] ?? '');
$call_flow_summary[$x]["destination_url"] = $destination_url;
if ($this->call_direction == 'outbound') {
$call_flow_summary[$x]["source_uuid"] = ($app['uuid'] ?? '');
$call_flow_summary[$x]["source_number"] = $app['source'];
$call_flow_summary[$x]["source_label"] = ($app['label'] ?? '');
$call_flow_summary[$x]["source_url"] = $destination_url;
$call_flow_summary[$x]["source_name"] = $app['description'] ?? '';
//$call_flow_summary[$x]["source_description"] = $app['description'] ?? '';
$call_flow_summary[$x]["destination_uuid"] = '';
$call_flow_summary[$x]["destination_number"] = '';
$call_flow_summary[$x]["destination_label"] = '';
$call_flow_summary[$x]["destination_url"] = '';
$call_flow_summary[$x]["destination_description"] = '';
}
else {
$call_flow_summary[$x]["source_uuid"] = '';
$call_flow_summary[$x]["source_number"] = '';
$call_flow_summary[$x]["source_label"] = '';
$call_flow_summary[$x]["source_url"] = '';
$call_flow_summary[$x]["destination_name"] = ($app['description'] ?? '');
$call_flow_summary[$x]["destination_uuid"] = ($app['uuid'] ?? '');
$call_flow_summary[$x]["destination_label"] = ($app['label'] ?? '');
$call_flow_summary[$x]["destination_url"] = $destination_url;
//$call_flow_summary[$x]["destination_description"] = $app['description'] ?? '';
}
$call_flow_summary[$x]["destination_number"] = $row["caller_profile"]["destination_number"];
$call_flow_summary[$x]["destination_label"] = ($app['label'] ?? '');
$call_flow_summary[$x]["destination_status"] = ($app['status'] ?? '');
$call_flow_summary[$x]["destination_description"] = $app['description'] ?? '';
//$call_flow_summary[$x]["application"] = $app;
//set the start and epoch
$profile_created_epoch = round($row['times']['profile_created_time'] / 1000000);
$profile_end_epoch = round($row['times']['profile_end_time'] / 1000000);
$profile_created_epoch = $row['times']['profile_created_time'] / 1000000;
$profile_end_epoch = $row['times']['profile_end_time'] / 1000000;
//add the call flow times
$call_flow_summary[$x]["start_epoch"] = $profile_created_epoch;
$call_flow_summary[$x]["end_epoch"] = $profile_end_epoch;
$call_flow_summary[$x]["start_epoch"] = round($profile_created_epoch);
$call_flow_summary[$x]["end_epoch"] = round($profile_end_epoch);
$call_flow_summary[$x]["start_stamp"] = date("Y-m-d H:i:s", $profile_created_epoch);
$call_flow_summary[$x]["end_stamp"] = date("Y-m-d H:i:s", $profile_end_epoch);
$call_flow_summary[$x]["duration_seconds"] = $profile_end_epoch - $profile_created_epoch;
$call_flow_summary[$x]["duration_seconds"] = round($profile_end_epoch - $profile_created_epoch);
$call_flow_summary[$x]["duration_formatted"] = gmdate("G:i:s",(int) $call_flow_summary[$x]["duration_seconds"]);
unset($app);
$x++;
@ -1355,6 +1407,9 @@ if (!class_exists('xml_cdr')) {
}
unset($x);
//set the last status to match the call detail record
$call_flow_summary[count($call_flow_summary)-1]['destination_status'] = $this->status;
//return the call flow summary array
return $call_flow_summary;
}

View File

@ -40,6 +40,9 @@
exit;
}
//connect to the database
$database = database::new();
//set permissions
$permission = array();
$permission['xml_cdr_view'] = permission_exists('xml_cdr_view');
@ -144,7 +147,6 @@
}
$sql .= "order by extension asc, number_alias asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$extensions = $database->select($sql, $parameters, 'all');
}
@ -154,7 +156,6 @@
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "order by queue_extension asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$call_center_queues = $database->select($sql, $parameters, 'all');
}

View File

@ -37,12 +37,15 @@
exit;
}
//connect to the database
$database = database::new();
//add multi-lingual support
$language = new text;
$text = $language->get();
//add the settings object
$settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
$settings = new settings(["database" => $database, "domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
$transcribe_enabled = $settings->get('transcribe', 'enabled', false);
$transcribe_engine = $settings->get('transcribe', 'engine', '');
$call_log_enabled = $settings->get('cdr', 'call_log_enabled', false);
@ -64,7 +67,6 @@
$parameters['domain_uuid'] = $domain_uuid;
}
$parameters['xml_cdr_uuid'] = $uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (!empty($row) && is_array($row) && @sizeof($row) != 0) {
$caller_id_name = trim($row["caller_id_name"] ?? '');
@ -116,7 +118,6 @@
$p->add('xml_cdr_edit', 'temp');
//remove record_path, record_name and record_length
$database = new database;
$database->app_name = 'xml_cdr';
$database->app_uuid = '4a085c51-7635-ff03-f67b-86e834422848';
$database->save($array, false);
@ -147,7 +148,6 @@
$parameters['domain_uuid'] = $domain_uuid;
}
$parameters['xml_cdr_uuid'] = $uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (!empty($row) && is_array($row) && @sizeof($row) != 0) {
$json_string = trim($row["json"] ?? '');
@ -167,7 +167,6 @@
$parameters['domain_uuid'] = $domain_uuid;
}
$parameters['xml_cdr_uuid'] = $uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (!empty($row) && is_array($row) && @sizeof($row) != 0) {
$call_flow = trim($row["call_flow"] ?? '');
@ -187,7 +186,7 @@
$parameters['domain_uuid'] = $domain_uuid;
}
$parameters['xml_cdr_uuid'] = $uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (!empty($row) && is_array($row) && @sizeof($row) != 0) {
$log_content = $row["log_content"];
@ -271,15 +270,18 @@
//build the call flow summary array
$xml_cdr = new xml_cdr;
$xml_cdr->domain_uuid = $_SESSION['domain_uuid'];
$xml_cdr->call_direction = $call_direction;
$xml_cdr->billsec = $billsec;
$xml_cdr->call_direction = $call_direction; //used to determine when the call is outbound
$xml_cdr->status = $status; //used to determine when the call is outbound
if (empty($call_flow)) {
//get the call flow summary from the xml_cdr_json table
$xml_cdr->call_details = $array;
$call_flow_array = $xml_cdr->call_flow();
}
else {
//get the call flow summary from the xml_cdr_flow table
$call_flow_array = json_decode($call_flow, true);
}
//prepares the raw call flow data to be displayed
$call_flow_summary = $xml_cdr->call_flow_summary($call_flow_array);
//debug information
@ -293,7 +295,6 @@
}
$i++;
}
view_array($call_flow_array, false);
}
//set the year, month and date
@ -498,6 +499,9 @@
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <th>".$text['label-application']."</th>\n";
if ($call_direction == 'outbound') {
echo " <th>".$text['label-source']."</th>\n";
}
echo " <th>".$text['label-destination']."</th>\n";
echo " <th>".$text['label-name']."</th>\n";
echo " <th>".$text['label-start']."</th>\n";
@ -509,8 +513,15 @@
foreach ($call_flow_summary as $row) {
echo "<tr >\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href=\"".$row["application_url"]."\">".escape($row["application_label"])."</a></td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href=\"".$row["destination_url"]."\">".escape($row["destination_number"])."</a></td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href=\"".$row["destination_url"]."\">".escape($row["destination_name"])."</a></td>\n";
if ($call_direction == 'outbound') {
echo " <td valign='top' class='".$row_style[$c]."'><a href=\"".$row["source_url"]."\">".escape($row["source_number"])."</a></td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row["destination_number"])."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href=\"".$row["source_url"]."\">".escape($row["source_name"])."</a></td>\n";
}
else {
echo " <td valign='top' class='".$row_style[$c]."'><a href=\"".$row["destination_url"]."\">".escape($row["destination_number"])."</a></td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href=\"".$row["destination_url"]."\">".escape($row["destination_name"])."</a></td>\n";
}
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row["start_stamp"])."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row["end_stamp"])."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row["duration_formatted"])."</td>\n";