Class: AccountsController

Inherits:
HasAccountsController
  • Object
show all
Defined in:
app/controllers/accounts_controller.rb

Instance Method Summary collapse

Instance Method Details

#csv_bookingsObject



29
30
31
32
33
# File 'app/controllers/accounts_controller.rb', line 29

def csv_bookings
  @account = Account.find(params[:id])
  @bookings = apply_scopes(Booking).(@account)
  send_csv @bookings, :only => [:value_date, :title, :comments, :amount, 'credit_account.code', 'debit_account.code'], :filename => "%s-%s.csv" % [@account.code, @account.title]
end

#edit_bookingsObject



35
36
37
38
# File 'app/controllers/accounts_controller.rb', line 35

def edit_bookings
  @account = Account.find(params[:id])
  @bookings = apply_scopes(Booking).(@account)
end

#indexObject



8
9
10
# File 'app/controllers/accounts_controller.rb', line 8

def index
  @accounts = apply_scopes(Account).includes(:account_type).includes(:credit_bookings, :credit_bookings)
end

#showObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/accounts_controller.rb', line 12

def show
  @account = Account.find(params[:id])
  @bookings = apply_scopes(Booking).includes(:debit_account => :account_type, :credit_account => :account_type).(@account)
  @bookings = @bookings.page(params[:page]) || 1

  if params[:only_credit_bookings]
    @bookings = @bookings.where(:credit_account_id => @account.id)
  end
  if params[:only_debit_bookings]
    @bookings = @bookings.where(:debit_account_id => @account.id)
  end
  @bookings = @bookings
  @carry_booking = @bookings.all.first

  show!
end

#update_bookingsObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/accounts_controller.rb', line 40

def update_bookings
  bookings = params[:bookings]

  bookings.each do |id, attributes|
    attributes.merge!({:credit_account_id => Account.find_by_code(attributes[:credit_account_code]).id})
    attributes.merge!({:debit_account_id => Account.find_by_code(attributes[:debit_account_code]).id})
    Booking.find(id).update_attributes(attributes)
  end

   = Account.find(params[:id])
  redirect_to 
end