From bd1b93277589c2b73c05d1e1b269a649bf665227 Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 25 Nov 2013 13:48:54 +0100 Subject: [PATCH 01/79] add receive screen, quantities for model, redistribution --- .../bootstrap_and_overrides.css.less | 10 ++ app/controllers/finance/receive_controller.rb | 37 ++++++ app/helpers/finance/receive_helper.rb | 9 ++ app/models/group_order_article.rb | 88 ++++++++------- app/models/order.rb | 3 + app/models/order_article.rb | 25 ++++- app/views/finance/balancing/_orders.html.haml | 1 + .../finance/receive/_edit_article.html.haml | 16 +++ .../finance/receive/_edit_articles.html.haml | 76 +++++++++++++ app/views/finance/receive/add_article.js.erb | 14 +++ app/views/finance/receive/edit.html.haml | 10 ++ config/locales/en.yml | 1 + config/routes.rb | 4 + ...0132511_add_quantities_to_order_article.rb | 6 + db/schema.rb | 4 +- spec/factories/order.rb | 4 - spec/models/order_article_spec.rb | 106 ++++++++++++++++++ 17 files changed, 365 insertions(+), 49 deletions(-) create mode 100644 app/controllers/finance/receive_controller.rb create mode 100644 app/helpers/finance/receive_helper.rb create mode 100644 app/views/finance/receive/_edit_article.html.haml create mode 100644 app/views/finance/receive/_edit_articles.html.haml create mode 100644 app/views/finance/receive/add_article.js.erb create mode 100644 app/views/finance/receive/edit.html.haml create mode 100644 db/migrate/20130930132511_add_quantities_to_order_article.rb create mode 100644 spec/models/order_article_spec.rb diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 6ad25972..1a514396 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -212,6 +212,16 @@ tr.unavailable { } } +// editable article list can be more compact +.ordered-articles input { + margin-bottom: 0; +} + +// entering units +.units_delta { + width: 2em; +} + // ********* Tweaks & fixes // need more space for supplier&order information (in German, at least) diff --git a/app/controllers/finance/receive_controller.rb b/app/controllers/finance/receive_controller.rb new file mode 100644 index 00000000..2ecbd059 --- /dev/null +++ b/app/controllers/finance/receive_controller.rb @@ -0,0 +1,37 @@ +class Finance::ReceiveController < Finance::BaseController + + def edit + @order = Order.find(params[:id]) + @order_articles = @order.order_articles.ordered.includes(:article) + end + + def update + OrderArticle.transaction do + params[:order_articles].each do |oa_id, oa_params| + unless oa_params.blank? + oa = OrderArticle.find(oa_id) + # update attributes + oa.update_attributes!(oa_params) + # and process consequences + oa.redistribute(oa.units_received * oa.price.unit_quantity) unless oa.units_received.blank? + oa.save! + end + end + + flash[:notice] = I18n.t('receive.update.notice') + redirect_to finance_order_index_path + end + end + + # ajax add article + def add_article + @order = Order.find(params[:receive_id]) + @order_article = @order.order_articles.where(:article_id => params[:article_id]).includes(:article).first + # we need to create the order article if it's not part of the current order + if @order_article.nil? + @order_article = @order.order_articles.build({order: @order, article_id: params[:article_id]}) + @order_article.save! + end + end + +end diff --git a/app/helpers/finance/receive_helper.rb b/app/helpers/finance/receive_helper.rb new file mode 100644 index 00000000..15b28a66 --- /dev/null +++ b/app/helpers/finance/receive_helper.rb @@ -0,0 +1,9 @@ +# :encoding:utf-8: +module Finance::ReceiveHelper + # TODO currently duplicate a bit of DeliveriesHelper.articles_for_select2 + def articles_for_select2(supplier) + supplier.articles.undeleted.reorder('articles.name ASC').map do |a| + {:id => a.id, :text => "#{a.name} (#{a.unit_quantity}⨯#{a.unit})"} + end + end +end diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 9d4b8c82..4d7bff09 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -99,57 +99,63 @@ class GroupOrderArticle < ActiveRecord::Base # Returns a hash with three keys: :quantity / :tolerance / :total # # See description of the ordering algorithm in the general application documentation for details. - def calculate_result - @calculate_result ||= begin - quantity = tolerance = total_quantity = 0 + def calculate_result(total = nil) + # return memoized result unless a total is given + return @calculate_result if total.nil? and not @calculate_result.nil? - # Get total - if order_article.article.is_a?(StockArticle) - total = order_article.article.quantity - logger.debug "<#{order_article.article.name}> (stock) => #{total}" - else - total = order_article.units_to_order * order_article.price.unit_quantity - logger.debug "<#{order_article.article.name}> units_to_order #{order_article.units_to_order} => #{total}" + quantity = tolerance = total_quantity = 0 + + # Get total + if not total.nil? + logger.debug "<#{order_article.article.name}> => #{total} (given)" + elsif order_article.article.is_a?(StockArticle) + total = order_article.article.quantity + logger.debug "<#{order_article.article.name}> (stock) => #{total}" + else + total = order_article.units_to_order * order_article.price.unit_quantity + logger.debug "<#{order_article.article.name}> units_to_order #{order_article.units_to_order} => #{total}" + end + + if total > 0 + # In total there are enough units ordered. Now check the individual result for the ordergroup (group_order). + # + # Get all GroupOrderArticleQuantities for this OrderArticle... + order_quantities = GroupOrderArticleQuantity.all( + :conditions => ["group_order_article_id IN (?)", order_article.group_order_article_ids], :order => 'created_on') + logger.debug "GroupOrderArticleQuantity records found: #{order_quantities.size}" + + # Determine quantities to be ordered... + order_quantities.each do |goaq| + q = [goaq.quantity, total - total_quantity].min + total_quantity += q + if goaq.group_order_article_id == self.id + logger.debug "increasing quantity by #{q}" + quantity += q + end + break if total_quantity >= total end - if total > 0 - # In total there are enough units ordered. Now check the individual result for the ordergroup (group_order). - # - # Get all GroupOrderArticleQuantities for this OrderArticle... - order_quantities = GroupOrderArticleQuantity.all( - :conditions => ["group_order_article_id IN (?)", order_article.group_order_article_ids], :order => 'created_on') - logger.debug "GroupOrderArticleQuantity records found: #{order_quantities.size}" - - # Determine quantities to be ordered... + # Determine tolerance to be ordered... + if total_quantity < total + logger.debug "determining additional items to be ordered from tolerance" order_quantities.each do |goaq| - q = [goaq.quantity, total - total_quantity].min + q = [goaq.tolerance, total - total_quantity].min total_quantity += q if goaq.group_order_article_id == self.id - logger.debug "increasing quantity by #{q}" - quantity += q + logger.debug "increasing tolerance by #{q}" + tolerance += q end break if total_quantity >= total end - - # Determine tolerance to be ordered... - if total_quantity < total - logger.debug "determining additional items to be ordered from tolerance" - order_quantities.each do |goaq| - q = [goaq.tolerance, total - total_quantity].min - total_quantity += q - if goaq.group_order_article_id == self.id - logger.debug "increasing tolerance by #{q}" - tolerance += q - end - break if total_quantity >= total - end - end - - logger.debug "determined quantity/tolerance/total: #{quantity} / #{tolerance} / #{quantity + tolerance}" end - {:quantity => quantity, :tolerance => tolerance, :total => quantity + tolerance} + logger.debug "determined quantity/tolerance/total: #{quantity} / #{tolerance} / #{quantity + tolerance}" end + + # memoize result unless a total is given + r = {:quantity => quantity, :tolerance => tolerance, :total => quantity + tolerance} + @calculate_result = r if total.nil? + r end # Returns order result, @@ -160,8 +166,8 @@ class GroupOrderArticle < ActiveRecord::Base end # This is used during order.finish!. - def save_results! - self.update_attribute(:result, calculate_result[:total]) + def save_results!(article_total = nil) + self.update_attribute(:result, calculate_result(article_total)[:total]) end # Returns total price for this individual article diff --git a/app/models/order.rb b/app/models/order.rb index 057c0768..087bf450 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -166,6 +166,9 @@ class Order < ActiveRecord::Base goa.save_results! # Delete no longer required order-history (group_order_article_quantities) and # TODO: Do we need articles, which aren't ordered? (units_to_order == 0 ?) + # A: Yes, we do - for redistributing articles when the number of articles + # delivered changes, and for statistics on popular articles. Records + # with both tolerance and quantity zero can be deleted. #goa.group_order_article_quantities.clear end end diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 3eb97aea..32211f24 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -12,8 +12,8 @@ class OrderArticle < ActiveRecord::Base validate :article_and_price_exist validates_uniqueness_of :article_id, scope: :order_id - scope :ordered, :conditions => "units_to_order > 0" - scope :ordered_or_member, -> { includes(:group_order_articles).where("units_to_order > 0 OR group_order_articles.result > 0") } + scope :ordered, -> { where("units_to_order > 0 OR units_billed > 0 OR units_received > 0") } + scope :ordered_or_member, -> { includes(:group_order_articles).where("units_to_order > 0 OR units_billed > 0 OR units_received > 0 OR group_order_articles.result > 0") } before_create :init_from_balancing after_destroy :update_ordergroup_prices @@ -34,7 +34,14 @@ class OrderArticle < ActiveRecord::Base def price article_price || article end - + + # latest information on available units + def units + return units_received unless units_received.nil? + return units_billed unless units_billed.nil? + units_to_order + end + # Count quantities of belonging group_orders. # In balancing this can differ from ordered (by supplier) quantity for this article. def group_orders_sum @@ -94,6 +101,18 @@ class OrderArticle < ActiveRecord::Base (units_to_order * price.unit_quantity) == group_orders_sum[:quantity] rescue false end + def redistribute(quantity) + # recompute + group_order_articles.each {|goa| goa.save_results! quantity } + + # Update GroupOrder prices & Ordergroup stats + # TODO only affected group_orders, and once after redistributing all articles + order.group_orders.each(&:update_price!) + order.ordergroups.each(&:update_stats!) + + # TODO notifications + end + # Updates order_article and belongings during balancing process def update_article_and_price!(order_article_attributes, article_attributes, price_attributes = nil) OrderArticle.transaction do diff --git a/app/views/finance/balancing/_orders.html.haml b/app/views/finance/balancing/_orders.html.haml index 6973aa32..3c54e340 100644 --- a/app/views/finance/balancing/_orders.html.haml +++ b/app/views/finance/balancing/_orders.html.haml @@ -19,6 +19,7 @@ %td= show_user(order.updated_by) %td - unless order.closed? + = link_to t('.receive'), edit_finance_receive_path(order), class: 'btn btn-mini' = link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary' = link_to t('.close'), close_direct_finance_order_path(order), :confirm => t('.confirm'), :method => :put, class: 'btn btn-mini' diff --git a/app/views/finance/receive/_edit_article.html.haml b/app/views/finance/receive/_edit_article.html.haml new file mode 100644 index 00000000..8be17a37 --- /dev/null +++ b/app/views/finance/receive/_edit_article.html.haml @@ -0,0 +1,16 @@ += fields_for 'order_articles', order_article, index: order_article.id do |form| + %tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"} + - order_title = [] + - order_title.append t('.manufacturer')+': ' + order_article.article.manufacturer unless order_article.article.manufacturer.to_s.empty? + - order_title.append t('.note')+': ' + order_article.article.note unless order_article.article.note.to_s.empty? + - units_expected = (order_article.units_billed or order_article.units_to_order) + %td= order_article.article.order_number + %td.name{title: order_title.join("\n")}= order_article.article.name + %td #{order_article.article.unit_quantity} × #{order_article.article.unit} + %td #{order_article.quantity} + #{order_article.tolerance} + %td= order_article.units_to_order + %td= order_article.units_billed + %td + = form.text_field :units_received, class: 'input-mini', data: {'units-expected' => units_expected} + / TODO add almost invisible text_field for entering single units + %td.units_delta diff --git a/app/views/finance/receive/_edit_articles.html.haml b/app/views/finance/receive/_edit_articles.html.haml new file mode 100644 index 00000000..afc71f12 --- /dev/null +++ b/app/views/finance/receive/_edit_articles.html.haml @@ -0,0 +1,76 @@ +- content_for :javascript do + :javascript + + function update_delta(input) { + var units = $(input).val(); + var expected = $(input).data('units-expected'); + var html; + + if (units.replace(/\s/g,"")=="") { + // no value + html = ''; + } else if (isNaN(units)) { + html = ''; + } else if (units == expected) { + // equal value + html = ''; + } else if (units < expected) { + html = '- '+(expected-units)+''; + } else /*if (units> expected)*/ { + html = '+ '+(units-expected)+''; + } + + $(input).closest('tr').find('.units_delta').html(html); + } + + $(document).on('change', 'input[data-units-expected]', function() { + update_delta(this); + }); + + $(function() { + $('input[data-units-expected]').each(function() { + update_delta(this); + }); + + $('#add_article').removeAttr('disabled').select2({ + placeholder: '#{t '.add_article'}', + data: #{articles_for_select2(@order).to_json}, + // TODO implement adding a new article, like in deliveries + }).on('change', function(e) { + var selectedArticle = $(e.currentTarget).select2('data'); + if(!selectedArticle) { + return false; + } + + $.ajax({ + url: '#{finance_receive_add_article_path(@order)}', + type: 'get', + data: {article_id: selectedArticle.id}, + contentType: 'application/json; charset=UTF-8' + }); + $('#add_article').select2('data', null); + return true; + }); + + }); + + +%table.ordered-articles.table.table-striped.stupidtable + %thead + %tr + %th.sort{:data => {:sort => 'string'}}= t('.number') + %th.sort{:data => {:sort => 'string'}}= t('.article') + %th= heading_helper GroupOrderArticle, :units + %th Members + %th Ordered + %th Invoice + %th Received + %th + %tbody#result_table + - @order_articles.each do |order_article| + = render :partial => 'edit_article', :locals => {:order_article => order_article} + %tfoot + %tr + %th{:colspan => 8} + %input#add_article{:style => 'width: 500px;'} + diff --git a/app/views/finance/receive/add_article.js.erb b/app/views/finance/receive/add_article.js.erb new file mode 100644 index 00000000..b73b6719 --- /dev/null +++ b/app/views/finance/receive/add_article.js.erb @@ -0,0 +1,14 @@ +$('div.container-fluid').prepend( + '<%= j(render(:partial => 'shared/alert_success', :locals => {:alert_message => t('.notice', :name => @order_article.article.name)})) %>' +); + +(function() { + $('.ordered-articles tr').removeClass('success'); + + var article_for_adding = $( + '<%= j(render(:partial => 'edit_article', :locals => {:order_article => @order_article})) %>' + ).addClass('success'); + + $('.ordered-articles tbody').append(article_for_adding); + updateSort('.ordered-articles'); +})(); diff --git a/app/views/finance/receive/edit.html.haml b/app/views/finance/receive/edit.html.haml new file mode 100644 index 00000000..4be57743 --- /dev/null +++ b/app/views/finance/receive/edit.html.haml @@ -0,0 +1,10 @@ +- title "Receiving #{@order.name}" + += form_tag(finance_receive_path(@order), :method => :put) do + %section#results + = render 'edit_articles' + .form-actions + = submit_tag t('.submit'), class: 'btn btn-primary' + = link_to t('ui.or_cancel'), finance_order_index_path + +%p= link_to_top diff --git a/config/locales/en.yml b/config/locales/en.yml index 5d3b1e06..efd2961e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -560,6 +560,7 @@ en: last_edited_by: Last edited by name: Supplier no_closed_orders: At the moment there are no closed orders. + receive: receive state: State summary: changed: Data was changed! diff --git a/config/routes.rb b/config/routes.rb index 655a1038..3a0b0608 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -144,6 +144,10 @@ Foodsoft::Application.routes.draw do resources :order_articles end + resources :receive do + get :add_article + end + resources :group_order_articles do member do put :update_result diff --git a/db/migrate/20130930132511_add_quantities_to_order_article.rb b/db/migrate/20130930132511_add_quantities_to_order_article.rb new file mode 100644 index 00000000..1477b194 --- /dev/null +++ b/db/migrate/20130930132511_add_quantities_to_order_article.rb @@ -0,0 +1,6 @@ +class AddQuantitiesToOrderArticle < ActiveRecord::Migration + def change + add_column :order_articles, :units_billed, :integer + add_column :order_articles, :units_received, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 4170d918..3093e9a1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130920201529) do +ActiveRecord::Schema.define(:version => 20130930132511) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -195,6 +195,8 @@ ActiveRecord::Schema.define(:version => 20130920201529) do t.integer "units_to_order", :default => 0, :null => false t.integer "lock_version", :default => 0, :null => false t.integer "article_price_id" + t.integer "units_billed" + t.integer "units_received" end add_index "order_articles", ["order_id", "article_id"], :name => "index_order_articles_on_order_id_and_article_id", :unique => true diff --git a/spec/factories/order.rb b/spec/factories/order.rb index 4bf63b00..ab89ff6e 100644 --- a/spec/factories/order.rb +++ b/spec/factories/order.rb @@ -24,8 +24,4 @@ FactoryGirl.define do end end - # requires order and article - factory :order_article do - end - end diff --git a/spec/models/order_article_spec.rb b/spec/models/order_article_spec.rb new file mode 100644 index 00000000..bc6dcc5c --- /dev/null +++ b/spec/models/order_article_spec.rb @@ -0,0 +1,106 @@ +require 'spec_helper' + +describe OrderArticle do + let(:order) { FactoryGirl.create :order, article_count: 1 } + let(:oa) { order.order_articles.first } + + it 'is not ordered by default' do + expect(OrderArticle.ordered.count).to eq 0 + end + + [:units_to_order, :units_billed, :units_received].each do |units| + + it "is ordered when there are #{units.to_s.gsub '_', ' '}" do + oa.update_attribute units, rand(1..99) + expect(OrderArticle.ordered.count).to eq 1 + end + + end + + it 'knows how many items there are' do + oa.units_to_order = rand(1..99) + expect(oa.units).to eq oa.units_to_order + oa.units_billed = rand(1..99) + expect(oa.units).to eq oa.units_billed + oa.units_received = rand(1..99) + expect(oa.units).to eq oa.units_received + + oa.units_billed = rand(1..99) + expect(oa.units).to eq oa.units_received + oa.units_to_order = rand(1..99) + expect(oa.units).to eq oa.units_received + oa.units_received = rand(1..99) + expect(oa.units).to eq oa.units_received + end + + describe 'redistribution' do + let(:admin) { FactoryGirl.create :user, groups:[FactoryGirl.create(:workgroup, role_finance: true)] } + let(:article) { FactoryGirl.create :article, unit_quantity: 3 } + let(:order) { FactoryGirl.create :order, article_ids: [article.id] } + let(:go1) { FactoryGirl.create :group_order, order: order } + let(:go2) { FactoryGirl.create :group_order, order: order } + let(:go3) { FactoryGirl.create :group_order, order: order } + let(:goa1) { FactoryGirl.create :group_order_article, group_order: go1, order_article: oa } + let(:goa2) { FactoryGirl.create :group_order_article, group_order: go2, order_article: oa } + let(:goa3) { FactoryGirl.create :group_order_article, group_order: go3, order_article: oa } + + # set quantities of group_order_articles + def set_quantities(q1, q2, q3) + goa1.update_quantities(*q1) + goa2.update_quantities(*q2) + goa3.update_quantities(*q3) + oa.update_results! + order.finish!(admin) + goa_reload + end + + # reload all group_order_articles + def goa_reload + [goa1, goa2, goa3].map(&:reload) + end + + it 'has expected units_to_order' do + set_quantities [3,2], [1,3], [1,0] + expect(oa.units*oa.article.unit_quantity).to eq 6 + expect([goa1, goa2, goa3].map(&:result)).to eq [4, 1, 1] + end + + it 'does nothing when nothing has changed' do + set_quantities [3,2], [1,3], [1,0] + oa.redistribute 6 + goa_reload + expect([goa1, goa2, goa3].map(&:result).map(&:to_i)).to eq [4, 1, 1] + end + + it 'works when there is nothing to distribute' do + set_quantities [3,2], [1,3], [1,0] + oa.redistribute 0 + goa_reload + expect([goa1, goa2, goa3].map(&:result)).to eq [0, 0, 0] + end + + it 'works when quantity needs to be reduced' do + set_quantities [3,2], [1,3], [1,0] + oa.redistribute 4 + goa_reload + expect([goa1, goa2, goa3].map(&:result)).to eq [3, 1, 0] + end + + it 'works when quantity is increased within quantity' do + set_quantities [3,0], [2,0], [2,0] + expect([goa1, goa2, goa3].map(&:result)).to eq [3, 2, 1] + oa.redistribute 7 + goa_reload + expect([goa1, goa2, goa3].map(&:result).map(&:to_i)).to eq [3, 2, 2] + end + + it 'works when there is just one for the first' do + set_quantities [3,2], [1,3], [1,0] + oa.redistribute 1 + goa_reload + expect([goa1, goa2, goa3].map(&:result)).to eq [1, 0, 0] + end + + end + +end From 9c340ec08ed511c63a646764eb39f957eb84137d Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 25 Nov 2013 15:13:54 +0100 Subject: [PATCH 02/79] more clarity whether a number is number units or boxes --- .../stylesheets/bootstrap_and_overrides.css.less | 12 ++++++++++++ app/views/finance/receive/_edit_article.html.haml | 11 ++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 1a514396..519614c0 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -252,3 +252,15 @@ tr.unavailable { .input-append button.add-on { height: inherit; } + +// show package icon after amount of package numbers +.package { + background: url(package-bg.png) no-repeat right center; +} +i.package { + width: 18px; + color: transparent; // hide text inside +} +.input-nano { + width: 30px; +} diff --git a/app/views/finance/receive/_edit_article.html.haml b/app/views/finance/receive/_edit_article.html.haml index 8be17a37..96047a7d 100644 --- a/app/views/finance/receive/_edit_article.html.haml +++ b/app/views/finance/receive/_edit_article.html.haml @@ -8,9 +8,14 @@ %td.name{title: order_title.join("\n")}= order_article.article.name %td #{order_article.article.unit_quantity} × #{order_article.article.unit} %td #{order_article.quantity} + #{order_article.tolerance} - %td= order_article.units_to_order - %td= order_article.units_billed %td - = form.text_field :units_received, class: 'input-mini', data: {'units-expected' => units_expected} + = order_article.units_to_order + %i.package pkg + %td + - unless order_article.units_billed.nil? + = order_article.units_billed + %i.package pkg + %td + = form.text_field :units_received, class: 'input-nano package', data: {'units-expected' => units_expected} / TODO add almost invisible text_field for entering single units %td.units_delta From 9990e059d4a24773ef2620a26f68a09176945eb9 Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 25 Nov 2013 15:24:20 +0100 Subject: [PATCH 03/79] fix i18n --- app/controllers/finance/receive_controller.rb | 2 +- app/views/finance/receive/_edit_article.html.haml | 4 ++-- config/locales/en.yml | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/finance/receive_controller.rb b/app/controllers/finance/receive_controller.rb index 2ecbd059..7bab88ca 100644 --- a/app/controllers/finance/receive_controller.rb +++ b/app/controllers/finance/receive_controller.rb @@ -18,7 +18,7 @@ class Finance::ReceiveController < Finance::BaseController end end - flash[:notice] = I18n.t('receive.update.notice') + flash[:notice] = I18n.t('finance.receive.update.notice') redirect_to finance_order_index_path end end diff --git a/app/views/finance/receive/_edit_article.html.haml b/app/views/finance/receive/_edit_article.html.haml index 96047a7d..9c96f80c 100644 --- a/app/views/finance/receive/_edit_article.html.haml +++ b/app/views/finance/receive/_edit_article.html.haml @@ -1,8 +1,8 @@ = fields_for 'order_articles', order_article, index: order_article.id do |form| %tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"} - order_title = [] - - order_title.append t('.manufacturer')+': ' + order_article.article.manufacturer unless order_article.article.manufacturer.to_s.empty? - - order_title.append t('.note')+': ' + order_article.article.note unless order_article.article.note.to_s.empty? + - order_title.append Article.human_attribute_name(:manufacturer)+': ' + order_article.article.manufacturer unless order_article.article.manufacturer.to_s.empty? + - order_title.append Article.human_attribute_name(:note)+': ' + order_article.article.note unless order_article.article.note.to_s.empty? - units_expected = (order_article.units_billed or order_article.units_to_order) %td= order_article.article.order_number %td.name{title: order_title.join("\n")}= order_article.article.name diff --git a/config/locales/en.yml b/config/locales/en.yml index efd2961e..db27433a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -662,6 +662,15 @@ en: contact: Contact name: Name new_transaction: New transaction + receive: + add_article: + notice: Article "%{name}" was added to the order. + edit: + submit: Receive order + edit_articles: + add_article: Add article + update: + notice: Updated received article amounts for order update: notice: Invoice was updated foodcoop: From 853e8ba9d210f984b5e3d30efe6169c289880c32 Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 25 Nov 2013 15:25:08 +0100 Subject: [PATCH 04/79] add package images [ci skip] --- app/assets/images/package-bg.png | Bin 0 -> 941 bytes app/assets/images/package.png | Bin 0 -> 1182 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/assets/images/package-bg.png create mode 100644 app/assets/images/package.png diff --git a/app/assets/images/package-bg.png b/app/assets/images/package-bg.png new file mode 100644 index 0000000000000000000000000000000000000000..018a2f87738b6e1f61813853f19ad962742c1f3c GIT binary patch literal 941 zcmV;e15*5nP)NLD2N z0FWjH9kHMz5)vj5B`A>vOYnNfdz;?ZKHTtg$%i4Ny#U_hdNz>(1S7_nZCurVjMpe|zWkovRnu z*3WIOWh+VCY=%LW5@iWPQxks=0u;y)H3%>xM3IjqR?XGbaO3(*D_d{8`a=5Cy~jrb zfdGK_-dk6$#cBrShc=92kC`FNAkl~XsAD^BcBnrKJTH3%t67fFO+j9a zAdJxN&?2%A0zd@vJY|h-6oaAm0#6Z~7A7c_HIyH!mI7so2jzw!@xc@Uj={46*611# z06_sD5D}CYgihOW7`IaK7!ZJ20A~Pgzz~QCAb>zXL~zzF13>`IO^F~77^5LlHG>7^ z1qe&EC4fbsh)&;I7?N7R00KJ)$0bkzKuSPqR)MQ~QUs#v1OUG8D@Yl5p(-LUR+k@F zfD&{Xbsn1taL%0?Dn$gUGFO(&0;BZ;fC?bB`?)azu=O1lQ`VlMXzmCo2)hbc2b6HG z{gCnm0@s246MH`&%w9XwNlQZourN$j1(9VVEUf?_2y8v_gGYzQXU?WiTJ6@Qs+3@6 zXstnW$Q(T1Va*r>XkF{!7k3WC8T=Z@Y5Ur4E1U1oE)1W)Hx|KgIAvqGHy%w7mujeU_w&hYI5K~Dgx^L}<8JQV&SX*guOGGd!tXSvz z#Y7+W`$c~1%O3{#k68jf(vX7(zyH!s=th1rdKUP><9X1^@s6D=Y3@000DKNkloxc(9^TCvp>m$;#C)2@B7~ORY3_n zAl`U+@3><-dkV$$Q`vlKn`4WTe%)>-AqLn^XD>t3n3c&C{h%m0(e7p8>} zU=fMgN24oHtt*UWcOjGNAmuGW$`~w}gmO{<1d0)B(Fvb835D~%-q9Oti z7A&^x8MoQIDWu3+0?S~b0hNr|sjVVmPYM>3M%i#EfCzlBCt#SseSkqGje$f0qTfq6 zld;5Orsv;~iEO#Q1&L)1!SmR@)BV9smV_x}bnLD|Y0;ymPs5MX8) ztv4;Qp=8l1TEjf@0{{_2n_%6|t9;o&DzoCjN)KYlab^vpH_>^}(fS0)XsB8BT=s;tI=n(sdG2Rf=V%2}GkZb+8eS4xLhA*4|3=_g*x*7Wskil9gk-Tu_ z-{pNzPS$ey)C-A3Tv^gaG`g+&eb?)alQAG7kTGB)5cR+NnTNj(_16fV?*|e9zW@2w zm1myVR-T$FKCNsUmQt{kLc6hi-*x@*(IO!T4f61a2zY*v?p0eiRHXZ@YxA#XGO6<3 zz2*Ip2Sk9@dgEI>B9S3Rt=75I?&^!3cK3^8XMXx>0C4L3eDCPY^r4B$(z)p!rIHW= zOeXYTqkF)i>8-ZcZg+xTI-THrtI?Y~@#Q6N<-m-@hi@G`d|-CZM`O8s?9Tl4>(zU; zUC~(|4!@_V(eVE0bj?LK2u^(P*~Ob{egdFI7v4T`e(sZ0a^LK8&%PQKUMa2(q0w+F zuBR_}9q-K1Gnc+yujr-#0C4T^>xT*xg>pWLEHlt(d0p4lmtEICS3!4fvuDa^tdS^+ wqlceAkW1Mo8_mw;n2a4iGWXq@C&|Oa|5k(@Ac6hz9smFU07*qoM6N<$g4v5K1ONa4 literal 0 HcmV?d00001 From 9cb9bf6c1a33e6e67e90e1307b0a9df1df11e5a4 Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 26 Nov 2013 13:00:34 +0100 Subject: [PATCH 05/79] focus newly added input in receive --- app/views/finance/receive/add_article.js.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/finance/receive/add_article.js.erb b/app/views/finance/receive/add_article.js.erb index b73b6719..c16259eb 100644 --- a/app/views/finance/receive/add_article.js.erb +++ b/app/views/finance/receive/add_article.js.erb @@ -11,4 +11,6 @@ $('div.container-fluid').prepend( $('.ordered-articles tbody').append(article_for_adding); updateSort('.ordered-articles'); + + $('#order_articles_<%= @order_article.id %>_units_received').focus(); })(); From beabe22a0108a127c01502c6cef1a9341dc61948 Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 26 Nov 2013 13:22:44 +0100 Subject: [PATCH 06/79] simplify model --- app/models/order_article.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 32211f24..7e8c4a86 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -12,8 +12,9 @@ class OrderArticle < ActiveRecord::Base validate :article_and_price_exist validates_uniqueness_of :article_id, scope: :order_id - scope :ordered, -> { where("units_to_order > 0 OR units_billed > 0 OR units_received > 0") } - scope :ordered_or_member, -> { includes(:group_order_articles).where("units_to_order > 0 OR units_billed > 0 OR units_received > 0 OR group_order_articles.result > 0") } + _ordered_sql = "units_to_order > 0 OR units_billed > 0 OR units_received > 0" + scope :ordered, -> { where(_ordered_sql) } + scope :ordered_or_member, -> { includes(:group_order_articles).where("#{_ordered_sql} OR group_order_articles.result > 0") } before_create :init_from_balancing after_destroy :update_ordergroup_prices From 2d991412295c77156adabbae7822708499f8d99d Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 26 Nov 2013 13:31:07 +0100 Subject: [PATCH 07/79] only allow to add articles not already present in receive --- app/helpers/finance/receive_helper.rb | 7 +++++-- .../finance/receive/_edit_articles.html.haml | 20 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/helpers/finance/receive_helper.rb b/app/helpers/finance/receive_helper.rb index 15b28a66..055337d7 100644 --- a/app/helpers/finance/receive_helper.rb +++ b/app/helpers/finance/receive_helper.rb @@ -1,8 +1,11 @@ # :encoding:utf-8: module Finance::ReceiveHelper # TODO currently duplicate a bit of DeliveriesHelper.articles_for_select2 - def articles_for_select2(supplier) - supplier.articles.undeleted.reorder('articles.name ASC').map do |a| + # except is an array of article id's to omit + def articles_for_select2(supplier, except = []) + articles = supplier.articles.reorder('articles.name ASC') + articles.reject! {|a| not except.index(a.id).nil? } if except + articles.map do |a| {:id => a.id, :text => "#{a.name} (#{a.unit_quantity}⨯#{a.unit})"} end end diff --git a/app/views/finance/receive/_edit_articles.html.haml b/app/views/finance/receive/_edit_articles.html.haml index afc71f12..b1b32eab 100644 --- a/app/views/finance/receive/_edit_articles.html.haml +++ b/app/views/finance/receive/_edit_articles.html.haml @@ -1,6 +1,8 @@ - content_for :javascript do :javascript + var new_article_data = #{articles_for_select2(@order, @order_articles.map(&:article_id)).to_json}; + function update_delta(input) { var units = $(input).val(); var expected = $(input).data('units-expected'); @@ -32,9 +34,13 @@ update_delta(this); }); - $('#add_article').removeAttr('disabled').select2({ + init_add_article('#add_article'); + }); + + function init_add_article(sel) { + $(sel).removeAttr('disabled').select2({ placeholder: '#{t '.add_article'}', - data: #{articles_for_select2(@order).to_json}, + data: new_article_data, // TODO implement adding a new article, like in deliveries }).on('change', function(e) { var selectedArticle = $(e.currentTarget).select2('data'); @@ -48,11 +54,17 @@ data: {article_id: selectedArticle.id}, contentType: 'application/json; charset=UTF-8' }); + // clear selection $('#add_article').select2('data', null); + // remove newly added item from list of items + new_article_data = $.grep(new_article_data, function(el, i) { + return el.id != selectedArticle.id; + }); + init_add_article(sel) return true; }); - - }); + } + %table.ordered-articles.table.table-striped.stupidtable From c900cf4988be085fb21037b89c6602940a43410a Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 26 Nov 2013 23:48:21 +0100 Subject: [PATCH 08/79] make product redistribution work! --- .../bootstrap_and_overrides.css.less | 5 ++ app/controllers/finance/receive_controller.rb | 29 ++++++++++-- app/models/order_article.rb | 46 ++++++++++++++++--- app/views/finance/receive/edit.html.haml | 17 ++++++- spec/models/order_article_spec.rb | 24 ++++++++-- 5 files changed, 103 insertions(+), 18 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 519614c0..24f6604c 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -253,6 +253,11 @@ tr.unavailable { height: inherit; } +// inline form elements +.inline { + display: inline; +} + // show package icon after amount of package numbers .package { background: url(package-bg.png) no-repeat right center; diff --git a/app/controllers/finance/receive_controller.rb b/app/controllers/finance/receive_controller.rb index 7bab88ca..9afffa85 100644 --- a/app/controllers/finance/receive_controller.rb +++ b/app/controllers/finance/receive_controller.rb @@ -6,19 +6,38 @@ class Finance::ReceiveController < Finance::BaseController end def update + # where to leave remainder during redistribution + rest_to = [] + rest_to << :tolerance if params[:rest_to_tolerance] + rest_to << :stock if params[:rest_to_stock] + rest_to << nil + # count what happens to the articles + counts = [0] * (rest_to.length+2) + cunits = [0] * (rest_to.length+2) OrderArticle.transaction do params[:order_articles].each do |oa_id, oa_params| unless oa_params.blank? oa = OrderArticle.find(oa_id) - # update attributes - oa.update_attributes!(oa_params) - # and process consequences - oa.redistribute(oa.units_received * oa.price.unit_quantity) unless oa.units_received.blank? + # update attributes; don't use update_attribute because it calls save + # which makes received_changed? not work anymore + oa.attributes = oa_params + counts[0] += 1 if oa.units_received_changed? + cunits[0] += oa.units_received * oa.article.unit_quantity + unless oa.units_received.blank? + oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to + oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 } + end oa.save! end end - flash[:notice] = I18n.t('finance.receive.update.notice') + #flash[:notice] = I18n.t('finance.receive.update.notice') + notice = "Order received:" + notice += " #{counts.shift} articles (#{cunits.shift} units) updated" + notice += ", #{counts.shift} (#{cunits.shift}) using tolerance" if params[:rest_to_tolerance] + notice += ", #{counts.shift} (#{cunits.shift}) go to stock if foodsoft would support that" if params[:rest_to_stock] + notice += ", #{counts.shift} (#{cunits.shift}) left over" + flash[:notice] = notice redirect_to finance_order_index_path end end diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 7e8c4a86..e9e31b2c 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -102,16 +102,50 @@ class OrderArticle < ActiveRecord::Base (units_to_order * price.unit_quantity) == group_orders_sum[:quantity] rescue false end - def redistribute(quantity) - # recompute - group_order_articles.each {|goa| goa.save_results! quantity } + # redistribute articles over ordergroups + # quantity Number of units to distribute + # surplus What to do when there are more articles than ordered quantity + # :tolerance fill member orders' tolerance + # :stock move to stock + # nil nothing; for catching the remaining count + # update_totals Whether to update group_order and ordergroup totals + # returns array with counts for each surplus method + def redistribute(quantity, surplus = [:tolerance], update_totals = true) + qty_left = quantity + counts = [0] * surplus.length + + if surplus.index(:tolerance).nil? + qty_for_members = [qty_left, self.quantity].min + else + qty_for_members = [qty_left, self.quantity+self.tolerance].min + counts[surplus.index(:tolerance)] = [0, qty_for_members-self.quantity].max + end + + # Recompute + group_order_articles.each {|goa| goa.save_results! qty_for_members } + qty_left -= qty_for_members + + # if there's anything left, move to stock if wanted + if qty_left > 0 and surplus.index(:stock) + counts[surplus.index(:stock)] = qty_left + # 1) find existing stock article with same name, unit, price + # 2) if not found, create new stock article + # avoiding duplicate stock article names + end + if qty_left > 0 and surplus.index(nil) + counts[surplus.index(nil)] = qty_left + end # Update GroupOrder prices & Ordergroup stats # TODO only affected group_orders, and once after redistributing all articles - order.group_orders.each(&:update_price!) - order.ordergroups.each(&:update_stats!) + if update_totals + update_ordergroup_prices + order.ordergroups.each(&:update_stats!) + end # TODO notifications + + counts end # Updates order_article and belongings during balancing process @@ -173,7 +207,7 @@ class OrderArticle < ActiveRecord::Base # updates prices of ALL ordergroups - these are actually too many # in case of performance issues, update only ordergroups, which ordered this article # CAUTION: in after_destroy callback related records (e.g. group_order_articles) are already non-existent - order.group_orders.each { |go| go.update_price! } + order.group_orders.each(&:update_price!) end end diff --git a/app/views/finance/receive/edit.html.haml b/app/views/finance/receive/edit.html.haml index 4be57743..cdeea92f 100644 --- a/app/views/finance/receive/edit.html.haml +++ b/app/views/finance/receive/edit.html.haml @@ -3,8 +3,21 @@ = form_tag(finance_receive_path(@order), :method => :put) do %section#results = render 'edit_articles' + .form-actions - = submit_tag t('.submit'), class: 'btn btn-primary' - = link_to t('ui.or_cancel'), finance_order_index_path + .pull-left + Surplus to + = label_tag :rest_to_tolerance, class: 'inline' do + = check_box_tag :rest_to_tolerance, 1, true + member tolerance, + %span{style: 'color: grey'} + and + = label_tag :rest_to_stock, class: 'inline' do + = check_box_tag :rest_to_stock, 1, false, disabled: true + stock + + .pull-right + = submit_tag t('.submit'), class: 'btn btn-primary' + = link_to t('ui.or_cancel'), finance_order_index_path %p= link_to_top diff --git a/spec/models/order_article_spec.rb b/spec/models/order_article_spec.rb index bc6dcc5c..c46d49ea 100644 --- a/spec/models/order_article_spec.rb +++ b/spec/models/order_article_spec.rb @@ -67,21 +67,21 @@ describe OrderArticle do it 'does nothing when nothing has changed' do set_quantities [3,2], [1,3], [1,0] - oa.redistribute 6 + expect(oa.redistribute 6, [:tolerance, nil]).to eq [1, 0] goa_reload expect([goa1, goa2, goa3].map(&:result).map(&:to_i)).to eq [4, 1, 1] end it 'works when there is nothing to distribute' do set_quantities [3,2], [1,3], [1,0] - oa.redistribute 0 + expect(oa.redistribute 0, [:tolerance, nil]).to eq [0, 0] goa_reload expect([goa1, goa2, goa3].map(&:result)).to eq [0, 0, 0] end it 'works when quantity needs to be reduced' do set_quantities [3,2], [1,3], [1,0] - oa.redistribute 4 + expect(oa.redistribute 4, [:tolerance, nil]).to eq [0, 0] goa_reload expect([goa1, goa2, goa3].map(&:result)).to eq [3, 1, 0] end @@ -89,18 +89,32 @@ describe OrderArticle do it 'works when quantity is increased within quantity' do set_quantities [3,0], [2,0], [2,0] expect([goa1, goa2, goa3].map(&:result)).to eq [3, 2, 1] - oa.redistribute 7 + expect(oa.redistribute 7, [:tolerance, nil]).to eq [0, 0] goa_reload expect([goa1, goa2, goa3].map(&:result).map(&:to_i)).to eq [3, 2, 2] end it 'works when there is just one for the first' do set_quantities [3,2], [1,3], [1,0] - oa.redistribute 1 + expect(oa.redistribute 1, [:tolerance, nil]).to eq [0, 0] goa_reload expect([goa1, goa2, goa3].map(&:result)).to eq [1, 0, 0] end + it 'works when there is tolerance and left-over' do + set_quantities [3,2], [1,1], [1,0] + expect(oa.redistribute 10, [:tolerance, nil]).to eq [3, 2] + goa_reload + expect([goa1, goa2, goa3].map(&:result)).to eq [5, 2, 1] + end + + it 'works when redistributing without tolerance' do + set_quantities [3,2], [1,3], [1,0] + expect(oa.redistribute 8, [nil]).to eq [3] + goa_reload + expect([goa1, goa2, goa3].map(&:result)).to eq [3, 1, 1] + end + end end From a0c6cf8afe39bf72bb3d9669f5d62aa33ed3a4e4 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 16:04:30 +0100 Subject: [PATCH 09/79] fix warning without text --- app/views/orders/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index 075706fe..62e24ae1 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -2,7 +2,7 @@ - if @order.finished? and !@order.closed? .alert.alert-warning - = t '.warn_not_closed' + = t '.warn_not_closed' // Order summary .well From 1ab09b41bde0593afadca8d6e4309eb3f6f62e76 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 17:34:45 +0100 Subject: [PATCH 10/79] fix articles_for_select2 helper --- app/helpers/deliveries_helper.rb | 13 +++++++++---- app/helpers/finance/receive_helper.rb | 9 --------- app/views/deliveries/_form.html.haml | 6 +++--- app/views/finance/receive/_edit_articles.html.haml | 3 ++- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/helpers/deliveries_helper.rb b/app/helpers/deliveries_helper.rb index 2ef5d14b..03a8f3ec 100644 --- a/app/helpers/deliveries_helper.rb +++ b/app/helpers/deliveries_helper.rb @@ -10,12 +10,17 @@ module DeliveriesHelper end end - def articles_for_select2(supplier) - supplier.articles.undeleted.reorder('articles.name ASC').map {|a| {:id => a.id, :text => "#{a.name} (#{number_to_currency a.price}/#{a.unit})"} } + def articles_for_select2(articles, except = [], &block) + articles = articles.reorder('articles.name ASC') + articles.reject! {|a| not except.index(a.id).nil? } if except + block_given? or block = Proc.new {|a| "#{a.name} (#{number_to_currency a.price}/#{a.unit})" } + articles.map do |a| + {:id => a.id, :text => block.call(a)} + end end - def stock_articles_for_table(supplier) - supplier.stock_articles.undeleted.reorder('articles.name ASC') + def articles_for_table(articles) + articles.undeleted.reorder('articles.name ASC') end def stock_change_remove_link(stock_change_form) diff --git a/app/helpers/finance/receive_helper.rb b/app/helpers/finance/receive_helper.rb index 055337d7..fe844d08 100644 --- a/app/helpers/finance/receive_helper.rb +++ b/app/helpers/finance/receive_helper.rb @@ -1,12 +1,3 @@ # :encoding:utf-8: module Finance::ReceiveHelper - # TODO currently duplicate a bit of DeliveriesHelper.articles_for_select2 - # except is an array of article id's to omit - def articles_for_select2(supplier, except = []) - articles = supplier.articles.reorder('articles.name ASC') - articles.reject! {|a| not except.index(a.id).nil? } if except - articles.map do |a| - {:id => a.id, :text => "#{a.name} (#{a.unit_quantity}⨯#{a.unit})"} - end - end end diff --git a/app/views/deliveries/_form.html.haml b/app/views/deliveries/_form.html.haml index 40337dde..8e2d7f75 100644 --- a/app/views/deliveries/_form.html.haml +++ b/app/views/deliveries/_form.html.haml @@ -20,7 +20,7 @@ $('#new_stock_article').removeAttr('disabled').select2({ placeholder: '#{t '.create_stock_article'}', - data: #{articles_for_select2(@supplier).to_json}, + data: #{articles_for_select2(@supplier.articles).to_json}, createSearchChoice: function(term) { return { id: 'new', @@ -115,12 +115,12 @@ %tfoot %tr %th{:colspan => 5} - - if articles_for_select2(@supplier).empty? + - if @supplier.articles.empty? = link_to t('.create_stock_article'), new_stock_article_path, :remote => true, :class => 'btn' - else %input#new_stock_article{:style => 'width: 500px;'} %tbody - - for article in stock_articles_for_table(@supplier) + - for article in articles_for_table(@supplier.stock_articles) = render :partial => 'stock_article_for_adding', :locals => {:article => article} %h2= t '.title_fill_quantities' diff --git a/app/views/finance/receive/_edit_articles.html.haml b/app/views/finance/receive/_edit_articles.html.haml index b1b32eab..7e99d1be 100644 --- a/app/views/finance/receive/_edit_articles.html.haml +++ b/app/views/finance/receive/_edit_articles.html.haml @@ -1,7 +1,8 @@ +- new_article_data = articles_for_select2(@order.articles, @order_articles.map(&:article_id)) {|a| "#{a.name} (#{a.unit_quantity}⨯#{a.unit})" } - content_for :javascript do :javascript - var new_article_data = #{articles_for_select2(@order, @order_articles.map(&:article_id)).to_json}; + var new_article_data = #{new_article_data.to_json}; function update_delta(input) { var units = $(input).val(); From 94b4454a1b3342b084025220865b69c664578dc9 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 19:21:39 +0100 Subject: [PATCH 11/79] add receive to order screen, and distinguish between finished and closed orders to put it in nicely --- app/controllers/orders_controller.rb | 5 ++- app/views/orders/index.html.haml | 63 ++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 578327f1..0df7eecb 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -8,7 +8,8 @@ class OrdersController < ApplicationController # List orders def index - @open_orders = Order.open + @open_orders = Order.open.includes(:supplier) + @orders_in_progress = Order.finished_not_closed.includes(:supplier) @per_page = 15 if params['sort'] sort = case params['sort'] @@ -20,7 +21,7 @@ class OrdersController < ApplicationController else sort = "ends DESC" end - @orders = Order.page(params[:page]).per(@per_page).order(sort).where("state != 'open'").includes(:supplier) + @orders = Order.closed.page(params[:page]).per(@per_page).includes(:supplier).order(sort) end # Gives a view for the results to a specific order diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 34b428af..6df1d96b 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -10,8 +10,13 @@ %li= link_to supplier.name, new_order_path(supplier_id: supplier.id), tabindex: -1 .well - %h2= t '.open_orders' - - unless @open_orders.empty? + - if not @open_orders.empty? + %h2= t '.open_orders' + - elsif not @orders_in_progress.empty? + %h2= t '.orders_in_progress' + - else + = t '.no_open_orders' + - unless @open_orders.empty? and @orders_in_progress.empty? %table.table.table-striped %thead %tr @@ -20,23 +25,45 @@ %th= heading_helper Order, :note %th{colspan: "2"} %tbody - - for order in @open_orders - - tr_class = " active" if order.expired? - %tr{class: tr_class} - %td= order.name - %td= format_time(order.ends) unless order.ends.nil? - %td= truncate(order.note) - %td= link_to t('.action_end'), finish_order_path(order), - confirm: t('.confirm_end', order: order.name), method: :post, - class: 'btn btn-small btn-success' + - unless @open_orders.empty? + - for order in @open_orders + - tr_class = " active" if order.expired? + %tr{class: tr_class} + %td= order.name + %td= format_time(order.ends) unless order.ends.nil? + %td= truncate(order.note) + %td= link_to t('.action_end'), finish_order_path(order), + confirm: t('.confirm_end', order: order.name), method: :post, + class: 'btn btn-small btn-success' - %td - = link_to t('ui.show'), order, class: 'btn btn-small' - = link_to t('ui.edit'), edit_order_path(order), class: 'btn btn-small' - = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, - class: 'btn btn-small btn-danger' - - else - = t '.no_open_orders' + %td + = link_to t('ui.edit'), edit_order_path(order), class: 'btn btn-small' + = link_to t('ui.show'), order, class: 'btn btn-small' + = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, + class: 'btn btn-small btn-danger' + + - unless @orders_in_progress.empty? + - unless @open_orders.empty? + %tr + %td{colspan: 6} + %h2= t '.orders_in_progress' + - for order in @orders_in_progress + %tr + %td= order.name + %td= format_time(order.ends) + %td= truncate(order.note) + %td + -# TODO btn-success class only if not received before + = link_to t('.receive'), edit_finance_receive_path(order), class: 'btn btn-small btn-success' + + %td + = link_to t('ui.edit'), '#', class: 'btn btn-small disabled' + = link_to t('ui.show'), order, class: 'btn btn-small' + = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, + class: 'btn btn-small btn-danger' + - else + %tr + %td{colspan: 6}= t '.no_orders_in_progress' %h2= t '.ended_orders' #orders_table From d299fa4870bde0b4cf9de5de84822dcba66154cc Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 21:06:05 +0100 Subject: [PATCH 12/79] move receive screen to orders --- app/controllers/finance/receive_controller.rb | 56 ------------------- app/controllers/orders_controller.rb | 54 ++++++++++++++++++ .../_edit_amount.html.haml} | 0 .../_edit_amounts.html.haml} | 10 ++-- .../receive => orders}/add_article.js.erb | 0 app/views/orders/index.html.haml | 2 +- .../receive.html.haml} | 6 +- app/views/orders/show.html.haml | 3 + config/locales/en.yml | 15 ++--- config/routes.rb | 8 +-- 10 files changed, 75 insertions(+), 79 deletions(-) delete mode 100644 app/controllers/finance/receive_controller.rb rename app/views/{finance/receive/_edit_article.html.haml => orders/_edit_amount.html.haml} (100%) rename app/views/{finance/receive/_edit_articles.html.haml => orders/_edit_amounts.html.haml} (87%) rename app/views/{finance/receive => orders}/add_article.js.erb (100%) rename app/views/{finance/receive/edit.html.haml => orders/receive.html.haml} (77%) diff --git a/app/controllers/finance/receive_controller.rb b/app/controllers/finance/receive_controller.rb deleted file mode 100644 index 9afffa85..00000000 --- a/app/controllers/finance/receive_controller.rb +++ /dev/null @@ -1,56 +0,0 @@ -class Finance::ReceiveController < Finance::BaseController - - def edit - @order = Order.find(params[:id]) - @order_articles = @order.order_articles.ordered.includes(:article) - end - - def update - # where to leave remainder during redistribution - rest_to = [] - rest_to << :tolerance if params[:rest_to_tolerance] - rest_to << :stock if params[:rest_to_stock] - rest_to << nil - # count what happens to the articles - counts = [0] * (rest_to.length+2) - cunits = [0] * (rest_to.length+2) - OrderArticle.transaction do - params[:order_articles].each do |oa_id, oa_params| - unless oa_params.blank? - oa = OrderArticle.find(oa_id) - # update attributes; don't use update_attribute because it calls save - # which makes received_changed? not work anymore - oa.attributes = oa_params - counts[0] += 1 if oa.units_received_changed? - cunits[0] += oa.units_received * oa.article.unit_quantity - unless oa.units_received.blank? - oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to - oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 } - end - oa.save! - end - end - - #flash[:notice] = I18n.t('finance.receive.update.notice') - notice = "Order received:" - notice += " #{counts.shift} articles (#{cunits.shift} units) updated" - notice += ", #{counts.shift} (#{cunits.shift}) using tolerance" if params[:rest_to_tolerance] - notice += ", #{counts.shift} (#{cunits.shift}) go to stock if foodsoft would support that" if params[:rest_to_stock] - notice += ", #{counts.shift} (#{cunits.shift}) left over" - flash[:notice] = notice - redirect_to finance_order_index_path - end - end - - # ajax add article - def add_article - @order = Order.find(params[:receive_id]) - @order_article = @order.order_articles.where(:article_id => params[:article_id]).includes(:article).first - # we need to create the order article if it's not part of the current order - if @order_article.nil? - @order_article = @order.order_articles.build({order: @order, article_id: params[:article_id]}) - @order_article.save! - end - end - -end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 0df7eecb..274a76c8 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -106,6 +106,27 @@ class OrdersController < ApplicationController redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message) end + # ajax add article + def add_article + @order = Order.find(params[:id]) + @order_article = @order.order_articles.where(:article_id => params[:article_id]).includes(:article).first + # we need to create the order article if it's not part of the current order + if @order_article.nil? + @order_article = @order.order_articles.build({order: @order, article_id: params[:article_id]}) + @order_article.save! + end + end + + def receive + @order = Order.find(params[:id]) + unless request.post? + @order_articles = @order.order_articles.ordered.includes(:article) + else + flash[:notice] = "Order received: " + update_order_amounts + redirect_to @order + end + end + protected # Renders the fax-text-file @@ -132,4 +153,37 @@ class OrdersController < ApplicationController end text end + + def update_order_amounts + # where to leave remainder during redistribution + rest_to = [] + rest_to << :tolerance if params[:rest_to_tolerance] + rest_to << :stock if params[:rest_to_stock] + rest_to << nil + # count what happens to the articles + counts = [0] * (rest_to.length+2) + cunits = [0] * (rest_to.length+2) + OrderArticle.transaction do + params[:order_articles].each do |oa_id, oa_params| + unless oa_params.blank? + oa = OrderArticle.find(oa_id) + # update attributes; don't use update_attribute because it calls save + # which makes received_changed? not work anymore + oa.attributes = oa_params + counts[0] += 1 if oa.units_received_changed? + cunits[0] += oa.units_received * oa.article.unit_quantity + unless oa.units_received.blank? + oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to + oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 } + end + oa.save! + end + end + end + notice = " #{counts.shift} articles (#{cunits.shift} units) updated" + notice += ", #{counts.shift} (#{cunits.shift}) using tolerance" if params[:rest_to_tolerance] + notice += ", #{counts.shift} (#{cunits.shift}) go to stock if foodsoft would support that" if params[:rest_to_stock] + notice += ", #{counts.shift} (#{cunits.shift}) left over" + end + end diff --git a/app/views/finance/receive/_edit_article.html.haml b/app/views/orders/_edit_amount.html.haml similarity index 100% rename from app/views/finance/receive/_edit_article.html.haml rename to app/views/orders/_edit_amount.html.haml diff --git a/app/views/finance/receive/_edit_articles.html.haml b/app/views/orders/_edit_amounts.html.haml similarity index 87% rename from app/views/finance/receive/_edit_articles.html.haml rename to app/views/orders/_edit_amounts.html.haml index 7e99d1be..d67ba0d6 100644 --- a/app/views/finance/receive/_edit_articles.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -40,7 +40,7 @@ function init_add_article(sel) { $(sel).removeAttr('disabled').select2({ - placeholder: '#{t '.add_article'}', + placeholder: '#{t 'orders.add_article.title'}', data: new_article_data, // TODO implement adding a new article, like in deliveries }).on('change', function(e) { @@ -50,7 +50,7 @@ } $.ajax({ - url: '#{finance_receive_add_article_path(@order)}', + url: '#{add_article_order_path(@order)}', type: 'get', data: {article_id: selectedArticle.id}, contentType: 'application/json; charset=UTF-8' @@ -71,8 +71,8 @@ %table.ordered-articles.table.table-striped.stupidtable %thead %tr - %th.sort{:data => {:sort => 'string'}}= t('.number') - %th.sort{:data => {:sort => 'string'}}= t('.article') + %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true + %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :name %th= heading_helper GroupOrderArticle, :units %th Members %th Ordered @@ -81,7 +81,7 @@ %th %tbody#result_table - @order_articles.each do |order_article| - = render :partial => 'edit_article', :locals => {:order_article => order_article} + = render :partial => 'edit_amount', :locals => {:order_article => order_article} %tfoot %tr %th{:colspan => 8} diff --git a/app/views/finance/receive/add_article.js.erb b/app/views/orders/add_article.js.erb similarity index 100% rename from app/views/finance/receive/add_article.js.erb rename to app/views/orders/add_article.js.erb diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 6df1d96b..9a2ff49f 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -54,7 +54,7 @@ %td= truncate(order.note) %td -# TODO btn-success class only if not received before - = link_to t('.receive'), edit_finance_receive_path(order), class: 'btn btn-small btn-success' + = link_to t('.receive'), receive_order_path(order), class: 'btn btn-small btn-success' %td = link_to t('ui.edit'), '#', class: 'btn btn-small disabled' diff --git a/app/views/finance/receive/edit.html.haml b/app/views/orders/receive.html.haml similarity index 77% rename from app/views/finance/receive/edit.html.haml rename to app/views/orders/receive.html.haml index cdeea92f..6f393225 100644 --- a/app/views/finance/receive/edit.html.haml +++ b/app/views/orders/receive.html.haml @@ -1,8 +1,8 @@ - title "Receiving #{@order.name}" -= form_tag(finance_receive_path(@order), :method => :put) do += form_tag(receive_order_path(@order)) do %section#results - = render 'edit_articles' + = render 'edit_amounts' .form-actions .pull-left @@ -18,6 +18,6 @@ .pull-right = submit_tag t('.submit'), class: 'btn btn-primary' - = link_to t('ui.or_cancel'), finance_order_index_path + = link_to t('ui.or_cancel'), order_path(@order) %p= link_to_top diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index 62e24ae1..73206da1 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -31,6 +31,9 @@ = link_to t('ui.edit'), edit_order_path(@order), class: 'btn' = link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success', confirm: t('.confirm_end', order: @order.name) + - elsif not @order.closed? + -# TODO btn-success class only if not received before + = link_to t('orders.index.receive'), receive_order_path(@order), class: 'btn btn-success' - unless @order.closed? = link_to t('ui.delete'), @order, confirm: t('.confirm_delete'), method: :delete, class: 'btn btn-danger' diff --git a/config/locales/en.yml b/config/locales/en.yml index 12aa5126..397bc4db 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -541,7 +541,6 @@ en: last_edited_by: Last edited by name: Supplier no_closed_orders: At the moment there are no closed orders. - receive: receive state: State summary: changed: Data was changed! @@ -625,15 +624,6 @@ en: ordergroups: account_statement: Account statement new_transaction: New transaction - receive: - add_article: - notice: Article "%{name}" was added to the order. - edit: - submit: Receive order - edit_articles: - add_article: Add article - update: - notice: Updated received article amounts for order update: notice: Invoice was updated foodcoop: @@ -1093,6 +1083,9 @@ en: error_single_group: ! '%{user} is already a member of another ordergroup' invalid_balance: is not a valid number orders: + add_article: + title: Add article + notice: Article "%{name}" was added to the order. articles: article_count: ! 'Ordered articles:' prices: Net/gross price @@ -1138,6 +1131,8 @@ en: warning_ordered_stock: ! 'Warning: Articles marked red have already been ordered/purchased within this open stock order. If you uncheck them here, all existing orders/purchases of these articles will be deleted and it will not be accounted for them.' new: title: Create new order + receive: + submit: Receive order show: action_end: Close! amounts: ! 'Net/gross sum:' diff --git a/config/routes.rb b/config/routes.rb index bd2a4a2b..9d9d508c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,6 +38,10 @@ Foodsoft::Application.routes.draw do member do post :finish post :add_comment + + get :receive + post :receive + get :add_article end end @@ -146,10 +150,6 @@ Foodsoft::Application.routes.draw do resources :order_articles end - resources :receive do - get :add_article - end - resources :group_order_articles do member do put :update_result From 82d1c41e9f8a276ebea0b4ff68fbef8bb566fd77 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 21:34:54 +0100 Subject: [PATCH 13/79] update show order --- .../bootstrap_and_overrides.css.less | 4 ++-- app/views/orders/_articles.html.haml | 23 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 42bafd17..6a598cbf 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -134,10 +134,10 @@ table { } // ordering -span.used { +.used { color: green; } -span.unused { +.unused { color: red; } diff --git a/app/views/orders/_articles.html.haml b/app/views/orders/_articles.html.haml index b0c54837..c1f02fa4 100644 --- a/app/views/orders/_articles.html.haml +++ b/app/views/orders/_articles.html.haml @@ -2,10 +2,12 @@ %thead %tr %th= heading_helper Article, :name - %th= heading_helper Article, :unit_quantity + %th= heading_helper Article, :units %th= t '.prices' - %th= t '.units_ordered' - - unless order.stockit? + - if order.stockit? + %th= t '.units_ordered' + - else + %th= 'Members' %th= t '.units_full' - total_net, total_gross, counter = 0, 0, 0 %tbody @@ -18,13 +20,14 @@ - order_articles.each do |order_article| - net_price = order_article.price.price - gross_price = order_article.price.gross_price - - units = order_article.units_to_order - unit_quantity = order_article.price.unit_quantity + - units = order_article.units - total_net += units * unit_quantity * net_price - total_gross += units * unit_quantity * gross_price - %tr{:class => cycle('even', 'odd', :name => 'articles'), :style => "color: #{units > 0 ? 'green' : 'red'}"} + - cssclass = (units > 0 ? 'used' : (order_article.quantity > 0 ? 'unused' : 'unavailable')) + %tr{:class => cycle('even', 'odd', :name => 'articles') + ' ' + cssclass} %td=h order_article.article.name - %td= "#{unit_quantity} x #{order_article.article.unit}" + %td #{unit_quantity} × #{order_article.article.unit} %td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" - if order.stockit? %td= units @@ -33,7 +36,13 @@ %td= "#{order_article.quantity} + #{order_article.tolerance}" - else %td= "#{order_article.quantity}" - %td= units + - unless order.open? + - units_info = "#{order_article.units_to_order} ordered" + - units_info += ", #{order_article.units_billed} billed" unless order_article.units_billed.nil? + - units_info += ", #{order_article.units_received} received" unless order_article.units_received.nil? + %td{title: units_info} + = units + %i.package pkg %p = t '.prices_sum' = "#{number_to_currency(total_net)} / #{number_to_currency(total_gross)}" From 4fede30a19d067d39b2e2bdafef239ca3ed21e6c Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 21:53:31 +0100 Subject: [PATCH 14/79] hide invoice columns until implemented --- app/views/orders/_edit_amount.html.haml | 2 +- app/views/orders/_edit_amounts.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 9c96f80c..e50640a1 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -8,7 +8,7 @@ %td.name{title: order_title.join("\n")}= order_article.article.name %td #{order_article.article.unit_quantity} × #{order_article.article.unit} %td #{order_article.quantity} + #{order_article.tolerance} - %td + -#%td # TODO implements invoice screen = order_article.units_to_order %i.package pkg %td diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index d67ba0d6..690288dd 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -76,7 +76,7 @@ %th= heading_helper GroupOrderArticle, :units %th Members %th Ordered - %th Invoice + -#%th Invoice # TODO implement invoice screen %th Received %th %tbody#result_table From 873a1ff108dda9182d268e49e1dc9438d0321966 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 21:58:15 +0100 Subject: [PATCH 15/79] update texts --- app/views/orders/index.html.haml | 2 +- config/locales/en.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 9a2ff49f..1a8d7c29 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -65,6 +65,6 @@ %tr %td{colspan: 6}= t '.no_orders_in_progress' -%h2= t '.ended_orders' +%h2= t '.closed_orders' #orders_table = render partial: 'orders' diff --git a/config/locales/en.yml b/config/locales/en.yml index 397bc4db..158673fb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1116,10 +1116,11 @@ en: action_end: Close confirm_delete: Do you really want to delete the order? confirm_end: Do you really want to close the order %{order}? There is no going back. - ended_orders: Closed orders + closed_orders: Settled orders new_order: Create new order no_open_orders: There are currently no open orders. open_orders: Current orders + orders_in_progress: Closed, in progress title: Manage orders model: error_closed: Order was already settled From 84fe791078429127c8d8592ffcf83a5a635594df Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 22:08:02 +0100 Subject: [PATCH 16/79] update balancing screen --- app/helpers/orders_helper.rb | 10 ++++++++++ app/views/finance/balancing/_order_article.html.haml | 5 +++-- app/views/finance/balancing/_orders.html.haml | 2 +- app/views/orders/_articles.html.haml | 6 +----- app/views/orders/index.html.haml | 2 +- app/views/orders/show.html.haml | 2 +- config/locales/en.yml | 1 + 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 9ddcca4a..b9e5698d 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -15,4 +15,14 @@ module OrdersHelper options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: 0)]] options_for_select(options) end + + def units_history_line(order_article) + if order_article.order.open? + nil + else + units_info = "#{order_article.units_to_order} ordered" + units_info += ", #{order_article.units_billed} billed" unless order_article.units_billed.nil? + units_info += ", #{order_article.units_received} received" unless order_article.units_received.nil? + end + end end diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index 6512d0c4..565cff89 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -1,8 +1,9 @@ %td.closed = link_to order_article.article.name, '#', 'data-toggle-this' => "#group_order_articles_#{order_article.id}" %td= order_article.article.order_number -%td - = order_article.units_to_order +%td{title: units_history_line(order_article)} + = order_article.units + %i.package pkg - unless order_article.ordered_quantities_equal_to_group_orders? %span{:style => "color:red;font-weight: bold"} ! %td #{order_article.price.unit_quantity} × #{order_article.article.unit} diff --git a/app/views/finance/balancing/_orders.html.haml b/app/views/finance/balancing/_orders.html.haml index 3c54e340..c25696e7 100644 --- a/app/views/finance/balancing/_orders.html.haml +++ b/app/views/finance/balancing/_orders.html.haml @@ -19,7 +19,7 @@ %td= show_user(order.updated_by) %td - unless order.closed? - = link_to t('.receive'), edit_finance_receive_path(order), class: 'btn btn-mini' + = link_to t('orders.index.action_receive'), receive_order_path(order), class: 'btn btn-mini' = link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary' = link_to t('.close'), close_direct_finance_order_path(order), :confirm => t('.confirm'), :method => :put, class: 'btn btn-mini' diff --git a/app/views/orders/_articles.html.haml b/app/views/orders/_articles.html.haml index c1f02fa4..562f9196 100644 --- a/app/views/orders/_articles.html.haml +++ b/app/views/orders/_articles.html.haml @@ -36,11 +36,7 @@ %td= "#{order_article.quantity} + #{order_article.tolerance}" - else %td= "#{order_article.quantity}" - - unless order.open? - - units_info = "#{order_article.units_to_order} ordered" - - units_info += ", #{order_article.units_billed} billed" unless order_article.units_billed.nil? - - units_info += ", #{order_article.units_received} received" unless order_article.units_received.nil? - %td{title: units_info} + %td{title: units_history_line(order_article)} = units %i.package pkg %p diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 1a8d7c29..c288de84 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -54,7 +54,7 @@ %td= truncate(order.note) %td -# TODO btn-success class only if not received before - = link_to t('.receive'), receive_order_path(order), class: 'btn btn-small btn-success' + = link_to t('.action_receive'), receive_order_path(order), class: 'btn btn-small btn-success' %td = link_to t('ui.edit'), '#', class: 'btn btn-small disabled' diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index 73206da1..ef294091 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -33,7 +33,7 @@ confirm: t('.confirm_end', order: @order.name) - elsif not @order.closed? -# TODO btn-success class only if not received before - = link_to t('orders.index.receive'), receive_order_path(@order), class: 'btn btn-success' + = link_to t('orders.index.action_receive'), receive_order_path(@order), class: 'btn btn-success' - unless @order.closed? = link_to t('ui.delete'), @order, confirm: t('.confirm_delete'), method: :delete, class: 'btn btn-danger' diff --git a/config/locales/en.yml b/config/locales/en.yml index 158673fb..71a7a3ad 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1114,6 +1114,7 @@ en: title: Article index: action_end: Close + action_receive: Receive confirm_delete: Do you really want to delete the order? confirm_end: Do you really want to close the order %{order}? There is no going back. closed_orders: Settled orders From 88f2dad706492376d2eae2c9253b8b73428d512f Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 22:14:52 +0100 Subject: [PATCH 17/79] language change --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 71a7a3ad..089f78fe 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1121,7 +1121,7 @@ en: new_order: Create new order no_open_orders: There are currently no open orders. open_orders: Current orders - orders_in_progress: Closed, in progress + orders_in_progress: In process title: Manage orders model: error_closed: Order was already settled From 7f813f2c0f96339e7543d84b3c21b65cf60df6ac Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 22:16:19 +0100 Subject: [PATCH 18/79] fix order add_article --- app/views/orders/add_article.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/orders/add_article.js.erb b/app/views/orders/add_article.js.erb index c16259eb..7343d501 100644 --- a/app/views/orders/add_article.js.erb +++ b/app/views/orders/add_article.js.erb @@ -6,7 +6,7 @@ $('div.container-fluid').prepend( $('.ordered-articles tr').removeClass('success'); var article_for_adding = $( - '<%= j(render(:partial => 'edit_article', :locals => {:order_article => @order_article})) %>' + '<%= j(render(:partial => 'edit_amount', :locals => {:order_article => @order_article})) %>' ).addClass('success'); $('.ordered-articles tbody').append(article_for_adding); From 3d511ea2fbad0c67220fc92ec909bab2e5f856be Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 22:19:36 +0100 Subject: [PATCH 19/79] only show receive in finance when access to ordering --- app/views/finance/balancing/_orders.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/finance/balancing/_orders.html.haml b/app/views/finance/balancing/_orders.html.haml index c25696e7..0f69abcc 100644 --- a/app/views/finance/balancing/_orders.html.haml +++ b/app/views/finance/balancing/_orders.html.haml @@ -19,7 +19,8 @@ %td= show_user(order.updated_by) %td - unless order.closed? - = link_to t('orders.index.action_receive'), receive_order_path(order), class: 'btn btn-mini' + - if current_user.role_orders? + = link_to t('orders.index.action_receive'), receive_order_path(order), class: 'btn btn-mini' = link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary' = link_to t('.close'), close_direct_finance_order_path(order), :confirm => t('.confirm'), :method => :put, class: 'btn btn-mini' From 68c4affb02058a4cf61be881d074e08fca869055 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 22:22:34 +0100 Subject: [PATCH 20/79] better disabled button --- app/assets/javascripts/application.js | 5 +++++ app/views/orders/index.html.haml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0517c896..e9eeffae 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -107,6 +107,11 @@ $(function() { return false; }); + // Disable action of disabled buttons + $(document).on('click', 'a.disabled', function() { + return false; + }); + // Show and hide loader on ajax callbacks $('*[data-remote]').bind('ajax:beforeSend', function() { $('#loader').show(); diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index c288de84..c705384a 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -57,7 +57,7 @@ = link_to t('.action_receive'), receive_order_path(order), class: 'btn btn-small btn-success' %td - = link_to t('ui.edit'), '#', class: 'btn btn-small disabled' + = link_to t('ui.edit'), '#', class: 'btn btn-small disabled', tabindex: -1 = link_to t('ui.show'), order, class: 'btn btn-small' = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, class: 'btn btn-small btn-danger' From 54e98474b1a3cd9a2b34a7912f845f27c6e0b1dc Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 22:35:01 +0100 Subject: [PATCH 21/79] remove unused helper [ci skip] --- app/helpers/finance/receive_helper.rb | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 app/helpers/finance/receive_helper.rb diff --git a/app/helpers/finance/receive_helper.rb b/app/helpers/finance/receive_helper.rb deleted file mode 100644 index fe844d08..00000000 --- a/app/helpers/finance/receive_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -# :encoding:utf-8: -module Finance::ReceiveHelper -end From bb331f99a7b5db55634699de86265fe811f6fa5a Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 19 Dec 2013 00:45:14 +0100 Subject: [PATCH 22/79] fix units_to_order display [ci skip] --- app/views/orders/_edit_amount.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index e50640a1..2f724753 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -8,10 +8,10 @@ %td.name{title: order_title.join("\n")}= order_article.article.name %td #{order_article.article.unit_quantity} × #{order_article.article.unit} %td #{order_article.quantity} + #{order_article.tolerance} - -#%td # TODO implements invoice screen + %td = order_article.units_to_order %i.package pkg - %td + -#%td # TODO implement invoice screen - unless order_article.units_billed.nil? = order_article.units_billed %i.package pkg From aa6041d33756a7e91e4675d95c0ad2dc1224f8dc Mon Sep 17 00:00:00 2001 From: wvengen Date: Sat, 21 Dec 2013 17:33:06 +0100 Subject: [PATCH 23/79] show all articles in receive screen (not just of this order) --- app/views/orders/_edit_amounts.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 690288dd..311d1e8f 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -1,4 +1,5 @@ -- new_article_data = articles_for_select2(@order.articles, @order_articles.map(&:article_id)) {|a| "#{a.name} (#{a.unit_quantity}⨯#{a.unit})" } +- new_articles = (@order.supplier.articles rescue @order.articles) +- new_article_data = articles_for_select2(new_articles, @order_articles.map(&:article_id)) {|a| "#{a.name} (#{a.unit_quantity}⨯#{a.unit})" } - content_for :javascript do :javascript From 41ea9ed66e1f9eb3bf07380db53a0180dc415f4c Mon Sep 17 00:00:00 2001 From: wvengen Date: Sat, 21 Dec 2013 17:36:25 +0100 Subject: [PATCH 24/79] hide receive screen for stock orders --- app/views/finance/balancing/_orders.html.haml | 5 ++++- app/views/orders/index.html.haml | 5 +++-- app/views/orders/show.html.haml | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/views/finance/balancing/_orders.html.haml b/app/views/finance/balancing/_orders.html.haml index 0f69abcc..a71dd0c5 100644 --- a/app/views/finance/balancing/_orders.html.haml +++ b/app/views/finance/balancing/_orders.html.haml @@ -20,7 +20,10 @@ %td - unless order.closed? - if current_user.role_orders? - = link_to t('orders.index.action_receive'), receive_order_path(order), class: 'btn btn-mini' + - unless order.stockit? + = link_to t('orders.index.action_receive'), receive_order_path(order), class: 'btn btn-mini' + - else + = link_to t('orders.index.action_receive'), '#', class: 'btn btn-mini disabled' = link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary' = link_to t('.close'), close_direct_finance_order_path(order), :confirm => t('.confirm'), :method => :put, class: 'btn btn-mini' diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index c705384a..6b662cfb 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -53,8 +53,9 @@ %td= format_time(order.ends) %td= truncate(order.note) %td - -# TODO btn-success class only if not received before - = link_to t('.action_receive'), receive_order_path(order), class: 'btn btn-small btn-success' + - unless order.stockit? + -# TODO btn-success class only if not received before + = link_to t('.action_receive'), receive_order_path(order), class: 'btn btn-small btn-success' %td = link_to t('ui.edit'), '#', class: 'btn btn-small disabled', tabindex: -1 diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index ef294091..9b40ef8a 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -31,7 +31,7 @@ = link_to t('ui.edit'), edit_order_path(@order), class: 'btn' = link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success', confirm: t('.confirm_end', order: @order.name) - - elsif not @order.closed? + - elsif not @order.closed? and not @order.stockit? -# TODO btn-success class only if not received before = link_to t('orders.index.action_receive'), receive_order_path(@order), class: 'btn btn-success' - unless @order.closed? From a28c6031a44602cb08c91ff4f6ea0c638672f903 Mon Sep 17 00:00:00 2001 From: wvengen Date: Sat, 21 Dec 2013 17:39:20 +0100 Subject: [PATCH 25/79] fix receive exception when input is set to nil --- app/controllers/orders_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 274a76c8..4c476cbe 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -171,8 +171,8 @@ class OrdersController < ApplicationController # which makes received_changed? not work anymore oa.attributes = oa_params counts[0] += 1 if oa.units_received_changed? - cunits[0] += oa.units_received * oa.article.unit_quantity unless oa.units_received.blank? + cunits[0] += oa.units_received * oa.article.unit_quantity oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 } end From 03bb83ecc0991ed224630ed4e42ab5d65d11bd83 Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 23 Dec 2013 12:32:26 +0100 Subject: [PATCH 26/79] show different warning signs for mismatch with ordered and received --- app/models/order_article.rb | 13 ++++++++++--- .../finance/balancing/_order_article.html.haml | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/models/order_article.rb b/app/models/order_article.rb index e9e31b2c..90a5e1c8 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -97,9 +97,16 @@ class OrderArticle < ActiveRecord::Base units_to_order * price.unit_quantity * price.gross_price end - def ordered_quantities_equal_to_group_orders? - # the rescue is a workaround for units_to_order not being defined in integration tests - (units_to_order * price.unit_quantity) == group_orders_sum[:quantity] rescue false + def ordered_quantities_different_from_group_orders?(ordered_mark="!", billed_mark="?", received_mark="?") + if not units_received.nil? + ((units_received * price.unit_quantity) == group_orders_sum[:quantity]) ? false : received_mark + elsif not units_billed.nil? + ((units_billed * price.unit_quantity) == group_orders_sum[:quantity]) ? false : billed_mark + elsif not units_to_order.nil? + ((units_to_order * price.unit_quantity) == group_orders_sum[:quantity]) ? false : ordered_mark + else + nil # can happen in integration tests + end end # redistribute articles over ordergroups diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index 565cff89..1e54e18d 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -4,8 +4,8 @@ %td{title: units_history_line(order_article)} = order_article.units %i.package pkg - - unless order_article.ordered_quantities_equal_to_group_orders? - %span{:style => "color:red;font-weight: bold"} ! + - if s=order_article.ordered_quantities_different_from_group_orders? + %span{:style => "color:red;font-weight: bold"}= s %td #{order_article.price.unit_quantity} × #{order_article.article.unit} %td = number_to_currency(order_article.price.price, :unit => "") From f5bd7a43e425a336123bf97f9f393dfe80176f50 Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 23 Dec 2013 15:25:45 +0100 Subject: [PATCH 27/79] update balancing order article edit screen to support received units --- app/assets/stylesheets/bootstrap_and_overrides.css.less | 7 +++++++ app/views/finance/order_articles/_edit.html.haml | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 6a598cbf..0b16874c 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -308,6 +308,13 @@ i.package { float: none; } } + // allow to add a hint for the whole line + > .help-block { + clear: both; + margin-left: 180px; + position: relative; + top: -2.5ex; + } } } // allow to have indicator text instead of input with same markup diff --git a/app/views/finance/order_articles/_edit.html.haml b/app/views/finance/order_articles/_edit.html.haml index 0dddf8cd..5501575a 100644 --- a/app/views/finance/order_articles/_edit.html.haml +++ b/app/views/finance/order_articles/_edit.html.haml @@ -3,7 +3,13 @@ = link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'} %h3= t '.title' .modal-body - = form.input :units_to_order + .fold-line + = form.input :units_to_order, label: 'Amount ordered', hint: '', input_html: {class: 'input-nano'} + -#= form.input :units_billed, label: 'invoice', input_html: {class: 'input-nano'} + = form.input :units_received, label: 'received', input_html: {class: 'input-nano'} + %p.help-block= t 'simple_form.hints.order_article.units_to_order' + + .foo{style: 'clear:both'} = simple_fields_for :article, @order_article.article do |f| = f.input :name From 81dfe8110c1812fa7865365e48d3ed3a5400c93a Mon Sep 17 00:00:00 2001 From: Julius Date: Mon, 30 Dec 2013 13:09:49 +0100 Subject: [PATCH 28/79] Apply publish/subscribe for OrderArticle#update --- app/controllers/finance/balancing_controller.rb | 6 ++++++ app/views/finance/balancing/new.html.haml | 15 +++++++++++++++ .../balancing/new_on_order_article_update.js.erb | 14 ++++++++++++++ app/views/finance/order_articles/update.js.erb | 9 +++++++++ app/views/finance/order_articles/update.js.haml | 4 ---- config/routes.rb | 2 ++ 6 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 app/views/finance/balancing/new_on_order_article_update.js.erb create mode 100644 app/views/finance/order_articles/update.js.erb delete mode 100644 app/views/finance/order_articles/update.js.haml diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 8de1444c..a0f354b2 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -29,6 +29,12 @@ class Finance::BalancingController < Finance::BaseController render layout: false if request.xhr? end + + def new_on_order_article_update # See publish/subscribe design pattern in /doc. + @order_article = OrderArticle.find(params[:order_article_id]) + + render :layout => false + end def update_summary @order = Order.find(params[:id]) diff --git a/app/views/finance/balancing/new.html.haml b/app/views/finance/balancing/new.html.haml index b8f08129..52828947 100644 --- a/app/views/finance/balancing/new.html.haml +++ b/app/views/finance/balancing/new.html.haml @@ -1,3 +1,18 @@ +- content_for :javascript do + :javascript + $(function() { + // Subscribe to database changes. + // See publish/subscribe design pattern in /doc. + $(document).on('OrderArticle#update', function(e) { + $.ajax({ + url: '#{new_on_order_article_update_finance_order_path(@order)}', + type: 'get', + data: {order_article_id: e.order_article_id}, + contentType: 'application/json; charset=UTF-8' + }); + }); + }); + - title t('.title', name: @order.name) - content_for :sidebar do diff --git a/app/views/finance/balancing/new_on_order_article_update.js.erb b/app/views/finance/balancing/new_on_order_article_update.js.erb new file mode 100644 index 00000000..a3fe6c27 --- /dev/null +++ b/app/views/finance/balancing/new_on_order_article_update.js.erb @@ -0,0 +1,14 @@ +// Handle more advanced DOM update after AJAX database manipulation. +// See publish/subscribe design pattern in /doc. +(function(w) { + $('#order_article_<%= @order_article.id %>').html( + '<%= j render('finance/balancing/order_article', order_article: @order_article) %>' + ); + + $('#group_order_articles_<%= @order_article.id %>').html( + '<%= j render('finance/balancing/group_order_articles', order_article: @order_article) %>' + ); + + $('#summaryChangedWarning').show(); +})(window); + diff --git a/app/views/finance/order_articles/update.js.erb b/app/views/finance/order_articles/update.js.erb new file mode 100644 index 00000000..4c7b7a68 --- /dev/null +++ b/app/views/finance/order_articles/update.js.erb @@ -0,0 +1,9 @@ +// Publish database changes. +// See publish/subscribe design pattern in /doc. +$(document).trigger({ + type: 'OrderArticle#update', + order_article_id: <%= @order_article.id %> +}); + +$('#modalContainer').modal('hide'); + diff --git a/app/views/finance/order_articles/update.js.haml b/app/views/finance/order_articles/update.js.haml deleted file mode 100644 index 36e66ccd..00000000 --- a/app/views/finance/order_articles/update.js.haml +++ /dev/null @@ -1,4 +0,0 @@ -$('#modalContainer').modal('hide'); -$('#order_article_#{@order_article.id}').html('#{j(render('finance/balancing/order_article', order_article: @order_article))}'); -$('#group_order_articles_#{@order_article.id}').html('#{j(render('finance/balancing/group_order_articles', order_article: @order_article))}'); -$('#summaryChangedWarning').show(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9d9d508c..2249c654 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -145,6 +145,8 @@ Foodsoft::Application.routes.draw do get :confirm put :close put :close_direct + + get :new_on_order_article_update end resources :order_articles From cf1e68f11dc0bdd552c1dd9b790b0b800b9e0bfb Mon Sep 17 00:00:00 2001 From: Julius Date: Mon, 30 Dec 2013 14:34:26 +0100 Subject: [PATCH 29/79] Allow to edit OrderArticle in Order#receive form --- app/controllers/orders_controller.rb | 6 ++++ app/views/orders/_edit_amount.html.haml | 11 +++++-- app/views/orders/_edit_amounts.html.haml | 5 +++- app/views/orders/receive.html.haml | 15 ++++++++++ .../receive_on_order_article_update.js.erb | 30 +++++++++++++++++++ config/routes.rb | 2 ++ 6 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 app/views/orders/receive_on_order_article_update.js.erb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 4c476cbe..a9649b8a 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -126,6 +126,12 @@ class OrdersController < ApplicationController redirect_to @order end end + + def receive_on_order_article_update # See publish/subscribe design pattern in /doc. + @order_article = OrderArticle.find(params[:order_article_id]) + + render :layout => false + end protected diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 2f724753..02fb9505 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -1,21 +1,28 @@ +# NOTE: if you modify tiny details here you must also change them in `receive_on_order_article_update.js.erb` = fields_for 'order_articles', order_article, index: order_article.id do |form| - %tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"} + %tr{id: "order_article_#{order_article.id}", class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"} - order_title = [] - order_title.append Article.human_attribute_name(:manufacturer)+': ' + order_article.article.manufacturer unless order_article.article.manufacturer.to_s.empty? - order_title.append Article.human_attribute_name(:note)+': ' + order_article.article.note unless order_article.article.note.to_s.empty? - units_expected = (order_article.units_billed or order_article.units_to_order) %td= order_article.article.order_number %td.name{title: order_title.join("\n")}= order_article.article.name - %td #{order_article.article.unit_quantity} × #{order_article.article.unit} + %td.unit= order_article.article.unit %td #{order_article.quantity} + #{order_article.tolerance} %td = order_article.units_to_order %i.package pkg + %span.article_unit_quantity (× #{order_article.article.unit_quantity}) + %td.article_price= number_to_currency order_article.article.price -#%td # TODO implement invoice screen - unless order_article.units_billed.nil? = order_article.units_billed %i.package pkg %td = form.text_field :units_received, class: 'input-nano package', data: {'units-expected' => units_expected} + %span.article_price_unit_quantity (× #{order_article.article_price.unit_quantity}) / TODO add almost invisible text_field for entering single units + %td.article_price_price= number_to_currency order_article.article_price.price %td.units_delta + %td + = link_to t('ui.edit'), edit_finance_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-mini' diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 311d1e8f..e84b998d 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -74,12 +74,15 @@ %tr %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :name - %th= heading_helper GroupOrderArticle, :units + %th= heading_helper Article, :unit %th Members %th Ordered + %th= heading_helper Article, :price -#%th Invoice # TODO implement invoice screen %th Received + %th= heading_helper ArticlePrice, :price %th + %th= t 'ui.actions' %tbody#result_table - @order_articles.each do |order_article| = render :partial => 'edit_amount', :locals => {:order_article => order_article} diff --git a/app/views/orders/receive.html.haml b/app/views/orders/receive.html.haml index 6f393225..127a8258 100644 --- a/app/views/orders/receive.html.haml +++ b/app/views/orders/receive.html.haml @@ -1,3 +1,18 @@ +- content_for :javascript do + :javascript + $(function() { + // Subscribe to database changes. + // See publish/subscribe design pattern in /doc. + $(document).on('OrderArticle#update', function(e) { + $.ajax({ + url: '#{receive_on_order_article_update_order_path(@order)}', + type: 'get', + data: {order_article_id: e.order_article_id}, + contentType: 'application/json; charset=UTF-8' + }); + }); + }); + - title "Receiving #{@order.name}" = form_tag(receive_order_path(@order)) do diff --git a/app/views/orders/receive_on_order_article_update.js.erb b/app/views/orders/receive_on_order_article_update.js.erb new file mode 100644 index 00000000..be58e641 --- /dev/null +++ b/app/views/orders/receive_on_order_article_update.js.erb @@ -0,0 +1,30 @@ +// Handle more advanced DOM update after AJAX database manipulation. +// See publish/subscribe design pattern in /doc. +(function(w) { + var order_article_entry = $('#order_article_<%= @order_article.id %>'); + + $('.name', order_article_entry).text( + '<%= j @order_article.article.name %>' + ); + + $('.unit', order_article_entry).text( + '<%= j @order_article.article.unit %>' + ); + + $('.article_unit_quantity', order_article_entry).text( + '(× <%= @order_article.article.unit_quantity %>)' + ); + + $('.article_price', order_article_entry).text( + '<%= j number_to_currency @order_article.article.price %>' + ); + + $('.article_price_unit_quantity', order_article_entry).text( + '(× <%= @order_article.article_price.unit_quantity %>)' + ); + + $('.article_price_price', order_article_entry).text( + '<%= j number_to_currency @order_article.article_price.price %>' + ); +})(window); + diff --git a/config/routes.rb b/config/routes.rb index 2249c654..18d955a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -42,6 +42,8 @@ Foodsoft::Application.routes.draw do get :receive post :receive get :add_article + + get :receive_on_order_article_update end end From 9ed906f4253bd0d7389024e033c6d0378ba0f345 Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 31 Dec 2013 09:58:58 +0100 Subject: [PATCH 30/79] Correct haml comment from '#' to '-#' --- app/views/orders/_edit_amount.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 02fb9505..72277c08 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -1,4 +1,4 @@ -# NOTE: if you modify tiny details here you must also change them in `receive_on_order_article_update.js.erb` +-# NOTE: if you modify tiny details here you must also change them in `receive_on_order_article_update.js.erb` = fields_for 'order_articles', order_article, index: order_article.id do |form| %tr{id: "order_article_#{order_article.id}", class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"} - order_title = [] From baa5f16cfcf59b27b0f0c4e23eb7dc3b5366e5b6 Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 31 Dec 2013 11:41:14 +0100 Subject: [PATCH 31/79] Free order_article resource from finance namespace; also unlock for role_orders --- app/controllers/application_controller.rb | 5 +++++ .../{finance => }/order_articles_controller.rb | 4 ++-- app/helpers/{finance => }/order_articles_helper.rb | 2 +- .../balancing/_edit_results_by_articles.html.haml | 2 +- app/views/finance/balancing/_order_article.html.haml | 4 ++-- .../{finance => }/order_articles/_edit.html.haml | 2 +- .../{finance => }/order_articles/_new.html.haml | 2 +- .../{finance => }/order_articles/create.js.haml | 0 .../{finance => }/order_articles/destroy.js.haml | 0 app/views/{finance => }/order_articles/edit.js.haml | 0 app/views/{finance => }/order_articles/new.js.haml | 0 app/views/{finance => }/order_articles/update.js.erb | 0 app/views/orders/_edit_amount.html.haml | 2 +- config/locales/de.yml | 12 ++++++------ config/locales/en.yml | 12 ++++++------ config/locales/fr.yml | 12 ++++++------ config/locales/nl.yml | 12 ++++++------ config/routes.rb | 4 ++-- 18 files changed, 40 insertions(+), 35 deletions(-) rename app/controllers/{finance => }/order_articles_controller.rb (94%) rename app/helpers/{finance => }/order_articles_helper.rb (84%) rename app/views/{finance => }/order_articles/_edit.html.haml (93%) rename app/views/{finance => }/order_articles/_new.html.haml (84%) rename app/views/{finance => }/order_articles/create.js.haml (100%) rename app/views/{finance => }/order_articles/destroy.js.haml (100%) rename app/views/{finance => }/order_articles/edit.js.haml (100%) rename app/views/{finance => }/order_articles/new.js.haml (100%) rename app/views/{finance => }/order_articles/update.js.erb (100%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dcc0f298..44c9b7e2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -47,6 +47,7 @@ class ApplicationController < ActionController::Base when "article_meta" then current_user.role_article_meta? when "suppliers" then current_user.role_suppliers? when "orders" then current_user.role_orders? + when "finance_or_orders" then (current_user.role_finance? || current_user.role_orders?) when "any" then true # no role required else false # any unknown role will always fail end @@ -78,6 +79,10 @@ class ApplicationController < ActionController::Base authenticate('orders') end + def authenticate_finance_or_orders + authenticate('finance_or_orders') + end + # checks if the current_user is member of given group. # if fails the user will redirected to startpage def authenticate_membership_or_admin(group_id = params[:id]) diff --git a/app/controllers/finance/order_articles_controller.rb b/app/controllers/order_articles_controller.rb similarity index 94% rename from app/controllers/finance/order_articles_controller.rb rename to app/controllers/order_articles_controller.rb index cc3351b0..6ce0ebda 100644 --- a/app/controllers/finance/order_articles_controller.rb +++ b/app/controllers/order_articles_controller.rb @@ -1,6 +1,6 @@ -class Finance::OrderArticlesController < ApplicationController +class OrderArticlesController < ApplicationController - before_filter :authenticate_finance + before_filter :authenticate_finance_or_orders layout false # We only use this controller to serve js snippets, no need for layout rendering diff --git a/app/helpers/finance/order_articles_helper.rb b/app/helpers/order_articles_helper.rb similarity index 84% rename from app/helpers/finance/order_articles_helper.rb rename to app/helpers/order_articles_helper.rb index 0ebbc835..4a83d330 100644 --- a/app/helpers/finance/order_articles_helper.rb +++ b/app/helpers/order_articles_helper.rb @@ -1,4 +1,4 @@ -module Finance::OrderArticlesHelper +module OrderArticlesHelper def new_order_articles_collection if @order.stockit? diff --git a/app/views/finance/balancing/_edit_results_by_articles.html.haml b/app/views/finance/balancing/_edit_results_by_articles.html.haml index ab77723e..55dbe212 100644 --- a/app/views/finance/balancing/_edit_results_by_articles.html.haml +++ b/app/views/finance/balancing/_edit_results_by_articles.html.haml @@ -10,7 +10,7 @@ %th= heading_helper Article, :tax %th= heading_helper Article, :deposit %th{:colspan => "2"} - = link_to t('.add_article'), new_finance_order_order_article_path(@order), remote: true, + = link_to t('.add_article'), new_order_order_article_path(@order), remote: true, class: 'btn btn-small' %tbody#result_table - for order_article in @articles diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index 1e54e18d..88cc55fc 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -20,8 +20,8 @@ %td #{order_article.price.tax}% %td= order_article.price.deposit %td - = link_to t('ui.edit'), edit_finance_order_order_article_path(order_article.order, order_article), remote: true, + = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-mini' %td - = link_to t('ui.delete'), finance_order_order_article_path(order_article.order, order_article), method: :delete, + = link_to t('ui.delete'), order_order_article_path(order_article.order, order_article), method: :delete, remote: true, confirm: t('.confirm'), class: 'btn btn-danger btn-mini' diff --git a/app/views/finance/order_articles/_edit.html.haml b/app/views/order_articles/_edit.html.haml similarity index 93% rename from app/views/finance/order_articles/_edit.html.haml rename to app/views/order_articles/_edit.html.haml index 5501575a..8167f08b 100644 --- a/app/views/finance/order_articles/_edit.html.haml +++ b/app/views/order_articles/_edit.html.haml @@ -1,4 +1,4 @@ -= simple_form_for [:finance, @order, @order_article], remote: true do |form| += simple_form_for [@order, @order_article], remote: true do |form| .modal-header = link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'} %h3= t '.title' diff --git a/app/views/finance/order_articles/_new.html.haml b/app/views/order_articles/_new.html.haml similarity index 84% rename from app/views/finance/order_articles/_new.html.haml rename to app/views/order_articles/_new.html.haml index 41619e6e..dd6c8237 100644 --- a/app/views/finance/order_articles/_new.html.haml +++ b/app/views/order_articles/_new.html.haml @@ -1,4 +1,4 @@ -= simple_form_for [:finance, @order, @order_article], remote: true do |form| += simple_form_for [@order, @order_article], remote: true do |form| .modal-header = link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'} %h3= t '.title' diff --git a/app/views/finance/order_articles/create.js.haml b/app/views/order_articles/create.js.haml similarity index 100% rename from app/views/finance/order_articles/create.js.haml rename to app/views/order_articles/create.js.haml diff --git a/app/views/finance/order_articles/destroy.js.haml b/app/views/order_articles/destroy.js.haml similarity index 100% rename from app/views/finance/order_articles/destroy.js.haml rename to app/views/order_articles/destroy.js.haml diff --git a/app/views/finance/order_articles/edit.js.haml b/app/views/order_articles/edit.js.haml similarity index 100% rename from app/views/finance/order_articles/edit.js.haml rename to app/views/order_articles/edit.js.haml diff --git a/app/views/finance/order_articles/new.js.haml b/app/views/order_articles/new.js.haml similarity index 100% rename from app/views/finance/order_articles/new.js.haml rename to app/views/order_articles/new.js.haml diff --git a/app/views/finance/order_articles/update.js.erb b/app/views/order_articles/update.js.erb similarity index 100% rename from app/views/finance/order_articles/update.js.erb rename to app/views/order_articles/update.js.erb diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 72277c08..cbca8838 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -25,4 +25,4 @@ %td.article_price_price= number_to_currency order_article.article_price.price %td.units_delta %td - = link_to t('ui.edit'), edit_finance_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-mini' + = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-mini' diff --git a/config/locales/de.yml b/config/locales/de.yml index 112e6f7a..29765905 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -611,12 +611,6 @@ de: show: back: Züruck title: Rechnung %{number} - order_articles: - edit: - stock_alert: Preise von Lagerartikeln können nicht geändert werden! - title: Artikel aktualisieren - new: - title: Neuer gelieferter Artikel die Bestellung ordergroups: index: new_transaction: Neue Überweisungen eingeben @@ -1083,6 +1077,12 @@ de: model: error_single_group: ! '%{user} ist schon in einer anderen Bestellgruppe' invalid_balance: ist keine gültige Zahl + order_articles: + edit: + stock_alert: Preise von Lagerartikeln können nicht geändert werden! + title: Artikel aktualisieren + new: + title: Neuer gelieferter Artikel der Bestellung orders: articles: article_count: ! 'Bestellte Artikel:' diff --git a/config/locales/en.yml b/config/locales/en.yml index 230aab46..27b62ded 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -615,12 +615,6 @@ en: show: back: Back title: Invoice %{number} - order_articles: - edit: - stock_alert: The price of stock articles cannot be changed! - title: Update article - new: - title: Add delivered article to order ordergroups: index: new_transaction: Add new transactions @@ -1087,6 +1081,12 @@ en: model: error_single_group: ! '%{user} is already a member of another ordergroup' invalid_balance: is not a valid number + order_articles: + edit: + stock_alert: The price of stock articles cannot be changed! + title: Update article + new: + title: Add delivered article to order orders: add_article: title: Add article diff --git a/config/locales/fr.yml b/config/locales/fr.yml index e73a720b..1d188530 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -625,12 +625,6 @@ fr: show: back: Retour title: Facture %{number} - order_articles: - edit: - stock_alert: - title: Mettre à jour la liste des article - new: - title: ordergroups: index: new_transaction: Saisir une nouvelle transaction @@ -1092,6 +1086,12 @@ fr: model: error_single_group: ! '%{user} fait déjà partie d''une autre cellule' invalid_balance: n'est pas un nombre valide + order_articles: + edit: + stock_alert: + title: Mettre à jour la liste des article + new: + title: orders: articles: article_count: ! 'Articles commandés:' diff --git a/config/locales/nl.yml b/config/locales/nl.yml index e11dfebc..8c6299bb 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -615,12 +615,6 @@ nl: show: back: Terug title: Factuur %{number} - order_articles: - edit: - stock_alert: De prijs van voorraadartikelen kan niet aangepast worden! - title: Artikel bijwerken - new: - title: Geleverd artikel aan bestelling toevoegen ordergroups: index: new_transaction: Nieuwe transacties toevoegen @@ -1067,6 +1061,12 @@ nl: model: error_single_group: ! '%{user} behoort al tot een ander huishouden' invalid_balance: is geen geldig nummer + order_articles: + edit: + stock_alert: De prijs van voorraadartikelen kan niet aangepast worden! + title: Artikel bijwerken + new: + title: Geleverd artikel aan bestelling toevoegen orders: articles: article_count: ! 'Bestelde artikelen:' diff --git a/config/routes.rb b/config/routes.rb index 18d955a1..46b4a12b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,6 +45,8 @@ Foodsoft::Application.routes.draw do get :receive_on_order_article_update end + + resources :order_articles end resources :group_orders do @@ -150,8 +152,6 @@ Foodsoft::Application.routes.draw do get :new_on_order_article_update end - - resources :order_articles end resources :group_order_articles do From 01264bc0acc89e7a36bb0c53c644ab5da0fb3ff0 Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 31 Dec 2013 12:27:10 +0100 Subject: [PATCH 32/79] Clean up OrderArticle#new form and related stuff --- app/controllers/order_articles_controller.rb | 8 ++++---- app/models/order_article.rb | 4 +++- app/views/order_articles/_new.html.haml | 3 ++- config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/fr.yml | 1 + config/locales/nl.yml | 1 + 7 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/controllers/order_articles_controller.rb b/app/controllers/order_articles_controller.rb index 6ce0ebda..55d5dcb7 100644 --- a/app/controllers/order_articles_controller.rb +++ b/app/controllers/order_articles_controller.rb @@ -18,11 +18,11 @@ class OrderArticlesController < ApplicationController if @order_article and @order_article.units_to_order == 0 @order_article.units_to_order = 1 else - @order_article = @order.order_articles.build(params[:order_article]) - end - unless @order_article.save - render action: :new + @order_article = OrderArticle.new(params[:order_article]) end + @order_article.save! + rescue + render action: :new end def edit diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 90a5e1c8..c11b49d5 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -199,7 +199,9 @@ class OrderArticle < ActiveRecord::Base private def article_and_price_exist - errors.add(:article, I18n.t('model.order_article.error_price')) if !(article = Article.find(article_id)) || article.fc_price.nil? + errors.add(:article, I18n.t('model.order_article.error_price')) if !(article = Article.find(article_id)) || article.fc_price.nil? + rescue + errors.add(:article, I18n.t('model.order_article.error_price')) end # Associate with current article price if created in a finished order diff --git a/app/views/order_articles/_new.html.haml b/app/views/order_articles/_new.html.haml index dd6c8237..335c7a16 100644 --- a/app/views/order_articles/_new.html.haml +++ b/app/views/order_articles/_new.html.haml @@ -1,9 +1,10 @@ = simple_form_for [@order, @order_article], remote: true do |form| + = form.association :order, as: :hidden .modal-header = link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'} %h3= t '.title' .modal-body - = form.input :article_id, as: :select, collection: new_order_articles_collection, :label => Article.model_name.human # Why do we need the label? + = form.association :article, collection: new_order_articles_collection .modal-footer = link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'} = form.submit class: 'btn btn-primary' diff --git a/config/locales/de.yml b/config/locales/de.yml index 29765905..1a7a4d81 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -78,6 +78,7 @@ de: starts: Läuft vom status: Status order_article: + article: Artikel missing_units: Fehlende Einheiten missing_units_short: Fehlende units_to_order: Menge diff --git a/config/locales/en.yml b/config/locales/en.yml index 27b62ded..dd5ac164 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -78,6 +78,7 @@ en: starts: Starts at status: Status order_article: + article: Article missing_units: Missing units missing_units_short: Missing units_to_order: Amount of units diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 1d188530..7113445c 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -78,6 +78,7 @@ fr: starts: Ouverture le status: order_article: + article: Article missing_units: Unités manquantes missing_units_short: units_to_order: Quantité diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 8c6299bb..ae774c4c 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -78,6 +78,7 @@ nl: starts: Start op status: Status order_article: + article: Artikel missing_units: Missende eenheden missing_units_short: Nodig units_to_order: Aantal eenheden From 5349ee142eba8a85837046582e8ad2712a7498d9 Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 31 Dec 2013 12:35:30 +0100 Subject: [PATCH 33/79] Offer _undeleted_ StockArticles for new OrderArticle only --- app/helpers/order_articles_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/order_articles_helper.rb b/app/helpers/order_articles_helper.rb index 4a83d330..c60ddf56 100644 --- a/app/helpers/order_articles_helper.rb +++ b/app/helpers/order_articles_helper.rb @@ -2,9 +2,9 @@ module OrderArticlesHelper def new_order_articles_collection if @order.stockit? - StockArticle.order('articles.name') + StockArticle.undeleted.reorder('articles.name') else - @order.supplier.articles.undeleted.order('articles.name') + @order.supplier.articles.undeleted.reorder('articles.name') end end end From 59c118a171382598ec9d1edd0edc0f3d4e0ce51d Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 31 Dec 2013 13:25:29 +0100 Subject: [PATCH 34/79] Apply publish/subscribe for OrderArticle#create --- app/controllers/finance/balancing_controller.rb | 6 ++++++ app/views/finance/balancing/new.html.haml | 9 +++++++++ .../balancing/new_on_order_article_create.js.erb | 10 ++++++++++ app/views/order_articles/create.js.erb | 9 +++++++++ app/views/order_articles/create.js.haml | 3 --- config/routes.rb | 1 + 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 app/views/finance/balancing/new_on_order_article_create.js.erb create mode 100644 app/views/order_articles/create.js.erb delete mode 100644 app/views/order_articles/create.js.haml diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index a0f354b2..61f73cef 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -30,6 +30,12 @@ class Finance::BalancingController < Finance::BaseController render layout: false if request.xhr? end + def new_on_order_article_create # See publish/subscribe design pattern in /doc. + @order_article = OrderArticle.find(params[:order_article_id]) + + render :layout => false + end + def new_on_order_article_update # See publish/subscribe design pattern in /doc. @order_article = OrderArticle.find(params[:order_article_id]) diff --git a/app/views/finance/balancing/new.html.haml b/app/views/finance/balancing/new.html.haml index 52828947..f98840d1 100644 --- a/app/views/finance/balancing/new.html.haml +++ b/app/views/finance/balancing/new.html.haml @@ -11,6 +11,15 @@ contentType: 'application/json; charset=UTF-8' }); }); + + $(document).on('OrderArticle#create', function(e) { + $.ajax({ + url: '#{new_on_order_article_create_finance_order_path(@order)}', + type: 'get', + data: {order_article_id: e.order_article_id}, + contentType: 'application/json; charset=UTF-8' + }); + }); }); - title t('.title', name: @order.name) diff --git a/app/views/finance/balancing/new_on_order_article_create.js.erb b/app/views/finance/balancing/new_on_order_article_create.js.erb new file mode 100644 index 00000000..98dc223e --- /dev/null +++ b/app/views/finance/balancing/new_on_order_article_create.js.erb @@ -0,0 +1,10 @@ +// Handle more advanced DOM update after AJAX database manipulation. +// See publish/subscribe design pattern in /doc. +(function(w) { + $('#result_table').prepend( + '<%= j render('finance/balancing/order_article_result', order_article: @order_article) %>' + ); + + $('#summaryChangedWarning').show(); +})(window); + diff --git a/app/views/order_articles/create.js.erb b/app/views/order_articles/create.js.erb new file mode 100644 index 00000000..ff77ce89 --- /dev/null +++ b/app/views/order_articles/create.js.erb @@ -0,0 +1,9 @@ +// Publish database changes. +// See publish/subscribe design pattern in /doc. +$(document).trigger({ + type: 'OrderArticle#create', + order_article_id: <%= @order_article.id %> +}); + +$('#modalContainer').modal('hide'); + diff --git a/app/views/order_articles/create.js.haml b/app/views/order_articles/create.js.haml deleted file mode 100644 index cc43206e..00000000 --- a/app/views/order_articles/create.js.haml +++ /dev/null @@ -1,3 +0,0 @@ -$('#modalContainer').modal('hide'); -$('#result_table').prepend('#{j(render('finance/balancing/order_article_result', order_article: @order_article))}'); -$('#summaryChangedWarning').show(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 46b4a12b..f395252b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -150,6 +150,7 @@ Foodsoft::Application.routes.draw do put :close put :close_direct + get :new_on_order_article_create get :new_on_order_article_update end end From 033aa90698491497ecacbdb8dbb8c8267242c6f8 Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 31 Dec 2013 13:46:25 +0100 Subject: [PATCH 35/79] Use OrderArticle#create in receive form instead of Order#add_article --- app/controllers/order_articles_controller.rb | 2 +- app/controllers/orders_controller.rb | 17 +++---- app/views/orders/_edit_amounts.html.haml | 48 +++---------------- app/views/orders/receive.html.haml | 9 ++++ .../receive_on_order_article_create.js.erb | 13 +++++ config/routes.rb | 2 +- 6 files changed, 36 insertions(+), 55 deletions(-) create mode 100644 app/views/orders/receive_on_order_article_create.js.erb diff --git a/app/controllers/order_articles_controller.rb b/app/controllers/order_articles_controller.rb index 55d5dcb7..f42844e1 100644 --- a/app/controllers/order_articles_controller.rb +++ b/app/controllers/order_articles_controller.rb @@ -16,7 +16,7 @@ class OrderArticlesController < ApplicationController # given mentioning that the article already exists, which is desired. @order_article = @order.order_articles.where(:article_id => params[:order_article][:article_id]).first if @order_article and @order_article.units_to_order == 0 - @order_article.units_to_order = 1 + @order_article.units_to_order = 1 # FIXME: this is ugly if used in the receive form else @order_article = OrderArticle.new(params[:order_article]) end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index a9649b8a..4aab2413 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -106,17 +106,6 @@ class OrdersController < ApplicationController redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message) end - # ajax add article - def add_article - @order = Order.find(params[:id]) - @order_article = @order.order_articles.where(:article_id => params[:article_id]).includes(:article).first - # we need to create the order article if it's not part of the current order - if @order_article.nil? - @order_article = @order.order_articles.build({order: @order, article_id: params[:article_id]}) - @order_article.save! - end - end - def receive @order = Order.find(params[:id]) unless request.post? @@ -127,6 +116,12 @@ class OrdersController < ApplicationController end end + def receive_on_order_article_create # See publish/subscribe design pattern in /doc. + @order_article = OrderArticle.find(params[:order_article_id]) + + render :layout => false + end + def receive_on_order_article_update # See publish/subscribe design pattern in /doc. @order_article = OrderArticle.find(params[:order_article_id]) diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index e84b998d..c7a6496d 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -1,10 +1,6 @@ -- new_articles = (@order.supplier.articles rescue @order.articles) -- new_article_data = articles_for_select2(new_articles, @order_articles.map(&:article_id)) {|a| "#{a.name} (#{a.unit_quantity}⨯#{a.unit})" } - content_for :javascript do :javascript - var new_article_data = #{new_article_data.to_json}; - function update_delta(input) { var units = $(input).val(); var expected = $(input).data('units-expected'); @@ -35,45 +31,13 @@ $('input[data-units-expected]').each(function() { update_delta(this); }); - - init_add_article('#add_article'); }); - function init_add_article(sel) { - $(sel).removeAttr('disabled').select2({ - placeholder: '#{t 'orders.add_article.title'}', - data: new_article_data, - // TODO implement adding a new article, like in deliveries - }).on('change', function(e) { - var selectedArticle = $(e.currentTarget).select2('data'); - if(!selectedArticle) { - return false; - } - - $.ajax({ - url: '#{add_article_order_path(@order)}', - type: 'get', - data: {article_id: selectedArticle.id}, - contentType: 'application/json; charset=UTF-8' - }); - // clear selection - $('#add_article').select2('data', null); - // remove newly added item from list of items - new_article_data = $.grep(new_article_data, function(el, i) { - return el.id != selectedArticle.id; - }); - init_add_article(sel) - return true; - }); - } - - - -%table.ordered-articles.table.table-striped.stupidtable +%table#order_articles.ordered-articles.table.table-striped.stupidtable %thead %tr %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true - %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :name + %th.default-sort.sort{:data => {:sort => 'string'}}= heading_helper Article, :name %th= heading_helper Article, :unit %th Members %th Ordered @@ -83,11 +47,11 @@ %th= heading_helper ArticlePrice, :price %th %th= t 'ui.actions' + %tfoot + %tr + %th{:colspan => 10} + = link_to t('.add_article'), new_order_order_article_path(@order), remote: true, class: 'btn btn-small' %tbody#result_table - @order_articles.each do |order_article| = render :partial => 'edit_amount', :locals => {:order_article => order_article} - %tfoot - %tr - %th{:colspan => 8} - %input#add_article{:style => 'width: 500px;'} diff --git a/app/views/orders/receive.html.haml b/app/views/orders/receive.html.haml index 127a8258..2a130614 100644 --- a/app/views/orders/receive.html.haml +++ b/app/views/orders/receive.html.haml @@ -11,6 +11,15 @@ contentType: 'application/json; charset=UTF-8' }); }); + + $(document).on('OrderArticle#create', function(e) { + $.ajax({ + url: '#{receive_on_order_article_create_order_path(@order)}', + type: 'get', + data: {order_article_id: e.order_article_id}, + contentType: 'application/json; charset=UTF-8' + }); + }); }); - title "Receiving #{@order.name}" diff --git a/app/views/orders/receive_on_order_article_create.js.erb b/app/views/orders/receive_on_order_article_create.js.erb new file mode 100644 index 00000000..1f76238b --- /dev/null +++ b/app/views/orders/receive_on_order_article_create.js.erb @@ -0,0 +1,13 @@ +// Handle more advanced DOM update after AJAX database manipulation. +// See publish/subscribe design pattern in /doc. +(function(w) { + $('#order_articles tr').removeClass('success'); + + var order_article_entry = $( + '<%= j render(partial: 'edit_amount', locals: {order_article: @order_article}) %>' + ).addClass('success'); + + $('#order_articles tbody').append(order_article_entry); + updateSort('#order_articles'); +})(window); + diff --git a/config/routes.rb b/config/routes.rb index f395252b..c3aba42f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,8 +41,8 @@ Foodsoft::Application.routes.draw do get :receive post :receive - get :add_article + get :receive_on_order_article_create get :receive_on_order_article_update end From a384532619881ce721d685d8ee0be5af3d056c29 Mon Sep 17 00:00:00 2001 From: Julius Date: Wed, 1 Jan 2014 16:54:49 +0100 Subject: [PATCH 36/79] Revert some changes of 20adce8a4e2d32548e7d7016dace250dd3e2eb9b --- app/controllers/order_articles_controller.rb | 2 +- app/views/order_articles/_new.html.haml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/order_articles_controller.rb b/app/controllers/order_articles_controller.rb index f42844e1..e9b3321b 100644 --- a/app/controllers/order_articles_controller.rb +++ b/app/controllers/order_articles_controller.rb @@ -18,7 +18,7 @@ class OrderArticlesController < ApplicationController if @order_article and @order_article.units_to_order == 0 @order_article.units_to_order = 1 # FIXME: this is ugly if used in the receive form else - @order_article = OrderArticle.new(params[:order_article]) + @order_article = @order.order_articles.build(params[:order_article]) end @order_article.save! rescue diff --git a/app/views/order_articles/_new.html.haml b/app/views/order_articles/_new.html.haml index 335c7a16..c0d501ab 100644 --- a/app/views/order_articles/_new.html.haml +++ b/app/views/order_articles/_new.html.haml @@ -1,5 +1,4 @@ = simple_form_for [@order, @order_article], remote: true do |form| - = form.association :order, as: :hidden .modal-header = link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'} %h3= t '.title' From 8e52fca3046fdc31f6e4db30a66d8e22f90011aa Mon Sep 17 00:00:00 2001 From: Julius Date: Wed, 1 Jan 2014 23:45:57 +0100 Subject: [PATCH 37/79] Do not set quantity of newly created OrderArticles to 1 --- app/controllers/order_articles_controller.rb | 6 ++-- app/helpers/deliveries_helper.rb | 2 +- app/models/order_article.rb | 1 - .../new_on_order_article_create.js.erb | 10 +++++-- app/views/orders/_edit_amounts.html.haml | 30 ++++++++++++++++++- .../receive_on_order_article_create.js.erb | 4 +++ 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/controllers/order_articles_controller.rb b/app/controllers/order_articles_controller.rb index e9b3321b..9fc340a8 100644 --- a/app/controllers/order_articles_controller.rb +++ b/app/controllers/order_articles_controller.rb @@ -6,7 +6,7 @@ class OrderArticlesController < ApplicationController def new @order = Order.find(params[:order_id]) - @order_article = @order.order_articles.build + @order_article = @order.order_articles.build(params[:order_article]) end def create @@ -15,9 +15,7 @@ class OrderArticlesController < ApplicationController # If order_article is ordered and a new order_article is created, an error message will be # given mentioning that the article already exists, which is desired. @order_article = @order.order_articles.where(:article_id => params[:order_article][:article_id]).first - if @order_article and @order_article.units_to_order == 0 - @order_article.units_to_order = 1 # FIXME: this is ugly if used in the receive form - else + unless (@order_article and @order_article.units_to_order == 0) @order_article = @order.order_articles.build(params[:order_article]) end @order_article.save! diff --git a/app/helpers/deliveries_helper.rb b/app/helpers/deliveries_helper.rb index 03a8f3ec..b2b5e976 100644 --- a/app/helpers/deliveries_helper.rb +++ b/app/helpers/deliveries_helper.rb @@ -16,7 +16,7 @@ module DeliveriesHelper block_given? or block = Proc.new {|a| "#{a.name} (#{number_to_currency a.price}/#{a.unit})" } articles.map do |a| {:id => a.id, :text => block.call(a)} - end + end.unshift({:id => '', :text => ''}) end def articles_for_table(articles) diff --git a/app/models/order_article.rb b/app/models/order_article.rb index c11b49d5..79b18d99 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -208,7 +208,6 @@ class OrderArticle < ActiveRecord::Base def init_from_balancing if order.present? and order.finished? self.article_price = article.article_prices.first - self.units_to_order = 1 end end diff --git a/app/views/finance/balancing/new_on_order_article_create.js.erb b/app/views/finance/balancing/new_on_order_article_create.js.erb index 98dc223e..5e55a80a 100644 --- a/app/views/finance/balancing/new_on_order_article_create.js.erb +++ b/app/views/finance/balancing/new_on_order_article_create.js.erb @@ -1,9 +1,15 @@ // Handle more advanced DOM update after AJAX database manipulation. // See publish/subscribe design pattern in /doc. (function(w) { - $('#result_table').prepend( + $('#order_article_<%= @order_article.id %>').remove(); // just to be sure: remove table row which is added below + + $('#ordered-articles tr').removeClass('success'); + + var order_article_entry = $( '<%= j render('finance/balancing/order_article_result', order_article: @order_article) %>' - ); + ).addClass('success'); + + $('#result_table').prepend(order_article_entry); $('#summaryChangedWarning').show(); })(window); diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index c7a6496d..80933172 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -1,3 +1,5 @@ +- new_articles = (@order.supplier.articles rescue @order.articles) +- new_article_data = articles_for_select2(new_articles, @order_articles.map(&:article_id)) {|a| "#{a.name} (#{a.unit_quantity}⨯#{a.unit})"} - content_for :javascript do :javascript @@ -31,7 +33,31 @@ $('input[data-units-expected]').each(function() { update_delta(this); }); + + init_add_article('#add_article'); }); + + function init_add_article(sel) { + $(sel).removeAttr('disabled').select2({ + placeholder: '#{j t('orders.add_article.title')}', + formatNoMatches: function(term) { return '#{j t('.no_articles_available')}';} + // TODO implement adding a new article, like in deliveries + }).on('change', function(e) { + var selectedArticle = $(e.currentTarget).select2('data'); + if(!selectedArticle) { + return false; + } + + $.ajax({ + url: '#{order_order_articles_path(@order)}', + type: 'post', + data: JSON.stringify({order_article: {article_id: selectedArticle.id}}), + contentType: 'application/json; charset=UTF-8' + }); + + $('#add_article').select2('data', null); + }).select2('data', null); + } %table#order_articles.ordered-articles.table.table-striped.stupidtable %thead @@ -50,7 +76,9 @@ %tfoot %tr %th{:colspan => 10} - = link_to t('.add_article'), new_order_order_article_path(@order), remote: true, class: 'btn btn-small' + %select#add_article{:style => 'width: 500px;'} + - new_article_data.each do |option| + %option{id: "add_article_#{option[:id]}", value: option[:id]}= option[:text] %tbody#result_table - @order_articles.each do |order_article| = render :partial => 'edit_amount', :locals => {:order_article => order_article} diff --git a/app/views/orders/receive_on_order_article_create.js.erb b/app/views/orders/receive_on_order_article_create.js.erb index 1f76238b..ed37975f 100644 --- a/app/views/orders/receive_on_order_article_create.js.erb +++ b/app/views/orders/receive_on_order_article_create.js.erb @@ -1,6 +1,8 @@ // Handle more advanced DOM update after AJAX database manipulation. // See publish/subscribe design pattern in /doc. (function(w) { + $('#order_article_<%= @order_article.id %>').remove(); // just to be sure: remove table row which is added below + $('#order_articles tr').removeClass('success'); var order_article_entry = $( @@ -9,5 +11,7 @@ $('#order_articles tbody').append(order_article_entry); updateSort('#order_articles'); + + $('#add_article_<%= @order_article.article.id %>').remove(); // remove option to add this article })(window); From dd138da1a6389b76b2bee296cd502e076e522919 Mon Sep 17 00:00:00 2001 From: Julius Date: Wed, 1 Jan 2014 23:54:01 +0100 Subject: [PATCH 38/79] Change comment according to 9d61e2e61569159489098eda1bd6c30d7322ce76 --- app/controllers/order_articles_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/order_articles_controller.rb b/app/controllers/order_articles_controller.rb index 9fc340a8..32e13693 100644 --- a/app/controllers/order_articles_controller.rb +++ b/app/controllers/order_articles_controller.rb @@ -11,7 +11,7 @@ class OrderArticlesController < ApplicationController def create @order = Order.find(params[:order_id]) - # The article may with zero units ordered - in that case find and set amount to nonzero. + # The article may be ordered with zero units - in that case do not complain. # If order_article is ordered and a new order_article is created, an error message will be # given mentioning that the article already exists, which is desired. @order_article = @order.order_articles.where(:article_id => params[:order_article][:article_id]).first From a439f26b67d866b06a5c6a44022e13b5c8d09d2a Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 2 Jan 2014 22:30:04 +0100 Subject: [PATCH 39/79] ui design update --- .../stylesheets/bootstrap_and_overrides.css.less | 11 ++++++++--- app/helpers/orders_helper.rb | 9 +++++++++ app/views/orders/_edit_amount.html.haml | 10 ++++------ app/views/orders/_edit_amounts.html.haml | 3 +-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 0b16874c..feccf178 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -263,12 +263,17 @@ tr.unavailable { } // show package icon after amount of package numbers -.package { +input.package { background: url(package-bg.png) no-repeat right center; } i.package { - width: 18px; - color: transparent; // hide text inside + background: url(package-bg.png) no-repeat left center; + min-width: 18px; + padding-left: 20px; + font-style: normal; +} +.package { + color: #999; } .input-nano { width: 30px; diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index b9e5698d..db408790 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -25,4 +25,13 @@ module OrdersHelper units_info += ", #{order_article.units_received} received" unless order_article.units_received.nil? end end + + # can be article or article_price + def pkg_helper(article, icon=true) + if icon + " × #{article.unit_quantity}".html_safe + else + " × #{article.unit_quantity}".html_safe + end + end end diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index cbca8838..d81c537b 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -8,21 +8,19 @@ %td= order_article.article.order_number %td.name{title: order_title.join("\n")}= order_article.article.name %td.unit= order_article.article.unit + %td.article_price= number_to_currency order_article.article.price %td #{order_article.quantity} + #{order_article.tolerance} %td = order_article.units_to_order - %i.package pkg - %span.article_unit_quantity (× #{order_article.article.unit_quantity}) - %td.article_price= number_to_currency order_article.article.price + = pkg_helper order_article.article -#%td # TODO implement invoice screen - unless order_article.units_billed.nil? = order_article.units_billed - %i.package pkg + = pkg_helper order_article.article %td = form.text_field :units_received, class: 'input-nano package', data: {'units-expected' => units_expected} - %span.article_price_unit_quantity (× #{order_article.article_price.unit_quantity}) + = pkg_helper order_article.article_price, false / TODO add almost invisible text_field for entering single units - %td.article_price_price= number_to_currency order_article.article_price.price %td.units_delta %td = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-mini' diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 80933172..84f5b644 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -65,12 +65,11 @@ %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true %th.default-sort.sort{:data => {:sort => 'string'}}= heading_helper Article, :name %th= heading_helper Article, :unit + %th= heading_helper Article, :price %th Members %th Ordered - %th= heading_helper Article, :price -#%th Invoice # TODO implement invoice screen %th Received - %th= heading_helper ArticlePrice, :price %th %th= t 'ui.actions' %tfoot From 7aae7f4d5564cdf6e7e7bdd51657b560ad8f8b8e Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 10:07:03 +0100 Subject: [PATCH 40/79] Add result_computed to GroupOrderArticle --- ...02170431_add_result_computed_to_group_order_articles.rb | 7 +++++++ db/schema.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20140102170431_add_result_computed_to_group_order_articles.rb diff --git a/db/migrate/20140102170431_add_result_computed_to_group_order_articles.rb b/db/migrate/20140102170431_add_result_computed_to_group_order_articles.rb new file mode 100644 index 00000000..76d92102 --- /dev/null +++ b/db/migrate/20140102170431_add_result_computed_to_group_order_articles.rb @@ -0,0 +1,7 @@ +class AddResultComputedToGroupOrderArticles < ActiveRecord::Migration + def change + add_column :group_order_articles, :result_computed, + :decimal, :precision => 8, :scale => 3, + :null => false, :default => 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 3093e9a1..b7803b3b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130930132511) do +ActiveRecord::Schema.define(:version => 20140102170431) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -101,6 +101,7 @@ ActiveRecord::Schema.define(:version => 20130930132511) do t.integer "tolerance", :default => 0, :null => false t.datetime "updated_on", :null => false t.decimal "result", :precision => 8, :scale => 3 + t.decimal "result_computed", :precision => 8, :scale => 3 end add_index "group_order_articles", ["group_order_id", "order_article_id"], :name => "goa_index", :unique => true From 98f59a3de3c708fd460e35d3fab61e4db808f3a5 Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 10:33:09 +0100 Subject: [PATCH 41/79] Readonly receive input if GroupOrderArticle result has manually been changed Conflicts: app/helpers/orders_helper.rb app/views/orders/_edit_amount.html.haml --- app/controllers/orders_controller.rb | 12 +++++++----- app/helpers/orders_helper.rb | 10 ++++++++++ app/models/group_order_article.rb | 10 ++++++++-- app/models/order_article.rb | 5 +++++ app/views/orders/_edit_amount.html.haml | 5 +++-- app/views/orders/_edit_amounts.html.haml | 8 ++++++++ config/locales/en.yml | 2 ++ 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 4aab2413..23788f86 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -171,11 +171,13 @@ class OrdersController < ApplicationController # update attributes; don't use update_attribute because it calls save # which makes received_changed? not work anymore oa.attributes = oa_params - counts[0] += 1 if oa.units_received_changed? - unless oa.units_received.blank? - cunits[0] += oa.units_received * oa.article.unit_quantity - oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to - oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 } + if oa.units_received_changed? + counts[0] += 1 + unless oa.units_received.blank? + cunits[0] += oa.units_received * oa.article.unit_quantity + oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to + oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 } + end end oa.save! end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index db408790..2d2a78fa 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -34,4 +34,14 @@ module OrdersHelper " × #{article.unit_quantity}".html_safe end end + + def receive_input_field(form) + order_article = form.object + units_expected = (order_article.units_billed or order_article.units_to_order) + form.text_field :units_received, class: 'input-nano package units_received', + data: {'units-expected' => units_expected}, + readonly: order_article.result_manually_changed? ? "readonly" : nil, + title: order_article.result_manually_changed? ? t('.locked_to_protect_manual_update') : nil, + autocomplete: 'off' + end end diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 4d7bff09..83693e10 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -165,9 +165,11 @@ class GroupOrderArticle < ActiveRecord::Base self[:result] || calculate_result[type] end - # This is used during order.finish!. + # This is used for automatic distribution, e.g., in order.finish! or when receiving orders def save_results!(article_total = nil) - self.update_attribute(:result, calculate_result(article_total)[:total]) + new_result = calculate_result(article_total)[:total] + self.update_attribute(:result_computed, new_result) + self.update_attribute(:result, new_result) end # Returns total price for this individual article @@ -186,6 +188,10 @@ class GroupOrderArticle < ActiveRecord::Base end end + # Check if the result deviates from the result_computed + def result_manually_changed? + result != result_computed + end end diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 79b18d99..440ab896 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -195,6 +195,11 @@ class OrderArticle < ActiveRecord::Base units = 0 if units < 0 units end + + # Check if the result of any associated GroupOrderArticle was overridden manually + def result_manually_changed? + group_order_articles.any? {|goa| goa.result_manually_changed?} + end private diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index d81c537b..6aee7ed4 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -4,7 +4,6 @@ - order_title = [] - order_title.append Article.human_attribute_name(:manufacturer)+': ' + order_article.article.manufacturer unless order_article.article.manufacturer.to_s.empty? - order_title.append Article.human_attribute_name(:note)+': ' + order_article.article.note unless order_article.article.note.to_s.empty? - - units_expected = (order_article.units_billed or order_article.units_to_order) %td= order_article.article.order_number %td.name{title: order_title.join("\n")}= order_article.article.name %td.unit= order_article.article.unit @@ -18,8 +17,10 @@ = order_article.units_billed = pkg_helper order_article.article %td - = form.text_field :units_received, class: 'input-nano package', data: {'units-expected' => units_expected} + = receive_input_field(form) = pkg_helper order_article.article_price, false + - if order_article.result_manually_changed? + %input{type: :button, value: t('.override', default: 'Override'), class: 'btn btn-small unlocker'} / TODO add almost invisible text_field for entering single units %td.units_delta %td diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 84f5b644..9c1adb5d 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -35,6 +35,8 @@ }); init_add_article('#add_article'); + + $('.unlocker', '#order_articles tbody').on('click', unlock_receive_input_field); }); function init_add_article(sel) { @@ -58,6 +60,12 @@ $('#add_article').select2('data', null); }).select2('data', null); } + + function unlock_receive_input_field() { + var order_article_entry = $(this).closest('tr'); + $('.units_received', order_article_entry).removeAttr('readonly'); + $(this).remove(); + } %table#order_articles.ordered-articles.table.table-striped.stupidtable %thead diff --git a/config/locales/en.yml b/config/locales/en.yml index dd5ac164..8919ab1d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1102,6 +1102,8 @@ en: notice: The order was created. edit: title: Edit order + edit_amount: + locked_to_protect_manual_update: The distribution of this article among the ordergroups was changed manually. This field is locked in order to protect those changes. fax: amount: Amount articles: Articles From 2ec3d382389cd6b3389b4491d86c6477fd3a39a7 Mon Sep 17 00:00:00 2001 From: Julius Date: Thu, 2 Jan 2014 21:17:55 +0100 Subject: [PATCH 42/79] Set readonly property with javascript by .prop instead of .attr --- app/views/orders/_edit_amounts.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 9c1adb5d..ab143f92 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -62,8 +62,7 @@ } function unlock_receive_input_field() { - var order_article_entry = $(this).closest('tr'); - $('.units_received', order_article_entry).removeAttr('readonly'); + $('.units_received', $(this).closest('tr')).prop('readonly', false); $(this).remove(); } From 0af8a065a1027a55b245443eeb612d1730eea58e Mon Sep 17 00:00:00 2001 From: Julius Date: Thu, 2 Jan 2014 21:36:45 +0100 Subject: [PATCH 43/79] Fix calculation of OrderArticle.total_price and .total_gross_price --- app/models/order_article.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 440ab896..84612616 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -89,12 +89,12 @@ class OrderArticle < ActiveRecord::Base # Calculate price for ordered quantity. def total_price - units_to_order * price.unit_quantity * price.price + units * price.unit_quantity * price.price end # Calculate gross price for ordered qunatity. def total_gross_price - units_to_order * price.unit_quantity * price.gross_price + units * price.unit_quantity * price.gross_price end def ordered_quantities_different_from_group_orders?(ordered_mark="!", billed_mark="?", received_mark="?") From f230d390554ccd875d0f410b34f993600730849a Mon Sep 17 00:00:00 2001 From: Julius Date: Thu, 2 Jan 2014 21:59:08 +0100 Subject: [PATCH 44/79] Merge price columns in receive form into one Conflicts: app/views/orders/_edit_amount.html.haml --- app/helpers/orders_helper.rb | 5 +++ app/views/orders/_edit_amount.html.haml | 6 ++-- .../receive_on_order_article_update.js.erb | 35 ++++++++----------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 2d2a78fa..46f9b079 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -35,6 +35,11 @@ module OrdersHelper end end + def article_price_change_hint(order_article) + return nil if order_article.article.price == order_article.article_price.price + "".html_safe + end + def receive_input_field(form) order_article = form.object units_expected = (order_article.units_billed or order_article.units_to_order) diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 6aee7ed4..218316e6 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -7,7 +7,9 @@ %td= order_article.article.order_number %td.name{title: order_title.join("\n")}= order_article.article.name %td.unit= order_article.article.unit - %td.article_price= number_to_currency order_article.article.price + %td.article_price + = number_to_currency order_article.article.price + = article_price_change_hint(order_article) %td #{order_article.quantity} + #{order_article.tolerance} %td = order_article.units_to_order @@ -16,7 +18,7 @@ - unless order_article.units_billed.nil? = order_article.units_billed = pkg_helper order_article.article - %td + %td.units_received_cell = receive_input_field(form) = pkg_helper order_article.article_price, false - if order_article.result_manually_changed? diff --git a/app/views/orders/receive_on_order_article_update.js.erb b/app/views/orders/receive_on_order_article_update.js.erb index be58e641..003c79df 100644 --- a/app/views/orders/receive_on_order_article_update.js.erb +++ b/app/views/orders/receive_on_order_article_update.js.erb @@ -1,30 +1,25 @@ // Handle more advanced DOM update after AJAX database manipulation. // See publish/subscribe design pattern in /doc. (function(w) { - var order_article_entry = $('#order_article_<%= @order_article.id %>'); + // get old element and update the cell which is reused + var old_order_article_entry = $('#order_article_<%= @order_article.id %>'); - $('.name', order_article_entry).text( - '<%= j @order_article.article.name %>' - ); - - $('.unit', order_article_entry).text( - '<%= j @order_article.article.unit %>' - ); - - $('.article_unit_quantity', order_article_entry).text( - '(× <%= @order_article.article.unit_quantity %>)' - ); - - $('.article_price', order_article_entry).text( - '<%= j number_to_currency @order_article.article.price %>' - ); - - $('.article_price_unit_quantity', order_article_entry).text( + $('.article_price_unit_quantity', old_order_article_entry).text( '(× <%= @order_article.article_price.unit_quantity %>)' ); - $('.article_price_price', order_article_entry).text( - '<%= j number_to_currency @order_article.article_price.price %>' + // render new element and inject dynamic cell + var new_order_article_entry = $( + '<%= j render(partial: 'edit_amount', locals: {order_article: @order_article}) %>' ); + + $('td.units_received_cell', new_order_article_entry).replaceWith( + $('td.units_received_cell', old_order_article_entry) + ); + + // finally replace the OrderArticle entry + old_order_article_entry.replaceWith(new_order_article_entry); + + update_delta($('input.units_received', new_order_article_entry)); })(window); From 5ead0fb4414f19bad00289ca832741a9acdad8fc Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 10:44:57 +0100 Subject: [PATCH 45/79] show correct price --- app/views/orders/_edit_amount.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 218316e6..69d251cd 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -8,7 +8,7 @@ %td.name{title: order_title.join("\n")}= order_article.article.name %td.unit= order_article.article.unit %td.article_price - = number_to_currency order_article.article.price + = number_to_currency order_article.article_price.price = article_price_change_hint(order_article) %td #{order_article.quantity} + #{order_article.tolerance} %td From f1ae2724c651b6596e5fac2a97b3e4bd2ab2b87e Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 10:45:15 +0100 Subject: [PATCH 46/79] fix unit quantity display after ajax update --- app/views/orders/receive_on_order_article_update.js.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/orders/receive_on_order_article_update.js.erb b/app/views/orders/receive_on_order_article_update.js.erb index 003c79df..dd434585 100644 --- a/app/views/orders/receive_on_order_article_update.js.erb +++ b/app/views/orders/receive_on_order_article_update.js.erb @@ -4,8 +4,8 @@ // get old element and update the cell which is reused var old_order_article_entry = $('#order_article_<%= @order_article.id %>'); - $('.article_price_unit_quantity', old_order_article_entry).text( - '(× <%= @order_article.article_price.unit_quantity %>)' + $('td.units_received_cell .package', old_order_article_entry).text( + '× <%= @order_article.article_price.unit_quantity %>' ); // render new element and inject dynamic cell From 014a62aa110c7da3c5f459800f4b2b4c951aa858 Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 10:59:42 +0100 Subject: [PATCH 47/79] use disabled property for input and fix style --- app/assets/stylesheets/bootstrap_and_overrides.css.less | 5 +++++ app/helpers/orders_helper.rb | 2 +- app/views/orders/_edit_amounts.html.haml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index feccf178..de47897f 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -265,6 +265,10 @@ tr.unavailable { // show package icon after amount of package numbers input.package { background: url(package-bg.png) no-repeat right center; + // disabled and readonly definitions though + &[disabled], &[readonly] { + background-color: @inputDisabledBackground; + } } i.package { background: url(package-bg.png) no-repeat left center; @@ -275,6 +279,7 @@ i.package { .package { color: #999; } + .input-nano { width: 30px; } diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 46f9b079..3d2d5bbe 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -45,7 +45,7 @@ module OrdersHelper units_expected = (order_article.units_billed or order_article.units_to_order) form.text_field :units_received, class: 'input-nano package units_received', data: {'units-expected' => units_expected}, - readonly: order_article.result_manually_changed? ? "readonly" : nil, + disabled: order_article.result_manually_changed?, title: order_article.result_manually_changed? ? t('.locked_to_protect_manual_update') : nil, autocomplete: 'off' end diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index ab143f92..ef8db3df 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -62,7 +62,7 @@ } function unlock_receive_input_field() { - $('.units_received', $(this).closest('tr')).prop('readonly', false); + $('.units_received', $(this).closest('tr')).prop('disabled', false); $(this).remove(); } From 4c9e84ecc64c26f06c0177c93107fa126ebd11f3 Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 11:26:39 +0100 Subject: [PATCH 48/79] change layout of receive unlock --- app/views/orders/_edit_amount.html.haml | 7 ++++--- config/locales/en.yml | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 69d251cd..d8488555 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -21,9 +21,10 @@ %td.units_received_cell = receive_input_field(form) = pkg_helper order_article.article_price, false - - if order_article.result_manually_changed? - %input{type: :button, value: t('.override', default: 'Override'), class: 'btn btn-small unlocker'} / TODO add almost invisible text_field for entering single units %td.units_delta %td - = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-mini' + = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-small' + - if order_article.result_manually_changed? + = button_tag nil, class: 'btn btn-small unlocker', title: t('.locked_to_protect_unlock_button') do + %i.icon-unlock diff --git a/config/locales/en.yml b/config/locales/en.yml index 8919ab1d..57642601 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1103,7 +1103,8 @@ en: edit: title: Edit order edit_amount: - locked_to_protect_manual_update: The distribution of this article among the ordergroups was changed manually. This field is locked in order to protect those changes. + locked_to_protect_manual_update: The distribution of this article among the ordergroups was changed manually. This field is locked in order to protect those changes. To redistribute anyway, press the unlock button and change the amount. + locked_to_protect_unlock_button: Press this button to unlock the received field. Any previous manual changes will be overwritten and the article will be redistributed over the ordergroups. fax: amount: Amount articles: Articles From 9219d099c89165269b5d9360607b7e9c9ecaeed4 Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 12:42:36 +0100 Subject: [PATCH 49/79] ui update for packages display --- .../bootstrap_and_overrides.css.less | 22 +++++++++++++------ app/helpers/orders_helper.rb | 7 ++++-- .../_edit_results_by_articles.html.haml | 2 +- .../balancing/_order_article.html.haml | 4 ++-- app/views/orders/_articles.html.haml | 10 +++++---- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index de47897f..031a40fa 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -55,6 +55,12 @@ body { @mainRedColor: #ED0606; +@articleUsedColor: green; +@articleUnusedColor: red; +@articleUnavailColor: #999; +@articleUpdatedColor: #468847; + + .logo { margin: 10px 0 0 30px; float: left; @@ -135,10 +141,10 @@ table { // ordering .used { - color: green; + color: @articleUsedColor; } .unused { - color: red; + color: @articleUnusedColor; } #order-footer, .article-info { @@ -202,11 +208,11 @@ tr.order-article:hover .article-info { // ********* Articles tr.just-updated { - color: #468847; + color: @articleUpdatedColor; } tr.unavailable { - color: #999; + color: @articleUnavailColor; } // articles edit all @@ -276,9 +282,11 @@ i.package { padding-left: 20px; font-style: normal; } -.package { - color: #999; -} +@packageDim: 35%; +.package { color: tint(@textColor, @packageDim); } +.used .package { color: tint(@articleUsedColor, @packageDim); } +.unused .package { color: tint(@articleUnusedColor, @packageDim); } +.unavailable .package { color: @articleUnavailColor; } .input-nano { width: 30px; diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 3d2d5bbe..d1b67932 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -28,6 +28,7 @@ module OrdersHelper # can be article or article_price def pkg_helper(article, icon=true) + return nil if article.unit_quantity == 1 if icon " × #{article.unit_quantity}".html_safe else @@ -35,9 +36,11 @@ module OrdersHelper end end - def article_price_change_hint(order_article) + def article_price_change_hint(order_article, gross=false) return nil if order_article.article.price == order_article.article_price.price - "".html_safe + title = "#{t('.old_price')}: #{number_to_currency order_article.article.price}" + title += " / #{number_to_currency order_article.article.gross_price}" if gross + "".html_safe end def receive_input_field(form) diff --git a/app/views/finance/balancing/_edit_results_by_articles.html.haml b/app/views/finance/balancing/_edit_results_by_articles.html.haml index 55dbe212..05e06071 100644 --- a/app/views/finance/balancing/_edit_results_by_articles.html.haml +++ b/app/views/finance/balancing/_edit_results_by_articles.html.haml @@ -4,7 +4,7 @@ %th= sort_link_helper Article.model_name.human, "name" %th= sort_link_helper Article.human_attribute_name(:order_number_short), "order_number" %th= t('.amount') - %th= heading_helper Article, :units + %th= heading_helper Article, :unit %th= t('.net') %th= t('.gross') %th= heading_helper Article, :tax diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index 88cc55fc..24125544 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -3,10 +3,10 @@ %td= order_article.article.order_number %td{title: units_history_line(order_article)} = order_article.units - %i.package pkg + = pkg_helper order_article.article_price - if s=order_article.ordered_quantities_different_from_group_orders? %span{:style => "color:red;font-weight: bold"}= s -%td #{order_article.price.unit_quantity} × #{order_article.article.unit} +%td #{order_article.article.unit} %td = number_to_currency(order_article.price.price, :unit => "") :plain diff --git a/app/views/orders/_articles.html.haml b/app/views/orders/_articles.html.haml index 562f9196..df0e9a4b 100644 --- a/app/views/orders/_articles.html.haml +++ b/app/views/orders/_articles.html.haml @@ -2,7 +2,7 @@ %thead %tr %th= heading_helper Article, :name - %th= heading_helper Article, :units + %th= heading_helper Article, :unit %th= t '.prices' - if order.stockit? %th= t '.units_ordered' @@ -27,8 +27,10 @@ - cssclass = (units > 0 ? 'used' : (order_article.quantity > 0 ? 'unused' : 'unavailable')) %tr{:class => cycle('even', 'odd', :name => 'articles') + ' ' + cssclass} %td=h order_article.article.name - %td #{unit_quantity} × #{order_article.article.unit} - %td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" + %td= order_article.article.unit + %td + = "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" + = article_price_change_hint(order_article, gross: true) - if order.stockit? %td= units - else @@ -38,7 +40,7 @@ %td= "#{order_article.quantity}" %td{title: units_history_line(order_article)} = units - %i.package pkg + = pkg_helper order_article.price %p = t '.prices_sum' = "#{number_to_currency(total_net)} / #{number_to_currency(total_gross)}" From ebe2966895ca718fc949da2c23fe2d8d3b9fef01 Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 12:50:49 +0100 Subject: [PATCH 50/79] fix migration, complements 7aae7f4d5564cdf6e7e7bdd51657b560ad8f8b8e --- ...140102170431_add_result_computed_to_group_order_articles.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/migrate/20140102170431_add_result_computed_to_group_order_articles.rb b/db/migrate/20140102170431_add_result_computed_to_group_order_articles.rb index 76d92102..e4503fa0 100644 --- a/db/migrate/20140102170431_add_result_computed_to_group_order_articles.rb +++ b/db/migrate/20140102170431_add_result_computed_to_group_order_articles.rb @@ -1,7 +1,6 @@ class AddResultComputedToGroupOrderArticles < ActiveRecord::Migration def change add_column :group_order_articles, :result_computed, - :decimal, :precision => 8, :scale => 3, - :null => false, :default => 0 + :decimal, :precision => 8, :scale => 3 end end From 438de974644b8e1d7ad683d733330047a8663a70 Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 13:00:14 +0100 Subject: [PATCH 51/79] fix non-closed order display --- app/helpers/orders_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index d1b67932..fff67eff 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -37,7 +37,7 @@ module OrdersHelper end def article_price_change_hint(order_article, gross=false) - return nil if order_article.article.price == order_article.article_price.price + return nil if order_article.article.price == order_article.price.price title = "#{t('.old_price')}: #{number_to_currency order_article.article.price}" title += " / #{number_to_currency order_article.article.gross_price}" if gross "".html_safe From 1a5dc3ebe4d6e9be1dafe860d03c9c10eb08169b Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 13:03:28 +0100 Subject: [PATCH 52/79] consider group_order_article without result not manually changed --- app/models/group_order_article.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 83693e10..74bb6210 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -190,7 +190,7 @@ class GroupOrderArticle < ActiveRecord::Base # Check if the result deviates from the result_computed def result_manually_changed? - result != result_computed + result != result_computed unless result.nil? end end From 133429720c1ad9e69d2a7ababd52095941345d3c Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 14:11:50 +0100 Subject: [PATCH 53/79] old price display tweaks --- .../bootstrap_and_overrides.css.less | 35 ++++++++++++------- app/helpers/orders_helper.rb | 2 +- config/locales/en.yml | 1 + 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 031a40fa..a0641542 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -30,7 +30,19 @@ body { // Example: // @linkColor: #ff0000; -// Custom styles + +// main ui colours +@mainRedColor: #ED0606; + +// article status +@articleUsedColor: green; +@articleUnusedColor: red; +@articleUnavailColor: #999; +@articleUpdatedColor: #468847; + +// dim colors by this amount when the information is less important +@nonessentialDim: 35%; + // Fix empty dd tags in horizontal dl, see https://github.com/twitter/bootstrap/issues/4062 .dl-horizontal { @@ -53,13 +65,6 @@ body { margin-bottom: 0; } -@mainRedColor: #ED0606; - -@articleUsedColor: green; -@articleUnusedColor: red; -@articleUnavailColor: #999; -@articleUpdatedColor: #468847; - .logo { margin: 10px 0 0 30px; @@ -258,6 +263,13 @@ tr.unavailable { } } +// it's a bit distracting +.icon-asterisk { + font-size: 80%; + vertical-align: middle; + padding-bottom: 0.4ex; +} + // allow buttons as input add-on (with proper height) .input-append button.add-on { height: inherit; @@ -282,10 +294,9 @@ i.package { padding-left: 20px; font-style: normal; } -@packageDim: 35%; -.package { color: tint(@textColor, @packageDim); } -.used .package { color: tint(@articleUsedColor, @packageDim); } -.unused .package { color: tint(@articleUnusedColor, @packageDim); } +.package { color: tint(@textColor, @nonessentialDim); } +.used .package { color: tint(@articleUsedColor, @nonessentialDim); } +.unused .package { color: tint(@articleUnusedColor, @nonessentialDim); } .unavailable .package { color: @articleUnavailColor; } .input-nano { diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index fff67eff..8e76d93e 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -38,7 +38,7 @@ module OrdersHelper def article_price_change_hint(order_article, gross=false) return nil if order_article.article.price == order_article.price.price - title = "#{t('.old_price')}: #{number_to_currency order_article.article.price}" + title = "#{t('helpers.orders.old_price')}: #{number_to_currency order_article.article.price}" title += " / #{number_to_currency order_article.article.gross_price}" if gross "".html_safe end diff --git a/config/locales/en.yml b/config/locales/en.yml index 57642601..351b19bf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -738,6 +738,7 @@ en: new_invoice: New invoice show_invoice: Show invoice orders: + old_price: Old price option_choose: Choose supplier/stock option_stock: Stock order_pdf: Create PDF From b800da9b9b68f58263f1cd3663b17c5b969c215d Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 14:52:44 +0100 Subject: [PATCH 54/79] use helper in ajax update too --- app/views/orders/receive_on_order_article_update.js.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/orders/receive_on_order_article_update.js.erb b/app/views/orders/receive_on_order_article_update.js.erb index dd434585..187195fe 100644 --- a/app/views/orders/receive_on_order_article_update.js.erb +++ b/app/views/orders/receive_on_order_article_update.js.erb @@ -4,8 +4,8 @@ // get old element and update the cell which is reused var old_order_article_entry = $('#order_article_<%= @order_article.id %>'); - $('td.units_received_cell .package', old_order_article_entry).text( - '× <%= @order_article.article_price.unit_quantity %>' + $('td.units_received_cell span.package', old_order_article_entry).replaceWith( + '<%= j pkg_helper(@order_article.article_price, false) %>' ); // render new element and inject dynamic cell From aa57cee96f75854d622860c938d852172ba84e8b Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 3 Jan 2014 13:54:02 +0100 Subject: [PATCH 55/79] do not show units fields in receive edit order article screen --- app/views/order_articles/_edit.html.haml | 13 +++++++------ app/views/orders/_edit_amount.html.haml | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/views/order_articles/_edit.html.haml b/app/views/order_articles/_edit.html.haml index 8167f08b..ce7e444f 100644 --- a/app/views/order_articles/_edit.html.haml +++ b/app/views/order_articles/_edit.html.haml @@ -3,13 +3,14 @@ = link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'} %h3= t '.title' .modal-body - .fold-line - = form.input :units_to_order, label: 'Amount ordered', hint: '', input_html: {class: 'input-nano'} - -#= form.input :units_billed, label: 'invoice', input_html: {class: 'input-nano'} - = form.input :units_received, label: 'received', input_html: {class: 'input-nano'} - %p.help-block= t 'simple_form.hints.order_article.units_to_order' + - unless params[:without_units] + .fold-line + = form.input :units_to_order, label: 'Amount ordered', hint: '', input_html: {class: 'input-nano'} + -#= form.input :units_billed, label: 'invoice', input_html: {class: 'input-nano'} + = form.input :units_received, label: 'received', input_html: {class: 'input-nano'} + %p.help-block= t 'simple_form.hints.order_article.units_to_order' - .foo{style: 'clear:both'} + .foo{style: 'clear:both'} = simple_fields_for :article, @order_article.article do |f| = f.input :name diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index d8488555..3001c475 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -24,7 +24,7 @@ / TODO add almost invisible text_field for entering single units %td.units_delta %td - = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-small' + = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article, without_units: true), remote: true, class: 'btn btn-small' - if order_article.result_manually_changed? = button_tag nil, class: 'btn btn-small unlocker', title: t('.locked_to_protect_unlock_button') do %i.icon-unlock From a8e604c1965f3aef5482ae3a7e532137f8168192 Mon Sep 17 00:00:00 2001 From: Julius Date: Sat, 4 Jan 2014 20:35:31 +0100 Subject: [PATCH 56/79] When receiving: hide OrderArticle unit fields also after failed validation --- app/views/order_articles/_edit.html.haml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/order_articles/_edit.html.haml b/app/views/order_articles/_edit.html.haml index ce7e444f..e8849551 100644 --- a/app/views/order_articles/_edit.html.haml +++ b/app/views/order_articles/_edit.html.haml @@ -3,7 +3,9 @@ = link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'} %h3= t '.title' .modal-body - - unless params[:without_units] + - if params[:without_units] + = hidden_field_tag :without_units, true + - else .fold-line = form.input :units_to_order, label: 'Amount ordered', hint: '', input_html: {class: 'input-nano'} -#= form.input :units_billed, label: 'invoice', input_html: {class: 'input-nano'} From 84796785307c7579457deb0def2e12de75def908 Mon Sep 17 00:00:00 2001 From: Julius Date: Fri, 3 Jan 2014 22:26:20 +0100 Subject: [PATCH 57/79] Improve unlock button for receiving OrderArticles manually adjusted Conflicts: app/views/orders/_edit_amount.html.haml --- .../stylesheets/bootstrap_and_overrides.css.less | 3 ++- app/helpers/orders_helper.rb | 13 ++++++++++++- app/views/orders/_edit_amount.html.haml | 3 --- app/views/orders/_edit_amounts.html.haml | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index a0641542..0d9cbf18 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -51,7 +51,8 @@ body { // Do not use additional margin for input in table .form-horizontal .control-group.control-group-intable, -.form-horizontal .controls.controls-intable { +.form-horizontal .controls.controls-intable, +.input-prepend.intable { margin: 0; } diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 8e76d93e..a931469a 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -46,10 +46,21 @@ module OrdersHelper def receive_input_field(form) order_article = form.object units_expected = (order_article.units_billed or order_article.units_to_order) - form.text_field :units_received, class: 'input-nano package units_received', + + # unlock button, to prevent overwriting if it was manually distributed + input_html = '' + if order_article.result_manually_changed? + input_html += '' + + button_tag(nil, type: :button, class: 'btn unlocker', title: t('.locked_to_protect_unlock_button')) {''.html_safe} + end + + input_html += form.text_field :units_received, class: 'input input-nano package units_received', data: {'units-expected' => units_expected}, disabled: order_article.result_manually_changed?, title: order_article.result_manually_changed? ? t('.locked_to_protect_manual_update') : nil, autocomplete: 'off' + + input_html += '' if order_article.result_manually_changed? + input_html.html_safe end end diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 3001c475..9b38ddda 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -25,6 +25,3 @@ %td.units_delta %td = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article, without_units: true), remote: true, class: 'btn btn-small' - - if order_article.result_manually_changed? - = button_tag nil, class: 'btn btn-small unlocker', title: t('.locked_to_protect_unlock_button') do - %i.icon-unlock diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index ef8db3df..590a111f 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -62,8 +62,8 @@ } function unlock_receive_input_field() { - $('.units_received', $(this).closest('tr')).prop('disabled', false); - $(this).remove(); + $('.units_received', $(this).closest('tr')).prop('disabled', false).focus(); + $(this).replaceWith(''); } %table#order_articles.ordered-articles.table.table-striped.stupidtable From d7c771d10a6973ac3166310b0e105b606fbc8831 Mon Sep 17 00:00:00 2001 From: Julius Date: Mon, 6 Jan 2014 23:48:39 +0100 Subject: [PATCH 58/79] Continue I18n of receive screen --- app/views/orders/_edit_amounts.html.haml | 9 +++++---- app/views/orders/receive.html.haml | 20 +++++++++----------- config/locales/de.yml | 8 ++++++++ config/locales/en.yml | 9 ++++++--- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 590a111f..ea75c1f9 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -41,7 +41,7 @@ function init_add_article(sel) { $(sel).removeAttr('disabled').select2({ - placeholder: '#{j t('orders.add_article.title')}', + placeholder: '#{j t('orders.receive.add_article')}', formatNoMatches: function(term) { return '#{j t('.no_articles_available')}';} // TODO implement adding a new article, like in deliveries }).on('change', function(e) { @@ -66,17 +66,17 @@ $(this).replaceWith(''); } -%table#order_articles.ordered-articles.table.table-striped.stupidtable +%table#order_articles.ordered-articles.table.table-striped.stupidtable{style: 'margin-bottom: 0'} %thead %tr %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true %th.default-sort.sort{:data => {:sort => 'string'}}= heading_helper Article, :name %th= heading_helper Article, :unit %th= heading_helper Article, :price - %th Members + %th= t '.members' # TODO: find term for this %th Ordered -#%th Invoice # TODO implement invoice screen - %th Received + %th= heading_helper OrderArticle, :units_received %th %th= t 'ui.actions' %tfoot @@ -85,6 +85,7 @@ %select#add_article{:style => 'width: 500px;'} - new_article_data.each do |option| %option{id: "add_article_#{option[:id]}", value: option[:id]}= option[:text] + %tbody#result_table - @order_articles.each do |order_article| = render :partial => 'edit_amount', :locals => {:order_article => order_article} diff --git a/app/views/orders/receive.html.haml b/app/views/orders/receive.html.haml index 2a130614..53105abd 100644 --- a/app/views/orders/receive.html.haml +++ b/app/views/orders/receive.html.haml @@ -22,24 +22,22 @@ }); }); -- title "Receiving #{@order.name}" +- title t('.title', order: @order.name) = form_tag(receive_order_path(@order)) do - %section#results + %fieldset#results = render 'edit_amounts' .form-actions .pull-left - Surplus to - = label_tag :rest_to_tolerance, class: 'inline' do + %b.checkbox.inline + = t '.surplus_options' + = label_tag :rest_to_tolerance, class: 'checkbox inline' do = check_box_tag :rest_to_tolerance, 1, true - member tolerance, - %span{style: 'color: grey'} - and - = label_tag :rest_to_stock, class: 'inline' do - = check_box_tag :rest_to_stock, 1, false, disabled: true - stock - + = t '.consider_member_tolerance' + = label_tag :rest_to_stock, class: 'checkbox inline' do + = check_box_tag :rest_to_stock, 1, false, disabled: true + %span{style: 'color: grey'}= t '.rest_to_stock' .pull-right = submit_tag t('.submit'), class: 'btn btn-primary' = link_to t('ui.or_cancel'), order_path(@order) diff --git a/config/locales/de.yml b/config/locales/de.yml index 1a7a4d81..6453e95c 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -81,6 +81,7 @@ de: article: Artikel missing_units: Fehlende Einheiten missing_units_short: Fehlende + units_received: Erhalten units_to_order: Menge update_current_price: Globalen Preis aktualisieren order_comment: @@ -1130,6 +1131,13 @@ de: warning_ordered_stock: ! 'Warnung: Die rot markierten Artikel wurden in der laufenden Lagerbestellung bereits bestellt bzw. gekauft. Wenn Du sie hier abwählst, werden alle bestehenden Bestellungen bzw. Käufe dieses Artikels gelöscht und nicht abgerechnet!' new: title: Neue Bestellung anlegen + receive: + add_article: Artikel hinzufügen + consider_member_tolerance: Toleranz berücksichtigen + rest_to_stock: Rest ins Lager + submit: Bestellung in Empfang nehmen + surplus_options: 'Verteilungsoptionen:' + title: »%{order}« in Empfang nehmen show: action_end: Beenden! amounts: ! 'Netto/Bruttosumme:' diff --git a/config/locales/en.yml b/config/locales/en.yml index 351b19bf..40855c21 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -81,6 +81,7 @@ en: article: Article missing_units: Missing units missing_units_short: Missing + units_received: Received units_to_order: Amount of units update_current_price: Globally update current price order_comment: @@ -1090,9 +1091,6 @@ en: new: title: Add delivered article to order orders: - add_article: - title: Add article - notice: Article "%{name}" was added to the order. articles: article_count: ! 'Ordered articles:' prices: Net/gross price @@ -1144,7 +1142,12 @@ en: new: title: Create new order receive: + add_article: Add article + consider_member_tolerance: consider tolerance + rest_to_stock: rest to stock submit: Receive order + surplus_options: 'Distribution options:' + title: Receiving %{order} show: action_end: Close! amounts: ! 'Net/gross sum:' From 563993fffafc3aeba4764297347a3c0d3efb4825 Mon Sep 17 00:00:00 2001 From: Julius Date: Wed, 8 Jan 2014 00:06:25 +0100 Subject: [PATCH 59/79] Complete I18n of current receive screen --- app/helpers/orders_helper.rb | 6 +++--- app/views/order_articles/_edit.html.haml | 4 ++-- app/views/orders/_edit_amounts.html.haml | 6 +++--- config/locales/de.yml | 18 ++++++++++++++---- config/locales/en.yml | 11 ++++++++--- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index a931469a..4c1e2367 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -20,9 +20,9 @@ module OrdersHelper if order_article.order.open? nil else - units_info = "#{order_article.units_to_order} ordered" - units_info += ", #{order_article.units_billed} billed" unless order_article.units_billed.nil? - units_info += ", #{order_article.units_received} received" unless order_article.units_received.nil? + units_info = "#{order_article.units_to_order} #{heading_helper OrderArticle, :units_to_order}" + units_info += ", #{order_article.units_billed} #{heading_helper OrderArticle, :units_billed}" unless order_article.units_billed.nil? + units_info += ", #{order_article.units_received} #{heading_helper OrderArticle, :units_received}" unless order_article.units_received.nil? end end diff --git a/app/views/order_articles/_edit.html.haml b/app/views/order_articles/_edit.html.haml index e8849551..bd19221e 100644 --- a/app/views/order_articles/_edit.html.haml +++ b/app/views/order_articles/_edit.html.haml @@ -7,9 +7,9 @@ = hidden_field_tag :without_units, true - else .fold-line - = form.input :units_to_order, label: 'Amount ordered', hint: '', input_html: {class: 'input-nano'} + = form.input :units_to_order, hint: '', input_html: {class: 'input-nano'} -#= form.input :units_billed, label: 'invoice', input_html: {class: 'input-nano'} - = form.input :units_received, label: 'received', input_html: {class: 'input-nano'} + = form.input :units_received, input_html: {class: 'input-nano'} %p.help-block= t 'simple_form.hints.order_article.units_to_order' .foo{style: 'clear:both'} diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index ea75c1f9..25ebdcde 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -73,10 +73,10 @@ %th.default-sort.sort{:data => {:sort => 'string'}}= heading_helper Article, :name %th= heading_helper Article, :unit %th= heading_helper Article, :price - %th= t '.members' # TODO: find term for this - %th Ordered + %th= heading_helper OrderArticle, :units_to_order, short: true + %th= heading_helper OrderArticle, :quantity, short: true -#%th Invoice # TODO implement invoice screen - %th= heading_helper OrderArticle, :units_received + %th= heading_helper OrderArticle, :units_received, short: true %th %th= t 'ui.actions' %tfoot diff --git a/config/locales/de.yml b/config/locales/de.yml index 6453e95c..614abe6a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -77,12 +77,17 @@ de: note: Notiz starts: Läuft vom status: Status + supplier: Lieferant order_article: article: Artikel missing_units: Fehlende Einheiten - missing_units_short: Fehlende - units_received: Erhalten - units_to_order: Menge + missing_units_short: Fehlend + quantity: Gewünschte Einheiten + quantity_short: Gewünscht + units_received: Gelieferte Gebinde + units_received_short: Geliefert + units_to_order: Bestellte Gebinde + units_to_order_short: Bestellt update_current_price: Globalen Preis aktualisieren order_comment: text: Kommentiere diese Bestellung ... @@ -1096,6 +1101,9 @@ de: notice: Die Bestellung wurde erstellt. edit: title: Bestellung bearbeiten + edit_amount: + locked_to_protect_manual_update: Die Verteilung dieses Artikels auf die einzelnen Bestellgruppen wurde manuell angepasst. Dieses Eingabefeld wurde gesperrt, um die manuellen Änderungen zu bewahren. Um den Artikel neu zu verteilen, drücke den Entsperrknopf und ändere die gelieferte Menge. + locked_to_protect_unlock_button: Drücke diesen Knopf, um das Eingabefeld für die gelieferte Menge zu entsperren. Vorherige manuelle Änderungen werden überschrieben und der Artikel wird wieder automatisch auf die Bestellgruppen aufgeteilt, wenn Du die Menge änderst. fax: amount: Menge articles: Artikel @@ -1114,12 +1122,14 @@ de: title: Artikel index: action_end: Beenden + action_receive: In Empfang nehmen + closed_orders: Abgerechnete Bestellungen confirm_delete: Willst Du wirklich die Bestellung löschen? confirm_end: Willst Du wirklich die Bestellung %{order} beenden? Es gibt kein zurück. - ended_orders: Beendete Bestellungen new_order: Neue Bestellung anlegen no_open_orders: Derzeit gibt es keine laufende Bestellungen. open_orders: Laufende Bestellungen + orders_in_progress: In Bearbeitung title: Bestellungen verwalten model: error_closed: Bestellung wurde schon abgerechnet diff --git a/config/locales/en.yml b/config/locales/en.yml index 40855c21..1ce8bf4b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -77,12 +77,17 @@ en: note: Note starts: Starts at status: Status + supplier: Supplier order_article: article: Article missing_units: Missing units missing_units_short: Missing - units_received: Received - units_to_order: Amount of units + quantity: Desired amount + quantity_short: Desired + units_received: Received amount of units + units_received_short: Received + units_to_order: Ordered amount of units + units_to_order_short: Ordered update_current_price: Globally update current price order_comment: text: Add comment to this order ... @@ -1102,7 +1107,7 @@ en: edit: title: Edit order edit_amount: - locked_to_protect_manual_update: The distribution of this article among the ordergroups was changed manually. This field is locked in order to protect those changes. To redistribute anyway, press the unlock button and change the amount. + locked_to_protect_manual_update: The distribution of this article among the ordergroups was changed manually. This field was locked in order to protect those changes. To redistribute anyway, press the unlock button and change the amount. locked_to_protect_unlock_button: Press this button to unlock the received field. Any previous manual changes will be overwritten and the article will be redistributed over the ordergroups. fax: amount: Amount From d01d1bc496ed40a5c8747b83da230670b1447538 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 8 Jan 2014 11:52:39 +0100 Subject: [PATCH 60/79] add integration tests for receive --- spec/integration/receive_spec.rb | 96 ++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 spec/integration/receive_spec.rb diff --git a/spec/integration/receive_spec.rb b/spec/integration/receive_spec.rb new file mode 100644 index 00000000..55bce007 --- /dev/null +++ b/spec/integration/receive_spec.rb @@ -0,0 +1,96 @@ +require_relative '../spec_helper' + +describe 'receiving an order', :type => :feature do + let(:admin) { create :user, groups:[create(:workgroup, role_orders: true)] } + let(:supplier) { create :supplier } + let(:article) { create :article, supplier: supplier, unit_quantity: 3 } + let(:order) { create :order, supplier: supplier, article_ids: [article.id] } # need to ref article + let(:go1) { create :group_order, order: order } + let(:go2) { create :group_order, order: order } + let(:oa) { order.order_articles.find_by_article_id(article.id) } + let(:goa1) { create :group_order_article, group_order: go1, order_article: oa } + let(:goa2) { create :group_order_article, group_order: go2, order_article: oa } + + # set quantities of group_order_articles + def set_quantities(q1, q2) + goa1.update_quantities(*q1) + goa2.update_quantities(*q2) + oa.update_results! + order.finish!(admin) + reload_articles + end + + # reload all group_order_articles + def reload_articles + [goa1, goa2].map(&:reload) + oa.reload + end + + describe :type => :feature, :js => true do + before { login admin } + + it 'has product ordered visible' do + set_quantities [3,0], [0,0] + visit receive_order_path(order) + expect(page).to have_content(article.name) + expect(page).to have_selector("#order_article_#{oa.id}") + end + + it 'has product not ordered invisible' do + set_quantities [0,0], [0,0] + visit receive_order_path(order) + expect(page).to_not have_selector("#order_article_#{oa.id}") + end + + it 'is not received by default' do + set_quantities [3,0], [0,0] + visit receive_order_path(order) + expect(find("#order_articles_#{oa.id}_units_received").value).to eq '' + end + + it 'does not change anything when received is ordered' do + set_quantities [2,0], [3,2] + visit receive_order_path(order) + expect { + fill_in "order_articles_#{oa.id}_units_received", :with => oa.units_to_order + find('input[type="submit"]').click + expect(page).to have_selector('body') + reload_articles + }.to_not change{[oa.units, goa1.result, goa2.result]} + end + + it 'redistributes properly when received is more' do + set_quantities [2,0], [3,2] + visit receive_order_path(order) + fill_in "order_articles_#{oa.id}_units_received", :with => 3 + find('input[type="submit"]').click + expect(page).to have_selector('body') + reload_articles + expect(oa.units).to eq 3 + expect(goa1.result).to be_within(1e-3).of 2 + expect(goa2.result).to be_within(1e-3).of 5 + end + + it 'redistributes properly when received is less' do + set_quantities [2,0], [3,2] + visit receive_order_path(order) + fill_in "order_articles_#{oa.id}_units_received", :with => 1 + find('input[type="submit"]').click + expect(page).to have_selector('body') + reload_articles + expect(oa.units).to eq 1 + expect(goa1.result).to be_within(1e-3).of 2 + expect(goa2.result).to be_within(1e-3).of 1 + end + + it 'has a locked field when edited elsewhere' do + set_quantities [2,0], [3,2] + goa1.result = goa1.result + 1 + goa1.save! + visit receive_order_path(order) + expect(find("#order_articles_#{oa.id}_units_received")).to be_disabled + end + + end + +end From 6e60f94484e5e14b5868c1bd2ca9e2dc0f2469df Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 8 Jan 2014 12:52:29 +0100 Subject: [PATCH 61/79] small receive-related i18n updates --- app/views/order_articles/_edit.html.haml | 3 ++- app/views/orders/_edit_amounts.html.haml | 2 +- config/locales/en.yml | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/views/order_articles/_edit.html.haml b/app/views/order_articles/_edit.html.haml index bd19221e..d1394aa4 100644 --- a/app/views/order_articles/_edit.html.haml +++ b/app/views/order_articles/_edit.html.haml @@ -9,7 +9,8 @@ .fold-line = form.input :units_to_order, hint: '', input_html: {class: 'input-nano'} -#= form.input :units_billed, label: 'invoice', input_html: {class: 'input-nano'} - = form.input :units_received, input_html: {class: 'input-nano'} + = form.input :units_received, input_html: {class: 'input-nano'}, + label: t('activerecord.attributes.order_article.units_received_short') %p.help-block= t 'simple_form.hints.order_article.units_to_order' .foo{style: 'clear:both'} diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 25ebdcde..1470ca92 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -73,8 +73,8 @@ %th.default-sort.sort{:data => {:sort => 'string'}}= heading_helper Article, :name %th= heading_helper Article, :unit %th= heading_helper Article, :price - %th= heading_helper OrderArticle, :units_to_order, short: true %th= heading_helper OrderArticle, :quantity, short: true + %th= heading_helper OrderArticle, :units_to_order, short: true -#%th Invoice # TODO implement invoice screen %th= heading_helper OrderArticle, :units_received, short: true %th diff --git a/config/locales/en.yml b/config/locales/en.yml index 1ce8bf4b..2bfb46a2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -84,9 +84,9 @@ en: missing_units_short: Missing quantity: Desired amount quantity_short: Desired - units_received: Received amount of units + units_received: Received units units_received_short: Received - units_to_order: Ordered amount of units + units_to_order: Ordered units units_to_order_short: Ordered update_current_price: Globally update current price order_comment: From 8f14ab31f35ba669d5fe42a42b8c9a3059de5942 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 8 Jan 2014 13:07:11 +0100 Subject: [PATCH 62/79] cleanup and expand receive integration test --- spec/integration/receive_spec.rb | 38 ++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/spec/integration/receive_spec.rb b/spec/integration/receive_spec.rb index 55bce007..219dd7f7 100644 --- a/spec/integration/receive_spec.rb +++ b/spec/integration/receive_spec.rb @@ -26,6 +26,14 @@ describe 'receiving an order', :type => :feature do oa.reload end + def check_quantities(units, q1, q2) + reload_articles + expect(oa.units).to eq units + expect(goa1.result).to be_within(1e-3).of q1 + expect(goa2.result).to be_within(1e-3).of q2 + end + + describe :type => :feature, :js => true do before { login admin } @@ -51,12 +59,10 @@ describe 'receiving an order', :type => :feature do it 'does not change anything when received is ordered' do set_quantities [2,0], [3,2] visit receive_order_path(order) - expect { - fill_in "order_articles_#{oa.id}_units_received", :with => oa.units_to_order - find('input[type="submit"]').click - expect(page).to have_selector('body') - reload_articles - }.to_not change{[oa.units, goa1.result, goa2.result]} + fill_in "order_articles_#{oa.id}_units_received", :with => oa.units_to_order + find('input[type="submit"]').click + expect(page).to have_selector('body') + check_quantities 2, 2, 4 end it 'redistributes properly when received is more' do @@ -65,10 +71,7 @@ describe 'receiving an order', :type => :feature do fill_in "order_articles_#{oa.id}_units_received", :with => 3 find('input[type="submit"]').click expect(page).to have_selector('body') - reload_articles - expect(oa.units).to eq 3 - expect(goa1.result).to be_within(1e-3).of 2 - expect(goa2.result).to be_within(1e-3).of 5 + check_quantities 3, 2, 5 end it 'redistributes properly when received is less' do @@ -77,10 +80,7 @@ describe 'receiving an order', :type => :feature do fill_in "order_articles_#{oa.id}_units_received", :with => 1 find('input[type="submit"]').click expect(page).to have_selector('body') - reload_articles - expect(oa.units).to eq 1 - expect(goa1.result).to be_within(1e-3).of 2 - expect(goa2.result).to be_within(1e-3).of 1 + check_quantities 1, 2, 1 end it 'has a locked field when edited elsewhere' do @@ -91,6 +91,16 @@ describe 'receiving an order', :type => :feature do expect(find("#order_articles_#{oa.id}_units_received")).to be_disabled end + it 'leaves locked rows alone when submitted' do + set_quantities [2,0], [3,2] + goa1.result = goa1.result + 1 + goa1.save! + visit receive_order_path(order) + find('input[type="submit"]').click + expect(page).to have_selector('body') + check_quantities 2, 3, 4 + end + end end From ce17bf33e04f25c4143ec166d3f6b7039e6d90d3 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 8 Jan 2014 13:39:49 +0100 Subject: [PATCH 63/79] complete and improve receive i18n --- app/controllers/orders_controller.rb | 14 +++++++++----- app/helpers/orders_helper.rb | 6 +++--- config/locales/en.yml | 19 ++++++++++++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 23788f86..e32f8f1d 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -111,7 +111,8 @@ class OrdersController < ApplicationController unless request.post? @order_articles = @order.order_articles.ordered.includes(:article) else - flash[:notice] = "Order received: " + update_order_amounts + s = update_order_amounts + flash[:notice] = (s ? I18n.t('orders.receive.notice', :msg => s) : I18n.t('orders.receive.notice_none')) redirect_to @order end end @@ -156,6 +157,7 @@ class OrdersController < ApplicationController end def update_order_amounts + return if not params[:order_articles] # where to leave remainder during redistribution rest_to = [] rest_to << :tolerance if params[:rest_to_tolerance] @@ -183,10 +185,12 @@ class OrdersController < ApplicationController end end end - notice = " #{counts.shift} articles (#{cunits.shift} units) updated" - notice += ", #{counts.shift} (#{cunits.shift}) using tolerance" if params[:rest_to_tolerance] - notice += ", #{counts.shift} (#{cunits.shift}) go to stock if foodsoft would support that" if params[:rest_to_stock] - notice += ", #{counts.shift} (#{cunits.shift}) left over" + notice = I18n.t('orders.update_order_amounts.msg1', count: counts.shift, units: cunits.shift) + notice += ", " + I18n.t('orders.update_order_amounts.msg2', count: counts.shift, units: cunits.shift) if params[:rest_to_tolerance] + notice += ", " + I18n.t('orders.update_order_amounts.msg3', count: counts.shift, units: cunits.shift) if params[:rest_to_stock] + if counts[0]>0 or cunits[0]>0 + notice += ", " + I18n.t('orders.update_order_amounts.msg4', count: counts.shift, units: cunits.shift) + end end end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 4c1e2367..e81576a9 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -20,9 +20,9 @@ module OrdersHelper if order_article.order.open? nil else - units_info = "#{order_article.units_to_order} #{heading_helper OrderArticle, :units_to_order}" - units_info += ", #{order_article.units_billed} #{heading_helper OrderArticle, :units_billed}" unless order_article.units_billed.nil? - units_info += ", #{order_article.units_received} #{heading_helper OrderArticle, :units_received}" unless order_article.units_received.nil? + units_info = "#{order_article.units_to_order} #{OrderArticle.human_attribute_name :units_to_order, count: order_article.units_to_order}" + units_info += ", #{order_article.units_billed} #{OrderArticle.human_attribute_name :units_billed_short, count: order_article.units_billed}" unless order_article.units_billed.nil? + units_info += ", #{order_article.units_received} #{OrderArticle.human_attribute_name :units_received_short, count: order_article.units_received}" unless order_article.units_received.nil? end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2bfb46a2..31c7d47c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -80,13 +80,19 @@ en: supplier: Supplier order_article: article: Article - missing_units: Missing units + missing_units: + one: Missing unit + other: Missing units missing_units_short: Missing quantity: Desired amount quantity_short: Desired - units_received: Received units + units_received: + one: Received unit + other: Received units units_received_short: Received - units_to_order: Ordered units + units_to_order: + one: Ordered unit + other: Ordered units units_to_order_short: Ordered update_current_price: Globally update current price order_comment: @@ -1149,6 +1155,8 @@ en: receive: add_article: Add article consider_member_tolerance: consider tolerance + notice: ! 'Order received: %{msg}' + notice_none: No new articles to receive rest_to_stock: rest to stock submit: Receive order surplus_options: 'Distribution options:' @@ -1184,6 +1192,11 @@ en: open: open update: notice: The order was updated. + update_order_amounts: + msg1: "%{count} articles (%{units} units) updated" + msg2: "%{count} (%{units}) using tolerance" + msg3: "%{count} (%{units}) go to stock if foodsoft would support that [don't translate]" + msg4: "%{count} (%{units}) left over" pages: all: new_page: Create new page From d1c3c83ed7979fbbe59cbababfa436bacd08db17 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 8 Jan 2014 18:23:34 +0100 Subject: [PATCH 64/79] use plural in table headings by default --- app/helpers/application_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 52ec9256..4a266ece 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -81,10 +81,10 @@ module ApplicationHelper # heading, with an abbreviation title of 'foo'. # Other options are passed through to I18n. def heading_helper(model, attribute, options = {}) - i18nopts = options.select {|a| !['short'].include?(a) } + i18nopts = options.select {|a| !['short'].include?(a) }.merge({count: 2}) s = model.human_attribute_name(attribute, i18nopts) if options[:short] - sshort = model.human_attribute_name("#{attribute}_short".to_sym, options.merge({fallback: true, default: ''})) + sshort = model.human_attribute_name("#{attribute}_short".to_sym, options.merge({fallback: true, default: '', count: 2})) s = raw "#{sshort}" unless sshort.blank? end s From 65e79d7e1b6afd78d48ac5031789b4f246029a1f Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 8 Jan 2014 19:28:39 +0100 Subject: [PATCH 65/79] small receive usability changes --- app/assets/stylesheets/bootstrap_and_overrides.css.less | 6 ++++++ app/views/orders/_edit_amounts.html.haml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 0d9cbf18..47551709 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -351,3 +351,9 @@ i.package { .control-text { margin-top: 5px; } + +// unlock button same size as warning sign +.input-prepend button.unlocker { + padding-right: 6px; + padding-left: 7px; +} diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 1470ca92..cae49e46 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -25,7 +25,7 @@ $(input).closest('tr').find('.units_delta').html(html); } - $(document).on('change', 'input[data-units-expected]', function() { + $(document).on('change keyup', 'input[data-units-expected]', function() { update_delta(this); }); From b331d9a2a93ee82ff65bd942d312a5cf12da9f8a Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 8 Jan 2014 19:58:45 +0100 Subject: [PATCH 66/79] better css responsiveness [ci skip] --- app/assets/stylesheets/bootstrap_and_overrides.css.less | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 47551709..6f70a2e1 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -292,16 +292,18 @@ input.package { i.package { background: url(package-bg.png) no-repeat left center; min-width: 18px; - padding-left: 20px; font-style: normal; + padding-left: 20px; + @media (max-width: 768px) { padding-left: 0; } } .package { color: tint(@textColor, @nonessentialDim); } .used .package { color: tint(@articleUsedColor, @nonessentialDim); } .unused .package { color: tint(@articleUnusedColor, @nonessentialDim); } .unavailable .package { color: @articleUnavailColor; } +// very small inputs - need !important for responsive selectors .input-nano { - width: 30px; + width: 30px !important; } // get rid of extra space on bottom of dialog with form From 5a7c9b817c9535ffbc092bd457781c85dee5c75c Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 9 Jan 2014 10:13:57 +0100 Subject: [PATCH 67/79] fix receive js for document updates [ci skip] --- app/views/orders/_edit_amounts.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index cae49e46..795e7e5e 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -29,14 +29,14 @@ update_delta(this); }); + $(document).on('click', '#order_articles .unlocker', unlock_receive_input_field); + $(function() { $('input[data-units-expected]').each(function() { update_delta(this); }); init_add_article('#add_article'); - - $('.unlocker', '#order_articles tbody').on('click', unlock_receive_input_field); }); function init_add_article(sel) { From 56bd527a8ba8427b81e8e8604b3870b01a11fe8b Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 9 Jan 2014 10:51:48 +0100 Subject: [PATCH 68/79] keep white input background with package class [ci skip] --- .../stylesheets/bootstrap_and_overrides.css.less | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 6f70a2e1..002ae8cc 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -281,16 +281,21 @@ tr.unavailable { display: inline; } -// show package icon after amount of package numbers +// show package icon after amount of wholesale units +.package-image (@align) { + background-image: url(package-bg.png); + background-repeat: no-repeat; + background-position: @align center; +} input.package { - background: url(package-bg.png) no-repeat right center; + .package-image(right); // disabled and readonly definitions though &[disabled], &[readonly] { background-color: @inputDisabledBackground; } } i.package { - background: url(package-bg.png) no-repeat left center; + .package-image(left); min-width: 18px; font-style: normal; padding-left: 20px; From 90c81de872b0500325dfead20c579336098b0cea Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 9 Jan 2014 12:17:25 +0100 Subject: [PATCH 69/79] update receive delta column + responsive css --- .../bootstrap_and_overrides.css.less | 13 +++++++++--- app/helpers/orders_helper.rb | 21 +++++++++++++++---- app/views/orders/_edit_amount.html.haml | 4 ++-- app/views/orders/_edit_amounts.html.haml | 11 ++++++---- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 002ae8cc..e3db2709 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -233,9 +233,9 @@ tr.unavailable { margin-bottom: 0; } -// entering units +// allow content to appear without sudden table change (receive) .units_delta { - width: 2em; + min-width: 3.5em; } // ********* Tweaks & fixes @@ -297,9 +297,16 @@ input.package { i.package { .package-image(left); min-width: 18px; + min-height: 18px; + vertical-align: baseline; font-style: normal; padding-left: 20px; - @media (max-width: 768px) { padding-left: 0; } + @media (max-width: 979px) { padding-left: 0; } +} +i.package.icon-only { + padding-left: 6px; + background-position: right; + display: inline-block; } .package { color: tint(@textColor, @nonessentialDim); } .used .package { color: tint(@articleUsedColor, @nonessentialDim); } diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index e81576a9..4203723b 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -27,14 +27,27 @@ module OrdersHelper end # can be article or article_price - def pkg_helper(article, icon=true) + # icon: `false` to not show the icon + # soft_uq: `true` to hide unit quantity specifier on small screens + # sensible in tables with multiple columns calling `pkg_helper` + def pkg_helper(article, options={}) return nil if article.unit_quantity == 1 - if icon - " × #{article.unit_quantity}".html_safe + uq_text = "× #{article.unit_quantity}" + uq_text = "#{uq_text}" if options[:soft_uq] + if options[:icon].nil? or options[:icon] + pkg_helper_icon(uq_text).html_safe else - " × #{article.unit_quantity}".html_safe + pkg_helper_icon(uq_text, tag: 'span').html_safe end end + def pkg_helper_icon(c=nil, options={}) + options = {tag: 'i', class: ''}.merge(options) + if c.nil? + c = " " + options[:class] += " icon-only" + end + "<#{options[:tag]} class='package #{options[:class]}'>#{c}" + end def article_price_change_hint(order_article, gross=false) return nil if order_article.article.price == order_article.price.price diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 9b38ddda..fb761d27 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -17,10 +17,10 @@ -#%td # TODO implement invoice screen - unless order_article.units_billed.nil? = order_article.units_billed - = pkg_helper order_article.article + = pkg_helper order_article.article, soft_uq: true %td.units_received_cell = receive_input_field(form) - = pkg_helper order_article.article_price, false + = pkg_helper order_article.article_price, icon: false, soft_uq: true / TODO add almost invisible text_field for entering single units %td.units_delta %td diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 795e7e5e..2afbd58c 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -16,10 +16,13 @@ } else if (units == expected) { // equal value html = ''; - } else if (units < expected) { - html = '- '+(expected-units)+''; - } else /*if (units> expected)*/ { - html = '+ '+(units-expected)+''; + } else { + if (units < expected) { + html = '- '+(expected-units)+''; + } else /*if (units> expected)*/ { + html = '+ '+(units-expected)+''; + } + html += '#{j pkg_helper_icon}'; } $(input).closest('tr').find('.units_delta').html(html); From 124341c7d6b09776cc7fff7ed822490515ac668e Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 9 Jan 2014 13:01:10 +0100 Subject: [PATCH 70/79] receive helper and i18n cleanup --- app/helpers/orders_helper.rb | 33 ++++++++++++------------ app/views/orders/_edit_amounts.html.haml | 1 + config/i18n-js.yml | 8 +++++- config/locales/en.yml | 6 ++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 4203723b..3e91848d 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -32,48 +32,47 @@ module OrdersHelper # sensible in tables with multiple columns calling `pkg_helper` def pkg_helper(article, options={}) return nil if article.unit_quantity == 1 - uq_text = "× #{article.unit_quantity}" - uq_text = "#{uq_text}" if options[:soft_uq] + uq_text = "× #{article.unit_quantity}".html_safe + uq_text = content_tag(:span, uq_text, class: 'hidden-phone') if options[:soft_uq] if options[:icon].nil? or options[:icon] - pkg_helper_icon(uq_text).html_safe + pkg_helper_icon(uq_text) else - pkg_helper_icon(uq_text, tag: 'span').html_safe + pkg_helper_icon(uq_text, tag: :span) end end def pkg_helper_icon(c=nil, options={}) options = {tag: 'i', class: ''}.merge(options) if c.nil? - c = " " + c = " ".html_safe options[:class] += " icon-only" end - "<#{options[:tag]} class='package #{options[:class]}'>#{c}" + content_tag(options[:tag], c, class: "package #{options[:class]}").html_safe end def article_price_change_hint(order_article, gross=false) return nil if order_article.article.price == order_article.price.price title = "#{t('helpers.orders.old_price')}: #{number_to_currency order_article.article.price}" title += " / #{number_to_currency order_article.article.gross_price}" if gross - "".html_safe + content_tag(:i, nil, class: 'icon-asterisk', title: j(title)).html_safe end def receive_input_field(form) order_article = form.object units_expected = (order_article.units_billed or order_article.units_to_order) - # unlock button, to prevent overwriting if it was manually distributed - input_html = '' - if order_article.result_manually_changed? - input_html += '' + - button_tag(nil, type: :button, class: 'btn unlocker', title: t('.locked_to_protect_unlock_button')) {''.html_safe} - end - - input_html += form.text_field :units_received, class: 'input input-nano package units_received', + input_html = form.text_field :units_received, class: 'input input-nano package units_received', data: {'units-expected' => units_expected}, disabled: order_article.result_manually_changed?, - title: order_article.result_manually_changed? ? t('.locked_to_protect_manual_update') : nil, autocomplete: 'off' - input_html += '' if order_article.result_manually_changed? + if order_article.result_manually_changed? + input_html = content_tag(:span, class: 'input-prepend intable', title: t('.field_locked_title', default: '')) { + button_tag(nil, type: :button, class: 'btn unlocker') { + content_tag(:i, nil, class: 'icon icon-unlock') + } + input_html + } + end + input_html.html_safe end end diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 2afbd58c..74e5653a 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -66,6 +66,7 @@ function unlock_receive_input_field() { $('.units_received', $(this).closest('tr')).prop('disabled', false).focus(); + $(this).closest('.input-prepend').prop('title', I18n.t('orders.edit_amount.field_unlocked_title')); $(this).replaceWith(''); } diff --git a/config/i18n-js.yml b/config/i18n-js.yml index 76af6fda..c1d71d19 100644 --- a/config/i18n-js.yml +++ b/config/i18n-js.yml @@ -1,4 +1,10 @@ # only serve selected strings for i18n-js to keep filesize down translations: - file: 'app/assets/javascripts/i18n/translations.js' - only: ['*.js.*', '*.number.*', '*.date.formats.*'] + only: [ + '*.js.*', + '*.number.*', + '*.date.formats.*', + # foodsoft-specific texts to keep js with normal translations + '*.orders.edit_amount.*' + ] diff --git a/config/locales/en.yml b/config/locales/en.yml index 31c7d47c..87e325ff 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -750,7 +750,7 @@ en: new_invoice: New invoice show_invoice: Show invoice orders: - old_price: Old price + old_price: Old price option_choose: Choose supplier/stock option_stock: Stock order_pdf: Create PDF @@ -1113,8 +1113,8 @@ en: edit: title: Edit order edit_amount: - locked_to_protect_manual_update: The distribution of this article among the ordergroups was changed manually. This field was locked in order to protect those changes. To redistribute anyway, press the unlock button and change the amount. - locked_to_protect_unlock_button: Press this button to unlock the received field. Any previous manual changes will be overwritten and the article will be redistributed over the ordergroups. + field_locked_title: The distribution of this article among the ordergroups was changed manually. This field is locked to protect those changes. To redistribute and overwrite those changes, press the unlock button and change the amount. + field_unlocked_title: The distribution of this article among the ordergroups was changed manually. When you change the amount, those manual changes will be overwritten. fax: amount: Amount articles: Articles From bea27060055d46350d9642b8b007eaaafe6726ed Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 9 Jan 2014 13:19:27 +0100 Subject: [PATCH 71/79] fix receive dynamic update (complements 90c81de872b0500325dfead20c579336098b0cea) --- app/views/orders/receive_on_order_article_update.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/orders/receive_on_order_article_update.js.erb b/app/views/orders/receive_on_order_article_update.js.erb index 187195fe..3e9ddda8 100644 --- a/app/views/orders/receive_on_order_article_update.js.erb +++ b/app/views/orders/receive_on_order_article_update.js.erb @@ -5,7 +5,7 @@ var old_order_article_entry = $('#order_article_<%= @order_article.id %>'); $('td.units_received_cell span.package', old_order_article_entry).replaceWith( - '<%= j pkg_helper(@order_article.article_price, false) %>' + '<%= j pkg_helper(@order_article.article_price, icon: false) %>' ); // render new element and inject dynamic cell From 2b97ca050af5565817176868022646c464f0c13f Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 9 Jan 2014 13:22:32 +0100 Subject: [PATCH 72/79] i18n oops --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 87e325ff..e3f56e35 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -750,7 +750,7 @@ en: new_invoice: New invoice show_invoice: Show invoice orders: - old_price: Old price + old_price: Old price option_choose: Choose supplier/stock option_stock: Stock order_pdf: Create PDF From dcb17e04b5b3f11577c8f89a428bdfeaa7b7599f Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 9 Jan 2014 13:24:40 +0100 Subject: [PATCH 73/79] do not show article hint in order view after all, since "old price" is actually the price of the current article, which will probably be different in the future --- app/views/orders/_articles.html.haml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/orders/_articles.html.haml b/app/views/orders/_articles.html.haml index df0e9a4b..8304486f 100644 --- a/app/views/orders/_articles.html.haml +++ b/app/views/orders/_articles.html.haml @@ -28,9 +28,7 @@ %tr{:class => cycle('even', 'odd', :name => 'articles') + ' ' + cssclass} %td=h order_article.article.name %td= order_article.article.unit - %td - = "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" - = article_price_change_hint(order_article, gross: true) + %td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" - if order.stockit? %td= units - else From 0b4cfde1b212620f9eff290f87b810524e2345ee Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 9 Jan 2014 14:47:05 +0100 Subject: [PATCH 74/79] put footer below body, now that is allowed in html5 --- app/views/orders/_edit_amounts.html.haml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index 74e5653a..a9825876 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -83,6 +83,9 @@ %th= heading_helper OrderArticle, :units_received, short: true %th %th= t 'ui.actions' + %tbody#result_table + - @order_articles.each do |order_article| + = render :partial => 'edit_amount', :locals => {:order_article => order_article} %tfoot %tr %th{:colspan => 10} @@ -90,7 +93,3 @@ - new_article_data.each do |option| %option{id: "add_article_#{option[:id]}", value: option[:id]}= option[:text] - %tbody#result_table - - @order_articles.each do |order_article| - = render :partial => 'edit_amount', :locals => {:order_article => order_article} - From 9db8cb72dfb54bcb9b43ba7878de8ba1aea2ca43 Mon Sep 17 00:00:00 2001 From: Julius Date: Fri, 10 Jan 2014 20:50:58 +0100 Subject: [PATCH 75/79] Synchronize German and English locales --- config/locales/de.yml | 33 ++++++++++++++++++++++++++------- config/locales/en.yml | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 70ad771b..f2d7d10a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -80,13 +80,19 @@ de: supplier: Lieferant order_article: article: Artikel - missing_units: Fehlende Einheiten + missing_units: + one: Fehlende Einheite + other: Fehlende Einheiten missing_units_short: Fehlend quantity: Gewünschte Einheiten quantity_short: Gewünscht - units_received: Gelieferte Gebinde + units_received: + one: Geliefertes Gebinde + other: Gelieferte Gebinde units_received_short: Geliefert - units_to_order: Bestellte Gebinde + units_to_order: + one: Bestelltes Gebinde + other: Bestellte Gebinde units_to_order_short: Bestellt update_current_price: Globalen Preis aktualisieren order_comment: @@ -284,6 +290,7 @@ de: error_denied: Du darfst die gewünschte Seite nicht sehen. Wenn Du denkst, dass Du dürfen solltest, frage eine Administratorin, dass sie Dir die entsprechenden Rechte einräumt. Falls Du Zugang zu mehreren Benutzerkonten hast, möchtest Du Dich vielleicht %{sign_in}. error_denied_sign_in: als ein anderer Benutzer anmelden error_members_only: Diese Aktion ist nur für Mitglieder der Gruppe erlaubt! + error_token: Zugriff verweigert (ungültiger Token)! article_categories: create: notice: Die Kategorie wurde gespeichert @@ -383,7 +390,9 @@ de: update: body: ! 'Jeder Artikel wird doppelt angezeigt: die alten Werte sind grau und die Textfelder sind mit den aktuellen Werten vorausgefüllt. Abweichungen zu den alten Artikeln sind gelb markiert.' title: Aktualisieren ... - update_msg: ! '%{count} Artikel müssen aktualisiert werden.' + update_msg: + one: Ein Artikel muss aktualisiert werden. + other: ! '%{count} Artikel müssen aktualisiert werden.' upload: body:

