Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add some nicer data representations

Signed-off-by: trebor8x <trobbe@online.de>
  • Loading branch information...
commit 2ac0effef7cf2b4d09d40d4f877f3227f3f41a90 1 parent cc6b390
Tobias Schmidt authored July 12, 2009 trebor8x committed July 31, 2009
10  app/models/doc.rb
... ...
@@ -1,8 +1,8 @@
1 1
 class Doc < StoredFile
2  
-	set_table_name "stored_files"
3  
-	has_attachment :content_type => 'application/msword',
4  
-	:max_size => 3.megabytes,
5  
-	:storage => :file_system
  2
+  set_table_name "stored_files"
  3
+  has_attachment  :content_type => 'application/msword',
  4
+                  :max_size => 3.megabytes,
  5
+                  :storage => :file_system
6 6
 
7  
-	validates_as_attachment
  7
+  validates_as_attachment
8 8
 end
43  app/views/customers/index.html.erb
... ...
@@ -1,26 +1,27 @@
1 1
 <h2 class="head">Kundenliste</h2>
2 2
 <div id="list">
3 3
 
4  
-	<table>
5  
-		<tr>
6  
-			<th>Kundennummer</th>
7  
-			<th>Firmenname</th>
8  
-			<th>Telefonnummer</th>
9  
-			<th>Email</th>
10  
-			<th>Kontaktname</th>
11  
-		</tr>
  4
+  <table>
  5
+    <tr>
  6
+      <th>#</th>
  7
+      <th>Firmenname</th>
  8
+      <th>Kontaktname</th>
  9
+      <th>Email</th>
  10
+      <th>Telefonnummer</th>
  11
+      <th colspan="3"></th>
  12
+    </tr>
12 13
 
13  
-		<% for customer in @customers %>
14  
-			<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
15  
-				<td><%=h customer.customer_num %></td>
16  
-				<td><%=h customer.company_name %></td>
17  
-				<td><%=h customer.tel_number %></td>
18  
-				<td><%=h customer.email %></td>
19  
-				<td><%=h customer.full_name %></td>
20  
-				<td><%= link_to 'Zeigen', customer %></td>
21  
-				<td><%= link_to 'Bearbeiten', edit_customer_path(customer) %></td>
22  
-				<td><%= link_to 'Löschen', customer, :confirm => 'Sind Sie sicher?', :method => :delete %></td>
23  
-			</tr>
24  
-		<% end %>
25  
-	</table>
  14
+    <% for customer in @customers %>
  15
+    <tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
  16
+      <td><%=h customer.customer_num %></td>
  17
+      <td><%=h customer.company_name %></td>
  18
+      <td><%=h customer.full_name %></td>
  19
+      <td><%= mail_to customer.email %></td>
  20
+      <td><%=h customer.tel_number %></td>
  21
+      <td><%= link_to 'Zeigen', customer %></td>
  22
+      <td><%= link_to 'Bearbeiten', edit_customer_path(customer) %></td>
  23
+      <td><%= link_to 'Löschen', customer, :confirm => 'Sind Sie sicher?', :method => :delete %></td>
  24
+    </tr>
  25
+    <% end %>
  26
+  </table>
26 27
 </div>
134  app/views/customers/show.html.erb
... ...
@@ -1,82 +1,58 @@
1 1
 <h2 class="head">Kontaktdaten</h2>
2 2
 <div id="list">
3  
-	<p>
4  
-	<b>Kundennummer:</b>
5  
-	<%=h @customer.customer_num %>
6  
-	</p>
7  
-
8  
-	<p>
9  
-	<b>Firmenname:</b>
10  
-	<%=h @customer.company_name %>
11  
-	</p>
12  
-
13  
-	<p>
14  
-	<b>Staat:</b>
15  
-	<%=h @customer.state %>
16  
-	</p>
17  
-
18  
-	<p>
19  
-	<b>Stadt:</b>
20  
-	<%=h @customer.city %>
21  
-	</p>
22  
-
23  
-	<p>
24  
-	<b>Postleitzahl:</b>
25  
-	<%=h @customer.zipcode %>
26  
-	</p>
27  
-
28  
-	<p>
29  
-	<b>Straße:</b>
30  
-	<%=h @customer.street %>
31  
-	</p>
32  
-
33  
-	<p>
34  
-	<b>Telefonnummer:</b>
35  
-	<%=h @customer.tel_number %>
36  
-	</p>
37  
-
38  
-	<p>
39  
-	<b>Email:</b>
40  
-	<%=h @customer.email %>
41  
-	</p>
42  
-
43  
-	<p>
44  
-	<b>Web:</b>
45  
-	<%=h @customer.web %>
46  
-	</p>
47  
-
48  
-	<p>
49  
-	<b>Kontaktname:</b>
50  
-	<%=h @customer.full_name %>
51  
-	</p>
52  
-
53  
-	<%= link_to 'Bearbeiten', edit_customer_path(@customer) %> |
54  
-	<%= link_to 'Zurück', customers_path %>
55  
-
56  
-	<br /><br />
57  
-	<div id="list">
58  
-		<h3>Rechnungsliste:</h2>
59  
-		<table>
60  
-			<tr>
61  
-				<th>Rechnungsnummer</th>
62  
-				<th>Rechnungssumme</th>
63  
-				<th>Rechnungsdatum</th>
64  
-				<th>Pdf</th>
65  
-				<th>Doc</th>
66  
-			</tr>
67  
-
68  
-			<% for invoice in @customer.invoices %>
69  
-				<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
70  
-					<td><%=h invoice.invoice_num %></td>
71  
-					<td><%=h invoice.sum %></td>
72  
-					<td><%=h invoice.date %></td>
73  
-				<td><%if invoice.pdf%><%= link_to image_tag("acroread.png"), invoice.pdf.public_filename %><%end%></td>
74  
-				<td><%if invoice.doc%><%= link_to image_tag("word.png"), invoice.doc.public_filename%><%end%></td>
75  
-					<td><%= link_to 'Zeigen', invoice %></td>
76  
-					<td><%= link_to 'Bearbeiten', edit_invoice_path(invoice) %></td>
77  
-					<td><%= link_to 'Löschen', invoice, :confirm => 'Sind Sie sicher?', :method => :delete %></td>
78  
-				</tr>
79  
-			<% end %>
80  
-		</table>
81  
-	</div>
  3
+  <p>
  4
+    <b>Kundennummer:</b>
  5
+    <%=h @customer.customer_num %>
  6
+  </p>
  7
+
  8
+  <p>
  9
+    <b>Firmenname:</b>
  10
+    <%=h @customer.company_name %>
  11
+  </p>
  12
+
  13
+  <p>
  14
+    <b>Staat:</b>
  15
+    <%=h @customer.state %>
  16
+  </p>
  17
+
  18
+  <p>
  19
+    <b>Stadt:</b>
  20
+    <%=h @customer.city %>
  21
+  </p>
  22
+
  23
+  <p>
  24
+    <b>Postleitzahl:</b>
  25
+    <%=h @customer.zipcode %>
  26
+  </p>
  27
+
  28
+  <p>
  29
+    <b>Straße:</b>
  30
+    <%=h @customer.street %>
  31
+  </p>
  32
+
  33
+  <p>
  34
+    <b>Telefonnummer:</b>
  35
+    <%=h @customer.tel_number %>
  36
+  </p>
  37
+
  38
+  <p>
  39
+    <b>Email:</b>
  40
+    <%=h @customer.email %>
  41
+  </p>
  42
+
  43
+  <p>
  44
+    <b>Web:</b>
  45
+    <%=h @customer.web %>
  46
+  </p>
  47
+
  48
+  <p>
  49
+    <b>Kontaktname:</b>
  50
+    <%=h @customer.full_name %>
  51
+  </p>
  52
+
  53
+  <%= link_to 'Bearbeiten', edit_customer_path(@customer) %> |
  54
+  <%= link_to 'Zurück', customers_path %>
  55
+
  56
+  <br /><br />
  57
+  <%= render :partial => "invoices/invoices", :object => @customer.invoices %>
82 58
 </div>
23  app/views/invoices/_invoices.html.erb
... ...
@@ -0,0 +1,23 @@
  1
+<table>
  2
+  <tr>
  3
+    <th class="right">#</th>
  4
+    <th>Firmenname</th>
  5
+    <th>Rechnungssumme</th>
  6
+    <th>Rechnungsdatum</th>
  7
+    <th>Pdf</th>
  8
+    <th>Doc</th>
  9
+  </tr>
  10
+  <%- for invoice in invoices -%>
  11
+  <tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
  12
+    <td class="right"><%= h invoice.invoice_num %></td>
  13
+    <td class="right"><%= link_to invoice.customer.company_name, customer_url(invoice.customer) %></td>
  14
+    <td class="right"><%= number_to_currency_with_euro(invoice.sum) %></td>
  15
+    <td class="right"><%= l invoice.date, :format => :long %></td>
  16
+    <td><% if invoice.pdf%><%= link_to image_tag("acroread.png"), invoice.pdf.public_filename %><% end %></td>
  17
+    <td><% if invoice.doc%><%= link_to image_tag("word.png"), invoice.doc.public_filename%><% end %></td>
  18
