This topic is locked
[SOLVED]

 Shipping Number

3/14/2011 11:53:10 AM
PHPRunner General questions
J
joker author

Hello I was wondering if someone could point me in the right direction.
I have a database with workorder numbers and serial numbers. Several serial numbers can be on a workorder.
I am creating a page where workorder or serial numbers will be scanned and added to a shipping manifest. I'm not sure how to go about adding these workorder numbers (all serials that match) and individual serial numbers to a new database but also assign them a unique shipping manifest number.
When I create the manifest number field and set it as auto-increment, every line item is a different number. I need all workorder numbers and serial numbers added on the scan page to have ONE unique shipping manifest number. Any ideas?
My scan page looks like this:
Workorder/Serial

____ (input box)

____ (input box)

____ (input box)

____ (input box)

____ (input box)

____ (input box)

____ (input box)
SUBMIT button

T
tedwilder 3/14/2011

hello

Im not 100% sure I understand your request. But from I get you need one auto created number and then severals field that are filled with same previous number.

It's my choice to never use the autoincremential field for my own data in mysql because it's a lot of trouble like the one you are experiencing. of course I keep an auto incremential id but it's for internal purpose only It's not showned in my project neither . I never use it . It's just for the sake of mysql internal working. I use my own script to create incremential numbers this way I'm free to edit things a lot easier specialy when it comes to edit datas with a thirs party mysql front ( navicat/phpmyadmin). Just my opinion though..
So to create a new number that is based on previous record :

1/ in event " before process"

retrieve the last number ( here it's an example based on my own field format that are : CR201103001 for today for isntance )

$sql="select max(substr(numcourrier,9)) as mx from courrier where substr(numcourrier,7,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="CR";

$str2=date("Ym");

$str3=($data["mx"]+1);

$_SESSION["numcourrier"]= "$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);

$_SESSION["numcontenu"]=$_SESSION["numcourrier"];
2/ as you can see I put the value in a session variable, so when the add page is loaded I can use them to set the default field value to my new next available number in a read only field so user cant change the number . so if you need severals fields to have same values as master field just put " $_SESSION["numcourrier"] " in editor under "default value " for this field.
3/ Of course now 5.3 has autofill so you can create lookup field and check autofill : it will enter values it has retrieve from another table or same table.
Hope this will help u to find a solution.

J
joker author 3/14/2011



hello

Im not 100% sure I understand your request. But from I get you need one auto created number and then severals field that are filled with same previous number.

It's my choice to never use the autoincremential field for my own data in mysql because it's a lot of trouble like the one you are experiencing. of course I keep an auto incremential id but it's for internal purpose only It's not showned in my project neither . I never use it . It's just for the sake of mysql internal working. I use my own script to create incremential numbers this way I'm free to edit things a lot easier specialy when it comes to edit datas with a thirs party mysql front ( navicat/phpmyadmin). Just my opinion though..
So to create a new number that is based on previous record :

1/ in event " before process"

retrieve the last number ( here it's an example based on my own field format that are : CR201103001 for today for isntance )

$sql="select max(substr(numcourrier,9)) as mx from courrier where substr(numcourrier,7,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="CR";

$str2=date("Ym");

$str3=($data["mx"]+1);

$_SESSION["numcourrier"]= "$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);

$_SESSION["numcontenu"]=$_SESSION["numcourrier"];
2/ as you can see I put the value in a session variable, so when the add page is loaded I can use them to set the default field value to my new next available number in a read only field so user cant change the number . so if you need severals fields to have same values as master field just put " $_SESSION["numcourrier"] " in editor under "default value " for this field.
3/ Of course now 5.3 has autofill so you can create lookup field and check autofill : it will enter values it has retrieve from another table or same table.
Hope this will help u to find a solution.


Thank you for looking at this. You are correct with your suggestion and I think I have half the problem solved by being able to call the last manifest number used and store that in a session variable.
My main problem is that i need some way for the user to say he is finished adding to this manifest number so that the next user doesn't get the last manifest number but a new one for his shipping job.
Maybe I need two new buttons -> one that says "New Manifest" and one for "Add to Open Manifest". I don't know. Do you see any easier way to do this?

T
tedwilder 3/14/2011

well it's quite easy : I dont have such problem because I never have 2 users entering at the same time data.

howevever you can :

1/ enabling table locking in phprunner : record is locked when a user is using it so a another user wont be able to create a record at the same time. ( I enjoy phprunner however I noticed severals time this function is somethimes buggous)
2/ if you need severals user to be able to create record at the same time and to generate new numbers for each you need to create a ( at least it's what comes to my mind right away) temporary table :

in the before process right after the code that define your number, you need to insert that number into your temporary table ( very easy : $sql = " insert into sometemptable where shippingnumber=".$SESSION_["numbercreate above"] (execept the 1st line of code in previous post will look into the temporary table instead of real record)

This way the user can stay on the add page as long as he wants, if another user wants to also add a record at the same time while 1st user has not finished , he will get the last created number from temporary table + 1 .

When user has filled the whole form and is ready to close/ validate the manifest , in the event "after record" you can delete the previous temporary field with a simple $sql DEL ..where number= $SESSION .. and clear session variable.
this way any user at any time always get the next number available without creating conflict.

I guess you could also fine tuning it in case a user start a manifest but never close it,( computer crash and has to be restarted for instance ) you should adding in the tomporary table a userowner field and statut field ( ex 1 for recorded 0 for in progress).this way if you edit before process php accordingly you could retrieve the number that was affected to user prior crash).
I guess we both agree that it would be nice if phprunner had an autonumbering customized function embedded <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57046&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

J
joker author 3/15/2011



well it's quite easy : I dont have such problem because I never have 2 users entering at the same time data.

howevever you can :

1/ enabling table locking in phprunner : record is locked when a user is using it so a another user wont be able to create a record at the same time. ( I enjoy phprunner however I noticed severals time this function is somethimes buggous)
2/ if you need severals user to be able to create record at the same time and to generate new numbers for each you need to create a ( at least it's what comes to my mind right away) temporary table :

in the before process right after the code that define your number, you need to insert that number into your temporary table ( very easy : $sql = " insert into sometemptable where shippingnumber=".$SESSION_["numbercreate above"] (execept the 1st line of code in previous post will look into the temporary table instead of real record)

This way the user can stay on the add page as long as he wants, if another user wants to also add a record at the same time while 1st user has not finished , he will get the last created number from temporary table + 1 .

When user has filled the whole form and is ready to close/ validate the manifest , in the event "after record" you can delete the previous temporary field with a simple $sql DEL ..where number= $SESSION .. and clear session variable.
this way any user at any time always get the next number available without creating conflict.

I guess you could also fine tuning it in case a user start a manifest but never close it,( computer crash and has to be restarted for instance ) you should adding in the tomporary table a userowner field and statut field ( ex 1 for recorded 0 for in progress).this way if you edit before process php accordingly you could retrieve the number that was affected to user prior crash).
I guess we both agree that it would be nice if phprunner had an autonumbering customized function embedded <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57071&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />


Thanks for all of your input. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57071&image=2&table=forumreplies' class='bbc_emoticon' alt=':)' /> I like the idea you have in number 2 suggesting the use of a temporary table. That makes a lot of sense to me, plus I can set up PHPRunner to allow users to view other users data but not edit.
Yes, It would be nice if there were some sort of auto-numbering function perhaps with the ability to append letters to the beginning of the auto-numbered field.