Improve stock_article_selections
This commit is contained in:
parent
524819b86f
commit
396a47b6af
10 changed files with 104 additions and 30 deletions
|
@ -1,8 +1,7 @@
|
|||
class StockitController < ApplicationController
|
||||
|
||||
def index
|
||||
@stock_articles = StockArticle.includes(:supplier, :article_category).
|
||||
order('suppliers.name, article_categories.name, articles.name')
|
||||
@stock_articles = StockArticle.elements_for_index
|
||||
@stock_article_selection = StockArticleSelection.new
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
class StockitSelectionsController < ApplicationController
|
||||
|
||||
def index
|
||||
@stock_article_selections = StockArticleSelection.all
|
||||
@stock_article_selections = StockArticleSelection.find(:all, :order => 'created_at DESC')
|
||||
end
|
||||
|
||||
def show
|
||||
|
@ -14,43 +14,48 @@ 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 wurde erstellt.')
|
||||
redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel erstellt.')
|
||||
else
|
||||
@stock_articles = StockArticle.includes(:supplier, :article_category).
|
||||
order('suppliers.name, article_categories.name, articles.name')
|
||||
@stock_articles = StockArticle.elements_for_index
|
||||
render 'stockit/index'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy # destroy (open or finished) selection without deleting articles
|
||||
def destroy # destroy selection without deleting articles
|
||||
stock_article_selection = StockArticleSelection.find(params[:id])
|
||||
stock_article_selection.destroy
|
||||
|
||||
redirect_to stock_article_selections_path, :notice => 'Löschvorschlag wurde verworfen.'
|
||||
redirect_to stock_article_selections_path, :notice => 'Löschvorschlag verworfen.'
|
||||
end
|
||||
|
||||
def articles # destroy articles, finish selection
|
||||
def articles # destroy articles
|
||||
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.delete would save some effort, but validations are important
|
||||
article.destroy
|
||||
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 # 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."
|
||||
if destroyed_articles_count > 0
|
||||
flash[:notice] = "#{destroyed_articles_count} gewählte Artikel gelöscht."
|
||||
flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count
|
||||
else
|
||||
flash[:error] = "Löschvorgang fehlgeschlagen. Es wurden keine Artikel gelöscht."
|
||||
flash[:error] = 'Löschvorgang fehlgeschlagen. 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
|
||||
|
|
|
@ -1,2 +1,18 @@
|
|||
# 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
|
||||
|
|
|
@ -23,6 +23,11 @@ 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
|
||||
|
|
|
@ -13,6 +13,18 @@ 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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
- content_for :javascript do
|
||||
:javascript
|
||||
$(function() {
|
||||
$('tr.unavailable,input.unavailable').hide();
|
||||
$('tr.unavailable,input.unavailable,div.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', tabindex: -1
|
||||
%li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable,div.unavailable', tabindex: -1
|
||||
|
||||
.btn-group
|
||||
= link_to_if @current_user.role_orders?, "Lagerbestellung online stellen", new_order_path(supplier_id: 0),
|
||||
|
@ -66,7 +66,8 @@
|
|||
= 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'
|
||||
%p= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' }
|
||||
.form-actions.unavailable
|
||||
= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' }
|
||||
%p
|
||||
Aktueller Lagerwert:
|
||||
= number_to_currency StockArticle.stock_value
|
||||
|
|
|
@ -2,15 +2,22 @@
|
|||
%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=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
|
||||
- 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
|
||||
= 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,
|
||||
|
|
|
@ -1,7 +1,25 @@
|
|||
- title "Löschvorschläge für Lagerartikel"
|
||||
- if @stock_article_selections.empty?
|
||||
|
||||
.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
|
||||
%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 => @stock_article_selections}
|
||||
= 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}
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
- 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=h @stock_article_selection.created_at
|
||||
%dd= format_time(@stock_article_selection.created_at)
|
||||
%dt Erstellt durch:
|
||||
%dd=h link_to_user_message_if_valid(@stock_article_selection.created_by)
|
||||
%dd= link_to_user_message_if_valid(@stock_article_selection.created_by)
|
||||
%dt Zu löschende Artikel
|
||||
- for article in @stock_article_selection.stock_articles
|
||||
%dd=h article.name
|
||||
- for article in @stock_article_selection.stock_articles.with_deleted
|
||||
%dd
|
||||
%span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name
|
||||
|
||||
|
||||
%p
|
||||
|
@ -15,4 +22,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 zeigen', stock_article_selections_path, class: 'btn'
|
||||
= link_to 'Alle Löschvorschläge anzeigen', stock_article_selections_path, class: 'btn'
|
||||
|
|
|
@ -95,6 +95,10 @@ Foodsoft::Application.routes.draw do
|
|||
member do
|
||||
delete 'articles'
|
||||
end
|
||||
|
||||
collection do
|
||||
delete 'finished'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue