2009-02-12 18:32:20 +01:00
|
|
|
class StockTakingsController < ApplicationController
|
2011-05-27 14:09:01 +02:00
|
|
|
inherit_resources
|
2009-02-12 18:32:20 +01:00
|
|
|
|
2012-10-29 18:28:17 +01:00
|
|
|
def index
|
|
|
|
@stock_takings = StockTaking.order('date DESC').page(params[:page]).per(@per_page)
|
|
|
|
end
|
|
|
|
|
2009-02-12 18:32:20 +01:00
|
|
|
def new
|
|
|
|
@stock_taking = StockTaking.new
|
2013-03-23 18:25:54 +01:00
|
|
|
StockArticle.undeleted.each { |a| @stock_taking.stock_changes.build(:stock_article => a) }
|
2009-02-12 18:32:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2011-05-27 14:09:01 +02:00
|
|
|
create!(:notice => "Inventur wurde erfolgreich angelegt.")
|
2009-02-12 18:32:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2011-05-27 14:09:01 +02:00
|
|
|
update!(:notice => "Inventur wurde aktualisiert.")
|
2009-02-12 18:32:20 +01:00
|
|
|
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 => 'stock_article_form', :locals => {:stock_article => stock_article}
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_stock_article
|
|
|
|
article = StockArticle.new(params[:stock_article])
|
|
|
|
render :update do |page|
|
|
|
|
if article.save
|
|
|
|
page.insert_html :top, 'stock_changes', :partial => 'stock_change',
|
|
|
|
:locals => {:stock_change => article.stock_changes.build}
|
|
|
|
|
|
|
|
page.replace_html 'new_stock_article', :partial => 'stock_article_form',
|
|
|
|
:locals => {:stock_article => StockArticle.new}
|
|
|
|
else
|
|
|
|
page.replace_html 'new_stock_article', :partial => 'stock_article_form',
|
|
|
|
:locals => {:stock_article => article}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def drop_stock_change
|
|
|
|
stock_change = StockChange.find(params[:stock_change_id])
|
|
|
|
stock_change.destroy
|
|
|
|
|
|
|
|
render :update do |page|
|
|
|
|
page.visual_effect :DropOut, "stock_change_#{stock_change.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|