Refactored stockit, delivery an stock_takings.

This commit is contained in:
benni 2011-05-27 14:09:01 +02:00
parent d4715fef4b
commit fc1d130113
20 changed files with 145 additions and 296 deletions

View file

@ -92,11 +92,7 @@ class DeliveriesController < ApplicationController
end end
def add_stock_change def add_stock_change
render :layout => false
render :update do |page|
page.insert_html :bottom, 'stock_changes', :partial => 'stock_change',
:locals => {:stock_change => StockChange.new, :supplier => @supplier}
end
end end
def fill_new_stock_article_form def fill_new_stock_article_form

View file

@ -1,76 +1,17 @@
class StockTakingsController < ApplicationController class StockTakingsController < ApplicationController
inherit_resources
def index
@stock_takings = StockTaking.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @stock_takings }
end
end
def show
@stock_taking = StockTaking.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @stock_taking }
end
end
def new def new
@stock_taking = StockTaking.new @stock_taking = StockTaking.new
StockArticle.without_deleted.each { |a| @stock_taking.stock_changes.build(:stock_article => a) } StockArticle.all.each { |a| @stock_taking.stock_changes.build(:stock_article => a) }
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @stock_taking }
end
end
def edit
@stock_taking = StockTaking.find(params[:id])
end end
def create def create
@stock_taking = StockTaking.new(params[:stock_taking]) create!(:notice => "Inventur wurde erfolgreich angelegt.")
respond_to do |format|
if @stock_taking.save
flash[:notice] = 'StockTaking was successfully created.'
format.html { redirect_to(@stock_taking) }
format.xml { render :xml => @stock_taking, :status => :created, :location => @stock_taking }
else
format.html { render :action => "new" }
format.xml { render :xml => @stock_taking.errors, :status => :unprocessable_entity }
end
end
end end
def update def update
@stock_taking = StockTaking.find(params[:id]) update!(:notice => "Inventur wurde aktualisiert.")
respond_to do |format|
if @stock_taking.update_attributes(params[:stock_taking])
flash[:notice] = 'StockTaking was successfully updated.'
format.html { redirect_to(@stock_taking) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @stock_taking.errors, :status => :unprocessable_entity }
end
end
end
def destroy
@stock_taking = StockTaking.find(params[:id])
@stock_taking.destroy
respond_to do |format|
format.html { redirect_to(stock_takings_url) }
format.xml { head :ok }
end
end end
def fill_new_stock_article_form def fill_new_stock_article_form

View file

@ -1,10 +1,8 @@
class StockitController < ApplicationController class StockitController < ApplicationController
def index def index
@stock_articles = StockArticle.without_deleted.all( @stock_articles = StockArticle.joins(:supplier, :article_category).
:include => [:supplier, :article_category], order('suppliers.name, article_categories.name, articles.name')
:order => 'suppliers.name, article_categories.name, articles.name'
)
end end
def new def new
@ -14,8 +12,7 @@ class StockitController < ApplicationController
def create def create
@stock_article = StockArticle.new(params[:stock_article]) @stock_article = StockArticle.new(params[:stock_article])
if @stock_article.save if @stock_article.save
flash[:notice] = "Lagerartikel wurde gespeichert." redirect_to stock_articles_path, :notice => "Lagerartikel wurde gespeichert."
redirect_to stock_articles_path
else else
render :action => 'new' render :action => 'new'
end end
@ -28,8 +25,7 @@ class StockitController < ApplicationController
def update def update
@stock_article = StockArticle.find(params[:id]) @stock_article = StockArticle.find(params[:id])
if @stock_article.update_attributes(params[:stock_article]) if @stock_article.update_attributes(params[:stock_article])
flash[:notice] = "Lagerartikel wurde gespeichert." redirect_to stock_articles_path, :notice => "Lagerartikel wurde gespeichert."
redirect_to stock_articles_path
else else
render :action => 'edit' render :action => 'edit'
end end
@ -43,16 +39,10 @@ class StockitController < ApplicationController
redirect_to stock_articles_path redirect_to stock_articles_path
end end
def auto_complete_for_article_name #TODO: Fix this!!
conditions = [ "LOWER(articles.name) LIKE ?", '%' + params[:article][:name].downcase + '%' ] def articles_search
@articles = Article.not_in_stock.limit(8).where(:name.matches => params[:term])
if params[:supplier_id] render :json => @articles.map(&:name)
@supplier = Supplier.find(params[:supplier_id])
@articles = @supplier.articles.without_deleted.all(:conditions => conditions, :limit => 8)
else
@articles = Article.without_deleted.not_in_stock.all(:conditions => conditions, :limit => 8)
end
render :partial => 'shared/auto_complete_articles'
end end
def fill_new_stock_article_form def fill_new_stock_article_form

View file

@ -10,7 +10,7 @@ module DeliveriesHelper
end end
def stock_articles_for_select(supplier) def stock_articles_for_select(supplier)
supplier.stock_articles.without_deleted.collect {|a| ["#{a.name} (#{number_to_currency a.price}/#{a.unit})", a.id] } supplier.stock_articles.map {|a| ["#{a.name} (#{number_to_currency a.price}/#{a.unit})", a.id] }
end end
end end

View file

@ -1,4 +1,6 @@
class StockArticle < Article class StockArticle < Article
acts_as_paranoid
has_many :stock_changes has_many :stock_changes
scope :available, :conditions => "quantity > 0" scope :available, :conditions => "quantity > 0"

View file

@ -1,52 +1,49 @@
.left_column(style="width:55%") - content_for :head do
- form_for([@supplier,@delivery]) do |f| :javascript
$(function() {
$('.destroy_stock_change').live('click', function() {
$(this).prev('input').val('1').parent().hide();
return false;
});
$('.remove_new_stock_change').live('click', function() {
$(this).parent().remove();
return false;
})
});
.left_column(style="width:50%")
= simple_form_for [@supplier,@delivery], :validate => true do |f|
.box_title .box_title
%h2 Lieferung anlegen %h2 Lieferung anlegen
.column_content .column_content
= f.error_messages
= f.hidden_field :supplier_id = f.hidden_field :supplier_id
%b Lagerartikel des Lieferanten %b Lagerartikel des Lieferanten
#stock_changes #stock_changes
- f.fields_for :stock_changes do |stock_change_form| = f.fields_for :stock_changes do |stock_change_form|
%p %p
= stock_change_form.select :stock_article_id, stock_articles_for_select(@supplier) = stock_change_form.select :stock_article_id, stock_articles_for_select(@supplier)
Menge Menge
= stock_change_form.text_field :quantity, :size => 5, :autocomplete => 'off' = stock_change_form.text_field :quantity, :size => 5, :autocomplete => 'off'
= stock_change_form.hidden_field :_delete = stock_change_form.hidden_field :_destroy
= link_to_function "Artikel aus Lieferung entfernen", "$(this).previous('input').value = 1; $(this).up('p').hide();" = link_to "Artikel aus Lieferung entfernen", "#", :class => 'destroy_stock_change'
%p %p
= remote_link_to "Lagerartikel der Lieferung hinzufügen", :url => {:action => 'add_stock_change', :supplier_id => @supplier.id} = link_to "Lagerartikel der Lieferung hinzufügen", {:action => 'add_stock_change', :supplier_id => @supplier.id}, :remote => true
%hr/ %hr/
%p = f.input :delivered_on
%b= f.label :delivered_on, "Lieferdatum" = f.input :note, :input_html => {:size => '35x4'}
= f.date_select :delivered_on = f.submit
%p
%b= f.label :note, "Notiz"
%br/
= f.text_area :note, :size => "35x4"
%p
= f.submit "Lieferung speichern"
oder
= link_to "Abbrechen", supplier_deliveries_path(@supplier)
.right_column{:style => "width:35%;"} .right_column{:style => "width:45%;"}
.box_title .box_title
%h2 Neuen Lagerartikel anlegen %h2 Neuen Lagerartikel anlegen
.column_content .column_content
%p %p
:javascript //TODO: Fix this!!
function fillNewStockArticle(text, li) {
new Ajax.Updater('stock_article_form', '#{url_for(:controller => "deliveries", :action => "fill_new_stock_article_form")}', {
method: 'get',
parameters: {article_id: li.id}
});
}
Suche nach Artikeln aus dem Suche nach Artikeln aus dem
%i= @supplier.name %i= @supplier.name
Katalog: Katalog:
= text_field_with_auto_complete :article, :name, {}, | = text_field_tag 'article_name'
{:url => {:controller => 'stockit', :action => 'auto_complete_for_article_name', :supplier_id => @supplier.id}, |
:after_update_element => 'fillNewStockArticle', :method => :get} |
%hr/ %hr/
#stock_article_form #stock_article_form
= render :partial => 'stock_article_form', :locals => {:stock_article => @supplier.stock_articles.build} = render :partial => 'stock_article_form', :locals => {:stock_article => @supplier.stock_articles.build}

