From 8fb43346101f1ab1471f9df0ef74841e1579aeae Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Fri, 3 Apr 2009 17:16:39 +0200 Subject: [PATCH 1/8] Modified sort_link helper method to allo non ajax links. --- app/helpers/application_helper.rb | 18 +++++++++++++----- .../_edit_results_by_articles.html.haml | 4 ++-- .../transactions/_ordergroups.html.haml | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 261595f6..0ad1bb94 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -58,10 +58,13 @@ module ApplicationHelper return result end - def sort_link_helper(text, param, per_page = (@per_page || 10), action = "list" ) - key = param - key += "_reverse" if params[:sort] == param - options = { + def sort_link_helper(text, key, options = {}) + per_page = options[:per_page] || 10 + action = options[:action] || "list" + remote = options[:remote].nil? ? true : options[:remote] + key += "_reverse" if params[:sort] == key + + link_options = { :url => url_for(:params => params.merge({:sort => key, :page => nil, :per_page => per_page})), :before => "Element.show('loader')", :success => "Element.hide('loader')", @@ -71,7 +74,12 @@ module ApplicationHelper :title => _("Nach #{text} sortieren"), :href => url_for(:action => action, :params => params.merge({:sort => key, :page => nil, :per_page => per_page})) } - link_to_remote(text, options, html_options) + + if remote + link_to_remote(text, link_options, html_options) + else + link_to(text, link_options[:url], html_options) + end end # Generates a link to the top of the website diff --git a/app/views/finance/balancing/_edit_results_by_articles.html.haml b/app/views/finance/balancing/_edit_results_by_articles.html.haml index 699321c7..c33de047 100644 --- a/app/views/finance/balancing/_edit_results_by_articles.html.haml +++ b/app/views/finance/balancing/_edit_results_by_articles.html.haml @@ -7,9 +7,9 @@ %thead %tr %th[sort_td_class_helper "name"]{:colspan => "1"} - = sort_link_helper "Artikel", "name", 1000, "new" + = sort_link_helper "Artikel", "name", :action => "new", :remote => false %th[sort_td_class_helper "order_number"] - = sort_link_helper "Nr.", "order_number", 1000, "new" + = sort_link_helper "Nr.", "order_number", :action => "new", :remote => false %th Menge %th GebGr * Einheit %th Netto diff --git a/app/views/finance/transactions/_ordergroups.html.haml b/app/views/finance/transactions/_ordergroups.html.haml index 4a145fb8..daa37180 100644 --- a/app/views/finance/transactions/_ordergroups.html.haml +++ b/app/views/finance/transactions/_ordergroups.html.haml @@ -12,9 +12,9 @@ %table.list %thead %tr - %th= sort_link_helper "Name", "name", @per_page + %th= sort_link_helper "Name", "name", :per_page => @per_page %th Kontakt - %th= sort_link_helper "Kontostand", "account_balance", @per_page + %th= sort_link_helper "Kontostand", "account_balance", :per_page => @per_page %th %tbody - for group in @groups From 596f5657bcc448fd0e0dea999a6fb6b5dd3878b5 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Fri, 3 Apr 2009 17:35:00 +0200 Subject: [PATCH 2/8] Fixed remote and non-remote link mixtures bug. --- app/controllers/finance/balancing_controller.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 98c4dde7..d17da816 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -33,7 +33,10 @@ class Finance::BalancingController < ApplicationController :order => sort ) - case params[:view] + view = params[:view] + params[:view] = nil + + case view when 'editResults' render :partial => 'edit_results_by_articles' and return when 'groupsOverview' @@ -41,15 +44,6 @@ class Finance::BalancingController < ApplicationController when 'articlesOverview' render :partial => 'shared/articles_by_articles', :locals => {:order => @order} and return end - - respond_to do |format| - format.html # new.haml - format.js do - render :update do |page| - page.replace_html 'results', :partial => "edit_results_by_articles" - end - end - end end def edit_note From 30aa04b710bc2c04b114c4ae4938f131796c404f Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Fri, 3 Apr 2009 17:50:17 +0200 Subject: [PATCH 3/8] Made sort by order_number balancing view work. --- app/controllers/finance/balancing_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index d17da816..79382de9 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -33,6 +33,12 @@ class Finance::BalancingController < ApplicationController :order => sort ) + if params[:sort] == "order_number" + @articles = @articles.sort { |a,b| a.article.order_number.gsub(/[a-zA-Z]/, "").to_i <=> b.article.order_number.gsub(/[a-zA-Z]/, "").to_i } + elsif params[:sort] == "order_number_reverse" + @articles = @articles.sort { |a,b| b.article.order_number.gsub(/[a-zA-Z]/, "").to_i <=> a.article.order_number.gsub(/[a-zA-Z]/, "").to_i } + end + view = params[:view] params[:view] = nil From 578002501b3cba3984ec7e7028df5b067fbf0d29 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Fri, 3 Apr 2009 18:01:19 +0200 Subject: [PATCH 4/8] Hide ordergroups with result = 0. --- app/views/finance/balancing/_group_order_articles.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/finance/balancing/_group_order_articles.html.haml b/app/views/finance/balancing/_group_order_articles.html.haml index c9441fec..a800d393 100644 --- a/app/views/finance/balancing/_group_order_articles.html.haml +++ b/app/views/finance/balancing/_group_order_articles.html.haml @@ -9,7 +9,7 @@ %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]) + - for group_order_article in order_article.group_order_articles.ordered.all(:include => [:group_order]) %tr{:class => cycle('even', 'odd', :name => 'results')}[group_order_article] %td %td{:style=>"width:50%"} From de1aa2ac3805ca28a405f36957bbec1f64d80cc5 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Fri, 3 Apr 2009 18:58:12 +0200 Subject: [PATCH 5/8] Headers and table improvements for matrix pdf. Fixed #204 --- app/views/orders/matrixPdf.pdf.prawn | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/views/orders/matrixPdf.pdf.prawn b/app/views/orders/matrixPdf.pdf.prawn index c89f5608..121d44dd 100644 --- a/app/views/orders/matrixPdf.pdf.prawn +++ b/app/views/orders/matrixPdf.pdf.prawn @@ -35,6 +35,9 @@ while (page_number * max_order_articles_per_page < total_num_order_articles) do page_number += 1 pdf.start_new_page(:layout => :landscape) + pdf.header [pdf.margin_box.left,pdf.margin_box.top+20] do + pdf.text title, :size => 10, :align => :center + end # Collect order_articles for this page current_order_articles = order_articles.select do |a| @@ -45,7 +48,7 @@ while (page_number * max_order_articles_per_page < total_num_order_articles) do # Make order_articles header header = [""] for header_article in current_order_articles - name = header_article.article.name.split("-").join(" ").split(".").join(". ").split("/").join(" ") + name = header_article.article.name.gsub(/[-\/]/, " ").gsub(".", ". ") name = name.split.collect { |w| truncate(w, :length => 8, :omission => "..") }.join(" ") header << truncate(name, :length => 30, :omission => " ..") end @@ -65,14 +68,15 @@ while (page_number * max_order_articles_per_page < total_num_order_articles) do end # Make table - widths = { } # Generate widths-hash for table layout - (max_order_articles_per_page + 1).times { |i| widths.merge!({ i => 40 }) unless i == 0 } + widths = {0 => 85} # Generate widths-hash for table layout + (max_order_articles_per_page + 1).times { |i| widths.merge!({ i => 41 }) unless i == 0 } + logger.debug "Spaltenbreiten: #{widths.inspect}" pdf.table groups_data, :font_size => 8, :border_style => :grid, :vertical_padding => 3, :headers => header, - :widths => widths, + :column_widths => widths, :row_colors => ['ffffff','ececec'] end \ No newline at end of file From d62d45e4a4094d7b062c36c1b1ae27e0b0cdf781 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Fri, 3 Apr 2009 23:32:24 +0200 Subject: [PATCH 6/8] Hide zero results in matrix pdf. --- app/controllers/orders_controller.rb | 7 ++++++- app/views/orders/matrixPdf.pdf.prawn | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 4b41a16e..f270b932 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -152,7 +152,12 @@ class OrdersController < ApplicationController # Renders the matrix PDF. def matrixPdf @order = Order.find(params[:id]) - prawnto :filename => "#{Date.today}_#{@order.name}_Matrix.pdf" + unless @order.order_articles.ordered.empty? + prawnto :filename => "#{Date.today}_#{@order.name}_Matrix.pdf" + else + flash[:error] = "Es sind keine Artikel bestellt worden." + redirect_to @order + end end # adds a Comment to the Order diff --git a/app/views/orders/matrixPdf.pdf.prawn b/app/views/orders/matrixPdf.pdf.prawn index 121d44dd..8b5d2bd4 100644 --- a/app/views/orders/matrixPdf.pdf.prawn +++ b/app/views/orders/matrixPdf.pdf.prawn @@ -6,6 +6,7 @@ pdf.header [pdf.margin_box.left,pdf.margin_box.top+20] do end pdf.footer [pdf.margin_box.left, pdf.margin_box.bottom-5] do pdf.stroke_horizontal_rule + pdf.move_down 2 pdf.text "Seite #{pdf.page_count}", :size => 8 end @@ -62,7 +63,7 @@ while (page_number * max_order_articles_per_page < total_num_order_articles) do for order_article in current_order_articles # get the Ordergroup result for this order_article goa = order_article.group_order_articles.first :conditions => { :group_order_id => group_order.id } - group_result << ((goa.nil? || goa == 0) ? "" : goa.result.to_i) + group_result << ((goa.nil? || goa.result == 0) ? "" : goa.result.to_i) end groups_data << group_result end From 40886b71f99ae75fd4962331d665cad4eb520c5c Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 5 Apr 2009 14:59:55 +0200 Subject: [PATCH 7/8] Fixed Bug in balancing controller when adding an ordergroup-result. --- app/controllers/finance/balancing_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 79382de9..30d907d3 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -164,6 +164,7 @@ class Finance::BalancingController < ApplicationController # 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 @@ -177,6 +178,12 @@ class Finance::BalancingController < ApplicationController 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 From 36f9bffdb8000024def5ceb481efbbdb8f1ee64c Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 5 Apr 2009 15:23:21 +0200 Subject: [PATCH 8/8] Allow input of decimal numbers for GroupOrderArticle-result. --- app/models/group_order_article.rb | 5 ++ ...31156_modify_group_order_article_result.rb | 9 +++ db/schema.rb | 64 ++++++++++--------- 3 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 db/migrate/20090405131156_modify_group_order_article_result.rb diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 89d41407..0b486c90 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -31,6 +31,11 @@ class GroupOrderArticle < ActiveRecord::Base attr_accessor :ordergroup_id # To create an new GroupOrder if neccessary named_scope :ordered, :conditions => 'result > 0' + + # Custom attribute setter that accepts decimal numbers using localized decimal separator. + def result=(result) + self[:result] = String.delocalized_decimal(result) + end # Updates the quantity/tolerance for this GroupOrderArticle by updating both GroupOrderArticle properties # and the associated GroupOrderArticleQuantities chronologically. diff --git a/db/migrate/20090405131156_modify_group_order_article_result.rb b/db/migrate/20090405131156_modify_group_order_article_result.rb new file mode 100644 index 00000000..f2955fd2 --- /dev/null +++ b/db/migrate/20090405131156_modify_group_order_article_result.rb @@ -0,0 +1,9 @@ +class ModifyGroupOrderArticleResult < ActiveRecord::Migration + def self.up + change_column :group_order_articles, :result, :decimal, :precision => 8, :scale => 3 + end + + def self.down + change_column :group_order_articles, :result, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 514a422f..8687cd15 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 => 20090317175355) do +ActiveRecord::Schema.define(:version => 20090405131156) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -28,25 +28,25 @@ ActiveRecord::Schema.define(:version => 20090317175355) do end create_table "articles", :force => true do |t| - t.string "name", :default => "", :null => false - t.integer "supplier_id", :default => 0, :null => false - t.integer "article_category_id", :default => 0, :null => false - t.string "unit", :default => "", :null => false + t.string "name", :default => "", :null => false + t.integer "supplier_id", :default => 0, :null => false + t.integer "article_category_id", :default => 0, :null => false + t.string "unit", :default => "", :null => false t.string "note" - t.boolean "availability", :default => true, :null => false + t.boolean "availability", :default => true, :null => false t.string "manufacturer" t.string "origin" t.datetime "shared_updated_on" - t.decimal "price" + t.decimal "price", :precision => 8, :scale => 2 t.float "tax" - t.decimal "deposit", :default => 0.0 - t.integer "unit_quantity", :default => 1, :null => false + t.decimal "deposit", :precision => 8, :scale => 2, :default => 0.0 + t.integer "unit_quantity", :default => 1, :null => false t.string "order_number" t.datetime "created_at" t.datetime "updated_at" - t.integer "quantity", :default => 0 t.datetime "deleted_at" t.string "type" + t.integer "quantity", :default => 0 end add_index "articles", ["name", "supplier_id"], :name => "index_articles_on_name_and_supplier_id" @@ -93,12 +93,12 @@ ActiveRecord::Schema.define(:version => 20090317175355) do end create_table "group_order_articles", :force => true do |t| - t.integer "group_order_id", :default => 0, :null => false - t.integer "order_article_id", :default => 0, :null => false - t.integer "quantity", :default => 0, :null => false - t.integer "tolerance", :default => 0, :null => false - t.datetime "updated_on", :null => false - t.integer "result" + t.integer "group_order_id", :default => 0, :null => false + t.integer "order_article_id", :default => 0, :null => false + t.integer "quantity", :default => 0, :null => false + t.integer "tolerance", :default => 0, :null => false + t.datetime "updated_on", :null => false + t.decimal "result", :precision => 8, :scale => 3 end add_index "group_order_articles", ["group_order_id", "order_article_id"], :name => "goa_index", :unique => true @@ -115,22 +115,22 @@ ActiveRecord::Schema.define(:version => 20090317175355) do add_index "group_orders", ["ordergroup_id", "order_id"], :name => "index_group_orders_on_ordergroup_id_and_order_id", :unique => true create_table "groups", :force => true do |t| - t.string "type", :default => "", :null => false - t.string "name", :default => "", :null => false + t.string "type", :default => "", :null => false + t.string "name", :default => "", :null => false t.string "description" - t.decimal "account_balance", :default => 0.0, :null => false + t.decimal "account_balance", :precision => 8, :scale => 2, :default => 0.0, :null => false t.datetime "account_updated" - t.datetime "created_on", :null => false - t.boolean "role_admin", :default => false, :null => false - t.boolean "role_suppliers", :default => false, :null => false - t.boolean "role_article_meta", :default => false, :null => false - t.boolean "role_finance", :default => false, :null => false - t.boolean "role_orders", :default => false, :null => false - t.boolean "weekly_task", :default => false + t.datetime "created_on", :null => false + t.boolean "role_admin", :default => false, :null => false + t.boolean "role_suppliers", :default => false, :null => false + t.boolean "role_article_meta", :default => false, :null => false + t.boolean "role_finance", :default => false, :null => false + t.boolean "role_orders", :default => false, :null => false + t.boolean "weekly_task", :default => false t.integer "weekday" t.string "task_name" t.string "task_description" - t.integer "task_required_users", :default => 1 + t.integer "task_required_users", :default => 1 t.datetime "deleted_at" t.string "contact_person" t.string "contact_phone" @@ -152,16 +152,16 @@ ActiveRecord::Schema.define(:version => 20090317175355) do create_table "invoices", :force => true do |t| t.integer "supplier_id" t.integer "delivery_id" + t.integer "order_id" t.string "number" t.date "date" t.date "paid_on" t.text "note" t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.datetime "created_at" - t.datetime "updated_at" - t.integer "order_id" t.decimal "deposit", :precision => 8, :scale => 2, :default => 0.0, :null => false t.decimal "deposit_credit", :precision => 8, :scale => 2, :default => 0.0, :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "memberships", :force => true do |t| @@ -211,6 +211,10 @@ ActiveRecord::Schema.define(:version => 20090317175355) do t.decimal "foodcoop_result", :precision => 8, :scale => 2 end + create_table "schema_info", :id => false, :force => true do |t| + t.integer "version" + end + create_table "stock_changes", :force => true do |t| t.integer "delivery_id" t.integer "order_id"