From f9658404967d5fd39d22980d953dd49c72795da6 Mon Sep 17 00:00:00 2001
From: Jed Barber <jjbarber@y7mail.com>
Date: Mon, 13 Feb 2017 06:24:27 +1100
Subject: Fixed paper transfer and exhausted paper tracking

---
 src/election.adb | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/election.adb b/src/election.adb
index 059f9a9..7a77c4c 100644
--- a/src/election.adb
+++ b/src/election.adb
@@ -336,6 +336,8 @@ package body Election is
         Working_Transfer := Transfers.First_Element;
         Transfers.Delete_First;
 
+        Exhausted.Paper_Change := Entries.Reference (Working_Transfer.Position).Total_Papers;
+
         if Entries.Reference (Working_Transfer.Position).Status = Excluded then
             Entries.Reference (Working_Transfer.Position).Vote_Change :=
                   - Entries.Reference (Working_Transfer.Position).Total_Votes;
@@ -350,6 +352,7 @@ package body Election is
         end if;
         Entries.Reference (Working_Transfer.Position).Paper_Change :=
               - Entries.Reference (Working_Transfer.Position).Total_Papers;
+        Entries.Reference (Working_Transfer.Position).Total_Papers := 0;
 
         for R in Still_Running.Iterate loop
             Working_Position := Still_Running.Reference (R).Index;
@@ -370,8 +373,10 @@ package body Election is
                             Entries.Reference (Working_Position).Vote_Change + Votes_In;
                     Entries.Reference (Working_Position).Paper_Change :=
                             Entries.Reference (Working_Position).Paper_Change + Papers_In;
+                    Exhausted.Paper_Change := Exhausted.Paper_Change - Papers_In;
                 elsif Papers_In > 0 then
                     Fractional.Paper_Change := Fractional.Paper_Change + Papers_In;
+                    Exhausted.Paper_Change := Exhausted.Paper_Change - Papers_In;
                 end if;
             end loop;
 
@@ -383,13 +388,6 @@ package body Election is
                     Entries.Reference (Working_Position).Paper_Change;
         end loop;
 
-        for From_Bundle of Pref_Data.Reference (Working_Transfer.From) loop
-            Papers_In := Given_Bundles.Count_Papers (From_Bundle);
-            if Papers_In > 0 then
-                Exhausted.Paper_Change := Exhausted.Paper_Change + Papers_In;
-            end if;
-        end loop;
-
         Pref_Data.Replace (Working_Transfer.From, Bundle_Containers.Bundle_Vectors.Empty_Vector);
 
         Fractional.Total_Papers := Fractional.Total_Papers + Fractional.Paper_Change;
-- 
cgit