Fix the late fee calculations
[cs356-p2-videostore.git] / app / models / coitem.rb
index 513625a..5d0a212 100644 (file)
@@ -21,6 +21,15 @@ class Coitem < ActiveRecord::Base
     return due_date < Time.now.to_date
   end
 
+  def late_fee
+    days_late = Time.now.to_date - (due_date)
+    if rentable.class == Video
+      return VideoPolicy.find_by_day(7).fee * days_late.to_i
+    else
+      return GamePolicy.find_by_day(7).fee * days_late.to_i
+    end
+  end
+
   protected
   def validate
     errors.add(:customer_id, "does not exist is the database") if customer.nil?