Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Increment invoice number based on set cycles

I am creating incrementing invoice numbers, like so: AABBBB1122.

'A' and 'B' are bound to identifiers in my code. But the digits I need to be month and year, respectively. For example: 0821 (august, 2021). I don't want to connect it to a calendar in any way. If possible I would like to define a starting date, and increment from there.

That is: 0821 would have to be incremented to 0921, 1021, 1121, 1221 - before the year is incremented as well; 0122.

How can I do that?

What I've got so far:

string AA {
    get { return this.IdentifierA.Substring(0, 2);
    set { SetAndNotify(ref this.AA, value); }
}

string BB {
    get { return this.IdentifierB.Substring(0, 4);
    set { SetAndNotify(ref this.BB, value); }
}

string InvoiceNumber {
   get { return String.Concat(AA + BB + /* what goes here? */).ToUpper(); }
   set { SetAndNotify(ref this.InvoiceNumber, value);
like image 498
Ole M Avatar asked Nov 19 '25 01:11

Ole M


1 Answers

Sounds like a peculiar way to do invoice numbers.. You are saying you don't want it based on the current date, but to just increment in a MMYY style?

Well given a typical auto-increment int KEY, which goes up by 1 for each invoice, use:

((KEY % 12).ToString("00")+(KEY/12).ToString("00"))

Start KEY at 12*21+8 to start with 0821.

.. But based on the invoice requirement I think what you must surely be asking for is:

(DateTime.Now.Month.ToString("00")+DateTime.Now.Year.ToString("00"))
like image 172
Chris Kuliukas Avatar answered Nov 20 '25 15:11

Chris Kuliukas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!