@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
<p><b>Number of Merchandise Items Sold: </b><%= @merch_count %></p>
<p><b>Income from Merchandise: </b><%= number_to_currency(@merch_sum) %></p>
+<br/>
<p><b>Number of Rentals: </b><%= @rent_count %></p>
<p><b>Income from Rentals: </b><%= number_to_currency(@rent_sum) %></p>
+<br/>
+<p><b>Number of Late Fee Payments: </b><%= @late_count %></p>
+<p><b>Income from Late Fee Payments: </b><%= number_to_currency(@late_sum) %></p>
+<br/>
<p><b>Total Income: </b><%= number_to_currency(@total) %></p>
<td><%=link_to purchase.date, :action => 'filterbydate', :id => purchase.date %></td>
<td><%=link_to purchase.class, :action => 'filterbytype', :id => purchase.type %></td>
<td><%=h purchase.title %></td>
- <td><%=h purchase.price %></td>
+ <td><%=h number_to_currency(purchase.price) %></td>
<td><%=link_to purchase.customer.name, :action => 'filterbycust', :id => purchase.customer_id %></td>
</tr>
<% end %>