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 {
|
||||
row.removeClass('selected');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Use with auto_complete to set a unique id,
|
||||
|
|
|
@ -69,6 +69,10 @@ table {
|
|||
td.odd {
|
||||
background-color: @tableBackgroundAccent;
|
||||
}
|
||||
|
||||
tr.selected td {
|
||||
background-color: @successBackground;
|
||||
}
|
||||
}
|
||||
|
||||
// Tasks ..
|
||||
|
|
|
@ -64,6 +64,7 @@ class OrdersController < ApplicationController
|
|||
flash[:notice] = "Die Bestellung wurde erstellt."
|
||||
redirect_to @order
|
||||
else
|
||||
logger.debug "[debug] order errors: #{@order.errors.messages}"
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,7 @@ class Order < ActiveRecord::Base
|
|||
|
||||
# Callbacks
|
||||
after_update :update_price_of_group_orders
|
||||
after_save :save_order_articles
|
||||
|
||||
# Finders
|
||||
scope :open, where(state: 'open').order('ends DESC')
|
||||
|
@ -47,25 +48,13 @@ class Order < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# Fetch last orders from same supplier, to generate an article selection proposal
|
||||
def templates
|
||||
if stockit?
|
||||
Order.stockit :limit => 5
|
||||
else
|
||||
supplier.orders.finished :limit => 5
|
||||
end
|
||||
# Save ids, and create/delete order_articles after successfully saved the order
|
||||
def article_ids=(ids)
|
||||
@article_ids = ids
|
||||
end
|
||||
|
||||
# Create or destroy OrderArticle associations on create/update
|
||||
def article_ids=(ids)
|
||||
# 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
|
||||
def article_ids
|
||||
@article_ids ||= order_articles.map(&:article_id)
|
||||
end
|
||||
|
||||
def open?
|
||||
|
@ -221,7 +210,11 @@ class Order < ActiveRecord::Base
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
|
|
@ -1,27 +1,16 @@
|
|||
= simple_form_for @order do |f|
|
||||
.single_column
|
||||
.box_title
|
||||
%h2 Bestellung für #{@order.name}
|
||||
.column_content
|
||||
= f.hidden_field :supplier_id
|
||||
= f.input :note
|
||||
= f.input :starts
|
||||
= f.input :ends
|
||||
= f.input :note, input_html: {rows: 8}
|
||||
= f.input :starts, input_html: {class: 'input-small'}
|
||||
= f.input :ends, input_html: {class: 'input-small'}
|
||||
|
||||
.box_title
|
||||
%h2 Artikel
|
||||
.column_content
|
||||
- if (@template_orders && !@template_orders.empty?)
|
||||
%p
|
||||
%label{:for => 'template'} Benutze Artikelauswahl von
|
||||
%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
|
||||
- if @order.errors.has_key?(:articles)
|
||||
.alert.alert-error
|
||||
= @order.errors.get(:articles).join(" ")
|
||||
%table.table.table-hover#articleList
|
||||
%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 Notiz
|
||||
- if @order.stockit?
|
||||
|
@ -32,15 +21,16 @@
|
|||
%th Gebinde
|
||||
%th Preis (netto/FC)
|
||||
- for category_name, articles in @order.articles_for_ordering
|
||||
%tr{:style => "background-color:#EFEFEF"}
|
||||
%tr.article-category
|
||||
%td
|
||||
%td{:colspan => "6", :style => "text-align:left"}
|
||||
%b=h category_name
|
||||
= category_name
|
||||
%i.icon-tag
|
||||
- for article in articles
|
||||
/ 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' : ''
|
||||
%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.click-me{'data-check-this' => "#checkbox_#{article.id}"}= article.name
|
||||
%td=h truncate article.note, :length => 25
|
||||
|
@ -52,12 +42,13 @@
|
|||
%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
|
||||
%td
|
||||
= check_box_tag 'checkall', "1", false, { 'data-check-all' => '#articleList' }
|
||||
%td{:colspan => "6"} Alle auswählen
|
||||
|
||||
- if (@template_orders && !@template_orders.empty?)
|
||||
= render :partial => 'template_orders_script'
|
||||
|
||||
= f.submit
|
||||
.form-actions
|
||||
= 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"
|
||||
|
||||
%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
|
||||
.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
|
||||
- unless @open_orders.empty?
|
||||
%table.table.table-striped
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
- title "Neue Bestellung anlegen"
|
||||
|
||||
= render :partial => 'form'
|
||||
= render 'form'
|
||||
|
|
Loading…
Reference in a new issue