+    <td><%= link_to 'Zeigen', invoice %></td>
  19
+    <td><%= link_to 'Bearbeiten', edit_invoice_path(invoice) %></td>
  20
+    <td><%= link_to 'Löschen', invoice, :confirm => 'Sind Sie sicher?', :method => :delete %></td>
  21
+  </tr>
  22
+  <%- end -%>
  23
+</table>
2  app/views/invoices/edit.html.erb
@@ -9,7 +9,7 @@
9 9
 		</p>
10 10
 		<p>
11 11
 		<%= f.label :date, 'Rechnungsdatum' %><br />
12  
-		<%= f.text_field :date %>
  12
+		<%= f.date_select :date %>
13 13
 		</p>
14 14
 		<p>
15 15
 		<%= f.label :customer_id, 'Kundenummer' %><br />
25  app/views/invoices/index.html.erb
... ...
@@ -1,27 +1,4 @@
1 1
 <h2 class="head">Rechnungsliste</h2>
2 2
 <div id="list">
3  
-	<table>
4  
-		<tr>
5  
-			<th>Rechnungsnummer</th>
6  
-			<th>Firmenname</th>
7  
-			<th>Rechnungssumme</th>
8  
-			<th>Rechnungsdatum</th>
9  
-			<th>Pdf</th>
10  
-			<th>Doc</th>
11  
-		</tr>
12  
-
13  
-		<% for invoice in @invoices %>
14  
-			<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
15  
-				<td><%=h invoice.invoice_num %></td>
16  
-				<td><%= link_to invoice.customer.company_name, customer_url(invoice.customer) %></td>
17  
-				<td><%=h invoice.sum %></td>
18  
-				<td><%=h invoice.date %></td>
19  
-			<td><%if invoice.pdf%><%= link_to image_tag("acroread.png"), invoice.pdf.public_filename %><%end%></td>
20  
-			<td><%if invoice.doc%><%= link_to image_tag("word.png"), invoice.doc.public_filename%><%end%></td>
21  
-				<td><%= link_to 'Zeigen', invoice %></td>
22  
-				<td><%= link_to 'Bearbeiten', edit_invoice_path(invoice) %></td>
23  
-				<td><%= link_to 'Löschen', invoice, :confirm => 'Sind Sie sicher?', :method => :delete %></td>
24  
-			</tr>
25  
-		<% end %>
26  
-	</table>
  3
+  <%= render :partial => "invoices" %>
27 4
 </div>
4  app/views/invoices/show.html.erb
@@ -7,7 +7,7 @@
7 7
 
8 8
 	<p>
9 9
 	<b>Rechnungsdatum:</b>
10  
-	<%= h @invoice.date %>
  10
+	<%= l @invoice.date, :format => :long %>
11 11
 	</p>
12 12
 	<p>
13 13
 	<b>Kundennummer:</b>
@@ -15,7 +15,7 @@
15 15
 	</p>
16 16
 	<p>
17 17
 	<b>Rechnungssumme:</b>
18  
-	<%= h @invoice.sum %>
  18
+	<%= number_to_currency_with_euro @invoice.sum %>
19 19
 	</p>
20 20
 	<p>
21 21
 	<b>Rechnung-Pdf:</b>
16  config/initializers/number_to_currency_euro.rb
... ...
@@ -0,0 +1,16 @@
  1
+module ActionView
  2
+  module Helpers
  3
+    module NumberHelper
  4
+      def number_to_currency_with_euro(number, options = {})
  5
+        defaults = {
  6
+          :unit => "&euro;", #obvious
  7
+          :precision => 2, #digits after separator
  8
+          :separator => ",", 
  9
+        :delimiter => ".", #thousands delimiter
  10
+        :format => "%n %u" } #put a space between number (%n) and unit (%u) and unit is after number
  11
+        s = number_to_currency_without_euro(number, defaults.merge(options))
  12
+      end
  13
+      alias_method_chain :number_to_currency, :euro
  14
+    end
  15
+  end
  16
+end
5  public/stylesheets/invoice.css
@@ -166,6 +166,7 @@ a:hover {
166 166
 
167 167
 #list table {
168 168
 	border-collapse: collapse;
  169
+	width: 100%;
169 170
 }
170 171
 
171 172
 #list table tr th {
@@ -178,6 +179,10 @@ a:hover {
178 179
 	vertical-align: middle;
179 180
 }
180 181
 
  182
+#list table tr .right {
  183
+  text-align: right;
  184
+}
  185
+
181 186
 #list .list-line-even {
182 187
 	background-color: #CCDDFF;
183 188
 }

0 notes on commit 2ac0eff

Please sign in to comment.
Something went wrong with that request. Please try again.