# How to format Invoice Numbers incremented automatically?

**URL:** <https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551>\
**Category:** Financial modules\
**Tags:** Linux, Invoices\
**Created:** [November 14, 2023, 12:29pm UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551 "2023-11-14T12:29:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![RiseValInfotech](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@RiseValInfotech](https://www.dolibarr.org/forum/u/RiseValInfotech)\
**Post date:** [November 14, 2023, 12:29pm UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/1 "2023-11-14T12:29:57Z")

</div>

Need help to auto number invoices, proposals and other documents. General convention followed in India is to identify these documents using financial year. Like FA2324-0001 is the Invoice done on Financial Year 2324 with number 1.

 ![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/7/7772f14a7f02fd4cc53ee9db68e0b8ebc4d6a21b.png)

Please see the above graphic. I am unable to automatically set current year plus one so as to make a financial year format.

Can you please help how to do this or point me to the code where I can do changes.

thanks  
yesbee

---

<div class="post-metadata">

**Author:** ![tiller](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@tiller](https://www.dolibarr.org/forum/u/tiller)\
**Post date:** [November 16, 2023, 2:10am UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/2 "2023-11-16T02:10:41Z")

</div>

have you tried wrapping the digit and + in curly braces{}?  
FA{yy}{yy+1}-{0000}

Skeptical, but give it a try

 ![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/7/747a9bbb2c948320f7a07258d748463a120eb5bc.png)

---

<div class="post-metadata">

**Author:** ![RiseValInfotech](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@RiseValInfotech](https://www.dolibarr.org/forum/u/RiseValInfotech)\
**Post date:** [November 27, 2023, 5:11am UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/3 "2023-11-27T05:11:22Z")

</div>

Ok. This shows logical thinkers think in similar pattern. But it didnt work in Dolibarr. ☹

---

<div class="post-metadata">

**Author:** ![DG-Rilling](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DG-Rilling](https://www.dolibarr.org/forum/u/DG-Rilling)\
**Post date:** [November 27, 2023, 12:01pm UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/4 "2023-11-27T12:01:07Z")

</div>

We use this to automatically reset the numbering.  
{yy} is here exchanged with the year from the systemdate.

![grafik](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/9/9045642345710dcee0b099cf151a60c4f261bdcc.png)

Each January the counter is reseted.  
 ![grafik](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/f/f440342d5725a17a90ec257f1a4606503a31efdd.png)

Hope this helps…

---

<div class="post-metadata">

**Author:** ![RiseValInfotech](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@RiseValInfotech](https://www.dolibarr.org/forum/u/RiseValInfotech)\
**Post date:** [December 13, 2023, 4:21am UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/5 "2023-12-13T04:21:01Z")

</div>

Hi,

Thanks a ton for the reply. However, I was trying to achieve standard invoice numbering practice in India. Like IN2324-0001 (where 23 is current year achieved by {yy}) But I could not achieve {yy+1} as 24.

@eldy , @ksar any help please.

thanks and regards,  
yesbee

---

<div class="post-metadata">

**Author:** ![sonikf](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@sonikf](https://www.dolibarr.org/forum/u/sonikf)\
**Post date:** [December 13, 2023, 2:45pm UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/6 "2023-12-13T14:45:43Z")

</div>

Ηι @RiseValInfotech  
If at years end last generated invoice is IN2324-0101 then for next fiscal year would be IN2425-0001 or IN2425-0102?

---

<div class="post-metadata">

**Author:** ![DG-Rilling](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DG-Rilling](https://www.dolibarr.org/forum/u/DG-Rilling)\
**Post date:** [December 13, 2023, 3:11pm UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/7 "2023-12-13T15:11:13Z")

</div>

If you start every year with IN2324-0001 then use the mask as i wrote above and from 01.01.2024 your invoices start automatically with IN2424-0001.  
Mask = IN{yy}24-{0000@0}

> [@DG-Rilling](#):
>
> {yy} is here exchanged with the year from the systemdate.

However, if you want your counter to be consecutive over the years, then unfortunately I can’t help you.

---

<div class="post-metadata">

**Author:** ![pcbleu](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/pcbleu/32/3120_2.png) [@pcbleu](https://www.dolibarr.org/forum/u/pcbleu)\
**Post date:** [December 13, 2023, 11:44pm UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/8 "2023-12-13T23:44:07Z")

</div>

Hello 🙂

in version 18.0.3, you can obtain this result with this change in htdocs/core/lib/functions2.lib.php…

 ![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/1/14c7d2266ca91cc6519264b08d823244c6718aa1.png)

Good continuation

---

<div class="post-metadata">

**Author:** ![inpilankar](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/inpilankar/32/7239_2.png) [@inpilankar](https://www.dolibarr.org/forum/u/inpilankar)\
**Post date:** [July 22, 2024, 6:02pm UTC](https://www.dolibarr.org/forum/t/how-to-format-invoice-numbers-incremented-automatically/24551/9 "2024-07-22T18:02:10Z")

</div>

In version 19.0.2

To have add dash, hypen or minus signs between current and next year. I used the following code in `htdocs/core/lib/functions2.lib.php`

```auto
		// We replace special codes except refclient
		if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype != '=') {	// yearoffsettype is - or +, so we don't want current year
			$numFinal = preg_replace('/\{yyyy\}/i', date("Y", $date) + $yearoffset, $numFinal);
			$numFinal = preg_replace('/\{yy\}/i', date("y", $date) + $yearoffset, $numFinal);
			$numFinal = preg_replace('/\{y\}/i', substr(date("y", $date), 1, 1) + $yearoffset, $numFinal);
		} else { // we want yyyy to be current year
			$numFinal = preg_replace('/\{yyyy\}/i', date("Y", $date), $numFinal);
			//$numFinal = preg_replace('/\{yy\}/i', date("y", $date), $numFinal); // disable default {yy} to be current year
			$numFinal = preg_replace('/\{yy\}/i', date("y", $date). '-' .(intval(date("y", $date)) + 1), $numFinal); // Modified Date to be 24-25 if using {yy}
			$numFinal = preg_replace('/\{y\}/i', substr(date("y", $date), 1, 1), $numFinal);
		}

```

But this doesn’t get reflected throughout the system, like on invoice no. while on invoice card or generatting PDF file
