From 74561aac0964ca7bd9283ad0a9b017e02431f845 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Fri, 23 Nov 2007 00:01:14 -0800 Subject: [PATCH] Add list of just-purchased items (this transaction) to the purchase view Signed-off-by: Ira W. Snyder --- app/controllers/purchase_controller.rb | 12 ++++++++-- app/models/merchandise.rb | 2 +- app/views/bitem/list.rhtml | 2 +- app/views/merchandise/_form.rhtml | 4 ++-- app/views/purchase/menu.rhtml | 12 ++++++++++ db/development.sqlite3 | Bin 17408 -> 17408 bytes db/migrate/020_rebuild_merchandises_table.rb | 24 +++++++++++++++++++ db/schema.rb | 4 ++-- 8 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 db/migrate/020_rebuild_merchandises_table.rb diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index 4445c07..704e38b 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -12,6 +12,7 @@ class PurchaseController < ApplicationController # enter a customer id here render :action => 'begin' session[:total] = 0.00 + session[:items] = [] end def customer_ok @@ -27,6 +28,7 @@ class PurchaseController < ApplicationController def menu @customer = Customer.find_by_id(session[:customer_id]) @total_price = session[:total] + @items = session[:items] render :action => 'menu' end @@ -69,10 +71,13 @@ class PurchaseController < ApplicationController purchase.customer_id = session[:customer_id] purchase.date = Time.now.to_date purchase.price = @rentable.calculated_price - session[:total] += @rentable.calculated_price purchase.rentable = @rentable purchase.save! + # Add te session variables + session[:total] += @rentable.calculated_price + session[:items].push @rentable + flash[:notice] = "Successfully made purchase" redirect_to :action => :menu end @@ -108,11 +113,14 @@ class PurchaseController < ApplicationController purchase.customer_id = session[:customer_id] purchase.date = Time.now.to_date purchase.price = @merchandise.price - session[:total] += @merchandise.price purchase.merchandise = @merchandise purchase.quantity = 1 @merchandise.quantity -= 1 + # Add to session variables + session[:total] += @merchandise.price + session[:items].push @merchandise + # Save both the merchandise (we changed the quantity) and the purchase to the log @merchandise.save! purchase.save! diff --git a/app/models/merchandise.rb b/app/models/merchandise.rb index 16fd1e8..efb7c7e 100644 --- a/app/models/merchandise.rb +++ b/app/models/merchandise.rb @@ -1,7 +1,7 @@ class Merchandise < ActiveRecord::Base has_many :merchandise_purchases - validates_presence_of :name + validates_presence_of :title validates_numericality_of :quantity validates_numericality_of :price diff --git a/app/views/bitem/list.rhtml b/app/views/bitem/list.rhtml index 6b5bb14..81a7d7c 100644 --- a/app/views/bitem/list.rhtml +++ b/app/views/bitem/list.rhtml @@ -12,7 +12,7 @@ <% for bitem in @bitems %> <%=h bitem.customer.name %> - <%=h bitem.merchandise.name %> + <%=h bitem.merchandise.title %> <% for column in Bitem.content_columns %> <%=h bitem.send(column.name) %> <% end %> diff --git a/app/views/merchandise/_form.rhtml b/app/views/merchandise/_form.rhtml index d7f7735..35db026 100644 --- a/app/views/merchandise/_form.rhtml +++ b/app/views/merchandise/_form.rhtml @@ -1,8 +1,8 @@ <%= error_messages_for 'merchandise' %> -


-<%= text_field 'merchandise', 'name' %>

+


+<%= text_field 'merchandise', 'title' %>


<%= text_field 'merchandise', 'quantity' %>

diff --git a/app/views/purchase/menu.rhtml b/app/views/purchase/menu.rhtml index ce8a646..6f5abd1 100644 --- a/app/views/purchase/menu.rhtml +++ b/app/views/purchase/menu.rhtml @@ -1,11 +1,23 @@

Purchase Menu

+

Customer Information

+

Items Purchased

+<% if @items.empty? %> + None +<% else %> + +<% end %> +