Forums / Managing Customers and Orders / How to Change Invoice Number to YYYYMMDDxxxx?

How to Change Invoice Number to YYYYMMDDxxxx?

Views: 4,999

Results 1 to 16 of 16
13 Aug 2011, 3:33 AM
#1
iddy avatar

iddy

Zen Follower

Join Date:
Jan 2009
Posts:
119
Plugin Contributions:
0

How to Change Invoice Number to YYYYMMDDxxxx?

Hi,
Is it possible to change the invoice numbers to reflect the date the order was raised.. e.g the fifth invoice raised on 13 August 2011 would have the invoice number 201108130005?

I've searched the forum and found this post but i don't know how to change it. Can anybody help me?

Thanks

It's easy to modify the order number shown on the invoice so that it includes the year of the order.
For example, if you have order number xyz, ordered in 2008 and want to display it on the invoice as Invoice No. xyz-2008 you can edit the file admin/invoices.php...
find this line of code at about line 141:

    <td class="main"><b><?php echo ENTRY_ORDER_ID . $oID; ?></b></td>

and replace it with this:

    <td class="main"><b><?php echo ENTRY_ORDER_ID . $oID . '-' . date(Y,strtotime($order->info['date_purchased'])) ; ?></b></td>

Then all your invoice numbers will include the year of the order, without ever having to update anything manually.

13 Aug 2011, 8:52 AM
#2
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: How to Change Invoice Number to YYYYMMDDxxxx?

What about that post wasn't clear ?

13 Aug 2011, 9:10 AM
#3
iddy avatar

iddy

Zen Follower

Join Date:
Jan 2009
Posts:
119
Plugin Contributions:
0

Re: How to Change Invoice Number to YYYYMMDDxxxx?

Its probably just that i cant read /dont understand php.
If i put that code in i get "Invoice No. xyz-2011"?

so I'm assuming...
$oID . gives me xyz
'-' gives me -
. date(Y,strtotime($order->info['date_purchased'])) gives me 2011?

What will give me yyyymmdd and is it just a matter of reversing it so i have yyymmddxyz?

is this a valid code?

<td class="main"><b><?php echo ENTRY_ORDER_ID date(Y,strtotime($order->info['date_purchased'])) . $oID . ; ?></b></td>
13 Aug 2011, 10:31 AM
#4
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: How to Change Invoice Number to YYYYMMDDxxxx?

Not quite. The dot before the semi-colon would give you a problem, and you will probably want to use "Ymd" rather than "Y" to give you the month and day too.

However, this won't restart the numerical part each day. If the last number today was 5, the first tomorrow will be 6.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

13 Aug 2011, 1:40 PM
#5
iddy avatar

iddy

Zen Follower

Join Date:
Jan 2009
Posts:
119
Plugin Contributions:
0

Re: How to Change Invoice Number to YYYYMMDDxxxx?

thanks kuroi, i'll remove the dot in question and change the Y. the end bit not changing is close enough to what i wanted to do (now that i know how its going to work)

thanks again for your help

14 Sep 2011, 11:09 AM
#6
tonyb6 avatar

tonyb6

New Zenner

Join Date:
Mar 2010
Posts:
77
Plugin Contributions:
0

Re: How to Change Invoice Number to YYYYMMDDxxxx?

Hi, I've been looking at the above and cant get the below code to work. My invoice numbers are just continuing to role over as normal without the Year Month Date prefix!

<td class="main"><b><?php echo ENTRY_ORDER_ID date(YMD,strtotime($order->info['date_purchased'])) . $oID ; ?></b></td>

The code I'm replacing is in the admin/invoice.php file and is shown below.

<td class="main"><b><?php echo ENTRY_ORDER_ID . $oID; ?></b></td>

Am i doing something wrong?

Thanks
Tony

14 Sep 2011, 11:10 AM
#7
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: How to Change Invoice Number to YYYYMMDDxxxx?

The YMD needs quotes around it. Single or double, either will do.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

14 Sep 2011, 11:24 AM
#8
tonyb6 avatar

