1 class PurchaseController < ApplicationController
4 redirect_to :action => :begin
8 @purchase_pages, @purchase = paginate :purchases, :per_page => 100
12 # enter a customer id here
13 render :action => 'begin'
14 session[:total] = 0.00
18 if Customer.find_by_id(params[:customer_id])
19 session[:customer_id] = params[:customer_id]
20 redirect_to :action => :menu
22 flash[:error] = "Customer ID is invalid"
23 redirect_to :action => :begin
28 @customer = Customer.find_by_id(session[:customer_id])
29 @total_price = session[:total]
30 render :action => 'menu'
34 render :action => 'rent_begin'
38 @customer = Customer.find_by_id(session[:customer_id])
39 @rentable = Rentable.find_by_id(params[:rentable_id])
42 flash[:error] = "Customer ID is invalid"
43 redirect_to :action => :begin
48 flash[:error] = "Rentable ID is invalid"
49 redirect_to :action => :rent_begin
53 # Actually record the purchase
54 purchase = RentablePurchase.new
55 purchase.customer_id = session[:customer_id]
56 purchase.date = Time.now.to_date
57 purchase.price = @rentable.calculated_price
58 session[:total] += @rentable.calculated_price
59 purchase.rentable = @rentable
62 flash[:notice] = "Successfully made purchase"
63 redirect_to :action => :menu
67 render :action => 'buy_begin'
71 @customer = Customer.find_by_id(session[:customer_id])
72 @merchandise = Merchandise.find_by_id(params[:merchandise_id])
75 flash[:error] = "Customer ID is invalid"
76 redirect_to :action => :begin
81 flash[:error] = "Merchandise ID is invalid"
82 redirect_to :action => :buy_begin
86 if @merchandise.quantity < 1
87 flash[:error] = "The system thinks we are out of this merchandise item!"
88 redirect_to :action => :buy_begin
92 # Actually record the purchase
93 purchase = MerchandisePurchase.new
94 purchase.customer_id = session[:customer_id]
95 purchase.date = Time.now.to_date
96 purchase.price = @merchandise.price
97 session[:total] += @merchandise.price
98 purchase.merchandise = @merchandise
100 @merchandise.quantity -= 1
102 # Save both the merchandise (we changed the quantity) and the purchase to the log
106 flash[:notice] = "Successfully made purchase"
107 redirect_to :action => :menu