X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=app%2Fcontrollers%2Fcoitem_controller.rb;h=a524f059b90b1e5c547ef2181ffdc7529671a254;hb=9b264f25255cc0e7cca3169d99905f590c8be578;hp=224806d589e971d6579ecf50fb3e7072adb37717;hpb=4930bd87730032786d9cc7f3d5c1d7cd1f5091bc;p=cs356-p2-videostore.git diff --git a/app/controllers/coitem_controller.rb b/app/controllers/coitem_controller.rb index 224806d..a524f05 100644 --- a/app/controllers/coitem_controller.rb +++ b/app/controllers/coitem_controller.rb @@ -48,4 +48,44 @@ class CoitemController < ApplicationController Coitem.find(params[:id]).destroy redirect_to :action => 'list' end + + # Awesome, paginating overdue list, ordered by customer + def overdue + @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