From da871e3e27c31759e0d017c89ccf16a14db1a227 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Mon, 26 Nov 2007 23:33:40 -0800 Subject: [PATCH] Lots of stuff, I got too tired to keep perfect revision history Among the things in here are: 1) Proper bonuses 2) Bonus Policy MVC 3) Bonuses show up on the reciept 4) Menu additions Signed-off-by: Ira W. Snyder --- app/controllers/bonus_policy_controller.rb | 56 +++++++++++ app/controllers/purchase_controller.rb | 50 +++++++++- app/helpers/bonus_policy_helper.rb | 2 + app/models/bonus_policy.rb | 20 ++++ app/models/bonus_purchase.rb | 27 +++++ app/models/customer.rb | 2 + app/models/purchase.rb | 9 +- app/models/video.rb | 2 - app/views/bonus_policy/_form.rhtml | 13 +++ app/views/bonus_policy/edit.rhtml | 9 ++ app/views/bonus_policy/list.rhtml | 29 ++++++ app/views/bonus_policy/new.rhtml | 8 ++ app/views/bonus_policy/show.rhtml | 8 ++ app/views/layouts/admin.rhtml | 2 +- app/views/layouts/bonus_policy.rhtml | 17 ++++ app/views/login/limits.rhtml | 3 +- app/views/login/list_users.rhtml | 3 + app/views/purchase/buy_merch.rhtml | 6 +- app/views/purchase/list.rhtml | 2 +- app/views/purchase/menu.rhtml | 2 +- app/views/purchase/receipt.rhtml | 9 +- app/views/purchase/rent.rhtml | 7 +- db/development.sqlite3 | Bin 30720 -> 37888 bytes db/migrate/033_create_bonus_policies.rb | 13 +++ db/schema.rb | 8 +- test/fixtures/bonus_policies.yml | 5 + .../bonus_policy_controller_test.rb | 92 ++++++++++++++++++ test/unit/bonus_policy_test.rb | 10 ++ 28 files changed, 398 insertions(+), 16 deletions(-) create mode 100644 app/controllers/bonus_policy_controller.rb create mode 100644 app/helpers/bonus_policy_helper.rb create mode 100644 app/models/bonus_policy.rb create mode 100644 app/models/bonus_purchase.rb create mode 100644 app/views/bonus_policy/_form.rhtml create mode 100644 app/views/bonus_policy/edit.rhtml create mode 100644 app/views/bonus_policy/list.rhtml create mode 100644 app/views/bonus_policy/new.rhtml create mode 100644 app/views/bonus_policy/show.rhtml create mode 100644 app/views/layouts/bonus_policy.rhtml create mode 100644 db/migrate/033_create_bonus_policies.rb create mode 100644 test/fixtures/bonus_policies.yml create mode 100644 test/functional/bonus_policy_controller_test.rb create mode 100644 test/unit/bonus_policy_test.rb diff --git a/app/controllers/bonus_policy_controller.rb b/app/controllers/bonus_policy_controller.rb new file mode 100644 index 0000000..a19d601 --- /dev/null +++ b/app/controllers/bonus_policy_controller.rb @@ -0,0 +1,56 @@ +class BonusPolicyController < ApplicationController + layout "admin" + + before_filter :authorize, :except => ['new', 'create', 'edit', 'update', 'destroy'] + before_filter :manager, :only => ['new', 'create', 'edit', 'update', 'destroy'] + + def index + list + render :action => 'list' + end + + # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) + verify :method => :post, :only => [ :destroy, :create, :update ], + :redirect_to => { :action => :list } + + def list + @bonus_policy_pages, @bonus_policies = paginate :bonus_policies, :per_page => 10 + end + + def show + @bonus_policy = BonusPolicy.find(params[:id]) + end + + def new + @bonus_policy = BonusPolicy.new + end + + def create + @bonus_policy = BonusPolicy.new(params[:bonus_policy]) + if @bonus_policy.save + flash[:notice] = 'BonusPolicy was successfully created.' + redirect_to :action => 'list' + else + render :action => 'new' + end + end + + def edit + @bonus_policy = BonusPolicy.find(params[:id]) + end + + def update + @bonus_policy = BonusPolicy.find(params[:id]) + if @bonus_policy.update_attributes(params[:bonus_policy]) + flash[:notice] = 'BonusPolicy was successfully updated.' + redirect_to :action => 'show', :id => @bonus_policy + else + render :action => 'edit' + end + end + + def destroy + BonusPolicy.find(params[:id]).destroy + redirect_to :action => 'list' + end +end diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index a086306..37b7401 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -77,6 +77,7 @@ class PurchaseController < ApplicationController render :action => 'begin' session[:total] = 0.00 session[:items] = [] + session[:bonus] = nil end def receipt @@ -85,10 +86,11 @@ class PurchaseController < ApplicationController @debt = @customer.debt @total = session[:total] + @debt @items = session[:items] + @bonus = session[:bonus] @time = Time.now # Record a Late Fee Payment if we need to - if @debt + if not @debt.zero? purchase = LateFeePurchase.new purchase.customer = @customer purchase.date = Time.now.to_date @@ -105,6 +107,7 @@ class PurchaseController < ApplicationController session[:customer_id] = nil session[:total] = nil session[:items] = nil + session[:bonus] = nil # Show the receipt render :action => 'receipt' @@ -179,6 +182,51 @@ class PurchaseController < ApplicationController return end + # Check for a Bonus + for bonus in BonusPolicy.find_all_by_bonus_type(@rentable.class.to_s) + # Find the earliest the period for this bonus extends + since_date = Time.now.advance(:days => (-1 * bonus.days)).to_date + + # Find the date of the latest bonus in this period + last_bonus_date = BonusPurchase.last_bonus_date(@customer, @rentable.class, since_date) + + # Find the number of rentals of this type in the period since the last bonus + count = 0 + for rental in RentablePurchase.find_all_by_customer_id(@customer, :conditions => ["date > ?", last_bonus_date]) + if rental.rentable.class == @rentable.class + count += 1 + end + end + + # We are eligible for a bonus! + if count >= bonus.number + + # 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! + + # Record the BonusPurchase + purchase = BonusPurchase.new + purchase.customer = @customer + purchase.date = Time.now.to_date + purchase.price = @rentable.calculated_price + purchase.rentable = @rentable + purchase.save! + + # Add to session variables + session[:items].push @rentable + session[:bonus] = @rentable + + flash[:notice] = "Successfully made bonus purchase" + redirect_to :action => :menu + return + end + end + # Check out the item checkout = Coitem.new checkout.customer = @customer diff --git a/app/helpers/bonus_policy_helper.rb b/app/helpers/bonus_policy_helper.rb new file mode 100644 index 0000000..1a1dec6 --- /dev/null +++ b/app/helpers/bonus_policy_helper.rb @@ -0,0 +1,2 @@ +module BonusPolicyHelper +end diff --git a/app/models/bonus_policy.rb b/app/models/bonus_policy.rb new file mode 100644 index 0000000..d51ec6f --- /dev/null +++ b/app/models/bonus_policy.rb @@ -0,0 +1,20 @@ +class BonusPolicy < ActiveRecord::Base + + validates_presence_of :number + validates_presence_of :bonus_type + validates_presence_of :days + + validates_numericality_of :number + validates_numericality_of :days + + def description + return "One #{bonus_type} free after #{number} #{bonus_type} rentals in the last #{days} days" + end + + protected + def validate + errors.add(:days, "must be at least 1") if days.nil? || days < 1 + errors.add(:number, "must be at least 1") if number.nil? || number < 1 + errors.add(:bonus_type, "must be either Video or Game") unless bonus_type == 'Video' or bonus_type == 'Game' + end +end diff --git a/app/models/bonus_purchase.rb b/app/models/bonus_purchase.rb new file mode 100644 index 0000000..36f7d9b --- /dev/null +++ b/app/models/bonus_purchase.rb @@ -0,0 +1,27 @@ +class BonusPurchase < Purchase + belongs_to :rentable + belongs_to :customer + + validates_presence_of :rentable_id + validates_numericality_of :rentable_id + + def self.last_bonus_date(customer,bonus_type,since_date) + bonuses = BonusPurchase.find_all_by_customer_id(customer, :conditions => ["date >= ?", since_date], :order => 'date DESC') + puts "*** BONUSES.length: #{bonuses.length} ***" + for bonus in bonuses + puts "#{bonus.rentable.class.to_s} == #{bonus_type.to_s} => #{bonus.rentable.class.to_s == bonus_type.to_s}" + if bonus.rentable.class.to_s == bonus_type.to_s + return bonus.date + end + end + + # Unable to find a last bonus, no bonuses in period + return since_date + end + + protected + def validate + errors.add(:rentable_id, "is not in the database") if rentable.nil? + end +end + diff --git a/app/models/customer.rb b/app/models/customer.rb index acd6869..b9e6ab9 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -2,6 +2,8 @@ class Customer < ActiveRecord::Base has_many :coitems has_many :merchandise_purchases has_many :rentable_purchases + has_many :bonus_purchases + has_many :late_fee_purchases validates_presence_of :name, :email, :phone, :address validates_numericality_of :debt diff --git a/app/models/purchase.rb b/app/models/purchase.rb index b596aa2..0f01813 100644 --- a/app/models/purchase.rb +++ b/app/models/purchase.rb @@ -7,9 +7,11 @@ class Purchase < ActiveRecord::Base validates_numericality_of :price def title - if type == MerchandisePurchase + if self.class == MerchandisePurchase return merchandise.title - elsif type == RentablePurchase + elsif self.class == RentablePurchase + return rentable.title + elsif self.class == BonusPurchase return rentable.title else return 'Late Fees' @@ -19,7 +21,8 @@ class Purchase < ActiveRecord::Base protected def validate errors.add(:price, "cannot be negative") if price < 0 - errors.add(:price, "cannot be less than $0.01") if price < 0.01 + # Need to leave this out for bonuses + #errors.add(:price, "cannot be less than $0.01") if price < 0.01 errors.add(:customer_id, "does not exist in the database") if customer.nil? end end diff --git a/app/models/video.rb b/app/models/video.rb index fd5d22f..8ca3901 100644 --- a/app/models/video.rb +++ b/app/models/video.rb @@ -15,7 +15,6 @@ class Video < Rentable end def calculated_price - # FIXME: generate this based on day of week, newrelease day_of_week = Time.now.to_date.wday base_fee = VideoPolicy.find_by_day(day_of_week).fee @@ -26,7 +25,6 @@ class Video < Rentable end def due_date - # FIXME: generate this based on the day of week, newrelease # NOTE: a Date.wday will tell you the day of week (0-6, meaning Sunday-Saturday) day_of_week = Time.now.to_date.wday base_period = VideoPolicy.find_by_day(day_of_week).period diff --git a/app/views/bonus_policy/_form.rhtml b/app/views/bonus_policy/_form.rhtml new file mode 100644 index 0000000..1f7fec4 --- /dev/null +++ b/app/views/bonus_policy/_form.rhtml @@ -0,0 +1,13 @@ +<%= error_messages_for 'bonus_policy' %> + + +


