Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mbulat/plutus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: fabioelia/plutus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 15 commits
  • 13 files changed
  • 3 contributors

Commits on Oct 25, 2012

  1. account can acts as polymorphic model

    Sharipov Ruslan committed Oct 25, 2012

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c9980a6 View commit details

Commits on Oct 26, 2012

  1. Copy the full SHA
    4c22a55 View commit details

Commits on Jan 22, 2013

  1. Copy the full SHA
    8fba602 View commit details

Commits on Jan 25, 2013

  1. Fix date issue

    fabioelia committed Jan 25, 2013
    Copy the full SHA
    d0c7699 View commit details
  2. Bug in dates

    fabioelia committed Jan 25, 2013
    Copy the full SHA
    a18267e View commit details
  3. Final fix =)

    fabioelia committed Jan 25, 2013
    Copy the full SHA
    b66f56a View commit details
  4. Global date check

    fabioelia committed Jan 25, 2013
    Copy the full SHA
    9cefb18 View commit details

Commits on Jan 26, 2013

  1. Trialbalance by date

    fabioelia committed Jan 26, 2013
    Copy the full SHA
    e6930ae View commit details
  2. Copy the full SHA
    3399dd7 View commit details
  3. Fix for yesturdays bad code

    fabioelia committed Jan 26, 2013
    Copy the full SHA
    fb39ce5 View commit details
  4. Copy the full SHA
    cde2a8b View commit details
  5. Dates dates dates =(

    fabioelia committed Jan 26, 2013
    Copy the full SHA
    1da65de View commit details
  6. Fix date nil

    fabioelia committed Jan 26, 2013
    Copy the full SHA
    b93333e View commit details
  7. Copy the full SHA
    67d7991 View commit details

Commits on Feb 4, 2013

  1. missing )

    fabioelia committed Feb 4, 2013
    Copy the full SHA
    58916da View commit details
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -2,4 +2,5 @@ test.sqlite3
spec/debug.log
.DS_Store
.yardoc/
pkg/
pkg/
*~
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
plutus (0.7.1)
plutus (0.7.2)
rails (~> 3.1)

GEM
@@ -53,7 +53,7 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
mime-types (1.19)
multi_json (1.3.5)
polyglot (0.3.3)
rack (1.3.6)
@@ -104,7 +104,7 @@ GEM
sqlite3 (1.3.6)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
treetop (1.4.11)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
21 changes: 18 additions & 3 deletions app/models/plutus/account.rb
Original file line number Diff line number Diff line change
@@ -31,15 +31,28 @@ module Plutus
# @author Michael Bulat
class Account < ActiveRecord::Base
attr_accessible :name, :contra

has_many :credit_amounts
has_many :debit_amounts
has_many :credit_transactions, :through => :credit_amounts, :source => :transaction
has_many :debit_transactions, :through => :debit_amounts, :source => :transaction
belongs_to :accountable, :polymorphic => true

validates_presence_of :type, :name
validates_uniqueness_of :name

def credits_by_date(start_date = "1900-01-01", end_date = Date.today + 15.days)
end_date = Date.today + 15.days if end_date.nil?
start_date = "1900-01-01" if start_date.nil?
credit_amounts.includes(:transaction).where("plutus_transactions.date >= '#{start_date}' AND DATE( plutus_transactions.date) <= '#{end_date.to_s}'")
end

def debits_by_date(start_date = "1900-01-01", end_date = Date.today + 15.days)
end_date = Date.today + 15.days if end_date.nil?
start_date = "1900-01-01" if start_date.nil?
debit_amounts.includes(:transaction).where("plutus_transactions.date >= '#{start_date}' AND DATE( plutus_transactions.date ) <= '#{end_date.to_s}'")
end

