From 86b2b28dc9e5e65897a2595155764b4ee5d94b7f Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Wed, 11 Feb 2009 18:09:04 +0100 Subject: [PATCH] Improved stockit: Creating/updating of stock_articles.\nTranslated deliveries and invoices. --- app/controllers/deliveries_controller.rb | 2 +- app/controllers/stockit_controller.rb | 58 +++++++++++++++- app/views/deliveries/edit.html.haml | 8 ++- app/views/deliveries/index.html.haml | 27 +++++--- app/views/finance/invoices/_form.html.haml | 18 ++--- app/views/finance/invoices/edit.html.erb | 6 +- app/views/finance/invoices/index.html.erb | 32 ++++----- app/views/finance/invoices/show.html.haml | 24 ++++--- app/views/stockit/_form.html.haml | 41 ++++++++++++ app/views/stockit/edit.html.haml | 3 + app/views/stockit/index.html.haml | 78 +++++++++++++--------- app/views/stockit/new.html.haml | 16 +++++ app/views/suppliers/index.haml | 8 ++- config/locales/de.yml | 1 + config/routes.rb | 2 + db/schema.rb | 2 +- public/stylesheets/main.css | 3 + public/stylesheets/print.css | 3 + public/stylesheets/sass/main.sass | 2 + 19 files changed, 248 insertions(+), 86 deletions(-) create mode 100644 app/views/stockit/_form.html.haml create mode 100644 app/views/stockit/edit.html.haml create mode 100644 app/views/stockit/new.html.haml diff --git a/app/controllers/deliveries_controller.rb b/app/controllers/deliveries_controller.rb index e0651236..9b3f752c 100644 --- a/app/controllers/deliveries_controller.rb +++ b/app/controllers/deliveries_controller.rb @@ -119,7 +119,7 @@ class DeliveriesController < ApplicationController def in_place_edit_for_stock_quantity stock_change = StockChange.find(params[:editorId]) - if stock_change.update_attribute(:quantity, params[:value]) + if stock_change.update_attributes(:quantity => params[:value]) render :inline => params[:value] else render :inline => "Ein Fehler ist aufgetreten." diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index 05a7bbaf..4f79bb60 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -1,6 +1,62 @@ class StockitController < ApplicationController + def index - @articles = StockArticle.all + @stock_articles = StockArticle.without_deleted( + :include => [:supplier, :article_category], + :order => 'suppliers.name, article_categories.name, articles.name' + ) end + def new + @supplier = Supplier.find(params[:supplier_id]) + @stock_article = @supplier.stock_articles.build(:tax => 7.0) + end + + def create + @stock_article = StockArticle.new(params[:stock_article]) + if @stock_article.save + redirect_to stock_articles_path + else + render :action => 'new' + end + end + + def edit + @stock_article = StockArticle.find(params[:id]) + end + + def update + @stock_article = StockArticle.find(params[:id]) + if @stock_article.update_attributes(params[:stock_article]) + redirect_to stock_articles_path + else + render :action => 'edit' + end + end + + def destroy + StockArticle.find(params[:id]).destroy + redirect_to stock_articles_path + rescue => error + flash[:error] = "Ein Fehler ist aufgetreten: " + error.message + redirect_to stock_articles_path + end + + def auto_complete_for_article_name + @supplier = Supplier.find(params[:supplier_id]) + @articles = @supplier.articles.without_deleted.find(:all, + :conditions => [ "LOWER(articles.name) LIKE ?", '%' + params[:article][:name].downcase + '%' ], + :limit => 8) + render :partial => 'shared/auto_complete_articles' + end + + def fill_new_stock_article_form + article = Article.find(params[:article_id]) + @supplier = article.supplier + stock_article = @supplier.stock_articles.build( + article.attributes.reject { |attr| attr == ('id' || 'type')} + ) + + render :partial => 'form', :locals => {:stock_article => stock_article} + end end diff --git a/app/views/deliveries/edit.html.haml b/app/views/deliveries/edit.html.haml index 4a15d1ac..7159de06 100644 --- a/app/views/deliveries/edit.html.haml +++ b/app/views/deliveries/edit.html.haml @@ -3,6 +3,9 @@ %p %b Lieferant: = @supplier.name +%p + %b Rechnungsbetrag: + = link_to_invoice(@delivery) - form_for([@supplier,@delivery]) do |f| = f.error_messages @@ -12,6 +15,7 @@ = f.date_select :delivered_on %h2 Artikel + %i Um die Mengen anzupassen einfach auf die Anzahl klicken. #stock_changes %table.list{:style => "width:40em"} %tr @@ -22,10 +26,10 @@ %tr[stock_change] %td= stock_change.stock_article.name %td - %span{:id => stock_change.id, :style => "width:5em"}= stock_change.quantity + %span.click-me{:id => stock_change.id, :style => "width:5em"}= stock_change.quantity = javascript_tag "new Ajax.InPlaceEditor('#{stock_change.id}', | '/deliveries/in_place_edit_for_stock_quantity', | - {size: 5, });" | + {size: 5});" | %td = link_to_remote "Artikel entfernen", | :url => drop_stock_change_supplier_delivery_path(@supplier, @delivery, :stock_change_id => stock_change), | diff --git a/app/views/deliveries/index.html.haml b/app/views/deliveries/index.html.haml index 53315f34..e8b615c3 100644 --- a/app/views/deliveries/index.html.haml +++ b/app/views/deliveries/index.html.haml @@ -1,18 +1,23 @@ - title "#{@supplier.name}/deliveries" -%table{:style => "width:50em"} - %tr - %th Delivered on - %th Invoice - - for delivery in @deliveries +%table.list{:style => "width:50em"} + %thead %tr - %td=h delivery.delivered_on - %td=h "invoice ..." - %td= link_to 'Show', [@supplier, delivery] - %td= link_to 'Edit', edit_supplier_delivery_path(@supplier,delivery) - %td= link_to 'Destroy', [@supplier,delivery], :confirm => 'Are you sure?', :method => :delete + %th Geliefert am + %th Rechnungsbetrag + %th + %th + %th + %tbody + - for delivery in @deliveries + %tr + %td=h delivery.delivered_on + %td= link_to_invoice(delivery) + %td= link_to 'Anzeigen', [@supplier, delivery] + %td= link_to 'Bearbeiten', edit_supplier_delivery_path(@supplier,delivery) + %td= link_to 'Löschen', [@supplier,delivery], :confirm => 'Are you sure?', :method => :delete %br/ -= link_to 'New delivery', new_supplier_delivery_path(@supplier) += link_to "Neue Lieferung für #{@supplier.name} anlegen", new_supplier_delivery_path(@supplier) | = link_to "Lieferantenübersicht", suppliers_path diff --git a/app/views/finance/invoices/_form.html.haml b/app/views/finance/invoices/_form.html.haml index 79957d34..d4a7ea5e 100644 --- a/app/views/finance/invoices/_form.html.haml +++ b/app/views/finance/invoices/_form.html.haml @@ -8,36 +8,36 @@ - if @invoice.order %p= "Diese Rechnung ist mit einer #{link_to "Bestellung", @invoice.order} verknüpft." %p - = f.label :supplier_id + Lieferant %br/ = f.select :supplier_id, Supplier.all.collect { |s| [s.name, s.id] } %p - = f.label :number + Rechnungsnummer %br/ = f.text_field :number %p - = f.label :date + Rechnungsdatum %br/ = f.date_select :date %p - = f.label :paid_on + Bezahlt am %br/ = f.date_select :paid_on, :include_blank => true %p - = f.label :amount + Rechnungsbetrag %br/ = f.text_field :amount %p - = f.label :deposit + Pfand berechnet %br/ = f.text_field :deposit %p - = f.label :deposit_credit + Pfand gutgeschrieben %br/ = f.text_field :deposit_credit %p - = f.label :note + Notiz %br/ - = f.text_area :note + = f.text_area :note, :size => "28x8" %p = f.submit "Speichern" diff --git a/app/views/finance/invoices/edit.html.erb b/app/views/finance/invoices/edit.html.erb index 151b221d..59d3a3ea 100644 --- a/app/views/finance/invoices/edit.html.erb +++ b/app/views/finance/invoices/edit.html.erb @@ -1,6 +1,6 @@ -

Editing invoice

+<% title "Rechnung bearbeiten" %> <%= render :partial => 'form' %> -<%= link_to 'Show', [:finance, @invoice] %> | -<%= link_to 'Back', finance_invoices_path %> +<%= link_to "Anzeigen", [:finance, @invoice] %> | +<%= link_to 'Zurück', finance_invoices_path %> diff --git a/app/views/finance/invoices/index.html.erb b/app/views/finance/invoices/index.html.erb index db3919f7..317f332a 100644 --- a/app/views/finance/invoices/index.html.erb +++ b/app/views/finance/invoices/index.html.erb @@ -1,33 +1,33 @@ -<% title "Invoices" %> +<% title "Rechnungen" %> - - - - - - + + + + + + + - <% for invoice in @invoices %> + - - - - + + + + - - - + + <% end %> @@ -35,4 +35,4 @@
-<%= link_to 'New invoice', new_finance_invoice_path %> +<%= link_to 'Neue Rechnung anlegen', new_finance_invoice_path %> diff --git a/app/views/finance/invoices/show.html.haml b/app/views/finance/invoices/show.html.haml index 2d274011..1afc4980 100644 --- a/app/views/finance/invoices/show.html.haml +++ b/app/views/finance/invoices/show.html.haml @@ -1,28 +1,34 @@ - title "Rechnung #{@invoice.number}" %p - %b Supplier: + %b Lieferant: =h @invoice.supplier.name - if @invoice.delivery %p - %b Delivery: + %b Lieferung: ="Diese Rechnung ist mit einer #{link_to "Lieferung", [@invoice.supplier,@invoice.delivery]} verknüpft." %p - %b Number: + %b Rechnungsnummer: =h @invoice.number %p - %b Date: + %b Datum: =h @invoice.date %p - %b Paid on: + %b Bezahlt am: =h @invoice.paid_on %p - %b Amount: + %b Rechnungsbetrag: =h @invoice.amount %p - %b Note: + %b Pfand berechnet: + =h @invoice.deposit +%p + %b Pfand gutgeschrieben: + =h @invoice.deposit_credit +%p + %b Notiz: =h @invoice.note -= link_to 'Edit', edit_finance_invoice_path(@invoice) += link_to "Bearbeiten", edit_finance_invoice_path(@invoice) | -= link_to 'Back', finance_invoices_path += link_to "Zurück", finance_invoices_path diff --git a/app/views/stockit/_form.html.haml b/app/views/stockit/_form.html.haml new file mode 100644 index 00000000..9d178c0b --- /dev/null +++ b/app/views/stockit/_form.html.haml @@ -0,0 +1,41 @@ +- form_for stock_article do |form| + = form.error_messages + = form.hidden_field :supplier_id + %p + Name + %br/ + = form.text_field :name + %p + Einheit + %br/ + = form.text_field :unit + %p + Notiz + %br/ + = form.text_field :note + - if stock_article.new_record? + %p + Nettopreis + %br/ + = form.text_field :price + %p + MwSt + %br/ + = form.text_field :tax, :value => (stock_article.tax || 7.0) + %p + Pfand + %br/ + = form.text_field :deposit + - else + %p + Preis: + %br/ + Um Chaos zu vermeiden können bis auf weiteres die Preise von angelegten + Lagerartikeln nicht mehr verändert werden. + %p + Kategorie: + = form.select :article_category_id, ArticleCategory.all(:order => 'name').collect { |c| [c.name, c.id] } + %p + = submit_tag "Lagerartikel speichern" + | + = link_to "Abbrechen", stock_articles_path \ No newline at end of file diff --git a/app/views/stockit/edit.html.haml b/app/views/stockit/edit.html.haml new file mode 100644 index 00000000..e27bebf3 --- /dev/null +++ b/app/views/stockit/edit.html.haml @@ -0,0 +1,3 @@ +- title "Lagerartikel bearbeiten" + += render :partial => 'form', :locals => {:stock_article => @stock_article} \ No newline at end of file diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index fd32cd20..7e5ab9a1 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -1,32 +1,50 @@ - title "Lagerübersicht" -%p - - form_tag do - Neue Lieferung anlegen für: - = select_tag :new_delivery, | - options_for_select([[" -- Lieferantin wählen --", ""]] + | - Supplier.without_deleted.collect {|s| [ s.name, url_for(new_supplier_delivery_path(s))] }), | - :onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" | -%p - = link_to "Lagerbestellung online stellen", new_order_path(:supplier_id => 0) -%p - %table.list - %thead - %tr - %th Artikel - %th im Lager - %th davon bestellt - %th Einheit - %th Preis - %th Lieferant - %th Kategorie - %tbody - - for article in @articles - %tr{:class => cycle("even", "odd")} - %td=h article.name - %td= article.quantity - %td= article.quantity - article.quantity_available - %td= article.unit - %td= article.price - %td= link_to article.supplier.name, article.supplier - %td= article.article_category.name +%div{:style => "padding:0 0 0.5em 0.7em;margin-bottom:2em"} + %span{:style => "float:left"} + - form_tag do + Neue Lieferung anlegen für: + = select_tag :new_delivery, | + options_for_select([[" -- Lieferantin wählen --", ""]] + | + Supplier.without_deleted.collect {|s| [ s.name, url_for(new_supplier_delivery_path(s))] }), | + :onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" | + +.single_column{:style => 'width:100%; clear:both'} + .box_title + .column_content + #actions + %b Neuen Lagerartikel anlegen für + = select_tag :new_stock_article, | + options_for_select([[" -- Lieferantin wählen --", ""]] + | + Supplier.without_deleted.collect {|s| [ s.name, url_for(new_stock_article_path(:supplier_id => s))] }), | + :onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" | + + | + = link_to_if @current_user.role_orders?, "Lagerbestellung online stellen", {:controller => 'orders', :action => 'new', :supplier_id => 0} + + #articles{:style => "clear:both;margin-top:1em"} + %table.list + %thead + %tr + %th Artikel + %th im Lager + %th davon bestellt + %th Einheit + %th Preis + %th Lieferant + %th Kategorie + %th + %tbody + - for article in @stock_articles + %tr{:class => cycle("even", "odd")} + %td=h article.name + %td= article.quantity + %td= article.quantity - article.quantity_available + %td= article.unit + %td= article.price + %td= link_to article.supplier.name, article.supplier + %td= article.article_category.name + %td + = link_to icon(:edit), edit_stock_article_path(article) + = link_to icon(:delete), article, :method => :delete, :confirm => "Bist Du sicher?" + diff --git a/app/views/stockit/new.html.haml b/app/views/stockit/new.html.haml new file mode 100644 index 00000000..4435d92a --- /dev/null +++ b/app/views/stockit/new.html.haml @@ -0,0 +1,16 @@ +- title "Neuen Lagerartikel für #{@supplier.name} anlegen" + +:javascript + function fillNewStockArticle(text, li) { + new Ajax.Updater('stock_article_form', '/stockit/fill_new_stock_article_form', { + parameters: {article_id: li.id} + }); + } + +%p + Suche nach Artikeln aus dem Katalog: + = text_field_with_auto_complete :article, :name, {}, | + {:url => {:action => 'auto_complete_for_article_name', :supplier_id => @supplier.id}, | + :after_update_element => 'fillNewStockArticle'} | +#stock_article_form + = render :partial => 'form', :locals => {:stock_article => @stock_article} \ No newline at end of file diff --git a/app/views/suppliers/index.haml b/app/views/suppliers/index.haml index 62c6bbfe..5e6ad7d2 100644 --- a/app/views/suppliers/index.haml +++ b/app/views/suppliers/index.haml @@ -17,14 +17,16 @@ %th Name %th Telefon %th KundenNr - %th + %th + %th %tbody - for supplier in @suppliers %tr{:class => cycle('even','odd', :name => 'suppliers')} - %td= link_to "#{h(supplier.name)} (#{supplier.articles.count})", supplier_articles_path(supplier) + %td= link_to h(supplier.name) , supplier %td=h supplier.phone %td=h supplier.customer_number - %td= link_to "Anzeigen", supplier + %td= link_to "Artikel (#{supplier.articles.count})", supplier_articles_path(supplier) + %td= link_to "Lieferungen", supplier_deliveries_path(supplier) .right_column{:style => "width:47%"} .box_title diff --git a/config/locales/de.yml b/config/locales/de.yml index c49a9ddd..d88b83dc 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -119,6 +119,7 @@ de: even: "muss gerade sein" models: article: Artikel + supplier: Lieferant user: Benutzerinnen workgroup: Arbeitsgruppe ordergroup: Bestellgruppe diff --git a/config/routes.rb b/config/routes.rb index eeb93e1d..8f1b4186 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,8 @@ ActionController::Routing::Routes.draw do |map| finance.resources :invoices end + map.resources :stock_articles, :controller => 'stockit', :as => 'stockit' + map.resources :suppliers, :collection => { :shared_suppliers => :get } do |suppliers| suppliers.resources :deliveries, :member => { :drop_stock_change => :post }, :collection => {:add_stock_article => :post} diff --git a/db/schema.rb b/db/schema.rb index 75648fb1..31ed8104 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20090119155930) do +ActiveRecord::Schema.define(:version => 20090120184410) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index edc031f5..e9c3183e 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -76,6 +76,9 @@ option { border-top: 1px solid #D7D7D7; margin: .2em 0; } +span.click-me { + cursor: pointer; } + #login { margin: auto; width: 27em; diff --git a/public/stylesheets/print.css b/public/stylesheets/print.css index 6e47ea14..b1fdb322 100644 --- a/public/stylesheets/print.css +++ b/public/stylesheets/print.css @@ -76,6 +76,9 @@ option { border-top: 1px solid #D7D7D7; margin: .2em 0; } +span.click-me { + cursor: pointer; } + #login { margin: auto; width: 27em; diff --git a/public/stylesheets/sass/main.sass b/public/stylesheets/sass/main.sass index 6ec34087..af001af7 100644 --- a/public/stylesheets/sass/main.sass +++ b/public/stylesheets/sass/main.sass @@ -86,6 +86,8 @@ option border-top: 1px solid #D7D7D7 margin: .2em 0 +span.click-me + cursor: pointer // ********************************* loginpage #login
SupplierNumberDatePaid onAmountDeliveryNummerLieferantDatumBezahlt amBetragLieferungBestellung Note
<%= link_to h(invoice.number), finance_invoice_path(invoice)%> <%=h invoice.supplier.name %><%=h invoice.number %><%= invoice.date %><%= invoice.paid_on %><%= invoice.amount %><%= format_date invoice.date %><%= format_date invoice.paid_on %><%= number_to_currency invoice.amount %> <%= link_to "Lieferung", [invoice.supplier,invoice.delivery] if invoice.delivery %><%= link_to format_date(invoice.order.ends), :controller => 'balancing', :action => 'new', :id => invoice.order if invoice.order %> <%=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 %><%= link_to icon(:edit), edit_finance_invoice_path(invoice) %><%= link_to icon(:delete), finance_invoice_path(invoice), :confirm => 'Are you sure?', :method => :delete %>