From: Ira W. Snyder Date: Fri, 23 Nov 2007 06:56:32 +0000 (-0800) Subject: Make system unable to check out already checked out items X-Git-Tag: turned-in~56 X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=56db4e1da35c068e247eadbd32edd0a09eb61127;p=cs356-p2-videostore.git Make system unable to check out already checked out items Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index 1516498..4445c07 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -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] diff --git a/app/models/game.rb b/app/models/game.rb index efdb260..872b45a 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -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 diff --git a/app/models/video.rb b/app/models/video.rb index fdf90c3..6f75a26 100644 --- a/app/models/video.rb +++ b/app/models/video.rb @@ -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? diff --git a/app/views/layouts/purchase.rhtml b/app/views/layouts/purchase.rhtml index 26387b8..0499b84 100644 --- a/app/views/layouts/purchase.rhtml +++ b/app/views/layouts/purchase.rhtml @@ -4,7 +4,7 @@ - Bitem: <%= controller.action_name %> + Purchase: <%= controller.action_name %> <%= stylesheet_link_tag 'scaffold' %> diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 3f10e53..f482dbe 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