+<%= text_field 'bonus_policy', 'number' %>

+ +


+<%= select 'bonus_policy', 'bonus_type', [Game, Video] %>

+ +


+<%= text_field 'bonus_policy', 'days' %>

+ + diff --git a/app/views/bonus_policy/edit.rhtml b/app/views/bonus_policy/edit.rhtml new file mode 100644 index 0000000..e1d1cf8 --- /dev/null +++ b/app/views/bonus_policy/edit.rhtml @@ -0,0 +1,9 @@ +

Editing bonus_policy

+ +<% form_tag :action => 'update', :id => @bonus_policy do %> + <%= render :partial => 'form' %> + <%= submit_tag 'Edit' %> +<% end %> + +<%= link_to 'Show', :action => 'show', :id => @bonus_policy %> | +<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/bonus_policy/list.rhtml b/app/views/bonus_policy/list.rhtml new file mode 100644 index 0000000..6535464 --- /dev/null +++ b/app/views/bonus_policy/list.rhtml @@ -0,0 +1,29 @@ +

Listing bonus_policies

+ + + + + + + + + +<% for bonus_policy in @bonus_policies %> + + + + + + + + + +<% end %> +
NumberBonus TypeDaysDescription
<%=h bonus_policy.number %><%=h bonus_policy.bonus_type %><%=h bonus_policy.days %><%=h bonus_policy.description %><%= link_to 'Show', :action => 'show', :id => bonus_policy %><%= link_to 'Edit', :action => 'edit', :id => bonus_policy %><%= link_to 'Destroy', { :action => 'destroy', :id => bonus_policy }, :confirm => 'Are you sure?', :method => :post %>
+ +<%= link_to 'Previous page', { :page => @bonus_policy_pages.current.previous } if @bonus_policy_pages.current.previous %> +<%= link_to 'Next page', { :page => @bonus_policy_pages.current.next } if @bonus_policy_pages.current.next %> + +
+ +<%= link_to 'New bonus_policy', :action => 'new' %> diff --git a/app/views/bonus_policy/new.rhtml b/app/views/bonus_policy/new.rhtml new file mode 100644 index 0000000..3d2d5b4 --- /dev/null +++ b/app/views/bonus_policy/new.rhtml @@ -0,0 +1,8 @@ +

