Make system unable to check out already checked out items
authorIra W. Snyder <devel@irasnyder.com>
Fri, 23 Nov 2007 06:56:32 +0000 (22:56 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Fri, 23 Nov 2007 06:56:32 +0000 (22:56 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/purchase_controller.rb
app/models/game.rb
app/models/video.rb
app/views/layouts/purchase.rhtml
db/development.sqlite3

index 1516498..4445c07 100644 (file)
@@ -50,6 +50,20 @@ class PurchaseController < ApplicationController
       return
     end
 
+    if @rentable.checkedout?
+      flash[:error] = "This #{@rentable.type} is already checked out!"
+      redirect_to :action => :rent_begin
+      return
+    end
+
+    # Check out the item
+    checkout = Coitem.new
+    checkout.customer = @customer
+    checkout.rentable = @rentable
+    checkout.out_date = Time.now.to_date
+    checkout.due_date = @rentable.due_date
+    checkout.save!
+
     # Actually record the purchase
     purchase = RentablePurchase.new
     purchase.customer_id = session[:customer_id]
index efdb260..872b45a 100644 (file)
@@ -6,4 +6,10 @@ class Game < Rentable
     # FIXME: generate this based on day of week, newrelase
     return 11
   end
+
+  def due_date
+    # FIXME: generate this based on the day of week, newrelease
+    return Time.now.advance(:days => 2).to_date
+  end
+
 end
index fdf90c3..6f75a26 100644 (file)
@@ -11,6 +11,11 @@ class Video < Rentable
     return 11
   end
 
+  def due_date
+    # FIXME: generate this based on the day of week, newrelease
+    return Time.now.advance(:days => 2).to_date
+  end
+
   protected
   def validate
     errors.add(:video_genre, "does not exist in the database") if video_genre.nil?
index 26387b8..0499b84 100644 (file)
@@ -4,7 +4,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
   <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
-  <title>Bitem: <%= controller.action_name %></title>
+  <title>Purchase: <%= controller.action_name %></title>
   <%= stylesheet_link_tag 'scaffold' %>
 </head>
 <body>
index 3f10e53..f482dbe 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