@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'
@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
# 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