updated docs
added email option to AST_VDsales_export and other report generating perl scripts git-svn-id: svn://192.168.202.10@1029 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -5,11 +5,14 @@
|
||||
# This script is designed to gather stats for the lists and write to static files
|
||||
# this script should be run from the web server
|
||||
#
|
||||
# Copyright (C) 2008 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
# /usr/share/astguiclient/AST_VDlist_summary_export.pl --email-list=test@gmail.com --email-sender=test@test.com
|
||||
#
|
||||
# Copyright (C) 2009 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# CHANGES
|
||||
# 81214-0001 - First version
|
||||
#
|
||||
# 90106-2308 - Added email sending
|
||||
#
|
||||
|
||||
$txt = '.txt';
|
||||
$US = '_';
|
||||
@@ -17,52 +20,75 @@ $MT[0] = '';
|
||||
|
||||
### begin parsing run-time options ###
|
||||
if (length($ARGV[0])>1)
|
||||
{
|
||||
{
|
||||
$i=0;
|
||||
while ($#ARGV >= $i)
|
||||
{
|
||||
$args = "$args $ARGV[$i]";
|
||||
$i++;
|
||||
}
|
||||
{
|
||||
$args = "$args $ARGV[$i]";
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($args =~ /--help/i)
|
||||
{
|
||||
print "allowed run time options:\n";
|
||||
print " [-q] = quiet\n";
|
||||
print " [-t] = test\n";
|
||||
print " [--debug] = debugging messages\n";
|
||||
print " [--debugX] = Super debugging messages\n";
|
||||
print "\n";
|
||||
{
|
||||
print "allowed run time options:\n";
|
||||
print " [-q] = quiet\n";
|
||||
print " [-t] = test\n";
|
||||
print " [--debug] = debugging messages\n";
|
||||
print " [--debugX] = Super debugging messages\n";
|
||||
print " [--email-list=test@test.com:test2@test.com] = send email results to these addresses\n";
|
||||
print " [--email-sender=vicidial@localhost] = sender for the email results\n";
|
||||
print "\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
if ($args =~ /--debug/i)
|
||||
{
|
||||
$DB=1;
|
||||
print "\n----- DEBUG MODE -----\n\n";
|
||||
}
|
||||
{
|
||||
$DB=1;
|
||||
print "\n----- DEBUG MODE -----\n\n";
|
||||
}
|
||||
if ($args =~ /--debugX/i)
|
||||
{
|
||||
$DBX=1;
|
||||
print "\n----- SUPER DEBUG MODE -----\n\n";
|
||||
}
|
||||
{
|
||||
$DBX=1;
|
||||
print "\n----- SUPER DEBUG MODE -----\n\n";
|
||||
}
|
||||
if ($args =~ /-q/i)
|
||||
{
|
||||
$q=1; $Q=1;
|
||||
}
|
||||
{
|
||||
$q=1; $Q=1;
|
||||
}
|
||||
if ($args =~ /--test/i)
|
||||
{
|
||||
$T=1; $TEST=1;
|
||||
print "\n----- TESTING -----\n\n";
|
||||
{
|
||||
$T=1; $TEST=1;
|
||||
print "\n----- TESTING -----\n\n";
|
||||
}
|
||||
if ($args =~ /--email-list=/i)
|
||||
{
|
||||
@data_in = split(/--email-list=/,$args);
|
||||
$email_list = $data_in[1];
|
||||
$email_list =~ s/ .*//gi;
|
||||
$email_list =~ s/:/,/gi;
|
||||
print "\n----- EMAIL NOTIFICATION: $email_list -----\n\n";
|
||||
}
|
||||
else
|
||||
{$email_list = '';}
|
||||
|
||||
if ($args =~ /--email-sender=/i)
|
||||
{
|
||||
@data_in = split(/--email-sender=/,$args);
|
||||
$email_sender = $data_in[1];
|
||||
$email_sender =~ s/ .*//gi;
|
||||
$email_sender =~ s/:/,/gi;
|
||||
print "\n----- EMAIL NOTIFICATION SENDER: $email_sender -----\n\n";
|
||||
}
|
||||
else
|
||||
{$email_sender = 'vicidial@localhost';}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no command line options set, using defaults.\n";
|
||||
}
|
||||
{
|
||||
print "no command line options set, using defaults.\n";
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
|
||||
@@ -162,10 +188,11 @@ if (!$Q)
|
||||
$outfile = "LIST_REPORT_$filedate$txt";
|
||||
|
||||
### open the X out file for writing ###
|
||||
open(out, ">$PATHweb/vicidial/server_reports/$outfile")
|
||||
|| die "Can't open $outfile: $!\n";
|
||||
$PATHoutfile = "$PATHweb/vicidial/server_reports/$outfile";
|
||||
open(out, ">$PATHoutfile")
|
||||
|| die "Can't open $PATHoutfile: $!\n";
|
||||
|
||||
print out "$timestamp LIST STATUS SUMMARY REPORT\n\n";
|
||||
$Ealert = "$timestamp LIST STATUS SUMMARY REPORT\n\n";
|
||||
|
||||
|
||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||
@@ -297,16 +324,10 @@ foreach(@lists_list_id)
|
||||
$lists_line_output[$i] =~ s/Campaign Name/Campaign Name: $lists_campaign_name[$i]/gi;
|
||||
$lists_line_output[$i] =~ s/TOTAL LEADS IN LIST/TOTAL LEADS IN LIST: $lists_line_tally[$i]/gi;
|
||||
|
||||
print "\n";
|
||||
print " LIST INFORMATION STATUS DESCRIPTION COUNT\n";
|
||||
print "-------------------------------------------------------------------------------\n";
|
||||
print "$lists_line_output[$i]";
|
||||
|
||||
print out "\n";
|
||||
print out " LIST INFORMATION STATUS DESCRIPTION COUNT\n";
|
||||
print out "--------------------------------------------------------------------------------\n";
|
||||
print out "$lists_line_output[$i]";
|
||||
|
||||
$Ealert .= "\n";
|
||||
$Ealert .= " LIST INFORMATION STATUS DESCRIPTION COUNT\n";
|
||||
$Ealert .= "-------------------------------------------------------------------------------\n";
|
||||
$Ealert .= "$lists_line_output[$i]";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
@@ -332,17 +353,61 @@ $secY = time();
|
||||
$secZ = ($secY - $secX);
|
||||
$secZm = ($secZ /60);
|
||||
|
||||
print "\n";
|
||||
print "-------------------------------------------------------------------------------------\n";
|
||||
print "LIST REPORT FOR $timestamp: $outfile\n";
|
||||
print "TOTAL LEADS IN SYSTEM: $TOTAL_LEADS\n";
|
||||
$Ealert .= "\n";
|
||||
$Ealert .= "-------------------------------------------------------------------------------------\n";
|
||||
$Ealert .= "LIST REPORT FOR $timestamp: $outfile\n";
|
||||
$Ealert .= "TOTAL LEADS IN SYSTEM: $TOTAL_LEADS\n";
|
||||
print "script execution time in seconds: $secZ minutes: $secZm\n";
|
||||
|
||||
print out"\n";
|
||||
print out "-------------------------------------------------------------------------------------\n";
|
||||
print out "LIST REPORT FOR $timestamp: $outfile\n";
|
||||
print out "TOTAL LEADS IN SYSTEM: $TOTAL_LEADS\n";
|
||||
print out "$Ealert";
|
||||
|
||||
close(out);
|
||||
|
||||
###### EMAIL SECTION
|
||||
|
||||
if ( (length($Ealert)>5) && (length($email_list) > 3) )
|
||||
{
|
||||
print "Sending email: $email_list\n";
|
||||
|
||||
use MIME::QuotedPrint;
|
||||
use MIME::Base64;
|
||||
use Mail::Sendmail;
|
||||
|
||||
$mailsubject = "VICIDIAL Lead Lists Report $shipdate";
|
||||
|
||||
%mail = ( To => "$email_list",
|
||||
From => "$email_sender",
|
||||
Subject => "$mailsubject",
|
||||
);
|
||||
$boundary = "====" . time() . "====";
|
||||
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
|
||||
|
||||
$message = encode_qp( "VICIDIAL Lead Lists Report for $shipdate:\n\n Attachment: $outfile" );
|
||||
|
||||
$Zfile = "$PATHoutfile";
|
||||
|
||||
open (F, $Zfile) or die "Cannot read $Zfile: $!";
|
||||
binmode F; undef $/;
|
||||
$attachment = encode_base64(<F>);
|
||||
close F;
|
||||
|
||||
$boundary = '--'.$boundary;
|
||||
$mail{body} .= "$boundary\n";
|
||||
$mail{body} .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
|
||||
$mail{body} .= "Content-Transfer-Encoding: quoted-printable\n\n";
|
||||
$mail{body} .= "$message\n";
|
||||
$mail{body} .= "$boundary\n";
|
||||
$mail{body} .= "Content-Type: application/octet-stream; name=\"$outfile\"\n";
|
||||
$mail{body} .= "Content-Transfer-Encoding: base64\n";
|
||||
$mail{body} .= "Content-Disposition: attachment; filename=\"$outfile\"\n\n";
|
||||
$mail{body} .= "$attachment\n";
|
||||
$mail{body} .= "$boundary";
|
||||
$mail{body} .= "--\n";
|
||||
|
||||
sendmail(%mail) or die $mail::Sendmail::error;
|
||||
print "ok. log says:\n", $mail::sendmail::log; ### print mail log for status
|
||||
|
||||
}
|
||||
|
||||
|
||||
exit;
|
||||
|
||||
@@ -0,0 +1,445 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_VDlist_summary_export_UK.pl version: 2.0.5
|
||||
#
|
||||
# This script is designed to gather stats for the lists and write to static files
|
||||
# this script should be run from the web server
|
||||
#
|
||||
# /usr/share/astguiclient/AST_VDlist_summary_export_UK.pl --campaign=GOODB-GROUP1 --good-statuses=NEW --filename=UNWORKED_LEADS_YYYY-MM-DD.txt --email-list=test@gmail.com --email-sender=test@test.com
|
||||
#
|
||||
# Copyright (C) 2009 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# CHANGES
|
||||
# 90105-2343 - First version
|
||||
# 90106-2308 - Added email sending
|
||||
#
|
||||
|
||||
$secX = time();
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
||||
$year = ($year + 1900);
|
||||
$mon++;
|
||||
|
||||
if ($mon < 10) {$mon = "0$mon";}
|
||||
if ($mday < 10) {$mday = "0$mday";}
|
||||
if ($hour < 10) {$hour = "0$hour";}
|
||||
if ($min < 10) {$min = "0$min";}
|
||||
if ($sec < 10) {$sec = "0$sec";}
|
||||
$timestamp = "$year-$mon-$mday $hour:$min:$sec";
|
||||
$filedate = "$year$mon$mday";
|
||||
$shipdate = "$year-$mon-$mday";
|
||||
$datestamp = "$year/$mon/$mday $hour:$min";
|
||||
|
||||
$txt = '.txt';
|
||||
$US = '_';
|
||||
$MT[0] = '';
|
||||
|
||||
### begin parsing run-time options ###
|
||||
if (length($ARGV[0])>1)
|
||||
{
|
||||
$i=0;
|
||||
while ($#ARGV >= $i)
|
||||
{
|
||||
$args = "$args $ARGV[$i]";
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($args =~ /--help/i)
|
||||
{
|
||||
print "allowed run time options:\n";
|
||||
print " [-q] = quiet\n";
|
||||
print " [-t] = test\n";
|
||||
print " [--debug] = debugging messages\n";
|
||||
print " [--debugX] = Super debugging messages\n";
|
||||
print " [--campaign=XXX] = Campaign that sales will be pulled from\n";
|
||||
print " [--good-statuses=XXX-XXY] = Statuses that are deemed to be \"Good\". Default NEW\n";
|
||||
print " [--filename=XXX] = Name to be used for file\n";
|
||||
print " [--email-list=test@test.com:test2@test.com] = send email results to these addresses\n";
|
||||
print " [--email-sender=vicidial@localhost] = sender for the email results\n";
|
||||
|
||||
print "\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($args =~ /--debug/i)
|
||||
{
|
||||
$DB=1;
|
||||
print "\n----- DEBUG MODE -----\n\n";
|
||||
}
|
||||
if ($args =~ /--debugX/i)
|
||||
{
|
||||
$DBX=1;
|
||||
print "\n----- SUPER DEBUG MODE -----\n\n";
|
||||
}
|
||||
if ($args =~ /-q/i)
|
||||
{
|
||||
$q=1; $Q=1;
|
||||
}
|
||||
if ($args =~ /--test/i)
|
||||
{
|
||||
$T=1; $TEST=1;
|
||||
print "\n----- TESTING -----\n\n";
|
||||
}
|
||||
if ($args =~ /--campaign=/i)
|
||||
{
|
||||
# print "\n|$ARGS|\n\n";
|
||||
@data_in = split(/--campaign=/,$args);
|
||||
$campaign = $data_in[1];
|
||||
$campaign =~ s/ .*$//gi;
|
||||
$campaignSQL = $campaign;
|
||||
if ($campaignSQL =~ /-/)
|
||||
{
|
||||
$campaignSQL =~ s/-/','/gi;
|
||||
}
|
||||
$campaignSQL = "'$campaignSQL'";
|
||||
}
|
||||
if ($args =~ /--good-statuses=/i)
|
||||
{
|
||||
@data_in = split(/--good-statuses=/,$args);
|
||||
$good_statuses = $data_in[1];
|
||||
$good_statuses =~ s/ .*$//gi;
|
||||
$good_statusesSQL = $good_statuses;
|
||||
$good_statusesSQL =~ s/-/','/gi;
|
||||
$good_statusesSQL = "'$good_statusesSQL'";
|
||||
}
|
||||
if ($args =~ /--email-list=/i)
|
||||
{
|
||||
@data_in = split(/--email-list=/,$args);
|
||||
$email_list = $data_in[1];
|
||||
$email_list =~ s/ .*//gi;
|
||||
$email_list =~ s/:/,/gi;
|
||||
print "\n----- EMAIL NOTIFICATION: $email_list -----\n\n";
|
||||
}
|
||||
else
|
||||
{$email_list = '';}
|
||||
|
||||
if ($args =~ /--email-sender=/i)
|
||||
{
|
||||
@data_in = split(/--email-sender=/,$args);
|
||||
$email_sender = $data_in[1];
|
||||
$email_sender =~ s/ .*//gi;
|
||||
$email_sender =~ s/:/,/gi;
|
||||
print "\n----- EMAIL NOTIFICATION SENDER: $email_sender -----\n\n";
|
||||
}
|
||||
else
|
||||
{$email_sender = 'vicidial@localhost';}
|
||||
if ($args =~ /--filename=/i)
|
||||
{
|
||||
# print "\n|$ARGS|\n\n";
|
||||
@data_in = split(/--filename=/,$args);
|
||||
$filename = $data_in[1];
|
||||
$filename =~ s/ .*$//gi;
|
||||
$filename =~ s/YYYY/$year/gi;
|
||||
$filename =~ s/MM/$mon/gi;
|
||||
$filename =~ s/DD/$mday/gi;
|
||||
$filename_override=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no command line options set, using defaults.\n";
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
# default path to astguiclient configuration file:
|
||||
$PATHconf = '/etc/astguiclient.conf';
|
||||
|
||||
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
|
||||
@conf = <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;}
|
||||
if ( ($line =~ /^VARREPORT_host/) && ($CLIREPORT_host < 1) )
|
||||
{$VARREPORT_host = $line; $VARREPORT_host =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_user/) && ($CLIREPORT_user < 1) )
|
||||
{$VARREPORT_user = $line; $VARREPORT_user =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_pass/) && ($CLIREPORT_pass < 1) )
|
||||
{$VARREPORT_pass = $line; $VARREPORT_pass =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_port/) && ($CLIREPORT_port < 1) )
|
||||
{$VARREPORT_port = $line; $VARREPORT_port =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARREPORT_dir/) && ($CLIREPORT_dir < 1) )
|
||||
{$VARREPORT_dir = $line; $VARREPORT_dir =~ s/.*=//gi;}
|
||||
$i++;
|
||||
}
|
||||
|
||||
# Customized Variables
|
||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
||||
|
||||
if (!$Q)
|
||||
{
|
||||
print "\n\n\n\n\n\n\n\n\n\n\n\n-- AST_VDlist_summary_export_UK.pl --\n\n";
|
||||
print "This program is designed to gather stats on lead lists and post them to a file. \n";
|
||||
print "\n";
|
||||
print "$timestamp UK LIST STATUS SUMMARY REPORT\n";
|
||||
print "\n";
|
||||
print "================================================================================\n";
|
||||
print "Region Postal --------------------- Prioirty ----------------------\n";
|
||||
print " Code Code 1 2 7 8 5 6 Bad Total\n";
|
||||
print "--------------------------------------------------------------------------------\n";
|
||||
}
|
||||
|
||||
$outfile = "UNWORKED_LEADS_$filedate$txt";
|
||||
if ($filename_override > 0) {$outfile = $filename;}
|
||||
|
||||
### open the X out file for writing ###
|
||||
$PATHoutfile = "$PATHweb/vicidial/server_reports/$outfile";
|
||||
open(out, ">$PATHoutfile")
|
||||
|| die "Can't open $PATHoutfile: $!\n";
|
||||
|
||||
|
||||
$Ealert .= "$timestamp UK REGION STATUS SUMMARY REPORT\n\n";
|
||||
$Ealert .= "================================================================================\n";
|
||||
$Ealert .= "Region Postal --------------------- Prioirty ----------------------\n";
|
||||
$Ealert .= " Code Code 1 2 7 8 5 6 Bad Total\n";
|
||||
$Ealert .= "--------------------------------------------------------------------------------\n";
|
||||
|
||||
|
||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||
|
||||
|
||||
use DBI;
|
||||
|
||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
||||
or die "Couldn't connect to database: " . DBI->errstr;
|
||||
|
||||
$TOTAL_LEADS=0;
|
||||
|
||||
|
||||
###########################################################################
|
||||
########### grab lists within campaigns and regions of the UK ######
|
||||
###########################################################################
|
||||
|
||||
$stmtA = "select list_id from vicidial_lists where campaign_id IN($campaignSQL);";
|
||||
if ($DBX) {print "|$stmtA|\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$i=0;
|
||||
while ($sthArows > $i)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$listSQL .= "'$aryA[0]',";
|
||||
$i++;
|
||||
}
|
||||
$sthA->finish();
|
||||
if ($sthArows < 1) {print "ERROR! no lists for campaigns $campaign"; exit;}
|
||||
else {$listSQL =~ s/,$//gi;}
|
||||
|
||||
$stmtA = "select region,region_code,post_code_prefix,country_code,list_code_id from vicidial_uk_region_codes order by region_code,post_code_prefix limit 2000;";
|
||||
if ($DBX) {print "|$stmtA|\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$i=0;
|
||||
$m=0;
|
||||
while ($sthArows > $m)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
if (length($aryA[2])<3)
|
||||
{
|
||||
$region[$i] = $aryA[0];
|
||||
$region_code[$i] = $aryA[1];
|
||||
$post_code_prefix[$i] = $aryA[2]; if (length($post_code_prefix[$i])<2) {$post_code_prefix[$i] = "$post_code_prefix[$i] ";}
|
||||
$country_code[$i] = $aryA[3];
|
||||
$list_code_id[$i] = $aryA[4];
|
||||
$i++;
|
||||
}
|
||||
$m++;
|
||||
}
|
||||
$sthA->finish();
|
||||
if ($sthArows < 1) {print "ERROR! no regions in the UK"; exit;}
|
||||
|
||||
$i=0;
|
||||
$k=0;
|
||||
$m=0;
|
||||
$previous_region_code='';
|
||||
$p1t=0; $p2t=0; $p7t=0; $p8t=0; $p5t=0; $p6t=0; $p9t=0; $pSt=0;
|
||||
$p1T=0; $p2T=0; $p7T=0; $p8T=0; $p5T=0; $p6T=0; $p9T=0; $pST=0;
|
||||
foreach(@region_code)
|
||||
{
|
||||
if ( ($region_code[$i] =~ /$previous_region_code/) && (length($region_code[$i]) == length($previous_region_code)) )
|
||||
{$do_nothing=1;}
|
||||
else
|
||||
{
|
||||
if ($i > 0)
|
||||
{
|
||||
$p1T = ($p1T + $p1t);
|
||||
$p2T = ($p2T + $p2t);
|
||||
$p7T = ($p7T + $p7t);
|
||||
$p8T = ($p8T + $p8t);
|
||||
$p5T = ($p5T + $p5t);
|
||||
$p6T = ($p6T + $p6t);
|
||||
$p9T = ($p9T + $p9t);
|
||||
$pST = ($pST + $pSt);
|
||||
$p1t = sprintf("%-8s",$p1t);
|
||||
$p2t = sprintf("%-8s",$p2t);
|
||||
$p7t = sprintf("%-8s",$p7t);
|
||||
$p8t = sprintf("%-8s",$p8t);
|
||||
$p5t = sprintf("%-8s",$p5t);
|
||||
$p6t = sprintf("%-8s",$p6t);
|
||||
$p9t = sprintf("%-7s",$p9t);
|
||||
$pSt = sprintf("%-8s",$pSt);
|
||||
$previous_region_code = sprintf("%-3s",$previous_region_code);
|
||||
|
||||
$Ealert .= " Subtotal: $previous_region_code $p1t$p2t$p7t$p8t$p5t$p6t$p9t$pSt\n";
|
||||
if ($DB) {print " Subtotal: $previous_region_code $p1t$p2t$p7t$p8t$p5t$p6t$p9t$pSt\n";}
|
||||
$p1t=0; $p2t=0; $p7t=0; $p8t=0; $p5t=0; $p6t=0; $p9t=0; $pSt=0;
|
||||
}
|
||||
$Ealert .= "$region[$i] - $region_code[$i]:\n";
|
||||
if ($DB) {print "$region[$i] - $region_code[$i]:\n";}
|
||||
$previous_region_code=$region_code[$i];
|
||||
}
|
||||
|
||||
$p1[$i]=0; $p2[$i]=0; $p7[$i]=0; $p8[$i]=0; $p5[$i]=0; $p6[$i]=0; $p9[$i]=0; $pS[$i]=0;
|
||||
$stmtA = "select count(*),list_id from vicidial_list where postal_code LIKE \"$post_code_prefix[$i]%\" and list_id IN($listSQL) and status IN($good_statusesSQL) group by list_id order by list_id,status;";
|
||||
if ($DBX) {print "|$stmtA|\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$k=0;
|
||||
while ($sthArows > $k)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$count[$k] = $aryA[0];
|
||||
$list_id[$k] = $aryA[1];
|
||||
if ($DBX) {print "$i|$k|$region_code[$i]|$post_code_prefix[$i]| |$count[$k]|$list_id[$k]|\n";}
|
||||
if ($list_id[$k] =~ /1$/) {$p1[$i]=($p1[$i] + $count[$k]); $p1t=($p1t + $count[$k]);}
|
||||
if ($list_id[$k] =~ /2$/) {$p2[$i]=($p2[$i] + $count[$k]); $p2t=($p2t + $count[$k]);}
|
||||
if ($list_id[$k] =~ /7$/) {$p7[$i]=($p7[$i] + $count[$k]); $p7t=($p7t + $count[$k]);}
|
||||
if ($list_id[$k] =~ /8$/) {$p8[$i]=($p8[$i] + $count[$k]); $p8t=($p8t + $count[$k]);}
|
||||
if ($list_id[$k] =~ /5$/) {$p5[$i]=($p5[$i] + $count[$k]); $p5t=($p5t + $count[$k]);}
|
||||
if ($list_id[$k] =~ /6$/) {$p6[$i]=($p6[$i] + $count[$k]); $p6t=($p6t + $count[$k]);}
|
||||
if ($list_id[$k] =~ /3$|4$|9$|0$/) {$p9[$i]=($p9[$i] + $count[$k]); $p9t=($p9t + $count[$k]);}
|
||||
$pS[$i] = ($pS[$i] + $count[$k]);
|
||||
$pSt = ($pSt + $count[$k]);
|
||||
$k++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$p1[$i] = sprintf("%-8s",$p1[$i]);
|
||||
$p2[$i] = sprintf("%-8s",$p2[$i]);
|
||||
$p7[$i] = sprintf("%-8s",$p7[$i]);
|
||||
$p8[$i] = sprintf("%-8s",$p8[$i]);
|
||||
$p5[$i] = sprintf("%-8s",$p5[$i]);
|
||||
$p6[$i] = sprintf("%-8s",$p6[$i]);
|
||||
$p9[$i] = sprintf("%-7s",$p9[$i]);
|
||||
$pS[$i] = sprintf("%-8s",$pS[$i]);
|
||||
$post_code_prefix[$i] = sprintf("%-5s",$post_code_prefix[$i]);
|
||||
|
||||
$Ealert .= " $post_code_prefix[$i]$p1[$i]$p2[$i]$p7[$i]$p8[$i]$p5[$i]$p6[$i]$p9[$i]$pS[$i]\n";
|
||||
if ($DB) {print " $post_code_prefix[$i]$p1[$i]$p2[$i]$p7[$i]$p8[$i]$p5[$i]$p6[$i]$p9[$i]$pS[$i]\n";}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$p1T = sprintf("%-8s",$p1T);
|
||||
$p2T = sprintf("%-8s",$p2T);
|
||||
$p7T = sprintf("%-8s",$p7T);
|
||||
$p8T = sprintf("%-8s",$p8T);
|
||||
$p5T = sprintf("%-8s",$p5T);
|
||||
$p6T = sprintf("%-8s",$p6T);
|
||||
$p9T = sprintf("%-7s",$p9T);
|
||||
$pST = sprintf("%-8s",$pST);
|
||||
|
||||
$Ealert .= "TOTAL $p1T$p2T$p7T$p8T$p5T$p6T$p9T$pST\n";
|
||||
if ($DB) {print "TOTAL $p1T$p2T$p7T$p8T$p5T$p6T$p9T$pST\n";}
|
||||
|
||||
|
||||
if ($ftp_transfer > 0)
|
||||
{
|
||||
use Net::FTP;
|
||||
|
||||
if (!$Q) {print "Sending File Over FTP: $outfile\n";}
|
||||
$ftp = Net::FTP->new("$VARREPORT_host", Port => $VARREPORT_port);
|
||||
$ftp->login("$VARREPORT_user","$VARREPORT_pass");
|
||||
$ftp->cwd("$VARREPORT_dir");
|
||||
$ftp->put("$PATHweb/vicidial/server_reports/$outfile", "$outfile");
|
||||
$ftp->quit;
|
||||
}
|
||||
|
||||
### calculate time to run script ###
|
||||
$secY = time();
|
||||
$secZ = ($secY - $secX);
|
||||
$secZm = ($secZ /60);
|
||||
|
||||
print "script execution time in seconds: $secZ minutes: $secZm\n";
|
||||
|
||||
print out "$Ealert";
|
||||
close(out);
|
||||
|
||||
###### EMAIL SECTION
|
||||
|
||||
if ( (length($Ealert)>5) && (length($email_list) > 3) )
|
||||
{
|
||||
print "Sending email: $email_list\n";
|
||||
|
||||
use MIME::QuotedPrint;
|
||||
use MIME::Base64;
|
||||
use Mail::Sendmail;
|
||||
|
||||
$mailsubject = "VICIDIAL Unworked Leads $outfile";
|
||||
|
||||
%mail = ( To => "$email_list",
|
||||
From => "$email_sender",
|
||||
Subject => "$mailsubject",
|
||||
);
|
||||
$boundary = "====" . time() . "====";
|
||||
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
|
||||
|
||||
$message = encode_qp( "VICIDIAL Unworked leads Report for $shipdate:\n\n Attachment: $outfile" );
|
||||
|
||||
$Zfile = "$PATHoutfile";
|
||||
|
||||
open (F, $Zfile) or die "Cannot read $Zfile: $!";
|
||||
binmode F; undef $/;
|
||||
$attachment = encode_base64(<F>);
|
||||
close F;
|
||||
|
||||
$boundary = '--'.$boundary;
|
||||
$mail{body} .= "$boundary\n";
|
||||
$mail{body} .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
|
||||
$mail{body} .= "Content-Transfer-Encoding: quoted-printable\n\n";
|
||||
$mail{body} .= "$message\n";
|
||||
$mail{body} .= "$boundary\n";
|
||||
$mail{body} .= "Content-Type: application/octet-stream; name=\"$outfile\"\n";
|
||||
$mail{body} .= "Content-Transfer-Encoding: base64\n";
|
||||
$mail{body} .= "Content-Disposition: attachment; filename=\"$outfile\"\n\n";
|
||||
$mail{body} .= "$attachment\n";
|
||||
$mail{body} .= "$boundary";
|
||||
$mail{body} .= "--\n";
|
||||
|
||||
sendmail(%mail) or die $mail::Sendmail::error;
|
||||
print "ok. log says:\n", $mail::sendmail::log; ### print mail log for status
|
||||
|
||||
}
|
||||
|
||||
exit;
|
||||
@@ -5,6 +5,8 @@
|
||||
# This script is designed to gather sales for a VICIDIAL Outbound-only campaign and
|
||||
# post them to a directory
|
||||
#
|
||||
# /usr/share/astguiclient/AST_VDsales_export.pl --campaign=GOODB-GROUP1-GROUP3-GROUP4-SPECIALS-DNC_BEDS --output-format=fixed-as400 --sale-statuses=SALE --debug --filename=BEDSsaleMMDD.txt --date=yesterday --email-list=test@gmail.com --email-sender=test@test.com
|
||||
#
|
||||
# Copyright (C) 2009 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# CHANGES
|
||||
@@ -14,6 +16,7 @@
|
||||
# 70709-1411 - Added FTP transfer option
|
||||
# 71005-0054 - Altered script to use astguiclient.conf for settings
|
||||
# 90105-1155 - Added AS400 export formats and changed around date override
|
||||
# 90106-2309 - Added email sending
|
||||
#
|
||||
|
||||
$txt = '.txt';
|
||||
@@ -88,6 +91,8 @@ if (length($ARGV[0])>1)
|
||||
print " [--output-format=XXX] = Format of file. Default \"pipe-standard\"\n";
|
||||
print " [--with-inbound=XXX-XXY] = include the following inbound groups\n";
|
||||
print " [--ftp-transfer] = Send results file by FTP to another server\n";
|
||||
print " [--email-list=test@test.com:test2@test.com] = send email results to these addresses\n";
|
||||
print " [--email-sender=vicidial@localhost] = sender for the email results\n";
|
||||
print " [-q] = quiet\n";
|
||||
print " [-t] = test\n";
|
||||
print " [--debug] = debugging messages\n";
|
||||
@@ -206,6 +211,27 @@ if (length($ARGV[0])>1)
|
||||
$T=1; $TEST=1;
|
||||
print "\n----- TESTING -----\n\n";
|
||||
}
|
||||
if ($args =~ /--email-list=/i)
|
||||
{
|
||||
@data_in = split(/--email-list=/,$args);
|
||||
$email_list = $data_in[1];
|
||||
$email_list =~ s/ .*//gi;
|
||||
$email_list =~ s/:/,/gi;
|
||||
print "\n----- EMAIL NOTIFICATION: $email_list -----\n\n";
|
||||
}
|
||||
else
|
||||
{$email_list = '';}
|
||||
|
||||
if ($args =~ /--email-sender=/i)
|
||||
{
|
||||
@data_in = split(/--email-sender=/,$args);
|
||||
$email_sender = $data_in[1];
|
||||
$email_sender =~ s/ .*//gi;
|
||||
$email_sender =~ s/:/,/gi;
|
||||
print "\n----- EMAIL NOTIFICATION SENDER: $email_sender -----\n\n";
|
||||
}
|
||||
else
|
||||
{$email_sender = 'vicidial@localhost';}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -315,8 +341,9 @@ $outfile = "$campaign$US$filedate$US$sale_statuses$txt";
|
||||
if ($filename_override > 0) {$outfile = $filename;}
|
||||
|
||||
### open the X out file for writing ###
|
||||
open(out, ">$PATHweb/vicidial/server_reports/$outfile")
|
||||
|| die "Can't open $outfile: $!\n";
|
||||
$PATHoutfile = "$PATHweb/vicidial/server_reports/$outfile";
|
||||
open(out, ">$PATHoutfile")
|
||||
|| die "Can't open $PATHoutfile: $!\n";
|
||||
|
||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||
|
||||
@@ -336,6 +363,7 @@ $TOTAL_SALES=0;
|
||||
########### CURRENT DAY SALES GATHERING outbound-only: vicidial_log ######
|
||||
###########################################################################
|
||||
$stmtA = "select vicidial_log.user,first_name,last_name,address1,address2,city,state,postal_code,vicidial_list.phone_number,email,security_phrase,vicidial_list.comments,call_date,vicidial_list.lead_id,vicidial_users.full_name,vicidial_log.status,vicidial_list.vendor_lead_code,vicidial_list.source_id,vicidial_log.list_id,title,address3,last_local_call_time from vicidial_list,vicidial_log,vicidial_users where campaign_id IN($campaignSQL) $sale_statusesSQL and call_date > '$shipdate 00:00:01' and call_date < '$shipdate 23:59:59' and vicidial_log.lead_id=vicidial_list.lead_id and vicidial_users.user=vicidial_log.user;";
|
||||
#$stmtA = "select vicidial_users.user,first_name,last_name,address1,address2,city,state,postal_code,phone_number,email,security_phrase,comments,last_local_call_time,lead_id,vicidial_users.full_name,status,vendor_lead_code,source_id,list_id,title,address3,last_local_call_time from vicidial_list,vicidial_users where list_id NOT IN('999','998') $sale_statusesSQL and called_count > 0 and vicidial_users.user=vicidial_list.user;";
|
||||
if ($DB) {print "|$stmtA|\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
@@ -435,9 +463,57 @@ if (length($with_inboundSQL)>3)
|
||||
$sthA->finish();
|
||||
}
|
||||
|
||||
|
||||
close(out);
|
||||
|
||||
|
||||
###### EMAIL SECTION
|
||||
|
||||
if ( (length($Ealert)>5) && (length($email_list) > 3) )
|
||||
{
|
||||
print "Sending email: $email_list\n";
|
||||
|
||||
use MIME::QuotedPrint;
|
||||
use MIME::Base64;
|
||||
use Mail::Sendmail;
|
||||
|
||||
$mailsubject = "VICIDIAL Lead Export $outfile";
|
||||
|
||||
%mail = ( To => "$email_list",
|
||||
From => "$email_sender",
|
||||
Subject => "$mailsubject",
|
||||
);
|
||||
$boundary = "====" . time() . "====";
|
||||
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
|
||||
|
||||
$message = encode_qp( "VICIDIAL Lead Export:\n\n Attachment: $outfile\n Total Records: $TOTAL_SALES\n" );
|
||||
|
||||
$Zfile = "$PATHoutfile";
|
||||
|
||||
open (F, $Zfile) or die "Cannot read $Zfile: $!";
|
||||
binmode F; undef $/;
|
||||
$attachment = encode_base64(<F>);
|
||||
close F;
|
||||
|
||||
$boundary = '--'.$boundary;
|
||||
$mail{body} .= "$boundary\n";
|
||||
$mail{body} .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
|
||||
$mail{body} .= "Content-Transfer-Encoding: quoted-printable\n\n";
|
||||
$mail{body} .= "$message\n";
|
||||
$mail{body} .= "$boundary\n";
|
||||
$mail{body} .= "Content-Type: application/octet-stream; name=\"$outfile\"\n";
|
||||
$mail{body} .= "Content-Transfer-Encoding: base64\n";
|
||||
$mail{body} .= "Content-Disposition: attachment; filename=\"$outfile\"\n\n";
|
||||
$mail{body} .= "$attachment\n";
|
||||
$mail{body} .= "$boundary";
|
||||
$mail{body} .= "--\n";
|
||||
|
||||
sendmail(%mail) or die $mail::Sendmail::error;
|
||||
print "ok. log says:\n", $mail::sendmail::log; ### print mail log for status
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($ftp_transfer > 0)
|
||||
{
|
||||
use Net::FTP;
|
||||
@@ -567,30 +643,39 @@ if ($output_format =~ /^html-rec$/)
|
||||
if ($output_format =~ /^fixed-as400$/)
|
||||
{
|
||||
# 16884259 MRS. JEAN BROWN RISALPUR BROMSBERROW HEATYH LEDBURY HEREFORDSHIRE ENGLAND HR8 1PQ 01531650052 1209200809:52NI 3205UK
|
||||
$vendor_id = sprintf("%-10s",$vendor_id);
|
||||
$title = sprintf("%-10s",$title);
|
||||
$first_name = sprintf("%-15s",$first_name);
|
||||
$last_name = sprintf("%-20s",$last_name);
|
||||
$address1 = sprintf("%-30s",$address1);
|
||||
$address2 = sprintf("%-30s",$address2);
|
||||
$address3 = sprintf("%-30s",$address3);
|
||||
$city = sprintf("%-50s",$city);
|
||||
$postal_code = sprintf("%-9s",$postal_code);
|
||||
$phone_number = sprintf("%-20s",$phone_number);
|
||||
$vendor_id = sprintf("%-10s",$vendor_id); while(length($vendor_id)>10) {$vendor_id =~ s/.$//gi;}
|
||||
$title = sprintf("%-10s",$title); while(length($title)>10) {$title =~ s/.$//gi;}
|
||||
$first_name = sprintf("%-15s",$first_name); while(length($first_name)>15) {$first_name =~ s/.$//gi;}
|
||||
$last_name = sprintf("%-20s",$last_name); while(length($last_name)>20) {$last_name =~ s/.$//gi;}
|
||||
$address1 = sprintf("%-30s",$address1); while(length($address1)>30) {$address1 =~ s/.$//gi;}
|
||||
$address2 = sprintf("%-30s",$address2); while(length($address2)>30) {$address2 =~ s/.$//gi;}
|
||||
$address3 = sprintf("%-30s",$address3); while(length($address3)>30) {$address3 =~ s/.$//gi;}
|
||||
$city = sprintf("%-50s",$city); while(length($city)>50) {$city =~ s/.$//gi;}
|
||||
$postal_code = sprintf("%-9s",$postal_code); while(length($postal_code)>9) {$postal_code =~ s/.$//gi;}
|
||||
$phone_number = sprintf("%-20s",$phone_number); while(length($phone_number)>20) {$phone_number =~ s/.$//gi;}
|
||||
@dtsplit = split(" ",$last_local_call_time);
|
||||
@datesplit = split("-",$dtsplit[0]);
|
||||
$timesplit = substr($dtsplit[1], 0, 5);
|
||||
$formatted_date = "$datesplit[1]$datesplit[2]$datesplit[0]$timesplit";
|
||||
$user = sprintf("%-4s",$user);
|
||||
if ($status =~ /^AA$/) {$status = 'A';}
|
||||
if ($status =~ /^A$/) {$status = 'A';}
|
||||
if ($status =~ /^B$/) {$status = 'B';}
|
||||
if ($status =~ /^N$/) {$status = 'N';}
|
||||
if ($status =~ /^NA$/) {$status = 'N';}
|
||||
if ($status =~ /^NP$/) {$status = 'N';}
|
||||
if ($status =~ /^PU$/) {$status = 'N';}
|
||||
if ($status =~ /^DROP$/) {$status = 'N';}
|
||||
if ($status =~ /^SALE$/) {$status = 'AP';}
|
||||
if ($status =~ /^A6$/) {$status = 'A6';}
|
||||
if ($status =~ /^DNC$/) {$status = 'DC';}
|
||||
if ($status =~ /^DNCL$/) {$status = 'DC';}
|
||||
if ($status =~ /^DC$/) {$status = 'D';}
|
||||
if ($status =~ /^DIED$/) {$status = 'DD';}
|
||||
if ($status =~ /^COMP$/) {$status = 'DD';}
|
||||
if ($status =~ /^DEC$/) {$status = 'DD';}
|
||||
if ($status =~ /^ERI$/) {$status = 'DD';}
|
||||
if ($status =~ /^INCALL$/) {$status = 'DD';}
|
||||
if ($status =~ /^SP$/) {$status = 'DD';}
|
||||
if ($status =~ /^WRON$/) {$status = 'DD';}
|
||||
if ($status =~ /^HBED$/) {$status = 'DD';}
|
||||
@@ -598,13 +683,8 @@ if ($output_format =~ /^fixed-as400$/)
|
||||
if ($status =~ /^HAP1$/) {$status = 'NI';}
|
||||
if ($status =~ /^HAP2$/) {$status = 'NI';}
|
||||
if ($status =~ /^NI$/) {$status = 'NI';}
|
||||
# DNC
|
||||
# DNCL
|
||||
# N
|
||||
# B
|
||||
# A
|
||||
# AA
|
||||
$status = sprintf("%-16s",$status);
|
||||
|
||||
$status = sprintf("%-16s",$status); while(length($status)>16) {$status =~ s/.$//gi;}
|
||||
$user =~ s/VDAD/ /gi;
|
||||
$UK = 'UK';
|
||||
|
||||
@@ -612,6 +692,7 @@ if ($output_format =~ /^fixed-as400$/)
|
||||
}
|
||||
|
||||
|
||||
$Ealert .= "$str";
|
||||
|
||||
print out "$str";
|
||||
if ($DBX) {print "$str\n";}
|
||||
|
||||
@@ -486,6 +486,7 @@ PHASE 6: ADDING CRONTAB ENTRIES FOR ASTGUICLIENT/VICIDIAL SCRIPTS
|
||||
### remove old vicidial logs and asterisk logs more than 2 days old
|
||||
28 0 * * * /usr/bin/find /var/log/astguiclient -maxdepth 1 -type f -mtime +2 -print | xargs rm -f
|
||||
29 0 * * * /usr/bin/find /var/log/asterisk -maxdepth 3 -type f -mtime +2 -print | xargs rm -f
|
||||
30 0 * * * /usr/bin/find / -maxdepth 1 -name "screenlog.0*" -mtime +4 -print | xargs rm -f
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2967,6 +2967,7 @@ SUBPHASE 6.5: setting up astguiclient scripts for continuous running
|
||||
### remove old vicidial logs and asterisk logs more than 2 days old
|
||||
28 0 * * * /usr/bin/find /var/log/astguiclient -maxdepth 1 -type f -mtime +2 -print | xargs rm -f
|
||||
29 0 * * * /usr/bin/find /var/log/asterisk -maxdepth 3 -type f -mtime +2 -print | xargs rm -f
|
||||
30 0 * * * /usr/bin/find / -maxdepth 1 -name "screenlog.0*" -mtime +4 -print | xargs rm -f
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user