2012-11-10 16:44:05 +01:00
|
|
|
class Finance::BalancingController < Finance::BaseController
|
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
|
|
|
|
2013-10-02 16:32:29 +02:00
|
|
|
@articles = @order.order_articles.ordered_or_member.includes(:article, :article_price,
|
2021-03-01 15:27:26 +01:00
|
|
|
group_order_articles: { group_order: :ordergroup })
|
2009-04-01 00:46:01 +02:00
|
|
|
|
2013-03-12 18:54:51 +01:00
|
|
|
sort_param = params['sort'] || 'name'
|
|
|
|
@articles = case sort_param
|
2021-03-01 15:27:26 +01:00
|
|
|
when 'name' then
|
|
|
|
@articles.order('articles.name ASC')
|
|
|
|
when 'name_reverse' then
|
|
|
|
@articles.order('articles.name DESC')
|
|
|
|
when 'order_number' then
|
|
|
|
@articles.order('articles.order_number ASC')
|
|
|
|
when 'order_number_reverse' then
|
|
|
|
@articles.order('articles.order_number DESC')
|
|
|
|
else
|
2022-10-06 12:42:58 +02:00
|
|
|
@articles # TODO: We will never get here
|
2013-03-12 18:54:51 +01:00
|
|
|
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
|
2020-02-28 12:17:27 +01:00
|
|
|
|
2013-12-31 13:25:29 +01:00
|
|
|
def new_on_order_article_create # See publish/subscribe design pattern in /doc.
|
|
|
|
@order_article = OrderArticle.find(params[:order_article_id])
|
2020-02-28 12:17:27 +01:00
|
|
|
|
2013-12-31 13:25:29 +01:00
|
|
|
render :layout => false
|
|
|
|
end
|
2020-02-28 12:17:27 +01:00
|
|
|
|
2013-12-30 13:09:49 +01:00
|
|
|
def new_on_order_article_update # See publish/subscribe design pattern in /doc.
|
|
|
|
@order_article = OrderArticle.find(params[:order_article_id])
|
2020-02-28 12:17:27 +01:00
|
|
|
|
2013-12-30 13:09:49 +01:00
|
|
|
render :layout => false
|
|
|
|
end
|
2009-01-10 22:22:16 +01:00
|
|
|
|
2013-03-17 15:47:50 +01:00
|
|
|
def update_summary
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
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
|
|
|
|
|
2020-03-19 00:22:20 +01:00
|
|
|
def edit_transport
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_transport
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
@order.update_attributes! params[:order]
|
|
|
|
redirect_to new_finance_order_path(order_id: @order.id)
|
|
|
|
rescue => error
|
|
|
|
redirect_to new_finance_order_path(order_id: @order.id), alert: t('errors.general_msg', msg: error.message)
|
|
|
|
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])
|
2018-04-25 01:06:48 +02:00
|
|
|
@type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
|
2017-03-04 14:15:18 +01:00
|
|
|
@order.close!(@current_user, @type)
|
2013-03-21 22:08:09 +01:00
|
|
|
redirect_to finance_order_index_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-03-21 22:08:09 +01:00
|
|
|
redirect_to finance_order_index_url, notice: t('finance.balancing.close_direct.notice')
|
2012-07-27 18:03:46 +02:00
|
|
|
rescue => error
|
2013-03-21 22:08:09 +01:00
|
|
|
redirect_to finance_order_index_url, alert: t('finance.balancing.close_direct.alert', message: error.message)
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
2020-02-28 12:17:27 +01:00
|
|
|
def close_all_direct_with_invoice
|
|
|
|
count = 0
|
|
|
|
Order.transaction do
|
|
|
|
Order.finished_not_closed.with_invoice.each do |order|
|
|
|
|
order.close_direct! current_user
|
|
|
|
count += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to finance_order_index_url, notice: t('finance.balancing.close_all_direct_with_invoice.notice', count: count)
|
|
|
|
rescue => error
|
2022-10-06 12:42:58 +02:00
|
|
|
redirect_to finance_order_index_url, alert: t('errors.general_msg', msg: error.message) #TODO: this can't be reached
|
2020-02-28 12:17:27 +01:00
|
|
|
end
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|