From: Ira W. Snyder Date: Tue, 27 Nov 2007 01:08:22 +0000 (-0800) Subject: Add Income tracking to the Purchase System X-Git-Tag: turned-in~12 X-Git-Url: https://www.irasnyder.com/gitweb/?p=cs356-p2-videostore.git;a=commitdiff_plain;h=2b6a0952011552367bc40f8cce3f5ff23b1f473f;hp=506205df80b0318a1d58f59cbf68d5be4329489a Add Income tracking to the Purchase System Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index 4492862..a8bfa8f 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -57,12 +57,15 @@ class PurchaseController < ApplicationController @end_date = Date.new params[:end_date]['(1i)'].to_i, params[:end_date]['(2i)'].to_i, params[:end_date]['(3i)'].to_i merchandises = MerchandisePurchase.find(:all, :conditions => ['date >= ? AND date <= ?', @begin_date, @end_date]) rentables = RentablePurchase.find(:all, :conditions => ['date >= ? AND date <= ?', @begin_date, @end_date]) + late_fees = LateFeePurchase.find(:all, :conditions => ['date >= ? AND date <= ?', @begin_date, @end_date]) @merch_count = merchandises.length @rent_count = rentables.length + @late_count = late_fees.length @merch_sum = merchandises.sum(&:price) @rent_sum = rentables.sum(&:price) - @total = @merch_sum + @rent_sum + @late_sum = late_fees.sum(&:price) + @total = @merch_sum + @rent_sum + @late_sum render :action => 'income_results' else render :action => 'income' @@ -84,6 +87,15 @@ class PurchaseController < ApplicationController @items = session[:items] @time = Time.now + # Record a Late Fee Payment if we need to + if @debt + purchase = LateFeePurchase.new + purchase.customer = @customer + purchase.date = Time.now.to_date + purchase.price = @debt + purchase.save + end + # Set the customer's debt to $0.00, she paid us @customer = Customer.find_by_id(session[:customer_id]) @customer.debt = 0.00 @@ -177,7 +189,7 @@ class PurchaseController < ApplicationController # Actually record the purchase purchase = RentablePurchase.new - purchase.customer_id = session[:customer_id][0] + purchase.customer = @customer purchase.date = Time.now.to_date purchase.price = @rentable.calculated_price purchase.rentable = @rentable diff --git a/app/models/late_fee_purchase.rb b/app/models/late_fee_purchase.rb new file mode 100644 index 0000000..e427846 --- /dev/null +++ b/app/models/late_fee_purchase.rb @@ -0,0 +1,4 @@ +class LateFeePurchase < Purchase + belongs_to :customer + +end diff --git a/app/models/purchase.rb b/app/models/purchase.rb index 26cf518..b596aa2 100644 --- a/app/models/purchase.rb +++ b/app/models/purchase.rb @@ -9,8 +9,10 @@ class Purchase < ActiveRecord::Base def title if type == MerchandisePurchase return merchandise.title - else + elsif type == RentablePurchase return rentable.title + else + return 'Late Fees' end end diff --git a/app/views/purchase/income_results.rhtml b/app/views/purchase/income_results.rhtml index eafd83f..6c10b8c 100644 --- a/app/views/purchase/income_results.rhtml +++ b/app/views/purchase/income_results.rhtml @@ -2,6 +2,11 @@

Number of Merchandise Items Sold: <%= @merch_count %>

Income from Merchandise: <%= number_to_currency(@merch_sum) %>

+

Number of Rentals: <%= @rent_count %>

Income from Rentals: <%= number_to_currency(@rent_sum) %>

+
+

Number of Late Fee Payments: <%= @late_count %>

+

Income from Late Fee Payments: <%= number_to_currency(@late_sum) %>

+

Total Income: <%= number_to_currency(@total) %>

diff --git a/app/views/purchase/list.rhtml b/app/views/purchase/list.rhtml index 6887d13..504bc61 100644 --- a/app/views/purchase/list.rhtml +++ b/app/views/purchase/list.rhtml @@ -14,7 +14,7 @@ <%=link_to purchase.date, :action => 'filterbydate', :id => purchase.date %> <%=link_to purchase.class, :action => 'filterbytype', :id => purchase.type %> <%=h purchase.title %> - <%=h purchase.price %> + <%=h number_to_currency(purchase.price) %> <%=link_to purchase.customer.name, :action => 'filterbycust', :id => purchase.customer_id %> <% end %> diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 74a0b45..694afec 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