bookkeeping 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +24 -0
- data/app/assets/javascripts/bookkeeping/application.js +13 -0
- data/app/assets/stylesheets/bookkeeping/application.css +15 -0
- data/app/controllers/bookkeeping/application_controller.rb +4 -0
- data/app/helpers/bookkeeping/application_helper.rb +4 -0
- data/app/models/bookkeeping/account.rb +90 -0
- data/app/models/bookkeeping/amount.rb +26 -0
- data/app/models/bookkeeping/asset_account.rb +26 -0
- data/app/models/bookkeeping/credit_amount.rb +16 -0
- data/app/models/bookkeeping/debit_amount.rb +16 -0
- data/app/models/bookkeeping/entry.rb +63 -0
- data/app/models/bookkeeping/equity_account.rb +26 -0
- data/app/models/bookkeeping/expense_account.rb +26 -0
- data/app/models/bookkeeping/extension.rb +29 -0
- data/app/models/bookkeeping/income_account.rb +26 -0
- data/app/models/bookkeeping/liability_account.rb +26 -0
- data/app/views/layouts/bookkeeping/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/lib/bookkeeping.rb +5 -0
- data/lib/bookkeeping/dsl.rb +46 -0
- data/lib/bookkeeping/engine.rb +14 -0
- data/lib/bookkeeping/version.rb +3 -0
- data/lib/generators/bookkeeping/bookkeeping_generator.rb +15 -0
- data/lib/generators/bookkeeping/templates/migration.rb +44 -0
- data/lib/tasks/bookkeeping_tasks.rake +4 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1546ea85dd27e3e962ce4f11e58a6e7e92c8c4e6
|
4
|
+
data.tar.gz: 315ead36edba9216723a54a4ab01411cabe74aac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 749270c9df89e09b0b2673c914c80a39e28a9a192e85a6b497ad9d3344a03fbaf93201230e313568d4a9f1f8a8809bc37167926d67c3d605ac21fed042018703
|
7
|
+
data.tar.gz: 5bd73eb78b84fd877a9cfada0a2467814abf0daf35cb442b99497302db2427c2b4658315ee170fbf596029b6eb0bd9d58cf7801379aa98fb2bf171abef054c12
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Alexander
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Bookkeeping'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
24
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_accounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# name :string
|
7
|
+
# type :string
|
8
|
+
# overdraft_enabled :boolean default(TRUE), not null
|
9
|
+
# accountable_id :integer
|
10
|
+
# accountable_type :string
|
11
|
+
# created_at :datetime
|
12
|
+
# updated_at :datetime
|
13
|
+
#
|
14
|
+
|
15
|
+
module Bookkeeping
|
16
|
+
class Account < ActiveRecord::Base
|
17
|
+
|
18
|
+
# Associations
|
19
|
+
belongs_to :accountable, polymorphic: true
|
20
|
+
has_many :debit_amounts, dependent: :destroy
|
21
|
+
has_many :credit_amounts, dependent: :destroy
|
22
|
+
|
23
|
+
# Validations
|
24
|
+
validates :name, presence: true
|
25
|
+
validate :prevent_overdraft, unless: :overdraft_enabled?
|
26
|
+
|
27
|
+
class NotFound < StandardError; end
|
28
|
+
class BadKind < StandardError; end
|
29
|
+
|
30
|
+
class << self
|
31
|
+
|
32
|
+
def by_kind(kind)
|
33
|
+
Bookkeeping.const_get "#{kind.to_s.capitalize}Account"
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](name, kind = nil, overdraft = true)
|
37
|
+
|
38
|
+
unless account = find_by(name: name)
|
39
|
+
raise NotFound, "account #{name} not found. Provide kind to create a new one" unless kind
|
40
|
+
|
41
|
+
raise BadKind if kind && !class_exists?("Bookkeeping::#{kind.to_s.classify}Account")
|
42
|
+
|
43
|
+
return by_kind(kind).create!(name: name.to_s, overdraft_enabled: overdraft)
|
44
|
+
end
|
45
|
+
|
46
|
+
raise BadKind if kind && by_kind(kind) != account.class
|
47
|
+
|
48
|
+
account.update_attributes! overdraft_enabled: overdraft if overdraft != account.overdraft_enabled?
|
49
|
+
|
50
|
+
return account
|
51
|
+
end
|
52
|
+
|
53
|
+
def total_balance
|
54
|
+
raise(NoMethodError, "undefined method 'total_balance'") unless self == Bookkeeping::Account
|
55
|
+
|
56
|
+
Bookkeeping::AssetAccount.balance + Bookkeeping::ExpenseAccount.balance - Bookkeeping::LiabilityAccount.balance - Bookkeeping::EquityAccount.balance - Bookkeeping::IncomeAccount.balance
|
57
|
+
end
|
58
|
+
|
59
|
+
def balanced?
|
60
|
+
total_balance == 0
|
61
|
+
end
|
62
|
+
|
63
|
+
def class_exists?(class_name)
|
64
|
+
klass = Module.const_get(class_name)
|
65
|
+
return klass.is_a?(Class)
|
66
|
+
rescue NameError
|
67
|
+
return false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
private_class_method :class_exists?
|
71
|
+
|
72
|
+
def debits_balance
|
73
|
+
debit_amounts.sum(:amount)
|
74
|
+
end
|
75
|
+
|
76
|
+
def credits_balance
|
77
|
+
credit_amounts.sum(:amount)
|
78
|
+
end
|
79
|
+
|
80
|
+
def overdraft?
|
81
|
+
balance < 0
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def prevent_overdraft
|
87
|
+
errors.add(:balance, :overdraft) if balance < 0
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_amounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# type :string
|
7
|
+
# is_debit :boolean default(TRUE), not null
|
8
|
+
# account_id :integer
|
9
|
+
# entry_id :integer
|
10
|
+
# amount :decimal(20, 2) default(0.0)
|
11
|
+
#
|
12
|
+
|
13
|
+
module Bookkeeping
|
14
|
+
class Amount < ActiveRecord::Base
|
15
|
+
|
16
|
+
belongs_to :entry, class_name: "Bookkeeping::Entry"
|
17
|
+
belongs_to :account, class_name: "Bookkeeping::Account"
|
18
|
+
|
19
|
+
validates :type, :amount, presence: true
|
20
|
+
|
21
|
+
def account_name=(name)
|
22
|
+
self.account = Account.find_by_name!(name)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_accounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# name :string
|
7
|
+
# type :string
|
8
|
+
# overdraft_enabled :boolean default(TRUE), not null
|
9
|
+
# accountable_id :integer
|
10
|
+
# accountable_type :string
|
11
|
+
# created_at :datetime
|
12
|
+
# updated_at :datetime
|
13
|
+
#
|
14
|
+
|
15
|
+
module Bookkeeping
|
16
|
+
class AssetAccount < Account
|
17
|
+
|
18
|
+
def self.balance
|
19
|
+
all.select(:id).to_a.sum(&:balance)
|
20
|
+
end
|
21
|
+
|
22
|
+
def balance
|
23
|
+
debits_balance - credits_balance
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_amounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# type :string
|
7
|
+
# is_debit :boolean default(TRUE), not null
|
8
|
+
# account_id :integer
|
9
|
+
# entry_id :integer
|
10
|
+
# amount :decimal(20, 2) default(0.0)
|
11
|
+
#
|
12
|
+
|
13
|
+
module Bookkeeping
|
14
|
+
class CreditAmount < Amount
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_amounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# type :string
|
7
|
+
# is_debit :boolean default(TRUE), not null
|
8
|
+
# account_id :integer
|
9
|
+
# entry_id :integer
|
10
|
+
# amount :decimal(20, 2) default(0.0)
|
11
|
+
#
|
12
|
+
|
13
|
+
module Bookkeeping
|
14
|
+
class DebitAmount < Amount
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_entries
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# description :string
|
7
|
+
# transactionable_id :integer
|
8
|
+
# transactionable_type :string
|
9
|
+
# rollback_entry_id :integer
|
10
|
+
# created_at :datetime
|
11
|
+
# updated_at :datetime
|
12
|
+
#
|
13
|
+
|
14
|
+
module Bookkeeping
|
15
|
+
class Entry < ActiveRecord::Base
|
16
|
+
|
17
|
+
belongs_to :transactionable, polymorphic: true
|
18
|
+
has_many :amounts, dependent: :destroy
|
19
|
+
has_many :debit_amounts, class_name: "Bookkeeping::DebitAmount"
|
20
|
+
has_many :credit_amounts, class_name: "Bookkeeping::CreditAmount"
|
21
|
+
|
22
|
+
validates :transactionable, :description, presence: true
|
23
|
+
validate :has_credit_amounts?
|
24
|
+
validate :has_debit_amounts?
|
25
|
+
validate :amounts_cancel?
|
26
|
+
|
27
|
+
def self.prepare(options = {}, &block)
|
28
|
+
new(options) do |entry|
|
29
|
+
dsl = Bookkeeping::DSL.new(entry)
|
30
|
+
dsl.instance_eval &block
|
31
|
+
dsl.build
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# TODO: not work
|
36
|
+
def rollback!(ref = nil)
|
37
|
+
tran = self
|
38
|
+
res = self.class.prepare do
|
39
|
+
tran.debit_amounts.each { |di| debit(di.account, -di.amount) }
|
40
|
+
tran.credit_amounts.each { |ci| credit(ci.account, -ci.amount) }
|
41
|
+
transactionable(ref || tran)
|
42
|
+
description("Rollback of #{tran.description}")
|
43
|
+
end
|
44
|
+
self.rollback_transaction_id = res.id
|
45
|
+
save!
|
46
|
+
res
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def has_credit_amounts?
|
52
|
+
errors[:base] << "Entry must have at least one credit amount" if self.credit_amounts.blank?
|
53
|
+
end
|
54
|
+
|
55
|
+
def has_debit_amounts?
|
56
|
+
errors[:base] << "Entry must have at least one debit amount" if self.debit_amounts.blank?
|
57
|
+
end
|
58
|
+
|
59
|
+
def amounts_cancel?
|
60
|
+
errors[:base] << "The credit and debit amounts are not equal" if credit_amounts.to_a.sum(&:amount) != debit_amounts.to_a.sum(&:amount)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_accounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# name :string
|
7
|
+
# type :string
|
8
|
+
# overdraft_enabled :boolean default(TRUE), not null
|
9
|
+
# accountable_id :integer
|
10
|
+
# accountable_type :string
|
11
|
+
# created_at :datetime
|
12
|
+
# updated_at :datetime
|
13
|
+
#
|
14
|
+
|
15
|
+
module Bookkeeping
|
16
|
+
class EquityAccount < Account
|
17
|
+
|
18
|
+
def self.balance
|
19
|
+
all.select(:id).to_a.sum(&:balance)
|
20
|
+
end
|
21
|
+
|
22
|
+
def balance
|
23
|
+
credits_balance - debits_balance
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_accounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# name :string
|
7
|
+
# type :string
|
8
|
+
# overdraft_enabled :boolean default(TRUE), not null
|
9
|
+
# accountable_id :integer
|
10
|
+
# accountable_type :string
|
11
|
+
# created_at :datetime
|
12
|
+
# updated_at :datetime
|
13
|
+
#
|
14
|
+
|
15
|
+
module Bookkeeping
|
16
|
+
class ExpenseAccount < Account
|
17
|
+
|
18
|
+
def self.balance
|
19
|
+
all.select(:id).to_a.sum(&:balance)
|
20
|
+
end
|
21
|
+
|
22
|
+
def balance
|
23
|
+
debits_balance - credits_balance
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Bookkeeping
|
2
|
+
module Extension
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ProxyMethods
|
6
|
+
|
7
|
+
[:asset, :expense, :liability, :equity, :income].each do |kind|
|
8
|
+
define_method kind do |name, overdraft = true|
|
9
|
+
define_method name do
|
10
|
+
self[name, kind, overdraft]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
|
19
|
+
def has_accounts(&block)
|
20
|
+
has_many :accounts, as: :accountable, class_name: 'Bookkeeping::Account', inverse_of: :accountable do
|
21
|
+
extend ProxyMethods
|
22
|
+
|
23
|
+
class_eval(&block) if block
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_accounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# name :string
|
7
|
+
# type :string
|
8
|
+
# overdraft_enabled :boolean default(TRUE), not null
|
9
|
+
# accountable_id :integer
|
10
|
+
# accountable_type :string
|
11
|
+
# created_at :datetime
|
12
|
+
# updated_at :datetime
|
13
|
+
#
|
14
|
+
|
15
|
+
module Bookkeeping
|
16
|
+
class IncomeAccount < Account
|
17
|
+
|
18
|
+
def self.balance
|
19
|
+
all.select(:id).to_a.sum(&:balance)
|
20
|
+
end
|
21
|
+
|
22
|
+
def balance
|
23
|
+
credits_balance - debits_balance
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: bookkeeping_accounts
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# name :string
|
7
|
+
# type :string
|
8
|
+
# overdraft_enabled :boolean default(TRUE), not null
|
9
|
+
# accountable_id :integer
|
10
|
+
# accountable_type :string
|
11
|
+
# created_at :datetime
|
12
|
+
# updated_at :datetime
|
13
|
+
#
|
14
|
+
|
15
|
+
module Bookkeeping
|
16
|
+
class LiabilityAccount < Account
|
17
|
+
|
18
|
+
def self.balance
|
19
|
+
all.select(:id).to_a.sum(&:balance)
|
20
|
+
end
|
21
|
+
|
22
|
+
def balance
|
23
|
+
credits_balance - debits_balance
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Bookkeeping</title>
|
5
|
+
<%= stylesheet_link_tag "bookkeeping/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "bookkeeping/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
data/lib/bookkeeping.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Bookkeeping
|
2
|
+
class DSL
|
3
|
+
attr_reader :debits, :credits, :description, :reference
|
4
|
+
attr_accessor :entry
|
5
|
+
|
6
|
+
def initialize(entry)
|
7
|
+
@debits ||= {}
|
8
|
+
@credits ||= {}
|
9
|
+
@entry = entry
|
10
|
+
end
|
11
|
+
|
12
|
+
def debit(account, amount)
|
13
|
+
@debits ||= {}
|
14
|
+
@debits[account] ||= 0
|
15
|
+
@debits[account] += amount
|
16
|
+
end
|
17
|
+
|
18
|
+
def credit(account, amount)
|
19
|
+
@credits ||= {}
|
20
|
+
@credits[account] ||= 0
|
21
|
+
@credits[account] += amount
|
22
|
+
end
|
23
|
+
|
24
|
+
def description(description)
|
25
|
+
@description = description
|
26
|
+
end
|
27
|
+
|
28
|
+
def transactionable(transactionable)
|
29
|
+
@transactionable = transactionable
|
30
|
+
end
|
31
|
+
|
32
|
+
def build
|
33
|
+
entry.transactionable = @transactionable || entry.transactionable
|
34
|
+
entry.description = @description || entry.description
|
35
|
+
|
36
|
+
debits.each do |account, amount|
|
37
|
+
entry.debit_amounts.build(account: account, amount: amount)
|
38
|
+
end
|
39
|
+
|
40
|
+
credits.each do |account, amount|
|
41
|
+
entry.credit_amounts.build(account: account, amount: amount)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Bookkeeping
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Bookkeeping
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :rspec
|
7
|
+
end
|
8
|
+
|
9
|
+
config.generators do |g|
|
10
|
+
g.test_framework :rspec, fixture: false
|
11
|
+
g.factory_girl dir: "spec/factories"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class BookkeepingGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def self.next_migration_number(path)
|
9
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_migration_file
|
13
|
+
migration_template 'migration.rb', 'db/migrate/create_bookkeeping_tables.rb'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class CreateBookkeepingTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :bookkeeping_accounts do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :type
|
6
|
+
t.boolean :overdraft_enabled, null: false, default: :true
|
7
|
+
t.references :accountable, polymorphic: true
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :bookkeeping_accounts, :accountable_id
|
12
|
+
add_index :bookkeeping_accounts, :accountable_type
|
13
|
+
|
14
|
+
create_table :bookkeeping_entries do |t|
|
15
|
+
t.string :description
|
16
|
+
t.references :transactionable, polymorphic: true
|
17
|
+
t.integer :rollback_entry_id
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :bookkeeping_entries, :transactionable_id
|
22
|
+
add_index :bookkeeping_entries, :transactionable_type
|
23
|
+
|
24
|
+
|
25
|
+
create_table :bookkeeping_amounts do |t|
|
26
|
+
t.string :type
|
27
|
+
t.boolean :is_debit, default: true, null: false
|
28
|
+
t.integer :account_id
|
29
|
+
t.integer :entry_id
|
30
|
+
t.decimal :amount, precision: 20, scale: 2, default: 0
|
31
|
+
end
|
32
|
+
|
33
|
+
add_index :bookkeeping_amounts, :account_id
|
34
|
+
add_index :bookkeeping_amounts, :entry_id
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.down
|
39
|
+
drop_table :bookkeeping_accounts
|
40
|
+
drop_table :bookkeeping_entries
|
41
|
+
drop_table :bookkeeping_amounts
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bookkeeping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Shlinchak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: factory_girl_rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: The goal of this gem is to build accounting (bookkeeping) system for
|
112
|
+
Rails projects using double entry theory.
|
113
|
+
email:
|
114
|
+
- minotep@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- MIT-LICENSE
|
120
|
+
- Rakefile
|
121
|
+
- app/assets/javascripts/bookkeeping/application.js
|
122
|
+
- app/assets/stylesheets/bookkeeping/application.css
|
123
|
+
- app/controllers/bookkeeping/application_controller.rb
|
124
|
+
- app/helpers/bookkeeping/application_helper.rb
|
125
|
+
- app/models/bookkeeping/account.rb
|
126
|
+
- app/models/bookkeeping/amount.rb
|
127
|
+
- app/models/bookkeeping/asset_account.rb
|
128
|
+
- app/models/bookkeeping/credit_amount.rb
|
129
|
+
- app/models/bookkeeping/debit_amount.rb
|
130
|
+
- app/models/bookkeeping/entry.rb
|
131
|
+
- app/models/bookkeeping/equity_account.rb
|
132
|
+
- app/models/bookkeeping/expense_account.rb
|
133
|
+
- app/models/bookkeeping/extension.rb
|
134
|
+
- app/models/bookkeeping/income_account.rb
|
135
|
+
- app/models/bookkeeping/liability_account.rb
|
136
|
+
- app/views/layouts/bookkeeping/application.html.erb
|
137
|
+
- config/routes.rb
|
138
|
+
- lib/bookkeeping.rb
|
139
|
+
- lib/bookkeeping/dsl.rb
|
140
|
+
- lib/bookkeeping/engine.rb
|
141
|
+
- lib/bookkeeping/version.rb
|
142
|
+
- lib/generators/bookkeeping/bookkeeping_generator.rb
|
143
|
+
- lib/generators/bookkeeping/templates/migration.rb
|
144
|
+
- lib/tasks/bookkeeping_tasks.rake
|
145
|
+
homepage: https://github.com/ashlinchak/bookkeeping
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.4.5
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Double Entry Bookkeeping System for Rails.
|
169
|
+
test_files: []
|
170
|
+
has_rdoc:
|