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 class StockitController < ApplicationController
def index 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 @stock_article_selection = StockArticleSelection.new
end end

View file

@ -2,7 +2,7 @@
class StockitSelectionsController < ApplicationController class StockitSelectionsController < ApplicationController
def index def index
@stock_article_selections = StockArticleSelection.find(:all, :order => 'created_at DESC') @stock_article_selections = StockArticleSelection.all
end end
def show def show
@ -14,48 +14,43 @@ class StockitSelectionsController < ApplicationController
@stock_article_selection.created_by = current_user @stock_article_selection.created_by = current_user
if @stock_article_selection.save 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 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' render 'stockit/index'
end end
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 = StockArticleSelection.find(params[:id])
stock_article_selection.destroy 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 end
def articles # destroy articles def articles # destroy articles, finish selection
stock_article_selection = StockArticleSelection.find(params[:id]) stock_article_selection = StockArticleSelection.find(params[:id])
destroyed_articles_count = 0 destroyed_articles_count = 0
failed_articles_count = 0 failed_articles_count = 0
stock_article_selection.stock_articles.each do |article| stock_article_selection.stock_articles.each do |article|
begin begin
article.destroy article.destroy # article.delete would save some effort, but validations are important
destroyed_articles_count += 1 destroyed_articles_count += 1
rescue => error # recover if article.destroy fails and continue with next article rescue => error # recover if article.destroy fails and continue with next article
failed_articles_count += 1 failed_articles_count += 1
end end
end end
if destroyed_articles_count > 0 if destroyed_articles_count>0 # note that 1 successful article.destroy is enough to destroy selection
flash[:notice] = "#{destroyed_articles_count} gewählte Artikel gelöscht." 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 flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count
else else
flash[:error] = 'Löschvorgang fehlgeschlagen. Keine Artikel gelöscht.' flash[:error] = "Löschvorgang fehlgeschlagen. Es wurden keine Artikel gelöscht."
end end
redirect_to stock_articles_path redirect_to stock_articles_path
end 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 end

View file

@ -1,18 +1,2 @@
# encoding: utf-8
module StockArticleSelectionsHelper 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 end

View file

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

View file

@ -13,18 +13,6 @@ class StockArticleSelection < ActiveRecord::Base
all_articles = stock_article_ids all_articles = stock_article_ids
end 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 protected
def include_stock_articles def include_stock_articles

View file

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

View file

@ -2,22 +2,15 @@
%table.table.table-hover %table.table.table-hover
%tr %tr
%th Artikel %th Artikel
%th Zusammenfassung
%th Erstellt am %th Erstellt am
%th Erstellt von %th Erstellt von
%th Optionen %th Optionen
- stock_article_selections.each do |stock_article_selection| - stock_article_selections.each do |stock_article_selection|
%tr %tr
%td %td=h truncate stock_article_selection.stock_articles.map{ |article| article.name}.join(', ')
- for article in stock_article_selection.stock_articles.with_deleted %td=h stock_article_selection.created_at
%span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name %td=h link_to_user_message_if_valid stock_article_selection.created_by
%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 %td
= link_to 'Anzeigen', stock_article_selection, class: 'btn btn-small' = 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, = 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" - title "Löschvorschläge für Lagerartikel"
- if @stock_article_selections.empty?
.well.well-small %p Es gibt keine ausstehenden Löschvorschläge.
.btn-toolbar %ul
.btn-group %li= link_to "Löschvorschlag erstellen", stock_articles_path
= 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
%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 - 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" - 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 %dl
%dt Löschvorschlag vom: %dt Löschvorschlag vom:
%dd= format_time(@stock_article_selection.created_at) %dd=h @stock_article_selection.created_at
%dt Erstellt durch: %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 %dt Zu löschende Artikel
- for article in @stock_article_selection.stock_articles.with_deleted - for article in @stock_article_selection.stock_articles
%dd %dd=h article.name
%span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name
%p %p
@ -22,4 +15,4 @@
:confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-danger' :confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-danger'
= link_to 'Verwerfen', @stock_article_selection, :method => :delete, = link_to 'Verwerfen', @stock_article_selection, :method => :delete,
:confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn' :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 member do
delete 'articles' delete 'articles'
end end
collection do
delete 'finished'
end
end end