View file

@ -1,33 +1,11 @@
- remote_form_for stock_article, :url => add_stock_article_supplier_deliveries_path(@supplier) do |form| = simple_form_for stock_article, add_stock_article_supplier_deliveries_path(@supplier), :remote => true,
= form.error_messages :validate => true do |f|
= form.hidden_field :supplier_id = f.hidden_field :supplier_id
= f.input :name
%p = f.input :unit
Name = f.input :note
%br/ = f.input :price
= form.text_field :name = f.input :tax
%p = f.input :deposit
Einheit = f.association :article_category
%br/ = f.submit
= form.text_field :unit
%p
Notiz
%br/
= form.text_field :note
%p
Preis
%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
%p
Kategorie:
= form.select :article_category_id, ArticleCategory.all(:order => 'name').collect { |c| [c.name, c.id] }
%p
= submit_tag "Lagerartikel speichern"

View file

@ -1,6 +1,6 @@
%p %p
- fields_for "delivery[new_stock_changes][]", stock_change do |form| = fields_for "delivery[new_stock_changes][]", stock_change do |form|
= form.select :stock_article_id, stock_articles_for_select(supplier) = form.select :stock_article_id, stock_articles_for_select(supplier)
Menge Menge
= form.text_field :quantity, :size => 5, :autocomplete => 'off' = form.text_field :quantity, :size => 5, :autocomplete => 'off'
= link_to_function "Artikel aus Lieferung entfernen", "$(this).up('p').remove()" = link_to "Artikel aus Lieferung entfernen", "#", :class => 'remove_new_stock_change'

View file

@ -0,0 +1 @@
$('#stock_changes').append('<%= escape_javascript(render(:partial => 'stock_change', :locals => {:stock_change => StockChange.new, :supplier => @supplier})) %>');

View file

@ -1,35 +1,10 @@
- remote_form_for stock_article, :url => add_stock_article_stock_takings_path do |form| - simple_form_for stock_article, add_stock_article_stock_takings_path, :remote => true do |f|
= form.error_messages = f.association :supplier
%p = f.input :name
Lieferantin = f.input :unit
%br/ = f.input :note
= form.select :supplier_id, Supplier.without_deleted(:order => 'name').collect{ |s| [s.name, s.id] } = f.input :price
%p = f.input :tax
Name = f.input :deposit
%br/ = f.association :article_category
= form.text_field :name = f.submit
%p
Einheit
%br/
= form.text_field :unit
%p
Notiz
%br/
= form.text_field :note
%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
%p
Kategorie:
= form.select :article_category_id, ArticleCategory.all(:order => 'name').collect { |c| [c.name, c.id] }
%p
= submit_tag "Lagerartikel hinzufügen"

View file

