From 190a77727849eba550c0d7c8ea1ef13c8768ea86 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Thu, 29 Jan 2009 21:28:22 +0100 Subject: [PATCH] Order refactoring part two: Balancing workflow was adapted to the new order schema. Article modification is still missing. --- .../finance/balancing_controller.rb | 341 ++++++++---------- .../finance/invoices_controller.rb | 18 +- app/controllers/orders_controller.rb | 4 +- app/helpers/application_helper.rb | 6 + app/models/group.rb | 3 +- app/models/group_order.rb | 5 +- app/models/group_order_article.rb | 5 +- app/models/invoice.rb | 5 + app/models/order.rb | 10 +- app/models/order_article.rb | 28 +- app/models/ordergroup.rb | 3 +- app/models/user.rb | 7 +- app/models/workgroup.rb | 3 +- .../finance/balancing/_articleResult.haml | 21 -- .../finance/balancing/_articleResultForm.haml | 29 -- .../finance/balancing/_articleResults.haml | 5 - .../finance/balancing/_articlesOverview.haml | 17 - .../finance/balancing/_editGroupResult.haml | 20 - app/views/finance/balancing/_editNote.haml | 10 - app/views/finance/balancing/_editSummary.haml | 27 -- .../_edit_group_order_article.html.haml | 21 ++ .../finance/balancing/_edit_note.html.haml | 9 + ...ml => _edit_results_by_articles.html.haml} | 8 +- .../balancing/_groupOrderArticleResults.haml | 25 -- app/views/finance/balancing/_groupResult.haml | 17 - .../finance/balancing/_groupResults.haml | 2 - .../balancing/_group_order_articles.html.haml | 39 ++ .../finance/balancing/_groupsOverview.haml | 30 -- .../finance/balancing/_invoice.html.haml | 24 ++ .../finance/balancing/_newArticleResult.haml | 7 - .../finance/balancing/_newGroupResult.haml | 17 - .../_new_group_order_article.html.haml | 17 + .../balancing/_new_order_article.html.haml | 7 + .../balancing/_order_article.html.haml | 18 + .../balancing/_order_article_form.html.haml | 26 ++ .../balancing/_order_article_result.html.haml | 5 + app/views/finance/balancing/_summary.haml | 81 ++--- app/views/finance/balancing/confirm.html.haml | 12 +- app/views/finance/balancing/index.haml | 4 +- app/views/finance/balancing/list.html.haml | 13 +- app/views/finance/balancing/new.html.haml | 39 +- app/views/finance/invoices/_form.html.haml | 11 + .../_articles_by_articles.html.haml | 0 .../_articles_by_groups.html.haml | 0 app/views/shared/_comments.haml | 10 +- db/migrate/20090119155930_acts_as_paranoid.rb | 4 +- .../20090120184410_refactor_order_logic.rb | 117 +++--- db/schema.rb | 4 +- public/images/arrow_right_red.png | Bin 0 -> 356 bytes public/stylesheets/main.css | 12 +- public/stylesheets/print.css | 12 +- public/stylesheets/sass/main.sass | 10 +- test/fixtures/groups.yml | 3 +- 53 files changed, 568 insertions(+), 603 deletions(-) delete mode 100644 app/views/finance/balancing/_articleResult.haml delete mode 100644 app/views/finance/balancing/_articleResultForm.haml delete mode 100644 app/views/finance/balancing/_articleResults.haml delete mode 100644 app/views/finance/balancing/_articlesOverview.haml delete mode 100644 app/views/finance/balancing/_editGroupResult.haml delete mode 100644 app/views/finance/balancing/_editNote.haml delete mode 100644 app/views/finance/balancing/_editSummary.haml create mode 100644 app/views/finance/balancing/_edit_group_order_article.html.haml create mode 100644 app/views/finance/balancing/_edit_note.html.haml rename app/views/finance/balancing/{_editResults.haml => _edit_results_by_articles.html.haml} (50%) delete mode 100644 app/views/finance/balancing/_groupOrderArticleResults.haml delete mode 100644 app/views/finance/balancing/_groupResult.haml delete mode 100644 app/views/finance/balancing/_groupResults.haml create mode 100644 app/views/finance/balancing/_group_order_articles.html.haml delete mode 100644 app/views/finance/balancing/_groupsOverview.haml create mode 100644 app/views/finance/balancing/_invoice.html.haml delete mode 100644 app/views/finance/balancing/_newArticleResult.haml delete mode 100644 app/views/finance/balancing/_newGroupResult.haml create mode 100644 app/views/finance/balancing/_new_group_order_article.html.haml create mode 100644 app/views/finance/balancing/_new_order_article.html.haml create mode 100644 app/views/finance/balancing/_order_article.html.haml create mode 100644 app/views/finance/balancing/_order_article_form.html.haml create mode 100644 app/views/finance/balancing/_order_article_result.html.haml rename app/views/{orders => shared}/_articles_by_articles.html.haml (100%) rename app/views/{orders => shared}/_articles_by_groups.html.haml (100%) create mode 100644 public/images/arrow_right_red.png diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 9a475057..f506b174 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -1,9 +1,10 @@ class Finance::BalancingController < ApplicationController before_filter :authenticate_finance - + verify :method => :post, :only => [:close_direct] + def index @financial_transactions = FinancialTransaction.find(:all, :order => "created_on DESC", :limit => 8) - @orders = Order.find(:all, :conditions => 'finished = 1 AND booked = 0', :order => 'ends DESC') + @orders = Order.finished @unpaid_invoices = Invoice.unpaid end @@ -16,204 +17,180 @@ class Finance::BalancingController < ApplicationController @comments = @order.comments case params[:view] when 'editResults' - render :partial => 'editResults' + render :partial => 'edit_results_by_articles' when 'groupsOverview' - render :partial => 'groupsOverview' + render :partial => 'shared/articles_by_groups', :locals => {:order => @order} when 'articlesOverview' - render :partial => 'articlesOverview' - when "editNote" - render :partial => "editNote" + render :partial => 'shared/articles_by_articles', :locals => {:order => @order} end end - def newArticleResult + def edit_note @order = Order.find(params[:id]) - @article = @order.order_article_results.build(:tax => 7, :deposit => 0) - render :update do |page| - page["edit_box"].replace_html :partial => "newArticleResult" - page["edit_box"].show - end + render :partial => 'edit_note' end - def createArticleResult - render :update do |page| - @article = OrderArticleResult.new(params[:order_article_result]) - @article.fc_markup = APP_CONFIG[:price_markup] - @article.make_gross if @article.tax && @article.deposit && @article.price - if @article.valid? - @article.save - @order = @article.order - page["edit_box"].hide - page["order_summary"].replace_html :partial => 'summary' - page.insert_html :bottom, "result_table", :partial => "articleResults" - page["order_article_result_#{@article.id}"].visual_effect :highlight, :duration => 2 - page["group_order_article_results_#{@article.id}"].show - else - page["edit_box"].replace_html :partial => "newArticleResult" - end - end - end - - def editArticleResult - @article = OrderArticleResult.find(params[:id]) - render :update do |page| - page["edit_box"].replace_html :partial => 'editArticleResult' - page["edit_box"].show - end - end - - def updateArticleResult - @article = OrderArticleResult.find(params[:id]) - @article.attributes=(params[:order_article_result]) # update attributes but doesn't save - @article.make_gross - @order = @article.order - @ordered_articles = @order.order_article_results - @group_orders = @order.group_order_results - render :update do |page| - if @article.save - page["edit_box"].hide - page["order_summary"].replace_html :partial => 'summary' - page["order_summary"].visual_effect :highlight, :duration => 2 - page["order_article_result_#{@article.id}"].replace_html :partial => 'articleResult' - page['order_article_result_'+@article.id.to_s].visual_effect :highlight, :delay => 0.5, :duration => 2 - page["group_order_article_results_#{@article.id}"].replace_html :partial => "groupOrderArticleResults" - else - page['edit_box'].replace_html :partial => 'editArticleResult' - end - end - end - - def destroyArticleResult - if @article = OrderArticleResult.find(params[:id]).destroy - @order = @article.order - render :update do |page| - page["order_article_result_#{@article.id}"].remove - page["group_order_article_results_#{@article.id}"].remove - page["order_summary"].replace_html :partial => 'summary' - page["order_summary"].visual_effect :highlight, :duration => 2 - end - end - end - - def newGroupResult - @result = OrderArticleResult.find(params[:id]).group_order_article_results.build - render :update do |page| - page["edit_box"].replace_html :partial => "newGroupResult" - page["edit_box"].show - end - end - - # Creates a new GroupOrderArticleResult - # If the the chosen Ordergroup hasn't ordered yet, a GroupOrderResult will created - def createGroupResult - @result = GroupOrderArticleResult.new(params[:group_order_article_result]) - order = @result.order_article_result.order - orderGroup = Ordergroup.find(params[:group_order_article_result][:group_order_result_id]) - # creates a new GroupOrderResult if necessary - unless @result.group_order_result = GroupOrderResult.find(:first, - :conditions => ["group_order_results.group_name = ? AND group_order_results.order_id = ?", orderGroup.name, order.id ]) - @result.group_order_result = GroupOrderResult.create(:order => order, :group_name => orderGroup.name) - end - render :update do |page| - if @result.valid? && @result.save - @result.group_order_result.updatePrice #updates the price attribute - article = @result.order_article_result - page["edit_box"].hide - page.insert_html :after, "groups_results_#{article.id}", :partial => "groupResults" - page["group_order_article_result_#{@result.id}"].visual_effect :highlight, :duration => 2 - page["groups_amount"].replace_html number_to_currency(article.order.sum('groups')) - page["profit"].replace_html number_to_currency(article.order.profit) - page["profit"].visual_effect :highlight, :duration => 2 - - # get the new sums for quantity and price and replace it - total = article.total - page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] - page["totalArticlePrice_#{article.id}"].replace_html number_to_currency(total[:price]) - else - page["edit_box"].replace_html :partial => "newGroupResult" - end - end - end - - def updateGroupResult - @result = GroupOrderArticleResult.find(params[:id]) - render :update do |page| - if params[:group_order_article_result] - if @result.update_attribute(:quantity, params[:group_order_article_result][:quantity]) - order = @result.group_order_result.order - groups_amount = order.sum(:groups) - article = @result.order_article_result - total = article.total - - page["edit_box"].hide - page["groups_amount"].replace_html number_to_currency(groups_amount) - page["profit"].replace_html number_to_currency(order.profit) - page["groups_amount"].visual_effect :highlight, :duration => 2 - page["profit"].visual_effect :highlight, :duration => 2 - page["group_order_article_result_#{@result.id}"].replace_html :partial => "groupResult" - page["group_order_article_result_#{@result.id}"].visual_effect :highlight, :duration => 2 - page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] - page["totalArticlePrice_#{article.id}"].replace_html total[:price] - page["sum_of_article_#{article.id}"].visual_effect :highlight, :duration => 2 - end - else - page["edit_box"].replace_html :partial => 'editGroupResult' - page["edit_box"].show - end - end - end - - def destroyGroupResult - @result = GroupOrderArticleResult.find(params[:id]) - if @result.destroy - render :update do |page| - article = @result.order_article_result - page["group_order_article_result_#{@result.id}"].remove - page["groups_amount"].replace_html number_to_currency(article.order.sum('groups')) - page["profit"].replace_html number_to_currency(article.order.profit) - page["profit"].visual_effect :highlight, :duration => 2 - total = article.total # get total quantity and price for the ArticleResult - page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] - page["totalArticleQuantity_#{article.id}"].visual_effect :highlight, :duration => 2 - page["totalArticlePrice_#{article.id}"].replace_html number_to_currency(total[:price]) - page["totalArticlePrice_#{article.id}"].visual_effect :highlight, :duration => 2 - end - end - end - - def editOrderSummary - @order = Order.find(params[:id]) - render :update do |page| - page["edit_box"].replace_html :partial => 'editSummary' - page["edit_box"].show - end - end - - def updateOrderSummary + def update_note @order = Order.find(params[:id]) render :update do |page| if @order.update_attributes(params[:order]) + page["note"].replace_html simple_format(@order.note) page["edit_box"].hide - page["order_summary"].replace_html :partial => "summary" - page["clear_invoice"].visual_effect :highlight, :duration => 2 else - page["edit_box"].replace_html :partial => 'editSummary' + page["results"].replace_html :partial => "edit_note" end end end - def updateOrderNote - @order = Order.find(params[:id]) + #TODO: Implement create/update of articles/article_prices... +# def new_order_article +# @order = Order.find(params[:id]) +# order_article = @order.order_articles.build(:tax => 7, :deposit => 0) +# render :update do |page| +# page["edit_box"].replace_html :partial => "new_order_article", :locals => {:order_article => order_article} +# page["edit_box"].show +# end +# end +# +# def create_order_article +# @order = Order.find(params[:order_article][:order_id]) +# order_article = OrderArticle.new(params[:order_article]) +# +# render :update do |page| +# if order_article.save +# page["edit_box"].hide +# page["summary"].replace_html :partial => 'summary' +# page.insert_html :bottom, "result_table", :partial => "order_article_result", :locals => {:order_article => order_article} +# page["order_article_#{order_article.id}"].visual_effect :highlight, :duration => 2 +# page["group_order_articles_#{order_article.id}"].show +# else +# page["edit_box"].replace_html :partial => "new_order_article", :locals => {:order_article => order_article} +# end +# end +# end +# +# def editArticleResult +# @article = OrderArticleResult.find(params[:id]) +# render :update do |page| +# page["edit_box"].replace_html :partial => 'editArticleResult' +# page["edit_box"].show +# end +# end +# +# def updateArticleResult +# @article = OrderArticleResult.find(params[:id]) +# @article.attributes=(params[:order_article_result]) # update attributes but doesn't save +# @article.make_gross +# @order = @article.order +# @ordered_articles = @order.order_article_results +# @group_orders = @order.group_order_results +# render :update do |page| +# if @article.save +# page["edit_box"].hide +# page["summary"].replace_html :partial => 'summary' +# page["summary"].visual_effect :highlight, :duration => 2 +# page["order_article_result_#{@article.id}"].replace_html :partial => 'articleResult' +# page['order_article_result_'+@article.id.to_s].visual_effect :highlight, :delay => 0.5, :duration => 2 +# page["group_order_article_results_#{@article.id}"].replace_html :partial => "groupOrderArticleResults" +# else +# page['edit_box'].replace_html :partial => 'editArticleResult' +# end +# end +# end + + def destroy_order_article + order_article = OrderArticle.find(params[:id]) + order_article.destroy + @order = order_article.order render :update do |page| - if @order.update_attribute(:note, params[:order][:note]) - page["note"].replace_html simple_format(@order.note) - page["results"].replace_html :partial => "groupsOverview" + page["order_article_#{order_article.id}"].remove + page["group_order_articles_#{order_article.id}"].remove + page["summary"].replace_html :partial => 'summary', :locals => {:order => @order} + page["summary"].visual_effect :highlight, :duration => 2 + end + end + + def new_group_order_article + group_order_article = 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 => group_order_article} + page["edit_box"].show + end + end + + # Creates a new GroupOrderArticle + # If the the chosen Ordergroup hasn't ordered yet, a GroupOrder will also be created + 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) + else + goa.group_order = group_order + end + + render :update do |page| + if goa.save + goa.group_order.update_price! # Updates the price attribute of new GroupOrder + page["edit_box"].hide + + 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["results"].replace_html :partial => "editNote" + 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! # Updates the price attribute of new GroupOrder + + page["edit_box"].hide + 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 destroy_group_order_article + goa = GroupOrderArticle.find(params[:id]) + goa.destroy + goa.group_order.update_price! # Updates the price attribute of new GroupOrder + + render :update do |page| + page["edit_box"].hide + page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles', + :locals => {:order_article => goa.order_article} + page["group_order_article_#{goa.id}"].visual_effect :highlight, :duration => 2 + page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order} + page["order_profit"].visual_effect :highlight, :duration => 2 + end + end + # before the order will booked, a view lists all Ordergroups and its order_prices def confirm @order = Order.find(params[:id]) @@ -232,13 +209,11 @@ class Finance::BalancingController < ApplicationController end end - # Set all GroupOrders that belong to this finished order to status 'booked'. - def setAllBooked + # Close the order directly, without automaticly updating ordergroups account balances + def close_direct @order = Order.find(params[:id]) - if (@order.finished?) - @order.booked = true - @order.updated_by = @current_user - @order.save! + 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 diff --git a/app/controllers/finance/invoices_controller.rb b/app/controllers/finance/invoices_controller.rb index 0af37494..d4f4a145 100644 --- a/app/controllers/finance/invoices_controller.rb +++ b/app/controllers/finance/invoices_controller.rb @@ -19,7 +19,8 @@ class Finance::InvoicesController < ApplicationController end def new - @invoice = Invoice.new(:supplier_id => params[:supplier_id], :delivery_id => params[:delivery_id]) + @invoice = Invoice.new :supplier_id => params[:supplier_id], + :delivery_id => params[:delivery_id], :order_id => params[:order_id] respond_to do |format| format.html # new.html.erb @@ -36,15 +37,16 @@ class Finance::InvoicesController < ApplicationController def create @invoice = Invoice.new(params[:invoice]) - respond_to do |format| - if @invoice.save - flash[:notice] = 'Invoice was successfully created.' - format.html { redirect_to([:finance, @invoice]) } - format.xml { render :xml => @invoice, :status => :created, :location => @invoice } + if @invoice.save + flash[:notice] = "Rechnung wurde erstellt." + if @invoice.order + # Redirect to balancing page + redirect_to :controller => 'balancing', :action => 'new', :id => @invoice.order else - format.html { render :action => "new" } - format.xml { render :xml => @invoice.errors, :status => :unprocessable_entity } + redirect_to [:finance, @invoice] end + else + render :action => "new" end end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 240ad081..3b502527 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -44,8 +44,8 @@ class OrdersController < ApplicationController if params[:view] # Articles-list will be replaced partial = case params[:view] when 'normal' then "articles" - when 'groups'then 'articles_by_groups' - when 'articles'then 'articles_by_articles' + when 'groups'then 'shared/articles_by_groups' + when 'articles'then 'shared/articles_by_articles' end render :partial => partial, :locals => {:order => @order} if partial end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index eb458cbc..665c6a5c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -111,4 +111,10 @@ module ApplicationHelper image_tag icons[name][:file], options end + + # Remote links with default 'loader'.gif during request + def remote_link_to(text, options={}) + remote_options = {:before => "Element.show('loader')", :success => "Element.hide('loader')"} + link_to_remote(text, remote_options.merge(options)) + end end diff --git a/app/models/group.rb b/app/models/group.rb index 5b889851..86089228 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 20090102171850 +# Schema version: 20090120184410 # # Table name: groups # @@ -21,6 +21,7 @@ # task_name :string(255) # task_description :string(255) # task_required_users :integer(4) default(1) +# deleted_at :datetime # # Groups organize the User. diff --git a/app/models/group_order.rb b/app/models/group_order.rb index f9da1f11..e730cac1 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 20090114101610 +# Schema version: 20090120184410 # # Table name: group_orders # @@ -9,7 +9,7 @@ # price :decimal(8, 2) default(0.0), not null # lock_version :integer(4) default(0), not null # updated_on :datetime not null -# updated_by_user_id :integer(4) default(0), not null +# updated_by_user_id :integer(4) # # A GroupOrder represents an Order placed by an Ordergroup. @@ -23,7 +23,6 @@ class GroupOrder < ActiveRecord::Base validates_presence_of :order_id validates_presence_of :ordergroup_id - validates_presence_of :updated_by validates_numericality_of :price validates_uniqueness_of :ordergroup_id, :scope => :order_id # order groups can only order once per order diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 9d61b796..215bab9c 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -20,12 +20,13 @@ class GroupOrderArticle < ActiveRecord::Base belongs_to :order_article has_many :group_order_article_quantities, :dependent => :destroy - validates_presence_of :group_order_id - validates_presence_of :order_article_id + validates_presence_of :group_order_id, :order_article_id validates_inclusion_of :quantity, :in => 0..99 validates_inclusion_of :tolerance, :in => 0..99 validates_uniqueness_of :order_article_id, :scope => :group_order_id # just once an article per group order + attr_accessor :ordergroup_id # To create an new GroupOrder if neccessary + # Updates the quantity/tolerance for this GroupOrderArticle by updating both GroupOrderArticle properties # and the associated GroupOrderArticleQuantities chronologically. # diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 5ce8f5d1..e18f18c1 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -43,4 +43,9 @@ class Invoice < ActiveRecord::Base def deposit_credit=(deposit) self[:deposit_credit] = String.delocalized_decimal(deposit) end + + # Amount without deposit + def net_amount + amount - deposit + deposit_credit + end end diff --git a/app/models/order.rb b/app/models/order.rb index 92a43cf6..fa93039d 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -82,9 +82,13 @@ class Order < ActiveRecord::Base memoize :get_articles # Returns the defecit/benefit for the foodcoop - def profit(with_markup = true) - groups_sum = with_markup ? sum(:groups) : sum(:groups_without_markup) - groups_sum - invoice_amount + deposit - deposit_credit + # Requires a valid invoice, belonging to this order + def profit(options = {}) + markup = options[:with_markup] || true + if invoice + groups_sum = markup ? sum(:groups) : sum(:groups_without_markup) + groups_sum - invoice.net_amount + end end # Returns the all round price of a finished order diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 9c4a40af..86576dd5 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -24,19 +24,39 @@ class OrderArticle < ActiveRecord::Base validates_presence_of :order_id validates_presence_of :article_id validates_uniqueness_of :article_id, :scope => :order_id # an article can only have one record per order + validate :article_and_price_exist named_scope :ordered, :conditions => "units_to_order >= 1" + # TODO: How to create/update articles/article_prices during balancing +# # Accessors for easy create of new order_articles in balancing process +# attr_accessor :name, :order_number, :units_to_order, :unit_quantity, :unit, :net_price, :tax, :deposit +# +# before_validation_on_create :create_new_article + # This method returns either the Article or the ArticlePrice # The latter will be set, when the the order is finished def price article_price || article end + # Count quantities of belonging group_orders. + # In balancing this can differ from ordered (by supplier) quantity for this article. + def group_orders_sum + quantity = group_order_articles.collect(&:quantity).sum + {:quantity => quantity, :price => quantity * price.fc_price} + end + private - def validate - errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil? - end - + def article_and_price_exist + errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil? + end + +# def create_new_article +# old_article = order.articles.find_by_name(name) # Check if there is already an Article with this name +# unless old_article +# self.article.build +# end +# end end diff --git a/app/models/ordergroup.rb b/app/models/ordergroup.rb index 8600550d..85930711 100644 --- a/app/models/ordergroup.rb +++ b/app/models/ordergroup.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 20090102171850 +# Schema version: 20090120184410 # # Table name: groups # @@ -21,6 +21,7 @@ # task_name :string(255) # task_description :string(255) # task_required_users :integer(4) default(1) +# deleted_at :datetime # # Ordergroups can order, they are "children" of the class Group diff --git a/app/models/user.rb b/app/models/user.rb index 588f3cd0..ea2a4c51 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -151,7 +151,12 @@ class User < ActiveRecord::Base def find_ordergroup ordergroups.first end - + + def ordergroup_name + ordergroup = find_ordergroup + ordergroup ? ordergroup.name : "keine Bestellgruppe" + end + # Find all tasks, for which the current user should be responsible # but which aren't accepted yet def unaccepted_tasks diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index d0c1e779..53c06dc5 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 20090113111624 +# Schema version: 20090120184410 # # Table name: groups # @@ -21,6 +21,7 @@ # task_name :string(255) # task_description :string(255) # task_required_users :integer(4) default(1) +# deleted_at :datetime # class Workgroup < Group diff --git a/app/views/finance/balancing/_articleResult.haml b/app/views/finance/balancing/_articleResult.haml deleted file mode 100644 index 9f88467f..00000000 --- a/app/views/finance/balancing/_articleResult.haml +++ /dev/null @@ -1,21 +0,0 @@ -%td= @article.name -%td= link_to_function image_tag("arrow_down_red.png", :size => "16x16", :border => 0), "Element.toggle('group_order_article_results_#{@article.id}')" -%td= @article.order_number -%td= @article.units_to_order -%td= @article.unit_quantity.to_s + ' * ' + @article.unit.to_s -%td= number_to_currency(@article.price) -%td= number_to_currency(@article.fc_price) -%td= @article.tax -%td= @article.deposit -%td - = link_to_remote image_tag('b_edit.png', :size => "16x16", :border => 0, :alt => 'Artikel ändern'), | - :url => {:action => 'editArticleResult', :id => @article}, | - :before => "Element.show('loader')", | - :success => "Element.hide('loader')" | -%td - = link_to_remote image_tag('b_drop.png', :size => "16x16", :border => 0, :alt => 'Artikel löschen'), | - :url => {:action => 'destroyArticleResult', :id => @article}, | - :confirm => 'Bist du sicher?', | - :method => 'post', | - :before => "Element.show('loader')", | - :success => "Element.hide('loader')" | diff --git a/app/views/finance/balancing/_articleResultForm.haml b/app/views/finance/balancing/_articleResultForm.haml deleted file mode 100644 index 39b88077..00000000 --- a/app/views/finance/balancing/_articleResultForm.haml +++ /dev/null @@ -1,29 +0,0 @@ -= error_messages_for 'article' -%p - %b Notiz: - = @form.text_field 'note', :size => 30 -%table - %tr - %th Name - %th Nr. - %th - %abbr{:title=>"Anzahl gelieferter Gebinde"} Menge - %th GebGr - %th Einheit - %th netto - %th MwSt. - %th Pfand - %tr - %td= @form.text_field 'name', :size => 20 - %td= @form.text_field 'order_number', :size => 3 - %td= @form.text_field 'units_to_order', :size => 5 - %td= @form.text_field 'unit_quantity', :size => 3 - %td= @form.text_field 'unit', :size => 5 - %td= @form.text_field 'price', :size => 3 - %td= @form.text_field 'tax', :size => 3 - %td= @form.text_field 'deposit', :size => 3 -= @form.hidden_field "order_id" -%br/ -= submit_tag "Speichern" -| -= link_to_function 'Abbrechen', "Element.hide('edit_box')" \ No newline at end of file diff --git a/app/views/finance/balancing/_articleResults.haml b/app/views/finance/balancing/_articleResults.haml deleted file mode 100644 index ac4edfad..00000000 --- a/app/views/finance/balancing/_articleResults.haml +++ /dev/null @@ -1,5 +0,0 @@ -%tr{:class => cycle('even', 'odd', :name => 'articles')}[@article] - = render :partial => 'articleResult' - -%tr{:id => "group_order_article_results_#{@article.id}", :class => "results", :style => "display:none"} - = render :partial => 'groupOrderArticleResults' \ No newline at end of file diff --git a/app/views/finance/balancing/_articlesOverview.haml b/app/views/finance/balancing/_articlesOverview.haml deleted file mode 100644 index 12d33173..00000000 --- a/app/views/finance/balancing/_articlesOverview.haml +++ /dev/null @@ -1,17 +0,0 @@ -%p - %b - Gelieferte Artikel: - = @order.order_article_results.size -- for article in @order.order_article_results - %table{:style=> "margin-bottom:1em; width:40em;"}[article] - %thead - %tr - %th{:colspan => "3"}= article.name + " (" + article.unit + " | " + article.unit_quantity.to_s + " | " + article.fc_price.to_s + ")" - %tbody - - for result in article.group_order_article_results - %tr{ :class => cycle('even', 'odd', :name => 'group')} - %td{:style=>"width:70%"}= result.group_order_result.group_name - %td= result.quantity - %td= article.fc_price * result.quantity - - reset_cycle("group") - \ No newline at end of file diff --git a/app/views/finance/balancing/_editGroupResult.haml b/app/views/finance/balancing/_editGroupResult.haml deleted file mode 100644 index d53ae022..00000000 --- a/app/views/finance/balancing/_editGroupResult.haml +++ /dev/null @@ -1,20 +0,0 @@ -%h2 Mengenänderung -%p - = @result.group_order_result.group_name - hat von - = @result.order_article_result.name - bekommen: - -- remote_form_for 'group_order_article_result', @result, :url => {:action => 'updateGroupResult', :id => @result }, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| | - - = error_messages_for 'group_order_article_result' - %p - %b Menge: - (Einheit: - = @result.order_article_result.unit - ) - = form.text_field "quantity", :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/_editNote.haml b/app/views/finance/balancing/_editNote.haml deleted file mode 100644 index dbba65c3..00000000 --- a/app/views/finance/balancing/_editNote.haml +++ /dev/null @@ -1,10 +0,0 @@ -%h2 Notiz bearbeiten -- remote_form_for 'order', @order, :url => {:action => 'updateOrderNote', :id => @order}, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| | - - %br/ - = form.text_area "note", :size => "60x20" - %p - = submit_tag "Speichern" - | - = link_to_remote 'Abbrechen', :update => 'results', :url => { :action => 'edit', :id => @order, :view => 'groupsOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" \ No newline at end of file diff --git a/app/views/finance/balancing/_editSummary.haml b/app/views/finance/balancing/_editSummary.haml deleted file mode 100644 index 822b8969..00000000 --- a/app/views/finance/balancing/_editSummary.haml +++ /dev/null @@ -1,27 +0,0 @@ -%h2 Bestelldaten ändern -- remote_form_for 'order', @order, :url => {:action => 'updateOrderSummary', :id => @order}, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| | - - = error_messages_for 'order' - %table{:style => "width:10em"} - %tr - %td Rechnungsnummer: - %td= form.text_field "invoice_number", :size => 10 - %tr - %td Rechnungsdatum: - %td= form.text_field "invoice_date", :size => 10 - %tr - %td - %abbr{:title => "(incl. Pfand/Gutschriften)"} Rechnungsbeitrag - %td= form.text_field 'invoice_amount', :size => 10 - %tr - %td - %abbr{:title => "z.B Kistepfand"} extra Pfand - %td= form.text_field 'deposit', :size => 10 - %tr - %td Pfandgutschrift - %td= form.text_field 'deposit_credit', :size => 10 - %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/_edit_group_order_article.html.haml b/app/views/finance/balancing/_edit_group_order_article.html.haml new file mode 100644 index 00000000..b67526ae --- /dev/null +++ b/app/views/finance/balancing/_edit_group_order_article.html.haml @@ -0,0 +1,21 @@ +%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 :quantity, :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_note.html.haml b/app/views/finance/balancing/_edit_note.html.haml new file mode 100644 index 00000000..2344603a --- /dev/null +++ b/app/views/finance/balancing/_edit_note.html.haml @@ -0,0 +1,9 @@ +%h2 Notiz bearbeiten +- remote_form_for 'order', @order, :url => {:action => 'update_note', :id => @order}, | + :before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| | + = form.error_messages + = form.text_area "note", :size => "60x20" + %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/_editResults.haml b/app/views/finance/balancing/_edit_results_by_articles.html.haml similarity index 50% rename from app/views/finance/balancing/_editResults.haml rename to app/views/finance/balancing/_edit_results_by_articles.html.haml index 8c6b94c9..578f8999 100644 --- a/app/views/finance/balancing/_editResults.haml +++ b/app/views/finance/balancing/_edit_results_by_articles.html.haml @@ -1,12 +1,12 @@ %p{:style => "float:left"} %b Lieferung bearbeiten %p{:style => "float:right"} - = link_to_remote "Artikel hinzufügen", :url => {:action => "newArticleResult", :id => @order} + //= remote_link_to "Artikel hinzufügen", :url => {:action => "newArticleResult", :id => @order} %table{:class => "ordered_articles", :style => "clear:both"} %thead %tr - %th{:colspan => "2"} Artikel + %th{:colspan => "1"} Artikel %th Nr. %th Menge %th GebGr * Einheit @@ -16,5 +16,5 @@ %th Pfand %th{:colspan => "2"} %tbody#result_table - - for @article in @order.order_article_results - = render :partial => "articleResults" \ No newline at end of file + - for order_article in @order.order_articles.all(:include => [:article, :article_price]) + = render :partial => "order_article_result", :locals => {:order_article => order_article} diff --git a/app/views/finance/balancing/_groupOrderArticleResults.haml b/app/views/finance/balancing/_groupOrderArticleResults.haml deleted file mode 100644 index 1947b371..00000000 --- a/app/views/finance/balancing/_groupOrderArticleResults.haml +++ /dev/null @@ -1,25 +0,0 @@ -%td{:colspan => "7"} - %p - Notiz: - = @article.note - %table - %thead - %tr - %td - %td{:style => "width:8em"} Gruppe - %td Einheiten - %td Gesamtpreis - %td{:colspan => "3",:style => "width:14em"} - = link_to_remote '[Gruppe hinzufügen]', :url => {:action => "newGroupResult", :id => @article}, :before => "Element.show('loader')", :success => "Element.hide('loader')" - %tbody{:id => "groups_results_#{@article.id}"} - - for @result in @article.group_order_article_results - = render :partial => "groupResults" - %tfoot - %tr{:class => cycle('even', 'odd', :name => 'results'), :id => "sum_of_article_#{@article.id}"} - %td - %td{:style => "width:8em"} Summe - %td{:id => "totalArticleQuantity_#{@article.id}"}= @article.total[:quantity] - %td{:id => "totalArticlePrice_#{@article.id}", :class => "currency"} - = number_to_currency(@article.total[:price]) - %td{:colspan => "3"} - - reset_cycle('results') \ No newline at end of file diff --git a/app/views/finance/balancing/_groupResult.haml b/app/views/finance/balancing/_groupResult.haml deleted file mode 100644 index bbfe1ab5..00000000 --- a/app/views/finance/balancing/_groupResult.haml +++ /dev/null @@ -1,17 +0,0 @@ -%td -%td{:style=>"width:50%"}= @result.group_order_result.group_name -%td{:id => "group_order_article_result_#{@result.id}_quantity"}= @result.quantity -%td{:class => "currency"}= number_to_currency(@result.order_article_result.fc_price * @result.quantity) -%td{:style=>"width:1em", :class => "actions"} - = link_to_remote image_tag('b_edit.png', :size => "16x16", :border => 0, :alt => 'Menge ändern'), | - :url => {:action => 'updateGroupResult', :id => @result}, | - :before => "Element.show('loader')", | - :success => "Element.hide('loader')" | -%td{:style=>"width:1em", :class => "actions"} - = link_to_remote image_tag('b_drop.png', :size => "16x16", :border => 0, :alt => 'Gruppenergebnis löschen'), | - :url => {:action => 'destroyGroupResult', :id => @result}, | - :confirm => 'Bist du sicher?', | - :method => 'post', | - :before => "Element.show('loader')", | - :success => "Element.hide('loader')" | -%td \ No newline at end of file diff --git a/app/views/finance/balancing/_groupResults.haml b/app/views/finance/balancing/_groupResults.haml deleted file mode 100644 index 59d1ec67..00000000 --- a/app/views/finance/balancing/_groupResults.haml +++ /dev/null @@ -1,2 +0,0 @@ -%tr{:class => cycle('even', 'odd', :name => 'results')}[@result] - = render :partial => "groupResult" \ 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 new file mode 100644 index 00000000..aa82f6e6 --- /dev/null +++ b/app/views/finance/balancing/_group_order_articles.html.haml @@ -0,0 +1,39 @@ +%td{:colspan => "7"} + %table + %thead + %tr + %td + %td{:style => "width:8em"} Gruppe + %td Einheiten + %td Gesamtpreis + %td{:colspan => "3",:style => "width:14em"} + = remote_link_to '[Gruppe hinzufügen]', :url => {:action => "new_group_order_article", :id => order_article} + %tbody + - for group_order_article in order_article.group_order_articles.all(:include => [:group_order]) + %tr{:class => cycle('even', 'odd', :name => 'results')}[group_order_article] + %td + %td{:style=>"width:50%"} + = group_order_article.group_order.ordergroup.name + %td{:id => "group_order_article_#{group_order_article.id}_quantity"} + = group_order_article.quantity + %td.currency + = number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.quantity, :unit => "") + %td.actions{:style=>"width:1em"} + = remote_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')" | + %td.actions{:style=>"width:1em"} + = remote_link_to icon(:delete), | + :url => {:action => 'destroy_group_order_article', :id => group_order_article}, | + :confirm => 'Bist du sicher?', :method => 'post' | + %td + %tfoot + %tr{:class => cycle('even', 'odd', :name => 'results')} + %td + %td{:style => "width:8em"} Summe + %td{:id => "group_orders_sum_quantity_#{order_article.id}"} + = order_article.group_orders_sum[:quantity] + %td{:id => "group_orders_sum_price_#{order_article.id}", :class => "currency"} + = number_to_currency(order_article.group_orders_sum[:price], :unit => "") + %td{:colspan => "3"} + - reset_cycle('results') \ No newline at end of file diff --git a/app/views/finance/balancing/_groupsOverview.haml b/app/views/finance/balancing/_groupsOverview.haml deleted file mode 100644 index 5368b697..00000000 --- a/app/views/finance/balancing/_groupsOverview.haml +++ /dev/null @@ -1,30 +0,0 @@ -%p - %b - Gruppenbestellungen: - = @order.group_order_results.size -- for groupOrderResult in @order.group_order_results - %p - %table{:style => "width:40em"}[groupOrderResult] - %thead - %tr - %th{:colspan => "6"}= groupOrderResult.group_name - %tbody - - total = 0 - - for result in groupOrderResult.group_order_article_results - - price = result.order_article_result.fc_price - - quantity = result.quantity - - subTotal = price * quantity - - total += subTotal - %tr{:class => cycle('even', 'odd', :name => 'article')} - %td= result.order_article_result.name - %td= quantity - %td{:class => "currency"}= number_to_currency(price) - %td= result.order_article_result.unit_quantity - %td= result.order_article_result.unit - %td= number_to_currency(subTotal) - %tfoot - %tr{:class => cycle('even', 'odd', :name => 'article')} - %td{:colspan => "5"} Summe - %td - %b= number_to_currency(total) - - reset_cycle("article") \ No newline at end of file diff --git a/app/views/finance/balancing/_invoice.html.haml b/app/views/finance/balancing/_invoice.html.haml new file mode 100644 index 00000000..d9be96e1 --- /dev/null +++ b/app/views/finance/balancing/_invoice.html.haml @@ -0,0 +1,24 @@ +- if invoice + %table + %tr + %td Rechnungsnummer: + %td= invoice.number + %tr + %td Rechnungsdatum: + %td= invoice.date + %tr + %td Rechnungsbetrag: + %td.curreny= number_to_currency invoice.amount + %tr + %td - Pfand berechnet: + %td.curreny= number_to_currency invoice.deposit + %tr + %td + Pfand gutgeschrieben: + %td.curreny= number_to_currency invoice.deposit_credit + %tr + %td pfandbereinigter Betrag: + %td.curreny= number_to_currency invoice.net_amount + +- else + Eine Rechnung für diese Bestellung anlegen: + = link_to "Neue Rechnung erstellen", new_finance_invoice_path(:order_id => @order, :supplier_id => @order.supplier) diff --git a/app/views/finance/balancing/_newArticleResult.haml b/app/views/finance/balancing/_newArticleResult.haml deleted file mode 100644 index eae43980..00000000 --- a/app/views/finance/balancing/_newArticleResult.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h2 - Neuer gelieferter Artikel die Bestellung - -- remote_form_for 'order_article_result', @article, :url => {:action => 'createArticleResult' }, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do |@form| | - - = render :partial => "articleResultForm" \ No newline at end of file diff --git a/app/views/finance/balancing/_newGroupResult.haml b/app/views/finance/balancing/_newGroupResult.haml deleted file mode 100644 index 88512b0c..00000000 --- a/app/views/finance/balancing/_newGroupResult.haml +++ /dev/null @@ -1,17 +0,0 @@ -%h2 - Neue Gruppenmenge für - = @result.order_article_result.name -- remote_form_for 'group_order_article_result', @result, :url => {:action => 'createGroupResult'}, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do |@form| | - = error_messages_for 'result' - %p - Gruppe: - = @form.select "group_order_result_id", Ordergroup.find(:all, :order => "name").collect {|og| [og.name, og.id] } - %p - Menge: - = @form.text_field "quantity", :size => 5 - = @form.hidden_field "order_article_result_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/_new_group_order_article.html.haml b/app/views/finance/balancing/_new_group_order_article.html.haml new file mode 100644 index 00000000..58e3eaf0 --- /dev/null +++ b/app/views/finance/balancing/_new_group_order_article.html.haml @@ -0,0 +1,17 @@ +%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 "quantity", :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/_new_order_article.html.haml b/app/views/finance/balancing/_new_order_article.html.haml new file mode 100644 index 00000000..0d46c1ea --- /dev/null +++ b/app/views/finance/balancing/_new_order_article.html.haml @@ -0,0 +1,7 @@ +%h2 + Neuer gelieferter Artikel die Bestellung + +- remote_form_for order_article, :url => {:action => 'create_order_article' }, | + :before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| | + + = render :partial => 'order_article_form', :locals => {:form => form} \ 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 new file mode 100644 index 00000000..97e840cb --- /dev/null +++ b/app/views/finance/balancing/_order_article.html.haml @@ -0,0 +1,18 @@ +%td.closed + = link_to_function order_article.article.name, | + "Element.toggle('group_order_articles_#{order_article.id}'); | + Element.toggleClassName(this.up('td'), 'open')" | +%td= order_article.article.order_number +%td= order_article.units_to_order +%td= order_article.price.unit_quantity.to_s + ' * ' + order_article.article.unit.to_s +%td= number_to_currency(order_article.price.price, :unit => "") +%td= number_to_currency(order_article.price.fc_price, :unit => "") +%td= order_article.price.tax +%td= order_article.price.deposit +%td + //= remote_link_to icon(:edit), | + //:url => {:action => 'edit_order_article', :id => order_article} | +%td + = remote_link_to icon(:delete), :confirm => 'Bist du sicher?', | + :url => {:action => 'destroy_order_article', :id => order_article}, | + :method => :post | diff --git a/app/views/finance/balancing/_order_article_form.html.haml b/app/views/finance/balancing/_order_article_form.html.haml new file mode 100644 index 00000000..4e73cf3a --- /dev/null +++ b/app/views/finance/balancing/_order_article_form.html.haml @@ -0,0 +1,26 @@ += form.error_messages +%table + %tr + %th Name + %th Nr. + %th + %abbr{:title=>"Anzahl gelieferter Gebinde"} Menge + %th GebGr + %th Einheit + %th netto + %th MwSt. + %th Pfand + %tr + %td= form.text_field 'name', :size => 20 + %td= form.text_field 'order_number', :size => 3 + %td= form.text_field 'units_to_order', :size => 5 + %td= form.text_field 'unit_quantity', :size => 3 + %td= form.text_field 'unit', :size => 5 + %td= form.text_field 'net_price', :size => 3 + %td= form.text_field 'tax', :size => 3 + %td= form.text_field 'deposit', :size => 3 += form.hidden_field "order_id" +%br/ += 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_result.html.haml b/app/views/finance/balancing/_order_article_result.html.haml new file mode 100644 index 00000000..16899a23 --- /dev/null +++ b/app/views/finance/balancing/_order_article_result.html.haml @@ -0,0 +1,5 @@ +%tr{:class => cycle('even', 'odd', :name => 'articles')}[order_article] + = render :partial => 'order_article', :locals => {:order_article => order_article} + +%tr{:id => "group_order_articles_#{order_article.id}", :class => "results", :style => "display:none"} + = render :partial => 'group_order_articles', :locals => {:order_article => order_article} \ No newline at end of file diff --git a/app/views/finance/balancing/_summary.haml b/app/views/finance/balancing/_summary.haml index f7abaa8a..eff935ef 100644 --- a/app/views/finance/balancing/_summary.haml +++ b/app/views/finance/balancing/_summary.haml @@ -1,60 +1,23 @@ +%b=h order.supplier.name +%br/ += "von #{format_date(order.starts)} bis #{format_date(order.ends)}" %p - %b=h @order.supplier ? @order.supplier.name : _('nonexistent') - | Rechnungsnummer: - = @order.invoice_number - | Rechnungsdatum: - = @order.invoice_date - | - = link_to_remote image_tag('b_edit.png', :size => "16x16", :border => 0, :alt => 'Rechnungsbetrag ändern'), | - :url => {:action => "editOrderSummary", :id => @order}, | - :before => "Element.show('loader')", | - :success => "Element.hide('loader')" | -%table - %tr - %td{:colspan => "2"} - %b Foodcoop - %td{:colspan => "2"} - %b Lieferant - %tr - %td - %abbr{:title => "gelieferten Artikel x Nettopreis"} Nettobetrag: - %td= number_to_currency(@order.sum(:clear)) - %td - Rechnungsbetrag - %small (incl. Pfand/Gutschriften) - %td#invoice_amount= number_to_currency(@order.invoice_amount) - %tr - %td - %abbr{:title => "Nettobetrag mit Pfand und MwSt."} Bruttobetrag: - %td= number_to_currency(@order.sum(:gross)) - %td - %span - extra Pfand - %small (Kistenpfand etc.) - %td#deposit= number_to_currency(@order.deposit) - %tr - %td - %abbr{:title => "Bruttobetrag mit Foodcoop Aufschlag"} FC Summe: - %td= number_to_currency(@order.sum(:fc)) - %td{:style => "border-bottom: 1px solid grey"} - + Pfandgutschriften - %td{:style => "border-bottom: 1px solid grey"} - #deposit_credit= number_to_currency(@order.deposit_credit) - %tr - %td - %abbr{:title => "Zugeteilte Mengen x Bruttopreise (inkl. Aufschlag)"} Gruppenbeträge: - %td#groups_amount= number_to_currency(@order.sum(:groups)) - %td - Summe - %small (Rechungsbetrag ohne Pfand) - %td#clear_invoice= number_to_currency(@order.invoice_amount - @order.deposit + @order.deposit_credit) - %tr - %td{:colspan => "4"} - %abbr{:title => "Gruppenbeträge ohne Aufschlag minus Rechnung ohne Pfand. | - Im Idealfall sollte hier 0.00 stehen."} Differenz ohne Aufschlag: | - %span#profit= number_to_currency(@order.profit(false)) - %tr - %td{:colspan => "4"} - %b - %abbr{:title => "= Gruppenbeträge - Rechnung ohne Pfand"} Differenz mit Aufschlag - = "(#{number_to_percentage(APP_CONFIG[:price_markup])}):" - %span#profit= number_to_currency(@order.profit) + %table + %tr + %td Nettobetrag: + %td= number_to_currency(order.sum(:clear)) + %tr + %td Bruttobetrag: + %td= number_to_currency(order.sum(:gross)) + %tr + %td FC-Betrag: + %td= number_to_currency(order.sum(:fc)) + %tr + %td Summe der Gruppenbeträge: + %td= number_to_currency(order.sum(:groups)) + %tr + %td FC Gewinn ohne Aufschlag: + %td= number_to_currency(order.profit(:with_markup => false)) + %tr + %td FC Gewinn mit Aufschlag: + %td#order_profit= number_to_currency(order.profit) \ 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 40712c12..1a6bdff5 100644 --- a/app/views/finance/balancing/confirm.html.haml +++ b/app/views/finance/balancing/confirm.html.haml @@ -1,16 +1,16 @@ -%h1 Bestellung abschließen -.single_column#confirm{:style => "width:35em"} +-title "Bestellung abschließen" +%div{:style => "width: 40em"} %p Wenn die Bestellung abgeschlossen wird, werden ebenfalls alle Gruppenkonten aktualisiert. %br/ Die Konten werden wie folgt belastet: %table.list{:style => "width:35em"} - - for groupResult in @order.group_order_results + - for group_order in @order.group_orders %tr{:class => cycle('even', 'odd')} - %td= groupResult.group_name - %td= number_to_currency(groupResult.price) + %td= group_order.ordergroup.name + %td= number_to_currency(group_order.price) %p %div{:style => "float:left"} = button_to "Abschließen", :action => "close", :id => @order %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', :action => 'new', :id => @order \ No newline at end of file diff --git a/app/views/finance/balancing/index.haml b/app/views/finance/balancing/index.haml index ffbaf9da..220092c8 100644 --- a/app/views/finance/balancing/index.haml +++ b/app/views/finance/balancing/index.haml @@ -48,7 +48,7 @@ %table.list %thead %tr - %th Name + %th Lieferant %th Ende %th Betrag(FC) %th @@ -58,6 +58,6 @@ %td= order.supplier.name %td= format_date(order.ends) %td{:class => "currency"}= number_to_currency(order.sum(:fc)) - %td= link_to "abrechnen", :action => "editOrder", :id => order + %td= link_to "abrechnen", :action => "new", :id => order - 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 687a0170..74906e72 100644 --- a/app/views/finance/balancing/list.html.haml +++ b/app/views/finance/balancing/list.html.haml @@ -1,11 +1,7 @@ -%h1 beendete Bestellungen -%p +- title "beendete Bestellungen" +%p{:style => "width:30em"} %i - Aktuell gibt es die Möglichkeit eine Bestellung mittels dem "abrechnen"-link zu verbuchen, d.h. - nach Bearbeitung der Liefermengen die Gruppenbeträge automatisiert zu verbuchen, - %br/ - oder die Bestellung manuell abzurechnen (Kontostände selbst zu aktualisieren) und mittels "auf gebucht setzen" - die Bestellung als abgeschlossen zu deklarieren. + Beschreibungstext für die Abrechnunsmodi .... .left_column{:style => "width:70em"} .box_title .column_content @@ -32,6 +28,7 @@ - unless order.closed? = link_to "abrechnen", :action => "new", :id => order | - = link_to 'auf "gebucht" setzen', {:action => 'setAllBooked', :id => order}, :confirm => 'Wirklich alle Gruppenbestellungen für diese Bestellung auf "gebucht" setzen?', :method => "post" + = link_to 'direkt schließen', {:action => 'close_direct', :id => order}, | + :confirm => 'Wirklich die Bestellung schließen setzen?', :method => "post" | - 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 04a69b6c..44ea93b0 100644 --- a/app/views/finance/balancing/new.html.haml +++ b/app/views/finance/balancing/new.html.haml @@ -1,37 +1,44 @@ -%h1 Bestellung abrechnen +- title "#{@order.supplier.name} abrechnen" - if @order.closed? %p %b Achtung, Bestellung wurde schon abgerechnet! -.left_column{:style => 'width: 50em'} +.left_column{:style => 'width: 24em'} .box_title - %h2 - = @order.supplier.name + " | " + format_date(@order.starts) + ' --> ' + format_date(@order.ends) + %h2 Zusammenfassung .column_content#summary - #order_summary - = render :partial => "summary" + = render :partial => "summary", :locals => {:order => @order} +.left_column{:style => 'width: 24em'} + .box_title + %h2 Rechnung + .column_content#invoice + = render :partial => "invoice", :locals => {:invoice => @order.invoice} + .right_column{:style => 'width: 20em'} .box_title %h2 Aktionen .column_content %ul + - unless @order.invoice + %li= link_to "Rechnung anlegen", new_finance_invoice_path(:order_id => @order) - unless @order.closed? %li= link_to "Bestellung abschließen", :action => "confirm", :id => @order .right_column{:style => 'clear:both;width: 28%'} .box_title - %h2 Protokoll + %h2 Notizen/Protokoll .column_content #note - unless @order.note.empty? = simple_format @order.note - else %p Hier kannst Du deine Abrechnung kommentieren - %small Protokoll bearbeiten: - = link_to_remote image_tag("b_edit.png", :size => "16x16", :border => "0"), | - :update => 'results', :url => { :action => 'new', :id => @order, :view => 'editNote' }, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" | - %hr/ + = remote_link_to "Notiz bearbeiten", | + :update => 'edit_box', :url => {:action => 'edit_note', :id => @order}, | + :success => "Element.hide('loader'); Element.show('edit_box')" | + .box_title + %h2 Kommentare + .column_content #comments = render :partial => 'shared/comments' @@ -39,11 +46,11 @@ .box_title #editOrderNav %ul - %li= link_to_remote 'Gruppenübersicht', :update => 'results', :url => { :action => 'new', :id => @order, :view => 'groupsOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" - %li= link_to_remote 'Artikelübersicht', :update => 'results', :url => { :action => 'new', :id => @order, :view => 'articlesOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" - %li= link_to_remote 'Bestellung bearbeiten', :update => 'results', :url => { :action => 'new', :id => @order, :view => 'editResults' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" + %li= remote_link_to 'Gruppenübersicht', :update => 'results', :url => {:action => 'new', :id => @order, :view => 'groupsOverview'} + %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'} .column_content #results - = render :partial => 'groupsOverview' + = 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/invoices/_form.html.haml b/app/views/finance/invoices/_form.html.haml index 9f10e3d0..79957d34 100644 --- a/app/views/finance/invoices/_form.html.haml +++ b/app/views/finance/invoices/_form.html.haml @@ -1,9 +1,12 @@ - form_for([:finance, @invoice]) do |f| = f.error_messages = f.hidden_field :delivery_id + = f.hidden_field :order_id - if @invoice.delivery %p= "Diese Rechnung ist mit einer #{link_to "Lieferung", [@invoice.supplier,@invoice.delivery]} verknüpft." + - if @invoice.order + %p= "Diese Rechnung ist mit einer #{link_to "Bestellung", @invoice.order} verknüpft." %p = f.label :supplier_id %br/ @@ -24,6 +27,14 @@ = f.label :amount %br/ = f.text_field :amount + %p + = f.label :deposit + %br/ + = f.text_field :deposit + %p + = f.label :deposit_credit + %br/ + = f.text_field :deposit_credit %p = f.label :note %br/ diff --git a/app/views/orders/_articles_by_articles.html.haml b/app/views/shared/_articles_by_articles.html.haml similarity index 100% rename from app/views/orders/_articles_by_articles.html.haml rename to app/views/shared/_articles_by_articles.html.haml diff --git a/app/views/orders/_articles_by_groups.html.haml b/app/views/shared/_articles_by_groups.html.haml similarity index 100% rename from app/views/orders/_articles_by_groups.html.haml rename to app/views/shared/_articles_by_groups.html.haml diff --git a/app/views/shared/_comments.haml b/app/views/shared/_comments.haml index 6ff2118c..661b119a 100644 --- a/app/views/shared/_comments.haml +++ b/app/views/shared/_comments.haml @@ -1,13 +1,9 @@ - unless comments.empty? - comments.each do |comment| .comment[comment] - %h3 - = "#{comment.user.find_ordergroup.name} :" if comment.user.find_ordergroup - = simple_format(comment.text) .timestamp - Erstellt am - = format_time(comment.created_at) - von - =h comment.user.nick + %b=h "#{comment.user.ordergroup_name}" + = "(#{comment.user.nick} am #{format_time(comment.created_at)}):" + = simple_format(comment.text) - else es gibt derzeit keine Kommentare. \ No newline at end of file diff --git a/db/migrate/20090119155930_acts_as_paranoid.rb b/db/migrate/20090119155930_acts_as_paranoid.rb index 8053f567..83239b27 100644 --- a/db/migrate/20090119155930_acts_as_paranoid.rb +++ b/db/migrate/20090119155930_acts_as_paranoid.rb @@ -5,7 +5,7 @@ class ActsAsParanoid < ActiveRecord::Migration end def self.down - remove_column :suppliers, :deleted_at, :datetime - remove_column :articles, :deleted_at, :datetime + remove_column :suppliers, :deleted_at + remove_column :articles, :deleted_at end end diff --git a/db/migrate/20090120184410_refactor_order_logic.rb b/db/migrate/20090120184410_refactor_order_logic.rb index 1747624e..2b3ac8c3 100644 --- a/db/migrate/20090120184410_refactor_order_logic.rb +++ b/db/migrate/20090120184410_refactor_order_logic.rb @@ -3,64 +3,67 @@ class RefactorOrderLogic < ActiveRecord::Migration # TODO: Combine migrations since foodsoft3-development into one file # and try to build a migration path from old data. - # articles - rename_column :articles, :net_price, :price - remove_column :articles, :gross_price +# # articles +# rename_column :articles, :net_price, :price +# remove_column :articles, :gross_price +# +# # orders +# drop_table :orders +# drop_table :group_order_results +# drop_table :order_article_results +# drop_table :group_order_article_results +# GroupOrder.delete_all; OrderArticle.delete_all; GroupOrderArticle.delete_all; GroupOrderArticleQuantity.delete_all +# +# create_table :orders do |t| +# t.references :supplier +# t.text :note +# t.datetime :starts +# t.datetime :ends +# t.string :state, :default => "open" # Statemachine ... open -> finished -> closed +# t.integer :lock_version, :default => 0, :null => false +# t.integer :updated_by_user_id +# end +# +# # invoices +# add_column :invoices, :order_id, :integer +# add_column :invoices, :deposit, :decimal, :precision => 8, :scale => 2, :default => 0.0, :null => false +# add_column :invoices, :deposit_credit, :decimal, :precision => 8, :scale => 2, :default => 0.0, :null => false +# +# # comments +# drop_table :comments +# create_table :order_comments do |t| +# t.references :order +# t.references :user +# t.text :text +# t.datetime :created_at +# end +# +# # article_prices +# create_table :article_prices do |t| +# t.references :article +# t.decimal :price, :precision => 8, :scale => 2, :default => 0.0, :null => false +# t.decimal :tax, :precision => 8, :scale => 2, :default => 0.0, :null => false +# t.decimal :deposit, :precision => 8, :scale => 2, :default => 0.0, :null => false +# t.integer :unit_quantity +# t.datetime :created_at +# end +# # Create price history for every Article +# Article.all.each do |a| +# a.article_prices.create :price => a.price, :tax => a.tax, +# :deposit => a.deposit, :unit_quantity => a.unit_quantity +# end +# # Every Article has now a Category. Fix it if neccessary. +# Article.all(:conditions => { :article_category_id => nil }).each do |article| +# article.update_attribute(:article_category, ArticleCategory.first) +# end +# # order-articles +# add_column :order_articles, :article_price_id, :integer +# +# # ordergroups +# add_column :groups, :deleted_at, :datetime - # orders - drop_table :orders - drop_table :group_order_results - drop_table :order_article_results - drop_table :group_order_article_results - GroupOrder.delete_all; OrderArticle.delete_all; GroupOrderArticle.delete_all; GroupOrderArticleQuantity.delete_all - - create_table :orders do |t| - t.references :supplier - t.text :note - t.datetime :starts - t.datetime :ends - t.string :state, :default => "open" # Statemachine ... open -> finished -> closed - t.integer :lock_version, :default => 0, :null => false - t.integer :updated_by_user_id - end - - # invoices - add_column :invoices, :order_id, :integer - add_column :invoices, :deposit, :decimal, :precision => 8, :scale => 2, :default => 0.0, :null => false - add_column :invoices, :deposit_credit, :decimal, :precision => 8, :scale => 2, :default => 0.0, :null => false - - # comments - drop_table :comments - create_table :order_comments do |t| - t.references :order - t.references :user - t.text :text - t.datetime :created_at - end - - # article_prices - create_table :article_prices do |t| - t.references :article - t.decimal :price, :precision => 8, :scale => 2, :default => 0.0, :null => false - t.decimal :tax, :precision => 8, :scale => 2, :default => 0.0, :null => false - t.decimal :deposit, :precision => 8, :scale => 2, :default => 0.0, :null => false - t.integer :unit_quantity - t.datetime :created_at - end - # Create price history for every Article - Article.all.each do |a| - a.article_prices.create :price => a.price, :tax => a.tax, - :deposit => a.deposit, :unit_quantity => a.unit_quantity - end - # Every Article has now a Category. Fix it if neccessary. - Article.all(:conditions => { :article_category_id => nil }).each do |article| - article.update_attribute(:article_category, ArticleCategory.first) - end - # order-articles - add_column :order_articles, :article_price_id, :integer - - # ordergroups - add_column :groups, :deleted_at, :datetime + # GroupOrders + change_column :group_orders, :updated_by_user_id, :integer, :default => nil, :null => true end def self.down diff --git a/db/schema.rb b/db/schema.rb index ca733844..2ffdd0f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20090120184410) do +ActiveRecord::Schema.define(:version => 20090119155930) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -107,7 +107,7 @@ ActiveRecord::Schema.define(:version => 20090120184410) do t.decimal "price", :precision => 8, :scale => 2, :default => 0.0, :null => false t.integer "lock_version", :default => 0, :null => false t.datetime "updated_on", :null => false - t.integer "updated_by_user_id", :default => 0, :null => false + t.integer "updated_by_user_id" end add_index "group_orders", ["ordergroup_id", "order_id"], :name => "index_group_orders_on_ordergroup_id_and_order_id", :unique => true diff --git a/public/images/arrow_right_red.png b/public/images/arrow_right_red.png new file mode 100644 index 0000000000000000000000000000000000000000..bf351f6d65592ad7160934a4cf46922748973320 GIT binary patch literal 356 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPggaMp*$S^AFLg9zY@464!_l=ltB< z)VvY~=c3falGGH1^30M9g^-L?1$R&1fcGh?c|e7`JzX3_EKc8@Y{+%ULBMrB*L}A| z6K>qN6~S5d$Z*Y;OQ+6x=_e$go4{Sc6D|FbPcDJ)fzlDRqnq+3M(i@sdGn`I=X3gl z{r#RZJzG7S;~Cv2drg*8>rI}uP5s?W6GP3?*DGj0LnS}iR zGx@D7{&}6BDI?5P=*g}FH