invoice number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • palanidharma
    New Member
    • Feb 2008
    • 10

    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
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    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.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by MarkoKlacar
      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.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by markusn00b
        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)

        Comment

        • MarkoKlacar
          Recognized Expert Contributor
          • Aug 2007
          • 296

          #5
          That's true, as you say you should have a combination.

          My post was a bit clumsy, thanks for pointing it out.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by hsriat
            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?

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by markusn00b
              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_co ntent); i++)
              $invoice .= "0";
              $invoice .= $file_content;

              $file_content++ ;
              //then save $file_content to the same file.
              [/php]

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                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..

                Comment

                • hsriat
                  Recognized Expert Top Contributor
                  • Jan 2008
                  • 1653

                  #9
                  Originally posted by markusn00b
                  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.

                  Comment

                  • TheServant
                    Recognized Expert Top Contributor
                    • Feb 2008
                    • 1168

                    #10
                    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.

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      Originally posted by TheServant
                      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

                      Comment

                      • TheServant
                        Recognized Expert Top Contributor
                        • Feb 2008
                        • 1168

                        #12
                        Originally posted by ronverdonk
                        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!

                        Comment

                        • Markus
                          Recognized Expert Expert
                          • Jun 2007
                          • 6092

                          #13
                          Originally posted by TheServant
                          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!

                          Comment

                          • TheServant
                            Recognized Expert Top Contributor
                            • Feb 2008
                            • 1168

                            #14
                            Originally posted by markusn00b
                            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!

                            Comment

                            • Markus
                              Recognized Expert Expert
                              • Jun 2007
                              • 6092

                              #15
                              Originally posted by TheServant
                              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!

                              Comment

                              Working...