Die Datei muss eine Textdatei mit der Endung '.csv' sein. Die erste Zeile wird beim Einlesen ignoriert.

Die Felder müssen mit einem Semikolon (';') getrennt und der Text mit doppelten Anführungszeichen ("Text...") umklammert werden.

Als Zeichensatz wird UTF-8 erwartet. Korrekte Reihenfolge der Spalten:

fields: @@ -475,7 +484,9 @@ de: - FC-Preis - Menge title: ! 'Sortiermatrix der Bestellung: %{name}, beendet am %{date}' - total: Insgesamt %{count} Artikel + total: + one: Insgesamt ein Artikel + other: ! 'Insgesamt %{count} Artikel' errors: general: Ein Problem ist aufgetreten. general_again: Ein Fehler ist aufgetreten. Bitte erneut versuchen. @@ -741,6 +752,7 @@ de: new_invoice: Rechnung anlegen show_invoice: Rechnung anzeigen orders: + old_price: Alter Preis option_choose: Lieferantin/Lager auswählen option_stock: Lager order_pdf: PDF erstellen @@ -1103,8 +1115,8 @@ de: edit: title: Bestellung bearbeiten edit_amount: - locked_to_protect_manual_update: Die Verteilung dieses Artikels auf die einzelnen Bestellgruppen wurde manuell angepasst. Dieses Eingabefeld wurde gesperrt, um die manuellen Änderungen zu bewahren. Um den Artikel neu zu verteilen, drücke den Entsperrknopf und ändere die gelieferte Menge. - locked_to_protect_unlock_button: Drücke diesen Knopf, um das Eingabefeld für die gelieferte Menge zu entsperren. Vorherige manuelle Änderungen werden überschrieben und der Artikel wird wieder automatisch auf die Bestellgruppen aufgeteilt, wenn Du die Menge änderst. + field_locked_title: Die Verteilung dieses Artikels auf die einzelnen Bestellgruppen wurde manuell angepasst. Das Eingabefeld wurde gesperrt, um die manuellen Änderungen zu bewahren. Um den Artikel neu zu verteilen, drücke den Entsperrknopf und ändere die gelieferte Menge. + field_unlocked_title: Die Verteilung dieses Artikels auf die einzelnen Bestellgruppen wurde manuell angepasst. Wenn du die gelieferte Menge änderst, werden die vorherigen manuellen Änderungen überschrieben. fax: amount: Menge articles: Artikel @@ -1145,6 +1157,8 @@ de: receive: add_article: Artikel hinzufügen consider_member_tolerance: Toleranz berücksichtigen + notice: ! 'Bestellung in Empfang genommen: %{msg}' + notice_none: Keine neuen Artikel für den Empfang ausgewählt. rest_to_stock: Rest ins Lager submit: Bestellung in Empfang nehmen surplus_options: 'Verteilungsoptionen:' @@ -1180,6 +1194,11 @@ de: open: laufend update: notice: Die Bestellung wurde aktualisiert. + update_order_amounts: + update_order_amounts: + msg1: "%{count} Artikel (%{units} Einheiten) aktualisiert" + msg2: "%{count} (%{units}) Toleranzmenge" + msg4: "%{count} (%{units}) übrig" pages: all: new_page: Neue Seite anlegen diff --git a/config/locales/en.yml b/config/locales/en.yml index a97fc2db..e74b0756 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1136,9 +1136,9 @@ en: index: action_end: Close action_receive: Receive + closed_orders: Settled orders confirm_delete: Do you really want to delete the order? confirm_end: Do you really want to close the order %{order}? There is no going back. - closed_orders: Settled orders new_order: Create new order no_open_orders: There are currently no open orders. open_orders: Current orders From 45e529b008455eae1b638dbcfe05333a5db0bc45 Mon Sep 17 00:00:00 2001 From: wvengen Date: Sat, 11 Jan 2014 16:30:11 +0100 Subject: [PATCH 76/79] revert i18n attributes pluralisation until plataformatec/simple_form#974 has a solution (reverts parts of ce17bf33e04f25c4143ec166d3f6b7039e6d90d3 and 9db8cb72dfb54bcb9b43ba7878de8ba1aea2ca43) --- config/locales/de.yml | 12 +++--------- config/locales/en.yml | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 5f1d0fb0..78ba3fae 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -80,19 +80,13 @@ de: supplier: Lieferant order_article: article: Artikel - missing_units: - one: Fehlende Einheite - other: Fehlende Einheiten + missing_units: Fehlende Einheiten missing_units_short: Fehlend quantity: Gewünschte Einheiten quantity_short: Gewünscht - units_received: - one: Geliefertes Gebinde - other: Gelieferte Gebinde + units_received: Gelieferte Gebinde units_received_short: Geliefert - units_to_order: - one: Bestelltes Gebinde - other: Bestellte Gebinde + units_to_order: Bestellte Gebinde units_to_order_short: Bestellt update_current_price: Globalen Preis aktualisieren order_comment: diff --git a/config/locales/en.yml b/config/locales/en.yml index ee2b8750..c8d052b5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -80,19 +80,13 @@ en: supplier: Supplier order_article: article: Article - missing_units: - one: Missing unit - other: Missing units + missing_units: Missing units missing_units_short: Missing quantity: Desired amount quantity_short: Desired - units_received: - one: Received unit - other: Received units + units_received: Received units units_received_short: Received - units_to_order: - one: Ordered unit - other: Ordered units + units_to_order: Ordered units units_to_order_short: Ordered update_current_price: Globally update current price order_comment: From 3b2d50b47dee811d5c1df92a5d1c658be118c9ec Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 13 Jan 2014 11:37:18 +0100 Subject: [PATCH 77/79] make receive delta work when unit_quantity changes --- app/helpers/orders_helper.rb | 7 +++++-- app/views/orders/_edit_amounts.html.haml | 14 +++++++++----- .../receive_on_order_article_update.js.erb | 16 +++++++++++++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 3e91848d..14fca94b 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -58,9 +58,12 @@ module OrdersHelper def receive_input_field(form) order_article = form.object - units_expected = (order_article.units_billed or order_article.units_to_order) + units_expected = (order_article.units_billed or order_article.units_to_order) * + 1.0 * order_article.article.unit_quantity / order_article.article_price.unit_quantity - input_html = form.text_field :units_received, class: 'input input-nano package units_received', + input_classes = 'input input-nano units_received' + input_classes += ' package' unless order_article.article_price.unit_quantity == 1 + input_html = form.text_field :units_received, class: input_classes, data: {'units-expected' => units_expected}, disabled: order_article.result_manually_changed?, autocomplete: 'off' diff --git a/app/views/orders/_edit_amounts.html.haml b/app/views/orders/_edit_amounts.html.haml index a9825876..3a62609f 100644 --- a/app/views/orders/_edit_amounts.html.haml +++ b/app/views/orders/_edit_amounts.html.haml @@ -6,6 +6,7 @@ function update_delta(input) { var units = $(input).val(); var expected = $(input).data('units-expected'); + var delta = Math.round((units-expected)*100)/100.0; var html; if (units.replace(/\s/g,"")=="") { @@ -13,16 +14,19 @@ html = ''; } else if (isNaN(units)) { html = ''; - } else if (units == expected) { + } else if (delta == 0) { // equal value html = ''; } else { - if (units < expected) { - html = '- '+(expected-units)+''; + if (delta < 0) { + html = '- '+(-delta)+''; } else /*if (units> expected)*/ { - html = '+ '+(units-expected)+''; + html = '+ '+(delta)+''; + } + // show package icon only if the receive field has one + if ($(input).hasClass('package')) { + html += '#{j pkg_helper_icon}'; } - html += '#{j pkg_helper_icon}'; } $(input).closest('tr').find('.units_delta').html(html); diff --git a/app/views/orders/receive_on_order_article_update.js.erb b/app/views/orders/receive_on_order_article_update.js.erb index 3e9ddda8..d4ee9a72 100644 --- a/app/views/orders/receive_on_order_article_update.js.erb +++ b/app/views/orders/receive_on_order_article_update.js.erb @@ -4,9 +4,19 @@ // get old element and update the cell which is reused var old_order_article_entry = $('#order_article_<%= @order_article.id %>'); - $('td.units_received_cell span.package', old_order_article_entry).replaceWith( - '<%= j pkg_helper(@order_article.article_price, icon: false) %>' - ); + // update package info after input + $('td.units_received_cell span.package', old_order_article_entry).remove(); + $('<%= j pkg_helper(@order_article.article_price, icon: false) %>') + .appendTo($('td.units_received_cell', old_order_article_entry)); + + // update package icon on input too + $('input', old_order_article_entry).toggleClass('package', <%= @order_article.article_price.unit_quantity == 1 ? 'false' : 'true' %>); + + // update expected units, since unit_quantity may have been changed + $('input', old_order_article_entry).data('units-expected', <%= + (@order_article.units_billed or @order_article.units_to_order) * + 1.0 * @order_article.article.unit_quantity / @order_article.article_price.unit_quantity + %>); // render new element and inject dynamic cell var new_order_article_entry = $( From 8760d87a766c67ea325a280caf265c3c370cab02 Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 13 Jan 2014 11:48:43 +0100 Subject: [PATCH 78/79] fix receive notice --- app/controllers/orders_controller.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index e32f8f1d..b8f97883 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -163,9 +163,10 @@ class OrdersController < ApplicationController rest_to << :tolerance if params[:rest_to_tolerance] rest_to << :stock if params[:rest_to_stock] rest_to << nil - # count what happens to the articles - counts = [0] * (rest_to.length+2) - cunits = [0] * (rest_to.length+2) + # count what happens to the articles: + # changed, rest_to_tolerance, rest_to_stock, left_over + counts = [0] * 4 + cunits = [0] * 4 OrderArticle.transaction do params[:order_articles].each do |oa_id, oa_params| unless oa_params.blank? @@ -185,12 +186,15 @@ class OrdersController < ApplicationController end end end - notice = I18n.t('orders.update_order_amounts.msg1', count: counts.shift, units: cunits.shift) - notice += ", " + I18n.t('orders.update_order_amounts.msg2', count: counts.shift, units: cunits.shift) if params[:rest_to_tolerance] - notice += ", " + I18n.t('orders.update_order_amounts.msg3', count: counts.shift, units: cunits.shift) if params[:rest_to_stock] - if counts[0]>0 or cunits[0]>0 - notice += ", " + I18n.t('orders.update_order_amounts.msg4', count: counts.shift, units: cunits.shift) + return nil if counts[0] == 0 + notice = [] + notice << I18n.t('orders.update_order_amounts.msg1', count: counts[0], units: cunits[0]) + notice << I18n.t('orders.update_order_amounts.msg2', count: counts[1], units: cunits[1]) if params[:rest_to_tolerance] + notice << I18n.t('orders.update_order_amounts.msg3', count: counts[2], units: cunits[2]) if params[:rest_to_stock] + if counts[3]>0 or cunits[3]>0 + notice << I18n.t('orders.update_order_amounts.msg4', count: counts[3], units: cunits[3]) end + notice.join(', ') end end From bab28d27706308b14bda1768f60ae6ae22565c8d Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 13 Jan 2014 23:21:03 +0100 Subject: [PATCH 79/79] i18n update --- app/controllers/orders_controller.rb | 2 +- app/views/orders/index.html.haml | 21 +++++++++------------ config/locales/de.yml | 8 ++++---- config/locales/en.yml | 8 ++++---- config/locales/fr.yml | 7 ++++--- config/locales/nl.yml | 7 ++++--- 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index b8f97883..7d326c40 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -9,7 +9,7 @@ class OrdersController < ApplicationController # List orders def index @open_orders = Order.open.includes(:supplier) - @orders_in_progress = Order.finished_not_closed.includes(:supplier) + @finished_orders = Order.finished_not_closed.includes(:supplier) @per_page = 15 if params['sort'] sort = case params['sort'] diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 6b662cfb..16546373 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -11,12 +11,12 @@ .well - if not @open_orders.empty? - %h2= t '.open_orders' - - elsif not @orders_in_progress.empty? - %h2= t '.orders_in_progress' + %h2= t '.orders_open' + - elsif not @finished_orders.empty? + %h2= t '.orders_finished' - else - = t '.no_open_orders' - - unless @open_orders.empty? and @orders_in_progress.empty? + = t '.no_open_or_finished_orders' + - unless @open_orders.empty? and @finished_orders.empty? %table.table.table-striped %thead %tr @@ -42,12 +42,12 @@ = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, class: 'btn btn-small btn-danger' - - unless @orders_in_progress.empty? + - unless @finished_orders.empty? - unless @open_orders.empty? %tr %td{colspan: 6} - %h2= t '.orders_in_progress' - - for order in @orders_in_progress + %h2= t '.orders_finished' + - for order in @finished_orders %tr %td= order.name %td= format_time(order.ends) @@ -62,10 +62,7 @@ = link_to t('ui.show'), order, class: 'btn btn-small' = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, class: 'btn btn-small btn-danger' - - else - %tr - %td{colspan: 6}= t '.no_orders_in_progress' -%h2= t '.closed_orders' +%h2= t '.orders_settled' #orders_table = render partial: 'orders' diff --git a/config/locales/de.yml b/config/locales/de.yml index 78ba3fae..79046d4e 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1130,13 +1130,13 @@ de: index: action_end: Beenden action_receive: In Empfang nehmen - closed_orders: Abgerechnete Bestellungen confirm_delete: Willst Du wirklich die Bestellung löschen? confirm_end: Willst Du wirklich die Bestellung %{order} beenden? Es gibt kein zurück. new_order: Neue Bestellung anlegen - no_open_orders: Derzeit gibt es keine laufende Bestellungen. - open_orders: Laufende Bestellungen - orders_in_progress: In Bearbeitung + no_open_or_finished_orders: Derzeit gibt es keine laufende oder beendete Bestellungen. + orders_finished: Beendet + orders_open: Laufend + orders_settled: Abgerechnet title: Bestellungen verwalten model: error_closed: Bestellung wurde schon abgerechnet diff --git a/config/locales/en.yml b/config/locales/en.yml index c8d052b5..db287551 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1130,13 +1130,13 @@ en: index: action_end: Close action_receive: Receive - closed_orders: Settled orders confirm_delete: Do you really want to delete the order? confirm_end: Do you really want to close the order %{order}? There is no going back. new_order: Create new order - no_open_orders: There are currently no open orders. - open_orders: Current orders - orders_in_progress: In process + no_open_or_finished_orders: There are currently no open or closed orders. + orders_finished: Closed + orders_open: Open + orders_settled: Settled title: Manage orders model: error_closed: Order was already settled diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 228bc1cf..189a5073 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1126,10 +1126,11 @@ fr: action_end: Terminer confirm_delete: Vraiment supprimer la commande? confirm_end: Veux tu vraiment mettre fin à la commande %{order}? Attention, il n'y aura pas d'annulation possible. - ended_orders: Commandes closes new_order: Définir une nouvelle commande - no_open_orders: Il n'y a aucune commande en cours en ce moment. - open_orders: Commandes en cours + no_open_or_finished_orders: Il n'y a aucune commande en cours en ce moment. + orders_finished: Close + orders_open: En cours + orders_settled: Décomptée title: Gestion des commandes model: error_closed: Cette commande a déjà été décomptée diff --git a/config/locales/nl.yml b/config/locales/nl.yml index f175d3f7..f9f305d8 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1101,10 +1101,11 @@ nl: action_end: Sluiten confirm_delete: Wil je de bestelling werkelijk verwijderen? confirm_end: Wil je de bestelling %{order} werkelijk sluiten? Dit kun je niet ongedaan maken. - ended_orders: Gesloten bestellingen new_order: Nieuwe bestelling openen - no_open_orders: Er zijn momenteel geen lopende bestellingen. - open_orders: Lopende bestellingen + no_open_or_finished_orders: Er zijn momenteel geen open of gesloten bestellingen. + orders_finished: Gesloten + orders_open: Open + orders_settled: Afgerekend title: Bestellingen beheren model: error_closed: Bestelling was al afgerekend