Extension Summary: Fix Start & End Date/Time search.

This commit is contained in:
Nate 2019-09-11 17:12:01 -06:00
parent 53d7796194
commit 0618d4eada
1 changed files with 126 additions and 126 deletions

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2016-2018
Portions created by the Initial Developer are Copyright (C) 2016-2019
the Initial Developer. All Rights Reserved.
Contributor(s):
@ -844,217 +844,217 @@ 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:00.000' and :start_stamp_end:59.999' \n";
$parameters['start_stamp_begin'] = $this->start_stamp_begin;
$parameters['start_stamp_end'] = $this->start_stamp_end;
$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:00.000' \n"; }
if (strlen($this->start_stamp_end) > 0) { $sql_date_range .= "AND start_stamp <= :start_stamp_end:59.999' \n"; }
$parameters['start_stamp_begin'] = $this->start_stamp_begin;
$parameters['start_stamp_end'] = $this->start_stamp_end;
if (strlen($this->start_stamp_begin) > 0) { $sql_date_range .= "and start_stamp >= :start_stamp_begin \n"; }
if (strlen($this->start_stamp_end) > 0) { $sql_date_range .= "and start_stamp <= :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 {
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
}
}
//calculate the summary data
$sql = "SELECT \n";
$sql = "select \n";
$sql .= "e.domain_uuid, \n";
$sql .= "d.domain_name, \n";
$sql .= "e.extension, \n";
$sql .= "e.number_alias, \n";
$sql .= "COUNT(*) \n";
$sql .= "FILTER( \n";
$sql .= " WHERE c.domain_uuid = e.domain_uuid \n";
$sql .= " AND ((\n";
$sql .= "count(*) \n";
$sql .= "filter( \n";
$sql .= " where c.domain_uuid = e.domain_uuid \n";
$sql .= " and ((\n";
$sql .= " c.caller_id_number = e.extension \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.extension) \n";
$sql .= " OR ( \n";
$sql .= " e.number_alias IS NOT NULL and ( \n";
$sql .= " or ( \n";
$sql .= " e.number_alias is not null and ( \n";
$sql .= " c.caller_id_number = e.number_alias \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.number_alias))) \n";
$sql .= " AND (\n";
$sql .= " c.answer_stamp IS NOT NULL \n";
$sql .= " and (\n";
$sql .= " c.answer_stamp is not null \n";
$sql .= " and \n";
$sql .= " c.bridge_uuid IS NOT NULL) \n";
$sql .= " c.bridge_uuid is not null) \n";
if ($this->include_internal) {
$sql .= " AND (direction = 'inbound' OR direction = 'local')) \n";
$sql .= " and (direction = 'inbound' or direction = 'local')) \n";
}
else {
$sql .= "AND direction = 'inbound') \n";
$sql .= "and direction = 'inbound') \n";
}
$sql .= "AS answered, \n";
$sql .= "COUNT(*) \n";
$sql .= "FILTER( \n";
$sql .= " WHERE (( \n";
$sql .= "count(*) \n";
$sql .= "filter( \n";
$sql .= " where (( \n";
$sql .= " c.caller_id_number = e.extension \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.extension) \n";
$sql .= " OR (\n";
$sql .= " e.number_alias IS NOT NULL \n";
$sql .= " AND ( \n";
$sql .= " or (\n";
$sql .= " e.number_alias is not null \n";
$sql .= " and ( \n";
$sql .= " c.caller_id_number = e.number_alias \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.number_alias))) \n";
$sql .= " AND ( \n";
$sql .= " and ( \n";
$sql .= " c.answer_stamp IS NULL \n";
$sql .= " AND \n";
$sql .= " and \n";
$sql .= " c.bridge_uuid IS NULL) \n";
if ($this->include_internal) {
$sql .= " AND (direction = 'inbound' OR direction = 'outbound'))";
$sql .= " and (direction = 'inbound' or direction = 'outbound'))";
} else {
$sql .= " AND direction = 'inbound')";
$sql .= " and direction = 'inbound')";
}
$sql .= "AS missed, \n";
$sql .= "as missed, \n";
$sql .= "COUNT(*) \n";
$sql .= "FILTER( \n";
$sql .= " WHERE (( \n";
$sql .= "count(*) \n";
$sql .= "filter( \n";
$sql .= " where (( \n";
$sql .= " c.caller_id_number = e.extension \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.extension) \n";
$sql .= " OR ( \n";
$sql .= " e.number_alias IS NOT NULL \n";
$sql .= " AND ( \n";
$sql .= " or ( \n";
$sql .= " e.number_alias is not null \n";
$sql .= " and ( \n";
$sql .= " c.caller_id_number = e.number_alias \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.number_alias))) \n";
$sql .= " AND c.hangup_cause = 'NO_ANSWER' \n";
$sql .= " and c.hangup_cause = 'NO_ANSWER' \n";
if ($this->include_internal) {
$sql .= " AND (direction = 'inbound' OR direction = 'local') \n";
$sql .= " and (direction = 'inbound' or direction = 'local') \n";
}
else {
$sql .= "AND direction = 'inbound' \n";
$sql .= "and direction = 'inbound' \n";
}
$sql .= ") AS no_answer, \n";
$sql .= ") as no_answer, \n";
$sql .= "COUNT(*) \n";
$sql .= "FILTER( \n";
$sql .= " WHERE (( \n";
$sql .= "count(*) \n";
$sql .= "filter( \n";
$sql .= " where (( \n";
$sql .= " c.caller_id_number = e.extension \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.extension) \n";
$sql .= " OR ( \n";
$sql .= " e.number_alias IS NOT NULL \n";
$sql .= " AND ( \n";
$sql .= " or ( \n";
$sql .= " e.number_alias is not null \n";
$sql .= " and ( \n";
$sql .= " c.caller_id_number = e.number_alias \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.number_alias))) \n";
$sql .= " AND \n";
$sql .= " and \n";
$sql .= " c.hangup_cause = 'USER_BUSY' \n";
if ($this->include_internal) {
$sql .= " AND (direction = 'inbound' OR direction = 'local')) \n";
$sql .= " and (direction = 'inbound' or direction = 'local')) \n";
}
else {
$sql .= " AND direction = 'inbound') \n";
$sql .= " and direction = 'inbound') \n";
}
$sql .= "AS busy, \n";
$sql .= "as busy, \n";
$sql .= "SUM(c.billsec) \n";
$sql .= "FILTER ( \n";
$sql .= " WHERE (( \n";
$sql .= "sum(c.billsec) \n";
$sql .= "filter ( \n";
$sql .= " where (( \n";
$sql .= " c.caller_id_number = e.extension \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.extension) \n";
$sql .= " OR ( \n";
$sql .= " e.number_alias IS NOT NULL \n";
$sql .= " AND ( \n";
$sql .= " or ( \n";
$sql .= " e.number_alias is not null \n";
$sql .= " and ( \n";
$sql .= " c.caller_id_number = e.number_alias \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.number_alias))) \n";
if ($this->include_internal) {
$sql .= " AND (direction = 'inbound' OR direction = 'outbound') \n";
$sql .= " and (direction = 'inbound' or direction = 'outbound') \n";
}
$sql .= " ) / \n";
$sql .= "COUNT(*) \n";
$sql .= "FILTER ( \n";
$sql .= " WHERE (( \n";
$sql .= "count(*) \n";
$sql .= "filter ( \n";
$sql .= " where (( \n";
$sql .= " c.caller_id_number = e.extension \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.extension) \n";
$sql .= " OR ( \n";
$sql .= " e.number_alias IS NOT NULL \n";
$sql .= " AND ( \n";
$sql .= " or ( \n";
$sql .= " e.number_alias is not null \n";
$sql .= " and ( \n";
$sql .= " c.caller_id_number = e.number_alias \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.number_alias))) \n";
if ($this->include_internal) {
$sql .= " AND (direction = 'inbound' OR direction = 'outbound') \n";
$sql .= " and (direction = 'inbound' or direction = 'outbound') \n";
}
$sql .= " ) AS aloc, \n";
$sql .= " ) as aloc, \n";
$sql .= "COUNT(*) \n";
$sql .= "FILTER ( \n";
$sql .= " WHERE (( \n";
$sql .= "count(*) \n";
$sql .= "filter ( \n";
$sql .= " where (( \n";
$sql .= " c.caller_id_number = e.extension \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.extension) \n";
$sql .= " OR ( \n";
$sql .= " e.number_alias IS NOT NULL \n";
$sql .= " AND ( \n";
$sql .= " or ( \n";
$sql .= " e.number_alias is not null \n";
$sql .= " and ( \n";
$sql .= " c.caller_id_number = e.number_alias \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.number_alias))) \n";
if ($this->include_internal) {
$sql .= " AND (direction = 'inbound' OR direction = 'local')) \n";
$sql .= " and (direction = 'inbound' or direction = 'local')) \n";
}
else {
$sql .= " AND direction = 'inbound') \n";
$sql .= " and direction = 'inbound') \n";
}
$sql .= "AS inbound_calls, \n";
$sql .= "as inbound_calls, \n";
$sql .= "SUM(c.billsec) \n";
$sql .= "FILTER ( \n";
$sql .= " WHERE (( \n";
$sql .= "sum(c.billsec) \n";
$sql .= "filter ( \n";
$sql .= " where (( \n";
$sql .= " c.caller_id_number = e.extension \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.extension) \n";
$sql .= " OR ( \n";
$sql .= " e.number_alias IS NOT NULL \n";
$sql .= " AND ( \n";
$sql .= " or ( \n";
$sql .= " e.number_alias is not null \n";
$sql .= " and ( \n";
$sql .= " c.caller_id_number = e.number_alias \n";
$sql .= " OR \n";
$sql .= " or \n";
$sql .= " c.destination_number = e.number_alias))) \n";
if ($this->include_internal) {
$sql .= " AND (direction = 'inbound' OR direction = 'local')) \n";
$sql .= " and (direction = 'inbound' or direction = 'local')) \n";
}
else {
$sql .= " AND direction = 'inbound') \n";
$sql .= " and direction = 'inbound') \n";
}
$sql .= "AS inbound_duration, \n";
$sql .= "as inbound_duration, \n";
$sql .= "COUNT(*) \n";
$sql .= "FILTER ( \n";
$sql .= " WHERE c.extension_uuid = e.extension_uuid \n";
$sql .= " AND c.direction = 'outbound' \n";
$sql .= "count(*) \n";
$sql .= "filter ( \n";
$sql .= " where c.extension_uuid = e.extension_uuid \n";
$sql .= " and c.direction = 'outbound' \n";
$sql .= ") \n";
$sql .= "AS outbound_calls, \n";
$sql .= "as outbound_calls, \n";
$sql .= "SUM(c.billsec) \n";
$sql .= "FILTER ( \n";
$sql .= " WHERE c.extension_uuid = e.extension_uuid \n";
$sql .= " AND c.direction = 'outbound' \n";
$sql .= "sum(c.billsec) \n";
$sql .= "filter ( \n";
$sql .= " where c.extension_uuid = e.extension_uuid \n";
$sql .= " and c.direction = 'outbound' \n";
$sql .= ") \n";
$sql .= "AS outbound_duration, \n";
$sql .= "as outbound_duration, \n";
$sql .= "e.description \n";
$sql .= "FROM v_extensions AS e, v_domains AS d, \n";
$sql .= "from v_extensions as e, v_domains as d, \n";
$sql .= "( SELECT \n";
$sql .= " domain_uuid, \n";
$sql .= " extension_uuid, \n";
@ -1066,18 +1066,18 @@ if (!class_exists('xml_cdr')) {
$sql .= " start_stamp, \n";
$sql .= " hangup_cause, \n";
$sql .= " billsec \n";
$sql .= " FROM v_xml_cdr \n";
$sql .= " WHERE domain_uuid = :domain_uuid \n";
$sql .= " from v_xml_cdr \n";
$sql .= " where domain_uuid = :domain_uuid \n";
$sql .= $sql_date_range;
$sql .= ") AS c \n";
$sql .= ") as c \n";
$sql .= "WHERE \n";
$sql .= "where \n";
$sql .= "d.domain_uuid = e.domain_uuid \n";
if (!($_GET['showall'] && permission_exists('xml_cdr_all'))) {
$sql .= "AND e.domain_uuid = :domain_uuid \n";
$sql .= "and e.domain_uuid = :domain_uuid \n";
}
$sql .= "GROUP BY e.extension, e.domain_uuid, d.domain_uuid, e.number_alias, e.description \n";
$sql .= "ORDER BY extension ASC \n";
$sql .= "group by e.extension, e.domain_uuid, d.domain_uuid, e.number_alias, e.description \n";
$sql .= "order by extension asc \n";
$parameters['domain_uuid'] = $this->domain_uuid;
$database = new database;
@ -1161,4 +1161,4 @@ if (!class_exists('xml_cdr')) {
$cdr->read_files();
*/
?>
?>