From 93daca12cd904df11a8faadda08e487e9a4de8b7 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Fri, 23 Nov 2007 02:06:36 -0800 Subject: [PATCH] Add RentablePolicy for MaxOverdueVideos and MaxOverdueGames Signed-off-by: Ira W. Snyder --- app/controllers/purchase_controller.rb | 14 +++++++++++++ app/models/customer.rb | 26 +++++++++++++++++++++++++ db/development.sqlite3 | Bin 19456 -> 19456 bytes 3 files changed, 40 insertions(+) diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index a3b61bb..ebb08cd 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -73,6 +73,20 @@ class PurchaseController < ApplicationController return end + @maxoverduevideos = RentablePolicy.find_by_name("MaxOverdueVideos") + if @rentable.class == Video and @customer.overdue_videos >= @maxoverduevideos.value + flash[:error] = "#{@maxoverduevideos.description} LIMIT REACHED" + redirect_to :action => :rent_begin + return + end + + @maxoverduegames = RentablePolicy.find_by_name("MaxOverdueGames") + if @rentable.class == Game and @customer.overdue_games >= @maxoverduegames.value + flash[:error] = "#{@maxoverduegames.description} LIMIT REACHED" + redirect_to :action => :rent_begin + return + end + # Check out the item checkout = Coitem.new checkout.customer = @customer diff --git a/app/models/customer.rb b/app/models/customer.rb index e56eafe..673cffd 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -33,6 +33,32 @@ class Customer < ActiveRecord::Base return game_count end + def overdue_videos + coitems = Coitem.find_all_by_customer_id(id) + overdue_video_count = 0 + + for item in coitems + if item.rentable.class == Video and item.overdue? + overdue_video_count += 1 + end + end + + return overdue_video_count + end + + def overdue_games + coitems = Coitem.find_all_by_customer_id(id) + overdue_game_count = 0 + + for item in coitems + if item.rentable.class == Game and item.overdue? + overdue_game_count += 1 + end + end + + return overdue_game_count + end + protected def validate diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 8470ab98fe0cb2805103a9e796c661c079a64566..72946714465818e87ab8b87eb62d19b6df64b970 100644 GIT binary patch delta 481 zcmZpe!Pqc^ae_4C&W$oJxCPjleHfS@F&|-G#@xZ2#q6`O(So^NhK-GZkx@~Rk=@9^ zz+BhRP}j&9&N7u@h01ck#gJuLpt7u3WtpL}%vfcaz_O-_j7%_TLo*o5$Uue>s+kck zhGg+30Tu%u7N)lh%=?&YnN679Zfv~ERPV~d%An1d>zi2NUzS>wQkv?Xn44P66q1pu zkegVMnOmBxkXM?Ulv<>apQexxQKFCzQln4+6ihBHF3HbLEplgOWzc2JM;H^9nUb1M z$eglFL69mGlQ!2nx3kFcGX7v-zQMc!80ZPi7R&-nFPIK6&0s2E@?cV6{IRj|8Y7dM u&18QYRc3ZIYcS2BW(B6%)GWa?tC|IvW>zzwJl{s0(QNX28}-S8-tPe$PI*xP delta 69 zcmV-L0J{Hxm;r#80gxL3rm-C83$p|?{R6WB5Cbp<0t0;j1HO|GAds<;;{vmNLx%(q b1_KZP1K0zw1Be4)12_W^v4Q*olMqYr25=SV -- 2.25.1