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])
|
2013-02-10 09:05:20 +01:00
|
|
|
flash.now.alert = t('finance.balancing.new.alert') if @order.closed?
|
2009-01-10 22:22:16 +01:00
|
|
|
@comments = @order.comments
|
2009-04-01 00:46:01 +02:00
|
|
|
|
|
|
|
if params['sort']
|
2009-05-04 17:56:52 +02:00
|
|
|
sort = case params['sort']
|
2009-04-01 00:46:01 +02:00
|
|
|
when "name" then "articles.name"
|
|
|
|
when "order_number" then "articles.order_number"
|
|
|
|
when "name_reverse" then "articles.name DESC"
|
|
|
|
when "order_number_reverse" then "articles.order_number DESC"
|
|
|
|
end
|
|
|
|
else
|
2009-05-04 17:56:52 +02:00
|
|
|
sort = "id"
|
2009-04-01 00:46:01 +02:00
|
|
|
end
|
|
|
|
|
2012-05-12 11:18:46 +02:00
|
|
|
@articles = @order.order_articles.ordered.includes(:article).order(sort)
|
2009-05-04 17:56:52 +02:00
|
|
|
|
2009-04-03 17:50:17 +02:00
|
|
|
if params[:sort] == "order_number"
|
2012-05-12 11:18:46 +02:00
|
|
|
@articles = @articles.to_a.sort { |a,b| a.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> b.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
|
2009-04-03 17:50:17 +02:00
|
|
|
elsif params[:sort] == "order_number_reverse"
|
2012-05-12 11:18:46 +02:00
|
|
|
@articles = @articles.to_a.sort { |a,b| b.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> a.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
|
2009-04-03 17:50:17 +02:00
|
|
|
end
|
|
|
|
|
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)
|
2013-02-10 09:05:20 +01:00
|
|
|
redirect_to finance_root_url, notice: t('finance.balancing.close.notice')
|
2012-07-27 18:03:46 +02:00
|
|
|
|
|
|
|
rescue => error
|
2013-02-10 09:05:20 +01:00
|
|
|
redirect_to new_finance_order_url(order_id: @order.id), alert: t('finance.balancing.close.alert', message: 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)
|
2013-02-10 09:05:20 +01:00
|
|
|
redirect_to finance_balancing_url, notice: t('finance.balancing.close_direct.notice')
|
2012-07-27 18:03:46 +02:00
|
|
|
rescue => error
|
2013-02-10 09:05:20 +01:00
|
|
|
redirect_to finance_balancing_url, alert: t('finance.balancing.close_direct.alert', message: error.message)
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|