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 8123517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:12:24+00:00 2026-06-06T06:12:24+00:00

I have a model called Invoice .I have made necessary CRUD for Invoice model

  • 0

I have a model called Invoice.I have made necessary CRUD for Invoice model.The attributes for the Invoice model are as like Invoice Title, Invoice No, Invoice Issue Date, Description.Now I want that when a user will redirect to invoice create page,the input field for Invoice No should be automatically filled in the create page with last inserted id +1 and it should have prefix like INV:.So the input field for Invoice No should be like this INV:12.By this a user don’t need to fill the invoice no manually in increasing order.Here is the image for the create page.enter image description here

  • 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-06T06:12:28+00:00Added an answer on June 6, 2026 at 6:12 am

    First of all==>This is not a good idea to store Invoice number dependent on table's unique id

    So you should insert last invoice number’s number part+1 with text..

    Now first get last invoice model then find its invoice number and populate the field..

    In controller..

    $model = new Invoice;
    
    $last_invoice = Invoice::model()->find(array('order'=>'id DESC'));
    $last_invoice_number = str_replace("INV:", "", $last_invoice->invoice_mumber);
    $new_invoice_number = $last_invoice_number+1;
    
    $model->invoice_number = "INV:".$new_invoice_number;
    
    $this->render('create',array('model'=>$model));
    

    EDIT:

    Reason why Yii::app()->db->lastInsertId) cannot be used..

    First as I said in first place its not good to dependent invoice id from unique id of table..second what if somebody inserted sonething in someother table in between..third what if the db connection is closed and started in between..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called note . I currently get notes like this: current_user.notes.order('date
I have a model called Contact which has_one guest like so. class Contact <
Have a model called contact_email.date_sent I want to be able to run a report
I have a model called Vote and this is what vote.rb looks like: class
I have a model called Category which looks like this: class Category < ActiveRecord::Base
I have a model called HeroStatus with the following attributes: id user_id recordable_type hero_type
I have a model (called Test): property :id, Serial property :title, String, :length =>
I have Model class Account: and other model called class Transactions: Now i have
I have model called Search and a resource named :search . I'd like to
I have a model called user. I want to show the password field just

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.