This topic is locked
[SOLVED]

 Generating invoice Number in Sequence based on last entry

1/27/2014 4:31:18 PM
PHPRunner General questions
P
prab author

Hello,
I am creating a form in PHPRunner 7. I need to generate an Unique invoice number stating from 3000001. And then auto increase from last entry and cant be duplicated.

Please help.
Thanks

Prab

Sergey Kornilov admin 1/28/2014

Sure, it's possible. You can execute a SQL query in BeforeAdd event, get the latest number and assign it to your invoice number field.
Assuming that table name is Invoices and field name is InvoiceNumber
BeforeAdd event:

$values["InvoiceNumber"]=DBLookup("select max(InvoiceNumber)+1 from Invoices");
P
prab author 1/28/2014

Thanks for quick reply.

My field name is :Invoice

Table is: dataentry
So on Add page --- Before record added: i added

$values['Invoice']=DBLookup("select max(Invoice)+1 from dataentry");
I added the Syntax properly. For the first time i added Value my self and second time it should pickup value and +1. The field remains blank. Please let me know if i need to do something to the field its self or i am doing something wrong here.
Thanks

Sergey Kornilov admin 1/28/2014

This field will be populated when Submit button is clicked. You won't see it on the page.
Displaying this number on the page is not reliable. Two users can open this page at the same time and that would result in duplicate invoice number.

P
prab author 1/28/2014

Thank you sir for the explanation. Works Great.

A
Abul 1/28/2014

I apologizes for not solution but a question. How can we make this invoice# based on like "2014-day of the year-xxx" format? Do you have an idea? Thanks in advance for tips.