diff --git a/www/vicidial/AST_campaign_status_list_report.php b/www/vicidial/AST_campaign_status_list_report.php index 86a2f5da..cc786ba3 100644 --- a/www/vicidial/AST_campaign_status_list_report.php +++ b/www/vicidial/AST_campaign_status_list_report.php @@ -11,6 +11,7 @@ # 110815-2138 - First build # 120224-0910 - Added HTML display option with bar graphs # 130414-0129 - Added report logging +# 130425-2113 - Added status flag summaries and other formatting cleanup # $startMS = microtime(); @@ -162,7 +163,7 @@ while($i < $group_ct) $i++; } -$stmt="select campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; +$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; $rslt=mysql_query($stmt, $link); if ($DB) {$HTML_text.="$stmt\n";} $campaigns_to_print = mysql_num_rows($rslt); @@ -300,17 +301,25 @@ $JS_onload="onload = function() {\n"; while($i < $group_ct) { - $stmt="select distinct status, status_name from vicidial_campaign_statuses where campaign_id='$group[$i]' UNION select distinct status, status_name from vicidial_statuses order by status, status_name"; + $stmt="SELECT status, status_name, human_answered, sale, dnc, customer_contact, not_interested, unworkable, scheduled_callback, completed from vicidial_campaign_statuses where campaign_id='$group[$i]' UNION SELECT status, status_name, human_answered, sale, dnc, customer_contact, not_interested, unworkable, scheduled_callback, completed from vicidial_statuses order by status, status_name"; $rslt=mysql_query($stmt, $link); while ($row=mysql_fetch_row($rslt)) { - $status_ary[$row[0]]=" - $row[1]"; + $status_ary[$row[0]] = " - $row[1]"; + $HA_ary[$row[0]] = $row[2]; + $SALE_ary[$row[0]] = $row[3]; + $DNC_ary[$row[0]] = $row[4]; + $CC_ary[$row[0]] = $row[5]; + $NI_ary[$row[0]] = $row[6]; + $UW_ary[$row[0]] = $row[7]; + $SC_ary[$row[0]] = $row[8]; + $COMP_ary[$row[0]] = $row[9]; } $ASCII_text.="CAMPAIGN: $group[$i]\n"; $GRAPH.="CAMPAIGN: $group[$i]\n"; $CSV_text.="\"CAMPAIGN: $group[$i]\"\n"; - $stmt="select closer_campaigns from vicidial_campaigns where campaign_id='$group[$i]'"; + $stmt="SELECT closer_campaigns from vicidial_campaigns where campaign_id='$group[$i]'"; $rslt=mysql_query($stmt, $link); if (mysql_num_rows($rslt)>0) { @@ -327,20 +336,30 @@ while($i < $group_ct) } } - $stmt="select distinct list_id, list_name from vicidial_lists where campaign_id='$group[$i]' order by list_id, list_name asc"; + $stmt="SELECT distinct list_id, list_name, active from vicidial_lists where campaign_id='$group[$i]' order by list_id, list_name asc"; $rslt=mysql_query($stmt, $link); while ($row=mysql_fetch_row($rslt)) { - $list_id=$row[0]; $list_name=$row[1]; + $list_id=$row[0]; $list_name=$row[1]; $list_active=$row[2]; + $HA_count=0; + $SALE_count=0; + $DNC_count=0; + $CC_count=0; + $NI_count=0; + $UW_count=0; + $SC_count=0; + $COMP_count=0; + $dispo_ary=""; $ASCII_text.="List ID #$list_id: $list_name\n"; $GRAPH.="List ID #$list_id: $list_name\n"; $CSV_text.="\"List ID #$list_id: $list_name\"\n"; - # $stat_stmt="select vs.status_name, count(*), sum(pause_sec), sum(wait_sec), sum(talk_sec), sum(dispo_sec), sum(dead_sec) from vicidial_agent_log val, vicidial_list vl, vicidial_statuses vs where val.event_time>='$query_date' and val.event_time<='$end_date' and val.campaign_id='$group[$i]' and val.lead_id=vl.list_id and vl.list_id='$list_id' and val.status=vs.status group by vs.status_name order by vs.status_name"; - #$stat_stmt="select val.status, count(*), sum(pause_sec), sum(wait_sec), sum(talk_sec), sum(dispo_sec), sum(dead_sec) from vicidial_agent_log val, vicidial_list vl where val.event_time>='$query_date' and val.event_time<='$end_date' and val.campaign_id='$group[$i]' and val.lead_id=vl.lead_id and vl.list_id='$list_id' group by val.status order by val.status"; - $stat_stmt="select vicidial_log.status, vicidial_log.uniqueid, vicidial_log.length_in_sec as duration, (vicidial_agent_log.talk_sec-vicidial_agent_log.dead_sec) as handle_time from vicidial_log LEFT OUTER JOIN vicidial_agent_log on vicidial_log.lead_id=vicidial_agent_log.lead_id and vicidial_log.uniqueid=vicidial_agent_log.uniqueid where vicidial_log.call_date>='$query_date' and vicidial_log.call_date<='$end_date' and vicidial_log.list_id='$list_id' UNION select vicidial_closer_log.status, vicidial_closer_log.uniqueid, vicidial_closer_log.length_in_sec as duration, (vicidial_agent_log.talk_sec-vicidial_agent_log.dead_sec) as handle_time from vicidial_closer_log LEFT OUTER JOIN vicidial_agent_log on vicidial_closer_log.lead_id=vicidial_agent_log.lead_id and vicidial_closer_log.uniqueid=vicidial_agent_log.uniqueid where call_date>='$query_date' and call_date<='$end_date' and list_id='$list_id' order by status"; + # $stat_stmt="SELECT vs.status_name, count(*), sum(pause_sec), sum(wait_sec), sum(talk_sec), sum(dispo_sec), sum(dead_sec) from vicidial_agent_log val, vicidial_list vl, vicidial_statuses vs where val.event_time>='$query_date' and val.event_time<='$end_date' and val.campaign_id='$group[$i]' and val.lead_id=vl.list_id and vl.list_id='$list_id' and val.status=vs.status group by vs.status_name order by vs.status_name"; + #$stat_stmt="SELECT val.status, count(*), sum(pause_sec), sum(wait_sec), sum(talk_sec), sum(dispo_sec), sum(dead_sec) from vicidial_agent_log val, vicidial_list vl where val.event_time>='$query_date' and val.event_time<='$end_date' and val.campaign_id='$group[$i]' and val.lead_id=vl.lead_id and vl.list_id='$list_id' group by val.status order by val.status"; + $stat_stmt="SELECT vicidial_log.status, vicidial_log.uniqueid, vicidial_log.length_in_sec as duration, (vicidial_agent_log.talk_sec-vicidial_agent_log.dead_sec) as handle_time from vicidial_log LEFT OUTER JOIN vicidial_agent_log on vicidial_log.lead_id=vicidial_agent_log.lead_id and vicidial_log.uniqueid=vicidial_agent_log.uniqueid where vicidial_log.call_date>='$query_date' and vicidial_log.call_date<='$end_date' and vicidial_log.list_id='$list_id' UNION SELECT vicidial_closer_log.status, vicidial_closer_log.uniqueid, vicidial_closer_log.length_in_sec as duration, (vicidial_agent_log.talk_sec-vicidial_agent_log.dead_sec) as handle_time from vicidial_closer_log LEFT OUTER JOIN vicidial_agent_log on vicidial_closer_log.lead_id=vicidial_agent_log.lead_id and vicidial_closer_log.uniqueid=vicidial_agent_log.uniqueid where call_date>='$query_date' and call_date<='$end_date' and list_id='$list_id' order by status"; + if ($DB) {$HTML_text.="|$stat_stmt|\n";} # $ASCII_text.=$stat_stmt."\n"; $stat_rslt=mysql_query($stat_stmt, $link); if (mysql_num_rows($stat_rslt)>0) @@ -360,9 +379,9 @@ while($i < $group_ct) $max_duration=1; $max_handletime=1; - $ASCII_text.="+-------------------------------------+-------+-----------+-------------+\n"; - $ASCII_text.="| DISPOSITION | CALLS | DURATION | HANDLE TIME |\n"; - $ASCII_text.="+-------------------------------------+-------+-----------+-------------+\n"; + $ASCII_text.="+------------------------------------------+--------+------------+-------------+\n"; + $ASCII_text.="| DISPOSITION | CALLS | DURATION | HANDLE TIME |\n"; + $ASCII_text.="+------------------------------------------+--------+------------+-------------+\n"; $CSV_text.="\"DISPOSITION\",\"CALLS\",\"DURATION\",\"HANDLE TIME\"\n"; while ($stat_row=mysql_fetch_row($stat_rslt)) { @@ -377,14 +396,22 @@ while($i < $group_ct) $total_calls++; $total_duration+=$stat_row[2]; $total_handle_time+=$stat_row[3]; + if ($HA_ary[$stat_row[0]]=="Y") {$HA_count++;} + if ($SALE_ary[$stat_row[0]]=="Y") {$SALE_count++;} + if ($DNC_ary[$stat_row[0]]=="Y") {$DNC_count++;} + if ($CC_ary[$stat_row[0]]=="Y") {$CC_count++;} + if ($NI_ary[$stat_row[0]]=="Y") {$NI_count++;} + if ($UW_ary[$stat_row[0]]=="Y") {$UW_count++;} + if ($SC_ary[$stat_row[0]]=="Y") {$SC_count++;} + if ($COMP_ary[$stat_row[0]]=="Y") {$COMP_count++;} } $d=0; while (list($key, $val)=each($dispo_ary)) { - $ASCII_text.="| ".sprintf("%-35s", $key.$status_ary[$key]); - $ASCII_text.=" | ".sprintf("%5s", $val[0]); - $ASCII_text.=" | ".sprintf("%9s", sec_convert($val[1], 'H')); + $ASCII_text.="| ".sprintf("%-40s", $key.$status_ary[$key]); + $ASCII_text.=" | ".sprintf("%6s", $val[0]); + $ASCII_text.=" | ".sprintf("%10s", sec_convert($val[1], 'H')); $ASCII_text.=" | ".sprintf("%11s", sec_convert($val[2], 'H'))." |\n"; $CSV_text.="\"".$key.$status_ary[$key]."\",\"$val[0]\",\"".sec_convert($val[1], 'H')."\",\"".sec_convert($val[2], 'H')."\"\n"; @@ -397,20 +424,61 @@ while($i < $group_ct) $graph_stats[$d][3]=$val[2]; $d++; } - $ASCII_text.="+-------------------------------------+-------+-----------+-------------+\n"; - $ASCII_text.="| TOTALS:"; - $ASCII_text.=" | ".sprintf("%5s", $total_calls); - $ASCII_text.=" | ".sprintf("%9s", sec_convert($total_duration, 'H')); + $ASCII_text.="+------------------------------------------+--------+------------+-------------+\n"; + $ASCII_text.="| TOTALS:"; + $ASCII_text.=" | ".sprintf("%6s", $total_calls); + $ASCII_text.=" | ".sprintf("%10s", sec_convert($total_duration, 'H')); $ASCII_text.=" | ".sprintf("%11s", sec_convert($total_handle_time, 'H'))." |\n"; - $ASCII_text.="+-------------------------------------+-------+-----------+-------------+\n"; + $ASCII_text.="+------------------------------------------+--------+------------+-------------+\n"; $CSV_text.="\"TOTALS:\",\"$total_calls\",\"".sec_convert($total_duration, 'H')."\",\"".sec_convert($total_handle_time, 'H')."\"\n\n"; - for ($d=0; $d6) {$HA_percent = substr("$HA_percent", 0, -1);} + $SALE_percent = sprintf("%6.2f", 100*($SALE_count/$total_calls)); while(strlen($SALE_percent)>6) {$SALE_percent = substr("$SALE_percent", 0, -1);} + $DNC_percent = sprintf("%6.2f", 100*($DNC_count/$total_calls)); while(strlen($DNC_percent)>6) {$DNC_percent = substr("$DNC_percent", 0, -1);} + $CC_percent = sprintf("%6.2f", 100*($CC_count/$total_calls)); while(strlen($CC_percent)>6) {$CC_percent = substr("$CC_percent", 0, -1);} + $NI_percent = sprintf("%6.2f", 100*($NI_count/$total_calls)); while(strlen($NI_percent)>6) {$NI_percent = substr("$NI_percent", 0, -1);} + $UW_percent = sprintf("%6.2f", 100*($UW_count/$total_calls)); while(strlen($UW_percent)>6) {$UW_percent = substr("$UW_percent", 0, -1);} + $SC_percent = sprintf("%6.2f", 100*($SC_count/$total_calls)); while(strlen($SC_percent)>6) {$SC_percent = substr("$SC_percent", 0, -1);} + $COMP_percent = sprintf("%6.2f", 100*($COMP_count/$total_calls)); while(strlen($COMP_percent)>6) {$COMP_percent = substr("$COMP_percent", 0, -1);} + + $HA_count = sprintf("%9s", "$HA_count"); while(strlen($HA_count)>9) {$HA_count = substr("$HA_count", 0, -1);} + $SALE_count = sprintf("%9s", "$SALE_count"); while(strlen($SALE_count)>9) {$SALE_count = substr("$SALE_count", 0, -1);} + $DNC_count = sprintf("%9s", "$DNC_count"); while(strlen($DNC_count)>9) {$DNC_count = substr("$DNC_count", 0, -1);} + $CC_count = sprintf("%9s", "$CC_count"); while(strlen($CC_count)>9) {$CC_count = substr("$CC_count", 0, -1);} + $NI_count = sprintf("%9s", "$NI_count"); while(strlen($NI_count)>9) {$NI_count = substr("$NI_count", 0, -1);} + $UW_count = sprintf("%9s", "$UW_count"); while(strlen($UW_count)>9) {$UW_count = substr("$UW_count", 0, -1);} + $SC_count = sprintf("%9s", "$SC_count"); while(strlen($SC_count)>9) {$SC_count = substr("$SC_count", 0, -1);} + $COMP_count = sprintf("%9s", "$COMP_count"); while(strlen($COMP_count)>9) {$COMP_count = substr("$COMP_count", 0, -1);} + + if ($list_active=='Y') {$list_active = 'ACTIVE ';} else {$list_active = 'INACTIVE';} + $header_list_id = "$list_id - $list_name"; + $header_list_id = sprintf("%-51s", $header_list_id); while(strlen($header_list_id)>51) {$header_list_id = substr("$header_list_id", 0, -1);} + $header_list_count = sprintf("%10s", $total_calls); while(strlen($header_list_count)>10) {$header_list_count = substr("$header_list_count", 0, -1);} + $ASCII_text .= "\n"; + $ASCII_text .= "+--------------------------------------------------------------+\n"; + $ASCII_text .= "| $header_list_id $list_active |\n"; + $ASCII_text .= "| TOTAL CALLS: $header_list_count |\n"; + $ASCII_text .= "+--------------------------------------------------------------+\n"; + $ASCII_text .= "| STATUS FLAGS BREAKDOWN: (and % of total leads in the list) |\n"; + $ASCII_text .= "| Human Answer: $HA_count $HA_percent% |\n"; + $ASCII_text .= "| Sale: $SALE_count $SALE_percent% |\n"; + $ASCII_text .= "| DNC: $DNC_count $DNC_percent% |\n"; + $ASCII_text .= "| Customer Contact: $CC_count $CC_percent% |\n"; + $ASCII_text .= "| Not Interested: $NI_count $NI_percent% |\n"; + $ASCII_text .= "| Unworkable: $UW_count $UW_percent% |\n"; + $ASCII_text .= "| Scheduled callbk: $SC_count $SC_percent% |\n"; + $ASCII_text .= "| Completed: $COMP_count $COMP_percent% |\n"; + $ASCII_text .= "+--------------------------------------------------------------+\n"; + + + for ($d=0; $d".$graph_stats[$d][0]."".$graph_stats[$d][1].""; $DURATION_graph.=" ".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][2], 'H').""; $HANDLETIME_graph.=" ".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][3], 'H').""; - } + } $CALLS_graph.="TOTAL:".trim($total_calls).""; $DURATION_graph.="TOTAL:".sec_convert($total_duration, 'H').""; $HANDLETIME_graph.="TOTAL:".sec_convert($total_handle_time, 'H').""; @@ -439,7 +507,6 @@ while($i < $group_ct) } $ASCII_text.="\n"; $GRAPH.="\n"; - } $i++; $ASCII_text.="\n\n";