Add Reciept to the Purchase System
authorIra W. Snyder <devel@irasnyder.com>
Tue, 27 Nov 2007 00:22:37 +0000 (16:22 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Tue, 27 Nov 2007 00:22:37 +0000 (16:22 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/purchase_controller.rb
app/views/purchase/menu.rhtml
app/views/purchase/reciept.rhtml [new file with mode: 0644]
db/development.sqlite3

index 6be4254..4492862 100644 (file)
@@ -76,17 +76,26 @@ class PurchaseController < ApplicationController
     session[:items] = []
   end
 
-  def success_end
-    # Set the customer's debt to $0.00. They MUST pay you before
-    # checking anything else out, of course
+  def reciept
+    # Save important data, since we're gonna wipe it out now
+    @customer = Customer.find_by_id(session[:customer_id])
+    @debt = @customer.debt
+    @total = session[:total] + @debt
+    @items = session[:items]
+    @time = Time.now
+
+    # Set the customer's debt to $0.00, she paid us
     @customer = Customer.find_by_id(session[:customer_id])
     @customer.debt = 0.00
     @customer.save
 
+    # Wipe session data
     session[:customer_id] = nil
     session[:total] = nil
     session[:items] = nil
-    redirect_to :action => :begin
+
+    # Show the reciept
+    render :action => 'reciept'
   end
 
   def customer_ok
@@ -174,7 +183,7 @@ class PurchaseController < ApplicationController
       purchase.rentable = @rentable
       purchase.save!
 
-      # Add te session variables
+      # Add to session variables
       session[:total] += @rentable.calculated_price
       session[:items].push @rentable
 
index e2e01b5..5fc8814 100644 (file)
@@ -27,6 +27,6 @@
   <br/>
   <br/>
   <br/>
-  <li><%=link_to 'End Purchase', :action => 'success_end' %></li>
+  <li><%=link_to 'End Purchase', :action => 'reciept' %></li>
 </ul>
 
diff --git a/app/views/purchase/reciept.rhtml b/app/views/purchase/reciept.rhtml
new file mode 100644 (file)
index 0000000..2c4918a
--- /dev/null
@@ -0,0 +1,49 @@
+<h1>Reciept</h1>
+
+<p><b>Customer ID: </b><%= @customer.id.to_s %></p>
+<p><b>Customer Name: </b><%= @customer.name.to_s %></p>
+<br/>
+<p><b>Transaction Date: </b><%= @time %></p>
+<br/>
+
+<p><b>Purchases:</b></p>
+<table border="1">
+  <!-- Header -->
+  <tr>
+    <th>Item</th>
+    <th>Due Date</th>
+    <th>Price</th>
+  </tr>
+
+  <!-- Debt -->
+  <% if @debt %>
+  <tr>
+    <td><b>Overdue Item Fees</b></td>
+    <td></td>
+    <td><%= number_to_currency(@debt) %></td>
+  </tr>
+  <% end %>
+<% for item in @items %>
+  <tr>
+    <td><%=h item.title %></td>
+  <% if item.class == Video or item.class == Game %>
+    <td><%=h item.due_date %></td>
+    <td><%=h number_to_currency(item.calculated_price) %></td>
+  <% else %>
+    <td></td>
+    <td><%=h number_to_currency(item.price) %></td>
+  <% end %>
+  </tr>
+<% end %>
+  <tr>
+    <td><b>Total</b></td>
+    <td></td>
+    <td><b><%= number_to_currency(@total) %></b></td>
+  </tr>
+</table>
+
+<br/>
+
+<%= link_to 'Start a new Purchase', :action => 'begin' %>
+
+
index 68cbfbe..74a0b45 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