Minus balance that makes no sense

I have an invoice for a client that was $701.88 inclusive of payment surcharges.

First they paid a partial amount through the billing portal, incurring a fee.

Later on they paid the remaining amount and incurred another fee.

The payments they made add up to $701.88 as expected as this was also the final invoice cost and invoice ninja has put the applicable fees on the invoices.

However when I look at the client, it says their balance is -$12.58 and I can’t understand why.

There is nothing else for this client other than what you see in the screenshots. No credits, no other payments etc.

Is this a bug or what should I be checking here? Nowhere else can I work out how this has happened and even the statement for the customer says a $0 balance.

Hi,

You can use: php artisan ninja:check-data to check for any errors like this.

And php artisan ninja:check-data --fix=true will correct it.

Thanks, I tried this and while errors with other clients were fixed it did not solve the issue experienced here. Any other ideas?

@david do you have any suggestions?

@hillel I also noticed at the end of your command it says:
"2022-07-13 10:16:27 Done: FAILURE
2022-07-13 10:16:27 Total execution time in seconds: 0.20475912094116

and when I run it with the --fix=true parameters it doesn’t actually seem to be fixing the errors?

However the command doesn’t show any issues for the client in question though so it’s not picking up any issue with this client

I cleared cache and re-ran your commands and they were a success but still didn’t correct the issue seen for this client. hmm

Now whenever I click on ledger for the client I get a slew of errors…sigh.

This command may help

php artisan ninja:type-check --all=true

Nothing found:

