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,27 +1,16 @@
|
||||||
= simple_form_for @order do |f|
|
= simple_form_for @order do |f|
|
||||||
.single_column
|
|
||||||
.box_title
|
|
||||||
%h2 Bestellung für #{@order.name}
|
|
||||||
.column_content
|
|
||||||
= f.hidden_field :supplier_id
|
= f.hidden_field :supplier_id
|
||||||
= f.input :note
|
= f.input :note, input_html: {rows: 8}
|
||||||
= f.input :starts
|
= f.input :starts, input_html: {class: 'input-small'}
|
||||||
= f.input :ends
|
= f.input :ends, input_html: {class: 'input-small'}
|
||||||
|
|
||||||
.box_title
|
|
||||||
%h2 Artikel
|
%h2 Artikel
|
||||||
.column_content
|
- if @order.errors.has_key?(:articles)
|
||||||
- if (@template_orders && !@template_orders.empty?)
|
.alert.alert-error
|
||||||
%p
|
= @order.errors.get(:articles).join(" ")
|
||||||
%label{:for => 'template'} Benutze Artikelauswahl von
|
%table.table.table-hover#articleList
|
||||||
%select{:name => "template_id", :onchange => "useTemplate(this[this.selectedIndex].value)"}
|
|
||||||
%option{:value => "-1", :selected => "selected"} Bestellung auswählen...
|
|
||||||
- i = -1
|
|
||||||
- for order in @template_orders
|
|
||||||
%option{:value => (i += 1)}= "#{h(order.name)} bis #{order.ends.strftime('%d. %b')}"
|
|
||||||
%table.list
|
|
||||||
%tr
|
%tr
|
||||||
%th= check_box_tag 'checkall', "1", false, { 'data-check-all' => 'form.order' }
|
%th= check_box_tag 'checkall', "1", false, { 'data-check-all' => '#articleList' }
|
||||||
%th Name
|
%th Name
|
||||||
%th Notiz
|
%th Notiz
|
||||||
- if @order.stockit?
|
- if @order.stockit?
|
||||||
|
@ -32,15 +21,16 @@
|
||||||
%th Gebinde
|
%th Gebinde
|
||||||
%th Preis (netto/FC)
|
%th Preis (netto/FC)
|
||||||
- for category_name, articles in @order.articles_for_ordering
|
- for category_name, articles in @order.articles_for_ordering
|
||||||
%tr{:style => "background-color:#EFEFEF"}
|
%tr.article-category
|
||||||
%td
|
%td
|
||||||
%td{:colspan => "6", :style => "text-align:left"}
|
%td{:colspan => "6", :style => "text-align:left"}
|
||||||
%b=h category_name
|
= category_name
|
||||||
|
%i.icon-tag
|
||||||
- for article in articles
|
- for article in articles
|
||||||
/ check if the article is selected
|
/ check if the article is selected
|
||||||
- included = @order.order_articles.detect { |order_article| order_article.article_id == article.id }
|
- included = @order.article_ids.include?(article.id)
|
||||||
- included_class = included ? ' selected' : ''
|
- included_class = included ? ' selected' : ''
|
||||||
%tr{:class => cycle('even', 'odd') + included_class, :id => article.id.to_s }
|
%tr{:class => included_class, :id => article.id.to_s }
|
||||||
%td= check_box_tag "order[article_ids][]", article.id, included, :id => "checkbox_#{article.id}"
|
%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.click-me{'data-check-this' => "#checkbox_#{article.id}"}= article.name
|
||||||
%td=h truncate article.note, :length => 25
|
%td=h truncate article.note, :length => 25
|
||||||
|
@ -52,12 +42,13 @@
|
||||||
%td= "#{article.unit_quantity} x #{article.unit}"
|
%td= "#{article.unit_quantity} x #{article.unit}"
|
||||||
%td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}"
|
%td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}"
|
||||||
%tr
|
%tr
|
||||||
%td{:colspan => "6"}
|
%td
|
||||||
= check_box_tag 'checkall', "1", false, { 'data-check-all' => 'form.order' }
|
= check_box_tag 'checkall', "1", false, { 'data-check-all' => '#articleList' }
|
||||||
Alle auswählen
|
%td{:colspan => "6"} 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
|
||||||
|
= f.submit class: 'btn'
|
||||||
= link_to "oder abbrechen", orders_path
|
= 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