<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>views/report_thank_yous.erb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,7 @@
 #!/usr/bin/env ruby
 require 'rubygems'
 require 'sinatra'
+set(:appfile=&gt;'giftsmas.rb', :views=&gt;'views')
 require 'cgi'
 enable :sessions
 
@@ -30,6 +31,9 @@ helpers do
 end
 
 error do
+  e = request.env['sinatra.error']
+  puts e.message
+  e.backtrace.each{|x| puts x}
   render(:erb, &quot;&lt;h3&gt;Oops, an error occurred.&lt;/h3&gt;&quot;)
 end
 
@@ -88,6 +92,11 @@ get '/reports/by_receiver' do
   render :erb, :report_receiver
 end
 
+get '/reports/thank_yous' do
+  @receivers = @event.thank_you_notes
+  render :erb, :report_thank_yous
+end
+
 get '/login' do
   render :erb, :login
 end</diff>
      <filename>giftsmas.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@ class Event &lt; Sequel::Model
   @scaffold_session_value = :user_id
   @scaffold_associations = [:gifts, :receivers, :senders]
   many_to_one :user
-  one_to_many :gifts, :order=&gt;:inserted_at, :eager=&gt;[:receivers, :senders], :order=&gt;:inserted_at
+  one_to_many :gifts, :eager=&gt;[:receivers, :senders], :order=&gt;:inserted_at
   many_to_many :senders, :class=&gt;:Person, :join_table=&gt;:event_senders, :right_key=&gt;:person_id, :order=&gt;:name
   many_to_many :receivers, :class=&gt;:Person, :join_table=&gt;:event_receivers, :right_key=&gt;:person_id, :order=&gt;:name
 
@@ -47,4 +47,19 @@ class Event &lt; Sequel::Model
     end
     [senders.sort, receivers.sort]
   end
+
+  def thank_you_notes
+    receivers = Hash.new{|h,k| h[k] = Hash.new{|h2,k| h2[k] = []}}
+    person_ids = model.db[:gifts].join(:gift_receivers, :gift_id=&gt;:id).filter(:event_id=&gt;id).select(:person_id).distinct(:person_id).order(:person_id).map(:person_id)
+    gifts.each do |g|
+      g.receivers.each do |r|
+        g.senders.reject{|s| person_ids.include?(s.id)}.each{|s| receivers[r.name][s.name] &lt;&lt; g.name}
+      end
+    end
+    receivers.values.each do |h| 
+      h.values.each{|h2| h2.sort}
+      h.sort
+    end
+    receivers.sort.map{|k, v| [k, v.sort.map{|k2, v2| [k2, v2.sort]}]}
+  end
 end</diff>
      <filename>models/event.rb</filename>
    </modified>
    <modified>
      <diff>@@ -139,5 +139,5 @@ ul.scaffold_associated_records_list li form { display: inline; }
         position: static;
         width: 99%;
     }
-    table.persongifts { page-break-after: always; }
+    .persongifts { page-break-after: always; }
 }</diff>
      <filename>public/application.css</filename>
    </modified>
    <modified>
      <diff>@@ -191,8 +191,8 @@ context &quot;Giftsmas&quot; do
     (n/:h4).mapih.should == ['Event: Christmas', 'Gift Reports', 'Other']
     as = n/:a
     eid = Event.first.id