2022-07-13 10:55:40 2022-07-13 10:55:40 Checking all clients and companies.
2022-07-13 10:55:41 Checking client 1
2022-07-13 10:55:41 Checking client 2
2022-07-13 10:55:41 Checking client 3
2022-07-13 10:55:41 Checking client 4
2022-07-13 10:55:41 Checking client 5
2022-07-13 10:55:41 Checking client 6
2022-07-13 10:55:41 Checking client 7
2022-07-13 10:55:41 Checking client 8
2022-07-13 10:55:41 Checking client 9
2022-07-13 10:55:41 Checking client 10
2022-07-13 10:55:41 Checking client 11
2022-07-13 10:55:41 Checking client 12
2022-07-13 10:55:41 Checking client 13
2022-07-13 10:55:41 Checking client 14
2022-07-13 10:55:41 Checking client 15
2022-07-13 10:55:41 Checking client 16
2022-07-13 10:55:41 Checking client 17
2022-07-13 10:55:41 Checking client 18
2022-07-13 10:55:41 Checking client 19
2022-07-13 10:55:41 Checking client 20
2022-07-13 10:55:41 Checking client 21
2022-07-13 10:55:41 Checking client 22
2022-07-13 10:55:41 Checking client 23
2022-07-13 10:55:41 Checking client 24
2022-07-13 10:55:41 Checking client 25
2022-07-13 10:55:41 Checking client 26
2022-07-13 10:55:41 Checking client 27
2022-07-13 10:55:41 Checking client 28
2022-07-13 10:55:41 Checking client 29
2022-07-13 10:55:41 Checking client 30
2022-07-13 10:55:41 Checking client 31
2022-07-13 10:55:41 Checking client 32
2022-07-13 10:55:41 Checking client 33
2022-07-13 10:55:41 Checking client 34
2022-07-13 10:55:41 Checking client 35
2022-07-13 10:55:41 Checking client 36
2022-07-13 10:55:41 Checking client 37
2022-07-13 10:55:41 Checking client 38
2022-07-13 10:55:41 Checking client 39
2022-07-13 10:55:41 Checking client 40
2022-07-13 10:55:41 Checking client 41
2022-07-13 10:55:41 Checking client 42
2022-07-13 10:55:41 Checking client 43
2022-07-13 10:55:41 Checking client 44
2022-07-13 10:55:41 Checking client 45
2022-07-13 10:55:41 Checking client 46
2022-07-13 10:55:41 Checking client 47
2022-07-13 10:55:41 Checking client 48
2022-07-13 10:55:41 Checking client 49
2022-07-13 10:55:41 Checking client 50
2022-07-13 10:55:41 Checking client 51
2022-07-13 10:55:41 Checking client 52
2022-07-13 10:55:41 Checking client 53
2022-07-13 10:55:41 Checking client 54
2022-07-13 10:55:41 Checking client 55
2022-07-13 10:55:41 Checking client 56
2022-07-13 10:55:41 Checking client 57
2022-07-13 10:55:41 Checking client 58
2022-07-13 10:55:41 Checking client 59
2022-07-13 10:55:41 Checking client 60
2022-07-13 10:55:41 Checking client 61
2022-07-13 10:55:41 Checking client 62
2022-07-13 10:55:41 Checking client 63
2022-07-13 10:55:41 Checking client 64
2022-07-13 10:55:41 Checking client 65
2022-07-13 10:55:41 Checking client 66
2022-07-13 10:55:41 Checking client 67
2022-07-13 10:55:41 Checking client 68
2022-07-13 10:55:41 Checking client 69
2022-07-13 10:55:41 Checking client 70
2022-07-13 10:55:41 Checking client 71
2022-07-13 10:55:41 Checking client 72
2022-07-13 10:55:41 Checking client 73
2022-07-13 10:55:41 Checking client 74
2022-07-13 10:55:41 Checking client 75
2022-07-13 10:55:41 Checking client 76
2022-07-13 10:55:41 Checking client 77
2022-07-13 10:55:41 Checking client 78
2022-07-13 10:55:41 Checking client 79
2022-07-13 10:55:41 Checking client 80
2022-07-13 10:55:41 Checking client 81
2022-07-13 10:55:41 Checking client 82
2022-07-13 10:55:41 Checking client 83
2022-07-13 10:55:41 Checking client 84
2022-07-13 10:55:41 Checking client 85
2022-07-13 10:55:41 Checking client 86
2022-07-13 10:55:41 Checking client 87
2022-07-13 10:55:41 Checking client 88
2022-07-13 10:55:41 Checking client 89
2022-07-13 10:55:41 Checking client 90
2022-07-13 10:55:41 Checking client 91
2022-07-13 10:55:41 Checking client 92
2022-07-13 10:55:41 Checking client 93
2022-07-13 10:55:42 Checking client 94
2022-07-13 10:55:42 Checking client 95
2022-07-13 10:55:42 Checking client 96
2022-07-13 10:55:42 Checking client 97
2022-07-13 10:55:42 Checking client 98
2022-07-13 10:55:42 Checking client 100
2022-07-13 10:55:42 Checking client 101
2022-07-13 10:55:42 Checking client 104
2022-07-13 10:55:42 Checking client 105
2022-07-13 10:55:42 Checking client 106
2022-07-13 10:55:42 Checking client 107
2022-07-13 10:55:42 Checking client 108
2022-07-13 10:55:42 Checking client 109
2022-07-13 10:55:42 Checking client 110
2022-07-13 10:55:42 Checking client 111
2022-07-13 10:55:42 Checking client 112
2022-07-13 10:55:42 Checking client 113
2022-07-13 10:55:42 Checking client 114
2022-07-13 10:55:42 Checking client 115
2022-07-13 10:55:42 Checking client 116
2022-07-13 10:55:42 Checking client 117
2022-07-13 10:55:42 Checking client 118
2022-07-13 10:55:42 Checking client 119
2022-07-13 10:55:42 Checking client 120
2022-07-13 10:55:42 Checking client 121
2022-07-13 10:55:42 Checking client 122
2022-07-13 10:55:42 Checking client 123
2022-07-13 10:55:42 Checking client 124
2022-07-13 10:55:42 Checking client 125
2022-07-13 10:55:42 Checking client 126
2022-07-13 10:55:42 Checking client 127
2022-07-13 10:55:42 Checking client 128
2022-07-13 10:55:42 Checking client 129
2022-07-13 10:55:42 Checking client 130
2022-07-13 10:55:42 Checking client 131
2022-07-13 10:55:42 Checking client 132
2022-07-13 10:55:42 Checking client 133
2022-07-13 10:55:42 Checking client 134
2022-07-13 10:55:42 Checking client 135
2022-07-13 10:55:42 Checking client 136
2022-07-13 10:55:42 Checking client 137
2022-07-13 10:55:42 Checking client 138
2022-07-13 10:55:42 Checking client 139
2022-07-13 10:55:42 Checking client 140
2022-07-13 10:55:42 Checking client 141
2022-07-13 10:55:42 Checking client 142
2022-07-13 10:55:42 Checking client 143
2022-07-13 10:55:42 Checking client 144
2022-07-13 10:55:42 Checking client 145
2022-07-13 10:55:42 Checking client 146
2022-07-13 10:55:42 Checking client 147
2022-07-13 10:55:42 Checking client 148
2022-07-13 10:55:42 Checking client 149
2022-07-13 10:55:42 Checking client 150
2022-07-13 10:55:42 Checking client 151
2022-07-13 10:55:42 Checking client 152
2022-07-13 10:55:42 Checking client 154
2022-07-13 10:55:42 Checking client 155
2022-07-13 10:55:42 Checking client 156
2022-07-13 10:55:42 Checking client 158
2022-07-13 10:55:42 Checking client 159
2022-07-13 10:55:42 Checking client 160
2022-07-13 10:55:42 Checking client 161
2022-07-13 10:55:42 Checking client 162
2022-07-13 10:55:42 Checking client 163
2022-07-13 10:55:42 Checking client 164
2022-07-13 10:55:42 Checking client 165
2022-07-13 10:55:42 Checking client 167
2022-07-13 10:55:42 Checking client 170
2022-07-13 10:55:42 Checking client 172
2022-07-13 10:55:42 Checking client 185
2022-07-13 10:55:42 Checking client 186
2022-07-13 10:55:42 Checking client 187
2022-07-13 10:55:42 Checking client 188
2022-07-13 10:55:42 Checking client 189
2022-07-13 10:55:42 Checking client 190
2022-07-13 10:55:42 Checking client 191
2022-07-13 10:55:42 Checking client 192
2022-07-13 10:55:42 Checking client 193
2022-07-13 10:55:42 Checking client 194
2022-07-13 10:55:42 Checking client 195
2022-07-13 10:55:42 Checking client 196
2022-07-13 10:55:42 Checking client 197
2022-07-13 10:55:42 Checking client 198
2022-07-13 10:55:42 Checking client 199
2022-07-13 10:55:42 Checking client 200
2022-07-13 10:55:42 Checking client 201
2022-07-13 10:55:42 Checking client 205
2022-07-13 10:55:42 Checking company 1
2022-07-13 10:55:42 Checking company 2

Ledger started working again…sometimes I get that error code though, not sure what’s happening honestly.

Anyway I noticed in the ledger something weird happened but there is no payment or anything to explain it.

Imo this is definitely a bug that cause erroneous data.

@kylegp

look like a bug with partial payments + gateway fees, out of interest, was the second gateway fee $12.58 ?

No, the gateway fees are shown in a screenshot in my first post.

The first payment for $570.28 included the $10.28 fee.

Then the remaining payment of $131.60 included the fee $2.60.

This is why I have no idea what that $12.58 is.

How can I correct this? I need to invoice this client but because they are in a negative balance, whenever I invoice them it’s reflecting a balance of $12.58 less…

@kylegp

if you run

php artisan ninja:check-data --fix=true --client_balance=true

This will fix the balance. I’ve done some additional testing on partial invoices and haven’t been able to recreate it. It would be helpful to understand more about this issue, in particular when the balance went out of sync.

I have tried this command amongst many other check-data commands and there are no issues found. Whatever has happened seems to be on a deeper database level.

This is the only client in which this bug has occurred and I only just noticed this issue when I went to invoice them for a second time.

All I can say is that I had an invoice for $689 originally. They made a partial payment via Stripe through the client portal and that partial payment was $560 + $10.28 fee, totaling $570.28.

When I completed the work, they paid the rest of the invoice again via the client portal and this time it was a payment of $129 + $2.60 fee, totaling $131.60.

As you can see from the screenshots, this is what I am seeing on the invoice and in the payments tab so there is nothing to explain this $12.58 that I can make sense of.

Here’s my stripe gateway fees as well:

I might just have to create the client again and start fresh which is not ideal because they may wish to access their previous invoice in the client portal. Can I somehow correct this on a database level. What would be the best way to correct this?

2022-07-13 11:55:21 2022-07-13 11:55:21 Running CheckData... on Connected to Default DB Fix Status = Fixing Issues

2022-07-13 11:55:21 0 clients with incorrect balances
2022-07-13 11:55:21 0 clients with incorrect paid to dates
2022-07-13 11:55:21 0 contacts without a contact_key
2022-07-13 11:55:21 0 clients without any contacts
2022-07-13 11:55:21 0 contacts without a contact_key
2022-07-13 11:55:21 0 vendors without any contacts
2022-07-13 11:55:21 0 invoices without any invitations
2022-07-13 11:55:21 0 quotes without any invitations
2022-07-13 11:55:21 0 credits without any invitations
2022-07-13 11:55:21 0 recurring_invoices without any invitations
2022-07-13 11:55:21 0 wrong invoices with bad balance state
2022-07-13 11:55:21 0 users with duplicate oauth ids
2022-07-13 11:55:21 Done: SUCCESS
2022-07-13 11:55:21 Total execution time in seconds: 0.20802307128906

That is definitely strange. After the invoice was paid, were any further changes manually made to the invoice at all? Were fees removed directly from the invoice? or were any amounts changed?

For the check data script for client balances, we sum up ALL invoice balances with sent/partial paid status and then compare this to the client balance, this would indicate that there is an invoice/s balance for this client which sums up to -12.58

I didn’t remove any fees and they are still present on the invoice. The payments add up to $701.88 and so does the invoice. I’m confused as well.

There are literally no other invoices or payments than what is seen here:

Also the balance due is $0.00 at the end of this invoice and it’s the only invoice so this is why I don’t understand where that $12.58 came from.

@david I think the invoice must have been adjusted or something after the fact and this caused some bug but I can’t recall. Do you have any suggestion on what I can check to resolve this?

I have had to just archive that client and create another one as I need to invoice them and don’t want confusion with it showing the wrong account balance to them.

If there’s something further in the DB I can check or you have a further suggestion, I can go back and look at the archived client closer.

@kylegp

I’d be interested to inspect the system to try and understand this because it isn’t making sense.

Sure, anything to help figure this out and prevent it from happening again or to others. I’ve PM’d you