+ @purchase_pages, @purchases = paginate :purchases, :per_page => 100
+ end
+
+ def filter
+ if request.post?
+ type = params[:type]
+ id = params[:id]
+
+ case type
+ when :customer, "customer"
+ redirect_to :action => 'filterbycust', :id => id
+ when :date, "date"
+ date = Date.new id['(1i)'].to_i, id['(2i)'].to_i, id['(3i)'].to_i
+ redirect_to :action => 'filterbydate', :id => date.to_s
+ end
+ else
+ @type = params[:type]
+ if @type.nil?
+ @type = "all"
+ end
+ render :action => 'filter'
+ end
+ end
+
+ def filterbycust
+ @purchase_pages, @purchases = paginate :purchases, :per_page => 100, :conditions => ["customer_id = ?", params[:id]]
+ render :action => 'list'
+ end
+
+ def filterbydate
+ @purchase_pages, @purchases = paginate :purchases, :per_page => 100, :conditions => ["date = ?", params[:id]]
+ render :action => 'list'
+ end
+
+ def filterbytype
+ @purchase_pages, @purchases = paginate :purchases, :per_page => 100, :conditions => ["type = ?", params[:id]]
+ 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])
+ 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)
+ @late_sum = late_fees.sum(&:price)
+ @total = @merch_sum + @rent_sum + @late_sum
+ render :action => 'income_results'
+ else
+ render :action => 'income'
+ end