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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ed73fe6e709a22d33f2a11f0360c57c0df95b940fe3b67ba97ea22171b941fc
4
- data.tar.gz: 23ededc317f6e6373938e23bc4225bb96685fcb4bc240474147ed951f2b7d449
3
+ metadata.gz: f0c526c5aff61f0ae1cf18cb178c35f83a21e41115084095c80c7f9a7062e34e
4
+ data.tar.gz: 3b482a97d3b010795f27ec03ef91015d2b8540c36185d394c2e92648ea297167
5
5
  SHA512:
6
- metadata.gz: 9eed73e765fbac8b03d41792381c8ced5c8c6e97dec7351ad52fed8c4f6d6aaeb8cf06744fff475590941d5f85050aebe8fa7afb40cfb4c67a3a4edd3ef2d879
7
- data.tar.gz: 3935d58c029083d95125f2e2d5aed927b718c16c6d457d232f86434b2ac4c968c6d287df9e4c0c5781eb74b72c6b2e894b965b5c2d2a70b7d3fab6a91d4e1ad4
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
- select_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
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(#{select_statement}) OVER(ORDER BY "borutus_entries"."created_at") AS balance
68
- }).group(
69
- :id,
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'
@@ -1,3 +1,3 @@
1
1
  module Borutus
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -58,7 +58,7 @@ module Borutus
58
58
  })
59
59
  end
60
60
 
61
- it "returns entries for only the account with a balance column" do
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: borutus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag