Invoice doubling - balancing issue

Have an issue I’ve encountered in some testing…

Have v5 finally running, data migrated, and everything seems ok. All balances were clean and all seemed ready to go. Have a payment gateway set up successfully using Stripe.

Created a test client, and then a test invoice (used a small $2.00 amount for testing). Paid the invoice online, payment was accepted and processed via Stripe, and all seems good. However, now that client is showing out of balance. When looking at the ledger for the client, I see the invoice listed twice. The following entries are showing in the ledger:

Payment -$2.00 ($2.00 balance)
Invoice 2.00 ($4.00 balance)
Invoice 2.00 ($2.00 balance) (same invoice number as above)
Client created 0.00 balance

Looked in the database directly, only one invoice is listed in the invoice table. Unsure of where/why the invoices is showing twice in the ledger and the client shows out of balance now.

@JFox

This isn’t the first time someone has mentioned the ledger going out of whack, however I have been unable to recreate it myself.

I followed your steps.

  1. Create invoice for $2.
  2. Pay invoice using Stripe in Test Mode
  3. View Client balance and it appears correct at $0.

I’d really like to get to the bottom of this, so if you are able to consistently recreate this issue can you please post the steps you used to get the ledger out of balance.

Here’s some additional detail I’ve discovered and found interesting. These are the records for this set of transactions in the company_ledgers table. Note the duplication for the invoice transaction, particularly the timestamps.

mysql> select id,activity_id,adjustment,balance,company_ledgerable_id,company_ledgerable_type,created_at from company_ledgers where
client_id = 28;
±—±------------±-----------±--------±----------------------±------------------------±---------------------------+
| id | activity_id | adjustment | balance | company_ledgerable_id | company_ledgerable_type | created_at |
±—±------------±-----------±--------±----------------------±------------------------±---------------------------+
| 5 | 5 | 2.0000 | 2.0000 | 38 | invoices | 2020-11-29 18:35:54.489105 |
| 6 | 5 | 2.0000 | 4.0000 | 38 | invoices | 2020-11-29 18:35:54.820424 |
| 7 | 11 | -2.0000 | 2.0000 | 13 | App\Models\Payment | 2020-11-29 20:26:50.151122 |
±—±------------±-----------±--------±----------------------±------------------------±---------------------------+

I am going to run through this process again, and monitor this table with each step. Hopefully I can duplicate the result.

So, it appears it is happening upon creating the invoice and selecting to email the invoice (removing it from draft). As soon as I did that, it generated these ledger records.

mysql> select id,activity_id,adjustment,balance,company_ledgerable_id,company_ledgerable_type,created_at from company_ledgers where
client_id = 60;
±—±------------±-----------±--------±----------------------±------------------------±---------------------------+
| id | activity_id | adjustment | balance | company_ledgerable_id | company_ledgerable_type | created_at |
±—±------------±-----------±--------±----------------------±------------------------±---------------------------+
| 8 | 5 | 1.0000 | 1.0000 | 70 | invoices | 2020-12-02 01:50:47.081111 |
| 9 | 5 | 1.0000 | 2.0000 | 70 | invoices | 2020-12-02 01:50:47.518231 |
±—±------------±-----------±--------±----------------------±------------------------±---------------------------+

I clicked on clients, clicked the + icon, and created the client.
I then clicked on the invoices module, clicked the + icon, and created a new invoice for the new client.
I then clicked the options button (three dots in top right corner), and selected Email Invoice. Email template displayed, and I clicked Send.
This is when the records were generated, and the client’s open balance now shows double.

Hopefully this helps in tracking this down!

The above is pretty consistent. This happens on literally every invoice that is created. Really curious as to the possible cause, especially if it’s not happening to everyone. Unfortunately, it renders the app almost useless until I can figure this out. Anyone have a chance to look into this? I will keep digging…

It’s been some time, but here’s an update on this issue… This happens any time the option is chosen to Email Invoice while the invoice is in a Draft state. The email is sent, state changed to Sent, and the ledger shows a duplicated entry. If I set the state of the invoice from Draft to Sent, and then choose the option to Email Invoice, the ledger and client balance remain in tact with expected values.

@JFox there is a fix for this in v5-develop, you can either switch to that branch, or we should be pushing another release in a couple of days.

2 Likes

@david, great news - thanks for the heads up!