dmitry-merzlyakov / nledger

.Net Ledger: Double-Entry Accounting System
Other
182 stars 51 forks source link

Error in Calculation #7

Closed VagyokC4 closed 4 years ago

VagyokC4 commented 4 years ago

Hi @dmitry-merzlyakov ,

I found a discrepancy in the equity calculations between Ledger and NLedger.

Using the following test.ledger I am added a 0.5 fee to 4 transactions:

= expr 'account =~ /Accounts:Client/ and has_tag("Payments") and has_tag("Credit") and amount < 1000'
  (Sample:Fees)  -0.5 GBP

2020-06-01  *  (4284af3d-dc3d-4b83-a3c0-f87f013f06f3) BITFINEX LTD-MA
  ; :Credit:Payments:
  Accounts:Client:9cc2fdda06e04c29a40071  35.00 GBP
  Accounts:External:bfc20917a2bd4ca18fb259

2020-06-01  *  (6c4f357e-fda6-4d1e-af66-5e26b0eb529e) BITFINEX LTD-MA
  ; :Credit:Payments:
  Accounts:Client:9cc2fdda06e04c29a40071  100.00 GBP
  Accounts:External:ed536d8eb7374e8da3439b

2020-06-01  *  (097f40d7-2f4c-44e1-944c-accf732e21ca) BITFINEX LTD-MA
  ; :Credit:Payments:
  Accounts:Client:9cc2fdda06e04c29a40071  50.00 GBP
  Accounts:External:67690e9002de45f7bfcea1

2020-06-01  *  (c9a9213a-a5e4-4035-92ab-fd71703ab480) BITFINEX LTD-MA
  ; :Credit:Payments:
  Accounts:Client:9cc2fdda06e04c29a40071  50.00 GBP
  Accounts:External:ed536d8eb7374e8da3439b

NLedger calculated the fee correctly in the balance sheet, but not in the equity image

But original Ledger correctly calculates in both reports. image

The above journal is a small example that shows the error, but this number exponentially grows when viewed with a larger ledger file as seen here: image

and here: image

And one last image that shows the pattern of the mis-calculation (side-by-side): image

dmitry-merzlyakov commented 4 years ago

Hi, I confirm that it was an issue in ported .Net code.

The problem is solved; the fix is available in NLedger/next-dev branch (commit b02e5318); test file is also added (/test/nledger/gh-issues-7.test; it works well for NLedger 0.8 and Ledger 3.2.1).

You can take fixed binaries created by CI build (please, check https://github.com/dmitry-merzlyakov/nledger/blob/next-dev/_CI.BuildLog.md) or just get the latest next-dev sources.

VagyokC4 commented 4 years ago

I can confirm the issue has been resolved in NLedger 0.8. Great work! Thank-you!