Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
Wrote check in and checkout email notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
maltyeva committed Jun 11, 2012
1 parent 362d10e commit 5e983b3
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 11 deletions.
26 changes: 24 additions & 2 deletions app/controllers/reservations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def update
reservation.save
end
flash[:notice] = error_msgs.empty? ? "Successfully checked out equipment!" : error_msgs #Allows admins to see all errors, but still checkout successfully
redirect_to :action => 'index' and return
redirect_to :action => 'show' and return

elsif params[:commit] == "Check in equipment"

Expand Down Expand Up @@ -145,7 +145,7 @@ def update
reservation.save
end
flash[:notice] = "Successfully checked in equipment!"
redirect_to :action => 'index' and return
redirect_to :action => 'show' and return
end

elsif params[:commit] == "Submit" #For editing reservations
Expand Down Expand Up @@ -183,5 +183,27 @@ def check_in_single
@reservation = Reservation.find(params[:id])
end

def checkout_email
@reservation = Reservation.find(params[:id])
if UserMailer.checkout_receipt(@reservation).deliver
redirect_to :back
flash[:notice] = "Delivered receipt email."
else
redirect_to @reservation
flash[:error] = "Unable to deliver receipt email. Please contact administrator for more support. "
end
end

def checkin_email
@reservation = Reservation.find(params[:id])
if UserMailer.checkin_receipt(@reservation).deliver
redirect_to :back
flash[:notice] = "Delivered receipt email."
else
redirect_to @reservation
flash[:error] = "Unable to deliver receipt email. Please contact administrator for more support. "
end
end

end

10 changes: 10 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,15 @@ def reservation_confirmation(reservation)
@reservation = reservation
mail(:to => reservation.reserver.email, :subject => "[Reservation] Confirmation of your equipment reservation")
end

def checkout_receipt(reservation)
@reservation = reservation
mail(:to => reservation.reserver.email, :subject => "[Reservation] Your equipment checkout receipt")
end

def checkin_receipt(reservation)
@reservation = reservation
mail(:to => reservation.reserver.email, :subject => "[Reservation] Your equipment return receipt")
end

end
1 change: 1 addition & 0 deletions app/views/equipment_models/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<%= link_to "View all "+@equipment_model.name.singularize+" objects", equipment_model_equipment_objects_path(@equipment_model) %>
</p> -->


<p>
<% if current_user.is_admin_in_adminmode? %>
<%= link_to "Edit "+@equipment_model.category.name.singularize, edit_equipment_model_path(@equipment_model) %> |
Expand Down
12 changes: 3 additions & 9 deletions app/views/reservations/check_out_single.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<%= stylesheet_link_tag('application', :media => :screen) %>
<%= stylesheet_link_tag('print', :media => :print) %>
<% title "Single Reservation Checkout" %>
<%= form_tag( {:controller => 'reservations', :action => "update"}, :method => "put" ) do %>

Expand Down Expand Up @@ -41,12 +38,9 @@
<% end %>
</ul>
</p>

<%= submit_tag "Check out equipment" %>

<p>
<%=link_to_function("Print this Page", "javascript:print()")%>
</p>

<%= submit_tag "Check out equipment" %>
<% end %>

14 changes: 14 additions & 0 deletions app/views/reservations/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<%= stylesheet_link_tag('application', :media => :screen) %>
<%= stylesheet_link_tag('print', :media => :print) %>
<% if current_user.can_checkout? || current_user == @reservation.reserver %>
<% title "Reservation ##{@reservation.id}" + (@reservation.status == "reserved" ? "" : " (#{@reservation.status})") %>

Expand Down Expand Up @@ -36,6 +39,17 @@
by <%= @reservation.checkin_handler.nil? ? "unknown" : @reservation.checkin_handler.name %>
</p>
<% end %>

<p>
<div id="left_stuff"> <%=link_to_function("Print this page", "javascript:print()")%></div>
<% if @reservation.status == "checked out"%>
<div id="right_stuff"><%=link_to "Email checkout receipt", :method => "get", :action => "checkout_email", :id => @reservation %></div>
<% elsif @reservation.status == "returned" %>
<div id="right_stuff"><%=link_to "Email return receipt", :action => "checkin_email", :id => @reservation, :method => "get" %></div>
<% end %>
</p> <br /> <br />


<p>
<% if current_user.can_checkout? %>
<% if @reservation.status == "reserved" %>
Expand Down
25 changes: 25 additions & 0 deletions app/views/user_mailer/checkin_receipt.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Hi <%= @reservation.reserver.name %>,
<br />

<p>This is a receipt for your equipment return. </p>

<p>Equipment returned: <%= @reservation.equipment_model.name%> (<%= @reservation.equipment_object.name %>) <br />
Checkout date: <%= @reservation.checked_out.strftime(" %B %e, %Y at %l:%M%P") %> <br />
Return date: <%= @reservation.checked_in.strftime(" %B %e, %Y at %l:%M%P") %> <br />

<% unless @reservation.notes.nil? %>
Notes: <%= @reservation.notes %> <br />
<% end %>
</p>

<p> <% if (@reservation.due_date - @reservation.checked_in ) < 86400 %>
Since the equipment was returned late, you will be charged a late fee of
<%= number_to_currency(@reservation.equipment_model.late_fee) %> per day,
for a total of <%= number_to_currency(((@reservation.checked_in - @reservation.due_date )/86400).to_i*(@reservation.equipment_model.late_fee))%>. </p>
<% end %></p>




Sincerely, <br />
<%= Settings.department_name %>
19 changes: 19 additions & 0 deletions app/views/user_mailer/checkout_receipt.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Hi <%= @reservation.reserver.name %>,
<br />

<p>This is a receipt for your equipment checkout. </p>

<p>Equipment picked up: <%= @reservation.equipment_model.name%> (<%= @reservation.equipment_object.name %>) <br />
Checkout date: <%= @reservation.checked_out.strftime(" %B %e, %Y at %l:%M%P") %> <br />
Due date: <%= @reservation.due_date.strftime("%B %e, %Y") %> <br />
<% unless @reservation.notes.nil? %>
Notes: <%= @reservation.notes %> <br />
<% end %>
</p>

<p>As a reminder, overdue equipment will incur a late fee of <%= number_to_currency(@reservation.equipment_model.late_fee) %> per day. </p>

<br />

Sincerely, <br />
<%= Settings.department_name %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
get :check_out_single
get :check_in_single
get :show_all
get :checkout_email
get :checkin_email
end
end

Expand Down
11 changes: 11 additions & 0 deletions public/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
overflow: hidden;
}

/*The next two divs are for buttons to display in the same line. */
#left_stuff {
width: 30%;
float: left;
}

#right_stuff {
width: 70%;
float: right;
}

#itg_wrapper {
width: 920px;
}
Expand Down

0 comments on commit 5e983b3

Please sign in to comment.