Improved delivery-invoice-workflow.

This commit is contained in:
Benjamin Meichsner 2009-01-18 17:42:51 +01:00
parent 936e6ef69a
commit ff6b460cfc
28 changed files with 253 additions and 231 deletions

View file

@ -2,6 +2,10 @@ class ArticleCategoriesController < ApplicationController
before_filter :authenticate_article_meta before_filter :authenticate_article_meta
def index
@article_categories = ArticleCategory.all :order => 'name'
end
def new def new
@article_category = ArticleCategory.new @article_category = ArticleCategory.new

View file

@ -307,7 +307,6 @@ class ArticlesController < ApplicationController
# sync all articles with the external database # sync all articles with the external database
# renders a form with articles, which should be updated # renders a form with articles, which should be updated
def sync def sync
@supplier = Supplier.find(params[:id])
# check if there is an shared_supplier # check if there is an shared_supplier
unless @supplier.shared_supplier unless @supplier.shared_supplier
flash[:error]= @supplier.name + _(" ist not assigned to an external database.") flash[:error]= @supplier.name + _(" ist not assigned to an external database.")

View file

@ -19,7 +19,7 @@ class Finance::InvoicesController < ApplicationController
end end
def new def new
@invoice = Invoice.new @invoice = Invoice.new(:supplier_id => params[:supplier_id], :delivery_id => params[:delivery_id])
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb

View file

@ -0,0 +1,6 @@
class StockitController < ApplicationController
def index
@articles = Article.in_stock
end
end

View file

@ -1,20 +1,15 @@
class SuppliersController < ApplicationController class SuppliersController < ApplicationController
before_filter :authenticate_suppliers, :except => [:index, :list] before_filter :authenticate_suppliers, :except => [:index, :list]
helper :deliveries
# messages
MSG_SUPPLIER_DESTOYED = "Lieferant wurde gelöscht"
MSG_SUPPLIER_UPDATED = 'Lieferant wurde aktualisiert'
MSG_SUPPLIER_CREATED = "Lieferant wurde erstellt"
def index def index
@suppliers = Supplier.all :order => 'name' @suppliers = Supplier.all :order => 'name'
#@categories = ArticleCategory.all :order => 'name' @deliveries = Delivery.recent
end end
def show def show
@supplier = Supplier.find(params[:id]) @supplier = Supplier.find(params[:id])
@supplier_column_names = ["Name", "Telefon", "Telefon2", "FAX", "Email", "URL", "Kontakt", "Kundennummer", "Liefertage", "BestellHowTo", "Notiz", "Mindestbestellmenge"] @deliveries = @supplier.deliveries.recent
@supplier_columns = ["name", "phone", "phone2", "fax", "email", "url", "contact_person", "customer_number", "delivery_days", "order_howto", "note", "min_order_quantity"]
end end
# new supplier # new supplier
@ -31,7 +26,7 @@ class SuppliersController < ApplicationController
def create def create
@supplier = Supplier.new(params[:supplier]) @supplier = Supplier.new(params[:supplier])
if @supplier.save if @supplier.save
flash[:notice] = MSG_SUPPLIER_CREATED flash[:notice] = "Lieferant wurde erstellt"
redirect_to suppliers_path redirect_to suppliers_path
else else
render :action => 'new' render :action => 'new'
@ -45,7 +40,7 @@ class SuppliersController < ApplicationController
def update def update
@supplier = Supplier.find(params[:id]) @supplier = Supplier.find(params[:id])
if @supplier.update_attributes(params[:supplier]) if @supplier.update_attributes(params[:supplier])
flash[:notice] = MSG_SUPPLIER_UPDATED flash[:notice] = 'Lieferant wurde aktualisiert'
redirect_to @supplier redirect_to @supplier
else else
render :action => 'edit' render :action => 'edit'
@ -55,7 +50,7 @@ class SuppliersController < ApplicationController
def destroy def destroy
@supplier = Supplier.find(params[:id]) @supplier = Supplier.find(params[:id])
@supplier.destroy @supplier.destroy
flash[:notice] = MSG_SUPPLIER_DESTOYED flash[:notice] = "Lieferant wurde gelöscht"
redirect_to suppliers_path redirect_to suppliers_path
rescue => e rescue => e
flash[:error] = _("An error has occurred: ") + e.message flash[:error] = _("An error has occurred: ") + e.message

