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/2016” (dd/mm/yyyy format) and this is the first invoice of 2016 so the invoice number generated will be “1/2016”, the next invoice number if I select again a date in 2016 year will be “2/2016”, “3/2016”, “4/2016”, …
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/2016”, then this number will be available. So after deleting the invoice “4/2016” the next invoice will be again the “4/2016”.
Now if I create a new invoice with the date´s year as 2015 and there is no invoice on 2015, the first one will start by “1/2015”, “2/2015”, …
And how do I tell bubble to perform the action of: if on the date picker I select 2015, to search the latest invoice so the next one will be the latest one number plus 1.
For example: the latest invoice of 2015 was the 3 so if I pick a date of the year 2015 bubble has to search that the latest one was the 3, so the next one will be the fourth one.
Also when a new year starts it has to begin again with the number 1 based on the year.
It’s a bit hard to explain but I’m sure you get it.
This seems kind of confusing but I think you’re saying you want the invoices to be identified by the days in a year.
The best way to understand the problem is to understand the app itself. So what are you trying to accomplish with this feature.
So If I pick today’s date 5/18/16 in the datepicker and there are no invoices for this year. The number for today’s invoice will be 1/2016, and if I was to delete today’s’ invoice the number 1/2016 would be available?
But what if you created two invoices today and they took the number 1/2016 and 2/2016 and you deleted the invoice with the 1/2016 number, what happens next.
I think I understand the goal you’re trying to accomplish. When an invoice is created you want to know if it’s the 1st, 2nd or 100th of the year and assign it that order. So if 55 invoices were created in 2016 the next one will have the 56th number assigned to it.
Ah, you aren’t in Italy by any chance ? I remember this from years back, VAT invoices must be sequential. No gaps allowed !
So I think Emmanuel is right, it is not going to be all that easy. But it will certainly be possible.
You will need two workflows on your “create invoice” button (or page). And you will also need some sort of “deleted invoice” table as well. Either that or have a status of “deleted” on your invoices.
The first workflow will be where there are no “deleted invoices” (search :count = 0 for the year) and you can create an invoice with the next sequential number.
The second workflow will be when there is a “deleted invoice”. In that case you will use the lowest deleted invoice number as you new invoice, and delete the row.
Or if you have a “deleted” status you would do a “make changes to thing” on the lowest invoice number instead. Change it to a “live” invoice and use that.
I´m in west Europe so it works the same as Italy´s sequential invoice. Other thing that we have to take care of is that they must be sequential and the sequence must start by one each year. So in 2015, the invoices will be 1/2015, 2/2015, … and in 2016 they will be 1/2016, 2/2016, …
What you say makes sense but how to accomplish it when you select the date on date picker? I mean if I select year 2016 and the latest of 2016 is 5, the next will be 6 but if I select 2015 as a year on date picker and the latest one of 2015 is the number 4 the next one will be 5.
To identify the invoices on the year we use a serial number based on the year selected. For example: 1/2016, 2/2016, …1/2015, 2/2015, …
Two invoices can be created on same day and they will be sequential.
Also we´re not allowing anyone to delete an invoice that is in the middle, just the latest invoice of the particular year. For example: if we have invoice´s number 1/2015, 2/2015, 3/2015, … we´re not going to allow to delete the number 1 and the number 2, just the number 3.