#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Php mysql invoice auto increment


    am working on a project on creating billing databse in PHP, MySQL.

    There is a table in MySQL:

    1.ID - (primary key, Auto increment)
    2.Party - (name of the party)
    3.Basic Amount -
    4.Service Tax amount - (12.36 % on Basic amount) (calculated automatically)
    5.Gross amount - (Basic amount + Service Tax amount) (calculated automatically)
    I have the following requirements :

    1.Bill no. will be as follows AB/ST/00001..2...3 etc./12-13 - pls. suggest how can i add this column in my database
    2.Service Tax amount will be calculated automatically and save on the database
    3.Gross amount will be calculated automatically and save on the database
  2. #2
  3. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    if your prefix is: AB/ST/0000
    Why not use the primary id and append it to this in php, makes it sortable also and less redundant

    something like so:
    PHP Code:
    <?php
     
    $prefix 
    "AB/ST/";

    $ids = array(1,10,22,33); //just some ids to simulate

    $leadingzeros '00000';

    //generate some invoicenumbers

    foreach($ids as $value){
        
    //check how many leading zero's are needed
        
    echo $prefix.substr($leadingzeros0, (-strlen($value))).$value.'<br />';
        
        
    }
    // outputs
    /*
    AB/ST/00001
    AB/ST/00010
    AB/ST/00022
    AB/ST/00033

    */
    ?>
    this way you can keep using the auto-increment functionality of the database
    Last edited by aeternus; December 31st, 2012 at 08:09 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Thanks for the reply.

    furthermore, can I make this as follows :

    ID - (PK) (INT)
    Prefix - AB/ (VAR)
    Suffix - /12-13 (VAR)
    BillNo. - (will be Prefix + ID + Suffix)

    now..pls. suggest how can i make this Bill No..in Mysql (i.e. the data will be saved in MYsql)
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    I think there's a big misunderstanding of what to store in a database and how.

    A database is supposed to hold unique information. When you store bills, you'll probably need something like the receiver, the amount etc. What you do not need to store is the billing number, because it's simply a "human readable" collection of various data (ID, prefix and suffix). The same goes for any derived amount like the service tax amount, the gross amount etc.

    In fact, it would be wrong to store these data, because this would be redundand. You'd store the same information multiple times, which is obviously inefficient, difficult to handle and error-prone (you can easily end up with conflicting data).

    So constructing the billing number has absolutely nothing to do with MySQL. This is what your application is for. Fetch the data you need and then let PHP make a string out of it.

    Comments on this post

    • aeternus agrees : indeed!

IMN logo majestic logo threadwatch logo seochat tools logo