From 2b6a0952011552367bc40f8cce3f5ff23b1f473f Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Mon, 26 Nov 2007 17:08:22 -0800 Subject: [PATCH 1/1] Add Income tracking to the Purchase System Signed-off-by: Ira W. Snyder --- app/controllers/purchase_controller.rb | 16 ++++++++++++++-- app/models/late_fee_purchase.rb | 4 ++++ app/models/purchase.rb | 4 +++- app/views/purchase/income_results.rhtml | 5 +++++ app/views/purchase/list.rhtml | 2 +- db/development.sqlite3 | Bin 30720 -> 30720 bytes 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 app/models/late_fee_purchase.rb 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 diff --git a/app/models/late_fee_purchase.rb b/app/models/late_fee_purchase.rb new file mode 100644 index 0000000..e427846 --- /dev/null +++ b/app/models/late_fee_purchase.rb @@ -0,0 +1,4 @@ +class LateFeePurchase < Purchase + belongs_to :customer + +end diff --git a/app/models/purchase.rb b/app/models/purchase.rb index 26cf518..b596aa2 100644 --- a/app/models/purchase.rb +++ b/app/models/purchase.rb @@ -9,8 +9,10 @@ class Purchase < ActiveRecord::Base def title if type == MerchandisePurchase return merchandise.title - else + elsif type == RentablePurchase return rentable.title + else + return 'Late Fees' end end diff --git a/app/views/purchase/income_results.rhtml b/app/views/purchase/income_results.rhtml index eafd83f..6c10b8c 100644 --- a/app/views/purchase/income_results.rhtml +++ b/app/views/purchase/income_results.rhtml @@ -2,6 +2,11 @@

Number of Merchandise Items Sold: <%= @merch_count %>

Income from Merchandise: <%= number_to_currency(@merch_sum) %>

+

Number of Rentals: <%= @rent_count %>

Income from Rentals: <%= number_to_currency(@rent_sum) %>

+
+

Number of Late Fee Payments: <%= @late_count %>

+

Income from Late Fee Payments: <%= number_to_currency(@late_sum) %>

+

Total Income: <%= number_to_currency(@total) %>

diff --git a/app/views/purchase/list.rhtml b/app/views/purchase/list.rhtml index 6887d13..504bc61 100644 --- a/app/views/purchase/list.rhtml +++ b/app/views/purchase/list.rhtml @@ -14,7 +14,7 @@ <%=link_to purchase.date, :action => 'filterbydate', :id => purchase.date %> <%=link_to purchase.class, :action => 'filterbytype', :id => purchase.type %> <%=h purchase.title %> - <%=h purchase.price %> + <%=h number_to_currency(purchase.price) %> <%=link_to purchase.customer.name, :action => 'filterbycust', :id => purchase.customer_id %> <% end %> diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 74a0b4545b532870429c8e474fd017248eae2f69..694afec03596fa3cefdee87a443d4e7ce92da64b 100644 GIT binary patch delta 273 zcmZqpz}WDCae_2&Gy?>P11YAB8Xx&Y8I24K%ykV7bqy?GEJKscdi>Won8g?pCbLUu zux?@KVMv(RsKcb?G8Xx&47xRm4*5|*A$zo9{?yFmGl_ zVPx6Ns&Ix~k6A>7iIqW}k