From 8fba6026c9afe9cf8941b8765a89a121e728eb75 Mon Sep 17 00:00:00 2001 From: fabioelia Date: Mon, 21 Jan 2013 20:03:48 -0500 Subject: [PATCH] Added date filtering to accounts --- app/models/plutus/account.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/plutus/account.rb b/app/models/plutus/account.rb index fdf9297c..c0dc7f95 100644 --- a/app/models/plutus/account.rb +++ b/app/models/plutus/account.rb @@ -31,9 +31,10 @@ module Plutus # @author Michael Bulat class Account < ActiveRecord::Base attr_accessible :name, :contra - - has_many :credit_amounts - has_many :debit_amounts + attr_accessor :start_date, :end_date + + has_many :credit_amounts, :include => :transaction, :conditions => proc { "plutus_transactions.date >= '#{start_date || "1900-01-01"}' AND plutus_transactions.date <= #{end_date || ( Date.today + 15.days ).to_s}" } + has_many :debit_amounts, :include => :transaction, :conditions => proc { "plutus_transactions.date >= '#{start_date || "1900-01-01"}' AND plutus_transactions.date <= #{end_date || ( Date.today + 15.days ).to_s}" has_many :credit_transactions, :through => :credit_amounts, :source => :transaction has_many :debit_transactions, :through => :debit_amounts, :source => :transaction belongs_to :accountable, :polymorphic => true