I’m Darshan Hiranandani, I’m working on setting up invoice numbers for each item purchased in my application. I need each invoice number to follow a sequential pattern like 1001, 1002, 1003, etc. However, if I delete an invoice, such as invoice 1004, from my sales database, I want that specific invoice number (1004) to be available again for reuse rather than the next invoice continuing as 1005. This is important for keeping my sales database organized and ensuring that invoice numbers remain consecutive.
Could anyone suggest a method or provide guidance on how to implement this functionality? I appreciate any advice or suggestions you can offer.
Normally in inventory or invoicing app, deleting should archive and not fully delete from the database.
What you are asking is if you have 1035 invoice and you delete invoice 1004, the next invoice number should be 1005 instead of 1036?
You can create a table in your database called Global variables
Inside that, keep an attribute of type number, called Next invoice number and set it initially to 1. Also keep an attribute of type number (list), called Deleted invoice numbers.
Create a new entry manually in the database (from the App data section of the Bubble editor) and set Next invoice number to 1.
From now on, whenever a new invoice is created, you can use the Next invoice number of the first item in the Global variables table and then increment that. Before doing so, make a check in your Deleted invoice numbers list (sorted by ascending order). If the list is not empty, use that invoice number and delete it from that list.
Whenever you delete an invoice, add the number of the invoice to the list.