abivia / ledger

General Ledger and Journal Accounting Package and API for Laravel
MIT License
102 stars 23 forks source link

API Responses #10

Closed c-myers1 closed 1 year ago

c-myers1 commented 1 year ago

Testing some of the APIs, I note the responses are not as described in the docs. Specifically calling domain/add and currency/add gets a reply with only "time" in the response whilst the docs show a fuller response.

Do I have a wrong config somewhere?

abivia commented 1 year ago

The test cases return the right response, so something else is going on. Possibly an error of some sort where nothing is returned. Can you share the currency/add request details? I'll try to reproduce in a test environment and see what's going on.

c-myers1 commented 1 year ago

Full disclosure: this is the latest Laravel (PHP 8.2 I suppose). I just sailed up a fresh app and pulled down Abivia. Other weird stuff going on: it created domain, ledger and currency but whilst is responds with 200 to creation of account, no record is inserted in ledger_accounts table.

Also, after installing Abivia, I manually copied the routes under vendor/abivia/ledger/routes into the routes/api file (I thought publishing config would have taken care of all that). So that's what you need to do to reproduce this.

abivia commented 1 year ago

I see the problem and have reproduced it. You need to create the ledger first (via api/ledger/root/create), so it is a case of not reporting an error correctly. Fixing that now!

Thanks for the report.

c-myers1 commented 1 year ago

I created a domain and it created records in both ledger_domains and ledger_names. Is that a wrong way to go about it?

abivia commented 1 year ago

That should have returned an error too. Creating the ledger sets some critical rules, mostly related to ledger accounts. Without the ledger root, not much will work. Right now it's triggering an unexpected exception and no information is being returned because there's a risk of information disclosure. However details are recorded in the audit log.

I'm going to change the exception so it's handled differently. I'm also going to set it so that at the least an unexpected exception returns a message to say the request failed. I'll add a half dozen test cases to cover this too.

abivia commented 1 year ago

To answer your question more directly, creating the ledger root is the first thing you should do before doing anything else.

c-myers1 commented 1 year ago

I really need to understand the model better then. Since I can have multiple "domains" each having their own ledger root, I would have thought the domain comes first. Do I have things muddled up?

abivia commented 1 year ago

Domains share the same Chart of Accounts. Each domain is a separate partition in the Journal but they all use the same CoA. The ledger root is the (hidden) parent of all top level accounts, and embeds rules like what an account code can look like, whether or not transactions can be posted to category accounts, and so on.

So the process is to create the ledger. Then you can define accounts, currencies, and domains in any order.

c-myers1 commented 1 year ago

Oh ok, reading here again, that's actually clearly stated. But I first read that a long time ago.

So it means Abivia can't really be used to maintain accounts of multiple entities with different chart of accounts within the same Laravel application then. Correct?

abivia commented 1 year ago

That's essentially correct. It's more designed for a single enterprise with multiple divisions/departments/etc. than a multi-tenant configuration.

Possibly the best approach for a multi-tenant application would be to use separate databases.

c-myers1 commented 1 year ago

Very true

abivia commented 1 year ago

Fixed in 1.9.0.