From af3c07f03188823fe71cadede34cb594e20515b1 Mon Sep 17 00:00:00 2001 From: benni Date: Fri, 27 Jul 2012 18:03:46 +0200 Subject: [PATCH] Simplifiying balancing view part 2. Lets call it finished. --- .../finance/balancing_controller.rb | 157 +++--------------- .../group_order_articles_controller.rb | 73 ++++++++ .../finance/order_articles_controller.rb | 2 +- app/helpers/finance/balancing_helper.rb | 13 ++ app/helpers/finance/order_articles_helper.rb | 8 + app/models/group_order_article.rb | 10 ++ app/models/order.rb | 6 + .../_edit_group_order_article.html.haml | 21 --- .../balancing/_edit_order_article.html.haml | 7 - .../balancing/_group_order_articles.html.haml | 18 +- .../_new_group_order_article.html.haml | 17 -- .../balancing/_order_article.html.haml | 4 +- app/views/finance/balancing/confirm.html.haml | 4 +- app/views/finance/balancing/index.html.haml | 2 +- app/views/finance/balancing/list.html.haml | 11 +- app/views/finance/balancing/new.html.haml | 11 +- app/views/finance/balancing/new.js.erb | 1 + .../group_order_articles/_form.html.haml | 9 + .../finance/group_order_articles/edit.js.erb | 1 + .../finance/group_order_articles/new.js.erb | 1 + .../group_order_articles/update.js.erb | 5 + .../finance/order_articles/_edit.html.haml | 1 - .../finance/order_articles/_new.html.haml | 2 +- config/locales/de.yml | 3 + config/routes.rb | 13 +- public/javascripts/application.js | 4 +- 26 files changed, 185 insertions(+), 219 deletions(-) create mode 100644 app/helpers/finance/balancing_helper.rb delete mode 100644 app/views/finance/balancing/_edit_group_order_article.html.haml delete mode 100644 app/views/finance/balancing/_edit_order_article.html.haml delete mode 100644 app/views/finance/balancing/_new_group_order_article.html.haml create mode 100644 app/views/finance/balancing/new.js.erb create mode 100644 app/views/finance/group_order_articles/_form.html.haml create mode 100644 app/views/finance/group_order_articles/edit.js.erb create mode 100644 app/views/finance/group_order_articles/new.js.erb create mode 100644 app/views/finance/group_order_articles/update.js.erb diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index b766320d..ed6478a6 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -13,7 +13,8 @@ class Finance::BalancingController < ApplicationController end def new - @order = Order.find(params[:id]) + @order = Order.find(params[:order_id]) + flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed? @comments = @order.comments if params['sort'] @@ -35,131 +36,20 @@ class Finance::BalancingController < ApplicationController @articles = @articles.to_a.sort { |a,b| b.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> a.article.order_number.gsub(/[^[:digit:]]/, "").to_i } end - view = params[:view] - params[:view] = nil - - case view.try(:to_sym) - when 'editResults' - render :partial => 'edit_results_by_articles' and return - when :groups_overview - render :partial => 'shared/articles_by_groups', :locals => {:order => @order} and return - when 'articlesOverview' - render :partial => 'shared/articles_by_articles', :locals => {:order => @order} and return - end + render layout: false if request.xhr? end - def new_group_order_article - goa = OrderArticle.find(params[:id]).group_order_articles.build - render :update do |page| - page["edit_box"].replace_html :partial => "new_group_order_article", - :locals => {:group_order_article => goa} - page["edit_box"].show - end + def edit_note + @order = Order.find(params[:id]) + render :layout => false end - # Creates a new GroupOrderArticle - # If the the chosen Ordergroup hasn't ordered yet, a GroupOrder will also be created - #FIXME: Clean up this messy code ! - def create_group_order_article - goa = GroupOrderArticle.new(params[:group_order_article]) - order_article = goa.order_article - order = order_article.order - - # creates a new GroupOrder if necessary - group_order = GroupOrder.first :conditions => {:order_id => order.id, :ordergroup_id => goa.ordergroup_id} - unless group_order - goa.create_group_order(:order_id => order.id, :ordergroup_id => goa.ordergroup_id) + def update_note + @order = Order.find(params[:id]) + if @order.update_attributes(params[:order]) + render :layout => false else - goa.group_order = group_order - end - - # If there is an GroupOrderArticle already, only update result attribute. - if group_order_article = GroupOrderArticle.first(:conditions => {:group_order_id => goa.group_order, :order_article_id => goa.order_article}) - goa = group_order_article - goa.result = params[:group_order_article]["result"] - end - - render :update do |page| - if goa.save - goa.group_order.update_price! # Update the price attribute of new GroupOrder - order_article.update_results! if order_article.article.is_a?(StockArticle) # Update units_to_order of order_article - page["edit_box"].hide - page["order_article_#{order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => order_article} - - page["group_order_articles_#{order_article.id}"].replace_html :partial => 'group_order_articles', - :locals => {:order_article => order_article} - page["group_order_article_#{goa.id}"].visual_effect :highlight, :duration => 2 - - page["summary"].replace_html :partial => 'summary', :locals => {:order => order} - page["order_profit"].visual_effect :highlight, :duration => 2 - else - page["edit_box"].replace_html :partial => "new_group_order_article", - :locals => {:group_order_article => goa} - end - end - end - - def edit_group_order_article - group_order_article = GroupOrderArticle.find(params[:id]) - render :partial => 'edit_group_order_article', - :locals => {:group_order_article => group_order_article} - end - - def update_group_order_article - goa = GroupOrderArticle.find(params[:id]) - - render :update do |page| - if goa.update_attributes(params[:group_order_article]) - goa.group_order.update_price! # Update the price attribute of new GroupOrder - goa.order_article.update_results! if goa.order_article.article.is_a?(StockArticle) # Update units_to_order of order_article - - page["edit_box"].hide - page["order_article_#{goa.order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => goa.order_article} - page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles', - :locals => {:order_article => goa.order_article} - page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order} - page["order_profit"].visual_effect :highlight, :duration => 2 - else - page["edit_box"].replace_html :partial => 'edit_group_order_article' - end - end - end - - def update_group_order_article_result - goa = GroupOrderArticle.find(params[:id]) - - if params[:modifier] == '-' - goa.update_attributes({:result => goa.result - 1}) - elsif params[:modifier] == '+' - goa.update_attributes({:result => goa.result + 1}) - end - - render :update do |page| - goa.group_order.update_price! # Update the price attribute of new GroupOrder - goa.order_article.update_results! if goa.order_article.article.is_a?(StockArticle) # Update units_to_order of order_article - - page["order_article_#{goa.order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => goa.order_article} - page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles', - :locals => {:order_article => goa.order_article} - page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order} - page["order_profit"].visual_effect :highlight, :duration => 2 - end - - end - - def destroy_group_order_article - goa = GroupOrderArticle.find(params[:id]) - goa.destroy - goa.group_order.update_price! # Updates the price attribute of new GroupOrder - goa.order_article.update_results! if goa.order_article.article.is_a?(StockArticle) # Update units_to_order of order_article - - render :update do |page| - page["edit_box"].hide - page["order_article_#{goa.order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => goa.order_article} - page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles', - :locals => {:order_article => goa.order_article} - page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order} - page["order_profit"].visual_effect :highlight, :duration => 2 + render :action => :edit_note, :layout => false end end @@ -171,27 +61,20 @@ class Finance::BalancingController < ApplicationController # Balances the Order, Update of the Ordergroup.account_balances def close @order = Order.find(params[:id]) - begin - @order.close!(@current_user) - flash[:notice] = "Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert." - redirect_to :action => "index" - rescue => e - flash[:error] = "Ein Fehler ist beim Abrechnen aufgetreten: " + e - redirect_to :action => "new", :id => @order - end + @order.close!(@current_user) + redirect_to finance_balancing_url, notice: "Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert." + + rescue => error + redirect_to finance_balancing_url, alert: "Ein Fehler ist beim Abrechnen aufgetreten: #{error.message}" end # Close the order directly, without automaticly updating ordergroups account balances def close_direct @order = Order.find(params[:id]) - if @order.finished? - @order.update_attributes(:state => 'closed', :updated_by => @current_user) - flash[:notice] = 'Die Bestellung wurde auf "gebucht" gesetzt.' - redirect_to :action => 'listOrders', :id => @order - else - flash[:error] = 'Die Bestellung ist noch nicht beendet.' - redirect_to :action => 'listOrders', :id => @order - end + @order.close_direct!(@current_user) + redirect_to finance_balancing_url, notice: "Bestellung wurde geschlossen." + rescue => error + redirect_to finance_balancing_url, alert: "Bestellung kann nicht geschlossen werden: #{error.message}" end end diff --git a/app/controllers/finance/group_order_articles_controller.rb b/app/controllers/finance/group_order_articles_controller.rb index 6f780c73..705e2b2f 100644 --- a/app/controllers/finance/group_order_articles_controller.rb +++ b/app/controllers/finance/group_order_articles_controller.rb @@ -6,5 +6,78 @@ class Finance::GroupOrderArticlesController < ApplicationController def new @order_article = OrderArticle.find(params[:order_article_id]) + @group_order_article = GroupOrderArticle.new(order_article: @order_article) + end + + def create + @group_order_article = GroupOrderArticle.new(params[:group_order_article]) + @order_article = @group_order_article.order_article + + # As we hide group_order_articles with a result of 0, we should not complain, when an existing group_order_article is found + goa = GroupOrderArticle.where(group_order_id: @group_order_article.group_order_id, + order_article_id: @order_article.id).first + + if goa and goa.update_attributes(params[:group_order_article]) + @group_order_article = goa + + update_summaries(@group_order_article) + render :update + + elsif @group_order_article.save + update_summaries(@group_order_article) + render :update + + else # Validation failed, show form + render :new + end + end + + def edit + @group_order_article = GroupOrderArticle.find(params[:id]) + @order_article = @group_order_article.order_article + end + + def update + @group_order_article = GroupOrderArticle.find(params[:id]) + @order_article = @group_order_article.order_article + + if @group_order_article.update_attributes(params[:group_order_article]) + update_summaries(@group_order_article) + else + render :edit + end + end + + def update_result + group_order_article = GroupOrderArticle.find(params[:id]) + @order_article = group_order_article.order_article + + if params[:modifier] == '-' + group_order_article.update_attribute :result, group_order_article.result - 1 + elsif params[:modifier] == '+' + group_order_article.update_attribute :result, group_order_article.result + 1 + end + + update_summaries(group_order_article) + + render :update + end + + def destroy + group_order_article = GroupOrderArticle.find(params[:id]) + group_order_article.destroy + update_summaries(group_order_article) + @order_article = group_order_article.order_article + + render :update + end + + protected + + def update_summaries(group_order_article) + # Update the price attribute of new GroupOrder + group_order_article.group_order.update_price! + # Update units_to_order of order_article + group_order_article.order_article.update_results! if group_order_article.order_article.article.is_a?(StockArticle) end end diff --git a/app/controllers/finance/order_articles_controller.rb b/app/controllers/finance/order_articles_controller.rb index a6e62b55..435d1712 100644 --- a/app/controllers/finance/order_articles_controller.rb +++ b/app/controllers/finance/order_articles_controller.rb @@ -2,7 +2,7 @@ class Finance::OrderArticlesController < ApplicationController before_filter :authenticate_finance - layout false # We only use this controller to server js snippets, no need for layout rendering + layout false # We only use this controller to serve js snippets, no need for layout rendering def new @order = Order.find(params[:order_id]) diff --git a/app/helpers/finance/balancing_helper.rb b/app/helpers/finance/balancing_helper.rb new file mode 100644 index 00000000..2daa44b2 --- /dev/null +++ b/app/helpers/finance/balancing_helper.rb @@ -0,0 +1,13 @@ +module Finance::BalancingHelper + def balancing_view_partial + view = params[:view] || 'edit_results' + case view + when 'edit_results' then + 'edit_results_by_articles' + when 'groups_overview' then + 'shared/articles_by_groups' + when 'articles_overview' then + 'shared/articles_by_articles' + end + end +end diff --git a/app/helpers/finance/order_articles_helper.rb b/app/helpers/finance/order_articles_helper.rb index 7c97d8da..dd2faf39 100644 --- a/app/helpers/finance/order_articles_helper.rb +++ b/app/helpers/finance/order_articles_helper.rb @@ -1,2 +1,10 @@ module Finance::OrderArticlesHelper + + def new_order_articles_collection + if @order.stockit? + StockArticle.order(:name) + else + @order.supplier.articles.order(:name) + end + end end diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 76255347..2ec41405 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -18,6 +18,16 @@ class GroupOrderArticle < ActiveRecord::Base localize_input_of :result + # Setter used in group_order_article#new + # We have to create an group_order, if the ordergroup wasn't involved in the order yet + def ordergroup_id=(id) + self.group_order = GroupOrder.find_or_initialize_by_order_id_and_ordergroup_id(order_article.order_id, id) + end + + def ordergroup_id + group_order.try(:ordergroup_id) + end + # Updates the quantity/tolerance for this GroupOrderArticle by updating both GroupOrderArticle properties # and the associated GroupOrderArticleQuantities chronologically. # diff --git a/app/models/order.rb b/app/models/order.rb index 4cea94b0..7578bbc3 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -194,6 +194,12 @@ class Order < ActiveRecord::Base end end + # Close the order directly, without automaticly updating ordergroups account balances + def close_direct!(user) + raise "Bestellung wurde schon abgerechnet" if closed? + update_attributes! state: 'closed', updated_by: user + end + protected def starts_before_ends diff --git a/app/views/finance/balancing/_edit_group_order_article.html.haml b/app/views/finance/balancing/_edit_group_order_article.html.haml deleted file mode 100644 index 3733af80..00000000 --- a/app/views/finance/balancing/_edit_group_order_article.html.haml +++ /dev/null @@ -1,21 +0,0 @@ -%h2 Mengenänderung -%p - = group_order_article.group_order.ordergroup.name - hat von - = group_order_article.order_article.article.name - bekommen: - -- remote_form_for group_order_article, | - :url => {:action => 'update_group_order_article', :id => group_order_article }, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| | - - = form.error_messages - %p - %b Menge: - (Einheit: - = group_order_article.order_article.article.unit - ) - = form.text_field :result, :size => "6" - = submit_tag "Speichern" - | - = link_to_function 'Abbrechen', "Element.hide('edit_box')" \ No newline at end of file diff --git a/app/views/finance/balancing/_edit_order_article.html.haml b/app/views/finance/balancing/_edit_order_article.html.haml deleted file mode 100644 index f20378d6..00000000 --- a/app/views/finance/balancing/_edit_order_article.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h2 - Bearbeiten von - = @order_article.article.name - -- remote_form_for :order_article, :url => {:action => 'update_order_article', :id => @order_article }, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do | - = render :partial => "order_article_form" \ No newline at end of file diff --git a/app/views/finance/balancing/_group_order_articles.html.haml b/app/views/finance/balancing/_group_order_articles.html.haml index e56856f4..aff458e4 100644 --- a/app/views/finance/balancing/_group_order_articles.html.haml +++ b/app/views/finance/balancing/_group_order_articles.html.haml @@ -7,7 +7,7 @@ %td Einheiten %td Gesamtpreis %td{:colspan => "3",:style => "width:14em"} - = link_to '[Gruppe hinzufügen]', new_finance_group_order_article_path(order_id: order_article.order_id), + = link_to '[Gruppe hinzufügen]', new_finance_group_order_article_path(order_article_id: order_article.id), remote: true %tbody - for group_order_article in order_article.group_order_articles.ordered.all(:include => [:group_order]) @@ -17,19 +17,17 @@ = group_order_article.group_order.ordergroup.name %td{:id => "group_order_article_#{group_order_article.id}_quantity", :style => "white-space:nowrap"} = group_order_article.result - /= button_to_remote( "+", :url => {:action => "update_group_order_article_result", :id => group_order_article, :modifier => '+'}, :html => {:style => "float:left"}, :success => "Element.hide('loader');", :before => "Element.show('loader');") - /= button_to_remote( "-", :url => {:action => "update_group_order_article_result", :id => group_order_article, :modifier => '-'}, :success => "Element.hide('loader');", :before => "Element.show('loader');") + = button_to "+", update_result_finance_group_order_article_path(group_order_article, modifier: '+'), + method: :put, remote: true, style: 'float:left' + = button_to "-", update_result_finance_group_order_article_path(group_order_article, modifier: '-'), + method: :put, remote: true %td.currency = number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.result, :unit => "") %td.actions{:style=>"width:1em"} - = link_to icon(:edit), '#' - /:update => 'edit_box', | - /:url => {:action => 'edit_group_order_article', :id => group_order_article}, | - /:success => "Element.hide('loader'); Element.show('edit_box')" | + = link_to icon(:edit), edit_finance_group_order_article_path(group_order_article), remote: true %td.actions{:style=>"width:1em"} - = link_to icon(:delete), '#' - /:url => {:action => 'destroy_group_order_article', :id => group_order_article}, | - /:confirm => 'Bist du sicher?', :method => 'post' | + = link_to icon(:delete), finance_group_order_article_path(group_order_article), method: :delete, + remote: true %td %tfoot %tr{:class => cycle('even', 'odd', :name => 'results')} diff --git a/app/views/finance/balancing/_new_group_order_article.html.haml b/app/views/finance/balancing/_new_group_order_article.html.haml deleted file mode 100644 index 1291ff01..00000000 --- a/app/views/finance/balancing/_new_group_order_article.html.haml +++ /dev/null @@ -1,17 +0,0 @@ -%h2 - Neue Gruppenmenge für - = group_order_article.order_article.article.name -- remote_form_for group_order_article, :url => {:action => 'create_group_order_article'}, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| | - = form.error_messages - %p - Gruppe: - = form.select :ordergroup_id, Ordergroup.all(:order => "name").collect{ |og| [og.name, og.id] } - %p - Menge: - = form.text_field :result, :size => 5 - = form.hidden_field :order_article_id - %p - = submit_tag "Speichern" - | - = link_to_function 'Abbrechen', "Element.hide('edit_box')" \ No newline at end of file diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index cbe12110..bd43d01b 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -19,7 +19,7 @@ %td= order_article.price.tax %td= order_article.price.deposit %td - = link_to icon(:edit), edit_finance_order_order_article_path(@order, order_article), remote: true + = link_to icon(:edit), edit_finance_order_order_article_path(order_article.order, order_article), remote: true %td - = link_to icon(:delete), finance_order_order_article_path(@order, order_article), method: :delete, + = link_to icon(:delete), finance_order_order_article_path(order_article.order, order_article), method: :delete, remote: true, confirm: 'Bist du sicher?' \ No newline at end of file diff --git a/app/views/finance/balancing/confirm.html.haml b/app/views/finance/balancing/confirm.html.haml index 1a6bdff5..48784f43 100644 --- a/app/views/finance/balancing/confirm.html.haml +++ b/app/views/finance/balancing/confirm.html.haml @@ -11,6 +11,6 @@ %td= number_to_currency(group_order.price) %p %div{:style => "float:left"} - = button_to "Abschließen", :action => "close", :id => @order + = button_to "Abschließen", close_finance_order_path(@order), method: :put %div{:style => "float:right"} - = link_to 'Zurück zur Abrechnung', :action => 'new', :id => @order \ No newline at end of file + = link_to 'Zurück zur Abrechnung', new_finance_order_path(order_id: @order.id) \ No newline at end of file diff --git a/app/views/finance/balancing/index.html.haml b/app/views/finance/balancing/index.html.haml index a52928f5..3d1bd13b 100644 --- a/app/views/finance/balancing/index.html.haml +++ b/app/views/finance/balancing/index.html.haml @@ -58,6 +58,6 @@ %td= order.name %td= format_date(order.ends) %td{:class => "currency"}= number_to_currency(order.sum(:fc)) - %td= link_to "abrechnen", new_finance_order_path(id: order) + %td= link_to "abrechnen", new_finance_order_path(order_id: order.id) - else Super, alles schon abgerechnet... \ No newline at end of file diff --git a/app/views/finance/balancing/list.html.haml b/app/views/finance/balancing/list.html.haml index 861c1e99..b60ce9c2 100644 --- a/app/views/finance/balancing/list.html.haml +++ b/app/views/finance/balancing/list.html.haml @@ -1,7 +1,4 @@ - title "beendete Bestellungen" -%p{:style => "width:30em"} - %i - Beschreibungstext für die Abrechnunsmodi .... .left_column{:style => "width:70em"} .box_title .column_content @@ -18,15 +15,15 @@ %tbody - @orders.each do |order| %tr{:class => cycle("even","odd", :name => "order")} - %td= link_to truncate(order.name), :action => "new", :id => order + %td= link_to truncate(order.name), new_finance_order_path(order_id: order.id) %td=h format_time(order.ends) unless order.ends.nil? %td= order.closed? ? "abgerechnet (#{number_to_currency order.foodcoop_result})" : "beendet" %td= order.updated_by.nil? ? '??' : order.updated_by.nick %td - unless order.closed? - = link_to "abrechnen", :action => "new", :id => order + = link_to "abrechnen", new_finance_order_path(order_id: order.id) | - = link_to 'direkt schließen', {:action => 'close_direct', :id => order}, | - :confirm => 'Wirklich die Bestellung schließen setzen?', :method => "post" | + = link_to 'direkt schließen', close_direct_finance_order_path(order), + :confirm => 'Wirklich die Bestellung schließen setzen?', :method => :put - else %i derzeit gibt es keine beendeten Bestellungen \ No newline at end of file diff --git a/app/views/finance/balancing/new.html.haml b/app/views/finance/balancing/new.html.haml index 184f722f..96f79d75 100644 --- a/app/views/finance/balancing/new.html.haml +++ b/app/views/finance/balancing/new.html.haml @@ -1,8 +1,5 @@ - title "#{@order.name} abrechnen" -- if @order.closed? - %p - %b Achtung, Bestellung wurde schon abgerechnet! .left_column{:style => 'width: 24em'} .box_title %h2 Zusammenfassung @@ -46,11 +43,11 @@ .box_title #editOrderNav %ul - %li= link_to 'Gruppenübersicht', new_finance_order_path(@order, view: :groups_overview) - /%li= remote_link_to 'Artikelübersicht', :update => 'results', :url => {:action => 'new', :id => @order, :view => 'articlesOverview'} - /%li= remote_link_to 'Bestellung bearbeiten', :update => 'results', :url => {:action => 'new', :id => @order, :view => 'editResults'} + %li= link_to 'Bestellung bearbeiten', new_finance_order_path(order_id: @order.id, view: 'edit_results'), remote: true + %li= link_to 'Gruppenübersicht', new_finance_order_path(order_id: @order.id, view: 'groups_overview'), remote: true + %li= link_to 'Artikelübersicht', new_finance_order_path(order_id: @order.id, view: 'articles_overview'), remote: true .column_content #results - = render :partial => 'edit_results_by_articles' + = render partial: 'edit_results_by_articles' %p= link_to_top #edit_box{:style => 'display:none'} \ No newline at end of file diff --git a/app/views/finance/balancing/new.js.erb b/app/views/finance/balancing/new.js.erb new file mode 100644 index 00000000..041f636f --- /dev/null +++ b/app/views/finance/balancing/new.js.erb @@ -0,0 +1 @@ +$('#results').html('<%= escape_javascript(render(partial: balancing_view_partial, locals: {order: @order})) %>'); \ No newline at end of file diff --git a/app/views/finance/group_order_articles/_form.html.haml b/app/views/finance/group_order_articles/_form.html.haml new file mode 100644 index 00000000..9b674c56 --- /dev/null +++ b/app/views/finance/group_order_articles/_form.html.haml @@ -0,0 +1,9 @@ +%h2 Mengenänderung +%p + %b Artikel: #{@order_article.article.name} + +- simple_form_for [:finance, @group_order_article], remote: true do |form| + = form.hidden_field :order_article_id + = form.input :ordergroup_id, as: :select, collection: Ordergroup.all.map { |g| [g.name, g.id] } + = form.input :result, hint: "Einheit: #{@order_article.article.unit}" + = form.submit 'Speichern' \ No newline at end of file diff --git a/app/views/finance/group_order_articles/edit.js.erb b/app/views/finance/group_order_articles/edit.js.erb new file mode 100644 index 00000000..1eb75cd7 --- /dev/null +++ b/app/views/finance/group_order_articles/edit.js.erb @@ -0,0 +1 @@ +$.fancybox('<%= escape_javascript(render('form')) %>'); \ No newline at end of file diff --git a/app/views/finance/group_order_articles/new.js.erb b/app/views/finance/group_order_articles/new.js.erb new file mode 100644 index 00000000..3c8d6f34 --- /dev/null +++ b/app/views/finance/group_order_articles/new.js.erb @@ -0,0 +1 @@ +$.fancybox('<%= escape_javascript(render("form")) %>'); \ No newline at end of file diff --git a/app/views/finance/group_order_articles/update.js.erb b/app/views/finance/group_order_articles/update.js.erb new file mode 100644 index 00000000..a4341f91 --- /dev/null +++ b/app/views/finance/group_order_articles/update.js.erb @@ -0,0 +1,5 @@ +$.fancybox.close(); +$('#order_article_<%= @order_article.id %>'). + html('<%= escape_javascript(render(partial: 'finance/balancing/order_article', locals: {order_article: @order_article})) %>'); +$('#group_order_articles_<%= @order_article.id %>'). + html('<%= escape_javascript(render(partial: 'finance/balancing/group_order_articles', locals: {order_article: @order_article})) %>'); \ No newline at end of file diff --git a/app/views/finance/order_articles/_edit.html.haml b/app/views/finance/order_articles/_edit.html.haml index 7d916395..200d7e26 100644 --- a/app/views/finance/order_articles/_edit.html.haml +++ b/app/views/finance/order_articles/_edit.html.haml @@ -1,7 +1,6 @@ %h2 Artikel aktualisieren = form_for [:finance, @order, @order_article], remote: true do |form| - = @order_article.errors.try(:full_messages) %table %tr %th Name diff --git a/app/views/finance/order_articles/_new.html.haml b/app/views/finance/order_articles/_new.html.haml index 04f7f564..03f29132 100644 --- a/app/views/finance/order_articles/_new.html.haml +++ b/app/views/finance/order_articles/_new.html.haml @@ -2,5 +2,5 @@ Neuer gelieferter Artikel die Bestellung = simple_form_for [:finance, @order, @order_article], remote: true do |form| - = form.input :article_id, as: :select, collection: @order.supplier.articles.order(:name) + = form.input :article_id, as: :select, collection: new_order_articles_collection = form.submit \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index f9c58c65..a9425d64 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -348,6 +348,9 @@ de: ends: "Endet am" order_article: article_id: Artikel aus dem Katalog wählen + group_order_article: + ordergroup_id: Bestellgruppe + result: Menge invoice: supplier: Lieferant number: Nummer diff --git a/config/routes.rb b/config/routes.rb index d78fba8f..63036cbc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -119,19 +119,26 @@ Foodsoft::Application.routes.draw do namespace :finance do root :to => 'balancing#index' + match 'balancing/list' => 'balancing#list', :as => 'balancing' resources :order, controller: 'balancing', path: 'balancing' do member do get :edit_note put :update_note + + get :confirm + put :close + put :close_direct end resources :order_articles end - resources :group_order_articles - - match 'balancing/list' => 'balancing#list', :as => 'balancing' + resources :group_order_articles do + member do + put :update_result + end + end resources :invoices diff --git a/public/javascripts/application.js b/public/javascripts/application.js index b1c8e9e0..60f5c492 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -2,13 +2,13 @@ $(function() { // Show/Hide a specific DOM element - $('a[data-toggle-this]').click(function() { + $('a[data-toggle-this]').live('click', function() { $($(this).data('toggle-this')).toggle(); return false; }); // Remove this item from DOM - $('a[data-remove-this').click(function() { + $('a[data-remove-this]').live('click', function() { $($(this).data('remove-this')).remove(); return false; });