2012-04-16 08:48:01 +02:00
|
|
|
# encoding: utf-8
|
2012-11-10 16:44:05 +01:00
|
|
|
class Finance::BalancingController < Finance::BaseController
|
2012-05-12 10:55:20 +02:00
|
|
|
|
2009-01-10 22:22:16 +01:00
|
|
|
def index
|
2012-11-10 16:44:05 +01:00
|
|
|
@orders = Order.finished.page(params[:page]).per(@per_page).order('ends DESC')
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2012-07-27 18:03:46 +02:00
|
|
|
@order = Order.find(params[:order_id])
|
|
|
|
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
|
2009-01-10 22:22:16 +01:00
|
|
|
@comments = @order.comments
|
2009-04-01 00:46:01 +02:00
|
|
|
|
2013-03-12 12:50:56 +01:00
|
|
|
@articles = @order.order_articles.ordered.includes(:order, :article_price,
|
2013-03-12 18:54:51 +01:00
|
|
|
group_order_articles: {group_order: :ordergroup})
|
|
|
|
|
|
|
|
sort_param = params['sort'] || 'name'
|
|
|
|
@articles = case sort_param
|
|
|
|
when 'name' then
|
|
|
|
OrderArticle.sort_by_name(@articles)
|
|
|
|
when 'name_reverse' then
|
|
|
|
OrderArticle.sort_by_name(@articles).reverse
|
|
|
|
when 'order_number' then
|
|
|
|
OrderArticle.sort_by_order_number(@articles)
|
|
|
|
when 'order_number_reverse' then
|
|
|
|
OrderArticle.sort_by_order_number(@articles).reverse
|
|
|
|
else
|
|
|
|
@articles
|
|
|
|
end
|
2009-04-03 17:50:17 +02:00
|
|
|
|
2012-07-27 18:03:46 +02:00
|
|
|
render layout: false if request.xhr?
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
2012-07-27 18:03:46 +02:00
|
|
|
def edit_note
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
render :layout => false
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
2012-07-27 18:03:46 +02:00
|
|
|
def update_note
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
if @order.update_attributes(params[:order])
|
|
|
|
render :layout => false
|
2009-01-29 21:28:22 +01:00
|
|
|
else
|
2012-07-27 18:03:46 +02:00
|
|
|
render :action => :edit_note, :layout => false
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-14 12:46:01 +01:00
|
|
|
# before the order will booked, a view lists all Ordergroups and its order_prices
|
2009-01-10 22:22:16 +01:00
|
|
|
def confirm
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2009-01-14 12:46:01 +01:00
|
|
|
# Balances the Order, Update of the Ordergroup.account_balances
|
2009-01-10 22:22:16 +01:00
|
|
|
def close
|
|
|
|
@order = Order.find(params[:id])
|
2012-07-27 18:03:46 +02:00
|
|
|
@order.close!(@current_user)
|
2012-11-10 16:44:05 +01:00
|
|
|
redirect_to finance_root_url, notice: "Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert."
|
2012-07-27 18:03:46 +02:00
|
|
|
|
|
|
|
rescue => error
|
2012-11-10 16:44:05 +01:00
|
|
|
redirect_to new_finance_order_url(order_id: @order.id), alert: "Ein Fehler ist beim Abrechnen aufgetreten: #{error.message}"
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
# Close the order directly, without automaticly updating ordergroups account balances
|
|
|
|
def close_direct
|
2009-01-10 22:22:16 +01:00
|
|
|
@order = Order.find(params[:id])
|
2012-07-27 18:03:46 +02:00
|
|
|
@order.close_direct!(@current_user)
|
|
|
|
redirect_to finance_balancing_url, notice: "Bestellung wurde geschlossen."
|
|
|
|
rescue => error
|
|
|
|
redirect_to finance_balancing_url, alert: "Bestellung kann nicht geschlossen werden: #{error.message}"
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|