New bonus_policy

+ +<% form_tag :action => 'create' do %> + <%= render :partial => 'form' %> + <%= submit_tag "Create" %> +<% end %> + +<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/bonus_policy/show.rhtml b/app/views/bonus_policy/show.rhtml new file mode 100644 index 0000000..1d03f7a --- /dev/null +++ b/app/views/bonus_policy/show.rhtml @@ -0,0 +1,8 @@ +<% for column in BonusPolicy.content_columns %> +

+ <%= column.human_name %>: <%=h @bonus_policy.send(column.name) %> +

+<% end %> + +<%= link_to 'Edit', :action => 'edit', :id => @bonus_policy %> | +<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/layouts/admin.rhtml b/app/views/layouts/admin.rhtml index 7a3e403..5ad36b2 100644 --- a/app/views/layouts/admin.rhtml +++ b/app/views/layouts/admin.rhtml @@ -23,7 +23,7 @@

<%= link_to "Customer Maintenence", :controller => 'customer', :action => 'index' %>

<%= link_to "Financial Information", :controller => 'purchase', :action => 'index' %>

<%= link_to "System Maintenence", :controller => 'login', :action => 'maintenence' %>

-

<%= link_to "Rental Policies and Limits", :controller => 'login', :action => 'limits' %>

+

<%= link_to "Rental and Bonus Policies", :controller => 'login', :action => 'limits' %>


<%= link_to "Logout", :controller => 'login', :action => 'logout' %>

diff --git a/app/views/layouts/bonus_policy.rhtml b/app/views/layouts/bonus_policy.rhtml new file mode 100644 index 0000000..11cf200 --- /dev/null +++ b/app/views/layouts/bonus_policy.rhtml @@ -0,0 +1,17 @@ + + + + + + BonusPolicy: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/login/limits.rhtml b/app/views/login/limits.rhtml index 5d86493..5c3a6b1 100644 --- a/app/views/login/limits.rhtml +++ b/app/views/login/limits.rhtml @@ -1,9 +1,10 @@ -

Rental Limits and Pricing

+

Rental and Bonus Policies

Actions

diff --git a/app/views/login/list_users.rhtml b/app/views/login/list_users.rhtml index d730d82..0f00737 100644 --- a/app/views/login/list_users.rhtml +++ b/app/views/login/list_users.rhtml @@ -1,4 +1,7 @@

Employees

+ +

Press the "[X]" next to the username to delete that user

+ diff --git a/app/views/purchase/receipt.rhtml b/app/views/purchase/receipt.rhtml index d5054cf..87e1c15 100644 --- a/app/views/purchase/receipt.rhtml +++ b/app/views/purchase/receipt.rhtml @@ -16,7 +16,7 @@ - <% if @debt %> + <% if not @debt.zero? %> Overdue Item Fees @@ -34,6 +34,13 @@ <%=h number_to_currency(item.price) %> <% end %> +<% end %> +<% if @bonus %> + + Bonus: <%=h @bonus.title %> + + - <%= number_to_currency(@bonus.calculated_price) %> + <% end %> Total diff --git a/app/views/purchase/rent.rhtml b/app/views/purchase/rent.rhtml index 07b2973..831325c 100644 --- a/app/views/purchase/rent.rhtml +++ b/app/views/purchase/rent.rhtml @@ -4,7 +4,10 @@ the box below.

<%= start_form_tag :action => 'rent'%> -<%= text_field 'rentable_id', nil %> - <%= submit_tag 'Ok' %> + <%= text_field 'rentable_id', nil %> + <%= submit_tag 'Ok' %> <%= end_form_tag %> +
+

<%=link_to 'Check Out', :action => 'receipt' %>

+ diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 2f9ea91798b5a2c9653cc4fdd697ff4613f5779b..2dcc744dbc3ff314c57140a464b2b8d1e57e1b27 100644 GIT binary patch delta 6095 zcmai2dvF`)asM6w@ghi?q)3tCA|X-)WhIeh`3T$*7Xo+4 z-9Zwlr0}J2on$&wDc7d0`$sZy(%6&MW0|SbX53C^nx^eclV)l=ZtG53d*s$hJ$ZQA zjwjBf-2+Gge6+e5f`{GT?)TXJc7Gq9_$hwkS#qbj*8U;1_qlqn_Z5fF=LKmcQV~+= zAJ7c-lkbqn=GQ$QL~g9#vl2 zV5?F*X`XO1KQAkCF0Ev>skoNSC}~CJ`-DU`G%y$(8XgIr8XfCL=5wBb{3W{sbzbQV z;CUr2s4OO>Gnyg~4Gayis1o0lkm?wy-4fo5Ga!(HB?J zBO{^U@bGXjG!PoV=WPzuG1ncy=LJ05*lhVSFg;uQWiewO?Wc@N%F2KaIYQvCrom9_a5s6%2)f10%(^fnfh2Xg^=j)*Pm78LL3%O7$^3YED(P;?rh- zbxXcwyaHJ!Hv6F_Lq)Bt`cUmaQR_T>xWOG;|Dm>h1#P3x88}28GOt!mwoVis*c^u- z2F;hMCi9a!2|Q8zo>SO zAEF&>Ik}@9J4_45tS~Kn_>w|9w#D!t+ZTU3Slj5k)&ch4%jD_ZJBdo)Dtu!T@X^$@ z{Xtzt%`m(+!bzroMW3Nh(s?-1t>owAKKV=XEP0Z|NEiMEejUGnKZ8GlPv9E#pXfF8 z++AbBJm1-uKR#9cA5XUZ@x^yfG}_TcOqQgyqzefaNk}@JX;wO*Y$cV|l9E7tL#+*V z)Po_6Oxa@RBtd60%BC=I_I;QNJk3Y!D6p%x&YoV<9j&(`->z;(87wpFtFxm;;)vnNJet{l_vBl3*uDLCGokuQ ztDX{i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UyG!Gv{Cx?p!*YGBOgNx=??mC)_Q!*#mah~8$xP+hKNBAbb zj4$B4g)_+JGtV^J$O@q+>EBp{TV$nF{MuZ}-hn 32) do +ActiveRecord::Schema.define(:version => 33) do + + create_table "bonus_policies", :force => true do |t| + t.column "number", :integer + t.column "bonus_type", :string + t.column "days", :integer + end create_table "coitems", :force => true do |t| t.column "customer_id", :integer diff --git a/test/fixtures/bonus_policies.yml b/test/fixtures/bonus_policies.yml new file mode 100644 index 0000000..b49c4eb --- /dev/null +++ b/test/fixtures/bonus_policies.yml @@ -0,0 +1,5 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +one: + id: 1 +two: + id: 2 diff --git a/test/functional/bonus_policy_controller_test.rb b/test/functional/bonus_policy_controller_test.rb new file mode 100644 index 0000000..97676f6 --- /dev/null +++ b/test/functional/bonus_policy_controller_test.rb @@ -0,0 +1,92 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'bonus_policy_controller' + +# Re-raise errors caught by the controller. +class BonusPolicyController; def rescue_action(e) raise e end; end + +class BonusPolicyControllerTest < Test::Unit::TestCase + fixtures :bonus_policies + + def setup + @controller = BonusPolicyController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @first_id = bonus_policies(:first).id + end + + def test_index + get :index + assert_response :success + assert_template 'list' + end + + def test_list + get :list + + assert_response :success + assert_template 'list' + + assert_not_nil assigns(:bonus_policies) + end + + def test_show + get :show, :id => @first_id + + assert_response :success + assert_template 'show' + + assert_not_nil assigns(:bonus_policy) + assert assigns(:bonus_policy).valid? + end + + def test_new + get :new + + assert_response :success + assert_template 'new' + + assert_not_nil assigns(:bonus_policy) + end + + def test_create + num_bonus_policies = BonusPolicy.count + + post :create, :bonus_policy => {} + + assert_response :redirect + assert_redirected_to :action => 'list' + + assert_equal num_bonus_policies + 1, BonusPolicy.count + end + + def test_edit + get :edit, :id => @first_id + + assert_response :success + assert_template 'edit' + + assert_not_nil assigns(:bonus_policy) + assert assigns(:bonus_policy).valid? + end + + def test_update + post :update, :id => @first_id + assert_response :redirect + assert_redirected_to :action => 'show', :id => @first_id + end + + def test_destroy + assert_nothing_raised { + BonusPolicy.find(@first_id) + } + + post :destroy, :id => @first_id + assert_response :redirect + assert_redirected_to :action => 'list' + + assert_raise(ActiveRecord::RecordNotFound) { + BonusPolicy.find(@first_id) + } + end +end diff --git a/test/unit/bonus_policy_test.rb b/test/unit/bonus_policy_test.rb new file mode 100644 index 0000000..a68f3ef --- /dev/null +++ b/test/unit/bonus_policy_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BonusPolicyTest < Test::Unit::TestCase + fixtures :bonus_policies + + # Replace this with your real tests. + def test_truth + assert true + end +end -- 2.25.1