Numbering over time

Invoices must follow a specific numbering scheme in relation to the issue date. The relationship can be summed to "Numbers always follow an ascending progression over time". This basically means that for any given InvoiceType gaps are allowed while number loops are not. The general principles are the following.

note: all dates are considered to be DateTimeOffsets

Validation rules:

The system is designed to allow both automatic resolution as well as external definition both for the date and the number. In essence this means that given an invoice type, a call to issue a new invoice omitting number & date will result now as the date and next available number incremental as the number.

The invoice life cycle is a state machine that progresses by altering the "invoice status". Basically there are only two operations that can affect status: upon "create" & "status-change"

On create

The invoice number must:

  1. be unique, i.e. not assigned to another invoice.
  2. not be empty unless the invoice status is Draft
  3. ascend over time:
    • if both number & date are provided, the date & the number of the request must be between those of the previous and the next stored invoice records (based upon the incoming invoice-number of course).
    • if an invoice date is provided, the request date must be greater than the date of the last record's date.
    • if none of the number and date properties are provided, the request date (current date) must have a date greater than the last record's date. Otherwise you must change it.

On status change

  1. Invoice must follow dates sequentially.
    • When the invoice status is changed from draft to another status and the invoice number in draft version is not assigned, the invoice number will be automatically generated. This means the invoice number must have a date greater than the last record's date.
    • When the invoice status is changed from draft to another status and the invoice number in draft version is assigned in the update invoice operation, the date and the number of the invoice must be between the date and the number of the previous and the next record. Otherwise you must change the invoice date or the invoice number.

Examples

Assuming we have the following invoices for a specific subscription and type id:

1. Scenario "mind the gap"

consider the gap between invoices #000001 & #000005

[
  {
    number = 1,
    date = "2017-09-25T12:57:38.000+03:00",
    ...
  },
  {
    number = 5,
    date = "2017-10-24T04:39:08.000+03:00"
  }
]

The table of possible outcome given pairs of Dates & numbers

Number Date Result
4 2017-10-20 4:39:08 PM +03:00 Ok
4 2017-10-26 4:39:08 PM +03:00 Bad request
4 2017-09-23 4:39:08 PM +03:00 Bad request

2. Scenario "Plan ahead"

we have skipped some numbers and started at the given offset. Invoices start from #000006 and there is only one invoice:

[
  {
    number = 6,
    date = "2017-11-25T12:57:38.000+03:00"
  }
]

The table of possible outcome given pairs of Dates & numbers

Number Date Result
2 2017-10-20 4:39:08 PM +03:00 Ok
2 2017-11-26 4:39:08 PM +03:00 Bad request
10 2017-11-29 4:39:08 PM +03:00 Ok
10 2017-11-24 4:39:08 PM +03:00 Bad request

3. Scenario "normal"

we got only one invoice stored and it has the lowest possible number one #000001

[
  {
    number = 1,
    date = "2017-09-25T12:57:38.000+03:00"
  }
]

The table of possible outcome given pairs of dates & numbers

Number Date Result
2 2017-09-28 4:39:08 PM +03:00 Ok
2 2017-09-10 4:39:08 PM +03:00 Bad request
4 2017-09-29 4:39:08 PM +03:00 Ok
4 2017-09-24 4:39:08 PM +03:00 Bad request
About INDICE

Have something to say? Send us a message.

For any legal issues or if you believe that incontrl infringes your privacy in any way, please contact our Legal & Privacy Officers.

Offices
22, Iakchou Str Athens, 11854 Greece
Copyright
© INDICE 2014 - 2024 All rights reserved. Oh and don't read the next sentence! You little rebel, we like you :)