Added call_quota_lead_ranking features, EXPERIMENTAL FOR NOW!

git-svn-id: svn://192.168.202.10@3122 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2019-07-20 03:54:49 +00:00
parent b97fe7d878
commit fb563fe4fc
15 changed files with 12954 additions and 114 deletions
+174 -2
View File
@@ -136,9 +136,10 @@
# 181028-1451 - Added vicidial_list stuck QUEUE reset at TEoD
# 190220-2258 - Added flushing of vicidial_sessions_recent table
# 190530-1411 - Added SIP logger code
# 190713-0900 - Added vicidial_lead_call_quota_counts log archiving
#
$build = '190530-1411';
$build = '190713-0900';
$DB=0; # Debug flag
$teodDB=0; # flag to log Timeclock End of Day processes to log file
@@ -167,6 +168,7 @@ $today_start = "$year-$mon-$mday 00:00:00";
$today_date = "$year-$mon-$mday";
$reset_test = "$hour$min";
$wday_now = $wday;
$min_test = $min;
### calculate the date and time for slightly less than 24 hours ago
$secX = time();
@@ -210,6 +212,19 @@ if ($SDsec < 10) {$SDsec = "0$SDsec";}
$SDSQLdate = "$SDyear-$SDmon-$SDmday $SDhour:$SDmin:$SDsec";
$SDdate = "$SDyear-$SDmon-$SDmday";
### calculate the date and time for 6 days ago
$SXtarget = ($secX - 604800); # 6 days ago
($SXsec,$SXmin,$SXhour,$SXmday,$SXmon,$SXyear,$SXwday,$SXyday,$SXisdst) = localtime($SXtarget);
$SXyear = ($SXyear + 1900);
$SXmon++;
if ($SXmon < 10) {$SXmon = "0$SXmon";}
if ($SXmday < 10) {$SXmday = "0$SXmday";}
if ($SXhour < 10) {$SXhour = "0$SXhour";}
if ($SXmin < 10) {$SXmin = "0$SXmin";}
if ($SXsec < 10) {$SXsec = "0$SXsec";}
$SXSQLdate = "$SXyear-$SXmon-$SXmday $SXhour:$SXmin:$SXsec";
$SXdate = "$SXyear-$SXmon-$SXmday";
### begin parsing run-time options ###
if (length($ARGV[0])>1)
@@ -406,7 +421,7 @@ $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VA
##### Get the settings from system_settings #####
$stmtA = "SELECT sounds_central_control_active,active_voicemail_server,custom_dialplan_entry,default_codecs,generate_cross_server_exten,voicemail_timezones,default_voicemail_timezone,call_menu_qualify_enabled,allow_voicemail_greeting,reload_timestamp,meetme_enter_login_filename,meetme_enter_leave3way_filename,allow_chats,enable_auto_reports,enable_drop_lists,expired_lists_inactive,sip_event_logging FROM system_settings;";
$stmtA = "SELECT sounds_central_control_active,active_voicemail_server,custom_dialplan_entry,default_codecs,generate_cross_server_exten,voicemail_timezones,default_voicemail_timezone,call_menu_qualify_enabled,allow_voicemail_greeting,reload_timestamp,meetme_enter_login_filename,meetme_enter_leave3way_filename,allow_chats,enable_auto_reports,enable_drop_lists,expired_lists_inactive,sip_event_logging,call_quota_lead_ranking FROM system_settings;";
# print "$stmtA\n";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@@ -431,6 +446,7 @@ if ($sthArows > 0)
$SSenable_drop_lists = $aryA[14];
$SSexpired_lists_inactive = $aryA[15];
$SSsip_event_logging = $aryA[16];
$SScall_quota_lead_ranking = $aryA[17];
}
$sthA->finish();
if ($DBXXX > 0) {print "SYSTEM SETTINGS: $sounds_central_control_active|$active_voicemail_server|$SScustom_dialplan_entry|$SSdefault_codecs\n";}
@@ -1954,6 +1970,76 @@ if ($timeclock_end_of_day_NOW > 0)
if ($teodDB) {&teod_logger;}
}
##### END roll sip_event logs into one of the 7-day archive tables
##### BEGIN roll Call Quota Lead Ranking logs into the archive table after 7 days
if ($SScall_quota_lead_ranking > 0)
{
if (!$Q) {print "\nProcessing vicidial_lead_call_quota_counts table...\n";}
$stmtA = "INSERT IGNORE INTO vicidial_lead_call_quota_counts_archive SELECT * from vicidial_lead_call_quota_counts where ( (first_call_date < \"$SXSQLdate\") or (first_call_date IS NULL) );";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows = $sthA->rows;
$event_string = "$sthArows rows inserted into vicidial_lead_call_quota_counts_archive table ($SXSQLdate) |$stmtA|";
if (!$Q) {print "$event_string \n";}
if ($teodDB) {&teod_logger;}
$rv = $sthA->err();
if (!$rv)
{
# Gather list of the leads that were just archived, set rank=0
$stmtA = "SELECT lead_id from vicidial_lead_call_quota_counts where ( (first_call_date < \"$SXSQLdate\") or (first_call_date IS NULL) );";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArowsDLISTS=$sthA->rows;
if ($DB > 0) {print "CALL QUOTA LEADS BEING ARCHIVED TO SET TO 0 RANK: |$sthArowsDLISTS| \n";}
$e=0;
while ($sthArowsDLISTS > $e)
{
@aryA = $sthA->fetchrow_array;
$DLISTlead_id[$e] = $aryA[0];
$e++;
}
$sthA->finish();
$e=0;
$e_update_ct=0;
while ($sthArowsDLISTS > $e)
{
$stmtA = "UPDATE vicidial_list SET rank=0 where lead_id='$DLISTlead_id[$e]';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows = $sthA->rows;
if ($DBX) {print "$sthArows|$event_string|$stmtA| \n";}
$e_update_ct = ($e_update_ct + $sthArows);
$e++;
}
$event_string = "$e_update_ct($e) leads updated to 0 rank";
if ($DBX) {print "$event_string \n";}
if ($teodDB) {&teod_logger;}
$stmtA = "DELETE FROM vicidial_lead_call_quota_counts where ( (first_call_date < \"$SXSQLdate\") or (first_call_date IS NULL) );";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows = $sthA->rows;
$event_string = "$sthArows rows deleted from vicidial_lead_call_quota_counts table ($SXSQLdate) |$stmtA|";
if (!$Q) {print "$event_string \n";}
if ($teodDB) {&teod_logger;}
$stmtA = "optimize table vicidial_lead_call_quota_counts;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
}
$stmtA = "UPDATE vicidial_lead_call_quota_counts SET session_one_today_calls='0',session_two_today_calls='0',session_three_today_calls='0',session_four_today_calls='0',session_five_today_calls='0',session_six_today_calls='0';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows = $sthA->rows;
$event_string = "$sthArows rows reset today session counts vicidial_lead_call_quota_counts table ($SXSQLdate)";
if (!$Q) {print "$event_string \n";}
if ($teodDB) {&teod_logger;}
}
##### END roll Call Quota Lead Ranking logs into the archive table after 7 days
}
}
@@ -4499,6 +4585,92 @@ if ($SSenable_drop_lists > 0)
################################################################################
##### BEGIN Call Quota Lead Ranking recycling process
################################################################################
if ( ($SScall_quota_lead_ranking > 0) && ($THISserver_voicemail > 0) )
{
$stmtA = "SELECT campaign_id,call_quota_lead_ranking FROM vicidial_campaigns where active='Y' and call_quota_lead_ranking!='DISABLED' limit 1000;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthBrows=$sthA->rows;
if ($DB) {print "Checking for Call Quota campaigns: |$sthBrows|$stmtA|\n";}
$r=0;
while ($sthBrows > $r)
{
@aryA = $sthA->fetchrow_array;
$CQcampaign_idARY[$r] = $aryA[0];
$CQcall_quota_lead_rankingARY[$r] = $aryA[1];
$r++;
}
$sthA->finish();
if ($sthBrows > 0)
{
$r=0;
while ($sthBrows > $r)
{
$call_quota_run_time='';
$stmtA = "SELECT container_entry FROM vicidial_settings_containers where container_id='$CQcall_quota_lead_rankingARY[$r]';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthSCrows=$sthA->rows;
if ($DB) {print "Checking for Call Quota campaigns: |$sthSCrows|$stmtA|\n";}
if ($sthSCrows > 0)
{
@aryA = $sthA->fetchrow_array;
$TEMPcontainer_entry = $aryA[0];
$TEMPcontainer_entry =~ s/\\//gi;
if (length($TEMPcontainer_entry) > 5)
{
@container_lines = split(/\n/,$TEMPcontainer_entry);
$c=0;
foreach(@container_lines)
{
$container_lines[$c] =~ s/;.*|\r|\t| //gi;
if (length($container_lines[$c]) > 5)
{
# define call_quota_run_time settings
if ($container_lines[$c] =~ /^call_quota_run_time/i)
{
$call_quota_run_time = $container_lines[$c];
$call_quota_run_time =~ s/call_quota_run_time=>//gi;
if ( (length($call_quota_run_time) > 0) && (length($call_quota_run_time) <= 70) )
{
$TESTcall_quota_run_time = ",$call_quota_run_time,";
}
else {$call_quota_run_time='';}
if ($DBX) {print "Call Quota DEBUG: $c|$CQcampaign_idARY[$r]|$CQcall_quota_lead_rankingARY[$r]|$TESTcall_quota_run_time|$call_quota_run_time|$min_test|\n";}
}
}
$c++;
}
}
}
$sthA->finish();
if ( (length($TESTcall_quota_run_time) >= 4) && ($TESTcall_quota_run_time =~ /,$min_test,/) )
{
$temp_campaign = $CQcampaign_idARY[$r];
$cq_command = "$PATHhome/AST_VDcall_quotas.pl --debug --log-to-adminlog --campaign=$temp_campaign ";
if ($DB) {print "starting call quota lead ranking process in a screen... |CQ$temp_campaign| |$call_quota_run_time|$min_test|\n";}
`/usr/bin/screen -d -m -S CQ$temp_campaign $cq_command `;
}
$r++;
}
if ($DB) {print "Call Quota Lead Ranking process launching DONE: $r\n";}
}
}
################################################################################
##### END Call Quota Lead Ranking recycling process
################################################################################
################################################################################
##### BEGIN Reset per-hour hopper dial counts for users
################################################################################
+337 -14
View File
@@ -25,7 +25,7 @@
# It is good practice to keep this program running by placing the associated
# KEEPALIVE script running every minute to ensure this program is always running
#
# Copyright (C) 2018 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2019 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGELOG:
# 50125-1201 - Changed dial timeout to 120 seconds from 180 seconds
@@ -129,6 +129,7 @@
# 180214-1559 - Added CID Group functionality
# 180301-1338 - Small changes for Inbound Queue No Dial
# 180812-1026 - Added code for scheduled_callbacks_auto_reschedule campaign feature
# 190709-2239 - Added Call Quota logging
#
### begin parsing run-time options ###
@@ -298,7 +299,7 @@ $event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|';
#############################################
##### START QUEUEMETRICS LOGGING LOOKUP #####
$stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,outbound_autodial_active,queuemetrics_loginout,queuemetrics_addmember_enabled,queuemetrics_pause_type,enable_drop_lists FROM system_settings;";
$stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,outbound_autodial_active,queuemetrics_loginout,queuemetrics_addmember_enabled,queuemetrics_pause_type,enable_drop_lists,call_quota_lead_ranking,timeclock_end_of_day FROM system_settings;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -316,6 +317,8 @@ if ($sthArows > 0)
$queuemetrics_addmember_enabled = $aryA[8];
$queuemetrics_pause_type = $aryA[9];
$enable_drop_lists = $aryA[10];
$SScall_quota_lead_ranking = $aryA[11];
$timeclock_end_of_day = $aryA[12];
}
$sthA->finish();
##### END QUEUEMETRICS LOGGING LOOKUP #####
@@ -642,7 +645,7 @@ while($one_day_interval > 0)
### grab the dial_level and multiply by active agents to get your goalcalls
$DBIPadlevel[$user_CIPct]=0;
$stmtA = "SELECT auto_dial_level,local_call_time,dial_timeout,dial_prefix,campaign_cid,active,campaign_vdad_exten,closer_campaigns,omit_phone_code,available_only_ratio_tally,auto_alt_dial,campaign_allow_inbound,queue_priority,dial_method,use_custom_cid,inbound_queue_no_dial,available_only_tally_threshold,available_only_tally_threshold_agents,dial_level_threshold,dial_level_threshold_agents,adaptive_dl_diff_target,dl_diff_target_method,inbound_no_agents_no_dial_container,inbound_no_agents_no_dial_threshold,cid_group_id,scheduled_callbacks_auto_reschedule FROM vicidial_campaigns where campaign_id='$DBIPcampaign[$user_CIPct]'";
$stmtA = "SELECT auto_dial_level,local_call_time,dial_timeout,dial_prefix,campaign_cid,active,campaign_vdad_exten,closer_campaigns,omit_phone_code,available_only_ratio_tally,auto_alt_dial,campaign_allow_inbound,queue_priority,dial_method,use_custom_cid,inbound_queue_no_dial,available_only_tally_threshold,available_only_tally_threshold_agents,dial_level_threshold,dial_level_threshold_agents,adaptive_dl_diff_target,dl_diff_target_method,inbound_no_agents_no_dial_container,inbound_no_agents_no_dial_threshold,cid_group_id,scheduled_callbacks_auto_reschedule,call_quota_lead_ranking FROM vicidial_campaigns where campaign_id='$DBIPcampaign[$user_CIPct]'";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -679,6 +682,7 @@ while($one_day_interval > 0)
$DBIPinbound_no_agents_no_dial_threshold[$user_CIPct] = $aryA[23];
$DBIPcid_group_id[$user_CIPct] = $aryA[24];
$DBIPscheduled_callbacks_auto_reschedule[$user_CIPct] = $aryA[25];
$DBIPcall_quota_lead_ranking[$user_CIPct] = $aryA[26];
if ($DBIPdl_diff_target_method[$user_CIPct] =~ /ADAPT_CALC_ONLY/)
{
@@ -1514,18 +1518,18 @@ while($one_day_interval > 0)
### insert a NEW record to the vicidial_manager table to be processed
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$DBIPaddress[$user_CIPct]','','Originate','$VqueryCID','Exten: $VDAD_dial_exten','Context: $ext_context','Channel: $local_DEF$Ndialstring$local_AMP$ext_context','Priority: 1','Callerid: $CIDstring','Timeout: $Local_dial_timeout','','','','VDACnote: $DBIPcampaign[$user_CIPct]|$lead_id|$phone_code|$phone_number|OUT|$alt_dial|$DBIPqueue_priority[$user_CIPct]')";
$affected_rows = $dbhA->do($stmtA);
$event_string = "| number call dialed|$DBIPcampaign[$user_CIPct]|$VqueryCID|$stmtA|$gmt_offset_now|$alt_dial|";
&event_logger;
$affected_rowsA = $dbhA->do($stmtA);
### insert a SENT record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls (server_ip,campaign_id,status,lead_id,callerid,phone_code,phone_number,call_time,call_type,alt_dial,queue_priority,last_update_time) values('$DBIPaddress[$user_CIPct]','$DBIPcampaign[$user_CIPct]','SENT','$lead_id','$VqueryCID','$phone_code','$phone_number','$SQLdate','OUT','$alt_dial','$DBIPqueue_priority[$user_CIPct]','$SQLdate')";
$affected_rows = $dbhA->do($stmtA);
$stmtB = "INSERT INTO vicidial_auto_calls (server_ip,campaign_id,status,lead_id,callerid,phone_code,phone_number,call_time,call_type,alt_dial,queue_priority,last_update_time) values('$DBIPaddress[$user_CIPct]','$DBIPcampaign[$user_CIPct]','SENT','$lead_id','$VqueryCID','$phone_code','$phone_number','$SQLdate','OUT','$alt_dial','$DBIPqueue_priority[$user_CIPct]','$SQLdate')";
$affected_rowsB = $dbhA->do($stmtB);
### insert log record into vicidial_dial_log table
$stmtA = "INSERT INTO vicidial_dial_log SET caller_code='$VqueryCID',lead_id='$lead_id',server_ip='$DBIPaddress[$user_CIPct]',call_date='$SQLdate',extension='$VDAD_dial_exten',channel='$local_DEF$Ndialstring$local_AMP$ext_context',timeout='$Local_dial_timeout',outbound_cid='$CIDstring',context='$ext_context';";
$affected_rows = $dbhA->do($stmtA);
$stmtC = "INSERT INTO vicidial_dial_log SET caller_code='$VqueryCID',lead_id='$lead_id',server_ip='$DBIPaddress[$user_CIPct]',call_date='$SQLdate',extension='$VDAD_dial_exten',channel='$local_DEF$Ndialstring$local_AMP$ext_context',timeout='$Local_dial_timeout',outbound_cid='$CIDstring',context='$ext_context';";
$affected_rowsC = $dbhA->do($stmtC);
$event_string = "| number call dialed|$DBIPcampaign[$user_CIPct]|$VqueryCID|$affected_rowsA|$stmtA|$gmt_offset_now|$alt_dial|$affected_rowsB|$affected_rowsC|";
&event_logger;
### sleep for a five hundredths of a second to not flood the server with new calls
# usleep(1*50*1000);
@@ -1959,11 +1963,11 @@ while($one_day_interval > 0)
$dbhB->disconnect();
}
##### BEGIN AUTO ALT PHONE DIAL SECTION #####
### check to see if campaign has alt_dial enabled
### check to see if campaign has alt_dial or call quotas enabled
$VD_auto_alt_dial = 'NONE';
$VD_auto_alt_dial_statuses='';
$stmtA="SELECT auto_alt_dial,auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc FROM vicidial_campaigns where campaign_id='$CLcampaign_id';";
$VD_call_quota_lead_ranking='DISABLED';
$stmtA="SELECT auto_alt_dial,auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,call_quota_lead_ranking FROM vicidial_campaigns where campaign_id='$CLcampaign_id';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -1975,8 +1979,327 @@ while($one_day_interval > 0)
$VD_use_internal_dnc = $aryA[2];
$VD_use_campaign_dnc = $aryA[3];
$VD_use_other_campaign_dnc = $aryA[4];
$VD_call_quota_lead_ranking = $aryA[5];
}
$sthA->finish();
##### BEGIN Call Quota Lead Ranking logging #####
if ( ($SScall_quota_lead_ranking > 0) && ($VD_call_quota_lead_ranking !~ /^DISABLED$/i) )
{
# Gather settings container for Call Quota Lead Ranking
$CQcontainer_entry='';
$stmtA = "SELECT container_entry FROM vicidial_settings_containers where container_id='$VD_call_quota_lead_ranking';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$CQcontainer_entry = $aryA[0];
$CQcontainer_entry =~ s/\\//gi;
}
$sthA->finish();
# Define variables for Call Quota settings
$session_one='';
$session_two='';
$session_three='';
$session_four='';
$session_five='';
$session_six='';
$settings_session_score=0;
$zero_rank_after_call=0;
if (length($CQcontainer_entry) > 5)
{
@container_lines = split(/\n/,$CQcontainer_entry);
$c=0;
foreach(@container_lines)
{
$container_lines[$c] =~ s/;.*|\r|\t| //gi;
if (length($container_lines[$c]) > 5)
{
# define core settings
if ($container_lines[$c] =~ /^zero_rank_after_call/i)
{
$container_lines[$c] =~ s/zero_rank_after_call=>//gi;
if ( ($container_lines[$c] >= 0) && ($container_lines[$c] <= 1) )
{
$zero_rank_after_call = $container_lines[$c];
}
}
# define sessions
if ($container_lines[$c] =~ /^session_one/i)
{
$session_one_valid=0; $session_one_start=''; $session_one_end='';
$session_one = $container_lines[$c];
$session_one =~ s/session_one=>//gi;
if ( (length($session_one) > 0) && (length($session_one) <= 9) && ($session_one =~ /,/) )
{
@session_oneARY = split(/,/,$session_one);
$session_one_start = $session_oneARY[0];
$session_one_end = $session_oneARY[1];
if ( (length($session_one_start) >= 4) && (length($session_one_end) >= 4) && ($session_one_start < $session_one_end) && ($session_one_end <= 2400) )
{
$settings_session_score++;
$session_one_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_two/i)
{
$session_two_valid=0; $session_two_start=''; $session_two_end='';
$session_two = $container_lines[$c];
$session_two =~ s/session_two=>//gi;
if ( (length($session_two) > 0) && (length($session_two) <= 9) && ($session_two =~ /,/) )
{
@session_twoARY = split(/,/,$session_two);
$session_two_start = $session_twoARY[0];
$session_two_end = $session_twoARY[1];
if ( (length($session_two_start) >= 4) && (length($session_two_end) >= 4) && ($session_one_valid > 0) && ($session_one_end <= $session_two_start) && ($session_two_start < $session_two_end) && ($session_two_end <= 2400) )
{
$settings_session_score++;
$session_two_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_three/i)
{
$session_three_valid=0; $session_three_start=''; $session_three_end='';
$session_three = $container_lines[$c];
$session_three =~ s/session_three=>//gi;
if ( (length($session_three) > 0) && (length($session_three) <= 9) && ($session_three =~ /,/) )
{
@session_threeARY = split(/,/,$session_three);
$session_three_start = $session_threeARY[0];
$session_three_end = $session_threeARY[1];
if ( (length($session_three_start) >= 4) && (length($session_three_end) >= 4) && ($session_two_valid > 0) && ($session_two_end <= $session_three_start) && ($session_three_start < $session_three_end) && ($session_three_end <= 2400) )
{
$settings_session_score++;
$session_three_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_four/i)
{
$session_four_valid=0; $session_four_start=''; $session_four_end='';
$session_four = $container_lines[$c];
$session_four =~ s/session_four=>//gi;
if ( (length($session_four) > 0) && (length($session_four) <= 9) && ($session_four =~ /,/) )
{
@session_fourARY = split(/,/,$session_four);
$session_four_start = $session_fourARY[0];
$session_four_end = $session_fourARY[1];
if ( (length($session_four_start) >= 4) && (length($session_four_end) >= 4) && ($session_three_valid > 0) && ($session_three_end <= $session_four_start) && ($session_four_start < $session_four_end) && ($session_four_end <= 2400) )
{
$settings_session_score++;
$session_four_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_five/i)
{
$session_five_valid=0; $session_five_start=''; $session_five_end='';
$session_five = $container_lines[$c];
$session_five =~ s/session_five=>//gi;
if ( (length($session_five) > 0) && (length($session_five) <= 9) && ($session_five =~ /,/) )
{
@session_fiveARY = split(/,/,$session_five);
$session_five_start = $session_fiveARY[0];
$session_five_end = $session_fiveARY[1];
if ( (length($session_five_start) >= 4) && (length($session_five_end) >= 4) && ($session_four_valid > 0) && ($session_four_end <= $session_five_start) && ($session_five_start < $session_five_end) && ($session_five_end <= 2400) )
{
$settings_session_score++;
$session_five_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_six/i)
{
$session_six_valid=0; $session_six_start=''; $session_six_end='';
$session_six = $container_lines[$c];
$session_six =~ s/session_six=>//gi;
if ( (length($session_six) > 0) && (length($session_six) <= 9) && ($session_six =~ /,/) )
{
@session_sixARY = split(/,/,$session_six);
$session_six_start = $session_sixARY[0];
$session_six_end = $session_sixARY[1];
if ( (length($session_six_start) >= 4) && (length($session_six_end) >= 4) && ($session_five_valid > 0) && ($session_five_end <= $session_six_start) && ($session_six_start < $session_six_end) && ($session_six_end <= 2400) )
{
$settings_session_score++;
$session_six_valid++;
}
}
}
}
else
{if ($DBX > 0) {print " blank line: $c|$container_lines[$c]|\n";}}
$c++;
}
if ($settings_session_score >= 1)
{
$stmtA = "SELECT list_id,called_count,rank FROM vicidial_list where lead_id='$CLlead_id';";
$event_string = "|$stmtA|"; &event_logger;
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$VLlist_id = $aryA[0];
$VLcalled_count = $aryA[1];
$VLrank = $aryA[2];
$tempVLrank = $VLrank;
if ( ($zero_rank_after_call > 0) && ($VLrank > 0) ) {$tempVLrank=0;}
}
$sthA->finish();
$secX = time();
$CQtarget = ($secX - 14400); # look back 4 hours
($CQsec,$CQmin,$CQhour,$CQmday,$CQmon,$CQyear,$CQwday,$CQyday,$CQisdst) = localtime($CQtarget);
$CQyear = ($CQyear + 1900);
$CQmon++;
if ($CQmon < 10) {$CQmon = "0$CQmon";}
if ($CQmday < 10) {$CQmday = "0$CQmday";}
if ($CQhour < 10) {$CQhour = "0$CQhour";}
if ($CQmin < 10) {$CQmin = "0$CQmin";}
if ($CQsec < 10) {$CQsec = "0$CQsec";}
$CQSQLdate = "$CQyear-$CQmon-$CQmday $CQhour:$CQmin:$CQsec";
$VDL_call_datetime='';
$stmtA = "SELECT call_date from vicidial_dial_log where lead_id='$CLlead_id' and call_date > \"$CQSQLdate\" and caller_code LIKE \"%$CLlead_id\" order by call_date desc limit 1;";
$event_string = "|$stmtA|"; &event_logger;
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$VDLcall_datetime = $aryA[0];
@VDLcall_datetimeARY = split(/ /,$VDLcall_datetime);
@VDLcall_timeARY = split(/:/,$VDLcall_datetimeARY[1]);
$VDLcall_hourmin = "$VDLcall_timeARY[0]$VDLcall_timeARY[1]";
if ( ($session_one_start <= $VDLcall_hourmin) and ($session_one_end > $VDLcall_hourmin) )
{
$call_in_session=1;
$session_newSQL=",session_one_calls='1',session_one_today_calls='1'";
$session_updateSQL=",session_one_calls=(session_one_calls + 1),session_one_today_calls=(session_one_today_calls + 1)";
}
if ( ($session_two_start <= $VDLcall_hourmin) and ($session_two_end > $VDLcall_hourmin) )
{
$call_in_session=2;
$session_newSQL=",session_two_calls='1',session_two_today_calls='1'";
$session_updateSQL=",session_two_calls=(session_two_calls + 1),session_two_today_calls=(session_two_today_calls + 1)";
}
if ( ($session_three_start <= $VDLcall_hourmin) and ($session_three_end > $VDLcall_hourmin) )
{
$call_in_session=3;
$session_newSQL=",session_three_calls='1',session_three_today_calls='1'";
$session_updateSQL=",session_three_calls=(session_three_calls + 1),session_three_today_calls=(session_three_today_calls + 1)";
}
if ( ($session_four_start <= $VDLcall_hourmin) and ($session_four_end > $VDLcall_hourmin) )
{
$call_in_session=4;
$session_newSQL=",session_four_calls='1',session_four_today_calls='1'";
$session_updateSQL=",session_four_calls=(session_four_calls + 1),session_four_today_calls=(session_four_today_calls + 1)";
}
if ( ($session_five_start <= $VDLcall_hourmin) and ($session_five_end > $VDLcall_hourmin) )
{
$call_in_session=5;
$session_newSQL=",session_five_calls='1',session_five_today_calls='1'";
$session_updateSQL=",session_five_calls=(session_five_calls + 1),session_five_today_calls=(session_five_today_calls + 1)";
}
if ( ($session_six_start <= $VDLcall_hourmin) and ($session_six_end > $VDLcall_hourmin) )
{
$call_in_session=6;
$session_newSQL=",session_six_calls='1',session_six_today_calls='1'";
$session_updateSQL=",session_six_calls=(session_six_calls + 1),session_six_today_calls=(session_six_today_calls + 1)";
}
$event_string = "CQ-Debug 2: $VDLcall_datetime|$VDLcall_hourmin|$timeclock_end_of_day|$session_one_start|$session_one_end|$call_in_session|"; &event_logger;
if ($call_in_session > 0)
{
if (length($timeclock_end_of_day) < 1) {$timeclock_end_of_day='0000';}
$timeclock_end_of_day_hour = (substr($timeclock_end_of_day, 0, 2) + 0);
$timeclock_end_of_day_min = (substr($timeclock_end_of_day, 2, 2) + 0);
$today_start_epoch = timelocal('0',$timeclock_end_of_day_min,$timeclock_end_of_day_hour,$mday,($mon-1),$year);
if ($timeclock_end_of_day > $VDLcall_hourmin)
{$today_start_epoch = ($today_start_epoch - 86400);}
$day_two_start_epoch = ($today_start_epoch - (86400 * 1));
$day_three_start_epoch = ($today_start_epoch - (86400 * 2));
$day_four_start_epoch = ($today_start_epoch - (86400 * 3));
$day_five_start_epoch = ($today_start_epoch - (86400 * 4));
$day_six_start_epoch = ($today_start_epoch - (86400 * 5));
$day_seven_start_epoch = ($today_start_epoch - (86400 * 6));
# Gather the details on existing vicidial_lead_call_quota_counts for this lead, if there is one
$stmtA = "SELECT first_call_date,UNIX_TIMESTAMP(first_call_date),last_call_date from vicidial_lead_call_quota_counts where lead_id='$CLlead_id' and list_id='$VLlist_id';";
$event_string = "|$stmtA|"; &event_logger;
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$VLCQCinfo_ct=$sthA->rows;
if ($VLCQCinfo_ct > 0)
{
@aryA = $sthA->fetchrow_array;
$VLCQCfirst_call_datetime = $aryA[0];
$VLCQCfirst_call_epoch = $aryA[1];
$VLCQClast_call_date = $aryA[2];
if ($VDLcall_datetime ne $VLCQClast_call_date)
{
if ($VLCQCfirst_call_epoch >= $today_start_epoch)
{$day_updateSQL=',day_one_calls=(day_one_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_two_start_epoch) and ($VLCQCfirst_call_epoch < $today_start_epoch) )
{$day_updateSQL=',day_two_calls=(day_two_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_three_start_epoch) and ($VLCQCfirst_call_epoch < $day_two_start_epoch) )
{$day_updateSQL=',day_three_calls=(day_three_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_four_start_epoch) and ($VLCQCfirst_call_epoch < $day_three_start_epoch) )
{$day_updateSQL=',day_four_calls=(day_four_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_five_start_epoch) and ($VLCQCfirst_call_epoch < $day_four_start_epoch) )
{$day_updateSQL=',day_five_calls=(day_five_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_six_start_epoch) and ($VLCQCfirst_call_epoch < $day_five_start_epoch) )
{$day_updateSQL=',day_six_calls=(day_six_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_seven_start_epoch) and ($VLCQCfirst_call_epoch < $day_six_start_epoch) )
{$day_updateSQL=',day_seven_calls=(day_seven_calls+1)';}
# Update in the vicidial_lead_call_quota_counts table for this lead
$stmtA="UPDATE vicidial_lead_call_quota_counts SET last_call_date='$VDLcall_datetime',status='$CLnew_status',called_count='$VLcalled_count',rank='$tempVLrank',modify_date=NOW() $session_updateSQL $day_updateSQL where lead_id='$CLlead_id' and list_id='$VLlist_id' and modify_date < NOW();";
}
else
{
# Update in the vicidial_lead_call_quota_counts table for this lead
$stmtA="UPDATE vicidial_lead_call_quota_counts SET status='$CLnew_status',called_count='$VLcalled_count',rank='$tempVLrank',modify_date=NOW() where lead_id='$CLlead_id' and list_id='$VLlist_id';";
}
$VLCQCaffected_rows_update = $dbhA->do($stmtA);
$event_string = "-- VLCQC record updated: |$VLCQCaffected_rows_update| |$stmtA|"; &event_logger;
}
else
{
# Insert new record into vicidial_lead_call_quota_counts table for this lead
$stmtA="INSERT INTO vicidial_lead_call_quota_counts SET lead_id='$CLlead_id',list_id='$VLlist_id',first_call_date='$VDLcall_datetime',last_call_date='$VDLcall_datetime',status='$CLnew_status',called_count='$VLcalled_count',day_one_calls='1',rank='$tempVLrank',modify_date=NOW() $session_newSQL;";
$VLCQCaffected_rows_update = $dbhA->do($stmtA);
$event_string = "-- VLCQC record inserted: |$VLCQCaffected_rows_update| |$stmtA|"; &event_logger;
}
if ( ($zero_rank_after_call > 0) && ($VLrank > 0) )
{
# Update this lead to rank=0
$stmtA="UPDATE vicidial_list SET rank='0' where lead_id='$CLlead_id';";
$VLCQCaffected_rows_zero_rank = $dbhA->do($stmtA);
$event_string = "-- VLCQC lead rank zero: |$VLCQCaffected_rows_zero_rank| |$stmtA|"; &event_logger;
}
}
}
$sthA->finish();
}
}
}
##### END Call Quota Lead Ranking logging #####
##### BEGIN AUTO ALT PHONE DIAL SECTION #####
$event_string = "|$stmtA|$VD_auto_alt_dial|$VD_auto_alt_dial_statuses|$CLnew_status|$CLlead_id|$CLalt_dial"; &event_logger;
if ( ($VD_auto_alt_dial_statuses =~ / $CLnew_status /) && ($CLlead_id > 0) )
{
File diff suppressed because it is too large Load Diff
+394 -53
View File
@@ -11,7 +11,7 @@
# agents that should appear to be logged in so that the calls can be transferred
# out to them properly.
#
# Copyright (C) 2017 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2019 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGELOG:
# 50215-0954 - First version of script
@@ -52,6 +52,7 @@
# 141113-1559 - Added concurrency check
# 161102-1032 - Fixed QM partition problem
# 170527-2348 - Fix for rare inbound logging issue #1017
# 190716-1628 - Added code for Call Quotas
#
### begin parsing run-time options ###
@@ -169,11 +170,28 @@ if (!$VDRLOGfile) {$VDRLOGfile = "$PATHlogs/remoteagent.$year-$mon-$mday";}
if (!$VARDB_port) {$VARDB_port='3306';}
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Time::Local;
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;
#############################################
##### Gather system_settings #####
$stmtA = "SELECT sip_event_logging,call_quota_lead_ranking FROM system_settings;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$SSsip_event_logging = $aryA[0];
$SScall_quota_lead_ranking = $aryA[1];
}
$sthA->finish();
###########################################
### Grab Server values from the database
$stmtA = "SELECT vd_server_logs,local_gmt,ext_context FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
@@ -367,63 +385,63 @@ while($one_day_interval > 0)
$stmtE = "INSERT IGNORE INTO vicidial_inbound_group_agents set calls_today=1,user='$QHuser[$w]',group_id='$QHcampaign_id[$w]';";
$Eaffected_rows = $dbhA->do($stmtE);
##### BEGIN check for user max inbound calls #####
$max_inbound_calls=0;
$stmtJ = "SELECT max_inbound_calls FROM vicidial_users where user='$QHuser[$w]';";
$sthA = $dbhA->prepare($stmtJ) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtJ ", $dbhA->errstr;
$sthArowsMIC=$sthA->rows;
if ($sthArowsMIC > 0)
{
@aryA = $sthA->fetchrow_array;
$VU_max_inbound_calls = $aryA[0];
}
$stmtJ = "SELECT max_inbound_calls FROM vicidial_campaigns where campaign_id='$QHcampaign_id[$w]';";
$sthA = $dbhA->prepare($stmtJ) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtJ ", $dbhA->errstr;
$sthArowsMIC=$sthA->rows;
if ($sthArowsMIC > 0)
{
@aryA = $sthA->fetchrow_array;
$CP_max_inbound_calls = $aryA[0];
}
if ( ($VU_max_inbound_calls > 0) || ($CP_max_inbound_calls > 0) )
{
$max_inbound_calls = $CP_max_inbound_calls;
if ($VU_max_inbound_calls > 0)
{$max_inbound_calls = $VU_max_inbound_calls;}
$max_inbound_count=0;
$stmtJ = "SELECT sum(calls_today) FROM vicidial_inbound_group_agents where user='$QHuser[$w]' and group_type='C';";
##### BEGIN check for user max inbound calls #####
$max_inbound_calls=0;
$stmtJ = "SELECT max_inbound_calls FROM vicidial_users where user='$QHuser[$w]';";
$sthA = $dbhA->prepare($stmtJ) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtJ ", $dbhA->errstr;
$sthArowsVIGA=$sthA->rows;
if ($sthArowsVIGA > 0)
$sthArowsMIC=$sthA->rows;
if ($sthArowsMIC > 0)
{
@aryA = $sthA->fetchrow_array;
$max_inbound_count = $aryA[0];
$VU_max_inbound_calls = $aryA[0];
}
if ($max_inbound_count >= $max_inbound_calls)
$stmtJ = "SELECT max_inbound_calls FROM vicidial_campaigns where campaign_id='$QHcampaign_id[$w]';";
$sthA = $dbhA->prepare($stmtJ) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtJ ", $dbhA->errstr;
$sthArowsMIC=$sthA->rows;
if ($sthArowsMIC > 0)
{
$stmtJ = "UPDATE vicidial_live_agents set closer_campaigns='' where user='$QHuser[$w]';";
$affected_rows = $dbhA->do($stmtJ);
$stmtJ = "DELETE FROM vicidial_live_inbound_agents where user='$QHuser[$w]';";
$affected_rows = $dbhA->do($stmtJ);
$stmtJ = "UPDATE vicidial_remote_agents set closer_campaigns='' where user_start='$QHuser[$w]';";
$affected_rows = $dbhA->do($stmtJ);
$stmtJ = "INSERT INTO vicidial_admin_log set event_date=NOW(), user='$QHuser[$w]', ip_address='$VARserver_ip', event_section='USERS', event_type='MODIFY', record_id='$QHuser[$w]', event_code='MAX IN CALLS MODIFY REMOTE AGENT', event_sql='DELETE FROM vicidial_live_inbound_agents where user=$QHuser[$w]', event_notes='|$max_inbound_count|$max_inbound_calls|$QHuser[$w]|$QHcall_id[$w]|RA|';";
$affected_rows = $dbhA->do($stmtJ);
if ($AGILOG) {$agi_string = "-- MAX INBOUND AGENT CALLS TRIGGER: |$max_inbound_count|$max_inbound_calls|$QHuser[$w]|$QHcall_id[$w]|"; &agi_output;}
@aryA = $sthA->fetchrow_array;
$CP_max_inbound_calls = $aryA[0];
}
}
##### END check for user max inbound calls #####
if ( ($VU_max_inbound_calls > 0) || ($CP_max_inbound_calls > 0) )
{
$max_inbound_calls = $CP_max_inbound_calls;
if ($VU_max_inbound_calls > 0)
{$max_inbound_calls = $VU_max_inbound_calls;}
$max_inbound_count=0;
$stmtJ = "SELECT sum(calls_today) FROM vicidial_inbound_group_agents where user='$QHuser[$w]' and group_type='C';";
$sthA = $dbhA->prepare($stmtJ) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtJ ", $dbhA->errstr;
$sthArowsVIGA=$sthA->rows;
if ($sthArowsVIGA > 0)
{
@aryA = $sthA->fetchrow_array;
$max_inbound_count = $aryA[0];
}
if ($max_inbound_count >= $max_inbound_calls)
{
$stmtJ = "UPDATE vicidial_live_agents set closer_campaigns='' where user='$QHuser[$w]';";
$affected_rows = $dbhA->do($stmtJ);
$stmtJ = "DELETE FROM vicidial_live_inbound_agents where user='$QHuser[$w]';";
$affected_rows = $dbhA->do($stmtJ);
$stmtJ = "UPDATE vicidial_remote_agents set closer_campaigns='' where user_start='$QHuser[$w]';";
$affected_rows = $dbhA->do($stmtJ);
$stmtJ = "INSERT INTO vicidial_admin_log set event_date=NOW(), user='$QHuser[$w]', ip_address='$VARserver_ip', event_section='USERS', event_type='MODIFY', record_id='$QHuser[$w]', event_code='MAX IN CALLS MODIFY REMOTE AGENT', event_sql='DELETE FROM vicidial_live_inbound_agents where user=$QHuser[$w]', event_notes='|$max_inbound_count|$max_inbound_calls|$QHuser[$w]|$QHcall_id[$w]|RA|';";
$affected_rows = $dbhA->do($stmtJ);
$event_string = "-- MAX INBOUND AGENT CALLS TRIGGER: |$max_inbound_count|$max_inbound_calls|$QHuser[$w]|$QHcall_id[$w]|"; &event_logger;
}
}
##### END check for user max inbound calls #####
$stmtG = "SELECT start_call_url FROM vicidial_inbound_groups where group_id='$QHcampaign_id[$w]';";
$stmtG = "SELECT start_call_url,'DISABLED' FROM vicidial_inbound_groups where group_id='$QHcampaign_id[$w]';";
}
else
{
@@ -433,7 +451,7 @@ while($one_day_interval > 0)
$Daffected_rows=0;
$Eaffected_rows=0;
$stmtG = "SELECT start_call_url FROM vicidial_campaigns where campaign_id='$QHcampaign_id[$w]';";
$stmtG = "SELECT start_call_url,call_quota_lead_ranking FROM vicidial_campaigns where campaign_id='$QHcampaign_id[$w]';";
}
$sthA = $dbhA->prepare($stmtG) or die "preparing: ",$dbhA->errstr;
@@ -442,10 +460,17 @@ while($one_day_interval > 0)
if ($start_url_ct > 0)
{
@aryA = $sthA->fetchrow_array;
$start_call_url = $aryA[0];
$start_call_url = $aryA[0];
$VD_call_quota_lead_ranking = $aryA[1];
}
$sthA->finish();
if ( ($SScall_quota_lead_ranking > 0) && ($VD_call_quota_lead_ranking !~ /^DISABLED$/i) )
{
$CIDlead_id = $QHlead_id[$w];
$temp_status = 'XFER';
&call_quota_logging;
}
##### BEGIN remote agent concurrent call calculation and updating
$concurrent_calls=0;
@@ -482,14 +507,14 @@ while($one_day_interval > 0)
$stmtA = "UPDATE vicidial_daily_ra_stats SET update_time=NOW(),total_calls=(total_calls + 1)$update_SQL where user='$QHra_user[$w]' and stats_flag='OPEN';";
$affected_rows = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "DAILY STATS UPDATE $channel_group|$affected_rows|$stmtA|\n"; &agi_output;}
$event_string = "DAILY STATS UPDATE $channel_group|$affected_rows|$stmtA|"; &event_logger;
}
else
{
$sthA->finish();
$stmtA = "INSERT INTO vicidial_daily_ra_stats SET stats_date='$YMD',update_time=NOW(),max_calls='$incalls_count',user='$QHra_user[$w]',stats_flag='OPEN',total_calls=1;";
$affected_rows = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "DAILY STATS INSERT $channel_group|$affected_rows|$stmtA|"; &agi_output;}
$event_string = "DAILY STATS INSERT $channel_group|$affected_rows|$stmtA|"; &event_logger;
}
##### END remote agent concurrent call calculation and updating
@@ -1288,3 +1313,319 @@ sub event_logger
}
$event_string='';
}
##### BEGIN Call Quota Lead Ranking logging #####
sub call_quota_logging
{
# Gather settings container for Call Quota Lead Ranking
$CQcontainer_entry='';
$stmtA = "SELECT container_entry FROM vicidial_settings_containers where container_id='$VD_call_quota_lead_ranking';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$CQcontainer_entry = $aryA[0];
$CQcontainer_entry =~ s/\\//gi;
}
$sthA->finish();
# Define variables for Call Quota settings
$session_one='';
$session_two='';
$session_three='';
$session_four='';
$session_five='';
$session_six='';
$settings_session_score=0;
$zero_rank_after_call=0;
if (length($CQcontainer_entry) > 5)
{
@container_lines = split(/\n/,$CQcontainer_entry);
$c=0;
foreach(@container_lines)
{
$container_lines[$c] =~ s/;.*|\r|\t| //gi;
if (length($container_lines[$c]) > 5)
{
# define core settings
if ($container_lines[$c] =~ /^zero_rank_after_call/i)
{
$container_lines[$c] =~ s/zero_rank_after_call=>//gi;
if ( ($container_lines[$c] >= 0) && ($container_lines[$c] <= 1) )
{
$zero_rank_after_call = $container_lines[$c];
}
}
# define sessions
if ($container_lines[$c] =~ /^session_one/i)
{
$session_one_valid=0; $session_one_start=''; $session_one_end='';
$session_one = $container_lines[$c];
$session_one =~ s/session_one=>//gi;
if ( (length($session_one) > 0) && (length($session_one) <= 9) && ($session_one =~ /,/) )
{
@session_oneARY = split(/,/,$session_one);
$session_one_start = $session_oneARY[0];
$session_one_end = $session_oneARY[1];
if ( (length($session_one_start) >= 4) && (length($session_one_end) >= 4) && ($session_one_start < $session_one_end) && ($session_one_end <= 2400) )
{
$settings_session_score++;
$session_one_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_two/i)
{
$session_two_valid=0; $session_two_start=''; $session_two_end='';
$session_two = $container_lines[$c];
$session_two =~ s/session_two=>//gi;
if ( (length($session_two) > 0) && (length($session_two) <= 9) && ($session_two =~ /,/) )
{
@session_twoARY = split(/,/,$session_two);
$session_two_start = $session_twoARY[0];
$session_two_end = $session_twoARY[1];
if ( (length($session_two_start) >= 4) && (length($session_two_end) >= 4) && ($session_one_valid > 0) && ($session_one_end <= $session_two_start) && ($session_two_start < $session_two_end) && ($session_two_end <= 2400) )
{
$settings_session_score++;
$session_two_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_three/i)
{
$session_three_valid=0; $session_three_start=''; $session_three_end='';
$session_three = $container_lines[$c];
$session_three =~ s/session_three=>//gi;
if ( (length($session_three) > 0) && (length($session_three) <= 9) && ($session_three =~ /,/) )
{
@session_threeARY = split(/,/,$session_three);
$session_three_start = $session_threeARY[0];
$session_three_end = $session_threeARY[1];
if ( (length($session_three_start) >= 4) && (length($session_three_end) >= 4) && ($session_two_valid > 0) && ($session_two_end <= $session_three_start) && ($session_three_start < $session_three_end) && ($session_three_end <= 2400) )
{
$settings_session_score++;
$session_three_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_four/i)
{
$session_four_valid=0; $session_four_start=''; $session_four_end='';
$session_four = $container_lines[$c];
$session_four =~ s/session_four=>//gi;
if ( (length($session_four) > 0) && (length($session_four) <= 9) && ($session_four =~ /,/) )
{
@session_fourARY = split(/,/,$session_four);
$session_four_start = $session_fourARY[0];
$session_four_end = $session_fourARY[1];
if ( (length($session_four_start) >= 4) && (length($session_four_end) >= 4) && ($session_three_valid > 0) && ($session_three_end <= $session_four_start) && ($session_four_start < $session_four_end) && ($session_four_end <= 2400) )
{
$settings_session_score++;
$session_four_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_five/i)
{
$session_five_valid=0; $session_five_start=''; $session_five_end='';
$session_five = $container_lines[$c];
$session_five =~ s/session_five=>//gi;
if ( (length($session_five) > 0) && (length($session_five) <= 9) && ($session_five =~ /,/) )
{
@session_fiveARY = split(/,/,$session_five);
$session_five_start = $session_fiveARY[0];
$session_five_end = $session_fiveARY[1];
if ( (length($session_five_start) >= 4) && (length($session_five_end) >= 4) && ($session_four_valid > 0) && ($session_four_end <= $session_five_start) && ($session_five_start < $session_five_end) && ($session_five_end <= 2400) )
{
$settings_session_score++;
$session_five_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_six/i)
{
$session_six_valid=0; $session_six_start=''; $session_six_end='';
$session_six = $container_lines[$c];
$session_six =~ s/session_six=>//gi;
if ( (length($session_six) > 0) && (length($session_six) <= 9) && ($session_six =~ /,/) )
{
@session_sixARY = split(/,/,$session_six);
$session_six_start = $session_sixARY[0];
$session_six_end = $session_sixARY[1];
if ( (length($session_six_start) >= 4) && (length($session_six_end) >= 4) && ($session_five_valid > 0) && ($session_five_end <= $session_six_start) && ($session_six_start < $session_six_end) && ($session_six_end <= 2400) )
{
$settings_session_score++;
$session_six_valid++;
}
}
}
}
else
{if ($DBX > 0) {print " blank line: $c|$container_lines[$c]|\n";}}
$c++;
}
if ($settings_session_score >= 1)
{
$stmtA = "SELECT list_id,called_count,rank FROM vicidial_list where lead_id='$CIDlead_id';";
$event_string = "|$stmtA|"; &event_logger;
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$VLlist_id = $aryA[0];
$VLcalled_count = $aryA[1];
$VLrank = $aryA[2];
$tempVLrank = $VLrank;
if ( ($zero_rank_after_call > 0) && ($VLrank > 0) ) {$tempVLrank=0;}
}
$sthA->finish();
$secX = time();
$CQtarget = ($secX - 14400); # look back 4 hours
($CQsec,$CQmin,$CQhour,$CQmday,$CQmon,$CQyear,$CQwday,$CQyday,$CQisdst) = localtime($CQtarget);
$CQyear = ($CQyear + 1900);
$CQmon++;
if ($CQmon < 10) {$CQmon = "0$CQmon";}
if ($CQmday < 10) {$CQmday = "0$CQmday";}
if ($CQhour < 10) {$CQhour = "0$CQhour";}
if ($CQmin < 10) {$CQmin = "0$CQmin";}
if ($CQsec < 10) {$CQsec = "0$CQsec";}
$CQSQLdate = "$CQyear-$CQmon-$CQmday $CQhour:$CQmin:$CQsec";
$VDL_call_datetime='';
$stmtA = "SELECT call_date from vicidial_dial_log where lead_id='$CIDlead_id' and call_date > \"$CQSQLdate\" and caller_code LIKE \"%$CIDlead_id\" order by call_date desc limit 1;";
$event_string = "|$stmtA|"; &event_logger;
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$VDLcall_datetime = $aryA[0];
@VDLcall_datetimeARY = split(/ /,$VDLcall_datetime);
@VDLcall_timeARY = split(/:/,$VDLcall_datetimeARY[1]);
$VDLcall_hourmin = "$VDLcall_timeARY[0]$VDLcall_timeARY[1]";
if ( ($session_one_start <= $VDLcall_hourmin) and ($session_one_end > $VDLcall_hourmin) )
{
$call_in_session=1;
$session_newSQL=",session_one_calls='1',session_one_today_calls='1'";
$session_updateSQL=",session_one_calls=(session_one_calls + 1),session_one_today_calls=(session_one_today_calls + 1)";
}
if ( ($session_two_start <= $VDLcall_hourmin) and ($session_two_end > $VDLcall_hourmin) )
{
$call_in_session=2;
$session_newSQL=",session_two_calls='1',session_two_today_calls='1'";
$session_updateSQL=",session_two_calls=(session_two_calls + 1),session_two_today_calls=(session_two_today_calls + 1)";
}
if ( ($session_three_start <= $VDLcall_hourmin) and ($session_three_end > $VDLcall_hourmin) )
{
$call_in_session=3;
$session_newSQL=",session_three_calls='1',session_three_today_calls='1'";
$session_updateSQL=",session_three_calls=(session_three_calls + 1),session_three_today_calls=(session_three_today_calls + 1)";
}
if ( ($session_four_start <= $VDLcall_hourmin) and ($session_four_end > $VDLcall_hourmin) )
{
$call_in_session=4;
$session_newSQL=",session_four_calls='1',session_four_today_calls='1'";
$session_updateSQL=",session_four_calls=(session_four_calls + 1),session_four_today_calls=(session_four_today_calls + 1)";
}
if ( ($session_five_start <= $VDLcall_hourmin) and ($session_five_end > $VDLcall_hourmin) )
{
$call_in_session=5;
$session_newSQL=",session_five_calls='1',session_five_today_calls='1'";
$session_updateSQL=",session_five_calls=(session_five_calls + 1),session_five_today_calls=(session_five_today_calls + 1)";
}
if ( ($session_six_start <= $VDLcall_hourmin) and ($session_six_end > $VDLcall_hourmin) )
{
$call_in_session=6;
$session_newSQL=",session_six_calls='1',session_six_today_calls='1'";
$session_updateSQL=",session_six_calls=(session_six_calls + 1),session_six_today_calls=(session_six_today_calls + 1)";
}
$event_string = "CQ-Debug 2: $VDLcall_datetime|$VDLcall_hourmin|$timeclock_end_of_day|$session_one_start|$session_one_end|$call_in_session|"; &event_logger;
if ($call_in_session > 0)
{
if (length($timeclock_end_of_day) < 1) {$timeclock_end_of_day='0000';}
$timeclock_end_of_day_hour = (substr($timeclock_end_of_day, 0, 2) + 0);
$timeclock_end_of_day_min = (substr($timeclock_end_of_day, 2, 2) + 0);
$today_start_epoch = timelocal('0',$timeclock_end_of_day_min,$timeclock_end_of_day_hour,$mday,($mon-1),$year);
if ($timeclock_end_of_day > $VDLcall_hourmin)
{$today_start_epoch = ($today_start_epoch - 86400);}
$day_two_start_epoch = ($today_start_epoch - (86400 * 1));
$day_three_start_epoch = ($today_start_epoch - (86400 * 2));
$day_four_start_epoch = ($today_start_epoch - (86400 * 3));
$day_five_start_epoch = ($today_start_epoch - (86400 * 4));
$day_six_start_epoch = ($today_start_epoch - (86400 * 5));
$day_seven_start_epoch = ($today_start_epoch - (86400 * 6));
# Gather the details on existing vicidial_lead_call_quota_counts for this lead, if there is one
$stmtA = "SELECT first_call_date,UNIX_TIMESTAMP(first_call_date),last_call_date from vicidial_lead_call_quota_counts where lead_id='$CIDlead_id' and list_id='$VLlist_id';";
$event_string = "|$stmtA|"; &event_logger;
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$VLCQCinfo_ct=$sthA->rows;
if ($VLCQCinfo_ct > 0)
{
@aryA = $sthA->fetchrow_array;
$VLCQCfirst_call_datetime = $aryA[0];
$VLCQCfirst_call_epoch = $aryA[1];
$VLCQClast_call_date = $aryA[2];
if ($VDLcall_datetime ne $VLCQClast_call_date)
{
if ($VLCQCfirst_call_epoch >= $today_start_epoch)
{$day_updateSQL=',day_one_calls=(day_one_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_two_start_epoch) and ($VLCQCfirst_call_epoch < $today_start_epoch) )
{$day_updateSQL=',day_two_calls=(day_two_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_three_start_epoch) and ($VLCQCfirst_call_epoch < $day_two_start_epoch) )
{$day_updateSQL=',day_three_calls=(day_three_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_four_start_epoch) and ($VLCQCfirst_call_epoch < $day_three_start_epoch) )
{$day_updateSQL=',day_four_calls=(day_four_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_five_start_epoch) and ($VLCQCfirst_call_epoch < $day_four_start_epoch) )
{$day_updateSQL=',day_five_calls=(day_five_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_six_start_epoch) and ($VLCQCfirst_call_epoch < $day_five_start_epoch) )
{$day_updateSQL=',day_six_calls=(day_six_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_seven_start_epoch) and ($VLCQCfirst_call_epoch < $day_six_start_epoch) )
{$day_updateSQL=',day_seven_calls=(day_seven_calls+1)';}
# Update in the vicidial_lead_call_quota_counts table for this lead
$stmtA="UPDATE vicidial_lead_call_quota_counts SET last_call_date='$VDLcall_datetime',status='$temp_status',called_count='$VLcalled_count',rank='$tempVLrank',modify_date=NOW() $session_updateSQL $day_updateSQL where lead_id='$CIDlead_id' and list_id='$VLlist_id';";
}
else
{
# Update in the vicidial_lead_call_quota_counts table for this lead
$stmtA="UPDATE vicidial_lead_call_quota_counts SET status='$temp_status',called_count='$VLcalled_count',rank='$tempVLrank',modify_date=NOW() where lead_id='$CIDlead_id' and list_id='$VLlist_id';";
}
$VLCQCaffected_rows_update = $dbhA->do($stmtA);
$event_string = "-- VLCQC record updated: |$VLCQCaffected_rows_update| |$stmtA|"; &event_logger;
}
else
{
# Insert new record into vicidial_lead_call_quota_counts table for this lead
$stmtA="INSERT INTO vicidial_lead_call_quota_counts SET lead_id='$CIDlead_id',list_id='$VLlist_id',first_call_date='$VDLcall_datetime',last_call_date='$VDLcall_datetime',status='$temp_status',called_count='$VLcalled_count',day_one_calls='1',rank='$tempVLrank',modify_date=NOW() $session_newSQL;";
$VLCQCaffected_rows_update = $dbhA->do($stmtA);
$event_string = "-- VLCQC record inserted: |$VLCQCaffected_rows_update| |$stmtA|"; &event_logger;
}
if ( ($zero_rank_after_call > 0) && ($VLrank > 0) )
{
# Update this lead to rank=0
$stmtA="UPDATE vicidial_list SET rank='0' where lead_id='$CIDlead_id';";
$VLCQCaffected_rows_zero_rank = $dbhA->do($stmtA);
$event_string = "-- VLCQC lead rank zero: |$VLCQCaffected_rows_zero_rank| |$stmtA|"; &event_logger;
}
}
}
$sthA->finish();
}
}
}
##### END Call Quota Lead Ranking logging #####
+363 -6
View File
@@ -25,7 +25,7 @@
# exten => h,1,DeadAGI(agi://127.0.0.1:4577/call_log--HVcauses--PRI-----NODEBUG-----${HANGUPCAUSE}-----${DIALSTATUS}-----${DIALEDTIME}-----${ANSWEREDTIME})
#
#
# Copyright (C) 2018 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2019 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGELOG:
# 61010-1007 - First test build
@@ -83,6 +83,7 @@
# 180521-1153 - Changed closer log logging to use agent if call was AGENTDIRECT
# 180919-1729 - Fix for rare non-NA-set-as-NA call logging issue
# 190626-1100 - Added more logging for Auto-Alt-Dial debug
# 190709-2240 - Added Call Quota logging
#
# defaults for PreFork
@@ -182,6 +183,7 @@ use vars qw(@ISA);
use Net::Server::PreFork; # any personality will do
@ISA = qw(Net::Server::PreFork);
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Time::Local;
@@ -1071,6 +1073,28 @@ sub process_request
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$VDLXaffected_rows = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- VDAD vicidial_extended_log insert: |$VDLXaffected_rows|$uniqueid|$CIDlead_id|$VDL_status|"; &agi_output;}
if ($SScall_quota_lead_ranking > 0)
{
### check to see if campaign call quotas enabled
$VD_call_quota_lead_ranking='DISABLED';
$stmtA="SELECT call_quota_lead_ranking FROM vicidial_campaigns where campaign_id='$VD_campaign_id';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$VD_call_quota_lead_ranking = $aryA[0];
}
if ($VD_call_quota_lead_ranking !~ /^DISABLED$/i)
{
$temp_status = $VDL_status;
&call_quota_logging;
}
}
}
}
if ( ($CPDfound > 0) && ($VDL_status !~ /AA/) )
@@ -1400,14 +1424,16 @@ sub process_request
#############################################
##### SYSTEM SETTINGS LOOKUP #####
$stmtA = "SELECT enable_drop_lists FROM system_settings;";
$stmtA = "SELECT enable_drop_lists,call_quota_lead_ranking,timeclock_end_of_day FROM system_settings;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$enable_drop_lists = $aryA[0];
$enable_drop_lists = $aryA[0];
$SScall_quota_lead_ranking = $aryA[1];
$timeclock_end_of_day = $aryA[2];
}
$sthA->finish();
##### END SYSTEM SETTINGS LOOKUP #####
@@ -1494,6 +1520,8 @@ sub process_request
}
$sthA->finish();
if (length($VDL_status) < 1) {$VDL_status='PDROP';}
$stmtA = "UPDATE vicidial_list SET status='PDROP' where lead_id='$VD_lead_id';";
$VLPDaffected_rows = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- PDROP vicidial_list update: |$VLPDaffected_rows|$uniqueid|$CIDlead_id|$VDL_status|"; &agi_output;}
@@ -1532,6 +1560,7 @@ sub process_request
{$VDLSQL_term_reason = '';}
}
$SQL_status = "status='DROP',$VDLSQL_term_reason";
if (length($VDL_status) < 1) {$VDL_status='DROP';}
########## FIND AND UPDATE vicidial_list ##########
$stmtA = "UPDATE vicidial_list set status='DROP' where lead_id = '$VD_lead_id';";
@@ -1583,6 +1612,7 @@ sub process_request
{
$VDCLSQL_status = "status='DROP',";
$VDCLSQL_queue_seconds = "queue_seconds='$VD_seconds',";
if (length($VDL_status) < 1) {$VDL_status='DROP';}
}
else
{
@@ -1637,11 +1667,11 @@ sub process_request
}
}
##### BEGIN AUTO ALT PHONE DIAL SECTION #####
### check to see if campaign has alt_dial enabled
### check to see if campaign has alt_dial or call quotas enabled
$VD_auto_alt_dial = 'NONE';
$VD_auto_alt_dial_statuses='';
$stmtA="SELECT auto_alt_dial,auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc FROM vicidial_campaigns where campaign_id='$VD_campaign_id';";
$VD_call_quota_lead_ranking='DISABLED';
$stmtA="SELECT auto_alt_dial,auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,call_quota_lead_ranking FROM vicidial_campaigns where campaign_id='$VD_campaign_id';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@@ -1655,8 +1685,22 @@ sub process_request
$VD_use_internal_dnc = $aryA[2];
$VD_use_campaign_dnc = $aryA[3];
$VD_use_other_campaign_dnc = $aryA[4];
$VD_call_quota_lead_ranking = $aryA[5];
$epc_countCAMPDATA++;
}
##### BEGIN Call Quota Lead Ranking logging #####
if ( ($SScall_quota_lead_ranking > 0) && ($VD_call_quota_lead_ranking !~ /^DISABLED$/i) )
{
$temp_status=$VDL_status;
if ( (length($VDL_status) < 1) || ($VDL_status =~ /^LIVE/i) ) {$temp_status=$VD_status;}
if ($temp_status =~ /^LIVE/i) {$temp_status='PU';}
&call_quota_logging;
}
##### END Call Quota Lead Ranking logging #####
##### BEGIN AUTO ALT PHONE DIAL SECTION #####
$sthA->finish();
# if ($AGILOG) {$agi_string = "AUTO-ALT TEST: |$VD_status|$VDL_status|$VD_auto_alt_dial_statuses|$VD_auto_alt_dial|"; &agi_output;}
if ($VD_auto_alt_dial_statuses =~ / $VD_status | $VDL_status /)
@@ -2012,6 +2056,319 @@ exit;
##### BEGIN Call Quota Lead Ranking logging #####
sub call_quota_logging
{
# Gather settings container for Call Quota Lead Ranking
$CQcontainer_entry='';
$stmtA = "SELECT container_entry FROM vicidial_settings_containers where container_id='$VD_call_quota_lead_ranking';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$CQcontainer_entry = $aryA[0];
$CQcontainer_entry =~ s/\\//gi;
}
$sthA->finish();
# Define variables for Call Quota settings
$session_one='';
$session_two='';
$session_three='';
$session_four='';
$session_five='';
$session_six='';
$settings_session_score=0;
$zero_rank_after_call=0;
if (length($CQcontainer_entry) > 5)
{
@container_lines = split(/\n/,$CQcontainer_entry);
$c=0;
foreach(@container_lines)
{
$container_lines[$c] =~ s/;.*|\r|\t| //gi;
if (length($container_lines[$c]) > 5)
{
# define core settings
if ($container_lines[$c] =~ /^zero_rank_after_call/i)
{
$container_lines[$c] =~ s/zero_rank_after_call=>//gi;
if ( ($container_lines[$c] >= 0) && ($container_lines[$c] <= 1) )
{
$zero_rank_after_call = $container_lines[$c];
}
}
# define sessions
if ($container_lines[$c] =~ /^session_one/i)
{
$session_one_valid=0; $session_one_start=''; $session_one_end='';
$session_one = $container_lines[$c];
$session_one =~ s/session_one=>//gi;
if ( (length($session_one) > 0) && (length($session_one) <= 9) && ($session_one =~ /,/) )
{
@session_oneARY = split(/,/,$session_one);
$session_one_start = $session_oneARY[0];
$session_one_end = $session_oneARY[1];
if ( (length($session_one_start) >= 4) && (length($session_one_end) >= 4) && ($session_one_start < $session_one_end) && ($session_one_end <= 2400) )
{
$settings_session_score++;
$session_one_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_two/i)
{
$session_two_valid=0; $session_two_start=''; $session_two_end='';
$session_two = $container_lines[$c];
$session_two =~ s/session_two=>//gi;
if ( (length($session_two) > 0) && (length($session_two) <= 9) && ($session_two =~ /,/) )
{
@session_twoARY = split(/,/,$session_two);
$session_two_start = $session_twoARY[0];
$session_two_end = $session_twoARY[1];
if ( (length($session_two_start) >= 4) && (length($session_two_end) >= 4) && ($session_one_valid > 0) && ($session_one_end <= $session_two_start) && ($session_two_start < $session_two_end) && ($session_two_end <= 2400) )
{
$settings_session_score++;
$session_two_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_three/i)
{
$session_three_valid=0; $session_three_start=''; $session_three_end='';
$session_three = $container_lines[$c];
$session_three =~ s/session_three=>//gi;
if ( (length($session_three) > 0) && (length($session_three) <= 9) && ($session_three =~ /,/) )
{
@session_threeARY = split(/,/,$session_three);
$session_three_start = $session_threeARY[0];
$session_three_end = $session_threeARY[1];
if ( (length($session_three_start) >= 4) && (length($session_three_end) >= 4) && ($session_two_valid > 0) && ($session_two_end <= $session_three_start) && ($session_three_start < $session_three_end) && ($session_three_end <= 2400) )
{
$settings_session_score++;
$session_three_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_four/i)
{
$session_four_valid=0; $session_four_start=''; $session_four_end='';
$session_four = $container_lines[$c];
$session_four =~ s/session_four=>//gi;
if ( (length($session_four) > 0) && (length($session_four) <= 9) && ($session_four =~ /,/) )
{
@session_fourARY = split(/,/,$session_four);
$session_four_start = $session_fourARY[0];
$session_four_end = $session_fourARY[1];
if ( (length($session_four_start) >= 4) && (length($session_four_end) >= 4) && ($session_three_valid > 0) && ($session_three_end <= $session_four_start) && ($session_four_start < $session_four_end) && ($session_four_end <= 2400) )
{
$settings_session_score++;
$session_four_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_five/i)
{
$session_five_valid=0; $session_five_start=''; $session_five_end='';
$session_five = $container_lines[$c];
$session_five =~ s/session_five=>//gi;
if ( (length($session_five) > 0) && (length($session_five) <= 9) && ($session_five =~ /,/) )
{
@session_fiveARY = split(/,/,$session_five);
$session_five_start = $session_fiveARY[0];
$session_five_end = $session_fiveARY[1];
if ( (length($session_five_start) >= 4) && (length($session_five_end) >= 4) && ($session_four_valid > 0) && ($session_four_end <= $session_five_start) && ($session_five_start < $session_five_end) && ($session_five_end <= 2400) )
{
$settings_session_score++;
$session_five_valid++;
}
}
}
if ($container_lines[$c] =~ /^session_six/i)
{
$session_six_valid=0; $session_six_start=''; $session_six_end='';
$session_six = $container_lines[$c];
$session_six =~ s/session_six=>//gi;
if ( (length($session_six) > 0) && (length($session_six) <= 9) && ($session_six =~ /,/) )
{
@session_sixARY = split(/,/,$session_six);
$session_six_start = $session_sixARY[0];
$session_six_end = $session_sixARY[1];
if ( (length($session_six_start) >= 4) && (length($session_six_end) >= 4) && ($session_five_valid > 0) && ($session_five_end <= $session_six_start) && ($session_six_start < $session_six_end) && ($session_six_end <= 2400) )
{
$settings_session_score++;
$session_six_valid++;
}
}
}
}
else
{if ($DBX > 0) {print " blank line: $c|$container_lines[$c]|\n";}}
$c++;
}
if ($settings_session_score >= 1)
{
$stmtA = "SELECT list_id,called_count,rank FROM vicidial_list where lead_id='$VD_lead_id';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$VLlist_id = $aryA[0];
$VLcalled_count = $aryA[1];
$VLrank = $aryA[2];
$tempVLrank = $VLrank;
if ( ($zero_rank_after_call > 0) && ($VLrank > 0) ) {$tempVLrank=0;}
}
$sthA->finish();
$secX = time();
$CQtarget = ($secX - 14400); # look back 4 hours
($CQsec,$CQmin,$CQhour,$CQmday,$CQmon,$CQyear,$CQwday,$CQyday,$CQisdst) = localtime($CQtarget);
$CQyear = ($CQyear + 1900);
$CQmon++;
if ($CQmon < 10) {$CQmon = "0$CQmon";}
if ($CQmday < 10) {$CQmday = "0$CQmday";}
if ($CQhour < 10) {$CQhour = "0$CQhour";}
if ($CQmin < 10) {$CQmin = "0$CQmin";}
if ($CQsec < 10) {$CQsec = "0$CQsec";}
$CQSQLdate = "$CQyear-$CQmon-$CQmday $CQhour:$CQmin:$CQsec";
$VDL_call_datetime='';
$stmtA = "SELECT call_date from vicidial_dial_log where lead_id='$VD_lead_id' and call_date > \"$CQSQLdate\" and caller_code LIKE \"%$VD_lead_id\" order by call_date desc limit 1;";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$VDLcall_datetime = $aryA[0];
@VDLcall_datetimeARY = split(/ /,$VDLcall_datetime);
@VDLcall_timeARY = split(/:/,$VDLcall_datetimeARY[1]);
$VDLcall_hourmin = "$VDLcall_timeARY[0]$VDLcall_timeARY[1]";
if ( ($session_one_start <= $VDLcall_hourmin) and ($session_one_end > $VDLcall_hourmin) )
{
$call_in_session=1;
$session_newSQL=",session_one_calls='1',session_one_today_calls='1'";
$session_updateSQL=",session_one_calls=(session_one_calls + 1),session_one_today_calls=(session_one_today_calls + 1)";
}
if ( ($session_two_start <= $VDLcall_hourmin) and ($session_two_end > $VDLcall_hourmin) )
{
$call_in_session=2;
$session_newSQL=",session_two_calls='1',session_two_today_calls='1'";
$session_updateSQL=",session_two_calls=(session_two_calls + 1),session_two_today_calls=(session_two_today_calls + 1)";
}
if ( ($session_three_start <= $VDLcall_hourmin) and ($session_three_end > $VDLcall_hourmin) )
{
$call_in_session=3;
$session_newSQL=",session_three_calls='1',session_three_today_calls='1'";
$session_updateSQL=",session_three_calls=(session_three_calls + 1),session_three_today_calls=(session_three_today_calls + 1)";
}
if ( ($session_four_start <= $VDLcall_hourmin) and ($session_four_end > $VDLcall_hourmin) )
{
$call_in_session=4;
$session_newSQL=",session_four_calls='1',session_four_today_calls='1'";
$session_updateSQL=",session_four_calls=(session_four_calls + 1),session_four_today_calls=(session_four_today_calls + 1)";
}
if ( ($session_five_start <= $VDLcall_hourmin) and ($session_five_end > $VDLcall_hourmin) )
{
$call_in_session=5;
$session_newSQL=",session_five_calls='1',session_five_today_calls='1'";
$session_updateSQL=",session_five_calls=(session_five_calls + 1),session_five_today_calls=(session_five_today_calls + 1)";
}
if ( ($session_six_start <= $VDLcall_hourmin) and ($session_six_end > $VDLcall_hourmin) )
{
$call_in_session=6;
$session_newSQL=",session_six_calls='1',session_six_today_calls='1'";
$session_updateSQL=",session_six_calls=(session_six_calls + 1),session_six_today_calls=(session_six_today_calls + 1)";
}
if ($AGILOG) {$agi_string = "CQ-Debug 2: $VDLcall_datetime|$VDLcall_hourmin|$timeclock_end_of_day|$session_one_start|$session_one_end|$call_in_session|"; &agi_output;}
if ($call_in_session > 0)
{
if (length($timeclock_end_of_day) < 1) {$timeclock_end_of_day='0000';}
$timeclock_end_of_day_hour = (substr($timeclock_end_of_day, 0, 2) + 0);
$timeclock_end_of_day_min = (substr($timeclock_end_of_day, 2, 2) + 0);
$today_start_epoch = timelocal('0',$timeclock_end_of_day_min,$timeclock_end_of_day_hour,$mday,($mon-1),$year);
if ($timeclock_end_of_day > $VDLcall_hourmin)
{$today_start_epoch = ($today_start_epoch - 86400);}
$day_two_start_epoch = ($today_start_epoch - (86400 * 1));
$day_three_start_epoch = ($today_start_epoch - (86400 * 2));
$day_four_start_epoch = ($today_start_epoch - (86400 * 3));
$day_five_start_epoch = ($today_start_epoch - (86400 * 4));
$day_six_start_epoch = ($today_start_epoch - (86400 * 5));
$day_seven_start_epoch = ($today_start_epoch - (86400 * 6));
# Gather the details on existing vicidial_lead_call_quota_counts for this lead, if there is one
$stmtA = "SELECT first_call_date,UNIX_TIMESTAMP(first_call_date),last_call_date from vicidial_lead_call_quota_counts where lead_id='$VD_lead_id' and list_id='$VLlist_id';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$VLCQCinfo_ct=$sthA->rows;
if ($VLCQCinfo_ct > 0)
{
@aryA = $sthA->fetchrow_array;
$VLCQCfirst_call_datetime = $aryA[0];
$VLCQCfirst_call_epoch = $aryA[1];
$VLCQClast_call_date = $aryA[2];
if ($VDLcall_datetime ne $VLCQClast_call_date)
{
if ($VLCQCfirst_call_epoch >= $today_start_epoch)
{$day_updateSQL=',day_one_calls=(day_one_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_two_start_epoch) and ($VLCQCfirst_call_epoch < $today_start_epoch) )
{$day_updateSQL=',day_two_calls=(day_two_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_three_start_epoch) and ($VLCQCfirst_call_epoch < $day_two_start_epoch) )
{$day_updateSQL=',day_three_calls=(day_three_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_four_start_epoch) and ($VLCQCfirst_call_epoch < $day_three_start_epoch) )
{$day_updateSQL=',day_four_calls=(day_four_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_five_start_epoch) and ($VLCQCfirst_call_epoch < $day_four_start_epoch) )
{$day_updateSQL=',day_five_calls=(day_five_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_six_start_epoch) and ($VLCQCfirst_call_epoch < $day_five_start_epoch) )
{$day_updateSQL=',day_six_calls=(day_six_calls+1)';}
if ( ($VLCQCfirst_call_epoch >= $day_seven_start_epoch) and ($VLCQCfirst_call_epoch < $day_six_start_epoch) )
{$day_updateSQL=',day_seven_calls=(day_seven_calls+1)';}
# Update in the vicidial_lead_call_quota_counts table for this lead
$stmtA="UPDATE vicidial_lead_call_quota_counts SET last_call_date='$VDLcall_datetime',status='$temp_status',called_count='$VLcalled_count',rank='$tempVLrank',modify_date=NOW() $session_updateSQL $day_updateSQL where lead_id='$VD_lead_id' and list_id='$VLlist_id' and modify_date < NOW();";
}
else
{
# Update in the vicidial_lead_call_quota_counts table for this lead
$stmtA="UPDATE vicidial_lead_call_quota_counts SET status='$temp_status',called_count='$VLcalled_count',rank='$tempVLrank',modify_date=NOW() where lead_id='$VD_lead_id' and list_id='$VLlist_id';";
}
$VLCQCaffected_rows_update = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- VLCQC record updated: |$VLCQCaffected_rows_update| |$stmtA|"; &agi_output;}
}
else
{
# Insert new record into vicidial_lead_call_quota_counts table for this lead
$stmtA="INSERT INTO vicidial_lead_call_quota_counts SET lead_id='$VD_lead_id',list_id='$VLlist_id',first_call_date='$VDLcall_datetime',last_call_date='$VDLcall_datetime',status='$temp_status',called_count='$VLcalled_count',day_one_calls='1',rank='$tempVLrank',modify_date=NOW() $session_newSQL;";
$VLCQCaffected_rows_update = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- VLCQC record inserted: |$VLCQCaffected_rows_update| |$stmtA|"; &agi_output;}
}
if ( ($zero_rank_after_call > 0) && ($VLrank > 0) )
{
# Update this lead to rank=0
$stmtA="UPDATE vicidial_list SET rank='0' where lead_id='$VD_lead_id';";
$VLCQCaffected_rows_zero_rank = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- VLCQC lead rank zero: |$VLCQCaffected_rows_zero_rank| |$stmtA|"; &agi_output;}
}
}
}
$sthA->finish();
}
}
}
sub agi_output
{