@coitem_pages, @coitems = paginate :coitems, :per_page => 50, :conditions => "due_date < DATE('NOW', 'LOCALTIME')", :order => "customer_id"
render :action => 'list'
end
+
+ def return
+ render :action => 'return'
+ end
+
+ def return_validate
+ rentable_id = params[:rentable_id]
+ @rentable = Rentable.find_by_id(rentable_id)
+
+ if @rentable.nil?
+ flash[:error] = "Unable to find this rentable"
+ redirect_to :action => :return
+ return
+ end
+
+ @coitem = Coitem.find_by_rentable_id(rentable_id)
+ if @coitem.nil?
+ flash[:error] = "This item is not checked out!"
+ redirect_to :action => :return
+ return
+ end
+
+ # Check if the item is overdue
+ if @coitem.overdue?
+ @coitem.customer.debt += @coitem.late_fee
+ @coitem.customer.save
+ end
+
+ # Delete the row
+ @coitem.destroy
+
+ flash[:notice] = "Successfully returned item"
+ redirect_to :action => :return
+ end
end
return due_date < Time.now.to_date
end
+ def late_fee
+ # FIXME: this should be calculated better
+ days_late = Time.now.to_date - (due_date)
+ return 3 * days_late.to_i
+ end
+
protected
def validate
errors.add(:customer_id, "does not exist is the database") if customer.nil?
--- /dev/null
+<h1>Return a Rentable Item</h1>
+
+<%= start_form_tag :action => 'return_validate'%>
+<%= text_field 'rentable_id', nil %>
+ <%= submit_tag 'Ok' %></form>
+<%= end_form_tag %>
+
+<br />