-    as.maphr.should == [&quot;/&quot;, &quot;/manage/edit_event_receivers/#{eid}&quot;, &quot;/manage/edit_event_senders/#{eid}&quot;, &quot;/choose_event&quot;, &quot;/reports/chronological&quot;, &quot;/reports/by_receiver&quot;, &quot;/reports/by_sender&quot;, &quot;/reports/summary&quot;, &quot;/reports/crosstab&quot;, &quot;/manage/manage_event&quot;, &quot;/manage/manage_gift&quot;, &quot;/manage/manage_person&quot;]
-    as.mapit.should == [&quot;Giftsmas&quot;, &quot;Associate Receivers&quot;, &quot;Associate Senders&quot;, &quot;Change Event&quot;, &quot;In Chronological Order&quot;, &quot;By Receiver&quot;, &quot;By Sender&quot;, &quot;Summary&quot;, &quot;Summary Crosstab&quot;, &quot;Manage Events&quot;, &quot;Manage Gifts&quot;, &quot;Manage People&quot;]
+    as.maphr.should == [&quot;/&quot;, &quot;/manage/edit_event_receivers/#{eid}&quot;, &quot;/manage/edit_event_senders/#{eid}&quot;, &quot;/choose_event&quot;, &quot;/reports/chronological&quot;, &quot;/reports/by_receiver&quot;, &quot;/reports/by_sender&quot;, &quot;/reports/summary&quot;, &quot;/reports/crosstab&quot;, &quot;/reports/thank_yous&quot;, &quot;/manage/manage_event&quot;, &quot;/manage/manage_gift&quot;, &quot;/manage/manage_person&quot;]
+    as.mapit.should == [&quot;Giftsmas&quot;, &quot;Associate Receivers&quot;, &quot;Associate Senders&quot;, &quot;Change Event&quot;, &quot;In Chronological Order&quot;, &quot;By Receiver&quot;, &quot;By Sender&quot;, &quot;Summary&quot;, &quot;Summary Crosstab&quot;, &quot;Thank You Notes&quot;, &quot;Manage Events&quot;, &quot;Manage Gifts&quot;, &quot;Manage People&quot;]
   end
 
   specify &quot;/add_gift should add gifts correctly&quot; do
@@ -342,6 +342,32 @@ context &quot;Giftsmas&quot; do
     table = tables.first
     (table/:th).mapit.should == ['Sender\Receiver', 'P2', 'P4']
     (table/&quot;tbody tr&quot;).map{|x| (x/:td).mapit}.should == [%w'P1 2 1', %w'P3 1 2']
+
+    c = content('/reports/thank_yous', :title=&gt;'Thank You Notes', :session=&gt;session)
+    uls1 = c/&quot;&gt; ul&quot;
+    uls1.length.should == 1
+    lis1 = uls1/&quot;&gt; li&quot;
+    lis1.length.should == 2
+    lis1.mapatt(&quot;class&quot;).should == ['persongifts']*2
+    li1 = lis1.first
+    li1.it.should =~ /\AP2/
+    lis2 = li1/&quot;&gt; ul &gt; li&quot;
+    li2 = lis2.first 
+    li2.it.should =~ /\AP1/
+    (li2/&quot;&gt; ul &gt; li&quot;).mapit.should == %w'G1 G2'
+    li2 = lis2.last
+    li2.it.should =~ /\AP3/
+    (li2/&quot;&gt; ul &gt; li&quot;).mapit.should == %w'G4'
+    lis1.last.it.should =~ /\AP4/
+    li1 = lis1.last
+    li1.it.should =~ /\AP4/
+    lis2 = li1/&quot;&gt; ul &gt; li&quot;
+    li2 = lis2.first 
+    li2.it.should =~ /\AP1/
+    (li2/&quot;&gt; ul &gt; li&quot;).mapit.should == %w'G3'
+    li2 = lis2.last
+    li2.it.should =~ /\AP3/
+    (li2/&quot;&gt; ul &gt; li&quot;).mapit.should == %w'G3 G4'
   end
 
   specify &quot;users can't see other other users events, people, or gifts&quot; do</diff>
      <filename>spec/integration.rb</filename>
    </modified>
    <modified>
      <diff>@@ -62,6 +62,16 @@ describe Event do
     g3 = Gift.add(@event, 'G3', [@receiver.id], [@sender.id], [], [])
     @event.reload.gifts_summary.should == [[['R', 1], ['S', 2]], [['R', 2], ['S', 1]]]
   end
+
+  specify &quot;#thank_you_notes should be a sorted hash of receivers with values being a sorted hash of senders with an associated array of gifts, excluding gifts where the sender was a receiver in the event&quot; do
+    @event.thank_you_notes.should == []
+    g = Gift.add(@event, 'G', [@sender.id], [@receiver.id], [], [])
+    @event.reload.thank_you_notes.should == [['R', [['S', ['G']]]]]
+    g2 = Gift.add(@event, 'G2', [@sender.id], [@receiver.id], [], [])
+    @event.reload.thank_you_notes.should == [['R', [['S', ['G', 'G2']]]]]
+    g3 = Gift.add(@event, 'G3', [@receiver.id], [@sender.id], [], [])
+    @event.reload.thank_you_notes.should == []
+  end
 end
 
 describe Gift do</diff>
      <filename>spec/unit.rb</filename>
    </modified>
    <modified>
      <diff>@@ -33,6 +33,7 @@
 &lt;a href=&quot;/reports/by_sender&quot;&gt;By Sender&lt;/a&gt;
 &lt;a href=&quot;/reports/summary&quot;&gt;Summary&lt;/a&gt;
 &lt;a href=&quot;/reports/crosstab&quot;&gt;Summary Crosstab&lt;/a&gt;
+&lt;a href=&quot;/reports/thank_yous&quot;&gt;Thank You Notes&lt;/a&gt;
 
 &lt;h4&gt;Other&lt;/h4&gt;
 &lt;a href=&quot;/manage/manage_event&quot;&gt;Manage Events&lt;/a&gt;</diff>
      <filename>views/layout.erb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bc8a0131ce8d6719735cc56841a06f8e65b7dc34</id>
    </parent>
  </parents>
  <author>
    <name>Jeremy Evans</name>
    <email>jeremy@lafirewall.jeremyevans.local</email>
  </author>
  <url>http://github.com/jeremyevans/giftsmas/commit/1522fdeaf2f5354bc6bbef127e77a8a2f2533a1c</url>
  <id>1522fdeaf2f5354bc6bbef127e77a8a2f2533a1c</id>
  <committed-date>2009-01-09T12:15:28-08:00</committed-date>
  <authored-date>2009-01-09T12:15:28-08:00</authored-date>
  <message>Add Thank You Notes report and a few minor changes

The Thank You Notes page will print on a different page for each
person in the event showing them the gifts they received by person,
excluding the gifts given by people who actually attended the event
(i.e. were a receiver in the event), since it is assumed that you
don't need to send thank you notes to those people.

Make sure error backtraces are logged to the console before
displaying a message to the user.

Remove :order argument used twice in User.gifts association

Set :appfile and :views in giftsmas.rb so test suite runs correctly.</message>
  <tree>ced365a47ebfb3fa6e269c3823511fbdd3f79995</tree>
  <committer>
    <name>Jeremy Evans</name>
    <email>jeremy@lafirewall.jeremyevans.local</email>
  </committer>
</commit>
