X-Git-Url: https://www.irasnyder.com/gitweb/?p=cs356-p2-videostore.git;a=blobdiff_plain;f=app%2Fcontrollers%2Fpurchase_controller.rb;h=a8bfa8f773673b27332329def0abdcb4a3fc214c;hp=449286203e3e1625a731ac21be428a70d6acbbb1;hb=2b6a0952011552367bc40f8cce3f5ff23b1f473f;hpb=506205df80b0318a1d58f59cbf68d5be4329489a 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