Invoice number based on date input´s year date (SOLVED)

Hello,

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”, …

The app is here: https://bubble.io/page?type=page&name=new_invoice&id=mynewtestapp&tab=tabs-1

Thanks a lot guys.

Can anyone help?

@emmanuel could you take a look at this?

Thanks a lot.

Not sure there is a good way to do this

What do you mean? I know the steps but I don’t know how to reproduce them on bubble.

Well it’s going to be quite cumbersome to do it, I would go for a simpler approach to be honest.

What simpler approach you mean?

Not trying to get back to the previous number when an item is deleted

Sorry I don’t understand Emmanuel. What do you propose ?

Maybe iterate a number and use that? I’ll let you think about options.

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.

Any thoughts?

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.

1 Like

Thanks for your reply @muradamod,

Not exactly. I want to generate invoice numbers based on the year picked in the date picker.

So if pick the date 12/01/2015 (dd/mm/yyyy) and the latest invoice of 2015 was the number 4, the next one will be the number 5.

But if pick a date of 2016 and there is no invoice in that year yet, the first one will be the number 1.

It’s a bit hard to explain. Let me know if I can get a better explanation.

Can you sort things out?

Thanks.

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.

Hopefully that makes sense ?

1 Like

Thanks for your reply @NigelG,

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, …

Do you how to accomplish?

Thanks a lot @NigelG

If it were me I would have some sort of Invoice Control Table, rather than trying to work it out each time from the data.

You would need to prepopulate with Years from now to 2020 or whatever.

Let me have a think.

Thanks for reply,

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.

Makes sense?

Thanks a lot @NigelG

I´ll be thinking too, I know the process but don´t know how to achieve that in Bubble.

So you can pull the year out of the date picker … and look up something …

It is then a question of handling the deleted invoices.

So maybe have a status on the invoice of Deleted and Replaced. Then when you allocate the next number you could search.