From 56db4e1da35c068e247eadbd32edd0a09eb61127 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Thu, 22 Nov 2007 22:56:32 -0800 Subject: [PATCH] Make system unable to check out already checked out items Signed-off-by: Ira W. Snyder --- app/controllers/purchase_controller.rb | 14 ++++++++++++++ app/models/game.rb | 6 ++++++ app/models/video.rb | 5 +++++ app/views/layouts/purchase.rhtml | 2 +- db/development.sqlite3 | Bin 17408 -> 17408 bytes 5 files changed, 26 insertions(+), 1 deletion(-) 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 3f10e53d0d1a2208886bfa8264c73991b11818cc..f482dbeddf0f35aee6a15925c1f72df0c6032889 100644 GIT binary patch delta 201 zcmZqZU~K4MoFL6B#Q*^UK#FOj#vN`hX69uK%#WClFfZFI$TEXDN`{$@fss*Bk&)TR zz`$JB&`{UN2+lH*VS>ss!Nrhe8KJU_*kl(8$nfz3?PX@}U|_z%yn(p`Xk!&KlN$5n mMjI6tZe}$m2!lzD5yW8PW?W>zGckajl@X{*a5In17j^*SF(c~$ delta 219 zcmZqZU~K4MoFL6B#DD}gYTV)GVPWoIV1C5BjJbpP$i~JB=6V?xHU>sUMMWkyBLf3- zT|+}%BSSdLM1~nE%K{fe$QsJ9LSz}4V6ui5FqV;_3?o#Q5g~?P@iHG`U}rkLnO)$g vG#@L_nT*W8L5>w<{=Hey;sZ02faoFvo=Fxg9HI=t49sVl=WXV(`N9qWmh32l -- 2.25.1