How to crate an invioce number

Hi, there! bubblers I’m Mohamed i need assistant recently i created a project about an inventory management tool , so my issue is how to add an invoice number my Receipt Order which contains fields [ date purchased , Invoice Number, customer name, phone and list of items ordered] so read in detail this article what i need to assist me.

Invoice number based on date input´s year date

I want to get the invoice number automatically generated based on this:
• The invoice number has to start always by number 1 and correlative based on the invoice´s year date.
• If you eliminate the latest invoice of that year then that number it will be available for the next invoice.
Here is an example: when creating the invoice, I select on the invoice date field this “01/01/2024” (dd/mm/yyyy format) and this is the first invoice of 2024 so the invoice number generated will be “1/2024”, after when I clicked my button save data the next invoice number if I select again a date in 2024 year will be “2/2024”, “3/2024”, “4/2024”, …
Now if I delete (or set the state of deleted) the latest invoice (the latest invoice will be the only one that can be deleted always) and this one was “4/2024”, then this number will be available. So after deleting the invoice “4/2024” the next invoice will be again the “4/2024”.
Now if I create a new invoice with the date´s year as 2025 and there is no invoice on 2025, the first one will start by “1/2025”, “2/2025”, …

If deleting the invoice would revert the count to the number before the latest invoice was created, you could simply use the count operator to count the number of invoice + 1 and add the current date’s year.

This way, you wouldn’t need to create a number of invoices field where you increase the number by 1 increment every time an invoice is created or deduct the number by 1 when you delete an invoice.

The caveat is you would be searching every time which has WU cost implications. But count operator only aggregates data (if I remember correctly) so it should relatively be fast and cheap. It would be different story though when you have thousands or hundreds of thousands of invoices already. If you wish to go with this route, make sure you have privacy rules enabled for the invoice data so you won’t need to search for other unnecessary data i.e. other user’s invoice.

1 Like

Thank you very much friend for your kind response to my post. I understand little bit but I want how use it as expression please show me I use it I’m not well experienced in bubble so help me how do that.