If I want to create a new invoice (in modal) AND most recent created invoice (having highest ID) has status ‘draft’ creation fails and a 500 is thrown.
POST https://iplane.local/index.php/invoices/ajax/create
→ [HTTP/1.1 500 Internal Server Error
If I change the existing invoice (highest ID) to a status != ‘draft’ - creating a new invoice works.
I’m using v1.6.1
For the 500 error check:
- the Developer Console of your browser
- the network tab
Click on the red line
What is the error that is shown?
Any errors in the .log file?
In /application/logs/
Found this in /application/logs:
ERROR - 2024-07-08 12:49:13 → Query error: Duplicate entry ‘’ for key ‘invoice_number’ - Invalid query: INSERT INTO ip_invoices
(client_id
, invoice_date_created
, invoice_group_id
, invoice_time_created
, invoice_password
, user_id
, payment_method
, invoice_date_due
, invoice_terms
, invoice_status_id
, invoice_number
, invoice_url_key
, invoice_date_modified
) VALUES (‘1’, ‘2024-07-08’, ‘3’, ‘12:49:07’, ‘’, ‘1’, ‘3’, ‘2024-07-11’, 'Here my terms… ', 1, ‘’, ‘url_key_removed_here’, ‘2024-07-08 12:49:13’)
My settings are, that for invoice drafts no invoice number is created.
Problem seems to be, that invoiceplane doesn’t accept (by db design) a draft invoice to be created without a invoice_number value if there already exists one also having no invoice_number set (because status=draft and no inv number created).
Is this behavior reproducable?
Thanks and greets
Great job finding the log and great job deducing
the problem!
I didn’t know that the setting existed.
Therd is a unique index on invoice_number so anything you do with that number it can’t be 2 things at the same time.
Even null
as that number, if you would accomplish that, then you can’t have 2 draft invoices.
Is the only reason that you have to keep tjose numbers sequential and that if you delete one you’ve got some explaining to do?
I’m only thinking out loud.
How about a separate invoice_group that prefoxes your invoice_number with DRAFT
and ghen just set the correct invoice_group after you send your invoice?
Hi UnderDog, thanks for your quick answer and your input.
I think having more than one invoice draft at a time isn‘t really a rare use case. At least for me.
The invoice group solution you proposed is possible with configuration only? If so it‘s really an easy and quick solution.
Alternatively, how about -if setting is ‚no invoice numbers for drafts‘- set the invoice number temporarely to the invoice ID, which is later overwritten by the created invoice number, if invoice status changes from draft to another?
I’m sorry, but ihad to read the alternative 3 times.
I don’t think it ends up in InvoicePlane itself, but you can program it for yourself.
Every time InvoicePlane makes a new version you’ll have to place your own personal solution back in that file.
You’ll always keep running into the problem of invoice_number
having to be unique.
InvoicePlane V2 relies on the structure of V1, meaning that we program as if V1 existed.
Let’s say you remove the unique from that table column, it will probably solve your problem.
Let’s say you’ll use InvoicePlane V2, there’s at least a rule saving the invoice: “hey, invoice_number must be unique”
Then you might still have this problem again
Give it a try:
- Create new invoice_group and give it your preferrred format
- Create new invoice and try to see if you xan change the invoice_group
If not, let me know, there’s a couple of persons that want to change the invoice_group as well for different reasons
- If you can change your invoice_group you can also change it (some day) once the invoice goes complete
If you want you can test it on https://demo.invoiceplane.com
username is demo@invoiceplane.com
password is demopass
if i’m not mistaking
Sorry, for some reason I didn’t read your question.
Exactly, sequential invoice numbers is the background.
I’ll give it a try, thanks a lot!