diff --git a/agc_2-X/trunk/www/vicidial/admin.php b/agc_2-X/trunk/www/vicidial/admin.php index 4ace578e..f0f23793 100644 --- a/agc_2-X/trunk/www/vicidial/admin.php +++ b/agc_2-X/trunk/www/vicidial/admin.php @@ -10375,6 +10375,7 @@ if ($ADD==999999)
  • CLOSER REPORT
  • AGENT PERFORMANCE
  • AGENT PERFORMANCE DETAIL +
  • AGENT SPREADSHEET PERFORMANCE
  • SERVER PERFORMANCE 0) diff --git a/agc_2-X/trunk/www/vicidial/spreadsheet_sales_viewer.pl b/agc_2-X/trunk/www/vicidial/spreadsheet_sales_viewer.pl new file mode 100644 index 00000000..cd42aa44 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/spreadsheet_sales_viewer.pl @@ -0,0 +1,385 @@ +#!/usr/bin/perl + +### spreadsheet_sales_viewer.pl version 2.0.4 *DBI-version* +### +### Copyright (C) 2007 Joe Johnson,Matt Florell LICENSE: GPLv2 +### +# +# +# CHANGES +# 70521-1734 - First build +# 70522-1554 - Changed to use DBI instead of Net::MySQL +# + +use Spreadsheet::WriteExcel; +use Time::Local; +use DBI; + +# default path to astguiclient configuration file: +$PATHconf = '/etc/astguiclient.conf'; + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) + {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) + {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} + if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) + {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} + if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) + {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} + if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) + {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + $i++; + } + +# Customized Variables +$server_ip = $VARserver_ip; # Asterisk server IP + +if (!$VARDB_port) {$VARDB_port='3306';} + +$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +$list_ids=$ARGV[0]; +$sales_number=$ARGV[1]; +$timestamp=$ARGV[2]; +$forc=$ARGV[3]; +$now=$ARGV[4]; +$dcampaign=$ARGV[5]; + +$list_id_clause="and v.list_id in ("; +@lists=split(/\,/, $list_ids); +for ($i=0; $i0)) { $list_id_clause.="$lists[$i], "; } +} +$list_id_clause=substr($list_id_clause, 0, -2); +$list_id_clause.=")"; + + +if ($sales_number==0) {undef $sales_number;} + + +$xl = Spreadsheet::WriteExcel->new("$PATHweb/vicidial/vicidial_closer_report_$now.xls"); +$xlsheet = $xl->add_worksheet(); +$xlsheet->set_landscape(); +$rptheader = $xl->add_format(); # Add a format +$rptheader->set_bold(); +$rptheader->set_size('8'); +$rptheader->set_color('10'); +$rptheader->set_align('center'); + +$rptheaderLEFT = $xl->add_format(); # Add a format +$rptheaderLEFT->set_bold(); +$rptheaderLEFT->set_size('8'); +$rptheaderLEFT->set_color('10'); +$rptheaderLEFT->set_align('left'); + +$normcell = $xl->add_format(); # Add a format +$normcell->set_size('8'); +$normcell->set_align('center'); +$normcell->set_bg_color('22'); + +$boldcell = $xl->add_format(); # Add a format +$boldcell->set_bold(); +$boldcell->set_size('8'); +$boldcell->set_align('center'); +$boldcell->set_bg_color('22'); + +$dollarformat = $xl->add_format(); # Add a format +$dollarformat->set_size('8'); +$dollarformat->set_num_format('$0.00'); + +$intformat = $xl->add_format(); # Add a format +$intformat->set_size('8'); +$intformat->set_num_format('0'); + +$numberformat = $xl->add_format(); # Add a format +$numberformat->set_size('8'); +$numberformat->set_num_format('0.00'); + +$pformat = $xl->add_format(); # Add a format +$pformat->set_size('8'); +$pformat->set_num_format('0.00%'); + +$p2format = $xl->add_format(); # Add a format +$p2format->set_size('8'); +$p2format->set_num_format('0%'); + +$statcell = $xl->add_format(num_format => '@'); # Add a format +$statcell->set_size('8'); + +$countcell = $xl->add_format(); # Add a format +$countcell->set_size('8'); +$countcell->set_bg_color('35'); + +$terminateheader = $xl->add_format(); # Add a format +$terminateheader->set_bold(); +$terminateheader->set_size('8'); +$terminateheader->set_color('10'); +$terminateheader->set_num_format('0.00'); + +$xlsheet->write("B1", "Closer stats", $rptheader); +$xlsheet->write("D1", "$dcampaign", $rptheaderLEFT); +$xlsheet->write("F1", "$list_ids", $rptheaderLEFT); +$xlsheet->write("A2", "Closer Name", $rptheader); +$xlsheet->write("B2", "# of calls", $rptheader); +$xlsheet->write("C2", "# of sales", $rptheader); +$xlsheet->write("D2", "Sales percentage", $rptheader); +$xlsheet->write("E2", "Calls per hour", $rptheader); +$xlsheet->write("F2", "Sales per hour", $rptheader); +$xlsheet->write("G2", "Total time in system", $rptheader); + +%closers=(); +%fronters=(); + + + +# Non-transfer +$sales=0; +$stmtA = "select v.status, u.full_name, u.user from vicidial_users u, vicidial_list v, vicidial_log vl where vl.call_date>='$timestamp' and vl.call_date<='$now' and vl.lead_id=v.lead_id $list_id_clause and vl.user=u.user;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +$rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + if (length($sales_number)==0 || $sales<$sales_number) + { + $closers{"$aryA[1]"}[0]++; + $fronters{"$aryA[1]"}[0]++; + if ($aryA[0] eq "SALE") + { + $sales++; + $closers{"$aryA[1]"}[1]++; + $fronters{"$aryA[1]"}[1]++; + } + } + $closers{"$aryA[1]"}[2]=$aryA[2]; + $fronters{"$aryA[1]"}[2]=$aryA[2]; + $rec_count++; + } +$sthA->finish(); + + +if ($forc eq "F") { + %closers=(); + + $sales=0; + $stmtA = "select v.status, u.full_name, u.user from vicidial_list v, vicidial_users u, vicidial_xfer_log vl where vl.call_date>='$timestamp' and vl.call_date<='$now' and vl.lead_id=v.lead_id $list_id_clause and vl.closer=u.user;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + if (!$sales_number || $sales<$sales_number) + { + $closers{"$aryA[1]"}[0]++; + if ($aryA[0] eq "SALE") + { + $sales++; + $closers{"$aryA[1]"}[1]++; + } + } + $closers{"$aryA[1]"}[2]=$aryA[2]; + $rec_count++; + } + $sthA->finish(); +} + + +$x=3; +$grand_total_time=0; +foreach $closername (sort(keys(%closers))) +{ + $closers{$closername}[0]+=0; + $closers{$closername}[1]+=0; + + $stmtA = "select sum(pause_sec+wait_sec+talk_sec), sec_to_time(sum(pause_sec+wait_sec+talk_sec)) from vicidial_agent_log where user=".$closers{$closername}[2]." and event_time>='$timestamp' and event_time<='$now' and pause_sec<28800 and wait_sec<28800 and talk_sec<28800;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $hours=($aryA[0]/3600); + $grand_total_time+=$aryA[0]; + $total_time=$aryA[1]; + $rec_count++; + } + $sthA->finish(); + $xlsheet->write("A$x", "$closername", $normcell); + $xlsheet->write("B$x", "=$closers{$closername}[0]+0", $intformat); + $xlsheet->write("C$x", "=$closers{$closername}[1]+0", $intformat); + $xlsheet->write("D$x", "=C$x/B$x", $pformat); + $xlsheet->write("E$x", "=B$x/$hours", $numberformat); + $xlsheet->write("F$x", "=C$x/$hours", $numberformat); + $xlsheet->write("G$x", "$total_time", $normcell); + $x++; +} +$hours=($grand_total_time/3600); + +$stmtA = "select sec_to_time($grand_total_time)"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +$rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $grand_total_time=$aryA[0]; + $rec_count++; + } +$sthA->finish(); + + +$y=($x+1); +$xlsheet->write("A$y", "Grand Total", $boldcell); +$xlsheet->write("B$y", "=SUM(B3:B$x)", $intformat); +$xlsheet->write("C$y", "=SUM(C3:C$x)", $intformat); +$xlsheet->write("D$y", "=C$y/B$y", $pformat); +$xlsheet->write("E$y", "=B$y/$hours", $numberformat); +$xlsheet->write("F$y", "=C$y/$hours", $numberformat); +$xlsheet->write("G$y", "$grand_total_time", $normcell); +$xl->close(); + + +if ($forc eq "F") { + $xl = Spreadsheet::WriteExcel->new("$PATHweb/vicidial/vicidial_fronter_report_$now.xls"); + $xlsheet = $xl->add_worksheet(); + $xlsheet->set_landscape(); + $rptheader = $xl->add_format(); # Add a format + $rptheader->set_bold(); + $rptheader->set_size('8'); + $rptheader->set_color('10'); + $rptheader->set_align('center'); + + $normcell = $xl->add_format(); # Add a format + $normcell->set_size('8'); + $normcell->set_align('center'); + $normcell->set_bg_color('22'); + + $boldcell = $xl->add_format(); # Add a format + $boldcell->set_bold(); + $boldcell->set_size('8'); + $boldcell->set_align('center'); + $boldcell->set_bg_color('22'); + + $dollarformat = $xl->add_format(); # Add a format + $dollarformat->set_size('8'); + $dollarformat->set_num_format('$0.00'); + + $intformat = $xl->add_format(); # Add a format + $intformat->set_size('8'); + $intformat->set_num_format('0'); + + $numberformat = $xl->add_format(); # Add a format + $numberformat->set_size('8'); + $numberformat->set_num_format('0.00'); + + $pformat = $xl->add_format(); # Add a format + $pformat->set_size('8'); + $pformat->set_num_format('0.00%'); + + $statcell = $xl->add_format(num_format => '@'); # Add a format + $statcell->set_size('8'); + + $countcell = $xl->add_format(); # Add a format + $countcell->set_size('8'); + $countcell->set_bg_color('35'); + + $terminateheader = $xl->add_format(); # Add a format + $terminateheader->set_bold(); + $terminateheader->set_size('8'); + $terminateheader->set_color('10'); + $terminateheader->set_num_format('0.00'); + + $xlsheet->write("D1", "Fronter stats", $rptheader); + $xlsheet->write("A2", "Fronter Name", $rptheader); + $xlsheet->write("B2", "# of calls", $rptheader); + $xlsheet->write("C2", "# of sales", $rptheader); + $xlsheet->write("D2", "Sales percentage", $rptheader); + $xlsheet->write("E2", "Calls per hour", $rptheader); + $xlsheet->write("F2", "Sales per hour", $rptheader); + $xlsheet->write("G2", "Total time in system", $rptheader); + + $x=3; + $grand_total_time=0; + foreach $tsrname (sort(keys(%fronters))) { + $fronters{$tsrname}[0]+=0; + $fronters{$tsrname}[1]+=0; + $stmtA = "select sum(pause_sec+wait_sec+talk_sec), sec_to_time(sum(pause_sec+wait_sec+talk_sec)) from vicidial_agent_log where user=".$fronters{$tsrname}[2]." and event_time>='$timestamp' and event_time<='$now' and pause_sec<28800 and wait_sec<28800 and talk_sec<28800;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $hours=($aryA[0]/3600); + $grand_total_time+=$aryA[0]; + $total_time=$aryA[1]; + $rec_count++; + } + $sthA->finish(); + + $xlsheet->write("A$x", "$tsrname", $normcell); + $xlsheet->write("B$x", "=$fronters{$tsrname}[0]+0", $intformat); + $xlsheet->write("C$x", "=$fronters{$tsrname}[1]+0", $intformat); + $xlsheet->write("D$x", "=C$x/B$x", $pformat); + $xlsheet->write("E$x", "=B$x/$hours", $numberformat); + $xlsheet->write("F$x", "=C$x/$hours", $numberformat); + $xlsheet->write("G$x", "$total_time", $normcell); + $x++; + } + $hours=($grand_total_time/3600); + + $stmtA = "select sec_to_time($grand_total_time)"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $grand_total_time=$aryA[0]; + $rec_count++; + } + $sthA->finish(); + + $y=($x+1); + $xlsheet->write("A$y", "Grand Total", $boldcell); + $xlsheet->write("B$y", "=SUM(B3:B$x)", $intformat); + $xlsheet->write("C$y", "=SUM(C3:C$x)", $intformat); + $xlsheet->write("D$y", "=C$y/B$y", $pformat); + $xlsheet->write("E$y", "=B$y/$hours", $numberformat); + $xlsheet->write("F$y", "=C$y/$hours", $numberformat); + $xlsheet->write("G$y", "$grand_total_time", $normcell); + + $xl->close(); +} + diff --git a/agc_2-X/trunk/www/vicidial/vicidial_sales_viewer.php b/agc_2-X/trunk/www/vicidial/vicidial_sales_viewer.php new file mode 100644 index 00000000..744ec29f --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/vicidial_sales_viewer.php @@ -0,0 +1,221 @@ + LICENSE: GPLv2 +# + + +if (isset($_GET["dcampaign"])) {$dcampaign=$_GET["dcampaign"];} + elseif (isset($_POST["dcampaign"])) {$dcampaign=$_POST["dcampaign"];} +if (isset($_GET["submit_report"])) {$submit_report=$_GET["submit_report"];} + elseif (isset($_POST["submit_report"])) {$submit_report=$_POST["submit_report"];} +if (isset($_GET["list_ids"])) {$list_ids=$_GET["list_ids"];} + elseif (isset($_POST["list_ids"])) {$list_ids=$_POST["list_ids"];} +if (isset($_GET["sales_number"])) {$sales_number=$_GET["sales_number"];} + elseif (isset($_POST["sales_number"])) {$sales_number=$_POST["sales_number"];} +if (isset($_GET["sales_time_frame"])) {$sales_time_frame=$_GET["sales_time_frame"];} + elseif (isset($_POST["sales_time_frame"])) {$sales_time_frame=$_POST["sales_time_frame"];} +if (isset($_GET["forc"])) {$forc=$_GET["forc"];} + elseif (isset($_POST["forc"])) {$forc=$_POST["forc"];} + +?> + + +VICIDIAL recent sales lookup + + + + +
    + + + + + + + + + + + + + + + + + + + + + +
    Vicidial OUTBOUND recent sales report               Back to Admin +
    + + + + + + + + + + +
    Select a VICIDIAL campaign:
    Select list ID(s) # (optional):
    +
    View sales made within the last OR...View the last sales**
    (If you enter values in both fields, the results will be limited by the first criteria met)
    Campaign is:    Transfer  Non-transfer
    ** - sorted by call date
    +
    +0)) { $list_id_clause.="$lists[$i], "; } + } + $list_id_clause=substr($list_id_clause, 0, -2); + $list_id_clause.=")"; + + if ($sales_number && $sales_number>0) { + $sales_number=eregi_replace("[^0-9]", "", $sales_number); + $limit_clause="limit $sales_number"; + } else { + $sales_number=0; + $limit_clause=""; + } + if ($sales_time_frame && $sales_time_frame>0) { + $hours=$sales_time_frame/60; + $timestamp=date("YmdHis", mktime(date("H"),(date("i")-$sales_time_frame),date("s"),date("m"),date("d"),date("Y"))); + } else { + $timestamp=date("YmdHis", mktime(date("H"),date("i"),date("s"),date("m"),(date("d")-1),date("Y"))); + $hours=24; + } + print "
    "; + print ""; + $i=0; + + $dfile=fopen("discover_stmts.txt", "w"); + if ($forc=="C") { + $stmt="select v.first_name, v.last_name, v.phone_number, vl.call_date, v.lead_id, u.full_name from vicidial_users u, vicidial_list v, vicidial_log vl where vl.call_date>='$timestamp' and vl.lead_id=v.lead_id and v.status='SALE' $list_id_clause and vl.user=u.user order by call_date desc $limit_clause"; + } else { + $stmt="select v.first_name, v.last_name, v.phone_number, vl.call_date, v.lead_id, vl.user, vl.closer from vicidial_list v, vicidial_xfer_log vl where vl.call_date>='$timestamp' and vl.lead_id=v.lead_id and v.status='SALE' $list_id_clause order by call_date desc $limit_clause"; + } + fwrite($dfile, "$stmt\n"); + $rslt=mysql_query($stmt, $link); + $q=0; + print "\n"; + print "\n"; + print "\t\n"; + print "\t\n"; + print "\t\n"; + print "\t\n"; + print "\t\n"; + print "\n"; + while ($row=mysql_fetch_row($rslt)) { + $rec_stmt="select max(recording_id) from recording_log where lead_id='$row[4]'"; + $rec_rslt=mysql_query($rec_stmt, $link); + $rec_row=mysql_fetch_row($rec_rslt); + + if ($forc=="F") { + $rep_stmt="select full_name from vicidial_users where user='$row[5]'"; + $rep_rslt=mysql_query($rep_stmt, $link); + $fr_row=mysql_fetch_array($rep_rslt); + + $rep_stmt="select full_name from vicidial_users where user='$row[6]'"; + $rep_rslt=mysql_query($rep_stmt, $link); + $cl_row=mysql_fetch_array($rep_rslt); + + $rep_name="$fr_row[full_name]/$cl_row[full_name]"; + } else { + $rep_name=$row[5]; + } + + if ($i%2==0) {$bgcolor="#999999";} else {$bgcolor="#CCCCCC";} + print "\n"; + print "\t\n"; + print "\t\n"; + print "\t\n"; + print "\t\n"; + print "\t\n"; + print "\n"; + flush(); + } + print "
    Last ".mysql_num_rows($rslt)." sales made
    Sales Rep(s)Customer NamePhoneRecording IDTimestamp
    $rep_name$row[0] $row[1]$row[2]$rec_row[0]$row[3]
    "; + passthru("$WeBServeRRooT/vicidial/spreadsheet_sales_viewer.pl $list_ids $sales_number $timestamp $forc $now $dcampaign"); +# print "\n\n
    $WeBServeRRooT/vicidial/spreadsheet_sales_viewer.pl $list_ids $sales_number $timestamp $forc $now $dcampaign
    \n"; + flush(); + print ""; + if ($forc=="F") { + print ""; + } + print ""; + print "
    View complete Excel fronter report for this shiftView complete Excel sales report for this shift
    "; +} +?> + + +