borutus 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/borutus/account.rb +9 -13
- data/lib/borutus/version.rb +1 -1
- data/spec/models/account_spec.rb +7 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0c526c5aff61f0ae1cf18cb178c35f83a21e41115084095c80c7f9a7062e34e
|
4
|
+
data.tar.gz: 3b482a97d3b010795f27ec03ef91015d2b8540c36185d394c2e92648ea297167
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d306a22f425827597905f4bdc519fde1c65830b9d011cebc12191adde8b39c864b1e410ac50ccb8f7c91052e3f90864efef0829b445fcccd944258000285f92
|
7
|
+
data.tar.gz: 44ec323985e18ac5f3b98d3a437da159557559188765366c04f00c31c1b8bafd78953fcd6fce62d4c3d544b7e0448d3fec584c3670d882f33d4ba03d0791f556
|
@@ -53,25 +53,21 @@ module Borutus
|
|
53
53
|
%{ SUM("borutus_amounts".amount) AS amount }
|
54
54
|
).group(:entry_id, :id)
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
sum_statement = if account.normal_credit_balance
|
57
|
+
%{ COALESCE("credit_table"."amount", 0) - COALESCE("debit_table"."amount", 0) }
|
58
|
+
else
|
59
|
+
%{ COALESCE("debit_table"."amount", 0) - COALESCE("credit_table"."amount", 0) }
|
60
|
+
end
|
61
61
|
|
62
62
|
joins(%{
|
63
63
|
LEFT OUTER JOIN (#{credit_table.to_sql}) AS "credit_table" ON "credit_table".entry_id = "borutus_entries".id
|
64
64
|
LEFT OUTER JOIN (#{debit_table.to_sql}) AS "debit_table" ON "debit_table".entry_id = "borutus_entries".id
|
65
65
|
}).select(%{
|
66
66
|
"borutus_entries".*,
|
67
|
-
SUM(#{
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
"debit_table".amount,
|
72
|
-
"credit_table".amount
|
73
|
-
}
|
74
|
-
).order(created_at: :asc)
|
67
|
+
SUM(#{sum_statement}) OVER(ORDER BY "borutus_entries"."created_at") AS balance,
|
68
|
+
#{sum_statement} AS change_amount
|
69
|
+
}).group(:id, %{ "debit_table".amount, "credit_table".amount })
|
70
|
+
.order(created_at: :asc)
|
75
71
|
end
|
76
72
|
end
|
77
73
|
has_many :credit_entries, :through => :credit_amounts, :source => :entry, :class_name => 'Borutus::Entry'
|
data/lib/borutus/version.rb
CHANGED
data/spec/models/account_spec.rb
CHANGED
@@ -58,7 +58,7 @@ module Borutus
|
|
58
58
|
})
|
59
59
|
end
|
60
60
|
|
61
|
-
it "returns entries for only the account with a balance
|
61
|
+
it "returns entries for only the account with a balance and change_amount columns" do
|
62
62
|
entry_1.save
|
63
63
|
entry_2.save
|
64
64
|
entry_3.save
|
@@ -66,15 +66,21 @@ module Borutus
|
|
66
66
|
receivable_entries = accounts_receivable.entries.with_running_balance
|
67
67
|
expect(receivable_entries.to_a.count).to eq 3
|
68
68
|
expect(receivable_entries.first.balance).to eq 50 # inital 50
|
69
|
+
expect(receivable_entries.first.change_amount).to eq 50 # inital 50
|
69
70
|
expect(receivable_entries.second.balance).to eq 20 # deduct 30 due to entry_2
|
71
|
+
expect(receivable_entries.second.change_amount).to eq -30 # deduct 30 due to entry_2
|
70
72
|
expect(receivable_entries.last.balance).to eq 5 # deduct 5 due to entry_3
|
73
|
+
expect(receivable_entries.last.change_amount).to eq -15 # deduct 5 due to entry_3
|
71
74
|
|
72
75
|
payable_entries = sales_tax_payable.entries.with_running_balance
|
73
76
|
.order(created_at: :asc)
|
74
77
|
expect(payable_entries.to_a.count).to eq 3
|
75
78
|
expect(payable_entries.first.balance).to eq 5
|
79
|
+
expect(payable_entries.first.change_amount).to eq 5
|
76
80
|
expect(payable_entries.second.balance).to eq 0 # deduct 5 due to entry_2
|
81
|
+
expect(payable_entries.second.change_amount).to eq -5
|
77
82
|
expect(payable_entries.last.balance).to eq -15 # deduct 15 due to entry_3
|
83
|
+
expect(payable_entries.last.change_amount).to eq -15
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|