# The trial balance of all accounts in the system. This should always equal zero,
# otherwise there is an error in the system.
#
@@ -48,9 +61,11 @@ class Account < ActiveRecord::Base
# => 0
#
# @return [BigDecimal] The decimal value balance of all accounts
def self.trial_balance
unless self.new.class == Account
def self.trial_balance(startDate = nil, endDate = nil)
if self.new.class != Account
raise(NoMethodError, "undefined method 'trial_balance'")
elsif startDate || endDate
Asset.balance( startDate, endDate ) - (Liability.balance( startDate, endDate ) + Equity.balance( startDate, endDate ) + Revenue.balance( startDate, endDate ) - Expense.balance( startDate, endDate ))
else
Asset.balance - (Liability.balance + Equity.balance + Revenue.balance - Expense.balance)
end
46 changes: 34 additions & 12 deletions app/models/plutus/asset.rb
Original file line number Diff line number Diff line change
@@ -16,11 +16,19 @@ class Asset < Account
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
#
# @return [BigDecimal] The decimal value credit balance
def credits_balance
def credits_balance(start_date = nil, end_date = nil )
credits_balance = BigDecimal.new('0')
credit_amounts.each do |credit_amount|
credits_balance += credit_amount.amount
if start_date || end_date
credits_by_date(start_date, end_date).each do |credit_amount|
credits_balance += credit_amount.amount
end
else
credit_amounts.each do |credit_amount|
credits_balance += credit_amount.amount
end
end


return credits_balance
end

@@ -31,10 +39,16 @@ def credits_balance
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
#
# @return [BigDecimal] The decimal value credit balance
def debits_balance
def debits_balance(start_date = nil, end_date = nil )
debits_balance = BigDecimal.new('0')
debit_amounts.each do |debit_amount|
debits_balance += debit_amount.amount
if start_date || end_date
debits_by_date(start_date, end_date).each do |debit_amount|
debits_balance += debit_amount.amount
end
else
debit_amounts.each do |debit_amount|
debits_balance += debit_amount.amount
end
end
return debits_balance
end
@@ -49,11 +63,15 @@ def debits_balance
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
#
# @return [BigDecimal] The decimal value balance
def balance
def balance(start_date = nil, end_date = nil)
unless contra
debits_balance - credits_balance
(start_date.nil? && end_date.nil?) ?
debits_balance - credits_balance :
debits_balance(start_date,end_date) - credits_balance(start_date,end_date)
else
credits_balance - debits_balance
(start_date.nil? && end_date.nil?) ?
credits_balance - debits_balance :
credits_balance(start_date,end_date) - debits_balance(start_date,end_date)
end
end

@@ -67,14 +85,18 @@ def balance
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
#
# @return [BigDecimal] The decimal value balance
def self.balance
def self.balance( start_date = nil, end_date = nil )
accounts_balance = BigDecimal.new('0')
accounts = self.find(:all)
accounts.each do |asset|
unless asset.contra
accounts_balance += asset.balance
(start_date.nil? && end_date.nil?) ?
accounts_balance += asset.balance :
accounts_balance += asset.balance( start_date, end_date )
else
accounts_balance -= asset.balance
(start_date.nil? && end_date.nil?) ?
accounts_balance -= asset.balance :
accounts_balance -= asset.balance( start_date, end_date )
end
end
accounts_balance
48 changes: 36 additions & 12 deletions app/models/plutus/equity.rb
Original file line number Diff line number Diff line change
@@ -16,10 +16,16 @@ class Equity < Account
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
#
# @return [BigDecimal] The decimal value credit balance
def credits_balance
def credits_balance( start_date = nil, end_date = nil )
credits_balance = BigDecimal.new('0')
credit_amounts.each do |credit_amount|
credits_balance = credits_balance + credit_amount.amount
if start_date || end_date
credits_by_date( start_date, end_date ).each do |credit_amount|
credits_balance = credits_balance + credit_amount.amount
end
else
credit_amounts.each do |credit_amount|
credits_balance = credits_balance + credit_amount.amount
end
end
return credits_balance
end
@@ -31,10 +37,16 @@ def credits_balance
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
#
# @return [BigDecimal] The decimal value credit balance
def debits_balance
def debits_balance( start_date = nil, end_date = nil )
debits_balance = BigDecimal.new('0')
debit_amounts.each do |debit_amount|
debits_balance = debits_balance + debit_amount.amount
if start_date || end_date
debits_by_date( start_date, end_date ).each do |debit_amount|
debits_balance = debits_balance + debit_amount.amount
end
else
debit_amounts.each do |debit_amount|
debits_balance = debits_balance + debit_amount.amount
end
end
return debits_balance
end
@@ -50,11 +62,15 @@ def debits_balance
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
#
# @return [BigDecimal] The decimal value balance
def balance
def balance(start_date = nil, end_date = nil)
unless contra
credits_balance - debits_balance
(start_date.nil? && end_date.nil?) ?
credits_balance - debits_balance :
credits_balance - debits_balance( start_date, end_date )
else
debits_balance - credits_balance
(start_date.nil? && end_date.nil?) ?
debits_balance - credits_balance :
debits_balance - credits_balance( start_date, end_date )
end
end

