X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=app%2Fcontrollers%2Fpurchase_controller.rb;h=6be425419fd37bb57c6578f5e91556b522e210db;hb=31c3621ad8a43715ecc02655d58b20099308fe50;hp=0f7e22fa1d79267903c7f463ad1e9df57b977e39;hpb=b12881a928516bca02b2bd8ce1bbe9288840c76f;p=cs356-p2-videostore.git diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index 0f7e22f..6be4254 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -2,8 +2,8 @@ class PurchaseController < ApplicationController layout "admin" # Make sure that a user logs in before doing any action here - before_filter :authorize, :except => [:filter, :filterbycust, :filterbydate, :filterbytype, :list, :index] - before_filter :manager, :only => [:filter, :filterbycust, :filterbydate, :filterbytype, :list, :index] + before_filter :authorize, :except => [:filter, :filterbycust, :filterbydate, :filterbytype, :list, :index, :income] + before_filter :manager, :only => [:filter, :filterbycust, :filterbydate, :filterbytype, :list, :index, :income] def index render :action => 'index' @@ -49,6 +49,26 @@ class PurchaseController < ApplicationController render :action => 'list' end + def income + if request.post? + # Find all purchases between :begin_date, and :end_date and sum up the total income + # from RentablePurchases, MerchandisePurchases. Print both sums, and the total sum. + @begin_date = Date.new params[:begin_date]['(1i)'].to_i, params[:begin_date]['(2i)'].to_i, params[:begin_date]['(3i)'].to_i + @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]) + + @merch_count = merchandises.length + @rent_count = rentables.length + @merch_sum = merchandises.sum(&:price) + @rent_sum = rentables.sum(&:price) + @total = @merch_sum + @rent_sum + render :action => 'income_results' + else + render :action => 'income' + end + end + def begin # enter a customer id here render :action => 'begin' @@ -148,7 +168,7 @@ class PurchaseController < ApplicationController # Actually record the purchase purchase = RentablePurchase.new - purchase.customer_id = session[:customer_id] + purchase.customer_id = session[:customer_id][0] purchase.date = Time.now.to_date purchase.price = @rentable.calculated_price purchase.rentable = @rentable