Class: Finance::BalancingController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/finance/balancing_controller.rb

Instance Method Summary collapse

Instance Method Details

#closeObject

Balances the Order, Update of the Ordergroup.account_balances


69
70
71
72
73
74
75
76
77
# File 'app/controllers/finance/balancing_controller.rb', line 69

def close
  @order = Order.find(params[:id])
  @type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
  @order.close!(@current_user, @type)
  redirect_to finance_order_index_url, notice: t('finance.balancing.close.notice')

rescue => error
  redirect_to new_finance_order_url(order_id: @order.id), alert: t('finance.balancing.close.alert', message: error.message)
end

#close_directObject

Close the order directly, without automaticly updating ordergroups account balances


80
81
82
83
84
85
86
# File 'app/controllers/finance/balancing_controller.rb', line 80

def close_direct
  @order = Order.find(params[:id])
  @order.close_direct!(@current_user)
  redirect_to finance_order_index_url, notice: t('finance.balancing.close_direct.notice')
rescue => error
  redirect_to finance_order_index_url, alert: t('finance.balancing.close_direct.alert', message: error.message)
end

#confirmObject

before the order will booked, a view lists all Ordergroups and its order_prices


64
65
66
# File 'app/controllers/finance/balancing_controller.rb', line 64

def confirm
  @order = Order.find(params[:id])
end

#edit_noteObject


49
50
51
52
# File 'app/controllers/finance/balancing_controller.rb', line 49

def edit_note
  @order = Order.find(params[:id])
  render :layout => false
end

#indexObject


4
5
6
# File 'app/controllers/finance/balancing_controller.rb', line 4

def index
  @orders = Order.finished.page(params[:page]).per(@per_page).order('ends DESC')
end

#newObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/finance/balancing_controller.rb', line 8

def new
  @order = Order.find(params[:order_id])
  flash.now.alert = t('finance.balancing.new.alert') if @order.closed?
  @comments = @order.comments

  @articles = @order.order_articles.ordered_or_member.includes(:article, :article_price,
                                                     group_order_articles: {group_order: :ordergroup})

  sort_param = params['sort'] || 'name'
  @articles = case sort_param
                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
                  @articles
              end

  render layout: false if request.xhr?
end

#new_on_order_article_createObject

See publish/subscribe design pattern in /doc.


33
34
35
36
37
# File 'app/controllers/finance/balancing_controller.rb', line 33

def new_on_order_article_create # See publish/subscribe design pattern in /doc.
  @order_article = OrderArticle.find(params[:order_article_id])
  
  render :layout => false
end

#new_on_order_article_updateObject

See publish/subscribe design pattern in /doc.


39
40
41
42
43
# File 'app/controllers/finance/balancing_controller.rb', line 39

def new_on_order_article_update # See publish/subscribe design pattern in /doc.
  @order_article = OrderArticle.find(params[:order_article_id])
  
  render :layout => false
end

#update_noteObject


54
55
56
57
58
59
60
61
# File 'app/controllers/finance/balancing_controller.rb', line 54

def update_note
  @order = Order.find(params[:id])
  if @order.update_attributes(params[:order])
    render :layout => false
  else
    render :action => :edit_note, :layout => false
  end
end

#update_summaryObject


45
46
47
# File 'app/controllers/finance/balancing_controller.rb', line 45

def update_summary
  @order = Order.find(params[:id])
end