View file

@ -9,4 +9,13 @@ module DeliveriesHelper
end end
end end
def link_to_invoice(delivery)
if delivery.invoice
link_to number_to_currency(delivery.invoice.amount), [:finance, delivery.invoice],
:title => "Rechnung anzeigen"
else
link_to "Rechnung anlegen", new_finance_invoice_path(:supplier_id => delivery.supplier.id, :delivery_id => delivery.id)
end
end
end end

View file

@ -0,0 +1,2 @@
module StockitHelper
end

View file

@ -28,6 +28,8 @@ class Article < ActiveRecord::Base
belongs_to :supplier belongs_to :supplier
belongs_to :article_category belongs_to :article_category
named_scope :in_stock, :conditions => "quantity > 0", :order => 'suppliers.name', :include => :supplier
validates_presence_of :name, :unit, :net_price, :tax, :deposit, :unit_quantity, :supplier_id validates_presence_of :name, :unit, :net_price, :tax, :deposit, :unit_quantity, :supplier_id
validates_length_of :name, :in => 4..60 validates_length_of :name, :in => 4..60
validates_length_of :unit, :in => 2..15 validates_length_of :unit, :in => 2..15

View file

@ -12,8 +12,11 @@
class Delivery < ActiveRecord::Base class Delivery < ActiveRecord::Base
belongs_to :supplier belongs_to :supplier
has_one :invoice
has_many :stock_changes has_many :stock_changes
named_scope :recent, :order => 'created_at DESC', :limit => 10
validates_presence_of :supplier_id validates_presence_of :supplier_id
def stock_change_attributes=(stock_change_attributes) def stock_change_attributes=(stock_change_attributes)

View file

@ -18,6 +18,7 @@
class Invoice < ActiveRecord::Base class Invoice < ActiveRecord::Base
belongs_to :supplier belongs_to :supplier
belongs_to :delivery
validates_presence_of :supplier_id validates_presence_of :supplier_id
validates_uniqueness_of :date, :scope => [:supplier_id] validates_uniqueness_of :date, :scope => [:supplier_id]

View file

@ -0,0 +1,8 @@
- title "Artikelkategorien"
.left_column{:style => "width:50em"}
.box_title
%h2 Artikelkategorien
.column_content#categories
#category_form.box.edit_form{:style => "display:none;margin-bottom:1em;"}
#category_list= render :partial => 'article_categories/list'

View file

@ -16,7 +16,7 @@
=_ 'Change supplier:' =_ 'Change supplier:'
- form_tag do - form_tag do
= select_tag :switch_supplier, | = select_tag :switch_supplier, |
options_for_select( Supplier.all.collect {|s| [s.name, url_for(supplier_articles_path(s))] }, | options_for_select( Supplier.all(:order => 'name').collect {|s| [s.name, url_for(supplier_articles_path(s))] }, |
url_for(supplier_articles_path(@supplier)) ), | url_for(supplier_articles_path(@supplier)) ), |
:onchange => "redirectTo(this)", | :onchange => "redirectTo(this)", |
:style => "font-size: 0.9em;margin-left:1em;" | :style => "font-size: 0.9em;margin-left:1em;" |

View file

