Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:45:16+00:00 2026-06-10T20:45:16+00:00

how to generate invoice number such as below : Invoice Number = MC1200001 MC

  • 0

how to generate invoice number such as below :

Invoice Number = MC1200001 

MC : Company name
12 : current year (Flexibel)
00001 : auto increment (Flexibel - auto increment and will reset to 00001 again if year is 2013)

expected result :

current year 2012 :

MC1200001
MC1200002
MC1200003
.....

year 2013

MC1300001
MC1300002
MC1300003
.....

Need your idea or solution for this problem.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:45:18+00:00Added an answer on June 10, 2026 at 8:45 pm

    You could use three columns to express the different parts of the number and use a view or simple CONCAT expression to grab the entire number per invoice.

    Then to get a new number, you’d insert a record using a function that would return the actual row id or concatenated number.

    I’d do something like this: (leaving the leading zero’s out for brevity)

    DROP TABLE IF EXISTS invoces;
    
    CREATE TABLE invoices (
       id INT NOT NULL UNIQUE AUTO_INCREMENT
      ,company CHAR(2)
      ,number INT
      ,fiscal_year INT
     , PRIMARY KEY (company, number, fiscal_year)
    );
    
    DROP PROCEDURE IF EXISTS spCreateInvoice;
    DELIMITER $$
    
    CREATE PROCEDURE spCreateInvoice
    (
       pCompany CHAR(2)
      ,pFiscalYear INT
    )
    BEGIN
      INSERT INTO invoices (
        company, fiscal_year, number
      ) SELECT
            pCompany
          , pFiscalYear
          , 1+MAX(number) 
        FROM invoices 
        WHERE 
            fiscal_year=pFiscalYear;
    
      SET @id = LAST_INSERT_ID();
    
      SELECT CONCAT(i.company, i.number, i.fiscal_year) invoice_number, i.* from invoices i WHERE id = @id;
    END;
    $$
    DELIMITER ;
    
    CALL spCreateInvoice('MC', 12);
    CALL spCreateInvoice('MC', 12);
    CALL spCreateInvoice('MC', 12);
    CALL spCreateInvoice('MC', 12);
    
    CALL spCreateInvoice('MC', 13);
    CALL spCreateInvoice('MC', 13);
    CALL spCreateInvoice('MC', 13);
    CALL spCreateInvoice('MC', 13);
    

    You can run this as a script against your mysql test database and see the following output:

    invoice_number  id  company number  fiscal_year
    MC012           1   MC      0       12
    
    invoice_number  id  company number  fiscal_year
    MC112           2   MC      1       12
    
    invoice_number  id  company number  fiscal_year
    MC212           3   MC      2       12
    
    invoice_number  id  company number  fiscal_year
    MC312           4   MC      3       12
    
    invoice_number  id  company number  fiscal_year
    MC013           5   MC      0       13
    
    invoice_number  id  company number  fiscal_year
    MC113           6   MC      1       13
    
    invoice_number  id  company number  fiscal_year
    MC213           7   MC      2       13
    
    invoice_number  id  company number  fiscal_year
    MC313           8   MC          3   13
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Requirment: To generate invoice in pdf format on company template and send it in
I need to generate invoices in large batch which will be transformed to EDI
To generate the following markup: <label class=foo>Bar</label> The PHP will look something like: <?php
I need to generate unique and consecutive numbers (for use on an invoice), in
We have a script that generate invoice once a month (cron). But we would
I need to generate a user interface for entering a sales document (eg invoice).
I generate reports through a web system that was built for the company I
I'm working on a Nopcommerce, and need to generate Invoice (custom made not as
I'm making a simple one-form Invoice bill printing, below is the screenshot to illustrate
i want to generate a unique number from a table. It has to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.