473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

invoice number

hi all,

i am new to php.how to generate invoice number (EX:INV2008001) this format.

plz reply me the code....


thanks
palani
Feb 20 '08 #1
21 8518
MarkoKlacar
296 Expert 100+
Hi,

I can't spoonfeed you the code, but you'll want to have a look at rand as a start.

Should be pretty straight forward for you.
Feb 20 '08 #2
Markus
6,050 Expert 4TB
Hi,

I can't spoonfeed you the code, but you'll want to have a look at rand as a start.

Should be pretty straight forward for you.
That could produce a duplicate invoice number, though.

I think the best way would be to have an invoice number : INV20000001, and then increment that.

Save it in a db maybe.
Feb 20 '08 #3
hsriat
1,654 Expert 1GB
That could produce a duplicate invoice number, though.

I think the best way would be to have an invoice number : INV20000001, and then increment that.

Save it in a db maybe.
Or use this...
[php]
$new_invoice = gettimeofday();
$new_invoice = $new_invoice[sec];
[/php]

This will help if the invoice is generated not too fast. (Not more than once in a sceond)
Feb 20 '08 #4
MarkoKlacar
296 Expert 100+
That's true, as you say you should have a combination.

My post was a bit clumsy, thanks for pointing it out.
Feb 20 '08 #5
Markus
6,050 Expert 4TB
Or use this...
[php]
$new_invoice = gettimeofday();
$new_invoice = $new_invoice[sec];
[/php]

This will help if the invoice is generated not too fast. (Not more than once in a sceond)
But still, it's not relevant to the invoices..

You'd typically (or is it just me) want to be able to keep track of the amount of invoices sent.. and don't invoice numbers generally go up as they are a way of tracking someone?
Feb 20 '08 #6
hsriat
1,654 Expert 1GB
But still, it's not relevant to the invoices..

You'd typically (or is it just me) want to be able to keep track of the amount of invoices sent.. and don't invoice numbers generally go up as they are a way of tracking someone?
Yeah, that will only help if you have to keep them unique. Not a counting of all.
But with this there is no db query required.

Or one other option can be...
- make a file with 0 written inside it.
- every time you create a new invoice, read that file and create the invoice like : [php]
//$file_content = content of the saved file
$invoice = "INV";
for ($i = 0; $i<10 - strlen($file_content); i++)
$invoice .= "0";
$invoice .= $file_content;

$file_content++;
//then save $file_content to the same file.
[/php]
Feb 20 '08 #7
Markus
6,050 Expert 4TB
I catch dig your jammin!

But, ultimately, it is better to use a database to keep track of records.

Look at us, i bet the OP has forgotten about this thread..
Feb 20 '08 #8
hsriat
1,654 Expert 1GB
I catch dig your jammin!

But, ultimately, it is better to use a database to keep track of records.

Look at us, i bet the OP has forgotten about this thread..
Yeh you are right in both the things...

1. Its better to use db, coz you might need to keep some other info about the invoice.. eg.. date, time, customer etc.

2. OP has forgotten about the thread.
Feb 20 '08 #9
TheServant
1,168 Expert 1GB
Good discussion though. How about using database table attributes:
INT(5) ZEROFILL AUTO_INCREMENT ? That way everytime a row is added it will increase by one but will appear as 00001 then 00002 etc...

Good idea/bad idea? I ask cos this is how I plan to set my system up.
Feb 20 '08 #10
ronverdonk
4,258 Expert 4TB
Good discussion though. How about using database table attributes:
INT(5) ZEROFILL AUTO_INCREMENT ? That way everytime a row is added it will increase by one but will appear as 00001 then 00002 etc...

Good idea/bad idea? I ask cos this is how I plan to set my system up.
Nothing wrong with the idea in itself, BUT ... never reorganize that table because your run the risk that it will be renumbered (assuming you sometimes delete rows from the table).

Ronald
Feb 20 '08 #11
TheServant
1,168 Expert 1GB
Nothing wrong with the idea in itself, BUT ... never reorganize that table because your run the risk that it will be renumbered (assuming you sometimes delete rows from the table).

Ronald
OK a little confused by what you mean. If i make a table:
00001 John
00002 Zed
00003 Adam

Then delete Row 2 (Zed). The next time I INSERT a row it will become:
00001 John
00003 Adam
00004 Tom

No repeat?

If I order by alphabetical order:
00003 Adam
00001 John
00004 Tom

Then INSERT a new row, I think it will be:
00003 Adam
00001 John
00004 Tom
00005 Wayne

Let me know if I am wrong, and also let me know if this is not what you meant. Thanks for your input!
Feb 21 '08 #12
Markus
6,050 Expert 4TB
Good discussion though. How about using database table attributes:
INT(5) ZEROFILL AUTO_INCREMENT ? That way everytime a row is added it will increase by one but will appear as 00001 then 00002 etc...

Good idea/bad idea? I ask cos this is how I plan to set my system up.
I like, and i didn't know about the ZEROFILL!
So it shall now be with me on my travels!
Feb 21 '08 #13
TheServant
1,168 Expert 1GB
I like, and i didn't know about the ZEROFILL!
So it shall now be with me on my travels!
w00t! I actually knew something someone didn't know! No offense markusn00b, u have already taught me so much, I'm glad to contribute something useful!
Feb 21 '08 #14
Markus
6,050 Expert 4TB
w00t! I actually knew something someone didn't know! No offense markusn00b, u have already taught me so much, I'm glad to contribute something useful!
Well, well!