@ -51,20 +51,21 @@
%td= article.deposit %td= article.deposit
%td= article.article_category.name if article.article_category %td= article.article_category.name if article.article_category
%tr %tr
- fields_for 'articles[]', @article do |form|
%td{:style => highlight_new(unequal_attributes, :name)} %td{:style => highlight_new(unequal_attributes, :name)}
= text_field 'article[]', 'name', :size => 0 = form.text_field 'name', :size => 0
= hidden_field 'article[]', 'shared_updated_on' = form.hidden_field 'shared_updated_on'
%td{:style => highlight_new(unequal_attributes, :note)}= text_field 'article[]', 'note', :size => 15 %td{:style => highlight_new(unequal_attributes, :note)}= form.text_field 'note', :size => 15
%td{:style => highlight_new(unequal_attributes, :manufacturer)}= text_field 'article[]', 'manufacturer', :size => 10 %td{:style => highlight_new(unequal_attributes, :manufacturer)}= form.text_field 'manufacturer', :size => 10
%td{:style => highlight_new(unequal_attributes, :origin)}= text_field 'article[]', 'origin', :size => 5 %td{:style => highlight_new(unequal_attributes, :origin)}= form.text_field 'origin', :size => 5
%td{:style => highlight_new(unequal_attributes, :unit)}= text_field 'article[]', 'unit', :size => 5 %td{:style => highlight_new(unequal_attributes, :unit)}= form.text_field 'unit', :size => 5
%td{:style => highlight_new(unequal_attributes, :unit_quantity)}= text_field 'article[]', 'unit_quantity', :size => 5 %td{:style => highlight_new(unequal_attributes, :unit_quantity)}= form.text_field 'unit_quantity', :size => 5
%td{:style => highlight_new(unequal_attributes, :net_price)}= text_field 'article[]', 'net_price', :size => 5 %td{:style => highlight_new(unequal_attributes, :net_price)}= form.text_field 'net_price', :size => 5
%td{:style => highlight_new(unequal_attributes, :tax)}= text_field 'article[]', 'tax', :size => 4 %td{:style => highlight_new(unequal_attributes, :tax)}= form.text_field 'tax', :size => 4
%td{:style => highlight_new(unequal_attributes, :deposit)}= text_field 'article[]', 'deposit', :size => 4 %td{:style => highlight_new(unequal_attributes, :deposit)}= form.text_field 'deposit', :size => 4
%td= select 'article[]', 'article_category_id', ArticleCategory.find(:all).collect {|a| [ a.name, a.id ] }, { :include_blank => true } %td= select 'article[]', 'article_category_id', ArticleCategory.find(:all).collect {|a| [ a.name, a.id ] }, { :include_blank => true }
%hr/ %hr/
= hidden_field 'supplier', 'id' = hidden_field 'supplier', 'id'
= submit_tag 'Alle löschen/aktualisieren' = submit_tag 'Alle löschen/aktualisieren'
| |
= link_to 'Abbrechen', :action => 'list', :id => @supplier = link_to 'Abbrechen', supplier_articles_path(@supplier)

View file

@ -14,3 +14,5 @@
%br/ %br/
= link_to 'New delivery', new_supplier_delivery_path(@supplier) = link_to 'New delivery', new_supplier_delivery_path(@supplier)
|
= link_to "Lieferantenübersicht", suppliers_path

View file

@ -5,7 +5,10 @@
=h @delivery.supplier.name =h @delivery.supplier.name
%p %p
%b Delivered on: %b Delivered on:
=h @delivery.delivered_on = @delivery.delivered_on
%p
%b Rechnungsbetrag:
= link_to_invoice(@delivery)
%h2 Artikel %h2 Artikel
%table.list{:style => "width:30em"} %table.list{:style => "width:30em"}

View file

@ -0,0 +1,32 @@
- form_for([:finance, @invoice]) do |f|
= f.error_messages
= f.hidden_field :delivery_id
- if @invoice.delivery
%p= "Diese Rechnung ist mit einer #{link_to "Lieferung", [@invoice.supplier,@invoice.delivery]} verknüpft."
%p
= f.label :supplier_id
%br/
= f.select :supplier_id, Supplier.all.collect { |s| [s.name, s.id] }
%p
= f.label :number
%br/
= f.text_field :number
%p
= f.label :date
%br/
= f.date_select :date
%p
= f.label :paid_on
%br/
= f.date_select :paid_on, :include_blank => true
%p
= f.label :amount
%br/
= f.text_field :amount
%p
= f.label :note
%br/
= f.text_area :note
%p
= f.submit "Speichern"

View file

@ -1,36 +1,6 @@
<h1>Editing invoice</h1> <h1>Editing invoice</h1>
<% form_for([:finance, @invoice]) do |f| %> <%= render :partial => 'form' %>
<%= f.error_messages %>
<p>
<%= f.label :supplier_id %><br />
<%= f.select :supplier_id, Supplier.all.collect { |s| [s.name, s.id] } %>
</p>
<p>
<%= f.label :number %><br />
<%= f.text_field :number %>
</p>
<p>
<%= f.label :date %><br />
<%= f.date_select :date %>
</p>
<p>
<%= f.label :paid_on %><br />
<%= f.date_select :paid_on, :include_blank => true %>
</p>
<p>
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</p>
<p>
<%= f.label :note %><br />
<%= f.text_area :note %>
</p>
<p>
<%= f.submit "Update" %>
</p>
<% end %>
<%= link_to 'Show', [:finance, @invoice] %> | <%= link_to 'Show', [:finance, @invoice] %> |
<%= link_to 'Back', finance_invoices_path %> <%= link_to 'Back', finance_invoices_path %>

