# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- AST_VDauto_dialORIGINAL.pl
+++ AST_VDauto_dial.pl
@@ -354,6 +354,7 @@
 		$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
 		$sthArows=$sthA->rows;
 		$rec_count=0;
+
 		while ($sthArows > $rec_count)
 			{
 			@aryA = $sthA->fetchrow_array;
@@ -509,6 +510,7 @@
 						if ($available_only_ratio_tally =~ /Y/) 
 							{
 							$DBIPcount[$user_CIPct] = $DBIPACTIVEcount[$user_CIPct];
+						#	$DBIPcount[$user_CIPct] = $DBIPACTIVEcount[$user_CIPct]+$DBIPINCALLcount[$user_CIPct];
 							$active_only=1;
 							}
 					$DBIPautoaltdial[$user_CIPct] =	"$aryA[10]";
@@ -518,8 +520,10 @@
 				$rec_count++;
 				}
 			$sthA->finish();
-
+## Added by Poundteam to troubleshoot
 			$DBIPgoalcalls[$user_CIPct] = ($DBIPadlevel[$user_CIPct] * $DBIPcount[$user_CIPct]);
+			$event_string="$DBIPcampaign[$user_CIPct] $DBIPaddress[$user_CIPct]: Goal Calls: $DBIPgoalcalls[$user_CIPct] = $DBIPcount[$user_CIPct]     pad_level: $DBIPadlevel[$user_CIPct] * agents: $DBIPcount[$user_CIPct]";
+			&event_logger;
 			if ($active_only > 0) 
 				{
 				$tally_xfer_line_counter=0;
@@ -537,7 +541,10 @@
 					}
 				$sthA->finish();
 
-				$DBIPgoalcalls[$user_CIPct] = ($DBIPgoalcalls[$user_CIPct] + $tally_xfer_line_counter);
+                                $event_string="$DBIPcampaign[$user_CIPct] $DBIPaddress[$user_CIPct]: ACTIVE ONLY Goal Calls: $DBIPgoalcalls[$user_CIPct] + Tally Xfer Line Counter: $tally_xfer_line_counter";
+                                &event_logger;
+#Removed to simplify ready agent calling (removing inbounds from calculations)
+#				$DBIPgoalcalls[$user_CIPct] = ($DBIPgoalcalls[$user_CIPct] + $tally_xfer_line_counter);
 				}
 			if ($DBIPactive[$user_CIPct] =~ /N/) {$DBIPgoalcalls[$user_CIPct] = 0;}
 			$DBIPgoalcalls[$user_CIPct] = sprintf("%.0f", $DBIPgoalcalls[$user_CIPct]);
@@ -558,11 +565,14 @@
 					$DBIPclosercamp[$user_CIPct] = "'$DBIPclosercamp[$user_CIPct]'";
 				   }
 				  else {$DBIPclosercamp[$user_CIPct]="''";}
-				
-				$campaign_query = "( (call_type='IN' and campaign_id IN($DBIPclosercamp[$user_CIPct])) or (campaign_id='$DBIPcampaign[$user_CIPct]' and call_type IN('OUT','OUTBALANCE')) )";
+#Change existing calls calcultion to READY only, exclude in and xfer (because READY already does that)
+#Will likely mess up "ADAPT" dial types
+				$campaign_query = "( (campaign_id='$DBIPcampaign[$user_CIPct]' and call_type IN('OUT','OUTBALANCE')) )";
+#ORIGINAL				$campaign_query = "( (call_type='IN' and campaign_id IN($DBIPclosercamp[$user_CIPct])) or (campaign_id='$DBIPcampaign[$user_CIPct]' and call_type IN('OUT','OUTBALANCE')) )";
 				}
 			else {$campaign_query = "(campaign_id='$DBIPcampaign[$user_CIPct]' and call_type IN('OUT','OUTBALANCE'))";}
-			$stmtA = "SELECT count(*) FROM vicidial_auto_calls where $campaign_query and server_ip='$DBIPaddress[$user_CIPct]' and status IN('SENT','RINGING','LIVE','XFER','CLOSER');";
+			$stmtA = "SELECT count(*) FROM vicidial_auto_calls where $campaign_query and server_ip='$DBIPaddress[$user_CIPct]' and status IN('SENT','RINGING','LIVE','CLOSER');";
+#ORIGINAL		$stmtA = "SELECT count(*) FROM vicidial_auto_calls where $campaign_query and server_ip='$DBIPaddress[$user_CIPct]' and status IN('SENT','RINGING','LIVE','XFER','CLOSER');";
 			$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
 			$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
 			$sthArows=$sthA->rows;
@@ -571,6 +581,8 @@
 				{
 				@aryA = $sthA->fetchrow_array;
 					$DBIPexistcalls[$user_CIPct] = "$aryA[0]";
+#                                        $event_string="$DBIPcampaign[$user_CIPct] $DBIPaddress[$user_CIPct]: Existing Calls: $DBIPexistcalls[$user_CIPct] from Query: \n$stmtA";
+#                                        &event_logger;
 				$rec_count++;
 				}
 			$sthA->finish();
@@ -622,7 +634,7 @@
 
 			if ($DBIPmakecalls[$user_CIPct] > 0) 
 				{$active_line_counter = ($DBIPmakecalls[$user_CIPct] + $active_line_counter);}
-			$event_string="$DBIPcampaign[$user_CIPct] $DBIPaddress[$user_CIPct]: Calls to place: $DBIPmakecalls[$user_CIPct] ($DBIPgoalcalls[$user_CIPct] - $DBIPexistcalls[$user_CIPct]) $active_line_counter $MVT_msg";
+			$event_string="$DBIPcampaign[$user_CIPct] $DBIPaddress[$user_CIPct]: Calls to place: $DBIPmakecalls[$user_CIPct] (Goal Calls: $DBIPgoalcalls[$user_CIPct] - Existing Calls: $DBIPexistcalls[$user_CIPct]) $active_line_counter $MVT_msg";
 			&event_logger;
 
 			### Calculate campaign-wide agent waiting and calls waiting differential
