473,396 Members | 1,918 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,396 software developers and data experts.

Invoice check number

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.

Example:
invoice number = 700123
invoice check number 700123(checknumber)

that check number should make the entire invoice number able to
validate using mod10/luhn

Mar 1 '07 #1
3 5979
"Kris" <Kr*************@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
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.

Example:
invoice number = 700123
invoice check number 700123(checknumber)

that check number should make the entire invoice number able to
validate using mod10/luhn

Google is your friend.

I cobbled this together from several sources; will it help?

Validate it thoroughly before relying on it!
<?php
$inv = "700123";
echo $inv . checkdigit($inv);

function checkdigit($num) {
/*
* 1. Reverse the number
* 2. Multiply all the digits in odd positions (The first digit, the third
digit, etc) by 2.
* 3. If any one is greater than 9 subtract 9 from it.
* 4. Sum those numbers up
* 5. Add the even numbered digits (the second, fourth, etc) to the number
you got in the previous step
* 6. The check digit is the amount you need to add to that number to make
a multiple of 10.
* So if you got 68 in the previous step the check digit would be 2.
* You can calculate the digit in code using checkdigit = ((sum / 10 +
1) * 10 - sum) % 10
* -- http://www.darkcoding.net/index.php/.../luhn-formula/
*/
$sum = 0;
$pos = 0;
$rev = strrev($num);
$len = strlen($num);
if ($len % 2 == 0) $len += 1;
while ($pos < $len) {
$odd = $rev[$pos] * 2;
if ($odd 9) {
$odd -= 9;
}
$sum += $odd;
if ($pos != ($len - 2)) {
$sum += $rev[$pos +1];
}
$pos += 2;
}
return ((floor($sum/10) + 1) * 10 - $sum) % 10;
}
?>
Mar 1 '07 #2
On Mar 1, 11:42 am, "McKirahan" <N...@McKirahan.comwrote:
"Kris" <Kristian.Nis...@gmail.comwrote in message

news:11**********************@j27g2000cwj.googlegr oups.com...
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.
Example:
invoice number = 700123
invoice check number 700123(checknumber)
that check number should make the entire invoice number able to
validate using mod10/luhn

Google is your friend.

I cobbled this together from several sources; will it help?

Validate it thoroughly before relying on it!

<?php
$inv = "700123";
echo $inv . checkdigit($inv);

function checkdigit($num) {
/*
* 1. Reverse the number
* 2. Multiply all the digits in odd positions (The first digit, the third
digit, etc) by 2.
* 3. If any one is greater than 9 subtract 9 from it.
* 4. Sum those numbers up
* 5. Add the even numbered digits (the second, fourth, etc) to the number
you got in the previous step
* 6. The check digit is the amount you need to add to that number to make
a multiple of 10.
* So if you got 68 in the previous step the check digit would be 2.
* You can calculate the digit in code using checkdigit = ((sum / 10 +
1) * 10 - sum) % 10
* --http://www.darkcoding.net/index.php/credit-card/luhn-formula/
*/
$sum = 0;
$pos = 0;
$rev = strrev($num);
$len = strlen($num);
if ($len % 2 == 0) $len += 1;
while ($pos < $len) {
$odd = $rev[$pos] * 2;
if ($odd 9) {
$odd -= 9;
}
$sum += $odd;
if ($pos != ($len - 2)) {
$sum += $rev[$pos +1];
}
$pos += 2;
}
return ((floor($sum/10) + 1) * 10 - $sum) % 10;}

?>
looks like its doing the job, great.
Mar 1 '07 #3
Nel

"McKirahan" <Ne**@McKirahan.comwrote in message
news:4q******************************@comcast.com. ..
"Kris" <Kr*************@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
>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.

Example:
invoice number = 700123
invoice check number 700123(checknumber)

that check number should make the entire invoice number able to
validate using mod10/luhn


Google is your friend.

I cobbled this together from several sources; will it help?

Validate it thoroughly before relying on it!
<?php
$inv = "700123";
echo $inv . checkdigit($inv);

function checkdigit($num) {
/*
* 1. Reverse the number
* 2. Multiply all the digits in odd positions (The first digit, the third
digit, etc) by 2.
* 3. If any one is greater than 9 subtract 9 from it.
* 4. Sum those numbers up
* 5. Add the even numbered digits (the second, fourth, etc) to the number
you got in the previous step
* 6. The check digit is the amount you need to add to that number to make
a multiple of 10.
* So if you got 68 in the previous step the check digit would be 2.
* You can calculate the digit in code using checkdigit = ((sum / 10 +
1) * 10 - sum) % 10
* -- http://www.darkcoding.net/index.php/.../luhn-formula/
*/
$sum = 0;
$pos = 0;
$rev = strrev($num);
$len = strlen($num);
if ($len % 2 == 0) $len += 1;
while ($pos < $len) {
$odd = $rev[$pos] * 2;
if ($odd 9) {
$odd -= 9;
}
$sum += $odd;
if ($pos != ($len - 2)) {
$sum += $rev[$pos +1];
}
$pos += 2;
}
return ((floor($sum/10) + 1) * 10 - $sum) % 10;
}
?>
Hi

Your example works well but produces two Notices in php.

Nel.
Output follows:
_______________________________________________

Notice: Uninitialized string offset: 6 in luhn.php on line 23

Notice: Uninitialized string offset: 7 in luhn.php on line 29
7001233
Mar 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.