Sha256: 4a257785b70440808ec9cccf3d8b5dffdc195fbc793e8064d5a0f860f82fd8d6

Contents?: true

Size: 1.95 KB

Versions: 3

Compression:

Stored size: 1.95 KB

Contents

class AccountsController < HasAccountsController
  # Scopes
  has_scope :by_date, :using => [:from, :to], :default => proc { |c| c.session[:has_scope] }
  has_scope :by_text

  has_scope :page, :only => :index

  def index
    @accounts = collection.includes(:account_type).includes(:credit_bookings, :credit_bookings).page(params[:page]).per_page(100)
  end

  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
    @saldo = @account.saldo(@carry_booking, false)

    if @account.profit_account? && params[:by_date] && params[:by_date][:to]
      @saldo -= @account.saldo(Date.parse(params[:by_date][:from]), false)
    end

    show!
  end

  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

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

  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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
has_accounts_engine-3.0.0.beta10 app/controllers/accounts_controller.rb
has_accounts_engine-3.0.0.beta9 app/controllers/accounts_controller.rb
has_accounts_engine-3.0.0.beta8 app/controllers/accounts_controller.rb