@ -1,9 +1,7 @@
%p %p
- fields_for "stock_taking[stock_change_attributes][]", stock_change do |form| = simple_fields_for "stock_taking[stock_change_attributes][]", stock_change do |form|
- article = stock_change.stock_article
= form.hidden_field :stock_article_id = form.hidden_field :stock_article_id
= "Menge (#{article.quantity_available})" = "Menge (#{stock_change.stock_article.quantity_available})"
= form.text_field :quantity, :size => 5, :autocomplete => 'off' = form.text_field :quantity, :size => 5, :autocomplete => 'off'
%b=h truncate(article.name) %b=h truncate(stock_change.stock_article.name)
= "(#{number_to_currency(article.price)} / #{article.unit})" = "(#{number_to_currency(stock_change.stock_article.price)} / #{stock_change.stock_article.unit})"

View file

@ -1,16 +1,7 @@
- title "Inventur bearbeiten" - title "Inventur bearbeiten"
- form_for(@stock_taking) do |f| - simple_form_for(@stock_taking) do |f|
= f.error_messages = f.input :date
%p = f.input :note
%b Datum = f.submit
%br/ = link_to "oder abbrechen", stock_takings_path
= f.date_select :date
%p
%b Notiz
%br/
= f.text_area :note, :size => "28x7"
%p
= f.submit "Invenur speichern"
|
= link_to "Abbrechen", stock_takings_path

View file

@ -1,7 +1,7 @@
- title "Inventurübersicht" - title "Inventurübersicht"
%p %p
= link_to "Neue Iniventur anlegen", new_stock_taking_path = link_to "Neue Inventur anlegen", new_stock_taking_path
| |
= link_to "Lager", stock_articles_path = link_to "Lager", stock_articles_path
@ -17,7 +17,7 @@
- for stock_taking in @stock_takings - for stock_taking in @stock_takings
%tr %tr
%td= link_to format_date(stock_taking.date), stock_taking %td= link_to format_date(stock_taking.date), stock_taking
%td=h truncate stock_taking.note %td= truncate stock_taking.note
%td= link_to 'Anzeigen', stock_taking %td= link_to 'Anzeigen', stock_taking
%td= link_to 'Bearbeiten', edit_stock_taking_path(stock_taking) %td= link_to 'Bearbeiten', edit_stock_taking_path(stock_taking)
%td= link_to 'Löschen', stock_taking, :confirm => 'Are you sure?', :method => :delete %td= link_to 'Löschen', stock_taking, :confirm => 'Are you sure?', :method => :delete

View file

@ -1,19 +1,12 @@
- title "Neue Inventur anlegen" - title "Neue Inventur anlegen"
.left_column{:style => "width:40em;"} .left_column{:style => "width:50%;"}
- form_for(@stock_taking) do |f| = simple_form_for(@stock_taking) do |f|
.box_title .box_title
%h2 Inventur anlegen %h2 Inventur anlegen
.column_content .column_content
= f.error_messages = f.input :date
%p = f.input :note, :input_html => {:size => "28x7", :value => "#{@current_user.nick}: ..."}
%b Datum
%br/
= f.date_select :date
%p
%b Notiz
%br/
= f.text_area :note, :size => "28x7", :value => "#{@current_user.nick}: ..."
%h2 Lagerartikel %h2 Lagerartikel
%p %p
%i %i
@ -22,27 +15,17 @@
ein. Bei Schwund benutze einfach ein Minus vor der Zahl. ein. Bei Schwund benutze einfach ein Minus vor der Zahl.
#stock_changes #stock_changes
= render :partial => 'stock_change', :collection => @stock_taking.stock_changes = render :partial => 'stock_change', :collection => @stock_taking.stock_changes
%p = f.submit
= f.submit "Inventur anlegen" = link_to "oder abbrechen", stock_takings_path
|
= link_to "Abbrechen", stock_takings_path
.right_column{:style => "width:30em;"} .right_column{:style => "width:45%;"}
.box_title .box_title
%h2 Neuen Lagerartikel anlegen %h2 Neuen Lagerartikel anlegen
.column_content .column_content
%p %p
:javascript // FIx this!
function fillNewStockArticle(text, li) {
new Ajax.Updater('stock_article_form', '/stock_takings/fill_new_stock_article_form', {
method: 'get',
parameters: {article_id: li.id}
});
}
Suche nach Artikeln aus dem allen Katalogen: Suche nach Artikeln aus dem allen Katalogen:
= text_field_with_auto_complete :article, :name, {}, | = text_field_tag :article_name
{:url => {:controller => 'stockit', :action => 'auto_complete_for_article_name' }, |
:after_update_element => 'fillNewStockArticle', :method => :get} |
%hr/ %hr/
#stock_article_form #stock_article_form
= render :partial => 'stock_article_form', :locals => {:stock_article => StockArticle.new} = render :partial => 'stock_article_form', :locals => {:stock_article => StockArticle.new}

