class CoitemController < ApplicationController
+ layout "admin"
# Make sure that the user has logged in before they can take any
# action on checked out items
before_filter :authorize
def index
- list
- render :action => 'list'
+ render :action => 'index'
end
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
@coitem = Coitem.find(params[:id])
end
- def new
- @coitem = Coitem.new
- end
-
- def create
- @coitem = Coitem.new(params[:coitem])
- if @coitem.save
- flash[:notice] = 'Coitem was successfully created.'
- redirect_to :action => 'list'
- else
- render :action => 'new'
- end
- end
+ # We should never create new checked out items via the web interface, so remove
+ # the new and create methods.
def edit
@coitem = Coitem.find(params[:id])
end
end
- def destroy
- Coitem.find(params[:id]).destroy
- redirect_to :action => 'list'
- end
+ # We should never delete a checked out item directly via the web interface, so
+ # remove the destroy method.
# 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'
+ @coitem_pages, @coitems = paginate :coitems, :per_page => 50, :conditions => ["due_date < ?", Time.now.to_date], :order => "customer_id"
+ render :action => 'overdue'
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
+ if request.post?
+ rentable_id = params[:rentable_id]
+ @rentable = Rentable.find_by_id(rentable_id)
+
+ if @rentable.nil?
+ flash[:notice] = "Unable to find this rentable"
+ redirect_to :action => :return
+ return
+ end
+
+ @coitem = Coitem.find_by_rentable_id(rentable_id)
+ if @coitem.nil?
+ flash[:notice] = "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, :method => :get
+ else
+ render :action => 'return'
end
-
- # Delete the row
- @coitem.destroy
-
- flash[:notice] = "Successfully returned item"
- redirect_to :action => :return
end
end
--- /dev/null
+<h1>Checked Out Items Maintenence</h1>
+
+<h3>Actions</h3>
+<ul>
+ <li><%= link_to 'List All Checked Out Items', :action => 'list' %></li>
+ <li><%= link_to 'List All Overdue Items', :action => 'overdue' %></li>
+ <li><%= link_to 'Return a Checked Out Item', :action => 'return' %></li>
+</ul>
-<h1>Listing coitems</h1>
+<h1>Listing Checked Out Items</h1>
-<table>
+<table border="1">
<tr>
- <th>Customer</th>
- <th>Rentable</th>
- <th>Overdue</th>
- <% for column in Coitem.content_columns %>
- <th><%= column.human_name %></th>
- <% end %>
+ <th>Customer</th>
+ <th>Rentable</th>
+ <th>Overdue</th>
+ <th>Date Checked Out</th>
+ <th>Due Date</th>
</tr>
<% for coitem in @coitems %>
<tr>
- <td><%=h coitem.customer.name %></td>
- <td><%=h coitem.rentable.title %></td>
- <td><%=h coitem.overdue? %></td>
- <% for column in Coitem.content_columns %>
- <td><%=h coitem.send(column.name) %></td>
- <% end %>
- <td><%= link_to 'Show', :action => 'show', :id => coitem %></td>
- <td><%= link_to 'Edit', :action => 'edit', :id => coitem %></td>
- <td><%= link_to 'Destroy', { :action => 'destroy', :id => coitem }, :confirm => 'Are you sure?', :method => :post %></td>
+ <td><%=h coitem.customer.name %></td>
+ <td><%=h coitem.rentable.title %></td>
+ <td><%=h tf_to_yesno(coitem.overdue?) %></td>
+ <td><%=h coitem.out_date %></td>
+ <td><%=h coitem.due_date %></td>
+ <td><%= link_to 'View', :action => 'show', :id => coitem %></td>
</tr>
<% end %>
</table>
<%= link_to 'Previous page', { :page => @coitem_pages.current.previous } if @coitem_pages.current.previous %>
<%= link_to 'Next page', { :page => @coitem_pages.current.next } if @coitem_pages.current.next %>
-<br />
-
-<%= link_to 'New coitem', :action => 'new' %>
+++ /dev/null
-<h1>New coitem</h1>
-
-<% form_tag :action => 'create' do %>
- <%= render :partial => 'form' %>
- <%= submit_tag "Create" %>
-<% end %>
-
-<%= link_to 'Back', :action => 'list' %>
--- /dev/null
+<h1>Listing Overdue Items</h1>
+
+<table border="1">
+ <tr>
+ <th>Customer</th>
+ <th>Customer Phone #</th>
+ <th>Customer Email</th>
+ <th>Type</th>
+ <th>Title</th>
+ <th>Overdue</th>
+ <th>Date Checked Out</th>
+ <th>Due Date</th>
+ </tr>
+
+<% for coitem in @coitems %>
+ <tr>
+ <td><%=link_to coitem.customer.name, :controller => 'customer', :action => 'show', :id => coitem.customer.id %></td>
+ <td><%=h coitem.customer.phone %></td>
+ <td><%=h coitem.customer.email %></td>
+ <td><%=h coitem.rentable.type %></td>
+ <td><%=h coitem.rentable.title %></td>
+ <td><%=h tf_to_yesno(coitem.overdue?) %></td>
+ <td><%=h coitem.out_date %></td>
+ <td><%=h coitem.due_date %></td>
+ <td><%= link_to 'View', :action => 'show', :id => coitem %></td>
+ </tr>
+<% end %>
+</table>
+
+<%= link_to 'Previous page', { :page => @coitem_pages.current.previous } if @coitem_pages.current.previous %>
+<%= link_to 'Next page', { :page => @coitem_pages.current.next } if @coitem_pages.current.next %>
+
-<h1>Return a Rentable Item</h1>
+<h1>Return a Checked Out Item</h1>
-<%= start_form_tag :action => 'return_validate'%>
+<%= start_form_tag :action => 'return'%>
<%= text_field 'rentable_id', nil %>
<%= submit_tag 'Ok' %></form>
<%= end_form_tag %>
<br/>
<p><%= link_to "Video Maintenence", :controller => 'video', :action => 'index' %></p>
<p><%= link_to "Game Maintenence", :controller => 'game', :action => 'index' %></p>
- <p><%= link_to "Checked Out Items", :controller => 'coitem', :action => 'list' %></p>
+ <p><%= link_to "Checked Out Items", :controller => 'coitem', :action => 'index' %></p>
<p><%= link_to "Customer Maintenence", :controller => 'customer', :action => 'list' %></p>
<br/>
<p><%= link_to "Logout", :controller => 'login', :action => 'logout' %></p>