From 1d85b880f25468679f703cdb31428fc82f471cb7 Mon Sep 17 00:00:00 2001
From: Benjamin Meichsner
Date: Sat, 10 Jan 2009 19:36:58 +0100
Subject: [PATCH] Created namespace 'finance' and moved invoices into it.
---
.../{ => finance}/invoices_controller.rb | 8 +--
app/controllers/finance_controller.rb | 1 +
app/models/invoice.rb | 2 +
app/views/finance/index.haml | 19 +++++
.../{ => finance}/invoices/edit.html.erb | 6 +-
app/views/finance/invoices/index.html.erb | 38 ++++++++++
app/views/{ => finance}/invoices/new.html.erb | 4 +-
.../{ => finance}/invoices/show.html.erb | 4 +-
app/views/index/index.haml | 71 +++++++++----------
app/views/invoices/index.html.erb | 32 ---------
app/views/layouts/_main_tabnav.html.erb | 2 +-
app/views/ordering/_currentOrders.haml | 66 +++++++++--------
app/views/ordering/index.haml | 16 ++---
config/routes.rb | 6 +-
public/stylesheets/main.css | 17 ++---
public/stylesheets/print.css | 3 +-
public/stylesheets/sass/main.sass | 1 +
17 files changed, 163 insertions(+), 133 deletions(-)
rename app/controllers/{ => finance}/invoices_controller.rb (88%)
rename app/views/{ => finance}/invoices/edit.html.erb (82%)
create mode 100644 app/views/finance/invoices/index.html.erb
rename app/views/{ => finance}/invoices/new.html.erb (87%)
rename app/views/{ => finance}/invoices/show.html.erb (80%)
delete mode 100644 app/views/invoices/index.html.erb
diff --git a/app/controllers/invoices_controller.rb b/app/controllers/finance/invoices_controller.rb
similarity index 88%
rename from app/controllers/invoices_controller.rb
rename to app/controllers/finance/invoices_controller.rb
index fa657891..76aad868 100644
--- a/app/controllers/invoices_controller.rb
+++ b/app/controllers/finance/invoices_controller.rb
@@ -1,4 +1,4 @@
-class InvoicesController < ApplicationController
+class Finance::InvoicesController < ApplicationController
def index
@invoices = Invoice.find(:all, :order => "date DESC")
@@ -39,7 +39,7 @@ class InvoicesController < ApplicationController
respond_to do |format|
if @invoice.save
flash[:notice] = 'Invoice was successfully created.'
- format.html { redirect_to(@invoice) }
+ format.html { redirect_to([:finance, @invoice]) }
format.xml { render :xml => @invoice, :status => :created, :location => @invoice }
else
format.html { render :action => "new" }
@@ -56,7 +56,7 @@ class InvoicesController < ApplicationController
respond_to do |format|
if @invoice.update_attributes(params[:invoice])
flash[:notice] = 'Invoice was successfully updated.'
- format.html { redirect_to(@invoice) }
+ format.html { redirect_to([:finance, @invoice]) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
@@ -72,7 +72,7 @@ class InvoicesController < ApplicationController
@invoice.destroy
respond_to do |format|
- format.html { redirect_to(invoices_path) }
+ format.html { redirect_to(finance_invoices_path) }
format.xml { head :ok }
end
end
diff --git a/app/controllers/finance_controller.rb b/app/controllers/finance_controller.rb
index 3ceb3089..0792f490 100644
--- a/app/controllers/finance_controller.rb
+++ b/app/controllers/finance_controller.rb
@@ -12,6 +12,7 @@ class FinanceController < ApplicationController
def index
@financial_transactions = FinancialTransaction.find(:all, :order => "created_on DESC", :limit => 8)
@orders = Order.find(:all, :conditions => 'finished = 1 AND booked = 0', :order => 'ends DESC')
+ @unpaid_invoices = Invoice.unpaid
end
#list all ordergroups
diff --git a/app/models/invoice.rb b/app/models/invoice.rb
index 2b5a7156..9b678c16 100644
--- a/app/models/invoice.rb
+++ b/app/models/invoice.rb
@@ -21,6 +21,8 @@ class Invoice < ActiveRecord::Base
validates_presence_of :supplier_id
validates_uniqueness_of :date, :scope => [:supplier_id]
+ named_scope :unpaid, :conditions => { :paid_on => nil }
+
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
def amount=(amount)
self[:amount] = String.delocalized_decimal(amount)
diff --git a/app/views/finance/index.haml b/app/views/finance/index.haml
index 0596d74e..c40935f2 100644
--- a/app/views/finance/index.haml
+++ b/app/views/finance/index.haml
@@ -1,5 +1,24 @@
%h1 Finanzbereich
.left_column{:style => 'width: 50%'}
+ .box_title
+ %h2 Unpaid invoices
+ .column_content
+ %p= link_to "Show all invoices", invoices_path
+ %table.list
+ %thead
+ %tr
+ %th Date
+ %th Amount
+ %th Supplier
+ %th
+ %tbody
+ - for invoice in @unpaid_invoices
+ %tr{:class => cycle("even","odd", :name => "invoices")}
+ %td= format_date(invoice.date)
+ %td= number_to_currency(invoice.amount)
+ %td=h invoice.supplier.name
+ %td= link_to "Edit", edit_invoice_path(invoice)
+
.box_title
%h2 letzte Überweisungen
.column_content
diff --git a/app/views/invoices/edit.html.erb b/app/views/finance/invoices/edit.html.erb
similarity index 82%
rename from app/views/invoices/edit.html.erb
rename to app/views/finance/invoices/edit.html.erb
index afa54dec..e14fec17 100644
--- a/app/views/invoices/edit.html.erb
+++ b/app/views/finance/invoices/edit.html.erb
@@ -1,6 +1,6 @@
Editing invoice
-<% form_for(@invoice) do |f| %>
+<% form_for([:finance, @invoice]) do |f| %>
<%= f.error_messages %>
@@ -32,5 +32,5 @@
<% end %>
-<%= link_to 'Show', @invoice %> |
-<%= link_to 'Back', invoices_path %>
+<%= link_to 'Show', [:finance, @invoice] %> |
+<%= link_to 'Back', finance_invoices_path %>
diff --git a/app/views/finance/invoices/index.html.erb b/app/views/finance/invoices/index.html.erb
new file mode 100644
index 00000000..9feb7f7f
--- /dev/null
+++ b/app/views/finance/invoices/index.html.erb
@@ -0,0 +1,38 @@
+<% title "Invoices" %>
+
+
+
+
+ Supplier |
+ Number |
+ Date |
+ Paid on |
+ Amount |
+ Delivery |
+ Note |
+ |
+ |
+ |
+
+
+
+ <% for invoice in @invoices %>
+
+ <%=h invoice.supplier.name %> |
+ <%=h invoice.number %> |
+ <%= invoice.date %> |
+ <%= invoice.paid_on %> |
+ <%= invoice.amount %> |
+ <%=h invoice.delivery_id %> |
+ <%=h truncate(invoice.note) %> |
+ <%= link_to 'Show', finance_invoice_path(invoice) %> |
+ <%= link_to 'Edit', edit_finance_invoice_path(invoice) %> |
+ <%= link_to 'Destroy', finance_invoice_path(invoice), :confirm => 'Are you sure?', :method => :delete %> |
+
+ <% end %>
+
+
+
+
+
+<%= link_to 'New invoice', new_finance_invoice_path %>
diff --git a/app/views/invoices/new.html.erb b/app/views/finance/invoices/new.html.erb
similarity index 87%
rename from app/views/invoices/new.html.erb
rename to app/views/finance/invoices/new.html.erb
index 3effdbc4..c51a13b6 100644
--- a/app/views/invoices/new.html.erb
+++ b/app/views/finance/invoices/new.html.erb
@@ -1,6 +1,6 @@
New invoice
-<% form_for(@invoice) do |f| %>
+<% form_for([:finance, @invoice]) do |f| %>
<%= f.error_messages %>
@@ -32,4 +32,4 @@
<% end %>
-<%= link_to 'Back', invoices_path %>
+<%= link_to 'Back', finance_invoices_path %>
diff --git a/app/views/invoices/show.html.erb b/app/views/finance/invoices/show.html.erb
similarity index 80%
rename from app/views/invoices/show.html.erb
rename to app/views/finance/invoices/show.html.erb
index 890498c4..17b58042 100644
--- a/app/views/invoices/show.html.erb
+++ b/app/views/finance/invoices/show.html.erb
@@ -36,5 +36,5 @@
-<%= link_to 'Edit', edit_invoice_path(@invoice) %> |
-<%= link_to 'Back', invoices_path %>
+<%= link_to 'Edit', edit_finance_invoice_path(@invoice) %> |
+<%= link_to 'Back', finance_invoices_path %>
diff --git a/app/views/index/index.haml b/app/views/index/index.haml
index b0d87398..532599ec 100644
--- a/app/views/index/index.haml
+++ b/app/views/index/index.haml
@@ -2,9 +2,9 @@
#start_nav
= render :partial => 'start_nav'
-
-- unless @unaccepted_tasks.empty? && @next_tasks.empty? && @unassigned_tasks_number == 0
- .right_column{:style => "width:70%"}
+
+.right_column{:style => "width:70%"}
+ - unless @unaccepted_tasks.empty? && @next_tasks.empty? && @unassigned_tasks_number == 0
.box_title
%h2=_ "Tasks"
.column_content
@@ -27,45 +27,42 @@
= _("There are") + " #{@unassigned_tasks_number} " + link_to(_("unassigned task(s)"), :controller => "tasks")
%p{:style => "clear:both"}= link_to _("My tasks"), :controller => "tasks", :action => "myTasks"
-- unless @messages.empty?
- .right_column{:style => "width:70%"}
+ - unless @messages.empty?
.box_title
%h2=_ "Unread messages"
.column_content
= render :partial => 'messages/unread'
%p= link_to _("All messages"), :controller => 'messages', :action => 'inbox'
-- if @orderGroup
- // Current orders
- = render :partial => 'ordering/currentOrders'
-
+ - if @orderGroup
+ // Current orders
+ = render :partial => 'ordering/currentOrders'
// OrderGroup overview
- .right_column{:style => "width:70%"}
- .box_title
- %h2=_ "My ordergroup"
- .column_content
- %p
- %b= @orderGroup.name
- |
- =_ "Account balance:"
- = number_to_currency(@orderGroup.account_balance)
- %span{:style => "color:grey"}
- (zuletzt aktualisiert vor
- = distance_of_time_in_words(Time.now, @orderGroup.account_updated) + ")"
- %h3=_ "Last transactions"
- %table
- %tr
- %th=_ "When"
- %th=_ "Who"
- %th=_ "Note"
- %th=_ "Amount"
- - for ft in @financial_transactions
- %tr{:class => cycle('even','odd')}
- %td= format_time(ft.created_on)
- %td= h(ft.user.nil? ? '?' : ft.user.nick)
- %td= h(ft.note)
- - color = ft.amount < 0 ? 'red' : 'black'
- %td{:style => "color:#{color}; width:5em", :class => "currency"}= number_to_currency(ft.amount)
- %br/
- = link_to _("more ..."), :action => "myOrdergroup"
\ No newline at end of file
+ .box_title
+ %h2=_ "My ordergroup"
+ .column_content
+ %p
+ %b= @orderGroup.name
+ |
+ =_ "Account balance:"
+ = number_to_currency(@orderGroup.account_balance)
+ %span{:style => "color:grey"}
+ (zuletzt aktualisiert vor
+ = distance_of_time_in_words(Time.now, @orderGroup.account_updated) + ")"
+ %h3=_ "Last transactions"
+ %table
+ %tr
+ %th=_ "When"
+ %th=_ "Who"
+ %th=_ "Note"
+ %th=_ "Amount"
+ - for ft in @financial_transactions
+ %tr{:class => cycle('even','odd')}
+ %td= format_time(ft.created_on)
+ %td= h(ft.user.nil? ? '?' : ft.user.nick)
+ %td= h(ft.note)
+ - color = ft.amount < 0 ? 'red' : 'black'
+ %td{:style => "color:#{color}; width:5em", :class => "currency"}= number_to_currency(ft.amount)
+ %br/
+ = link_to _("more ..."), :action => "myOrdergroup"
\ No newline at end of file
diff --git a/app/views/invoices/index.html.erb b/app/views/invoices/index.html.erb
deleted file mode 100644
index 3c08f4e1..00000000
--- a/app/views/invoices/index.html.erb
+++ /dev/null
@@ -1,32 +0,0 @@
-<% title "Invoices" %>
-
-
-
- Supplier |
- Number |
- Date |
- Paid on |
- Amount |
- Delivery |
- Note |
-
-
-<% for invoice in @invoices %>
-
- <%=h invoice.supplier.name %> |
- <%=h invoice.number %> |
- <%= invoice.date %> |
- <%= invoice.paid_on %> |
- <%= invoice.amount %> |
- <%=h invoice.delivery_id %> |
- <%=h truncate(invoice.note) %> |
- <%= link_to 'Show', invoice %> |
- <%= link_to 'Edit', edit_invoice_path(invoice) %> |
- <%= link_to 'Destroy', invoice, :confirm => 'Are you sure?', :method => :delete %> |
-
-<% end %>
-
-
-
-
-<%= link_to 'New invoice', new_invoice_path %>
diff --git a/app/views/layouts/_main_tabnav.html.erb b/app/views/layouts/_main_tabnav.html.erb
index eaecae3c..e9591032 100644
--- a/app/views/layouts/_main_tabnav.html.erb
+++ b/app/views/layouts/_main_tabnav.html.erb
@@ -31,7 +31,7 @@
:subnav => [
{ :name => "Ordergroups", :url => "/finance/listOrdergroups" },
{ :name => "Balance orders", :url => "/finance/listOrders" },
- { :name => "Invoices", :url => invoices_path }
+ { :name => "Invoices", :url => finance_invoices_path }
]
},
{ :name => "Administration", :url => "/admin", :active => ["admin"],
diff --git a/app/views/ordering/_currentOrders.haml b/app/views/ordering/_currentOrders.haml
index 121ce829..49af6db8 100644
--- a/app/views/ordering/_currentOrders.haml
+++ b/app/views/ordering/_currentOrders.haml
@@ -1,34 +1,32 @@
-- if @orderGroup
- .right_column{:style => "width:70%"}
- .box_title
- %h2=_ "Running orders"
- .column_content
- - unless @currentOrders.empty?
- %table.list
- %thead
- %tr
- %th=_ "Name"
- %th=_ "Supplier"
- %th=_ "End"
- %th=_ "Who ordered?"
- %th=_ "Sum"
- %tbody
- - total = 0
- - @currentOrders.each do |order|
- %tr{:class => cycle('even', 'odd', :name => 'current_orders')}
- %td= link_to order.name, :controller => 'ordering', :action => 'order', :id => order
- %td=h order.supplier.name
- %td=h format_time(order.ends) unless order.ends.nil?
- - if (groupOrder = order.group_orders.find(:first, :conditions => ["order_group_id = ?", @orderGroup.id]))
- - total += groupOrder.price
- %td=h groupOrder.updated_by.nil? ? '??' : "#{groupOrder.updated_by.nick} (#{format_time(groupOrder.updated_on)})"
- %td= number_to_currency(groupOrder.price)
- - else
- %td
- %td
- - if total > 0
- %p
- =_ "Total sum"
- %b= number_to_currency(total)
- - else
- %i=_ "There aren't current orders at the moment."
\ No newline at end of file
+.box_title
+ %h2=_ "Running orders"
+.column_content
+ - unless @currentOrders.empty?
+ %table.list
+ %thead
+ %tr
+ %th=_ "Name"
+ %th=_ "Supplier"
+ %th=_ "End"
+ %th=_ "Who ordered?"
+ %th=_ "Sum"
+ %tbody
+ - total = 0
+ - @currentOrders.each do |order|
+ %tr{:class => cycle('even', 'odd', :name => 'current_orders')}
+ %td= link_to order.name, :controller => 'ordering', :action => 'order', :id => order
+ %td=h order.supplier.name
+ %td=h format_time(order.ends) unless order.ends.nil?
+ - if (groupOrder = order.group_orders.find(:first, :conditions => ["order_group_id = ?", @orderGroup.id]))
+ - total += groupOrder.price
+ %td=h groupOrder.updated_by.nil? ? '??' : "#{groupOrder.updated_by.nick} (#{format_time(groupOrder.updated_on)})"
+ %td= number_to_currency(groupOrder.price)
+ - else
+ %td
+ %td
+ - if total > 0
+ %p
+ =_ "Total sum"
+ %b= number_to_currency(total)
+ - else
+ %i=_ "There aren't current orders at the moment."
\ No newline at end of file
diff --git a/app/views/ordering/index.haml b/app/views/ordering/index.haml
index 052dc6c2..9f112091 100644
--- a/app/views/ordering/index.haml
+++ b/app/views/ordering/index.haml
@@ -19,12 +19,13 @@
%th= _('Available')
%th{:class => "currency"}= number_to_currency(@orderGroup.account_balance - @currentOrdersValue - @nonbookedOrdersValue)
-// Current Orders
-= render :partial => "currentOrders"
+.right_column{:style => "width:70%"}
+ // Current Orders
+ - if @orderGroup
+ = render :partial => "currentOrders"
-// finished, nonbooked Orders
-- unless @finishedOrders.empty?
- .right_column{:style => "width:70%"}
+ // finished, nonbooked Orders
+ - unless @finishedOrders.empty?
.box_title
%h2= _('unrecorded orders')
.column_content
@@ -34,9 +35,8 @@
= _('total order value')
%b= number_to_currency(@nonbookedOrdersValue)
-// bookedOrders
-- unless @bookedOrders.empty?
- .right_column{:style => "width:70%"}
+ // bookedOrders
+ - unless @bookedOrders.empty?
.box_title
%h2= _('balanced orders')
.column_content
diff --git a/config/routes.rb b/config/routes.rb
index 09e333d1..292d6fde 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,6 +1,10 @@
ActionController::Routing::Routes.draw do |map|
- map.resources :invoices
+ map.namespace :finance do |finance|
+ finance.resources :invoices
+ end
+
+ #map.resources :invoices
map.resources :suppliers,
:has_many => [:deliveries],
:collection => { :shared_suppliers => :get }
diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css
index 004a7337..73191d93 100644
--- a/public/stylesheets/main.css
+++ b/public/stylesheets/main.css
@@ -133,31 +133,31 @@ abbr, acronym {
background: #f5f5f5;
padding: 0 10px 0px 5px;
float: left; }
- .menu ul, #start_nav ul {
+ .menu ul, #start_nav ul {
list-style-type: none;
margin: 0 0 0.2em 0;
padding: 0; }
- .menu ul li, #start_nav ul li {
+ .menu ul li, #start_nav ul li {
border-bottom: 1px solid #dedede;
color: #666;
margin: 0.8em 0 0 0;
font-weight: bold; }
- .menu ul li a:link, .menu ul li a:visited, #start_nav ul li a:link, #start_nav ul li a:visited {
+ .menu ul li a:link, .menu ul li a:visited, #start_nav ul li a:link, #start_nav ul li a:visited {
display: block;
padding: 0.25em 1em;
text-decoration: none;
width: 12em; }
- .menu ul li a:hover, .menu ul li a:focus, #start_nav ul li a:hover, #start_nav ul li a:focus {
+ .menu ul li a:hover, .menu ul li a:focus, #start_nav ul li a:hover, #start_nav ul li a:focus {
background-color: #e3e3e3; }
- .menu ul li ul, #start_nav ul li ul {
+ .menu ul li ul, #start_nav ul li ul {
margin: 0;
padding: 0; }
- .menu ul li ul li, #start_nav ul li ul li {
+ .menu ul li ul li, #start_nav ul li ul li {
border-top: 1px solid #dedede;
border-bottom: none;
margin: 0;
font-weight: normal; }
- .menu ul li ul li a:link, .menu ul li ul li a:visited, #start_nav ul li ul li a:link, #start_nav ul li ul li a:visited {
+ .menu ul li ul li a:link, .menu ul li ul li a:visited, #start_nav ul li ul li a:link, #start_nav ul li ul li a:visited {
width: 11.5em;
padding: 0 1em 0.1em 1.5em;
font-weight: normal;
@@ -291,7 +291,8 @@ div.box_title {
div.column_content {
background: #e4eed6;
color: black;
- padding: 10px; }
+ padding: 10px;
+ margin-bottom: 2em; }
div.column_content h2 {
color: black;
font-size: 1.3em;
diff --git a/public/stylesheets/print.css b/public/stylesheets/print.css
index 98d2ebf5..948501bf 100644
--- a/public/stylesheets/print.css
+++ b/public/stylesheets/print.css
@@ -291,7 +291,8 @@ div.box_title {
div.column_content {
background: #e4eed6;
color: black;
- padding: 10px; }
+ padding: 10px;
+ margin-bottom: 2em; }
div.column_content h2 {
color: black;
font-size: 1.3em;
diff --git a/public/stylesheets/sass/main.sass b/public/stylesheets/sass/main.sass
index 5734aa50..f6caa10f 100644
--- a/public/stylesheets/sass/main.sass
+++ b/public/stylesheets/sass/main.sass
@@ -329,6 +329,7 @@ div.column_content
:background = !boxContent
:color black
:padding 10px
+ margin-bottom: 2em
h2
:color black
:font-size 1.3em