473,799 Members | 3,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(checknum ber)

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

Mar 1 '07 #1
3 6013
"Kris" <Kr************ *@gmail.comwrot e in message
news:11******** **************@ j27g2000cwj.goo glegroups.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(checknum ber)

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.comwrot e in message

news:11******** **************@ j27g2000cwj.goo glegroups.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(checknum ber)
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.comwrot e in message
news:11******** **************@ j27g2000cwj.goo glegroups.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(checknum ber)

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
1897
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 should be equal to orders.invoiceId in my strWhere clause shown below.Can somebody help me ? strWhere = "orders.InvoiceID = " & Forms!!.Value Dim varRow As Variant For Each varRow In frm.ListInvoices.ItemsSelected
3
2840
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 table using append queries to get transactions from the 2 tables between selected dates. then draw these into a report grouped by the Sales and Facilities Hire This all works fine. However the customer requires invoices (reports) to have consecutive...
15
5284
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 information and one of the field (the user cannot change the info in it.) is invoice #. Right now, everythime i click on "Create new invoice", the invoice # add 1. But my problem is sometime the employee dont fill it (for x reason) and shut it down,...
2
1717
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 sales transaction info including a field named "invno". Then created a form to input the sales and in the form is where I want
2
1650
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 then give you the invoices for the selected month. 2) The first is adding the number of outstanding invoices in the report footer in the Invoice. I use this text box = IIf(Min()<Date()-30,"Please Pay Up","") to calcualte if the invoice had been...
14
10483
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 issue 1 receipt with 12 payments (1 check for each month of the year) and then, everytime a check comes to delivery, the invoice is printed out with the receipt number. What would be the relation between the receipt/invoice tables and how do I...
6
5909
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 some customers paid 2 - 3 times for 1 invoices (different amount and date) so when I total the invoice amount it duplicated since the report will show the same invoice amount for 2 payments for example: invoice number invoice amount ...
4
6677
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 entry fields and so there is a button you press which then takes to through to a print preview of the invoice and you print out the invoice but recent ly this message ahs started appearing and does not allow you to view the print preview of the invoice...
12
3871
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 way to reset the number field (line-number field) to 0 for each invoice created. This would be incremented by 1 for each product purchase. Example below: Invoice # line number product price 0123 ...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10485
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10252
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10231
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.