Add overdue handling to checked out items
authorIra W. Snyder <devel@irasnyder.com>
Thu, 22 Nov 2007 08:28:05 +0000 (00:28 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Thu, 22 Nov 2007 08:28:05 +0000 (00:28 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/coitem_controller.rb
app/models/coitem.rb
app/views/coitem/list.rhtml
db/development.sqlite3

index 224806d..73049f3 100644 (file)
@@ -48,4 +48,10 @@ class CoitemController < ApplicationController
     Coitem.find(params[:id]).destroy
     redirect_to :action => 'list'
   end
+
+  # Awesome, paginating overdue list, ordered by customer
+  def overdue
+    @coitem_pages, @coitems = paginate :coitems, :per_page => 50, :conditions => "due_date < DATE('NOW', 'LOCALTIME')", :order => "customer_id"
+    render :action => 'list'
+  end
 end
index 8513465..513625a 100644 (file)
@@ -17,6 +17,10 @@ class Coitem < ActiveRecord::Base
   validates_associated :customer
   validates_associated :rentable
 
+  def overdue?
+    return due_date < Time.now.to_date
+  end
+
   protected
   def validate
     errors.add(:customer_id, "does not exist is the database") if customer.nil?
index e506366..f6514cb 100644 (file)
@@ -4,6 +4,7 @@
   <tr>
   <th>Customer</th>
   <th>Rentable</th>
+  <th>Overdue</th>
   <% for column in Coitem.content_columns %>
     <th><%= column.human_name %></th>
   <% end %>
@@ -13,6 +14,7 @@
   <tr>
   <td><%=h coitem.customer.name %></td>
   <td><%=h coitem.rentable.title %></td>
+  <td><%=h coitem.overdue? %></td>
   <% for column in Coitem.content_columns %>
     <td><%=h coitem.send(column.name) %></td>
   <% end %>
index 0e9ea78..7673ae7 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