Student has become the teacher!
Feb 21 '08 #15
TheServant
1,168 Expert 1GB
Anyway, Ronald, how about my question above?
Feb 21 '08 #16
ronverdonk
4,258 Expert 4TB
Anyway, Ronald, how about my question above?
Sorry, I have been away for a day.
What I meant is that when you REORGANIZE your table all the auto_increment values are also reorganized. So your table
Expand|Select|Wrap|Line Numbers
  1. 00001 John
  2. 00003 Adam
  3. 00004 Tom
  4. 00005 Wayne
wll after the reorganize look:
Expand|Select|Wrap|Line Numbers
  1. 00001 John
  2. 00002 Adam
  3. 00003 Tom
  4. 00004 Wayne
But of course, if you never reorganize, that's fine. And if your auto_increment numbers do not represent values like an invoice number, fine. My remark was just a liitle warning.

Ronald
Feb 21 '08 #17
TheServant
1,168 Expert 1GB
Sorry, I have been away for a day.
What I meant is that when you REORGANIZE your table all the auto_increment values are also reorganized. So your table
Expand|Select|Wrap|Line Numbers
  1. 00001 John
  2. 00003 Adam
  3. 00004 Tom
  4. 00005 Wayne
wll after the reorganize look:
Expand|Select|Wrap|Line Numbers
  1. 00001 John
  2. 00002 Adam
  3. 00003 Tom
  4. 00004 Wayne
But of course, if you never reorganize, that's fine. And if your auto_increment numbers do not represent values like an invoice number, fine. My remark was just a liitle warning.

Ronald
Fair enough. I think I am thinking of something different. When you say reorganise, do you mean ORDERBY or is there a REORGANISE function?
Feb 21 '08 #18
ronverdonk
4,258 Expert 4TB
Fair enough. I think I am thinking of something different. When you say reorganise, do you mean ORDERBY or is there a REORGANISE function?
The original question in this thread was about invoices.
By reorganize I mean just a SELECT INSERT sequence wehereby you get rid of the holes in your table sequences. MySQL does not have a REORGANIZE function (yet).

Ronald
Feb 21 '08 #19
TheServant
1,168 Expert 1GB
Sorry to go off topic a bit, but I think the OP has left:
If I have a hole and go INSERT, it shouldn't plug up the hole but continue the sequence. I have tried this before, so I guess I want to know how to plug that hole so I can avoid doing it!
Feb 22 '08 #20
ronverdonk
4,258 Expert 4TB
Sorry to go off topic a bit, but I think the OP has left:
If I have a hole and go INSERT, it shouldn't plug up the hole but continue the sequence. I have tried this before, so I guess I want to know how to plug that hole so I can avoid doing it!
This goes beyond the thread problem. I will ans wer this and then close this discussion. I was not talking about a simple INSERT, but re-arranging the auto_increment index into a new table using INSERT SELECT...

People do that because they have a very heavily changing table and are afraid that the auto_increment index is running out. (an INT as key and a million changes per day can get you into such a situation).


Ronald
Feb 22 '08 #21
Markus
6,050 Expert 4TB
Forgot to close it ;)
Feb 22 '08 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hohn Upshew | last post by:
I have a rather complicated function for updating from a list box called ListInvoices I want after updating to have a message saying " Invoice number ... has been updated."The invoice number...
3
by: David B | last post by:
I am creating invoices for an app I am busy with. The transactions for the invoice come from 2 tables which store Sales and Facilities Hire. The current arrangement is that I create a temp...
15
by: NomoreSpam4Me | last post by:
Hi there i have a little problem with my invoice. Here it is: i have a main menu with buttons, one of my button is "Create new invoice", when click on it a form pop up so i can enter my...
2
by: samdev | last post by:
I need to set up invoices so each new invoice has next available number assigned. I have a table Named "InvoiceNumbers" that has a single field = "nextnumber" A 2nd table that contains the...
2
by: yellowarmy | last post by:
Theres two problems i have. 1) Theres a question i have to answer in a mock is that the company does invoices every month but i need it for to select invoice and then select the month whcih would...
3
by: Kris | last post by:
I need to create a valid mod10 or luhn number that can be attached to an invoice, I have found several examples showing how to validate a credit card number or validate a number using mod10/luhn. ...
14
by: eyalco | last post by:
I'm building a receipt/invoice database - I've started with the invoice first, then the receipt. I have invoice = parents and sons + receipt = parents and sons tables + a customer table. I want to...
6
by: ConfusedMay | last post by:
Hi I need some helps in calculating the invoice amount in access 2003 report. Basically I have an access report that shows invoice#, invoice amount, payment amount, and payment date. The problem is...
4
by: gazza10001 | last post by:
Hi i hope you can help my company uses access and has modified for its needs usually what happens is you serach for the invoice by its number and then it brings all the information up such as...
12
by: Coni | last post by:
Hi All, I am working in Access to print Invoices. On each invoice there is a line number column which is a field to number each line for a product purchase. I would like to know if there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.