tonyb6

New Zenner

Join Date:
Mar 2010
Posts:
77
Plugin Contributions:
0

Re: How to Change Invoice Number to YYYYMMDDxxxx?

still not having it!

I dont have to change anything in the DB do I? field length etc??

14 Sep 2011, 11:35 AM
#9
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: How to Change Invoice Number to YYYYMMDDxxxx?

You're missing a concatenation dot between ENTRY_ORDER_ID and the date function.

i.e. should read > ENTRY_ORDER_ID . date("YMD", etc

and this won't change your underlying order numbers, just prepend the date when displaying in this specific location.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

14 Sep 2011, 12:04 PM
#10
tonyb6 avatar

tonyb6

New Zenner

Join Date:
Mar 2010
Posts:
77
Plugin Contributions:
0

Re: How to Change Invoice Number to YYYYMMDDxxxx?

thanks for the advice but its still not having it. I'll look at it again when I have more time.

thanks again.

14 Sep 2011, 12:22 PM
#11
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: How to Change Invoice Number to YYYYMMDDxxxx?

When clients bring me this sort of request, my first question is usually "how many more sales will you get from this?"

There's no obvious reason why this shouldn't work, but it's also not clear that there's business benefit that warrants spending more than a couple of minutes on it.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

16 Jan 2012, 4:38 AM
#12
racinjason avatar

racinjason

New Zenner

Join Date:
Jan 2012
Posts:
30
Plugin Contributions:
0

Re: How to Change Invoice Number to YYYYMMDDxxxx?

Try to just have the date in the invoice number 201201150000001
Copy and pasted the code in the first thread......not working

<td class="main"><b><?php echo ENTRY_ORDER_ID . $oID . '-' . date(Y,strtotime($order->info['date_purchased'])) ; ?></b></td>

What is wrong?

I don't want it to say date purchased if that is what is going to happen too.

17 Jan 2012, 2:54 PM
#13
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to Change Invoice Number to YYYYMMDDxxxx?

What exactly do you mean by "not working"? Does it do anything? The code as posted will give some custom text and the order number followed by date. What you want would take something like this ```php

<td class="main"><b><?php echo date('Ymd',strtotime($order->info['date_purchased'])) . $oID; ?></b></td> ``` Also, as mentioned, this will not affect the actual order number at all, or its display in any other location. If you really want the order number itself to work as described, you could schedule a cron job to run at midnight every day and reset the next order number to the date as shown plus whatever quantity of zeros.
17 Jan 2012, 9:02 PM
#14
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to Change Invoice Number to YYYYMMDDxxxx?

I don't know if it's compatible with ZC admin control of the db, but this article may be useful to someone wanting to actually identify order numbers by time period: Working with MySQL Events

I reset order numbers each year, so this year's orders start like 120001. Sites with higher order frequency may want different criteria.
See Admin->Tools->Store Manager to reset order numbers.

4 Feb 2012, 9:59 AM
#15
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: How to Change Invoice Number to YYYYMMDDxxxx?

racinjason:

Try to just have the date in the invoice number 201201150000001
Copy and pasted the code in the first thread......not working

<td class="main"><b><?php echo ENTRY_ORDER_ID . $oID . '-' . date(Y,strtotime($order->info['date_purchased'])) ; ?></b></td>

What is wrong?

I don't want it to say date purchased if that is what is going to happen too.The code as posted won't work because the the first parameter in the date function needs to be in quotes.

This would be easier to diagnose if you explained where you'd put the code, and specifically what symptoms, results or lack of them lead you to conclude that it's "not working".

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

1 Mar 2012, 6:03 PM
#16
mqeprez avatar

mqeprez

New Zenner

Join Date:
Feb 2012
Posts:
10
Plugin Contributions:
0

Re: How to Change Invoice Number to YYYYMMDDxxxx?

Have been reading the post here and have a question..
What if all we wanted was to put a prefix to the order number i.e. "w1000" ? How would that be done? thru the database or code?
Thanks!