def balance(hash={})
      if hash[:from_date] && hash[:to_date]
        from_date = hash[:from_date].kind_of?(Date) ? hash[:from_date] : Date.parse(hash[:from_date])
        to_date = hash[:to_date].kind_of?(Date) ? hash[:to_date] : Date.parse(hash[:to_date])
        includes(:entry).where('borutus_entries.date' => from_date..to_date).sum(:amount)
      else
        sum(:amount)
      end
    end
def balance(hash={})
      if hash[:from_date] && hash[:to_date]
        from_date = hash[:from_date].kind_of?(Date) ? hash[:from_date] : Date.parse(hash[:from_date])
        to_date = hash[:to_date].kind_of?(Date) ? hash[:to_date] : Date.parse(hash[:to_date])
        includes(:entry).where('borutus_entries.date' => from_date..to_date).sum(:amount)
      else
        sum(:amount)
      end
    end
Returns a sum of the referenced Amount objects.

 Takes a hash specifying :from_date and :to_date for calculating balances during periods.
 :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects

 This runs the summation in the database, so it only works on persisted records.

 @example
   credit_amounts.balance({:from_date => "2000-01-01", :to_date => Date.today})
   => #<BigDecimal:103259bb8,'0.2E4',4(12)>

 @return [BigDecimal] The decimal value balance