This commit is contained in:
Julius 2013-02-25 10:13:44 +01:00
parent ccf0d010b4
commit 8f15cfb446
10 changed files with 30 additions and 104 deletions

View file

@ -1,7 +1,8 @@
class StockitController < ApplicationController
def index
@stock_articles = StockArticle.elements_for_index
@stock_articles = StockArticle.includes(:supplier, :article_category).
order('suppliers.name, article_categories.name, articles.name')
@stock_article_selection = StockArticleSelection.new
end

View file

@ -2,7 +2,7 @@
class StockitSelectionsController < ApplicationController
def index
@stock_article_selections = StockArticleSelection.find(:all, :order => 'created_at DESC')
@stock_article_selections = StockArticleSelection.all
end
def show
@ -14,48 +14,43 @@ class StockitSelectionsController < ApplicationController
@stock_article_selection.created_by = current_user
if @stock_article_selection.save
redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel erstellt.')
redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel wurde erstellt.')
else
@stock_articles = StockArticle.elements_for_index
@stock_articles = StockArticle.includes(:supplier, :article_category).
order('suppliers.name, article_categories.name, articles.name')
render 'stockit/index'
end
end
def destroy # destroy selection without deleting articles
def destroy # destroy (open or finished) selection without deleting articles
stock_article_selection = StockArticleSelection.find(params[:id])
stock_article_selection.destroy
redirect_to stock_article_selections_path, :notice => 'Löschvorschlag verworfen.'
redirect_to stock_article_selections_path, :notice => 'Löschvorschlag wurde verworfen.'
end
def articles # destroy articles
def articles # destroy articles, finish selection
stock_article_selection = StockArticleSelection.find(params[:id])
destroyed_articles_count = 0
failed_articles_count = 0
stock_article_selection.stock_articles.each do |article|
begin
article.destroy
article.destroy # article.delete would save some effort, but validations are important
destroyed_articles_count += 1
rescue => error # recover if article.destroy fails and continue with next article
failed_articles_count += 1
end
end
if destroyed_articles_count > 0
flash[:notice] = "#{destroyed_articles_count} gewählte Artikel gelöscht."
if destroyed_articles_count>0 # note that 1 successful article.destroy is enough to destroy selection
stock_article_selection.destroy
flash[:notice] = "#{destroyed_articles_count} gewählte Artikel sind nun gelöscht."
flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count
else
flash[:error] = 'Löschvorgang fehlgeschlagen. Keine Artikel gelöscht.'
flash[:error] = "Löschvorgang fehlgeschlagen. Es wurden keine Artikel gelöscht."
end
redirect_to stock_articles_path
end
def finished # delete all finished selections
finished_selections = StockArticleSelection.all.select { |sel| sel.deletable_count + sel.nondeletable_count <= 0 }
finished_selections.each { |sel| sel.destroy }
redirect_to stock_article_selections_path, :notice => 'Alle erledigten Löschvorschläge entfernt.'
end
end

View file

@ -1,18 +1,2 @@
# encoding: utf-8
module StockArticleSelectionsHelper
def article_deletion_classes(article)
className = "label label-success" # usual deletable case, maybe modified below
className = "label label-important" if article.quantity_available > 0
className = "label" if article.deleted?
className
end
def article_deletion_title(article)
myTitle = "Löschbar" # usual deletable case, maybe modified below
myTitle = "Nicht löschbar, da im Lager vorhanden" if article.quantity_available > 0
myTitle = "Bereits gelöscht" if article.deleted?
myTitle
end
end

View file

@ -23,11 +23,6 @@ class StockArticle < Article
available.collect { |a| a.quantity * a.gross_price }.sum
end
def self.elements_for_index
StockArticle.includes(:supplier, :article_category).
order('suppliers.name, article_categories.name, articles.name')
end
protected
def check_quantity

View file

@ -13,18 +13,6 @@ class StockArticleSelection < ActiveRecord::Base
all_articles = stock_article_ids
end
def deletable_count
stock_articles.select { |a| a.quantity_available<=0 }.length
end
def nondeletable_count
stock_articles.select { |a| a.quantity_available>0 }.length
end
def deleted_count
stock_articles.only_deleted.count
end
protected
def include_stock_articles

View file

@ -2,7 +2,7 @@
- content_for :javascript do
:javascript
$(function() {
$('tr.unavailable,input.unavailable,div.unavailable').hide();
$('tr.unavailable,input.unavailable').hide();
})
.well.well-small
@ -12,7 +12,7 @@
Ansichtsoptionen
%span.caret
%ul.dropdown-menu
%li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable,div.unavailable', tabindex: -1
%li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable', tabindex: -1
.btn-group
= link_to_if @current_user.role_orders?, "Lagerbestellung online stellen", new_order_path(supplier_id: 0),
@ -65,8 +65,7 @@
%td
= link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini'
= link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", class: 'btn btn-mini btn-danger', :remote => true
.form-actions.unavailable
= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' }
%p= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' }
%p
Aktueller Lagerwert:
= number_to_currency StockArticle.stock_value

View file

@ -2,22 +2,15 @@
%table.table.table-hover
%tr
%th Artikel
%th Zusammenfassung
%th Erstellt am
%th Erstellt von
%th Optionen
- stock_article_selections.each do |stock_article_selection|
%tr
%td
- for article in stock_article_selection.stock_articles.with_deleted
%span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name
%td
%span{:class => 'label label-success'}= "#{stock_article_selection.deletable_count} Löschbar"
%span{:class => 'label'}= "#{stock_article_selection.deleted_count} Gelöscht"
%span{:class => 'label label-important'}= "#{stock_article_selection.nondeletable_count} Nicht löschbar"
%td= format_date(stock_article_selection.created_at)
%td= link_to_user_message_if_valid stock_article_selection.created_by
%td=h truncate stock_article_selection.stock_articles.map{ |article| article.name}.join(', ')
%td=h stock_article_selection.created_at
%td=h link_to_user_message_if_valid stock_article_selection.created_by
%td
= link_to 'Anzeigen', stock_article_selection, class: 'btn btn-small'
= link_to "Artikel löschen", articles_stock_article_selection_path(stock_article_selection), :method => :delete,

View file

@ -1,25 +1,7 @@
- title "Löschvorschläge für Lagerartikel"
.well.well-small
.btn-toolbar
.btn-group
= link_to "Lager anzeigen", stock_articles_path, class: 'btn'
= link_to "Aufräumen", finished_stock_article_selections_path, :method => 'delete',
:confirm => 'Wirklich alle erledigten Löschvorschläge entfernen?', class: 'btn'
.well
%h2 Ausstehende Löschvorschläge
- open_selections = @stock_article_selections.select { |sel| sel.deletable_count + sel.nondeletable_count > 0 }
- if open_selections.length == 0
- if @stock_article_selections.empty?
%p Es gibt keine ausstehenden Löschvorschläge.
%ul
%li= link_to "Löschvorschlag erstellen", stock_articles_path
- else
= render :partial => 'overview', :locals => {:stock_article_selections => open_selections}
%h2 Erledigte Löschvorschläge
- finished_selections = @stock_article_selections.select { |sel| sel.deletable_count + sel.nondeletable_count <= 0 }
- if finished_selections.length == 0
%p Es gibt keine erledigten Löschvorschläge.
- else
= render :partial => 'overview', :locals => {:stock_article_selections => finished_selections}
= render :partial => 'overview', :locals => {:stock_article_selections => @stock_article_selections}

View file

@ -1,20 +1,13 @@
- title "Löschvorschlag für #{@stock_article_selection.stock_articles.count} Lagerartikel"
.well.well-small
.btn-toolbar
.btn-group
= link_to "Lager anzeigen", stock_articles_path, class: 'btn'
= link_to 'Alle Löschvorschläge anzeigen', stock_article_selections_path, class: 'btn'
%dl
%dt Löschvorschlag vom:
%dd= format_time(@stock_article_selection.created_at)
%dd=h @stock_article_selection.created_at
%dt Erstellt durch:
%dd= link_to_user_message_if_valid(@stock_article_selection.created_by)
%dd=h link_to_user_message_if_valid(@stock_article_selection.created_by)
%dt Zu löschende Artikel
- for article in @stock_article_selection.stock_articles.with_deleted
%dd
%span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name
- for article in @stock_article_selection.stock_articles
%dd=h article.name
%p
@ -22,4 +15,4 @@
:confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-danger'
= link_to 'Verwerfen', @stock_article_selection, :method => :delete,
:confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn'
= link_to 'Alle Löschvorschläge anzeigen', stock_article_selections_path, class: 'btn'
= link_to 'Alle Löschvorschläge zeigen', stock_article_selections_path, class: 'btn'

View file

@ -95,10 +95,6 @@ Foodsoft::Application.routes.draw do
member do
delete 'articles'
end
collection do
delete 'finished'
end
end