View file

@ -23,7 +23,7 @@
<td><%= invoice.date %></td> <td><%= invoice.date %></td>
<td><%= invoice.paid_on %></td> <td><%= invoice.paid_on %></td>
<td><%= invoice.amount %></td> <td><%= invoice.amount %></td>
<td><%=h invoice.delivery_id %></td> <td><%= link_to "Lieferung", [invoice.supplier,invoice.delivery] if invoice.delivery %></td>
<td><%=h truncate(invoice.note) %></td> <td><%=h truncate(invoice.note) %></td>
<td><%= link_to 'Show', finance_invoice_path(invoice) %></td> <td><%= link_to 'Show', finance_invoice_path(invoice) %></td>
<td><%= link_to 'Edit', edit_finance_invoice_path(invoice) %></td> <td><%= link_to 'Edit', edit_finance_invoice_path(invoice) %></td>

View file

@ -1,35 +1,4 @@
<h1>New invoice</h1> <% title "Neue Rechnung anlegen" -%>
<% form_for([:finance, @invoice]) do |f| %> <%= render :partial => 'form' %>
<%= f.error_messages %> <%= link_to 'Zurück', finance_invoices_path %>
<p>
<%= f.label :supplier_id %><br />
<%= f.select :supplier_id, Supplier.all.collect { |s| [s.name, s.id] } %>
</p>
<p>
<%= f.label :number %><br />
<%= f.text_field :number %>
</p>
<p>
<%= f.label :date %><br />
<%= f.date_select :date %>
</p>
<p>
<%= f.label :paid_on %><br />
<%= f.date_select :paid_on, :include_blank => true %>
</p>
<p>
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</p>
<p>
<%= f.label :note %><br />
<%= f.text_area :note %>
</p>
<p>
<%= f.submit "Create" %>
</p>
<% end %>
<%= link_to 'Back', finance_invoices_path %>

View file

@ -1,40 +0,0 @@
<% title "Show invoice #{@invoice.number}" %>
<p>
<b>Supplier:</b>
<%=h @invoice.supplier.name %>
</p>
<p>
<b>Delivery:</b>
<%=h @invoice.delivery_id %>
</p>
<p>
<b>Number:</b>
<%=h @invoice.number %>
</p>
<p>
<b>Date:</b>
<%=h @invoice.date %>
</p>
<p>
<b>Paid on:</b>
<%=h @invoice.paid_on %>
</p>
<p>
<b>Amount:</b>
<%=h @invoice.amount %>
</p>
<p>
<b>Note:</b>
<%=h @invoice.note %>
</p>
<%= link_to 'Edit', edit_finance_invoice_path(@invoice) %> |
<%= link_to 'Back', finance_invoices_path %>

View file

@ -0,0 +1,28 @@
- title "Rechnung #{@invoice.number}"
%p
%b Supplier:
=h @invoice.supplier.name
- if @invoice.delivery
%p
%b Delivery:
="Diese Rechnung ist mit einer #{link_to "Lieferung", [@invoice.supplier,@invoice.delivery]} verknüpft."
%p
%b Number:
=h @invoice.number
%p
%b Date:
=h @invoice.date
%p
%b Paid on:
=h @invoice.paid_on
%p
%b Amount:
=h @invoice.amount
%p
%b Note:
=h @invoice.note
= link_to 'Edit', edit_finance_invoice_path(@invoice)
|
= link_to 'Back', finance_invoices_path

View file