View file

@ -1,44 +1,16 @@
- form_for stock_article do |form| - simple_form_for stock_article, :validate => true do |f|
= form.error_messages = f.association :supplier
%p = f.input :name
Lieferantin = f.input :unit
%br/ = f.input :note
= form.select :supplier_id, Supplier.without_deleted(:order => 'name').collect{ |s| [s.name, s.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? - if stock_article.new_record?
%p = f.input :price
Nettopreis = f.input :tax
%br/ = f.input :deposit
= 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 - else
%p = f.input :price, :input_html => {:disabled => 'disabled'},
Preis: :hint => "Um Chaos zu vermeiden können bis auf weiteres die Preise von angelegten Lagerartikeln nicht mehr verändert werden."
%br/ = f.association :article_category
Um Chaos zu vermeiden können bis auf weiteres die Preise von angelegten = f.submit
Lagerartikeln nicht mehr verändert werden. = link_to "oder abbrechen", stock_articles_path
%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

View file

@ -1,23 +1,26 @@
- title "Lagerübersicht: #{StockArticle.available.count} Artikel im Lager" - title "Lagerübersicht: #{StockArticle.available.count} Artikel im Lager"
- content_for :head do
:javascript
$(function() {
$('tr.unavailable').hide();
})
.menu .menu
- form_tag do - form_tag do
%ul %ul
%li %li
Ansichtsoptionen Ansichtsoptionen
%ul %ul
%li= link_to_function "Nicht verfügbare Artikel zeigen/verstecken", | %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable',
"$$('tr.unavailable').invoke('toggleClassName', 'hidden');", :style => "width:15em" | :style => "width:15em"
%div{:style => "padding:0 0 0.5em 0.7em;margin-bottom:2em"} %div{:style => "padding:0 0 0.5em 0.7em;margin-bottom:2em"}
%span{:style => "float:left"} %span{:style => "float:left"}
- form_tag do - form_tag do
Neue Lieferung anlegen für: Neue Lieferung anlegen für:
= select_tag :new_delivery, | = select_tag :new_delivery,
options_for_select([[" -- Lieferantin wählen --", ""]] + | options_for_select([[" -- Lieferantin wählen --", ""]] + Supplier.all.map {|s| [ s.name, new_supplier_delivery_url(s)]}),
Supplier.without_deleted.collect {|s| [ s.name, url_for(new_supplier_delivery_path(s))] }), | 'data-redirect-to' => true, :style => "font-size: 0.9em;margin-left:1em;"
:onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" |
.single_column{:style => 'width:100%; clear:both'} .single_column{:style => 'width:100%; clear:both'}
.box_title .box_title
@ -48,7 +51,7 @@
%tbody %tbody
- for article in @stock_articles - for article in @stock_articles
- class_name = cycle :even, :odd - class_name = cycle :even, :odd
- class_name += " unavailable hidden" if article.quantity_available <= 0 - class_name += " unavailable" if article.quantity_available <= 0
- class_name += " supplier_#{article.supplier.id}" - class_name += " supplier_#{article.supplier.id}"
%tr{:class => class_name} %tr{:class => class_name}
%td=h article.name %td=h article.name

View file

@ -1,16 +1,20 @@
- title "Neuen Lagerartikel anlegen" - title "Neuen Lagerartikel anlegen"
:javascript - content_for :head do
function fillNewStockArticle(text, li) { :javascript
new Ajax.Updater('stock_article_form', '/stockit/fill_new_stock_article_form', { $(function() {
parameters: {article_id: li.id} $('#article_search').autocomplete({
}); source: '#{articles_search_stock_articles_path}',
select: function(e, ui) {
alert(ui.item.value);
//location.href = '#{nil}' + ui.item.value;
} }
});
})
%p %p
Suche nach Artikeln aus allen Katalogen: Suche nach Artikeln aus allen Katalogen:
= text_field_with_auto_complete :article, :name, {}, | = text_field_tag 'article_search'
{:url => {:action => 'auto_complete_for_article_name'}, |
:after_update_element => 'fillNewStockArticle'} |
#stock_article_form #stock_article_form
= render :partial => 'form', :locals => {:stock_article => @stock_article} = render :partial => 'form', :locals => {:stock_article => @stock_article}

View file

@ -160,6 +160,9 @@ de:
task: Aufgabe task: Aufgabe
message: Nachricht message: Nachricht
article_category: Artikelkategorie article_category: Artikelkategorie
stock_article: Lagerartikel
delivery: Lieferung
stock_taking: Inventur
attributes: attributes:
article: article:
price: Nettopreis price: Nettopreis
@ -210,6 +213,8 @@ de:
description: 'Beschreibung' description: 'Beschreibung'
title: 'Titel' title: 'Titel'
email: 'E-Mail' email: 'E-Mail'
note: 'Notiz'
date: 'Datum'
workgroup: workgroup:
weekly_task: 'Monatlichen Job definieren?' weekly_task: 'Monatlichen Job definieren?'
weekday: 'Wochentag' weekday: 'Wochentag'
@ -257,7 +262,12 @@ de:
order_number: 'Bestellnummer' order_number: 'Bestellnummer'
tax: 'MwSt' tax: 'MwSt'
deposit: 'Pfand' deposit: 'Pfand'
stock_article:
supplier: 'Lieferant'
delivery:
delivered_on: 'Lieferdatum'
hints: hints:
tax: 'In Prozent, Standard sind 7,0'
task: task:
duration: 'Wie lange dauert die Aufgabe, 1-3 Stunden' duration: 'Wie lange dauert die Aufgabe, 1-3 Stunden'
required_users: 'Wieviel Benutzerinnen werden insgesamt benötigt?' required_users: 'Wieviel Benutzerinnen werden insgesamt benötigt?'
@ -265,3 +275,5 @@ de:
min_order_quantity: 'Die Mindestbestellmenge wird während der Bestellung angezeigt und soll motivieren' min_order_quantity: 'Die Mindestbestellmenge wird während der Bestellung angezeigt und soll motivieren'
article: article:
unit: 'z.B. KG oder 1L oder 500g' unit: 'z.B. KG oder 1L oder 500g'
stock_article:
supplier: ''

View file

@ -77,7 +77,7 @@ Foodsoft::Application.routes.draw do
resources :stock_articles, :to => 'stockit' do resources :stock_articles, :to => 'stockit' do
collection do collection do
get :auto_complete_for_article_name get :articles_search
get :fill_new_stock_article_form get :fill_new_stock_article_form
end end
end end

View file

@ -7,6 +7,12 @@ $(function() {
return false; return false;
}); });
// Remove this item from DOM
$('a[data-remove-this').click(function() {
$($(this).data('remove-this')).remove();
return false;
});
// Check/Uncheck a single checkbox // Check/Uncheck a single checkbox
$('[data-check-this]').live('click', function() { $('[data-check-this]').live('click', function() {
var checkbox = $($(this).data('check-this')); var checkbox = $($(this).data('check-this'));