Fixes orders.
This commit is contained in:
parent
8f7e21b918
commit
16de9124fe
8 changed files with 78 additions and 106 deletions
|
@ -109,7 +109,6 @@ function highlightRow(checkbox) {
|
||||||
} else {
|
} else {
|
||||||
row.removeClass('selected');
|
row.removeClass('selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use with auto_complete to set a unique id,
|
// Use with auto_complete to set a unique id,
|
||||||
|
|
|
@ -69,6 +69,10 @@ table {
|
||||||
td.odd {
|
td.odd {
|
||||||
background-color: @tableBackgroundAccent;
|
background-color: @tableBackgroundAccent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tr.selected td {
|
||||||
|
background-color: @successBackground;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tasks ..
|
// Tasks ..
|
||||||
|
|
|
@ -64,6 +64,7 @@ class OrdersController < ApplicationController
|
||||||
flash[:notice] = "Die Bestellung wurde erstellt."
|
flash[:notice] = "Die Bestellung wurde erstellt."
|
||||||
redirect_to @order
|
redirect_to @order
|
||||||
else
|
else
|
||||||
|
logger.debug "[debug] order errors: #{@order.errors.messages}"
|
||||||
render :action => 'new'
|
render :action => 'new'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,7 @@ class Order < ActiveRecord::Base
|
||||||
|
|
||||||
# Callbacks
|
# Callbacks
|
||||||
after_update :update_price_of_group_orders
|
after_update :update_price_of_group_orders
|
||||||
|
after_save :save_order_articles
|
||||||
|
|
||||||
# Finders
|
# Finders
|
||||||
scope :open, where(state: 'open').order('ends DESC')
|
scope :open, where(state: 'open').order('ends DESC')
|
||||||
|
@ -47,25 +48,13 @@ class Order < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fetch last orders from same supplier, to generate an article selection proposal
|
# Save ids, and create/delete order_articles after successfully saved the order
|
||||||
def templates
|
def article_ids=(ids)
|
||||||
if stockit?
|
@article_ids = ids
|
||||||
Order.stockit :limit => 5
|
|
||||||
else
|
|
||||||
supplier.orders.finished :limit => 5
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create or destroy OrderArticle associations on create/update
|
def article_ids
|
||||||
def article_ids=(ids)
|
@article_ids ||= order_articles.map(&:article_id)
|
||||||
# fetch selected articles
|
|
||||||
articles_list = Article.find(ids)
|
|
||||||
# create new order_articles
|
|
||||||
(articles_list - articles).each { |article| order_articles.build(:article => article) }
|
|
||||||
# delete old order_articles
|
|
||||||
articles.reject { |article| articles_list.include?(article) }.each do |article|
|
|
||||||
order_articles.detect { |order_article| order_article.article_id == article.id }.destroy
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def open?
|
def open?
|
||||||
|
@ -221,7 +210,11 @@ class Order < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_articles
|
def include_articles
|
||||||
errors.add(:order_articles, "Es muss mindestens ein Artikel ausgewählt sein") if order_articles.empty?
|
errors.add(:articles, "Es muss mindestens ein Artikel ausgewählt sein") if article_ids.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_order_articles
|
||||||
|
self.articles = Article.find(article_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,63 +1,54 @@
|
||||||
= simple_form_for @order do |f|
|
= simple_form_for @order do |f|
|
||||||
.single_column
|
= f.hidden_field :supplier_id
|
||||||
.box_title
|
= f.input :note, input_html: {rows: 8}
|
||||||
%h2 Bestellung für #{@order.name}
|
= f.input :starts, input_html: {class: 'input-small'}
|
||||||
.column_content
|
= f.input :ends, input_html: {class: 'input-small'}
|
||||||
= f.hidden_field :supplier_id
|
|
||||||
= f.input :note
|
|
||||||
= f.input :starts
|
|
||||||
= f.input :ends
|
|
||||||
|
|
||||||
.box_title
|
%h2 Artikel
|
||||||
%h2 Artikel
|
- if @order.errors.has_key?(:articles)
|
||||||
.column_content
|
.alert.alert-error
|
||||||
- if (@template_orders && !@template_orders.empty?)
|
= @order.errors.get(:articles).join(" ")
|
||||||
%p
|
%table.table.table-hover#articleList
|
||||||
%label{:for => 'template'} Benutze Artikelauswahl von
|
%tr
|
||||||
%select{:name => "template_id", :onchange => "useTemplate(this[this.selectedIndex].value)"}
|
%th= check_box_tag 'checkall', "1", false, { 'data-check-all' => '#articleList' }
|
||||||
%option{:value => "-1", :selected => "selected"} Bestellung auswählen...
|
%th Name
|
||||||
- i = -1
|
%th Notiz
|
||||||
- for order in @template_orders
|
- if @order.stockit?
|
||||||
%option{:value => (i += 1)}= "#{h(order.name)} bis #{order.ends.strftime('%d. %b')}"
|
%th Verfügbar
|
||||||
%table.list
|
- else
|
||||||
%tr
|
%th Herkunft
|
||||||
%th= check_box_tag 'checkall', "1", false, { 'data-check-all' => 'form.order' }
|
%th Hersteller
|
||||||
%th Name
|
%th Gebinde
|
||||||
%th Notiz
|
%th Preis (netto/FC)
|
||||||
|
- for category_name, articles in @order.articles_for_ordering
|
||||||
|
%tr.article-category
|
||||||
|
%td
|
||||||
|
%td{:colspan => "6", :style => "text-align:left"}
|
||||||
|
= category_name
|
||||||
|
%i.icon-tag
|
||||||
|
- for article in articles
|
||||||
|
/ check if the article is selected
|
||||||
|
- included = @order.article_ids.include?(article.id)
|
||||||
|
- included_class = included ? ' selected' : ''
|
||||||
|
%tr{:class => included_class, :id => article.id.to_s }
|
||||||
|
%td= check_box_tag "order[article_ids][]", article.id, included, :id => "checkbox_#{article.id}"
|
||||||
|
%td.click-me{'data-check-this' => "#checkbox_#{article.id}"}= article.name
|
||||||
|
%td=h truncate article.note, :length => 25
|
||||||
- if @order.stockit?
|
- if @order.stockit?
|
||||||
%th Verfügbar
|
%td= "#{article.quantity_available} * #{article.unit}"
|
||||||
- else
|
- else
|
||||||
%th Herkunft
|
%td=h truncate article.origin, :length => 15
|
||||||
%th Hersteller
|
%td=h truncate article.manufacturer, :length => 15
|
||||||
%th Gebinde
|
%td= "#{article.unit_quantity} x #{article.unit}"
|
||||||
%th Preis (netto/FC)
|
%td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}"
|
||||||
- for category_name, articles in @order.articles_for_ordering
|
%tr
|
||||||
%tr{:style => "background-color:#EFEFEF"}
|
%td
|
||||||
%td
|
= check_box_tag 'checkall', "1", false, { 'data-check-all' => '#articleList' }
|
||||||
%td{:colspan => "6", :style => "text-align:left"}
|
%td{:colspan => "6"} Alle auswählen
|
||||||
%b=h category_name
|
|
||||||
- for article in articles
|
|
||||||
/ check if the article is selected
|
|
||||||
- included = @order.order_articles.detect { |order_article| order_article.article_id == article.id }
|
|
||||||
- included_class = included ? ' selected' : ''
|
|
||||||
%tr{:class => cycle('even', 'odd') + included_class, :id => article.id.to_s }
|
|
||||||
%td= check_box_tag "order[article_ids][]", article.id, included, :id => "checkbox_#{article.id}"
|
|
||||||
%td.click-me{'data-check-this' => "#checkbox_#{article.id}"}= article.name
|
|
||||||
%td=h truncate article.note, :length => 25
|
|
||||||
- if @order.stockit?
|
|
||||||
%td= "#{article.quantity_available} * #{article.unit}"
|
|
||||||
- else
|
|
||||||
%td=h truncate article.origin, :length => 15
|
|
||||||
%td=h truncate article.manufacturer, :length => 15
|
|
||||||
%td= "#{article.unit_quantity} x #{article.unit}"
|
|
||||||
%td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}"
|
|
||||||
%tr
|
|
||||||
%td{:colspan => "6"}
|
|
||||||
= check_box_tag 'checkall', "1", false, { 'data-check-all' => 'form.order' }
|
|
||||||
Alle auswählen
|
|
||||||
|
|
||||||
- if (@template_orders && !@template_orders.empty?)
|
- if (@template_orders && !@template_orders.empty?)
|
||||||
= render :partial => 'template_orders_script'
|
= render :partial => 'template_orders_script'
|
||||||
|
|
||||||
= f.submit
|
.form-actions
|
||||||
= link_to "oder abbrechen", orders_path
|
= f.submit class: 'btn'
|
||||||
|
= link_to "oder abbrechen", orders_path
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
:javascript
|
|
||||||
//
|
|
||||||
// Preset selected order articles per template order:
|
|
||||||
var template = new Array();
|
|
||||||
<haml:silent> current_article_ids = @order.supplier.articles.available.map(&:id)
|
|
||||||
</haml:silent><haml:silent> i = -1; for order in @template_orders
|
|
||||||
</haml:silent><haml:block> template[#{i += 1}] = new Array(#{current_article_ids.collect { |id| order.article_ids.include?(id) }.join(', ')});
|
|
||||||
</haml:block> // Call with index into template-array to select order articles from template.
|
|
||||||
function useTemplate(id) {
|
|
||||||
if (id >= 0 && id < template.length) {
|
|
||||||
<haml:silent> i = -1; for article_id in current_article_ids
|
|
||||||
</haml:silent><haml:block> var status = template[id][#{i += 1}]
|
|
||||||
$('checkbox_#{article_id}').checked = status;
|
|
||||||
highlightRow('#{article_id}',status);
|
|
||||||
</haml:block> }
|
|
||||||
}
|
|
||||||
//
|
|
|
@ -1,13 +1,14 @@
|
||||||
- title "Bestellungen verwalten"
|
- title "Bestellungen verwalten"
|
||||||
|
|
||||||
%p
|
|
||||||
- form_tag do
|
|
||||||
Neue Bestellung anlegen für
|
|
||||||
= select_tag :switch_supplier,
|
|
||||||
options_for_suppliers_to_select,
|
|
||||||
style: "font-size: 0.9em;margin-left:1em;",
|
|
||||||
'data-redirect-to' => true
|
|
||||||
.well
|
.well
|
||||||
|
.btn-group.pull-right
|
||||||
|
= link_to '#', data: {toggle: 'dropdown'}, class: 'btn btn-primary dropdown-toggle' do
|
||||||
|
Neue Bestellung für ..
|
||||||
|
%span.caret
|
||||||
|
%ul.dropdown-menu
|
||||||
|
- Supplier.all.each do |supplier|
|
||||||
|
%li= link_to supplier.name, new_order_path(supplier_id: supplier.id), tabindex: -1
|
||||||
|
|
||||||
%h2 Laufende Bestellungen
|
%h2 Laufende Bestellungen
|
||||||
- unless @open_orders.empty?
|
- unless @open_orders.empty?
|
||||||
%table.table.table-striped
|
%table.table.table-striped
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
- title "Neue Bestellung anlegen"
|
- title "Neue Bestellung anlegen"
|
||||||
|
|
||||||
= render :partial => 'form'
|
= render 'form'
|
||||||
|
|
Loading…
Reference in a new issue