@ -23,12 +23,14 @@
{ :name => "Manage orders", :url => "/orders", :access? => (u.role_orders?) } { :name => "Manage orders", :url => "/orders", :access? => (u.role_orders?) }
] ]
}, },
{ :name => "Articles", :url => "/suppliers", :active => ["articles", "suppliers", "deliveries", "article_categories"], { :name => "Articles", :url => "/suppliers",
:active => ["articles", "suppliers", "deliveries", "article_categories", "stockit"],
:access? => (u.role_article_meta? || u.role_suppliers?), :access? => (u.role_article_meta? || u.role_suppliers?),
:subnav => [ :subnav => [
{ :name => "Show articles", :url => "/suppliers" }, { :name => "Artikel", :url => supplier_articles_path(Supplier.first) },
{ :name => "Categories", :url => "/suppliers" }, { :name => "Lager", :url => "/stockit" },
{ :name => "Suppliers", :url => suppliers_path, :access? => (u.role_suppliers?) } { :name => "Lieferantinnen", :url => suppliers_path, :access? => (u.role_suppliers?) },
{ :name => "Kategorien", :url => "/article_categories"}
] ]
}, },
{ :name => "Finance", :url => "/finance", { :name => "Finance", :url => "/finance",

View file

@ -1,17 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>ArticleCategories: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>

View file

@ -1,17 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Workgroups: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>

View file

@ -0,0 +1,27 @@
- title "Lagerübersicht"
%p
- form_tag do
Neue Lieferung anlegen für:
= select_tag :new_delivery, |
options_for_select([" -- Lieferantin wählen --", ""] + |
Supplier.find(:all).collect {|s| [ s.name, url_for(new_supplier_delivery_path(s))] }), |
:onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" |
%p
%table.list
%thead
%tr
%th Artikel
%th Menge
%th Einheit
%th Preis
%th Lieferant
%tbody
- for article in @articles
%tr{:class => cycle("even", "odd")}
%td=h article.name
%td= article.quantity
%td= article.unit
%td= article.net_price
%td= link_to article.supplier.name, article.supplier

View file

@ -28,7 +28,15 @@
.right_column{:style => "width:47%"} .right_column{:style => "width:47%"}
.box_title .box_title
%h2 Artikelkategorien %h2 Letzte Lieferungen
.column_content#categories .column_content
#category_form.box.edit_form{:style => "display:none;margin-bottom:1em;"} %table{:style => "width:50em"}
#category_list= render :partial => 'article_categories/list' %tr
%th Datum
%th Betrag
%th Lieferant
- for delivery in @deliveries
%tr
%td= link_to delivery.delivered_on, [delivery.supplier, delivery]
%td= link_to_invoice(delivery)
%td=h delivery.supplier.name

View file

@ -1,14 +1,14 @@
%h1 - title "Lieferantin #{h(@supplier.name)}"
Lieferantin
=h @supplier.name .left_column{:style => "width:45%"}
.box_title
%h2=h @supplier.name
.column_content
- if shared_supplier = @supplier.shared_supplier - if shared_supplier = @supplier.shared_supplier
%p %p
%strong Der Lieferant ist mit der externen ArtikleDatenbank verknüpft. %strong Der Lieferant ist mit der externen ArtikleDatenbank verknüpft.
%table{:style => "width:40em"} %table{:style => "width:40em"}
%tr
%td Name:
%td{:style => "font-weight:bold"}=h @supplier.name
%tr %tr
%td Adresse: %td Adresse:
%td{:style => "font-weight:bold"}=h @supplier.address %td{:style => "font-weight:bold"}=h @supplier.address
@ -52,3 +52,20 @@
= link_to 'Löschen', @supplier, :confirm => 'Bist Du sicher?', :method => :delete = link_to 'Löschen', @supplier, :confirm => 'Bist Du sicher?', :method => :delete
| |
= link_to 'zurück', suppliers_path = link_to 'zurück', suppliers_path
.right_column{:style => "width:45%"}
.box_title
%h2 Letzte Lieferungen
.column_content
%table
%tr
%th Datum
%th Betrag
- for delivery in @deliveries
%tr
%td= link_to delivery.delivered_on, [@supplier, delivery]
%td= link_to_invoice(delivery)
%p
= link_to "Neue Lieferung anlegen", new_supplier_delivery_path(@supplier)
|
= link_to "Zeige alle Lieferungen", supplier_deliveries_path(@supplier)

View file

@ -0,0 +1,8 @@
require 'test_helper'
class StockitControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end