Complete refactoring of orders-workflow.
OrderResult tables are removed. Data consistency is now possible through new article.price-history (ArticlePrice). Balancing-workflow needs to be updated.
This commit is contained in:
parent
80287aeea4
commit
9eb2125f15
98 changed files with 1121 additions and 1717 deletions
|
|
@ -121,7 +121,7 @@ class ArticlesController < ApplicationController
|
|||
def destroy
|
||||
@article = Article.find(params[:id])
|
||||
|
||||
@order = @article.inUse # If article is in an active Order, the Order will be returned
|
||||
@order = @article.in_open_order # If article is in an active Order, the Order will be returned
|
||||
if @order
|
||||
render :update do |page|
|
||||
page.insert_html :after, @article.id.to_s, :partial => 'destroyActiveArticle'
|
||||
|
|
@ -226,7 +226,7 @@ class ArticlesController < ApplicationController
|
|||
:origin => row[:origin],
|
||||
:unit => row[:unit],
|
||||
:article_category => ArticleCategory.find_by_name(row[:category]),
|
||||
:net_price => row[:price],
|
||||
:price => row[:price],
|
||||
:unit_quantity => row[:unit_quantity],
|
||||
:order_number => row[:number],
|
||||
:deposit => row[:deposit],
|
||||
|
|
@ -290,7 +290,7 @@ class ArticlesController < ApplicationController
|
|||
:note => shared_article.note,
|
||||
:manufacturer => shared_article.manufacturer,
|
||||
:origin => shared_article.origin,
|
||||
:net_price => shared_article.price,
|
||||
:price => shared_article.price,
|
||||
:tax => shared_article.tax,
|
||||
:deposit => shared_article.deposit,
|
||||
:unit_quantity => shared_article.unit_quantity,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Finance::BalancingController < ApplicationController
|
|||
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.net_price
|
||||
@article.make_gross if @article.tax && @article.deposit && @article.price
|
||||
if @article.valid?
|
||||
@article.save
|
||||
@order = @article.order
|
||||
|
|
@ -121,9 +121,9 @@ class Finance::BalancingController < ApplicationController
|
|||
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.sumPrice('groups'))
|
||||
page["fcProfit"].replace_html number_to_currency(article.order.fcProfit)
|
||||
page["fcProfit"].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
|
||||
|
|
@ -141,15 +141,15 @@ class Finance::BalancingController < ApplicationController
|
|||
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.sumPrice("groups")
|
||||
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["fcProfit"].replace_html number_to_currency(order.fcProfit)
|
||||
page["profit"].replace_html number_to_currency(order.profit)
|
||||
page["groups_amount"].visual_effect :highlight, :duration => 2
|
||||
page["fcProfit"].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]
|
||||
|
|
@ -169,9 +169,9 @@ class Finance::BalancingController < ApplicationController
|
|||
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.sumPrice('groups'))
|
||||
page["fcProfit"].replace_html number_to_currency(article.order.fcProfit)
|
||||
page["fcProfit"].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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class FoodcoopController < ApplicationController
|
|||
conditions = "first_name LIKE '%#{params[:query]}%' OR last_name LIKE '%#{params[:query]}%'" unless params[:query].blank?
|
||||
|
||||
@total = User.count(:conditions => conditions)
|
||||
@users = User.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "nick", :include => "groups")
|
||||
@users = User.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "nick", :include => :groups)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ class HomeController < ApplicationController
|
|||
helper :messages
|
||||
|
||||
def index
|
||||
@currentOrders = Order.find_current
|
||||
@orderGroup = @current_user.find_ordergroup
|
||||
if @orderGroup
|
||||
@financial_transactions = @orderGroup.financial_transactions.find(:all, :order => 'created_on desc', :limit => 3)
|
||||
@currentOrders = Order.open
|
||||
@ordergroup = @current_user.find_ordergroup
|
||||
if @ordergroup
|
||||
@financial_transactions = @ordergroup.financial_transactions.find(:all, :order => 'created_on desc', :limit => 3)
|
||||
end
|
||||
# unaccepted tasks
|
||||
@unaccepted_tasks = @current_user.unaccepted_tasks
|
||||
|
|
|
|||
|
|
@ -8,22 +8,13 @@ class OrderingController < ApplicationController
|
|||
verify :method => :post, :only => [:saveOrder], :redirect_to => { :action => :index }
|
||||
|
||||
# Index page.
|
||||
def index
|
||||
@orderGroup = @current_user.find_ordergroup
|
||||
@currentOrders = Order.find_current
|
||||
@finishedOrders = @orderGroup.findExpiredOrders + @orderGroup.findFinishedNotBooked
|
||||
@bookedOrders = @orderGroup.findBookedOrders(5)
|
||||
|
||||
# Calculate how much the order group has spent on open or nonbooked orders:
|
||||
@currentOrdersValue, @nonbookedOrdersValue = 0, 0
|
||||
@orderGroup.findCurrent.each { |groupOrder| @currentOrdersValue += groupOrder.price}
|
||||
@finishedOrders.each { |groupOrder| @nonbookedOrdersValue += groupOrder.price}
|
||||
def index
|
||||
end
|
||||
|
||||
# Edit a current order.
|
||||
def order
|
||||
@current_orders = Order.find_current
|
||||
@other_orders = @current_orders.reject{|order| order == @order}
|
||||
@open_orders = Order.open
|
||||
@other_orders = @open_orders.reject{|order| order == @order}
|
||||
# Load order article data...
|
||||
@articles_by_category = @order.get_articles
|
||||
# save results of earlier orders in array
|
||||
|
|
@ -39,10 +30,10 @@ class OrderingController < ApplicationController
|
|||
'tolerance_result' => result[:tolerance]}
|
||||
end
|
||||
@version = @group_order.lock_version
|
||||
@availableFunds = @ordergroup.getAvailableFunds(@group_order)
|
||||
@availableFunds = @ordergroup.get_available_funds(@group_order)
|
||||
else
|
||||
@version = 0
|
||||
@availableFunds = @ordergroup.getAvailableFunds
|
||||
@availableFunds = @ordergroup.get_available_funds
|
||||
end
|
||||
|
||||
# load prices ....
|
||||
|
|
@ -50,10 +41,10 @@ class OrderingController < ApplicationController
|
|||
@others_quantity = Array.new; @quantity = Array.new; @quantity_result = Array.new; @used_quantity = Array.new; @unused_quantity = Array.new
|
||||
@others_tolerance = Array.new; @tolerance = Array.new; @tolerance_result = Array.new; @used_tolerance = Array.new; @unused_tolerance = Array.new
|
||||
i = 0;
|
||||
@articles_by_category.each do |category, order_articles|
|
||||
@articles_by_category.each do |category_name, order_articles|
|
||||
for order_article in order_articles
|
||||
# price/unit size
|
||||
@price[i] = order_article.article.gross_price
|
||||
@price[i] = order_article.article.fc_price
|
||||
@unit[i] = order_article.article.unit_quantity
|
||||
# quantity
|
||||
@quantity[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id]['quantity'] : 0)
|
||||
|
|
@ -78,12 +69,12 @@ class OrderingController < ApplicationController
|
|||
begin
|
||||
Order.transaction do
|
||||
# Create group order if necessary...
|
||||
if (groupOrder = order.group_orders.find(:first, :conditions => "ordergroup_id = #{ordergroup.id}", :include => [:group_order_articles]))
|
||||
if (groupOrder = order.group_orders.find(:first, :conditions => "ordergroup_id = #{@ordergroup.id}", :include => [:group_order_articles]))
|
||||
if (params[:version].to_i != groupOrder.lock_version) # check for conflicts well ahead
|
||||
raise ActiveRecord::StaleObjectError
|
||||
end
|
||||
else
|
||||
groupOrder = GroupOrder.new(:ordergroup => ordergroup, :order => order, :updated_by => @current_user, :price => 0)
|
||||
groupOrder = GroupOrder.new(:ordergroup => @ordergroup, :order => order, :updated_by => @current_user, :price => 0)
|
||||
groupOrder.save!
|
||||
end
|
||||
# Create/update GroupOrderArticles...
|
||||
|
|
@ -98,15 +89,15 @@ class OrderingController < ApplicationController
|
|||
unless (quantities = ordered.delete(article.id.to_s)) && (quantity = quantities['quantity']) && (tolerance = quantities['tolerance'])
|
||||
quantity = tolerance = 0
|
||||
end
|
||||
groupOrderArticle.updateQuantities(quantity.to_i, tolerance.to_i)
|
||||
groupOrderArticle.update_quantities(quantity.to_i, tolerance.to_i)
|
||||
# Add to new list of GroupOrderArticles:
|
||||
newGroupOrderArticles.push(groupOrderArticle)
|
||||
end
|
||||
groupOrder.group_order_articles = newGroupOrderArticles
|
||||
groupOrder.updatePrice
|
||||
groupOrder.update_price!
|
||||
groupOrder.updated_by = @current_user
|
||||
groupOrder.save!
|
||||
order.updateQuantities
|
||||
order.update_quantities
|
||||
order.save!
|
||||
end
|
||||
flash[:notice] = 'Die Bestellung wurde gespeichert.'
|
||||
|
|
@ -124,86 +115,53 @@ class OrderingController < ApplicationController
|
|||
# this method decides between finished and unfinished orders
|
||||
def my_order_result
|
||||
@order= Order.find(params[:id])
|
||||
@current_orders = Order.find_current #.reject{|order| order == @order}
|
||||
if @order.finished?
|
||||
@finished= true
|
||||
@groupOrderResult= @order.group_order_results.find_by_group_name(@current_user.find_ordergroup.name)
|
||||
@order_value= @groupOrderResult.price if @groupOrderResult
|
||||
@comments= @order.comments
|
||||
else
|
||||
@group_order = @order.group_orders.find_by_ordergroup_id(@current_user.find_ordergroup.id)
|
||||
@order_value= @group_order.price if @group_order
|
||||
end
|
||||
@group_order = @order.group_order(@ordergroup)
|
||||
end
|
||||
|
||||
# Shows all Orders of the Ordergroup
|
||||
# if selected, it shows all orders of the foodcoop
|
||||
def myOrders
|
||||
@orderGroup = @current_user.find_ordergroup
|
||||
unless params[:show_all] == "1"
|
||||
# get only orders belonging to the ordergroup
|
||||
@finishedOrders = @orderGroup.findExpiredOrders + @orderGroup.findFinishedNotBooked
|
||||
@bookedOrders = GroupOrderResult.paginate :page => params[:page], :per_page => 10,
|
||||
:include => :order,
|
||||
:conditions => ["group_order_results.group_name = ? AND group_order_results.order_id = orders.id AND orders.finished = ? AND orders.booked = ? ", @orderGroup.name, true, true],
|
||||
:order => "orders.ends DESC"
|
||||
else
|
||||
# get all orders, take care of different models in @finishedOrders
|
||||
@show_all = true
|
||||
@finishedOrders = Order.find_finished
|
||||
@bookedOrders = Order.paginate_all_by_booked true, :page => params[:page], :per_page => 10, :order => 'ends desc'
|
||||
end
|
||||
|
||||
# get only orders belonging to the ordergroup
|
||||
@closed_orders = Order.paginate :page => params[:page], :per_page => 10,
|
||||
:conditions => { :state => 'closed' }, :order => "orders.ends DESC"
|
||||
|
||||
respond_to do |format|
|
||||
format.html # myOrders.haml
|
||||
format.js do
|
||||
render :update do |page|
|
||||
page.replace_html 'bookedOrders', :partial => "bookedOrders"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# sends a form for adding a new comment
|
||||
def newComment
|
||||
@order = Order.find(params[:id])
|
||||
render :update do |page|
|
||||
page.replace_html 'newComment', :partial => 'shared/newComment', :object => @order
|
||||
page["newComment"].show
|
||||
format.js { render :partial => "orders" }
|
||||
end
|
||||
end
|
||||
|
||||
# adds a Comment to the Order
|
||||
def addComment
|
||||
@order = Order.find(params[:id])
|
||||
@comment = Comment.new(params[:comment])
|
||||
@comment.user = @current_user
|
||||
if @comment.title.length > 3 && @order.comments << @comment
|
||||
flash[:notice] = _("Comment has been created.")
|
||||
redirect_to :action => 'my_order_result', :id => @order
|
||||
def add_comment
|
||||
order = Order.find(params[:id])
|
||||
comment = order.comments.build(params[:comment])
|
||||
comment.user = @current_user
|
||||
if !comment.text.empty? and comment.save
|
||||
flash[:notice] = "Kommentar wurde erstellt."
|
||||
else
|
||||
flash[:error] = _("The comment has not been saved. Check the title and try again.")
|
||||
redirect_to :action => 'my_order_result', :id => @order
|
||||
flash[:error] = "Kommentar konnte nicht erstellt werden. Leerer Kommentar?"
|
||||
end
|
||||
redirect_to :action => 'my_order_result', :id => order
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns true if @current_user is member of an Ordergroup.
|
||||
# Used as a :before_filter by OrderingController.
|
||||
def ensure_ordergroup_member
|
||||
unless @current_user.find_ordergroup
|
||||
flash[:notice] = 'Sie gehören keiner Bestellgruppe an.'
|
||||
redirect_to :controller => root_path
|
||||
end
|
||||
# Returns true if @current_user is member of an Ordergroup.
|
||||
# Used as a :before_filter by OrderingController.
|
||||
def ensure_ordergroup_member
|
||||
@ordergroup = @current_user.find_ordergroup
|
||||
if @ordergroup.nil?
|
||||
flash[:notice] = 'Sie gehören keiner Bestellgruppe an.'
|
||||
redirect_to :controller => root_path
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_open_order
|
||||
@order = Order.find(params[:id], :include => [:supplier, :order_articles])
|
||||
unless @order.current?
|
||||
flash[:notice] = 'Diese Bestellung ist bereits abgeschlossen.'
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
def ensure_open_order
|
||||
@order = Order.find(params[:id], :include => [:supplier, :order_articles])
|
||||
unless @order.open?
|
||||
flash[:notice] = 'Diese Bestellung ist bereits abgeschlossen.'
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
# Controller for managing orders, i.e. all actions that require the "orders" role.
|
||||
# Normal ordering actions of members of order groups is handled by the OrderingController.
|
||||
class OrdersController < ApplicationController
|
||||
# Security
|
||||
|
||||
before_filter :authenticate_orders
|
||||
verify :method => :post, :only => [:finish, :create, :update, :destroy, :setAllBooked], :redirect_to => { :action => :index }
|
||||
|
||||
# Define layout exceptions for PDF actions:
|
||||
layout "application", :except => [:faxPdf, :matrixPdf, :articlesPdf, :groupsPdf]
|
||||
|
|
@ -11,20 +10,20 @@ class OrdersController < ApplicationController
|
|||
|
||||
# List orders
|
||||
def index
|
||||
@current_orders = Order.find_current
|
||||
@open_orders = Order.open
|
||||
@per_page = 15
|
||||
if params['sort']
|
||||
sort = case params['sort']
|
||||
when "supplier" then "suppliers.name, ends DESC"
|
||||
when "ends" then "ends DESC"
|
||||
when "supplier_reverse" then "suppliers.name DESC, ends DESC"
|
||||
when "supplier_reverse" then "suppliers.name DESC"
|
||||
when "ends_reverse" then "ends"
|
||||
end
|
||||
else
|
||||
sort = "ends DESC"
|
||||
end
|
||||
@orders = Order.paginate :page => params[:page], :per_page => @per_page,
|
||||
:order => sort, :conditions => ['ends < ? OR starts > ? OR finished = ?', Time.now, Time.now, true],
|
||||
:order => sort, :conditions => "state != 'open'",
|
||||
:include => :supplier
|
||||
|
||||
respond_to do |format|
|
||||
|
|
@ -38,30 +37,25 @@ class OrdersController < ApplicationController
|
|||
end
|
||||
|
||||
# Gives a view for the results to a specific order
|
||||
# Renders also the pdf
|
||||
def show
|
||||
@order= Order.find(params[:id])
|
||||
unless @order.finished?
|
||||
@order_articles= @order.get_articles
|
||||
@group_orders= @order.group_orders
|
||||
else
|
||||
@finished= true
|
||||
@order_articles= @order.order_article_results
|
||||
@group_orders= @order.group_order_results
|
||||
@comments= @order.comments
|
||||
|
||||
if params[:view] # Articles-list will be replaced
|
||||
partial = case params[:view]
|
||||
when 'normal' then "showResult"
|
||||
when 'groups'then 'showResult_groups'
|
||||
when 'articles'then 'showResult_articles'
|
||||
when 'normal' then "articles"
|
||||
when 'groups'then 'articles_by_groups'
|
||||
when 'articles'then 'articles_by_articles'
|
||||
end
|
||||
render :partial => partial if partial
|
||||
render :partial => partial, :locals => {:order => @order} if partial
|
||||
end
|
||||
end
|
||||
|
||||
# Page to create a new order.
|
||||
def new
|
||||
@supplier = Supplier.find(params[:id])
|
||||
@supplier = Supplier.find(params[:supplier_id])
|
||||
@order = @supplier.orders.build :ends => 4.days.from_now
|
||||
@template_orders = Order.find_all_by_supplier_id_and_finished(@supplier.id, true, :limit => 3, :order => 'starts DESC', :include => "order_article_results")
|
||||
@template_orders = @supplier.orders.finished :order => 'starts DESC', :include => "order_article_results"
|
||||
end
|
||||
|
||||
# Save a new order.
|
||||
|
|
@ -69,8 +63,8 @@ class OrdersController < ApplicationController
|
|||
def create
|
||||
@order = Order.new(params[:order])
|
||||
if @order.save
|
||||
flash[:notice] = _("The order has been created successfully.")
|
||||
redirect_to :action => 'show', :id => @order
|
||||
flash[:notice] = "Die Bestellung wurde erstellt."
|
||||
redirect_to @order
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
|
|
@ -86,12 +80,11 @@ class OrdersController < ApplicationController
|
|||
def update
|
||||
@order = Order.find params[:id]
|
||||
if @order.update_attributes params[:order]
|
||||
flash[:notice] = _("The order has been updated.")
|
||||
flash[:notice] = "Die Bestellung wurde aktualisiert."
|
||||
redirect_to :action => 'show', :id => @order
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
@order.updateAllGroupOrders #important if ordered articles has been removed
|
||||
end
|
||||
|
||||
# Delete an order.
|
||||
|
|
@ -103,21 +96,21 @@ class OrdersController < ApplicationController
|
|||
# Finish a current order.
|
||||
def finish
|
||||
order = Order.find(params[:id])
|
||||
order.finish(@current_user)
|
||||
flash[:notice] = _("The order has been finished successfully.")
|
||||
redirect_to :action => 'show', :id => order
|
||||
order.finish!(@current_user)
|
||||
flash[:notice] = "Die Bestellung wurde beendet."
|
||||
redirect_to order
|
||||
end
|
||||
|
||||
# Renders the groups-orderd PDF.
|
||||
def groupsPdf
|
||||
@order = Order.find(params[:id])
|
||||
prawnto :filename => "#{Date.today}_#{@order.name}_GruppenSortierung.pdf"
|
||||
prawnto :filename => "#{Date.today}_#{@order.supplier.name}_GruppenSortierung.pdf"
|
||||
end
|
||||
|
||||
# Renders the articles-orderd PDF.
|
||||
def articlesPdf
|
||||
@order = Order.find(params[:id])
|
||||
prawnto :filename => "#{Date.today}_#{@order.name}_ArtikelSortierung.pdf",
|
||||
prawnto :filename => "#{Date.today}_#{@order.supplier.name}_ArtikelSortierung.pdf",
|
||||
:prawn => { :left_margin => 48,
|
||||
:right_margin => 48,
|
||||
:top_margin => 48,
|
||||
|
|
@ -127,7 +120,7 @@ class OrdersController < ApplicationController
|
|||
# Renders the fax PDF.
|
||||
def faxPdf
|
||||
@order = Order.find(params[:id])
|
||||
prawnto :filename => "#{Date.today}_#{@order.name}_FAX.pdf"
|
||||
prawnto :filename => "#{Date.today}_#{@order.supplier.name}_FAX.pdf"
|
||||
end
|
||||
|
||||
# Renders the fax-text-file
|
||||
|
|
@ -136,51 +129,43 @@ class OrdersController < ApplicationController
|
|||
order = Order.find(params[:id])
|
||||
supplier = order.supplier
|
||||
contact = APP_CONFIG[:contact].symbolize_keys
|
||||
text = _("Order for") + " #{APP_CONFIG[:name]}"
|
||||
text += "\n" + _("Customer number") + ": #{supplier.customer_number}" unless supplier.customer_number.blank?
|
||||
text += "\n" + _("Delivery date") + ": "
|
||||
text = "Bestellung für" + " #{APP_CONFIG[:name]}"
|
||||
text += "\n" + "Kundennummer" + ": #{supplier.customer_number}" unless supplier.customer_number.blank?
|
||||
text += "\n" + "Liefertag" + ": "
|
||||
text += "\n\n#{supplier.name}\n#{supplier.address}\nFAX: #{supplier.fax}\n\n"
|
||||
text += "****** " + _("Shipping address") + "\n\n"
|
||||
text += "****** " + "Versandadresse" + "\n\n"
|
||||
text += "#{APP_CONFIG[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n"
|
||||
text += "****** " + _("Articles") + "\n\n"
|
||||
text += _("Number") + " " + _("Quantity") + " " + _("Name") + "\n"
|
||||
text += "****** " + "Artikel" + "\n\n"
|
||||
text += "Nummer" + " " + "Menge" + " " + "Name" + "\n"
|
||||
# now display all ordered articles
|
||||
order.order_article_results.each do |article|
|
||||
text += article.order_number.blank? ? " " : "#{article.order_number} "
|
||||
quantity = article.units_to_order.to_i.to_s
|
||||
order.order_articles.all(:include => [:article, :article_price]).each do |oa|
|
||||
number = oa.article.order_number
|
||||
(8 - number.size).times { number += " " }
|
||||
quantity = oa.units_to_order.to_i.to_s
|
||||
quantity = " " + quantity if quantity.size < 2
|
||||
text += "#{quantity} #{article.name}\n"
|
||||
text += "#{number} #{quantity} #{oa.article.name}\n"
|
||||
end
|
||||
send_data text,
|
||||
:type => 'text/plain; charset=utf-8; header=present',
|
||||
:disposition => "attachment; filename=#{order.name}"
|
||||
:disposition => "attachment; filename=#{order.supplier.name}"
|
||||
end
|
||||
|
||||
# Renders the matrix PDF.
|
||||
def matrixPdf
|
||||
@order = Order.find(params[:id])
|
||||
prawnto :filename => "#{Date.today}_#{@order.name}_Matrix.pdf"
|
||||
prawnto :filename => "#{Date.today}_#{@order.supplier.name}_Matrix.pdf"
|
||||
end
|
||||
|
||||
# sends a form for adding a new comment
|
||||
def newComment
|
||||
@order = Order.find(params[:id])
|
||||
render :update do |page|
|
||||
page.replace_html 'newComment', :partial => 'shared/newComment', :object => @order
|
||||
end
|
||||
end
|
||||
|
||||
# adds a Comment to the Order
|
||||
def addComment
|
||||
@order = Order.find(params[:id])
|
||||
@comment = Comment.new(params[:comment])
|
||||
@comment.user = @current_user
|
||||
if @comment.title.length > 3 && @order.comments << @comment
|
||||
flash[:notice] = _("Comment has been created.")
|
||||
redirect_to :action => 'show', :id => @order
|
||||
def add_comment
|
||||
order = Order.find(params[:id])
|
||||
comment = order.comments.build(params[:comment])
|
||||
comment.user = @current_user
|
||||
if !comment.text.empty? and comment.save
|
||||
flash[:notice] = "Kommentar wurde erstellt."
|
||||
else
|
||||
flash[:error] = _("The comment has not been saved. Check the title and try again.")
|
||||
redirect_to :action => 'show', :id => @order
|
||||
flash[:error] = "Kommentar konnte nicht erstellt werden. Leerer Kommentar?"
|
||||
end
|
||||
redirect_to order
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue