Class: AccountsController
- Inherits:
-
HasAccountsController
- Object
- HasAccountsController
- AccountsController
- Defined in:
- app/controllers/accounts_controller.rb
Instance Method Summary collapse
- #csv_bookings ⇒ Object
- #edit_bookings ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #update_bookings ⇒ Object
Instance Method Details
#csv_bookings ⇒ Object
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).by_account(@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_bookings ⇒ Object
35 36 37 38 |
# File 'app/controllers/accounts_controller.rb', line 35 def edit_bookings @account = Account.find(params[:id]) @bookings = apply_scopes(Booking).by_account(@account) end |
#index ⇒ Object
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 |
#show ⇒ Object
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).by_account(@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_bookings ⇒ Object
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 = Account.find(params[:id]) redirect_to account end |