Find the Gap

Cubus Arts Blog
Jakob Cosoroabă

Find the Gap

Jakob Cosoroabă

In one of our products (factureaza.ro) being a invoicing service, clients can define document series. Each document within a particular series has a order-number. If everything works perfectly the order-numbers are consecutive, but as we don’t live in a perfect world documents get moved to different series, are deleted, the user adjusts the order-number manually and there we have it: the client created a gap in the numbering.

That in fact wouldn’t be so bad but if afterwards we need to deal with questions like:

“the last invoice I’ve created was 23/INV-2011, but I only issued 19 invoices this year”

In oder to give the user more transparency and a option to fill the gaps we needed first to find them. This was easy: just make an Range from the first to the last, turn it into an Array and subtract all of those that do exist

OK done. Not quite yet because we still need to show them to the user. There is a possibility that he created a Document with the order_number 1 and one with the order_number 1000, and showing the user a list of numbers going from 2 to 999 filling up the screen isn’t nice nor useful.

So we condensed the Array back into Ranges like this

Yes works out nice and by the next update of the service user will be able to find and if they like even fill the gaps in their document series.