@@ -68,14 +84,22 @@ def balance
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
#
# @return [BigDecimal] The decimal value balance
def self.balance
def self.balance( start_date = nil, end_date = nil )
accounts_balance = BigDecimal.new('0')
accounts = self.find(:all)
accounts.each do |equity|

unless equity.contra
accounts_balance += equity.balance
(start_date.nil? && end_date.nil?) ?
accounts_balance += equity.balance :
accounts_balance += equity.balance( start_date, end_date )

else
accounts_balance -= equity.balance

(start_date.nil? && end_date.nil?) ?
accounts_balance -= equity.balance :
accounts_balance -= equity.balance( start_date, end_date )

end
end
accounts_balance
44 changes: 32 additions & 12 deletions app/models/plutus/expense.rb
Original file line number Diff line number Diff line change
@@ -16,10 +16,16 @@ class Expense < Account
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
#
# @return [BigDecimal] The decimal value credit balance
def credits_balance
def credits_balance( start_date = nil, end_date = nil )
credits_balance = BigDecimal.new('0')
credit_amounts.each do |credit_amount|
credits_balance = credits_balance + credit_amount.amount
if start_date || end_date
credits_by_date( start_date, end_date ).each do |credit_amount|
credits_balance = credits_balance + credit_amount.amount
end
else
credit_amounts.each do |credit_amount|
credits_balance = credits_balance + credit_amount.amount
end
end
return credits_balance
end
@@ -31,10 +37,16 @@ def credits_balance
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
#
# @return [BigDecimal] The decimal value credit balance
def debits_balance
def debits_balance( start_date = nil, end_date = nil )
debits_balance = BigDecimal.new('0')
debit_amounts.each do |debit_amount|
debits_balance = debits_balance + debit_amount.amount
if start_date || end_date
debits_by_date( start_date, end_date ).each do |debit_amount|
debits_balance = debits_balance + debit_amount.amount
end
else
debit_amounts.each do |debit_amount|
debits_balance = debits_balance + debit_amount.amount
end
end
return debits_balance
end
@@ -49,11 +61,15 @@ def debits_balance
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
#
# @return [BigDecimal] The decimal value balance
def balance
def balance( start_date = nil, end_date = nil )
unless contra
debits_balance - credits_balance
(start_date.nil? && end_date.nil?) ?
debits_balance - credits_balance :
debits_balance( start_date, end_date ) - credits_balance( start_date, end_date )
else
credits_balance - debits_balance
(start_date.nil? && end_date.nil?) ?
credits_balance - debits_balance :
credits_balance( start_date, end_date ) - debits_balance( start_date, end_date )
end
end

@@ -67,14 +83,18 @@ def balance
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
#
# @return [BigDecimal] The decimal value balance
def self.balance
def self.balance( start_date = nil, end_date = nil )
accounts_balance = BigDecimal.new('0')
accounts = self.find(:all)
accounts.each do |expense|
unless expense.contra
accounts_balance += expense.balance
(start_date.nil? && end_date.nil?) ?
accounts_balance += expense.balance :
accounts_balance += expense.balance( start_date, end_date )
else
accounts_balance -= expense.balance
(start_date.nil? && end_date.nil?) ?
accounts_balance -= expense.balance :
accounts_balance -= expense.balance( start_date, end_date )
end
end
accounts_balance
Loading